-
Notifications
You must be signed in to change notification settings - Fork 28
feat(Settings): Add settings layout #360
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
289 changes: 289 additions & 0 deletions
289
packages/module/patternfly-docs/content/extensions/chatbot/examples/UI/Settings.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,289 @@ | ||
import React from 'react'; | ||
|
||
import SettingsForm from '@patternfly/chatbot/dist/dynamic/Settings'; | ||
import { | ||
Button, | ||
Divider, | ||
Dropdown, | ||
DropdownGroup, | ||
DropdownItem, | ||
DropdownList, | ||
MenuToggle, | ||
MenuToggleElement, | ||
Switch, | ||
Title | ||
} from '@patternfly/react-core'; | ||
import Chatbot, { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot'; | ||
import ChatbotHeader, { | ||
ChatbotHeaderActions, | ||
ChatbotHeaderCloseButton, | ||
ChatbotHeaderMain, | ||
ChatbotHeaderOptionsDropdown, | ||
ChatbotHeaderTitle | ||
} from '@patternfly/chatbot/dist/dynamic/ChatbotHeader'; | ||
import { CogIcon, ExpandIcon, OpenDrawerRightIcon, OutlinedWindowRestoreIcon } from '@patternfly/react-icons'; | ||
|
||
export const SettingsDemo: React.FunctionComponent = () => { | ||
const [isChecked, setIsChecked] = React.useState<boolean>(true); | ||
const [isThemeOpen, setIsThemeOpen] = React.useState(false); | ||
const [isLanguageOpen, setIsLanguageOpen] = React.useState(false); | ||
const [isVoiceOpen, setIsVoiceOpen] = React.useState(false); | ||
const [displayMode, setDisplayMode] = React.useState(ChatbotDisplayMode.default); | ||
const [areSettingsOpen, setAreSettingsOpen] = React.useState(true); | ||
const chatbotVisible = true; | ||
|
||
const onFocus = (id: string) => { | ||
const element = document.getElementById(id); | ||
(element as HTMLElement).focus(); | ||
}; | ||
|
||
const onThemeToggleClick = () => { | ||
setIsThemeOpen(!isThemeOpen); | ||
}; | ||
|
||
const onThemeSelect = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
value: string | number | undefined | ||
) => { | ||
// eslint-disable-next-line no-console | ||
console.log('selected', value); | ||
onFocus('theme'); | ||
setIsThemeOpen(false); | ||
}; | ||
|
||
const onLanguageToggleClick = () => { | ||
setIsLanguageOpen(!isLanguageOpen); | ||
}; | ||
|
||
const onLanguageSelect = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
value: string | number | undefined | ||
) => { | ||
// eslint-disable-next-line no-console | ||
console.log('selected', value); | ||
onFocus('language'); | ||
setIsLanguageOpen(false); | ||
}; | ||
|
||
const onVoiceToggleClick = () => { | ||
onFocus('voice'); | ||
setIsVoiceOpen(!isVoiceOpen); | ||
}; | ||
|
||
const onVoiceSelect = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
value: string | number | undefined | ||
) => { | ||
// eslint-disable-next-line no-console | ||
console.log('selected', value); | ||
setIsVoiceOpen(false); | ||
}; | ||
|
||
const handleChange = (_event: React.FormEvent<HTMLInputElement>, checked: boolean) => { | ||
setIsChecked(checked); | ||
}; | ||
|
||
const themeDropdown = ( | ||
<Dropdown | ||
isOpen={isThemeOpen} | ||
onSelect={onThemeSelect} | ||
onOpenChange={(isOpen: boolean) => setIsThemeOpen(isOpen)} | ||
shouldFocusToggleOnSelect | ||
shouldFocusFirstItemOnOpen | ||
shouldPreventScrollOnItemFocus | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<MenuToggle id="theme" ref={toggleRef} onClick={onThemeToggleClick} isExpanded={isThemeOpen}> | ||
System | ||
</MenuToggle> | ||
)} | ||
ouiaId="ThemeDropdown" | ||
> | ||
<DropdownList> | ||
<DropdownItem value="System" key="system"> | ||
System | ||
</DropdownItem> | ||
</DropdownList> | ||
</Dropdown> | ||
); | ||
|
||
const languageDropdown = ( | ||
<Dropdown | ||
isOpen={isLanguageOpen} | ||
onSelect={onLanguageSelect} | ||
onOpenChange={(isOpen: boolean) => setIsLanguageOpen(isOpen)} | ||
shouldFocusToggleOnSelect | ||
shouldFocusFirstItemOnOpen | ||
shouldPreventScrollOnItemFocus | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<MenuToggle id="language" ref={toggleRef} onClick={onLanguageToggleClick} isExpanded={isLanguageOpen}> | ||
Auto-detect | ||
</MenuToggle> | ||
)} | ||
ouiaId="LanguageDropdown" | ||
> | ||
<DropdownList> | ||
<DropdownItem value="Auto-detect" key="auto-detect"> | ||
Auto-detect | ||
</DropdownItem> | ||
</DropdownList> | ||
</Dropdown> | ||
); | ||
const voiceDropdown = ( | ||
<Dropdown | ||
isOpen={isVoiceOpen} | ||
onSelect={onVoiceSelect} | ||
onOpenChange={(isOpen: boolean) => setIsVoiceOpen(isOpen)} | ||
shouldFocusToggleOnSelect | ||
shouldFocusFirstItemOnOpen | ||
shouldPreventScrollOnItemFocus | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<MenuToggle id="voice" ref={toggleRef} onClick={onVoiceToggleClick} isExpanded={isVoiceOpen}> | ||
Bot | ||
</MenuToggle> | ||
)} | ||
ouiaId="VoiceDropdown" | ||
> | ||
<DropdownList> | ||
<DropdownItem value="Bot" key="bot"> | ||
Bot | ||
</DropdownItem> | ||
</DropdownList> | ||
</Dropdown> | ||
); | ||
const children = [ | ||
{ id: 'theme', label: 'Theme', field: themeDropdown }, | ||
{ id: 'language', label: 'Language', field: languageDropdown }, | ||
{ id: 'voice', label: 'Voice', field: voiceDropdown }, | ||
{ | ||
id: 'analytics', | ||
label: 'Share analytics', | ||
field: ( | ||
<Switch | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
id="analytics" | ||
aria-label="Togglable option for whether to share analytics" | ||
isChecked={isChecked} | ||
onChange={handleChange} | ||
/> | ||
) | ||
}, | ||
{ | ||
id: 'archived-chat', | ||
label: 'Archive chat', | ||
field: ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<Button id="archived-chat" variant="secondary"> | ||
Manage | ||
</Button> | ||
) | ||
}, | ||
{ | ||
id: 'archive-all', | ||
label: 'Archive all chat', | ||
field: ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<Button id="archive-all" variant="secondary"> | ||
Archive all | ||
</Button> | ||
) | ||
}, | ||
{ | ||
id: 'delete-all', | ||
label: 'Delete all chats', | ||
field: ( | ||
// We want to add the id property here as well so the label is coupled | ||
// with the button on screen readers. | ||
<Button id="delete-all" variant="danger"> | ||
Delete all | ||
</Button> | ||
) | ||
} | ||
]; | ||
|
||
const onSelectDropdownItem = ( | ||
_event: React.MouseEvent<Element, MouseEvent> | undefined, | ||
value: string | number | undefined | ||
) => { | ||
if (value === 'Settings') { | ||
setAreSettingsOpen(true); | ||
} else { | ||
setDisplayMode(value as ChatbotDisplayMode); | ||
} | ||
}; | ||
|
||
const regularChatbot = ( | ||
<ChatbotHeader> | ||
<ChatbotHeaderActions> | ||
<ChatbotHeaderOptionsDropdown onSelect={onSelectDropdownItem}> | ||
<DropdownGroup label="Display mode"> | ||
<DropdownList> | ||
<DropdownItem | ||
value={ChatbotDisplayMode.default} | ||
key="switchDisplayOverlay" | ||
icon={<OutlinedWindowRestoreIcon aria-hidden />} | ||
isSelected={displayMode === ChatbotDisplayMode.default} | ||
> | ||
<span>Overlay</span> | ||
</DropdownItem> | ||
<DropdownItem | ||
value={ChatbotDisplayMode.docked} | ||
key="switchDisplayDock" | ||
icon={<OpenDrawerRightIcon aria-hidden />} | ||
isSelected={displayMode === ChatbotDisplayMode.docked} | ||
> | ||
<span>Dock to window</span> | ||
</DropdownItem> | ||
<DropdownItem | ||
value={ChatbotDisplayMode.fullscreen} | ||
key="switchDisplayFullscreen" | ||
icon={<ExpandIcon aria-hidden />} | ||
isSelected={displayMode === ChatbotDisplayMode.fullscreen} | ||
> | ||
<span>Fullscreen</span> | ||
</DropdownItem> | ||
</DropdownList> | ||
</DropdownGroup> | ||
<Divider /> | ||
<DropdownList> | ||
<DropdownItem value="Settings" key="switchSettings" icon={<CogIcon aria-hidden />}> | ||
<span>Settings</span> | ||
</DropdownItem> | ||
</DropdownList> | ||
</ChatbotHeaderOptionsDropdown> | ||
</ChatbotHeaderActions> | ||
</ChatbotHeader> | ||
); | ||
|
||
return ( | ||
<> | ||
<Chatbot isVisible={chatbotVisible} displayMode={displayMode}> | ||
{areSettingsOpen ? ( | ||
<> | ||
<ChatbotHeader> | ||
<ChatbotHeaderMain> | ||
<ChatbotHeaderTitle> | ||
<Title headingLevel="h1" size="2xl"> | ||
Settings | ||
</Title> | ||
</ChatbotHeaderTitle> | ||
</ChatbotHeaderMain> | ||
<ChatbotHeaderCloseButton onClick={() => setAreSettingsOpen(false)} /> | ||
</ChatbotHeader> | ||
<SettingsForm fields={children} /> | ||
</> | ||
) : ( | ||
<>{regularChatbot}</> | ||
)} | ||
</Chatbot> | ||
</> | ||
); | ||
}; |
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
51 changes: 51 additions & 0 deletions
51
packages/module/src/ChatbotHeader/ChatbotHeaderCloseButton.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,51 @@ | ||
import React from 'react'; | ||
|
||
import { Button, Icon, Tooltip, TooltipProps } from '@patternfly/react-core'; | ||
import { CloseIcon } from '@patternfly/react-icons'; | ||
|
||
export interface ChatbotHeaderCloseButtonProps { | ||
/** Callback function for when button is clicked */ | ||
onClick: () => void; | ||
/** Custom classname for the header component */ | ||
className?: string; | ||
/** Props spread to the PF Tooltip component wrapping the display mode dropdown */ | ||
tooltipProps?: TooltipProps; | ||
/** Aria label for menu */ | ||
menuAriaLabel?: string; | ||
/** Ref applied to menu */ | ||
innerRef?: React.Ref<HTMLButtonElement>; | ||
/** Content used in tooltip */ | ||
tooltipContent?: string; | ||
} | ||
|
||
const ChatbotHeaderCloseButtonBase: React.FunctionComponent<ChatbotHeaderCloseButtonProps> = ({ | ||
className, | ||
onClick, | ||
tooltipProps, | ||
menuAriaLabel = 'Close', | ||
innerRef, | ||
tooltipContent = 'Close' | ||
}: ChatbotHeaderCloseButtonProps) => ( | ||
<div className={`pf-chatbot__menu ${className}`}> | ||
<Tooltip content={tooltipContent} position="bottom" {...tooltipProps}> | ||
<Button | ||
className="pf-chatbot__button--toggle-menu" | ||
variant="plain" | ||
onClick={onClick} | ||
aria-label={menuAriaLabel} | ||
ref={innerRef} | ||
icon={ | ||
<Icon size="xl" isInline> | ||
<CloseIcon /> | ||
</Icon> | ||
} | ||
/> | ||
</Tooltip> | ||
</div> | ||
); | ||
|
||
export const ChatbotHeaderCloseButton = React.forwardRef( | ||
(props: ChatbotHeaderCloseButtonProps, ref: React.Ref<HTMLButtonElement>) => ( | ||
<ChatbotHeaderCloseButtonBase innerRef={ref} {...props} /> | ||
) | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to deliver a whole new close button component? what about this one is different than other buttons?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Kayla and the Lightspeeds might want a close button for the general chatbot if they're going to be toggling it from other locations. This way it can be used for Settings or in the main chatbot itself. We don't have a universal chatbot button yet that incorporates all the header button styles - I'd want to do that maybe as we have time.