Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import { FormControl, FormLabel, Select } from '@invoke-ai/ui-library';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { InformationalPopover } from 'common/components/InformationalPopover/InformationalPopover';
import {
aspectRatioIdChanged,
selectAllowedAspectRatioIDs,
selectAspectRatioID,
selectAspectRatioSizes,
} from 'features/controlLayers/store/paramsSlice';
import { isAspectRatioID, zAspectRatioID } from 'features/controlLayers/store/types';
import type { ChangeEventHandler } from 'react';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { PiCaretDownBold } from 'react-icons/pi';
export const DimensionsAspectRatioSelect = memo(() => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const id = useAppSelector(selectAspectRatioID);
const allowedAspectRatios = useAppSelector(selectAllowedAspectRatioIDs);
const aspectRatioSizes = useAppSelector(selectAspectRatioSizes);
const options = allowedAspectRatios ?? zAspectRatioID.options;
const onChange = useCallback<ChangeEventHandler<HTMLSelectElement>>(
(e) => {
if (!isAspectRatioID(e.target.value)) {
return;
}
const fixedSize = aspectRatioSizes?.[e.target.value] ?? undefined;
dispatch(aspectRatioIdChanged({ id: e.target.value, fixedSize }));
},
[dispatch, aspectRatioSizes]
);
return (
<FormControl>
<InformationalPopover feature="paramAspect">
<FormLabel>{t('parameters.aspect')}</FormLabel>
</InformationalPopover>
<Select size="sm" value={id} onChange={onChange} cursor="pointer" iconSize="0.75rem" icon={<PiCaretDownBold />}>
{options.map((ratio) => (
<option key={ratio} value={ratio}>
{ratio}
</option>
))}
</Select>
</FormControl>
);
});
DimensionsAspectRatioSelect.displayName = 'DimensionsAspectRatioSelect';