Skip to content

Commit 4befb4a

Browse files
refactor: update chat input section layout and functionality
- Changed input section from grid to flex layout for better responsiveness. - Adjusted textarea and send button styles for improved usability. - Added event listeners for enabling/disabling the send button based on input. - Updated send button SVG to use currentColor for better theming.
1 parent 0e269fd commit 4befb4a

2 files changed

Lines changed: 42 additions & 36 deletions

File tree

hlx_statics/blocks/ai-assistant/ai-assistant.css

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,20 @@
238238
* MARK: Input Section
239239
*/
240240
.chat-window .chat-window-input-section {
241-
display: grid;
242-
grid-template-areas:
243-
"textarea textarea"
244-
"disclaimer-text send-button";
245-
grid-template-columns: 1fr 72px;
246-
grid-template-rows: auto auto;
247-
gap: 4px 12px;
241+
display: flex;
242+
flex-direction: column;
243+
gap: 4px;
248244
padding: 0 24px 24px 24px;
249245

246+
.chat-textarea-wrapper {
247+
position: relative;
248+
}
249+
250250
textarea {
251-
grid-area: textarea;
251+
width: 100%;
252252
min-height: 96px;
253253
max-height: 120px;
254-
padding: 12px;
254+
padding: 12px 12px 48px 12px;
255255
border: 2px solid #dadada;
256256
border-radius: 8px;
257257
font-family: "adobe-clean", "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Trebuchet MS", "Lucida Grande", sans-serif;
@@ -261,6 +261,7 @@
261261
background: #ffffff;
262262
resize: none;
263263
overflow-y: auto;
264+
box-sizing: border-box;
264265

265266
&:focus {
266267
outline: none;
@@ -273,8 +274,6 @@
273274
}
274275

275276
.chat-disclaimer-text {
276-
grid-area: disclaimer-text;
277-
align-self: center;
278277
font-size: 14px;
279278
line-height: 21px;
280279
color: #222222;
@@ -291,36 +290,33 @@
291290
}
292291

293292
.chat-send-button {
294-
grid-area: send-button;
295-
align-self: center;
296-
width: 100%;
293+
position: absolute;
294+
bottom: 8px;
295+
right: 8px;
296+
width: 72px;
297297
height: 32px;
298298
padding: 0;
299299
border: none;
300300
border-radius: 16px;
301-
background: #3b63fb;
301+
background: #e8e8e8;
302+
color: #292929;
302303
display: flex;
303304
align-items: center;
304305
justify-content: center;
306+
cursor: pointer;
305307

306-
&:hover {
307-
background: #2952e0;
308+
&:hover:not(:disabled) {
309+
background: #d0d0d0;
308310
}
309311

310-
&:active {
311-
background: #1f42c7;
312+
&:active:not(:disabled) {
313+
background: #b8b8b8;
312314
}
313315

314316
&:disabled {
315-
background: #e1e1e1;
317+
opacity: 0.5;
316318
cursor: not-allowed;
317319
}
318-
319-
img {
320-
width: 20px;
321-
height: 20px;
322-
filter: brightness(0) invert(1);
323-
}
324320
}
325321
}
326322

hlx_statics/blocks/ai-assistant/ai-assistant.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,29 @@ const createInputSection = () => {
675675
type: "button",
676676
"aria-label": "Send message",
677677
});
678-
sendButton.innerHTML = `<svg width="20" height="20" viewBox="0 0 20 20" focusable="false" aria-hidden="true" role="img" class="spectrum-Icon spectrum-Icon--sizeXL"><path d="M18.6485 9.97369C18.6482 9.67918 18.4769 9.41125 18.2059 9.29075L4.05752 2.93301C3.80133 2.81769 3.50129 2.85602 3.28171 3.03141C3.06178 3.20784 2.95889 3.49165 3.01516 3.76752L4.28678 10.0082L3.06488 16.2386C3.0162 16.4854 3.09492 16.7382 3.27031 16.9136C3.29068 16.9339 3.31278 16.9533 3.33522 16.9716C3.55619 17.1456 3.85519 17.1822 4.11069 17.0662L18.2086 10.658C18.4773 10.5358 18.6489 10.2682 18.6485 9.97369ZM14.406 9.22735L5.66439 9.25398L4.77705 4.90103L14.406 9.22735ZM4.81711 15.0974L5.6694 10.7531L14.4323 10.7265L4.81711 15.0974Z" fill="#ffffff"/></svg>`;
678+
sendButton.innerHTML = `<svg width="20" height="20" viewBox="0 0 20 20" focusable="false" aria-hidden="true" role="img" class="spectrum-Icon spectrum-Icon--sizeXL"><path d="M18.6485 9.97369C18.6482 9.67918 18.4769 9.41125 18.2059 9.29075L4.05752 2.93301C3.80133 2.81769 3.50129 2.85602 3.28171 3.03141C3.06178 3.20784 2.95889 3.49165 3.01516 3.76752L4.28678 10.0082L3.06488 16.2386C3.0162 16.4854 3.09492 16.7382 3.27031 16.9136C3.29068 16.9339 3.31278 16.9533 3.33522 16.9716C3.55619 17.1456 3.85519 17.1822 4.11069 17.0662L18.2086 10.658C18.4773 10.5358 18.6489 10.2682 18.6485 9.97369ZM14.406 9.22735L5.66439 9.25398L4.77705 4.90103L14.406 9.22735ZM4.81711 15.0974L5.6694 10.7531L14.4323 10.7265L4.81711 15.0974Z" fill="currentColor"/></svg>`;
679+
sendButton.disabled = true;
679680

680-
inputSection.appendChild(textarea);
681+
const textareaWrapper = createTag("div", { class: "chat-textarea-wrapper" });
682+
textareaWrapper.appendChild(textarea);
683+
textareaWrapper.appendChild(sendButton);
684+
685+
inputSection.appendChild(textareaWrapper);
681686
inputSection.appendChild(disclaimerText);
682-
inputSection.appendChild(sendButton);
683687
ELEMENTS.CHAT_SEND_BUTTON = sendButton;
684688
ELEMENTS.CHAT_TEXTAREA = textarea;
689+
690+
sendButton.addEventListener("click", handleUserQuery);
691+
textarea.addEventListener("input", () => {
692+
sendButton.disabled = textarea.value.trim() === "";
693+
});
694+
textarea.addEventListener("keydown", (e) => {
695+
if (e.key === "Enter" && !e.shiftKey) {
696+
e.preventDefault();
697+
handleUserQuery();
698+
}
699+
});
700+
685701
return inputSection;
686702
};
687703

@@ -820,6 +836,7 @@ const handleUserQuery = async (messageContentOverride) => {
820836
if (!messageContentOverride) {
821837
messageContent = ELEMENTS.CHAT_TEXTAREA.value.trim();
822838
ELEMENTS.CHAT_TEXTAREA.value = "";
839+
ELEMENTS.CHAT_TEXTAREA.dispatchEvent(new Event("input"));
823840
}
824841

825842
if (!messageContent) {
@@ -1056,12 +1073,5 @@ export default async function decorate(block) {
10561073
minimizeChatWindow,
10571074
);
10581075
ELEMENTS.CHAT_WINDOW_CLOSE_BUTTON.addEventListener("click", closeChatWindow);
1059-
ELEMENTS.CHAT_SEND_BUTTON.addEventListener("click", handleUserQuery);
1060-
ELEMENTS.CHAT_TEXTAREA.addEventListener("keydown", (e) => {
1061-
if (e.key === "Enter" && !e.shiftKey) {
1062-
e.preventDefault();
1063-
handleUserQuery();
1064-
}
1065-
});
10661076
}
10671077
// #endregion

0 commit comments

Comments
 (0)