From d54ab485ee1dfe3fe0c4eeb78c8f3bdf580a9ee1 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:53:24 +1200 Subject: [PATCH] feat: Add Setting Switch Component --- invokeai/frontend/web/public/locales/en.json | 7 ++- .../web/src/common/components/IAISwitch.tsx | 4 +- .../SettingsModal/SettingSwitch.tsx | 57 +++++++++++++++++++ .../SettingsModal/SettingsModal.tsx | 48 +++++++++------- 4 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 invokeai/frontend/web/src/features/system/components/SettingsModal/SettingSwitch.tsx diff --git a/invokeai/frontend/web/public/locales/en.json b/invokeai/frontend/web/public/locales/en.json index 32ff5749254..f5922a6ff40 100644 --- a/invokeai/frontend/web/public/locales/en.json +++ b/invokeai/frontend/web/public/locales/en.json @@ -547,7 +547,8 @@ "saveSteps": "Save images every n steps", "confirmOnDelete": "Confirm On Delete", "displayHelpIcons": "Display Help Icons", - "useCanvasBeta": "Use Canvas Beta Layout", + "alternateCanvasLayout": "Alternate Canvas Layout", + "enableNodesEditor": "Enable Nodes Editor", "enableImageDebugging": "Enable Image Debugging", "useSlidersForAll": "Use Sliders For All Options", "showProgressInViewer": "Show Progress Images in Viewer", @@ -564,7 +565,9 @@ "ui": "User Interface", "favoriteSchedulers": "Favorite Schedulers", "favoriteSchedulersPlaceholder": "No schedulers favorited", - "showAdvancedOptions": "Show Advanced Options" + "showAdvancedOptions": "Show Advanced Options", + "experimental": "Experimental", + "beta": "Beta" }, "toast": { "serverError": "Server Error", diff --git a/invokeai/frontend/web/src/common/components/IAISwitch.tsx b/invokeai/frontend/web/src/common/components/IAISwitch.tsx index d25ab0d87e9..98036263970 100644 --- a/invokeai/frontend/web/src/common/components/IAISwitch.tsx +++ b/invokeai/frontend/web/src/common/components/IAISwitch.tsx @@ -9,7 +9,7 @@ import { } from '@chakra-ui/react'; import { memo } from 'react'; -interface Props extends SwitchProps { +export interface IAISwitchProps extends SwitchProps { label?: string; width?: string | number; formControlProps?: FormControlProps; @@ -20,7 +20,7 @@ interface Props extends SwitchProps { /** * Customized Chakra FormControl + Switch multi-part component. */ -const IAISwitch = (props: Props) => { +const IAISwitch = (props: IAISwitchProps) => { const { label, isDisabled = false, diff --git a/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingSwitch.tsx b/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingSwitch.tsx new file mode 100644 index 00000000000..e035b90d3a4 --- /dev/null +++ b/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingSwitch.tsx @@ -0,0 +1,57 @@ +import { Badge, BadgeProps, Flex, Text, TextProps } from '@chakra-ui/react'; +import IAISwitch, { IAISwitchProps } from 'common/components/IAISwitch'; +import { useTranslation } from 'react-i18next'; + +type SettingSwitchProps = IAISwitchProps & { + label: string; + useBadge?: boolean; + badgeLabel?: string; + textProps?: TextProps; + badgeProps?: BadgeProps; +}; + +export default function SettingSwitch(props: SettingSwitchProps) { + const { t } = useTranslation(); + + const { + label, + textProps, + useBadge = false, + badgeLabel = t('settings.experimental'), + badgeProps, + ...rest + } = props; + + return ( + + + + {label} + + {useBadge && ( + + {badgeLabel} + + )} + + + + ); +} diff --git a/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsModal.tsx b/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsModal.tsx index ccc4a9aa247..5ec7a09b676 100644 --- a/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsModal.tsx +++ b/invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsModal.tsx @@ -11,13 +11,12 @@ import { Text, useDisclosure, } from '@chakra-ui/react'; -import { createSelector, current } from '@reduxjs/toolkit'; +import { createSelector } from '@reduxjs/toolkit'; import { VALID_LOG_LEVELS } from 'app/logging/useLogger'; import { LOCALSTORAGE_KEYS, LOCALSTORAGE_PREFIX } from 'app/store/constants'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import IAIButton from 'common/components/IAIButton'; import IAIMantineSelect from 'common/components/IAIMantineSelect'; -import IAISwitch from 'common/components/IAISwitch'; import { systemSelector } from 'features/system/store/systemSelectors'; import { SystemState, @@ -48,8 +47,9 @@ import { } from 'react'; import { useTranslation } from 'react-i18next'; import { LogLevelName } from 'roarr'; -import SettingsSchedulers from './SettingsSchedulers'; +import SettingSwitch from './SettingSwitch'; import SettingsClearIntermediates from './SettingsClearIntermediates'; +import SettingsSchedulers from './SettingsSchedulers'; const selector = createSelector( [systemSelector, uiSelector], @@ -206,7 +206,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => { {t('settings.general')} - ) => @@ -214,7 +214,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => { } /> {shouldShowAdvancedOptionsSettings && ( - ) => @@ -231,37 +231,29 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => { {t('settings.ui')} - ) => dispatch(setShouldDisplayGuides(e.target.checked)) } /> - {shouldShowBetaLayout && ( - ) => - dispatch(setShouldUseCanvasBetaLayout(e.target.checked)) - } - /> - )} - ) => dispatch(setShouldUseSliders(e.target.checked)) } /> - ) => dispatch(setShouldShowProgressInViewer(e.target.checked)) } /> - ) => @@ -270,9 +262,21 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => { ) } /> + {shouldShowBetaLayout && ( + ) => + dispatch(setShouldUseCanvasBetaLayout(e.target.checked)) + } + /> + )} {shouldShowNodesToggle && ( - @@ -282,7 +286,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => { {shouldShowDeveloperSettings && ( {t('settings.developer')} - { value={consoleLogLevel} data={VALID_LOG_LEVELS.concat()} /> - ) =>