import { useState, FunctionComponent, MouseEvent, Ref } 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: FunctionComponent = () => { const [isChecked, setIsChecked] = useState(true); const [isThemeOpen, setIsThemeOpen] = useState(false); const [isLanguageOpen, setIsLanguageOpen] = useState(false); const [isVoiceOpen, setIsVoiceOpen] = useState(false); const [displayMode, setDisplayMode] = useState(ChatbotDisplayMode.default); const [areSettingsOpen, setAreSettingsOpen] = 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: 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: 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: MouseEvent | undefined, value: string | number | undefined) => { // eslint-disable-next-line no-console console.log('selected', value); setIsVoiceOpen(false); }; const handleChange = (_event: FormEvent, checked: boolean) => { setIsChecked(checked); }; const themeDropdown = ( setIsThemeOpen(isOpen)} shouldFocusToggleOnSelect shouldFocusFirstItemOnOpen shouldPreventScrollOnItemFocus toggle={(toggleRef: Ref) => ( // We want to add the id property here as well so the label is coupled // with the button on screen readers. System )} ouiaId="ThemeDropdown" > System ); const languageDropdown = ( setIsLanguageOpen(isOpen)} shouldFocusToggleOnSelect shouldFocusFirstItemOnOpen shouldPreventScrollOnItemFocus toggle={(toggleRef: Ref) => ( // We want to add the id property here as well so the label is coupled // with the button on screen readers. Auto-detect )} ouiaId="LanguageDropdown" > Auto-detect ); const voiceDropdown = ( setIsVoiceOpen(isOpen)} shouldFocusToggleOnSelect shouldFocusFirstItemOnOpen shouldPreventScrollOnItemFocus toggle={(toggleRef: Ref) => ( // We want to add the id property here as well so the label is coupled // with the button on screen readers. Bot )} ouiaId="VoiceDropdown" > Bot ); 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: ( ) }, { 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. ) }, { id: 'archive-all', label: 'Archive all chats', field: ( // We want to add the id property here as well so the label is coupled // with the button on screen readers. ) }, { 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. ) } ]; const onSelectDropdownItem = ( _event: MouseEvent | undefined, value: string | number | undefined ) => { if (value === 'Settings') { setAreSettingsOpen(true); } else { setDisplayMode(value as ChatbotDisplayMode); } }; const regularChatbot = ( } isSelected={displayMode === ChatbotDisplayMode.default} > Overlay } isSelected={displayMode === ChatbotDisplayMode.docked} > Dock to window } isSelected={displayMode === ChatbotDisplayMode.fullscreen} > Fullscreen }> Settings ); return ( <> {areSettingsOpen ? ( <> Settings setAreSettingsOpen(false)} /> ) : ( <>{regularChatbot} )} ); };