Skip to content

Commit 2e208a6

Browse files
committed
feat(MessageBar): pulled in compass styles
1 parent c082f9c commit 2e208a6

File tree

9 files changed

+106
-93
lines changed

9 files changed

+106
-93
lines changed

package-lock.json

Lines changed: 13 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@babel/preset-react": "^7.23.3",
4040
"@babel/preset-typescript": "^7.23.3",
4141
"@octokit/rest": "^18.0.0",
42-
"@patternfly/documentation-framework": "6.28.6",
42+
"@patternfly/documentation-framework": "6.28.9",
4343
"@patternfly/patternfly": "^6.1.0",
4444
"@patternfly/react-icons": "^6.1.0",
4545
"@patternfly/react-table": "^6.1.0",

packages/module/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"devDependencies": {
5757
"@octokit/rest": "^18.0.0",
58-
"@patternfly/documentation-framework": "6.28.6",
58+
"@patternfly/documentation-framework": "6.28.9",
5959
"@patternfly/patternfly": "^6.1.0",
6060
"@patternfly/patternfly-a11y": "^5.0.0",
6161
"@types/dom-speech-recognition": "^0.0.4",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FunctionComponent, useState } from 'react';
2+
import { MessageBar } from '@patternfly/chatbot/dist/dynamic/MessageBar';
3+
4+
export const ChatbotMessageBarIndicatorThinking: FunctionComponent = () => {
5+
const [isThinking, setIsThinking] = useState(false);
6+
const handleSend = (_message: string | number) => {
7+
console.log('handling');
8+
setIsThinking(true);
9+
10+
setTimeout(() => {
11+
setIsThinking(false);
12+
}, 10000);
13+
};
14+
15+
return <MessageBar onSendMessage={handleSend} hasAiIndicator isThinking={isThinking} />;
16+
};

packages/module/patternfly-docs/content/extensions/chatbot/examples/UI/UI.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ To enable the stop button, set `hasStopButton` to `true` and pass in a `handleSt
314314

315315
```
316316

317+
### Message bar with indicator and animation
318+
319+
You can pass the `hasAiIndicator` property to the `<MessageBar>` to give it a more pronounced AI indicator style. You can also pass the `isThinking` property to enable a "thinking" animation.
320+
321+
The following example shows a simplified way of how you might hanbdle the "thinking" animation: when you send a message, the `isThinking` property is set to `true`, then after 10 seconds it is set back to false to disable the animation again.
322+
323+
```ts file="./ChatbotMessageBarIndicatorThinking.tsx"
324+
325+
```
326+
317327
## Navigation
318328

319329
### Side nav in a drawer

packages/module/src/MessageBar/MessageBar.scss

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626

2727
overflow: hidden;
2828

29-
&.pf-m-primary {
30-
box-shadow: inset 0 0 0 1px var(--pf-t--global--border--color--default);
31-
}
29+
&:not(.pf-v6-m-thinking) {
30+
&.pf-m-primary {
31+
box-shadow: inset 0 0 0 1px var(--pf-t--global--border--color--default);
32+
}
3233

33-
&:hover {
34-
box-shadow: inset 0 0 0 1px var(--pf-t--global--border--color--default);
35-
}
34+
&:hover {
35+
box-shadow: inset 0 0 0 1px var(--pf-t--global--border--color--default);
36+
}
3637

37-
&:focus-within {
38-
box-shadow: inset 0 0 0 2px var(--pf-t--global--color--brand--default);
38+
&:focus-within {
39+
box-shadow: inset 0 0 0 2px var(--pf-t--global--color--brand--default);
40+
}
3941
}
4042

4143
&-actions {

packages/module/src/MessageBar/MessageBar.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,16 @@ describe('Message bar', () => {
448448
const { container } = render(<MessageBar isPrimary onSendMessage={jest.fn} />);
449449
expect(container.querySelector('.pf-m-primary')).toBeTruthy();
450450
});
451+
452+
it('Renders with class pf-v6-m-ai-indicator when hasAiIndicator is true', () => {
453+
render(<MessageBar onSendMessage={jest.fn} hasAiIndicator />);
454+
455+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-ai-indicator');
456+
});
457+
458+
it('Renders with class pf-v6-m-thinking when isThinking is true', () => {
459+
render(<MessageBar onSendMessage={jest.fn} isThinking />);
460+
461+
expect(screen.getByRole('textbox').closest('.pf-chatbot__message-bar')).toHaveClass('pf-v6-m-thinking');
462+
});
451463
});

packages/module/src/MessageBar/MessageBar.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TextAreaProps,
1111
TooltipProps
1212
} from '@patternfly/react-core';
13+
import { css } from '../utils/css';
1314

1415
// Import Chatbot components
1516
import SendButton from './SendButton';
@@ -120,6 +121,10 @@ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
120121
innerRef?: React.Ref<HTMLTextAreaElement>;
121122
/** Sets background color to primary */
122123
isPrimary?: boolean;
124+
/** Flag indicating whether the message bar has an AI indicator border. */
125+
hasAiIndicator?: boolean;
126+
/** Flag indicating whether the chatbot is thinking in response to a query, adding an animation to the message bar. */
127+
isThinking?: boolean;
123128
}
124129

125130
export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
@@ -151,6 +156,8 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
151156
dropzoneProps,
152157
innerRef,
153158
isPrimary,
159+
hasAiIndicator,
160+
isThinking,
154161
...props
155162
}: MessageBarProps) => {
156163
// Text Input
@@ -472,7 +479,15 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
472479
}
473480

474481
return (
475-
<div className={`pf-chatbot__message-bar ${isPrimary ? 'pf-m-primary' : ''} ${className ?? ''}`}>
482+
<div
483+
className={css(
484+
'pf-chatbot__message-bar',
485+
isPrimary && 'pf-m-primary',
486+
hasAiIndicator && 'pf-v6-m-ai-indicator',
487+
isThinking && 'pf-v6-m-thinking',
488+
className
489+
)}
490+
>
476491
{messageBarContents}
477492
</div>
478493
);

packages/module/src/utils/css.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export function css(...args: any): string {
2+
// Adapted from https://github.com/JedWatson/classnames/blob/master/index.js
3+
// Copied from patternfly/react-styles
4+
const classes = [] as string[];
5+
const hasOwn = {}.hasOwnProperty;
6+
7+
args.filter(Boolean).forEach((arg: any) => {
8+
const argType = typeof arg;
9+
10+
if (argType === 'string' || argType === 'number') {
11+
classes.push(arg);
12+
} else if (Array.isArray(arg) && arg.length) {
13+
const inner = css(...(arg as any));
14+
if (inner) {
15+
classes.push(inner);
16+
}
17+
} else if (argType === 'object') {
18+
for (const key in arg) {
19+
if (hasOwn.call(arg, key) && arg[key]) {
20+
classes.push(key);
21+
}
22+
}
23+
}
24+
});
25+
26+
return classes.join(' ');
27+
}

0 commit comments

Comments
 (0)