|
| 1 | +import { Select } from 'antd'; |
| 2 | +import { memo, useCallback, useMemo } from 'react'; |
| 3 | + |
| 4 | +import { useAgentStore } from '@/store/agent'; |
| 5 | +import { agentChatConfigSelectors } from '@/store/agent/selectors'; |
| 6 | + |
| 7 | +const NANO_BANANA_ASPECT_RATIOS = [ |
| 8 | + '1:1', // 1024x1024 / 2048x2048 / 4096x4096 |
| 9 | + '2:3', // 848x1264 / 1696x2528 / 3392x5056 |
| 10 | + '3:2', // 1264x848 / 2528x1696 / 5056x3392 |
| 11 | + '3:4', // 896x1200 / 1792x2400 / 3584x4800 |
| 12 | + '4:3', // 1200x896 / 2400x1792 / 4800x3584 |
| 13 | + '4:5', // 928x1152 / 1856x2304 / 3712x4608 |
| 14 | + '5:4', // 1152x928 / 2304x1856 / 4608x3712 |
| 15 | + '9:16', // 768x1376 / 1536x2752 / 3072x5504 |
| 16 | + '16:9', // 1376x768 / 2752x1536 / 5504x3072 |
| 17 | + '21:9', // 1584x672 / 3168x1344 / 6336x2688 |
| 18 | +]; |
| 19 | + |
| 20 | +const ImageAspectRatioSelect = memo(() => { |
| 21 | + const [config, updateAgentChatConfig] = useAgentStore((s) => [ |
| 22 | + agentChatConfigSelectors.currentChatConfig(s), |
| 23 | + s.updateAgentChatConfig, |
| 24 | + ]); |
| 25 | + |
| 26 | + const imageAspectRatio = config.imageAspectRatio || '1:1'; |
| 27 | + |
| 28 | + const options = useMemo( |
| 29 | + () => |
| 30 | + NANO_BANANA_ASPECT_RATIOS.map((ratio) => ({ |
| 31 | + label: ratio, |
| 32 | + value: ratio, |
| 33 | + })), |
| 34 | + [], |
| 35 | + ); |
| 36 | + |
| 37 | + const updateAspectRatio = useCallback( |
| 38 | + (value: string) => { |
| 39 | + updateAgentChatConfig({ imageAspectRatio: value }); |
| 40 | + }, |
| 41 | + [updateAgentChatConfig], |
| 42 | + ); |
| 43 | + |
| 44 | + return ( |
| 45 | + <Select |
| 46 | + onChange={updateAspectRatio} |
| 47 | + options={options} |
| 48 | + style={{ height: 32, marginRight: 10, width: 75 }} |
| 49 | + value={imageAspectRatio} |
| 50 | + /> |
| 51 | + ); |
| 52 | +}); |
| 53 | + |
| 54 | +export default ImageAspectRatioSelect; |
0 commit comments