import { Box } from '@mui/material'; import React, { useState } from 'react'; import ToolTextInput from '../../../components/input/ToolTextInput'; import ToolTextResult from '../../../components/result/ToolTextResult'; import * as Yup from 'yup'; import ToolOptions from '../../../components/options/ToolOptions'; import { rotateList, SplitOperatorType } from './service'; import ToolInputAndResult from '../../../components/ToolInputAndResult'; import SimpleRadio from '../../../components/options/SimpleRadio'; import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc'; import { formatNumber } from '../../../utils/number'; const initialValues = { splitOperatorType: 'symbol' as SplitOperatorType, input: '', splitSeparator: ',', joinSeparator: ',', right: true, step: 1 }; 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.' } ]; const rotationDirections: { title: string; description: string; value: boolean; }[] = [ { title: 'Rotate forward', description: 'Rotate list items to the right. (Down if a vertical column list.)', value: true }, { title: 'Rotate backward', description: 'Rotate list items to the left. (Up if a vertical column list.)', value: false } ]; export default function Rotate() { const [input, setInput] = useState(''); const [result, setResult] = useState(''); const compute = (optionsValues: typeof initialValues, input: any) => { const { splitOperatorType, splitSeparator, joinSeparator, right, step } = optionsValues; setResult( rotateList( splitOperatorType, input, splitSeparator, joinSeparator, right, step ) ); }; return ( } result={} /> [ { title: 'Item split mode', component: ( {splitOperators.map(({ title, description, type }) => ( updateField('splitOperatorType', type)} title={title} description={description} checked={values.splitOperatorType === type} /> ))} updateField('splitSeparator', val)} /> ) }, { title: 'Rotation Direction and Count', component: ( {rotationDirections.map(({ title, description, value }) => ( updateField('right', value)} title={title} description={description} checked={values.right === value} /> ))} updateField('step', formatNumber(val, 1)) } /> ) }, { title: 'Rotated List Joining Symbol', component: ( updateField('joinSeparator', value)} description={ 'Enter the character that goes between items in the rotated list.' } /> ) } ]} initialValues={initialValues} input={input} /> ); }