Skip to content

Commit 07bcf3c

Browse files
psychedeliciousmaryhipp
authored andcommitted
feat(ui): port bbox select to native select
1 parent 8ed5585 commit 07bcf3c

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

invokeai/frontend/web/src/features/controlLayers/store/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export type StagingAreaImage = {
387387
offsetY: number;
388388
};
389389

390-
const zAspectRatioID = z.enum(['Free', '16:9', '3:2', '4:3', '1:1', '3:4', '2:3', '9:16']);
390+
export const zAspectRatioID = z.enum(['Free', '16:9', '3:2', '4:3', '1:1', '3:4', '2:3', '9:16']);
391391
export type AspectRatioID = z.infer<typeof zAspectRatioID>;
392392
export const isAspectRatioID = (v: string): v is AspectRatioID => zAspectRatioID.safeParse(v).success;
393393

invokeai/frontend/web/src/features/parameters/components/Bbox/BboxAspectRatioSelect.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
import type { ComboboxOption, SystemStyleObject } from '@invoke-ai/ui-library';
2-
import { Combobox, FormControl, FormLabel } from '@invoke-ai/ui-library';
1+
import { FormControl, FormLabel, Select } from '@invoke-ai/ui-library';
32
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
4-
import type { SingleValue } from 'chakra-react-select';
53
import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover';
64
import { bboxAspectRatioIdChanged } from 'features/controlLayers/store/canvasSlice';
75
import { selectIsStaging } from 'features/controlLayers/store/canvasStagingAreaSlice';
86
import { selectAspectRatioID } from 'features/controlLayers/store/selectors';
9-
import { isAspectRatioID } from 'features/controlLayers/store/types';
10-
import { ASPECT_RATIO_OPTIONS } from 'features/parameters/components/Bbox/constants';
11-
import { memo, useCallback, useMemo } from 'react';
7+
import { isAspectRatioID, zAspectRatioID } from 'features/controlLayers/store/types';
8+
import type { ChangeEventHandler } from 'react';
9+
import { memo, useCallback } from 'react';
1210
import { useTranslation } from 'react-i18next';
11+
import { PiCaretDownBold } from 'react-icons/pi';
1312

1413
export const BboxAspectRatioSelect = memo(() => {
1514
const { t } = useTranslation();
1615
const dispatch = useAppDispatch();
1716
const id = useAppSelector(selectAspectRatioID);
1817
const isStaging = useAppSelector(selectIsStaging);
1918

20-
const onChange = useCallback(
21-
(v: SingleValue<ComboboxOption>) => {
22-
if (!v || !isAspectRatioID(v.value)) {
19+
const onChange = useCallback<ChangeEventHandler<HTMLSelectElement>>(
20+
(e) => {
21+
if (!isAspectRatioID(e.target.value)) {
2322
return;
2423
}
25-
dispatch(bboxAspectRatioIdChanged({ id: v.value }));
24+
dispatch(bboxAspectRatioIdChanged({ id: e.target.value }));
2625
},
2726
[dispatch]
2827
);
2928

30-
const value = useMemo(() => ASPECT_RATIO_OPTIONS.filter((o) => o.value === id)[0], [id]);
31-
3229
return (
3330
<FormControl isDisabled={isStaging}>
3431
<InformationalPopover feature="paramAspect">
3532
<FormLabel>{t('parameters.aspect')}</FormLabel>
3633
</InformationalPopover>
37-
<Combobox value={value} onChange={onChange} options={ASPECT_RATIO_OPTIONS} sx={selectStyles} />
34+
<Select size="sm" value={id} onChange={onChange} cursor="pointer" iconSize="0.75rem" icon={<PiCaretDownBold />}>
35+
{zAspectRatioID.options.map((ratio) => (
36+
<option key={ratio} value={ratio}>
37+
{ratio}
38+
</option>
39+
))}
40+
</Select>
3841
</FormControl>
3942
);
4043
});
4144

4245
BboxAspectRatioSelect.displayName = 'BboxAspectRatioSelect';
43-
44-
const selectStyles: SystemStyleObject = { minW: 24 };

invokeai/frontend/web/src/features/parameters/components/Bbox/constants.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
import type { ComboboxOption } from '@invoke-ai/ui-library';
21
import type { AspectRatioID } from 'features/controlLayers/store/types';
32

4-
export const ASPECT_RATIO_OPTIONS: ComboboxOption[] = [
5-
{ label: 'Free' as const, value: 'Free' },
6-
{ label: '16:9' as const, value: '16:9' },
7-
{ label: '3:2' as const, value: '3:2' },
8-
{ label: '4:3' as const, value: '4:3' },
9-
{ label: '1:1' as const, value: '1:1' },
10-
{ label: '3:4' as const, value: '3:4' },
11-
{ label: '2:3' as const, value: '2:3' },
12-
{ label: '9:16' as const, value: '9:16' },
13-
] as const;
14-
153
export const ASPECT_RATIO_MAP: Record<Exclude<AspectRatioID, 'Free'>, { ratio: number; inverseID: AspectRatioID }> = {
164
'16:9': { ratio: 16 / 9, inverseID: '9:16' },
175
'3:2': { ratio: 3 / 2, inverseID: '2:3' },

0 commit comments

Comments
 (0)