import { Box } from '@mui/material'; import React, { useState } from 'react'; import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextResult from '@components/result/ToolTextResult'; import ToolContent from '@components/ToolContent'; import { shuffleList, SplitOperatorType } from './service'; import SimpleRadio from '@components/options/SimpleRadio'; import TextFieldWithDesc from '@components/options/TextFieldWithDesc'; import { isNumber } from '@utils/string'; import { useTranslation } from 'react-i18next'; const initialValues = { splitOperatorType: 'symbol' as SplitOperatorType, splitSeparator: ',', joinSeparator: ',', length: '' }; const splitOperators: { title: string; description: string; type: SplitOperatorType; }[] = [ { title: 'Use a Symbol for Splitting', description: 'Delimit input list items with a character.', type: 'symbol' }, { title: 'Use a Regex for Splitting', type: 'regex', description: 'Delimit input list items with a regular expression.' } ]; export default function Shuffle() { const { t } = useTranslation(); const [input, setInput] = useState(''); const [result, setResult] = useState(''); const compute = (optionsValues: typeof initialValues, input: any) => { const { splitOperatorType, splitSeparator, joinSeparator, length } = optionsValues; setResult( shuffleList( splitOperatorType, input, splitSeparator, joinSeparator, isNumber(length) ? Number(length) : undefined ) ); }; return ( } resultComponent={ } getGroups={({ values, updateField }) => [ { title: t('list.shuffle.inputListSeparator'), component: ( {splitOperators.map(({ title, description, type }) => ( updateField('splitOperatorType', type)} title={title} description={description} checked={values.splitOperatorType === type} /> ))} updateField('splitSeparator', val)} /> ) }, { title: t('list.shuffle.shuffledListLength'), component: ( updateField('length', val)} /> ) }, { title: t('list.shuffle.shuffledListSeparator'), component: ( updateField('joinSeparator', value)} description={t('list.shuffle.joinSeparatorDescription')} /> ) } ]} /> ); }