-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Port Schedulers to Mantine (#3552)
- Ports Schedulers to use IAIMantineSelect. - Adds ability to favorite schedulers in Settings. Favorited schedulers show up at the top of the list. - Adds IAIMantineMultiSelect component. - Change SettingsSchedulers component to use IAIMantineMultiSelect instead of Chakra Menus.
- Loading branch information
Showing
10 changed files
with
210 additions
and
82 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
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
94 changes: 94 additions & 0 deletions
94
invokeai/frontend/web/src/common/components/IAIMantineMultiSelect.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,94 @@ | ||
import { Tooltip } from '@chakra-ui/react'; | ||
import { MultiSelect, MultiSelectProps } from '@mantine/core'; | ||
import { memo } from 'react'; | ||
|
||
type IAIMultiSelectProps = MultiSelectProps & { | ||
tooltip?: string; | ||
}; | ||
|
||
const IAIMantineMultiSelect = (props: IAIMultiSelectProps) => { | ||
const { searchable = true, tooltip, ...rest } = props; | ||
return ( | ||
<Tooltip label={tooltip} placement="top" hasArrow> | ||
<MultiSelect | ||
searchable={searchable} | ||
styles={() => ({ | ||
label: { | ||
color: 'var(--invokeai-colors-base-300)', | ||
fontWeight: 'normal', | ||
}, | ||
searchInput: { | ||
'::placeholder': { | ||
color: 'var(--invokeai-colors-base-700)', | ||
}, | ||
}, | ||
input: { | ||
backgroundColor: 'var(--invokeai-colors-base-900)', | ||
borderWidth: '2px', | ||
borderColor: 'var(--invokeai-colors-base-800)', | ||
color: 'var(--invokeai-colors-base-100)', | ||
padding: 10, | ||
paddingRight: 24, | ||
fontWeight: 600, | ||
'&:hover': { borderColor: 'var(--invokeai-colors-base-700)' }, | ||
'&:focus': { | ||
borderColor: 'var(--invokeai-colors-accent-600)', | ||
}, | ||
'&:focus-within': { | ||
borderColor: 'var(--invokeai-colors-accent-600)', | ||
}, | ||
}, | ||
value: { | ||
backgroundColor: 'var(--invokeai-colors-base-800)', | ||
color: 'var(--invokeai-colors-base-100)', | ||
button: { | ||
color: 'var(--invokeai-colors-base-100)', | ||
}, | ||
'&:hover': { | ||
backgroundColor: 'var(--invokeai-colors-base-700)', | ||
cursor: 'pointer', | ||
}, | ||
}, | ||
dropdown: { | ||
backgroundColor: 'var(--invokeai-colors-base-800)', | ||
borderColor: 'var(--invokeai-colors-base-700)', | ||
}, | ||
item: { | ||
backgroundColor: 'var(--invokeai-colors-base-800)', | ||
color: 'var(--invokeai-colors-base-200)', | ||
padding: 6, | ||
'&[data-hovered]': { | ||
color: 'var(--invokeai-colors-base-100)', | ||
backgroundColor: 'var(--invokeai-colors-base-750)', | ||
}, | ||
'&[data-active]': { | ||
backgroundColor: 'var(--invokeai-colors-base-750)', | ||
'&:hover': { | ||
color: 'var(--invokeai-colors-base-100)', | ||
backgroundColor: 'var(--invokeai-colors-base-750)', | ||
}, | ||
}, | ||
'&[data-selected]': { | ||
color: 'var(--invokeai-colors-base-50)', | ||
backgroundColor: 'var(--invokeai-colors-accent-650)', | ||
fontWeight: 600, | ||
'&:hover': { | ||
backgroundColor: 'var(--invokeai-colors-accent-600)', | ||
}, | ||
}, | ||
}, | ||
rightSection: { | ||
width: 24, | ||
padding: 20, | ||
button: { | ||
color: 'var(--invokeai-colors-base-100)', | ||
}, | ||
}, | ||
})} | ||
{...rest} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default memo(IAIMantineMultiSelect); |
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
4 changes: 2 additions & 2 deletions
4
...rontend/web/src/features/parameters/components/Parameters/Core/ParamSchedulerAndModel.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
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
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
67 changes: 32 additions & 35 deletions
67
invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsSchedulers.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,47 +1,44 @@ | ||
import { | ||
Menu, | ||
MenuButton, | ||
MenuItemOption, | ||
MenuList, | ||
MenuOptionGroup, | ||
} from '@chakra-ui/react'; | ||
import { SCHEDULERS } from 'app/constants'; | ||
|
||
import { SCHEDULER_LABEL_MAP, SCHEDULER_NAMES } from 'app/constants'; | ||
import { RootState } from 'app/store/store'; | ||
|
||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; | ||
import IAIButton from 'common/components/IAIButton'; | ||
import { setSchedulers } from 'features/ui/store/uiSlice'; | ||
import { isArray } from 'lodash-es'; | ||
import IAIMantineMultiSelect from 'common/components/IAIMantineMultiSelect'; | ||
import { SchedulerParam } from 'features/parameters/store/parameterZodSchemas'; | ||
import { favoriteSchedulersChanged } from 'features/ui/store/uiSlice'; | ||
import { map } from 'lodash-es'; | ||
import { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function SettingsSchedulers() { | ||
const schedulers = useAppSelector((state: RootState) => state.ui.schedulers); | ||
const data = map(SCHEDULER_NAMES, (s) => ({ | ||
value: s, | ||
label: SCHEDULER_LABEL_MAP[s], | ||
})).sort((a, b) => a.label.localeCompare(b.label)); | ||
|
||
export default function SettingsSchedulers() { | ||
const dispatch = useAppDispatch(); | ||
const { t } = useTranslation(); | ||
|
||
const schedulerSettingsHandler = (v: string | string[]) => { | ||
if (isArray(v)) dispatch(setSchedulers(v.sort())); | ||
}; | ||
const enabledSchedulers = useAppSelector( | ||
(state: RootState) => state.ui.favoriteSchedulers | ||
); | ||
|
||
const handleChange = useCallback( | ||
(v: string[]) => { | ||
dispatch(favoriteSchedulersChanged(v as SchedulerParam[])); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
return ( | ||
<Menu closeOnSelect={false}> | ||
<MenuButton as={IAIButton}> | ||
{t('settings.availableSchedulers')} | ||
</MenuButton> | ||
<MenuList maxHeight={64} overflowY="scroll"> | ||
<MenuOptionGroup | ||
value={schedulers} | ||
type="checkbox" | ||
onChange={schedulerSettingsHandler} | ||
> | ||
{SCHEDULERS.map((scheduler) => ( | ||
<MenuItemOption key={scheduler} value={scheduler}> | ||
{scheduler} | ||
</MenuItemOption> | ||
))} | ||
</MenuOptionGroup> | ||
</MenuList> | ||
</Menu> | ||
<IAIMantineMultiSelect | ||
label={t('settings.favoriteSchedulers')} | ||
value={enabledSchedulers} | ||
data={data} | ||
onChange={handleChange} | ||
clearable | ||
searchable | ||
maxSelectedValues={99} | ||
placeholder={t('settings.favoriteSchedulersPlaceholder')} | ||
/> | ||
); | ||
} |
Oops, something went wrong.