Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHCLOUD-31242 Add chatbot loading state #5

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sourceLink: https://github.com/patternfly/virtual-assistant/blob/main/packages/m

import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant';
import VirtualAssistantAction from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistantAction';
import LoadingMessage from '@patternfly/virtual-assistant/dist/dynamic/LoadingMessage';
import { GrinIcon } from '@patternfly/react-icons';
import { AngleDownIcon } from '@patternfly/react-icons';

The **virtual assistant** component renders body of the virtual assistant window.
Expand Down Expand Up @@ -61,3 +63,12 @@ Custom actions can be added to the assistant body using the `actions` property.
```js file="./VirtualAssistantWithActions.tsx"

```

### Loading Messages

The `LoadingMessage` component shows a typing indicator for messages still being processed, introducing an intentional delay to simulate a smoother flow of conversation. Additionally, it allows for the use of a custom icon through the `icon` property.


```js file="./VirtualAssistantLoadingMessage.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant';
import LoadingMessage from '@patternfly/virtual-assistant/dist/esm/LoadingMessage'
import GrinIcon from '@patternfly/react-icons/dist/js/icons/bacon-icon';

export const BasicExample: React.FunctionComponent = () => (
<VirtualAssistant >
<LoadingMessage />
<LoadingMessage icon={GrinIcon} />
</VirtualAssistant>
);
86 changes: 86 additions & 0 deletions packages/module/src/LoadingMessage/LoadingMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { Icon, Split, SplitItem } from '@patternfly/react-core';
import { createUseStyles } from 'react-jss';
import classnames from "clsx";

import RobotIcon from '@patternfly/react-icons/dist/js/icons/robot-icon';

const useStyles = createUseStyles({
chatbot: {
marginBottom: "var(--pf-v5-global--spacer--md)",
marginRight: "40px",
},
bubble: {
border: "1px solid var(--pf-v5-global--BackgroundColor--dark-400)",
borderRadius: "14px",
padding: "var(--pf-v5-global--spacer--sm) var(--pf-v5-global--spacer--md) var(--pf-v5-global--spacer--sm) var(--pf-v5-global--spacer--md)",
maxWidth: "100%",
wordWrap: "break-word",
},
"@keyframes mercuryTypingAnimation": {
"0%": {
transform: "translateY(0px)",
backgroundColor: "var(--pf-v5-global--palette--black-600)",
},
"28%": {
transform: "translateY(-7px)",
backgroundColor: "var(--pf-v5-global--palette--black-400)",
},
"44%": {
transform: "translateY(0px)",
backgroundColor: "var(--pf-v5-global--palette--black-200)",
}
},
dot: {},
typing: {
height: "17px",
"& $dot": {
animation: "$mercuryTypingAnimation 1.8s infinite ease-in-out",
borderRadius: "50%",
display: "inline-block",
height: "7px",
marginRight: "4px",
marginTop: "6px",
verticalAlign: "middle",
width: "7px",
"&:nth-child(1)": {
animationDelay: "200ms",
},
"&:nth-child(2)": {
animationDelay: "300ms",
},
"&:nth-child(3)": {
animationDelay: "400ms",
},
"&:last-child": {
marginRight: "0",
},
}
}
})

export interface LoadingMessageProps {
icon?: React.ComponentClass;
}

export const LoadingMessage: React.FunctionComponent<LoadingMessageProps> = ({ icon: IconComponent = RobotIcon }) => {
const classes = useStyles();
return (
<Split className={classes.chatbot}>
<SplitItem>
<Icon size="lg" className="pf-v5-u-mr-sm pf-v5-u-pt-md">
<IconComponent />
</Icon>
</SplitItem>
<SplitItem className={classnames(classes.bubble," pf-u-background-color-200")} >
<div className={classnames(classes.typing,"pf-v5-u-display-flex pf-u-align-items-center")}>
<div className={classes.dot}></div>
<div className={classes.dot}></div>
<div className={classes.dot}></div>
</div>
</SplitItem>
</Split>
);
};

export default LoadingMessage;
3 changes: 3 additions & 0 deletions packages/module/src/LoadingMessage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default } from './LoadingMessage';

export * from './LoadingMessage';
3 changes: 3 additions & 0 deletions packages/module/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// this file is autogenerated by generate-index.js, modifying it manually will have no effect

export { default as LoadingMessage } from './LoadingMessage';
export * from './LoadingMessage';

export { default as VirtualAssistant } from './VirtualAssistant';
export * from './VirtualAssistant';

Expand Down
Loading