|
| 1 | +'use client'; |
| 2 | +import { Button, Tabs } from 'antd'; |
| 3 | +import React, { FC } from 'react'; |
| 4 | +import { FormProvider, Controller } from 'react-hook-form'; |
| 5 | +import { Grid, Row, Col, PanelGroup, Panel, Form } from 'rsuite'; |
| 6 | +import { AppLayout } from '@/Layout/App'; |
| 7 | +import { PRESET_SIZE_OPTIONS } from '@/app/image_generator/presetSize'; |
| 8 | +import { |
| 9 | + useImageGenerator, |
| 10 | + DEFAULT_VALUES, |
| 11 | + SIZE_LIMIT, |
| 12 | + UNSPLASH_FILE_TYPES, |
| 13 | + PLACEHOLD_FILE_TYPES, |
| 14 | +} from '@/app/image_generator/useImageGenerator'; |
| 15 | +import { FormRow } from '@/components/common/Form/FormRow'; |
| 16 | +import { InputNumber } from '@/components/common/Form/InputNumber'; |
| 17 | +import { Select } from '@/components/common/Form/Select'; |
| 18 | +import { PageTitle } from '@/components/common/PageTitle'; |
| 19 | +import { PanelHeader } from '@/components/common/PanelHeader'; |
| 20 | + |
| 21 | +const width = 250; |
| 22 | + |
| 23 | +export const ImageGenerator: FC = () => { |
| 24 | + const title = '画像生成'; |
| 25 | + const { methods, src, onClickGenerate, onSelectPreset, onChangeTab } = useImageGenerator(); |
| 26 | + const { control } = methods; |
| 27 | + |
| 28 | + return ( |
| 29 | + <FormProvider {...methods}> |
| 30 | + <AppLayout> |
| 31 | + <Grid fluid> |
| 32 | + <PageTitle title={title} /> |
| 33 | + <Row gutter={5}> |
| 34 | + <Col xs={24} md={12}> |
| 35 | + <Form fluid layout="horizontal"> |
| 36 | + <PanelGroup bordered> |
| 37 | + <Panel bordered header={<PanelHeader title="設定" />}> |
| 38 | + <Tabs |
| 39 | + defaultActiveKey="Unsplash" |
| 40 | + onChange={onChangeTab} |
| 41 | + items={[ |
| 42 | + { |
| 43 | + label: 'Unsplash', |
| 44 | + key: 'unsplash', |
| 45 | + children: <UnsplashTab control={control} />, |
| 46 | + }, |
| 47 | + { |
| 48 | + label: 'Placehold', |
| 49 | + key: 'placehold', |
| 50 | + children: <PlaceholdTab control={control} />, |
| 51 | + }, |
| 52 | + ]} |
| 53 | + /> |
| 54 | + </Panel> |
| 55 | + <Panel bordered header={<PanelHeader title="プリセット" />}> |
| 56 | + <FormRow label="サイズ"> |
| 57 | + <Select |
| 58 | + style={{ width: 250 }} |
| 59 | + options={PRESET_SIZE_OPTIONS} |
| 60 | + onSelect={onSelectPreset} |
| 61 | + /> |
| 62 | + </FormRow> |
| 63 | + <Button type="primary" onClick={onClickGenerate}> |
| 64 | + 生成 |
| 65 | + </Button> |
| 66 | + </Panel> |
| 67 | + </PanelGroup> |
| 68 | + </Form> |
| 69 | + </Col> |
| 70 | + <Col xs={24} md={12}> |
| 71 | + <Panel bordered header={<PanelHeader title="生成画像" />}> |
| 72 | + <img src={src} width="100%" loading="lazy" alt="生成画像" /> |
| 73 | + </Panel> |
| 74 | + </Col> |
| 75 | + </Row> |
| 76 | + </Grid> |
| 77 | + </AppLayout> |
| 78 | + </FormProvider> |
| 79 | + ); |
| 80 | +}; |
| 81 | + |
| 82 | +const CommonForm: FC<{ control: any }> = ({ control }) => { |
| 83 | + return ( |
| 84 | + <> |
| 85 | + <FormRow label="高さ"> |
| 86 | + <Controller |
| 87 | + render={({ field }) => ( |
| 88 | + <InputNumber {...field} style={{ width }} min={SIZE_LIMIT.min} max={SIZE_LIMIT.max} /> |
| 89 | + )} |
| 90 | + name="height" |
| 91 | + control={control} |
| 92 | + /> |
| 93 | + </FormRow> |
| 94 | + <FormRow label="幅"> |
| 95 | + <Controller |
| 96 | + render={({ field }) => ( |
| 97 | + <InputNumber {...field} style={{ width }} min={SIZE_LIMIT.min} max={SIZE_LIMIT.max} /> |
| 98 | + )} |
| 99 | + name="wight" |
| 100 | + control={control} |
| 101 | + /> |
| 102 | + </FormRow> |
| 103 | + </> |
| 104 | + ); |
| 105 | +}; |
| 106 | + |
| 107 | +const UnsplashTab: FC<{ control: any }> = ({ control }) => { |
| 108 | + return ( |
| 109 | + <> |
| 110 | + <CommonForm control={control} /> |
| 111 | + <FormRow label="拡張子"> |
| 112 | + <Controller |
| 113 | + render={({ field }) => ( |
| 114 | + <Select |
| 115 | + {...field} |
| 116 | + style={{ width }} |
| 117 | + options={UNSPLASH_FILE_TYPES} |
| 118 | + defaultValue={DEFAULT_VALUES.type} |
| 119 | + /> |
| 120 | + )} |
| 121 | + name="type" |
| 122 | + control={control} |
| 123 | + /> |
| 124 | + </FormRow> |
| 125 | + </> |
| 126 | + ); |
| 127 | +}; |
| 128 | + |
| 129 | +const PlaceholdTab: FC<{ control: any }> = ({ control }) => { |
| 130 | + return ( |
| 131 | + <> |
| 132 | + <CommonForm control={control} /> |
| 133 | + <FormRow label="拡張子"> |
| 134 | + <Controller |
| 135 | + render={({ field }) => ( |
| 136 | + <Select |
| 137 | + {...field} |
| 138 | + style={{ width }} |
| 139 | + options={PLACEHOLD_FILE_TYPES} |
| 140 | + defaultValue={DEFAULT_VALUES.type} |
| 141 | + /> |
| 142 | + )} |
| 143 | + name="type" |
| 144 | + control={control} |
| 145 | + /> |
| 146 | + </FormRow> |
| 147 | + </> |
| 148 | + ); |
| 149 | +}; |
0 commit comments