import React, { useState } from 'react'; import { Box } from '@mui/material'; import ToolContent from '@components/ToolContent'; import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextResult from '@components/result/ToolTextResult'; import { stringQuoter } from './service'; import { CardExampleType } from '@components/examples/ToolExamples'; import { ToolComponentProps } from '@tools/defineTool'; import { GetGroupsType } from '@components/options/ToolOptions'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import CheckboxWithDesc from '@components/options/CheckboxWithDesc'; import { useTranslation } from 'react-i18next'; interface InitialValuesType { leftQuote: string; rightQuote: string; doubleQuotation: boolean; emptyQuoting: boolean; multiLine: boolean; } const initialValues: InitialValuesType = { leftQuote: '"', rightQuote: '"', doubleQuotation: false, emptyQuoting: true, multiLine: true }; const exampleCards: CardExampleType[] = [ { title: 'Quote text with double quotes', description: 'This example shows how to quote text with double quotes.', sampleText: 'Hello World', sampleResult: '"Hello World"', sampleOptions: { leftQuote: '"', rightQuote: '"', doubleQuotation: false, emptyQuoting: true, multiLine: false } }, { title: 'Quote multi-line text with single quotes', description: 'This example shows how to quote multi-line text with single quotes.', sampleText: 'Hello\nWorld', sampleResult: "'Hello'\n'World'", sampleOptions: { leftQuote: "'", rightQuote: "'", doubleQuotation: false, emptyQuoting: true, multiLine: true } }, { title: 'Quote with custom quotes', description: 'This example shows how to quote text with custom quotes.', sampleText: 'Hello World', sampleResult: '<>', sampleOptions: { leftQuote: '<<', rightQuote: '>>', doubleQuotation: false, emptyQuoting: true, multiLine: false } } ]; export default function Quote({ title }: ToolComponentProps) { const { t } = useTranslation(); const [input, setInput] = useState(''); const [result, setResult] = useState(''); const compute = (optionsValues: InitialValuesType, input: string) => { if (input) { setResult( stringQuoter( input, optionsValues.leftQuote, optionsValues.rightQuote, optionsValues.doubleQuotation, optionsValues.emptyQuoting, optionsValues.multiLine ) ); } }; const getGroups: GetGroupsType = ({ values, updateField }) => [ { title: t('string.quote.quoteOptions'), component: ( updateField('leftQuote', val)} description={t('string.quote.leftQuoteDescription')} /> updateField('rightQuote', val)} description={t('string.quote.rightQuoteDescription')} /> updateField('doubleQuotation', checked)} title={t('string.quote.allowDoubleQuotation')} /> updateField('emptyQuoting', checked)} title={t('string.quote.quoteEmptyLines')} /> updateField('multiLine', checked)} title={t('string.quote.processAsMultiLine')} /> ) } ]; return ( } resultComponent={ } initialValues={initialValues} getGroups={getGroups} toolInfo={{ title: t('string.quote.toolInfo.title'), description: t('string.quote.toolInfo.description') }} exampleCards={exampleCards} input={input} setInput={setInput} compute={compute} /> ); }