|
1 | 1 | 'use client'; |
2 | | -import CopyIcon from '@rsuite/icons/Copy'; |
3 | 2 | import { Space } from 'antd'; |
4 | | -import { toASCII, encode } from 'punycode/'; |
5 | 3 | import React, { FC } from 'react'; |
6 | 4 | import { Controller, FormProvider } from 'react-hook-form'; |
7 | | -import { Col, Grid, InputGroup, Panel, PanelGroup, Row, ButtonToolbar } from 'rsuite'; |
| 5 | +import { Col, Grid, Panel, PanelGroup, Row, ButtonToolbar } from 'rsuite'; |
8 | 6 | import { AppLayout } from '@/Layout/App'; |
| 7 | +import { usePunycode } from '@/app/punycode/usePunycode'; |
9 | 8 | import { Editor } from '@/components/common/Editor'; |
10 | 9 | import { ClearButton } from '@/components/common/Form/ClearButton'; |
11 | 10 | import { CopyButton } from '@/components/common/Form/CopyButton'; |
12 | | -import { Input } from '@/components/common/Form/Input'; |
13 | | -import { useCustomForm } from '@/components/common/Form/useCustomForm'; |
| 11 | +import { TextArea } from '@/components/common/Form/TextArea'; |
14 | 12 | import { PageTitle } from '@/components/common/PageTitle'; |
15 | 13 | import { PanelHeader } from '@/components/common/PanelHeader'; |
16 | | -import { useCopy } from '@/hooks/useCopy'; |
17 | | - |
18 | | -type PunycodeForm = { |
19 | | - input: string; |
20 | | -}; |
21 | 14 |
|
22 | 15 | export const Punycode: FC = () => { |
23 | 16 | const title = 'punycode変換(日本語ドメイン変換)'; |
24 | | - const methods = useCustomForm<PunycodeForm>({ |
25 | | - defaultValues: { |
26 | | - input: '', |
27 | | - }, |
28 | | - }); |
29 | | - const { control, watch } = methods; |
30 | | - const { copy } = useCopy(); |
31 | | - |
32 | | - const converted_ascii = toASCII(watch('input', '')); |
33 | | - const converted_punycode = encode(watch('input', '')); |
| 17 | + const INPUT_ROWS = 5; |
| 18 | + const { methods, converted_ascii, converted_punycode } = usePunycode(); |
| 19 | + const { control } = methods; |
34 | 20 |
|
35 | 21 | return ( |
36 | 22 | <FormProvider {...methods}> |
@@ -61,16 +47,28 @@ export const Punycode: FC = () => { |
61 | 47 | </Col> |
62 | 48 | <Col xs={24} md={12}> |
63 | 49 | <PanelGroup bordered> |
64 | | - <Panel header={<PanelHeader title="ドメイン変換" />}> |
| 50 | + <Panel |
| 51 | + header={ |
| 52 | + <PanelHeader |
| 53 | + title="ドメイン変換" |
| 54 | + right={<CopyButton size="small" copyText={converted_punycode} />} |
| 55 | + /> |
| 56 | + } |
| 57 | + > |
65 | 58 | <Space.Compact block> |
66 | | - <Input readOnly value={converted_ascii} /> |
67 | | - <CopyButton copyText={converted_punycode} /> |
| 59 | + <TextArea rows={INPUT_ROWS} readOnly value={converted_ascii} /> |
68 | 60 | </Space.Compact> |
69 | 61 | </Panel> |
70 | | - <Panel header={<PanelHeader title="punycode変換" />}> |
| 62 | + <Panel |
| 63 | + header={ |
| 64 | + <PanelHeader |
| 65 | + title="punycode変換" |
| 66 | + right={<CopyButton size="small" copyText={converted_punycode} />} |
| 67 | + /> |
| 68 | + } |
| 69 | + > |
71 | 70 | <Space.Compact block> |
72 | | - <Input readOnly value={converted_punycode} /> |
73 | | - <CopyButton copyText={converted_punycode} /> |
| 71 | + <TextArea rows={INPUT_ROWS} readOnly value={converted_punycode} /> |
74 | 72 | </Space.Compact> |
75 | 73 | </Panel> |
76 | 74 | </PanelGroup> |
|
0 commit comments