-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from josejulio/RHCLOUD-31230
- Loading branch information
Showing
11 changed files
with
388 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ent/extensions/virtual-assistant/examples/VirtualAssistant/VirtualAssistantCustomText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant'; | ||
|
||
export const VirtualAssistantCustomText: React.FunctionComponent = () => ( | ||
<VirtualAssistant | ||
title="PatternFly assistant" | ||
inputPlaceholder="You can ask anything in here." | ||
/> | ||
); |
17 changes: 17 additions & 0 deletions
17
...nsions/virtual-assistant/examples/VirtualAssistant/VirtualAssistantDisableOnEmptyText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant'; | ||
|
||
export const VirtualAssistantDisableOnEmptyText: React.FunctionComponent = () => { | ||
|
||
const [ message, setMessage ] = React.useState<string>(""); | ||
|
||
return ( | ||
<> | ||
<VirtualAssistant | ||
message={message} | ||
onChangeMessage={(_event, value) => setMessage(value)} | ||
isSendButtonDisabled={message.trim() === ""} | ||
/> | ||
</> | ||
) | ||
}; |
21 changes: 21 additions & 0 deletions
21
...ntent/extensions/virtual-assistant/examples/VirtualAssistant/VirtualAssistantMessages.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant'; | ||
|
||
export const VirtualAssistantMessages: React.FunctionComponent = () => { | ||
|
||
const [ message, setMessage ] = React.useState<string>(); | ||
const [ lastMessage, setLastMessage ] = React.useState<string>(); | ||
|
||
return ( | ||
<> | ||
<p><b>Last received message: </b> {lastMessage}</p> | ||
<VirtualAssistant | ||
message={message} | ||
onChangeMessage={(_event, value) => setMessage(value)} | ||
onSendMessage={(message: string) => { | ||
setLastMessage(message); | ||
}} | ||
/> | ||
</> | ||
) | ||
}; |
12 changes: 12 additions & 0 deletions
12
...nt/extensions/virtual-assistant/examples/VirtualAssistant/VirtualAssistantWithActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import VirtualAssistant from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistant'; | ||
import VirtualAssistantAction from '@patternfly/virtual-assistant/dist/dynamic/VirtualAssistantAction'; | ||
import { AngleDownIcon } from '@patternfly/react-icons'; | ||
|
||
export const VirtualAssistantWithActions: React.FunctionComponent = () => ( | ||
<VirtualAssistant actions={<> | ||
<VirtualAssistantAction aria-label="Minimize virtual assistant"> | ||
<AngleDownIcon/> | ||
</VirtualAssistantAction> | ||
</>} /> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 115 additions & 7 deletions
122
packages/module/src/VirtualAssistant/VirtualAssistant.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,122 @@ | ||
import React from 'react'; | ||
import { Text } from '@patternfly/react-core' | ||
import { | ||
Button, | ||
Card, | ||
CardBody, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
InputGroup, | ||
InputGroupText, | ||
TextArea | ||
} from '@patternfly/react-core'; | ||
import { createUseStyles } from 'react-jss'; | ||
import classnames from "clsx"; | ||
import { PaperPlaneIcon } from '@patternfly/react-icons'; | ||
|
||
const useStyles = createUseStyles({ | ||
card: { | ||
width: "350px", | ||
height: "550px", | ||
overflow: "hidden", | ||
"@media screen and (max-width: 768px)": { | ||
height: "420px", | ||
width: "100%", | ||
}, | ||
}, | ||
cardHeader: { | ||
background: "var(--pf-v5-global--BackgroundColor--dark-400)", | ||
}, | ||
cardTitle: { | ||
color: "var(--pf-v5-global--Color--light-100)", | ||
}, | ||
cardBody: { | ||
backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", | ||
paddingLeft: "var(--pf-v5-global--spacer--md)", | ||
paddingRight: "var(--pf-v5-global--spacer--md)", | ||
paddingTop: "var(--pf-v5-global--spacer--lg)", | ||
overflowY: "scroll", | ||
"&::-webkit-scrollbar": "display: none", | ||
}, | ||
cardFooter: { | ||
padding: "0", | ||
}, | ||
inputGroup: { | ||
height: "60px", | ||
}, | ||
textArea: { | ||
resize: "none", | ||
} | ||
}) | ||
|
||
export interface VirtualAssistantProps { | ||
/** Content text */ | ||
text?: string; | ||
}; | ||
/** Messages rendered within the assistant */ | ||
children?: React.ReactNode; | ||
/** Header title for the assistant */ | ||
title?: string; | ||
/** Input's placeholder for the assistant */ | ||
inputPlaceholder?: string; | ||
/** Input's content */ | ||
message?: string; | ||
/** Header actions of the assistant */ | ||
actions?: React.ReactNode; | ||
/** Input's content change */ | ||
onChangeMessage?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => void; | ||
/** Fire when clicking the Send (Plane) icon */ | ||
onSendMessage?: (message: string) => void; | ||
/** Disables the text input */ | ||
isInputDisabled?: boolean; | ||
/** Disables the send button */ | ||
isSendButtonDisabled?: boolean; | ||
} | ||
|
||
const VirtualAssistant: React.FunctionComponent<VirtualAssistantProps> = ({ text, ...props }: VirtualAssistantProps) => ( | ||
<Text {...props}>{text ?? 'Virtual assistant content'}</Text> | ||
); | ||
export const VirtualAssistant: React.FunctionComponent<VirtualAssistantProps> = ({ | ||
children, | ||
title = 'Virtual Assistant', | ||
inputPlaceholder = 'Type a message...', | ||
message = '', | ||
actions, | ||
onChangeMessage, | ||
onSendMessage, | ||
isInputDisabled = false, | ||
isSendButtonDisabled = false, | ||
}: VirtualAssistantProps) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Card className={classes.card}> | ||
<CardHeader className={classes.cardHeader} actions={actions ? { | ||
actions | ||
} : undefined}> | ||
<CardTitle className={classnames(classes.cardTitle,"pf-v5-u-font-size-xl")}> | ||
{title} | ||
</CardTitle> | ||
</CardHeader> | ||
<CardBody className={classes.cardBody}> | ||
{children} | ||
</CardBody> | ||
<CardFooter className={classes.cardFooter}> | ||
<InputGroup className={classes.inputGroup}> | ||
<TextArea | ||
className={classes.textArea} | ||
placeholder={inputPlaceholder} | ||
value={message} | ||
onChange={onChangeMessage} | ||
type="text" | ||
aria-label="Assistant input" | ||
isDisabled={isInputDisabled} | ||
/> | ||
<InputGroupText> | ||
<Button isDisabled={isSendButtonDisabled} aria-label="Virtual assistant's message" variant="plain" className="pf-v5-u-px-sm" onClick={onSendMessage ? () => { | ||
onSendMessage(message); | ||
} : undefined}> | ||
<PaperPlaneIcon /> | ||
</Button> | ||
</InputGroupText> | ||
</InputGroup> | ||
</CardFooter> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default VirtualAssistant; |
Oops, something went wrong.