mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-13 11:09:30 +02:00
chore: output selector
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
"plugin:react/recommended",
|
"plugin:react/recommended",
|
||||||
"plugin:@typescript-eslint/eslint-recommended",
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
"plugin:@typescript-eslint/recommended",
|
"plugin:@typescript-eslint/recommended",
|
||||||
// "plugin:prettier/recommended",
|
"plugin:prettier/recommended",
|
||||||
"plugin:tailwindcss/recommended"
|
"plugin:tailwindcss/recommended"
|
||||||
],
|
],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
|
@@ -1,15 +1,25 @@
|
|||||||
import { Box, Stack, useTheme } from '@mui/material'
|
import { Box, Stack, useTheme } from '@mui/material';
|
||||||
import SettingsIcon from '@mui/icons-material/Settings'
|
import SettingsIcon from '@mui/icons-material/Settings';
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography';
|
||||||
import React, { ReactNode } from 'react'
|
import React, { ReactNode } from 'react';
|
||||||
|
|
||||||
export default function ToolOptions({ children }: { children: ReactNode }) {
|
export default function ToolOptions({ children }: { children: ReactNode }) {
|
||||||
const theme = useTheme()
|
const theme = useTheme();
|
||||||
return (<Box sx={{ mb: 2, borderRadius: 2, padding: 2, backgroundColor: theme.palette.background.default }} mt={2}>
|
return (
|
||||||
<Stack direction={'row'} spacing={1} alignItems={'center'}>
|
<Box
|
||||||
<SettingsIcon />
|
sx={{
|
||||||
<Typography fontSize={22}>Tool options</Typography>
|
mb: 2,
|
||||||
</Stack>
|
borderRadius: 2,
|
||||||
{children}
|
padding: 2,
|
||||||
</Box>)
|
backgroundColor: theme.palette.background.default
|
||||||
|
}}
|
||||||
|
mt={2}
|
||||||
|
>
|
||||||
|
<Stack direction={'row'} spacing={1} alignItems={'center'}>
|
||||||
|
<SettingsIcon />
|
||||||
|
<Typography fontSize={22}>Tool options</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Box mt={2}>{children}</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,14 @@
|
|||||||
import ToolHeader from '../../../components/ToolHeader'
|
import ToolHeader from '../../../components/ToolHeader';
|
||||||
import ToolLayout from '../../../components/ToolLayout'
|
import ToolLayout from '../../../components/ToolLayout';
|
||||||
import { Box, Radio, Stack, TextField, useTheme } from '@mui/material'
|
import { Box, Stack, TextField } from '@mui/material';
|
||||||
import Grid from '@mui/material/Grid'
|
import Grid from '@mui/material/Grid';
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography';
|
||||||
import Button from '@mui/material/Button'
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import PublishIcon from '@mui/icons-material/Publish'
|
import ToolTextInput from '../../../components/input/ToolTextInput';
|
||||||
import ContentPasteIcon from '@mui/icons-material/ContentPaste'
|
import ToolTextResult from '../../../components/result/ToolTextResult';
|
||||||
import DownloadIcon from '@mui/icons-material/Download'
|
import { Field, Formik, FormikProps } from 'formik';
|
||||||
import React, { useEffect, useRef, useState } from 'react'
|
import * as Yup from 'yup';
|
||||||
import ToolTextInput from '../../../components/input/ToolTextInput'
|
import ToolOptions from '../../../components/ToolOptions';
|
||||||
import ToolTextResult from '../../../components/result/ToolTextResult'
|
|
||||||
import SettingsIcon from '@mui/icons-material/Settings'
|
|
||||||
import { Field, Formik, FormikProps } from 'formik'
|
|
||||||
import * as Yup from 'yup'
|
|
||||||
import ToolOptions from '../../../components/ToolOptions'
|
|
||||||
|
|
||||||
type SplitOperatorType = 'symbol' | 'regex' | 'length' | 'chunks';
|
type SplitOperatorType = 'symbol' | 'regex' | 'length' | 'chunks';
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
@@ -21,45 +16,74 @@ const initialValues = {
|
|||||||
symbolValue: ' ',
|
symbolValue: ' ',
|
||||||
regexValue: '/\\s+/',
|
regexValue: '/\\s+/',
|
||||||
lengthValue: '16',
|
lengthValue: '16',
|
||||||
chunksValue: '4'
|
chunksValue: '4',
|
||||||
}
|
|
||||||
const initialSplitOperators: {
|
outputSeparator: '\\n',
|
||||||
|
charBeforeChunk: '',
|
||||||
|
charAfterChunk: ''
|
||||||
|
};
|
||||||
|
const splitOperators: {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
type: SplitOperatorType
|
type: SplitOperatorType;
|
||||||
}[] = [{
|
}[] = [
|
||||||
title: 'Use a Symbol for Splitting', description: 'Character that will be used to\n' +
|
{
|
||||||
'break text into parts.\n' +
|
title: 'Use a Symbol for Splitting',
|
||||||
'(Space by default.)',
|
description:
|
||||||
type: 'symbol'
|
'Character that will be used to\n' +
|
||||||
},
|
'break text into parts.\n' +
|
||||||
|
'(Space by default.)',
|
||||||
|
type: 'symbol'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Use a Regex for Splitting',
|
title: 'Use a Regex for Splitting',
|
||||||
type: 'regex',
|
type: 'regex',
|
||||||
description: 'Regular expression that will be\n' +
|
description:
|
||||||
|
'Regular expression that will be\n' +
|
||||||
'used to break text into parts.\n' +
|
'used to break text into parts.\n' +
|
||||||
'(Multiple spaces by default.)'
|
'(Multiple spaces by default.)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Use Length for Splitting', description: 'Number of symbols that will be\n' +
|
title: 'Use Length for Splitting',
|
||||||
'put in each output chunk.',
|
description:
|
||||||
|
'Number of symbols that will be\n' + 'put in each output chunk.',
|
||||||
type: 'length'
|
type: 'length'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Use a Number of Chunks', description: 'Number of chunks of equal\n' +
|
title: 'Use a Number of Chunks',
|
||||||
'length in the output.',
|
description: 'Number of chunks of equal\n' + 'length in the output.',
|
||||||
type: 'chunks'
|
type: 'chunks'
|
||||||
}]
|
}
|
||||||
|
];
|
||||||
|
const outputOptions: {
|
||||||
|
description: string;
|
||||||
|
accessor: keyof typeof initialValues;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
description:
|
||||||
|
'Character that will be put\n' +
|
||||||
|
'between the split chunks.\n' +
|
||||||
|
'(It\'s newline "\\n" by default.)',
|
||||||
|
accessor: 'outputSeparator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'Character before each chunk',
|
||||||
|
accessor: 'charBeforeChunk'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'Character after each chunk',
|
||||||
|
accessor: 'charAfterChunk'
|
||||||
|
}
|
||||||
|
];
|
||||||
const CustomRadioButton = ({
|
const CustomRadioButton = ({
|
||||||
fieldName,
|
fieldName,
|
||||||
type,
|
type,
|
||||||
title,
|
title,
|
||||||
onTypeChange,
|
onTypeChange,
|
||||||
value,
|
value,
|
||||||
description,
|
description,
|
||||||
onTextChange
|
onTextChange
|
||||||
}: {
|
}: {
|
||||||
fieldName: string;
|
fieldName: string;
|
||||||
title: string;
|
title: string;
|
||||||
type: SplitOperatorType;
|
type: SplitOperatorType;
|
||||||
@@ -68,42 +92,68 @@ const CustomRadioButton = ({
|
|||||||
description: string;
|
description: string;
|
||||||
onTextChange: (value: string) => void;
|
onTextChange: (value: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const onChange = () => onTypeChange(type)
|
const onChange = () => onTypeChange(type);
|
||||||
return (<Box>
|
return (
|
||||||
<Stack direction={'row'} sx={{ mt: 2, mb: 1, cursor: 'pointer' }} onClick={onChange} alignItems={'center'}
|
<Box>
|
||||||
spacing={1}>
|
<Stack
|
||||||
<Field
|
direction={'row'}
|
||||||
type="radio"
|
sx={{ mt: 2, mb: 1, cursor: 'pointer' }}
|
||||||
name={fieldName}
|
onClick={onChange}
|
||||||
value={type}
|
alignItems={'center'}
|
||||||
onChange={onChange}
|
spacing={1}
|
||||||
/>
|
>
|
||||||
|
<Field type="radio" name={fieldName} value={type} onChange={onChange} />
|
||||||
<Typography>{title}</Typography>
|
<Typography>{title}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<TextField sx={{ backgroundColor: 'white' }} value={value}
|
<InputWithDesc
|
||||||
onChange={event => onTextChange(event.target.value)} />
|
value={value}
|
||||||
<Typography fontSize={12} mt={1}>{description}</Typography>
|
onChange={onTextChange}
|
||||||
|
description={description}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const InputWithDesc = ({
|
||||||
|
description,
|
||||||
|
value,
|
||||||
|
onChange
|
||||||
|
}: {
|
||||||
|
description: string;
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<TextField
|
||||||
|
sx={{ backgroundColor: 'white' }}
|
||||||
|
value={value}
|
||||||
|
onChange={(event) => onChange(event.target.value)}
|
||||||
|
/>
|
||||||
|
<Typography fontSize={12} mt={1}>
|
||||||
|
{description}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
export default function SplitText() {
|
export default function SplitText() {
|
||||||
const [input, setInput] = useState<string>('')
|
const [input, setInput] = useState<string>('');
|
||||||
const [result, setResult] = useState<string>('')
|
const [result, setResult] = useState<string>('');
|
||||||
const formRef = useRef<FormikProps<typeof initialValues>>()
|
const formRef = useRef<FormikProps<typeof initialValues>>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setResult(input.split(' ').join('\n'))
|
setResult(input.split(' ').join('\n'));
|
||||||
}, [input])
|
}, [input]);
|
||||||
|
|
||||||
const validationSchema = Yup.object({
|
const validationSchema = Yup.object({
|
||||||
splitSeparator: Yup.string().required('The separator is required')
|
// splitSeparator: Yup.string().required('The separator is required')
|
||||||
})
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolLayout>
|
<ToolLayout>
|
||||||
<ToolHeader
|
<ToolHeader
|
||||||
title={'Text Splitter'}
|
title={'Text Splitter'}
|
||||||
description={
|
description={
|
||||||
'World\'s simplest browser-based utility for splitting text. Load your text in the input form on the left and you\'ll automatically get pieces of this text on the right. Powerful, free, and fast. Load text – get chunks.'
|
"World's simplest browser-based utility for splitting text. Load your text in the input form on the left and you'll automatically get pieces of this text on the right. Powerful, free, and fast. Load text – get chunks."
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -120,29 +170,42 @@ export default function SplitText() {
|
|||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
innerRef={formRef}
|
innerRef={formRef}
|
||||||
onSubmit={() => {
|
onSubmit={() => {}}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{({ setFieldValue, values }) => (
|
{({ setFieldValue, values }) => (
|
||||||
<Stack direction={'row'}>
|
<Stack direction={'row'} spacing={2}>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography fontSize={22}>Split separator options</Typography>
|
<Typography fontSize={22}>Split separator options</Typography>
|
||||||
{initialSplitOperators.map(({ title, description, type }) =>
|
{splitOperators.map(({ title, description, type }) => (
|
||||||
<CustomRadioButton
|
<CustomRadioButton
|
||||||
|
key={type}
|
||||||
type={type}
|
type={type}
|
||||||
title={title}
|
title={title}
|
||||||
fieldName={'splitSeparatorType'}
|
fieldName={'splitSeparatorType'}
|
||||||
description={description}
|
description={description}
|
||||||
value={values[`${type}Value`]}
|
value={values[`${type}Value`]}
|
||||||
onTypeChange={(type) => setFieldValue('splitSeparatorType', type)}
|
onTypeChange={(type) =>
|
||||||
|
setFieldValue('splitSeparatorType', type)
|
||||||
|
}
|
||||||
onTextChange={(val) => setFieldValue(`${type}Value`, val)}
|
onTextChange={(val) => setFieldValue(`${type}Value`, val)}
|
||||||
/>)}
|
/>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography fontSize={22}>Output separator options</Typography>
|
||||||
|
{outputOptions.map((option) => (
|
||||||
|
<InputWithDesc
|
||||||
|
key={option.accessor}
|
||||||
|
value={values[option.accessor]}
|
||||||
|
onChange={(value) => setFieldValue(option.accessor, value)}
|
||||||
|
description={option.description}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
<Box></Box>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
</ToolOptions>
|
</ToolOptions>
|
||||||
</ToolLayout>
|
</ToolLayout>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user