From ff628c0ef12ddfbef241feea810fb463540b60b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Jesus?= Date: Tue, 25 Mar 2025 16:42:21 +0000 Subject: [PATCH] Added tool options --- src/pages/tools/json/json-to-xml/index.tsx | 110 +++++++++++---------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/src/pages/tools/json/json-to-xml/index.tsx b/src/pages/tools/json/json-to-xml/index.tsx index 3439e54..17be45b 100644 --- a/src/pages/tools/json/json-to-xml/index.tsx +++ b/src/pages/tools/json/json-to-xml/index.tsx @@ -5,46 +5,55 @@ import ToolTextResult from '@components/result/ToolTextResult'; // import { convertJsonToXml } from './service'; import { CardExampleType } from '@components/examples/ToolExamples'; import { ToolComponentProps } from '@tools/defineTool'; -import { Box } from '@mui/material'; +import { Box, Radio } from '@mui/material'; import CheckboxWithDesc from '@components/options/CheckboxWithDesc'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; +import RadioWithTextField from '@components/options/RadioWithTextField'; +import SimpleRadio from '@components/options/SimpleRadio'; type InitialValuesType = { - delimiter: string; - quote: string; - comment: string; - useHeaders: boolean; - skipEmptyLines: boolean; + indentationType: 'space' | 'tab' | 'none'; + addMetaTag: boolean; }; const initialValues: InitialValuesType = { - delimiter: ',', - quote: '"', - comment: '#', - useHeaders: true, - skipEmptyLines: true + indentationType: 'space', + addMetaTag: false }; const exampleCards: CardExampleType[] = [ { - title: 'Basic CSV to XML', - description: 'Convert a simple CSV file into an XML format.', - sampleText: 'name,age,city\nJohn,30,New York\nAlice,25,London', + title: 'Basic JSON to XML', + description: 'Convert a simple JSON object into an XML format.', + sampleText: ` +{ + "users": [ + { + "name": "John", + "age": 30, + "city": "New York" + }, + { + "name": "Alice", + "age": 25, + "city": "London" + } + ] +}`, sampleResult: ` - - John - 30 - New York - - - Alice - 25 - London - +\t +\t\tJohn +\t\t30 +\t\tNew York +\t +\t +\t\tAlice +\t\t25 +\t\tLondon +\t `, sampleOptions: { - ...initialValues, - useHeaders: true + ...initialValues } } ]; @@ -82,42 +91,43 @@ export default function JsonToXml({ title }: ToolComponentProps) { resultComponent={} getGroups={({ values, updateField }) => [ { - title: 'Input Json Format', + title: 'Output XML Indentation', component: ( - updateField('delimiter', val)} + updateField('indentationType', 'space')} /> - updateField('quote', val)} - value={values.quote} + updateField('indentationType', 'tab')} /> - updateField('comment', val)} + updateField('indentationType', 'none')} /> ) }, { - title: 'Conversion Options', + title: 'XML Meta Information', component: ( updateField('useHeaders', value)} - title="Use Headers" - description="First row is treated as column headers" - /> - updateField('skipEmptyLines', value)} - title="Skip Empty Lines" - description="Don't process empty lines in the CSV" + checked={values.addMetaTag} + onChange={(value) => updateField('addMetaTag', value)} + title="Add an XML Meta Tag" + description="Add a meta tag at the beginning of the XML output." /> )