diff --git a/.eslintrc b/.eslintrc
index ef1ea0f..b03a663 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -15,7 +15,7 @@
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
- // "plugin:prettier/recommended",
+ "plugin:prettier/recommended",
"plugin:tailwindcss/recommended"
],
"parser": "@typescript-eslint/parser",
diff --git a/src/components/ToolOptions.tsx b/src/components/ToolOptions.tsx
index 0dceb12..f6c5955 100644
--- a/src/components/ToolOptions.tsx
+++ b/src/components/ToolOptions.tsx
@@ -1,15 +1,25 @@
-import { Box, Stack, useTheme } from '@mui/material'
-import SettingsIcon from '@mui/icons-material/Settings'
-import Typography from '@mui/material/Typography'
-import React, { ReactNode } from 'react'
+import { Box, Stack, useTheme } from '@mui/material';
+import SettingsIcon from '@mui/icons-material/Settings';
+import Typography from '@mui/material/Typography';
+import React, { ReactNode } from 'react';
export default function ToolOptions({ children }: { children: ReactNode }) {
- const theme = useTheme()
- return (
-
-
- Tool options
-
- {children}
- )
+ const theme = useTheme();
+ return (
+
+
+
+ Tool options
+
+ {children}
+
+ );
}
diff --git a/src/pages/string/split/index.tsx b/src/pages/string/split/index.tsx
index 49cdb89..0e669d8 100644
--- a/src/pages/string/split/index.tsx
+++ b/src/pages/string/split/index.tsx
@@ -1,19 +1,14 @@
-import ToolHeader from '../../../components/ToolHeader'
-import ToolLayout from '../../../components/ToolLayout'
-import { Box, Radio, Stack, TextField, useTheme } from '@mui/material'
-import Grid from '@mui/material/Grid'
-import Typography from '@mui/material/Typography'
-import Button from '@mui/material/Button'
-import PublishIcon from '@mui/icons-material/Publish'
-import ContentPasteIcon from '@mui/icons-material/ContentPaste'
-import DownloadIcon from '@mui/icons-material/Download'
-import React, { useEffect, useRef, useState } from 'react'
-import ToolTextInput from '../../../components/input/ToolTextInput'
-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'
+import ToolHeader from '../../../components/ToolHeader';
+import ToolLayout from '../../../components/ToolLayout';
+import { Box, Stack, TextField } from '@mui/material';
+import Grid from '@mui/material/Grid';
+import Typography from '@mui/material/Typography';
+import React, { useEffect, useRef, useState } from 'react';
+import ToolTextInput from '../../../components/input/ToolTextInput';
+import ToolTextResult from '../../../components/result/ToolTextResult';
+import { Field, Formik, FormikProps } from 'formik';
+import * as Yup from 'yup';
+import ToolOptions from '../../../components/ToolOptions';
type SplitOperatorType = 'symbol' | 'regex' | 'length' | 'chunks';
const initialValues = {
@@ -21,45 +16,74 @@ const initialValues = {
symbolValue: ' ',
regexValue: '/\\s+/',
lengthValue: '16',
- chunksValue: '4'
-}
-const initialSplitOperators: {
+ chunksValue: '4',
+
+ outputSeparator: '\\n',
+ charBeforeChunk: '',
+ charAfterChunk: ''
+};
+const splitOperators: {
title: string;
description: string;
- type: SplitOperatorType
-}[] = [{
- title: 'Use a Symbol for Splitting', description: 'Character that will be used to\n' +
- 'break text into parts.\n' +
- '(Space by default.)',
- type: 'symbol'
-},
+ type: SplitOperatorType;
+}[] = [
+ {
+ title: 'Use a Symbol for Splitting',
+ description:
+ 'Character that will be used to\n' +
+ 'break text into parts.\n' +
+ '(Space by default.)',
+ type: 'symbol'
+ },
{
title: 'Use a Regex for Splitting',
type: 'regex',
- description: 'Regular expression that will be\n' +
+ description:
+ 'Regular expression that will be\n' +
'used to break text into parts.\n' +
'(Multiple spaces by default.)'
},
{
- title: 'Use Length for Splitting', description: 'Number of symbols that will be\n' +
- 'put in each output chunk.',
+ title: 'Use Length for Splitting',
+ description:
+ 'Number of symbols that will be\n' + 'put in each output chunk.',
type: 'length'
},
{
- title: 'Use a Number of Chunks', description: 'Number of chunks of equal\n' +
- 'length in the output.',
+ title: 'Use a Number of Chunks',
+ description: 'Number of chunks of equal\n' + 'length in the output.',
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 = ({
- fieldName,
- type,
- title,
- onTypeChange,
- value,
- description,
- onTextChange
- }: {
+ fieldName,
+ type,
+ title,
+ onTypeChange,
+ value,
+ description,
+ onTextChange
+}: {
fieldName: string;
title: string;
type: SplitOperatorType;
@@ -68,42 +92,68 @@ const CustomRadioButton = ({
description: string;
onTextChange: (value: string) => void;
}) => {
- const onChange = () => onTypeChange(type)
- return (
-
-
+ const onChange = () => onTypeChange(type);
+ return (
+
+
+
{title}
- onTextChange(event.target.value)} />
- {description}
+
- )
-}
+ );
+};
+
+const InputWithDesc = ({
+ description,
+ value,
+ onChange
+}: {
+ description: string;
+ value: string;
+ onChange: (value: string) => void;
+}) => {
+ return (
+
+ onChange(event.target.value)}
+ />
+
+ {description}
+
+
+ );
+};
export default function SplitText() {
- const [input, setInput] = useState('')
- const [result, setResult] = useState('')
- const formRef = useRef>()
+ const [input, setInput] = useState('');
+ const [result, setResult] = useState('');
+ const formRef = useRef>();
useEffect(() => {
- setResult(input.split(' ').join('\n'))
- }, [input])
+ setResult(input.split(' ').join('\n'));
+ }, [input]);
const validationSchema = Yup.object({
- splitSeparator: Yup.string().required('The separator is required')
- })
+ // splitSeparator: Yup.string().required('The separator is required')
+ });
return (
@@ -120,29 +170,42 @@ export default function SplitText() {
initialValues={initialValues}
validationSchema={validationSchema}
innerRef={formRef}
- onSubmit={() => {
- }}
+ onSubmit={() => {}}
>
{({ setFieldValue, values }) => (
-
+
Split separator options
- {initialSplitOperators.map(({ title, description, type }) =>
+ {splitOperators.map(({ title, description, type }) => (
setFieldValue('splitSeparatorType', type)}
+ onTypeChange={(type) =>
+ setFieldValue('splitSeparatorType', type)
+ }
onTextChange={(val) => setFieldValue(`${type}Value`, val)}
- />)}
+ />
+ ))}
+
+
+ Output separator options
+ {outputOptions.map((option) => (
+ setFieldValue(option.accessor, value)}
+ description={option.description}
+ />
+ ))}
-
)}
- )
+ );
}