Skip to content

Commit 74a2c42

Browse files
khelif96shaneeza
andauthored
Make loading message configurable for @lg-chat/input-bar (#3116)
* Update InputBarFeedback.tsx * Support custom loading message * Changeset * run lint * CR * Use ReactNode * lint --------- Co-authored-by: Shaneeza <[email protected]>
1 parent 67dd0da commit 74a2c42

File tree

7 files changed

+45
-17
lines changed

7 files changed

+45
-17
lines changed

.changeset/sixty-hoops-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lg-chat/input-bar': minor
3+
---
4+
5+
Add support for configurable loadingMessage prop to InputBar

chat/input-bar/README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,21 @@ return (
5656

5757
## Properties
5858

59-
| Prop | Type | Description | Default |
60-
| ----------------------------- | ---------------------------------------------- | ----------------------------------------------------------- | ------- |
61-
| `badgeText` | `string` | Determines the text inside the rendered Badge | |
62-
| `darkMode` | `boolean` | Determines if the component will render in dark mode | `false` |
63-
| `disabled` | `boolean` | Determines whether the user can interact with the InputBar | `false` |
64-
| `disableSend` | `boolean` | When defined as `true`, disables the send action and button | |
65-
| `errorMessage` | `ReactNode` | Custom error message to display when `state='error'` | |
66-
| `onMessageSend` | `(messageBody: string, e?: FormEvent) => void` | Submit event handler. | |
67-
| `shouldRenderGradient` | `boolean` | Toggles the gradient animation around the input | `true` |
68-
| `shouldRenderHotkeyIndicator` | `boolean` | Toggles the hotkey indicator on the right side of the input | `false` |
69-
| `textareaProps` | `TextareaAutosizeProps` | Props passed to the TextareaAutosize component. | |
70-
| `textareaRef` | `RefObject<HTMLTextAreaElement>` | Ref object to access the textarea element directly | |
71-
| `state` | `'unset' \| 'error' \| 'loading'` | The current state of the InputBar. | |
72-
| `...` | `HTMLElementProps<'form'>` | Props spread on the root element | |
59+
| Prop | Type | Description | Default |
60+
| ----------------------------- | ---------------------------------------------- | ----------------------------------------------------------- | ------------------------------- |
61+
| `badgeText` | `string` | Determines the text inside the rendered Badge | |
62+
| `darkMode` | `boolean` | Determines if the component will render in dark mode | `false` |
63+
| `disabled` | `boolean` | Determines whether the user can interact with the InputBar | `false` |
64+
| `disableSend` | `boolean` | When defined as `true`, disables the send action and button | |
65+
| `loadingMessage` | `ReactNode` | Custom loading message to display when `state='loading'` | `MongoDB Assistant is thinking` |
66+
| `errorMessage` | `ReactNode` | Custom error message to display when `state='error'` | |
67+
| `onMessageSend` | `(messageBody: string, e?: FormEvent) => void` | Submit event handler. | |
68+
| `shouldRenderGradient` | `boolean` | Toggles the gradient animation around the input | `true` |
69+
| `shouldRenderHotkeyIndicator` | `boolean` | Toggles the hotkey indicator on the right side of the input | `false` |
70+
| `textareaProps` | `TextareaAutosizeProps` | Props passed to the TextareaAutosize component. | |
71+
| `textareaRef` | `RefObject<HTMLTextAreaElement>` | Ref object to access the textarea element directly | |
72+
| `state` | `'unset' \| 'error' \| 'loading'` | The current state of the InputBar. | |
73+
| `...` | `HTMLElementProps<'form'>` | Props spread on the root element | |
7374

7475
## TextareaAutosizeProps
7576

chat/input-bar/src/InputBar.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const meta: StoryMetaType<typeof InputBar> = {
2424
darkMode: [false, true],
2525
disabled: [false, true],
2626
disableSend: [false, true],
27+
loadingMessage: [undefined, 'Custom loading message'],
2728
state: Object.values(State),
2829
textareaProps: [
2930
{ value: '' },

chat/input-bar/src/InputBar/InputBar.spec.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,23 @@ describe('packages/input-bar', () => {
302302
});
303303

304304
describe('status states', () => {
305-
test('renders loading state when state is "loading"', () => {
305+
test('renders loading state with default message when state is "loading"', () => {
306306
renderInputBar({ state: State.Loading });
307307

308308
expect(
309309
screen.getByText(/MongoDB Assistant is thinking/i),
310310
).toBeInTheDocument();
311311
});
312312

313+
test('renders loading state with custom message when state is "loading" and loadingMessage provided', () => {
314+
renderInputBar({
315+
state: State.Loading,
316+
loadingMessage: 'Custom loading message',
317+
});
318+
319+
expect(screen.getByText(/Custom loading message/i)).toBeInTheDocument();
320+
});
321+
313322
test('renders error state with default message when state is "error" and no message provided', () => {
314323
renderInputBar({ state: State.Error });
315324

chat/input-bar/src/InputBar/InputBar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const InputBar = forwardRef<HTMLFormElement, InputBarProps>(
7474
dropdownFooterSlot,
7575
dropdownProps,
7676
errorMessage,
77+
loadingMessage,
7778
onMessageSend,
7879
onSubmit,
7980
shouldRenderGradient: shouldRenderGradientProp = true,
@@ -433,7 +434,11 @@ export const InputBar = forwardRef<HTMLFormElement, InputBarProps>(
433434
{...rest}
434435
>
435436
{isCompact && (
436-
<InputBarFeedback errorMessage={errorMessage} state={state} />
437+
<InputBarFeedback
438+
errorMessage={errorMessage}
439+
loadingMessage={loadingMessage}
440+
state={state}
441+
/>
437442
)}
438443
<div className={outerFocusContainerStyles}>
439444
<div

chat/input-bar/src/InputBar/InputBarFeedback.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const InputBarFeedback = forwardRef<
3232
className,
3333
darkMode: darkModeProp,
3434
errorMessage,
35+
loadingMessage,
3536
state,
3637
...rest
3738
},
@@ -51,7 +52,7 @@ export const InputBarFeedback = forwardRef<
5152
<div className={loadingContainerStyles}>
5253
<AssistantAvatar darkMode={darkMode} size={20} />
5354
<Body className={getLoadingTextStyles(theme)}>
54-
{messages.loading}
55+
{loadingMessage || messages.loading}
5556
</Body>
5657
</div>
5758
)}

chat/input-bar/src/InputBar/shared.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ export interface SharedInputBarProps {
1919
* @remarks This prop is only considered when the parent `LeafyGreenChatProvider` has `variant="compact"`.
2020
*/
2121
state?: State;
22+
23+
/**
24+
* Custom loading message to display when `state='loading'`
25+
* @remarks This prop is only considered when the parent `LeafyGreenChatProvider` has `variant="compact"`.
26+
*/
27+
loadingMessage?: ReactNode;
2228
}

0 commit comments

Comments
 (0)