Skip to content

Commit d77eb1a

Browse files
committed
氏名
1 parent 41e020d commit d77eb1a

4 files changed

Lines changed: 129 additions & 30 deletions

File tree

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,62 @@
11
'use client';
22
import PlusIcon from '@rsuite/icons/legacy/Plus';
3-
import { Table } from 'antd';
3+
import { Table, Form } from 'antd';
4+
import type { DefaultOptionType } from 'antd/es/select';
45
import type { ColumnsType } from 'antd/es/table';
56
import React, { FC } from 'react';
67
import { FormProvider, Controller } from 'react-hook-form';
7-
import { Grid, Row, Col, Form, PanelGroup, Panel, IconButton } from 'rsuite';
8+
import { Grid, Row, Col, PanelGroup, Panel, IconButton } from 'rsuite';
89
import { AppLayout } from '@/Layout/App';
9-
import { useDummy, DataType } from '@/app/dummy_generator/useDummy';
10-
import { Input } from '@/components/common/Form/Input';
10+
import { dataTypeOptions } from '@/app/dummy_generator/facker';
11+
import type { DataType } from '@/app/dummy_generator/facker';
12+
import { NameOptions } from '@/app/dummy_generator/options/NameOptions';
13+
import { useDummy, RecordType } from '@/app/dummy_generator/useDummy';
14+
import { FormRow } from '@/components/common/Form/FormRow';
15+
import { Select } from '@/components/common/Form/Select';
1116
import { PageTitle } from '@/components/common/PageTitle';
1217
import { PanelHeader } from '@/components/common/PanelHeader';
1318

14-
const columns: ColumnsType<DataType> = [
19+
const columns: ColumnsType<RecordType> = [
1520
{
1621
title: 'ID',
1722
key: 'key',
1823
dataIndex: 'key',
24+
width: '5%',
1925
},
2026
{
2127
title: 'Content',
2228
key: 'content',
2329
dataIndex: 'content',
2430
},
2531
{
26-
title: 'Action',
32+
title: '削除',
2733
key: 'action',
2834
dataIndex: 'action',
35+
width: '15%',
2936
},
3037
];
3138

3239
export const DummyGenerator: FC = () => {
3340
const title = 'ダミー情報の生成';
3441
const { methods, fields, onClickAdd } = useDummy();
42+
const { watch, control } = methods;
3543

3644
const source = fields.map((value, index) => {
3745
return {
3846
key: index,
39-
content: <ConfigRow id={value.id} index={index} control={methods.control} />,
47+
content: <ConfigRow id={value.id} index={index} control={control} watch={watch} />,
4048
action: null,
4149
};
4250
});
4351

44-
// const source: DataType[] = [
45-
// {
46-
// key: 1,
47-
// content: '1',
48-
// action: 'a',
49-
// },
50-
// {
51-
// key: 2,
52-
// content: '2',
53-
// action: 'a',
54-
// }
55-
// ];
56-
5752
return (
5853
<FormProvider {...methods}>
5954
<AppLayout>
6055
<Grid fluid>
6156
<PageTitle title={title} />
6257
<Row gutter={5}>
6358
<Col md={12} xs={24}>
64-
<Form fluid layout="horizontal">
59+
<Form layout="horizontal">
6560
<PanelGroup bordered>
6661
<Panel bordered header={<PanelHeader title="管理" />}>
6762
<IconButton
@@ -93,13 +88,40 @@ const ConfigRow: FC<{
9388
id: string;
9489
index: number;
9590
control: any;
96-
}> = ({ id, index, control }) => {
91+
watch: any;
92+
}> = ({ id, index, control, watch }) => {
9793
return (
98-
<Controller
99-
key={id}
100-
name={`items.${index}.firstName`}
101-
control={control}
102-
render={({ field: { ref, ...field } }) => <Input {...field} />}
103-
/>
94+
<FormRow label="形式">
95+
<Controller
96+
key={id}
97+
name={`items.${index}.dataType`}
98+
control={control}
99+
render={({ field: { ref, ...field } }) => (
100+
<Select
101+
style={{ width: 250 }}
102+
options={dataTypeOptions as unknown as DefaultOptionType[]}
103+
defaultValue={undefined}
104+
showSearch
105+
{...field}
106+
/>
107+
)}
108+
/>
109+
<Options dataType={watch(`items.${index}.dataType`)} index={index} control={control} />
110+
</FormRow>
104111
);
105112
};
113+
114+
const Options: FC<{ dataType: DataType; index: number; control: any }> = ({
115+
dataType,
116+
index,
117+
control,
118+
}) => {
119+
switch (dataType) {
120+
case 'name': {
121+
return <NameOptions />;
122+
}
123+
default: {
124+
return null;
125+
}
126+
}
127+
};

src/app/dummy_generator/facker.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
11
import { faker } from '@faker-js/faker/locale/ja';
2+
import type { DefaultOptionType } from 'antd/es/select';
3+
4+
export const dataTypeOptions = [
5+
{
6+
label: '氏名',
7+
options: [
8+
{
9+
label: '氏名',
10+
value: 'name',
11+
},
12+
],
13+
},
14+
] as const;
15+
16+
export type DataType = (typeof dataTypeOptions)[number]['options'][number]['value'];
17+
18+
export const nameOptions = [
19+
{
20+
label: '姓名',
21+
value: 'name',
22+
},
23+
{
24+
label: '名字',
25+
value: 'lastName',
26+
},
27+
{
28+
label: '名前',
29+
value: 'firstName',
30+
},
31+
] as const;
32+
33+
export const nameDataOptions = [
34+
{
35+
label: '漢字',
36+
value: 'ja',
37+
},
38+
{
39+
label: 'カタカナ',
40+
value: 'jaKana',
41+
},
42+
{
43+
label: 'ローマ字',
44+
value: 'jaRomazi',
45+
},
46+
] as const;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Radio, Form } from 'antd';
2+
import React, { FC } from 'react';
3+
import { nameOptions, nameDataOptions } from '@/app/dummy_generator/facker';
4+
5+
export const NameOptions: FC = () => {
6+
return (
7+
<>
8+
<Form.Item style={{ marginTop: 12, marginBottom: 0 }}>
9+
<Radio.Group defaultValue={nameOptions[0].value} buttonStyle="outline">
10+
{nameOptions.map(({ label, value }) => {
11+
return (
12+
<Radio.Button key={label} value={value}>
13+
{label}
14+
</Radio.Button>
15+
);
16+
})}
17+
</Radio.Group>
18+
</Form.Item>
19+
<Form.Item style={{ marginTop: 12, marginBottom: 0 }}>
20+
<Radio.Group defaultValue={nameDataOptions[0].value} buttonStyle="outline">
21+
{nameDataOptions.map(({ label, value }) => {
22+
return (
23+
<Radio.Button key={label} value={value}>
24+
{label}
25+
</Radio.Button>
26+
);
27+
})}
28+
</Radio.Group>
29+
</Form.Item>
30+
</>
31+
);
32+
};

src/app/dummy_generator/useDummy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type DummyForm = {
88
items: any;
99
};
1010

11-
export interface DataType {
11+
export interface RecordType {
1212
key: number;
1313
content: any;
1414
action: string;
@@ -23,7 +23,7 @@ export const useDummy = () => {
2323
});
2424

2525
const onClickAdd = useCallback(() => {
26-
append({ firstName: '' });
26+
append({ dataType: '' });
2727
}, [append]);
2828

2929
console.log(methods.watch());

0 commit comments

Comments
 (0)