|
| 1 | +'use client'; |
| 2 | +import React, { FC } from 'react'; |
| 3 | +import dynamic from 'next/dynamic'; |
| 4 | +import { Controller, FormProvider } from 'react-hook-form'; |
| 5 | +import { Col, Grid, Panel, PanelGroup, Row } from 'rsuite'; |
| 6 | +import { AppLayout } from '@/Layout/App'; |
| 7 | +import { useJsonView } from '@/app/json_view/useJsonView'; |
| 8 | +import { Editor, ex } from '@/components/common/Editor'; |
| 9 | +import { ClearButton } from '@/components/common/Form/ClearButton'; |
| 10 | +import { CopyButton } from '@/components/common/Form/CopyButton'; |
| 11 | +import { PageTitle } from '@/components/common/PageTitle'; |
| 12 | +import { PanelHeader } from '@/components/common/PanelHeader'; |
| 13 | +const ReactJson = dynamic(() => import('react-json-view'), { |
| 14 | + ssr: false, |
| 15 | +}); |
| 16 | + |
| 17 | +export const JsonView: FC = () => { |
| 18 | + const title = 'JSONビューアー'; |
| 19 | + const { input, methods } = useJsonView(); |
| 20 | + |
| 21 | + return ( |
| 22 | + <FormProvider {...methods}> |
| 23 | + <AppLayout> |
| 24 | + <Grid fluid> |
| 25 | + <PageTitle title={title} /> |
| 26 | + <Row gutter={5}> |
| 27 | + <Col xs={24} md={12}> |
| 28 | + <PanelGroup bordered> |
| 29 | + <Panel |
| 30 | + bordered |
| 31 | + header={<PanelHeader title="入力" right={<ClearButton name="input" />} />} |
| 32 | + > |
| 33 | + <Controller |
| 34 | + render={({ field }) => <Editor extensions={[ex.json]} {...field} />} |
| 35 | + name="input" |
| 36 | + control={methods.control} |
| 37 | + /> |
| 38 | + </Panel> |
| 39 | + </PanelGroup> |
| 40 | + </Col> |
| 41 | + <Col xs={24} md={12}> |
| 42 | + <Panel |
| 43 | + bordered |
| 44 | + header={ |
| 45 | + <PanelHeader |
| 46 | + title="JSON" |
| 47 | + right={<CopyButton size="small" copyText={JSON.stringify(input)} />} |
| 48 | + /> |
| 49 | + } |
| 50 | + > |
| 51 | + <ReactJson |
| 52 | + src={input} |
| 53 | + theme="chalk" |
| 54 | + style={{ padding: '4px', border: '1px solid #a4a9b3', borderRadius: '6px' }} |
| 55 | + /> |
| 56 | + </Panel> |
| 57 | + </Col> |
| 58 | + </Row> |
| 59 | + </Grid> |
| 60 | + </AppLayout> |
| 61 | + </FormProvider> |
| 62 | + ); |
| 63 | +}; |
0 commit comments