Skip to content

Commit 57224ba

Browse files
committed
テキストサイズを追加、フォームラベルのスタイルを調整
1 parent edc74eb commit 57224ba

4 files changed

Lines changed: 36 additions & 15 deletions

File tree

src/app/image_generator/ImageGenerator.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { PRESET_SIZE_OPTIONS } from '@/app/image_generator/presetSize';
88
import {
99
useImageGenerator,
1010
DEFAULT_VALUES,
11-
SIZE_LIMIT,
11+
IMG_SIZE_LIMIT,
12+
TEXT_SIZE_LIMIT,
1213
UNSPLASH_FILE_TYPES,
1314
PLACEHOLD_FILE_TYPES,
1415
} from '@/app/image_generator/useImageGenerator';
@@ -92,8 +93,8 @@ const CommonForm: FC<{ control: any }> = ({ control }) => {
9293
<InputNumber
9394
{...field}
9495
style={{ width }}
95-
min={SIZE_LIMIT.min}
96-
max={SIZE_LIMIT.max}
96+
min={IMG_SIZE_LIMIT.min}
97+
max={IMG_SIZE_LIMIT.max}
9798
defaultValue={DEFAULT_VALUES.wight}
9899
/>
99100
)}
@@ -107,8 +108,8 @@ const CommonForm: FC<{ control: any }> = ({ control }) => {
107108
<InputNumber
108109
{...field}
109110
style={{ width }}
110-
min={SIZE_LIMIT.min}
111-
max={SIZE_LIMIT.max}
111+
min={IMG_SIZE_LIMIT.min}
112+
max={IMG_SIZE_LIMIT.max}
112113
defaultValue={DEFAULT_VALUES.height}
113114
/>
114115
)}
@@ -179,11 +180,24 @@ const PlaceholdTab: FC<{ control: any }> = ({ control }) => {
179180
/>
180181
</FormRow>
181182
<FormRow label="テキスト">
183+
<Controller
184+
render={({ field: { ref, ...field } }) => <Input {...field} style={{ width }} />}
185+
name="text"
186+
control={control}
187+
/>
188+
</FormRow>
189+
<FormRow label="テキストサイズ">
182190
<Controller
183191
render={({ field: { ref, ...field } }) => (
184-
<Input {...field} style={{ width }} noResize="none" />
192+
<InputNumber
193+
{...field}
194+
style={{ width }}
195+
min={TEXT_SIZE_LIMIT.min}
196+
max={TEXT_SIZE_LIMIT.max}
197+
defaultValue={DEFAULT_VALUES.textSize}
198+
/>
185199
)}
186-
name="text"
200+
name="textSize"
187201
control={control}
188202
/>
189203
</FormRow>

src/app/image_generator/useImageGenerator.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ImageGeneratorForm = {
1212
textColor: Color | undefined;
1313
tab: 'unsplash' | 'placehold';
1414
text: string;
15+
textSize: number | undefined;
1516
};
1617

1718
export const DEFAULT_VALUES: ImageGeneratorForm = {
@@ -22,13 +23,19 @@ export const DEFAULT_VALUES: ImageGeneratorForm = {
2223
textColor: new ColorFactory('1668dc00'),
2324
tab: 'unsplash',
2425
text: '',
26+
textSize: undefined,
2527
};
2628

27-
export const SIZE_LIMIT = {
29+
export const IMG_SIZE_LIMIT = {
2830
min: 1,
2931
max: 5000,
3032
};
3133

34+
export const TEXT_SIZE_LIMIT = {
35+
min: 1,
36+
max: 999,
37+
};
38+
3239
export const UNSPLASH_FILE_TYPES = [
3340
{
3441
label: 'JPG',
@@ -114,13 +121,14 @@ const createUnsplashURL = (values: ImageGeneratorForm) => {
114121

115122
// https://placehold.jp/
116123
const createPlaceholdURL = (values: ImageGeneratorForm) => {
117-
const { wight, height, type, textColor, bgColor, text } = values;
124+
const { wight, height, type, textColor, bgColor, text, textSize } = values;
125+
const textSizePath = textSize ? '' : `/${textSize}`;
118126
const bgColorPath = bgColor ? `/${bgColor.toHex()}` : '';
119127
const textColorPath = textColor ? `/${textColor.toHex()}` : '';
120128

121129
const params = new URLSearchParams({
122130
text,
123131
});
124132

125-
return `https://placehold.jp${bgColorPath}${textColorPath}/${wight}x${height}.${type}?${params}`;
133+
return `https://placehold.jp${textSizePath}${bgColorPath}${textColorPath}/${wight}x${height}.${type}?${params}`;
126134
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import styled from '@emotion/styled';
22
import { Form } from 'rsuite';
33

4-
export const ConfigLabel = styled(Form.ControlLabel)`
4+
export const FormLabel = styled(Form.ControlLabel)`
55
padding-left: 6px !important;
6-
width: 90px !important;
7-
line-height: 12px !important;
86
text-align: left !important;
7+
line-height: 12px !important;
98
`;

src/components/common/Form/FormRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC } from 'react';
22
import { Form, Grid, Row, Col } from 'rsuite';
3-
import { ConfigLabel } from '@/components/common/Form/ConfigForm';
3+
import { FormLabel } from '@/components/common/Form/FormLabel';
44

55
type Props = {
66
label: string;
@@ -13,7 +13,7 @@ export const FormRow: FC<Props> = ({ label, children, ...rest }) => {
1313
<Grid {...rest} fluid>
1414
<Row>
1515
<Col xl={4} md={8} sm={12} xs={24}>
16-
<ConfigLabel>{label}</ConfigLabel>
16+
<FormLabel>{label}</FormLabel>
1717
</Col>
1818
<Col xl={20} md={16} sm={12} xs={24}>
1919
{children}

0 commit comments

Comments
 (0)