Skip to content

Commit eb8a7bf

Browse files
committed
Fix: 削除ボタンの追加
1 parent 2bf9e62 commit eb8a7bf

File tree

2 files changed

+56
-48
lines changed

2 files changed

+56
-48
lines changed
Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client';
22
import { Space } from 'antd';
33
import React, { FC } from 'react';
4-
import { Controller } from 'react-hook-form';
4+
import { Controller , FormProvider } from 'react-hook-form';
55
import { Col, Grid, Panel, PanelGroup, Row, Form } from 'rsuite';
66
import { AppLayout } from '@/Layout/App';
77
import { useNumberComma } from '@/app/number_comma/useNumberComma';
88
import { CopyButton } from '@/components/common/CopyButton';
9+
import { ClearButton } from '@/components/common/Form/ClearButton';
910
import { FormRow } from '@/components/common/Form/FormRow';
1011
import { Input } from '@/components/common/Form/Input';
1112
import { Select } from '@/components/common/Form/Select';
@@ -14,53 +15,59 @@ import { PanelHeader } from '@/components/common/PanelHeader';
1415

1516
export const NumberComma: FC = () => {
1617
const title = '数値区切り';
17-
const { control, output, SEPARATOR_LIST, DEFAULT_VALUES } = useNumberComma();
18+
const { methods, output, SEPARATOR_LIST, DEFAULT_VALUES } = useNumberComma();
1819

1920
return (
20-
<AppLayout>
21-
<Grid fluid>
22-
<PageTitle title={title} />
23-
<Row gutter={5}>
24-
<Col xs={24} md={12}>
25-
<PanelGroup bordered>
26-
<Panel header={<PanelHeader title="区切りたい数値" />}>
27-
<Controller
28-
render={({ field }) => <Input noResize="none" {...field} />}
29-
name="input"
30-
control={control}
31-
defaultValue={DEFAULT_VALUES.input}
32-
/>
21+
<FormProvider {...methods}>
22+
<AppLayout>
23+
<Grid fluid>
24+
<PageTitle title={title} />
25+
<Row gutter={5}>
26+
<Col xs={24} md={12}>
27+
<PanelGroup bordered>
28+
<Panel
29+
header={
30+
<PanelHeader title="区切りたい数値" right={<ClearButton name="input" />} />
31+
}
32+
>
33+
<Controller
34+
render={({ field }) => <Input noResize="none" {...field} />}
35+
name="input"
36+
control={methods.control}
37+
defaultValue={DEFAULT_VALUES.input}
38+
/>
39+
</Panel>
40+
<Panel bordered header={<PanelHeader title="設定" />}>
41+
<Form fluid layout="horizontal">
42+
<FormRow label="区切り文字">
43+
<Controller
44+
render={({ field }) => (
45+
<Select
46+
style={{ width: 250 }}
47+
options={SEPARATOR_LIST}
48+
defaultValue={DEFAULT_VALUES.separator}
49+
{...field}
50+
/>
51+
)}
52+
name="separator"
53+
control={methods.control}
54+
/>
55+
</FormRow>
56+
</Form>
57+
</Panel>
58+
</PanelGroup>
59+
</Col>
60+
<Col xs={24} md={12}>
61+
<Panel bordered header={<PanelHeader title="区切った数値" />}>
62+
<Space.Compact block>
63+
<Input noResize="none" readOnly value={output} />
64+
<CopyButton copyText={output} />
65+
</Space.Compact>
3366
</Panel>
34-
<Panel bordered header={<PanelHeader title="設定" />}>
35-
<Form fluid layout="horizontal">
36-
<FormRow label="区切り文字">
37-
<Controller
38-
render={({ field }) => (
39-
<Select
40-
style={{ width: 250 }}
41-
options={SEPARATOR_LIST}
42-
defaultValue={DEFAULT_VALUES.separator}
43-
{...field}
44-
/>
45-
)}
46-
name="separator"
47-
control={control}
48-
/>
49-
</FormRow>
50-
</Form>
51-
</Panel>
52-
</PanelGroup>
53-
</Col>
54-
<Col xs={24} md={12}>
55-
<Panel bordered header={<PanelHeader title="区切った数値" />}>
56-
<Space.Compact block>
57-
<Input noResize="none" readOnly value={output} />
58-
<CopyButton copyText={output} />
59-
</Space.Compact>
60-
</Panel>
61-
</Col>
62-
</Row>
63-
</Grid>
64-
</AppLayout>
67+
</Col>
68+
</Row>
69+
</Grid>
70+
</AppLayout>
71+
</FormProvider>
6572
);
6673
};

src/app/number_comma/useNumberComma.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ const DEFAULT_VALUES: NumberCommaForm = {
2222
};
2323

2424
export const useNumberComma = () => {
25-
const { control, watch } = useCustomForm<NumberCommaForm>({
25+
const methods = useCustomForm<NumberCommaForm>({
2626
defaultValues: DEFAULT_VALUES,
2727
});
28+
const { control, watch } = methods;
2829

2930
const input = watch('input', DEFAULT_VALUES.input);
3031
const separator = watch('separator', DEFAULT_VALUES.separator);
3132
const output = comma(input, separator);
3233

3334
return {
34-
control,
35+
methods,
3536
output,
3637
SEPARATOR_LIST,
3738
DEFAULT_VALUES,

0 commit comments

Comments
 (0)