feat: Add Setting Switch Component (#3847)

This commit is contained in:
blessedcoolant 2023-07-20 14:17:51 +12:00 committed by GitHub
parent f6d5e93020
commit 6e36c275c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 26 deletions

View File

@ -547,7 +547,8 @@
"saveSteps": "Save images every n steps", "saveSteps": "Save images every n steps",
"confirmOnDelete": "Confirm On Delete", "confirmOnDelete": "Confirm On Delete",
"displayHelpIcons": "Display Help Icons", "displayHelpIcons": "Display Help Icons",
"useCanvasBeta": "Use Canvas Beta Layout", "alternateCanvasLayout": "Alternate Canvas Layout",
"enableNodesEditor": "Enable Nodes Editor",
"enableImageDebugging": "Enable Image Debugging", "enableImageDebugging": "Enable Image Debugging",
"useSlidersForAll": "Use Sliders For All Options", "useSlidersForAll": "Use Sliders For All Options",
"showProgressInViewer": "Show Progress Images in Viewer", "showProgressInViewer": "Show Progress Images in Viewer",
@ -564,7 +565,9 @@
"ui": "User Interface", "ui": "User Interface",
"favoriteSchedulers": "Favorite Schedulers", "favoriteSchedulers": "Favorite Schedulers",
"favoriteSchedulersPlaceholder": "No schedulers favorited", "favoriteSchedulersPlaceholder": "No schedulers favorited",
"showAdvancedOptions": "Show Advanced Options" "showAdvancedOptions": "Show Advanced Options",
"experimental": "Experimental",
"beta": "Beta"
}, },
"toast": { "toast": {
"serverError": "Server Error", "serverError": "Server Error",

View File

@ -9,7 +9,7 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { memo } from 'react'; import { memo } from 'react';
interface Props extends SwitchProps { export interface IAISwitchProps extends SwitchProps {
label?: string; label?: string;
width?: string | number; width?: string | number;
formControlProps?: FormControlProps; formControlProps?: FormControlProps;
@ -20,7 +20,7 @@ interface Props extends SwitchProps {
/** /**
* Customized Chakra FormControl + Switch multi-part component. * Customized Chakra FormControl + Switch multi-part component.
*/ */
const IAISwitch = (props: Props) => { const IAISwitch = (props: IAISwitchProps) => {
const { const {
label, label,
isDisabled = false, isDisabled = false,

View File

@ -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 (
<Flex justifyContent="space-between" py={1}>
<Flex gap={2} alignItems="center">
<Text
sx={{
fontSize: 14,
_dark: {
color: 'base.300',
},
}}
{...textProps}
>
{label}
</Text>
{useBadge && (
<Badge
size="xs"
sx={{
px: 2,
color: 'base.700',
bg: 'accent.200',
_dark: { bg: 'accent.500', color: 'base.200' },
}}
{...badgeProps}
>
{badgeLabel}
</Badge>
)}
</Flex>
<IAISwitch {...rest} />
</Flex>
);
}

View File

@ -11,13 +11,12 @@ import {
Text, Text,
useDisclosure, useDisclosure,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { createSelector, current } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { VALID_LOG_LEVELS } from 'app/logging/useLogger'; import { VALID_LOG_LEVELS } from 'app/logging/useLogger';
import { LOCALSTORAGE_KEYS, LOCALSTORAGE_PREFIX } from 'app/store/constants'; import { LOCALSTORAGE_KEYS, LOCALSTORAGE_PREFIX } from 'app/store/constants';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAIButton from 'common/components/IAIButton'; import IAIButton from 'common/components/IAIButton';
import IAIMantineSelect from 'common/components/IAIMantineSelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import IAISwitch from 'common/components/IAISwitch';
import { systemSelector } from 'features/system/store/systemSelectors'; import { systemSelector } from 'features/system/store/systemSelectors';
import { import {
SystemState, SystemState,
@ -48,8 +47,9 @@ import {
} from 'react'; } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { LogLevelName } from 'roarr'; import { LogLevelName } from 'roarr';
import SettingsSchedulers from './SettingsSchedulers'; import SettingSwitch from './SettingSwitch';
import SettingsClearIntermediates from './SettingsClearIntermediates'; import SettingsClearIntermediates from './SettingsClearIntermediates';
import SettingsSchedulers from './SettingsSchedulers';
const selector = createSelector( const selector = createSelector(
[systemSelector, uiSelector], [systemSelector, uiSelector],
@ -206,7 +206,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
<Flex sx={{ gap: 4, flexDirection: 'column' }}> <Flex sx={{ gap: 4, flexDirection: 'column' }}>
<StyledFlex> <StyledFlex>
<Heading size="sm">{t('settings.general')}</Heading> <Heading size="sm">{t('settings.general')}</Heading>
<IAISwitch <SettingSwitch
label={t('settings.confirmOnDelete')} label={t('settings.confirmOnDelete')}
isChecked={shouldConfirmOnDelete} isChecked={shouldConfirmOnDelete}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
@ -214,7 +214,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
} }
/> />
{shouldShowAdvancedOptionsSettings && ( {shouldShowAdvancedOptionsSettings && (
<IAISwitch <SettingSwitch
label={t('settings.showAdvancedOptions')} label={t('settings.showAdvancedOptions')}
isChecked={shouldShowAdvancedOptions} isChecked={shouldShowAdvancedOptions}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
@ -231,37 +231,29 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
<StyledFlex> <StyledFlex>
<Heading size="sm">{t('settings.ui')}</Heading> <Heading size="sm">{t('settings.ui')}</Heading>
<IAISwitch <SettingSwitch
label={t('settings.displayHelpIcons')} label={t('settings.displayHelpIcons')}
isChecked={shouldDisplayGuides} isChecked={shouldDisplayGuides}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldDisplayGuides(e.target.checked)) dispatch(setShouldDisplayGuides(e.target.checked))
} }
/> />
{shouldShowBetaLayout && (
<IAISwitch <SettingSwitch
label={t('settings.useCanvasBeta')}
isChecked={shouldUseCanvasBetaLayout}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldUseCanvasBetaLayout(e.target.checked))
}
/>
)}
<IAISwitch
label={t('settings.useSlidersForAll')} label={t('settings.useSlidersForAll')}
isChecked={shouldUseSliders} isChecked={shouldUseSliders}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldUseSliders(e.target.checked)) dispatch(setShouldUseSliders(e.target.checked))
} }
/> />
<IAISwitch <SettingSwitch
label={t('settings.showProgressInViewer')} label={t('settings.showProgressInViewer')}
isChecked={shouldShowProgressInViewer} isChecked={shouldShowProgressInViewer}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldShowProgressInViewer(e.target.checked)) dispatch(setShouldShowProgressInViewer(e.target.checked))
} }
/> />
<IAISwitch <SettingSwitch
label={t('settings.antialiasProgressImages')} label={t('settings.antialiasProgressImages')}
isChecked={shouldAntialiasProgressImage} isChecked={shouldAntialiasProgressImage}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
@ -270,9 +262,21 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
) )
} }
/> />
{shouldShowBetaLayout && (
<SettingSwitch
label={t('settings.alternateCanvasLayout')}
useBadge
badgeLabel={t('settings.beta')}
isChecked={shouldUseCanvasBetaLayout}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldUseCanvasBetaLayout(e.target.checked))
}
/>
)}
{shouldShowNodesToggle && ( {shouldShowNodesToggle && (
<IAISwitch <SettingSwitch
label="Enable Nodes Editor (Experimental)" label={t('settings.enableNodesEditor')}
useBadge
isChecked={isNodesEnabled} isChecked={isNodesEnabled}
onChange={handleToggleNodes} onChange={handleToggleNodes}
/> />
@ -282,7 +286,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
{shouldShowDeveloperSettings && ( {shouldShowDeveloperSettings && (
<StyledFlex> <StyledFlex>
<Heading size="sm">{t('settings.developer')}</Heading> <Heading size="sm">{t('settings.developer')}</Heading>
<IAISwitch <SettingSwitch
label={t('settings.shouldLogToConsole')} label={t('settings.shouldLogToConsole')}
isChecked={shouldLogToConsole} isChecked={shouldLogToConsole}
onChange={handleLogToConsoleChanged} onChange={handleLogToConsoleChanged}
@ -294,7 +298,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
value={consoleLogLevel} value={consoleLogLevel}
data={VALID_LOG_LEVELS.concat()} data={VALID_LOG_LEVELS.concat()}
/> />
<IAISwitch <SettingSwitch
label={t('settings.enableImageDebugging')} label={t('settings.enableImageDebugging')}
isChecked={enableImageDebugging} isChecked={enableImageDebugging}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>