Skip to content

Commit 9c5ef44

Browse files
committed
クリアボタンを追加
1 parent 2610f5e commit 9c5ef44

5 files changed

Lines changed: 42 additions & 25 deletions

File tree

src/app/dummy_generator/DummyGenerator.tsx

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use client';
2-
import { DeleteOutlined } from '@ant-design/icons';
3-
import PlusIcon from '@rsuite/icons/legacy/Plus';
4-
import { Table, Form, Popconfirm, Button } from 'antd';
2+
import { DeleteOutlined, PlusOutlined } from '@ant-design/icons';
3+
import { Table, Form, Popconfirm, Button, Space } from 'antd';
54
import type { DefaultOptionType } from 'antd/es/select';
65
import type { ColumnsType } from 'antd/es/table';
76
import React, { FC } from 'react';
87
import { FormProvider, Controller } from 'react-hook-form';
98
import type { Control, UseFormWatch } from 'react-hook-form/dist/types/form';
10-
import { Grid, Row, Col, PanelGroup, Panel, IconButton } from 'rsuite';
9+
import { Grid, Row, Col, PanelGroup, Panel } from 'rsuite';
1110
import { AppLayout } from '@/Layout/App';
12-
import { dataTypeOptions } from '@/app/dummy_generator/facker';
13-
import type { DataType } from '@/app/dummy_generator/facker';
11+
import { dataTypeOptions } from '@/app/dummy_generator/options';
12+
import type { DataType } from '@/app/dummy_generator/options';
1413
import { AddressOptions } from '@/app/dummy_generator/options/AddressOptions';
1514
import { NameOptions } from '@/app/dummy_generator/options/NameOptions';
1615
import { useDummy, RecordType, DummyForm } from '@/app/dummy_generator/useDummy';
@@ -22,7 +21,7 @@ import { PanelHeader } from '@/components/common/PanelHeader';
2221

2322
export const DummyGenerator: FC = () => {
2423
const title = 'ダミー情報の生成';
25-
const { methods, fields, output, onClickAdd, onClickDelete } = useDummy();
24+
const { methods, fields, output, onClickAdd, onClickClear, onClickDelete } = useDummy();
2625
const { watch, control } = methods;
2726

2827
const source = fields.map((value, index) => {
@@ -64,25 +63,41 @@ export const DummyGenerator: FC = () => {
6463
<Col md={12} xs={24}>
6564
<Form layout="horizontal">
6665
<PanelGroup bordered>
67-
<Panel bordered header={<PanelHeader title="管理" />}>
68-
<IconButton
69-
icon={<PlusIcon />}
70-
placement="right"
71-
size="xs"
72-
onClick={onClickAdd}
73-
>
74-
追加
75-
</IconButton>
76-
</Panel>
77-
<Panel bordered header={<PanelHeader title="設定" />}>
78-
<Table columns={columns} dataSource={source} />
66+
<Panel bordered header={<PanelHeader title="管理" />}></Panel>
67+
<Panel
68+
bordered
69+
header={
70+
<PanelHeader
71+
title="設定"
72+
right={
73+
<Space.Compact block>
74+
<Button icon={<PlusOutlined />} size="small" onClick={onClickAdd}>
75+
追加
76+
</Button>
77+
<Popconfirm title="全て削除していいですか?" onConfirm={onClickClear}>
78+
<Button icon={<DeleteOutlined />} danger size="small">
79+
クリア
80+
</Button>
81+
</Popconfirm>
82+
</Space.Compact>
83+
}
84+
/>
85+
}
86+
>
87+
<Table
88+
pagination={{
89+
pageSize: 20,
90+
}}
91+
columns={columns}
92+
dataSource={source}
93+
/>
7994
</Panel>
8095
</PanelGroup>
8196
</Form>
8297
</Col>
8398
<Col md={12} xs={24}>
8499
<Panel bordered header={<PanelHeader title="テストデータ" />}>
85-
<TextArea value={output} readOnly rows={20} />
100+
<TextArea value={output} readOnly rows={30} />
86101
</Panel>
87102
</Col>
88103
</Row>
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { faker } from '@faker-js/faker/locale/ja';
2-
import type { DefaultOptionType } from 'antd/es/select';
3-
41
export const dataTypeOptions = [
52
{
63
label: '個人情報',

src/app/dummy_generator/options/AddressOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Radio, Form } from 'antd';
22
import React, { FC } from 'react';
33
import { Controller } from 'react-hook-form';
44
import type { Control } from 'react-hook-form/dist/types/form';
5-
import { addressOptions } from '@/app/dummy_generator/facker';
5+
import { addressOptions } from '@/app/dummy_generator/options';
66
import { DummyForm } from '@/app/dummy_generator/useDummy';
77

88
type Props<TFieldValues> = {

src/app/dummy_generator/options/NameOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Radio, Form } from 'antd';
22
import React, { FC } from 'react';
33
import { Controller } from 'react-hook-form';
44
import type { Control } from 'react-hook-form/dist/types/form';
5-
import { nameOptions, nameDataOptions } from '@/app/dummy_generator/facker';
5+
import { nameOptions, nameDataOptions } from '@/app/dummy_generator/options';
66
import { DummyForm } from '@/app/dummy_generator/useDummy';
77

88
type Props<TFieldValues> = {

src/app/dummy_generator/useDummy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const useDummy = () => {
2828
append({ dataType: '' });
2929
}, [append]);
3030

31+
const onClickClear = useCallback(() => {
32+
remove();
33+
}, [remove]);
34+
3135
const onClickDelete = useCallback(
3236
(index: number) => () => {
3337
remove(index);
@@ -42,6 +46,7 @@ export const useDummy = () => {
4246
fields,
4347
output,
4448
onClickAdd,
49+
onClickClear,
4550
onClickDelete,
4651
};
4752
};

0 commit comments

Comments
 (0)