mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-19 03:24:02 +01:00
feat: generate Numbers
This commit is contained in:
@@ -5,15 +5,17 @@ export default function ToolInputAndResult({
|
||||
input,
|
||||
result
|
||||
}: {
|
||||
input: ReactNode;
|
||||
input?: ReactNode;
|
||||
result: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Grid id="tool" container spacing={2}>
|
||||
<Grid item xs={12} md={6}>
|
||||
{input}
|
||||
</Grid>
|
||||
<Grid item xs={12} md={6}>
|
||||
{input && (
|
||||
<Grid item xs={12} md={6}>
|
||||
{input}
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} md={input ? 6 : 12}>
|
||||
{result}
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -20,7 +20,7 @@ const FormikListenerComponent = <T,>({
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (values && input) compute(values, input);
|
||||
compute(values, input);
|
||||
} catch (exception: unknown) {
|
||||
if (exception instanceof Error) showSnackBar(exception.message, 'error');
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export default function ToolOptions<T extends FormikValues>({
|
||||
initialValues: T;
|
||||
validationSchema: any | (() => any);
|
||||
compute: (optionsValues: T, input: any) => void;
|
||||
input: any;
|
||||
input?: any;
|
||||
getGroups: (formikProps: FormikProps<T>) => ToolOptionGroup[];
|
||||
formRef?: RefObject<FormikProps<T>>;
|
||||
}) {
|
||||
|
||||
@@ -1,11 +1,85 @@
|
||||
import { Box } from '@mui/material';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import ToolTextResult from '../../../components/result/ToolTextResult';
|
||||
import * as Yup from 'yup';
|
||||
import ToolOptions from '../../../components/options/ToolOptions';
|
||||
import { listOfIntegers } from './service';
|
||||
import ToolInputAndResult from '../../../components/ToolInputAndResult';
|
||||
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
|
||||
|
||||
const initialValues = {};
|
||||
const validationSchema = Yup.object({
|
||||
// splitSeparator: Yup.string().required('The separator is required')
|
||||
});
|
||||
export default function Generate() {
|
||||
return <Box>Lorem ipsum</Box>;
|
||||
const initialValues = {
|
||||
firstValue: '1',
|
||||
numberOfNumbers: '10',
|
||||
step: '1',
|
||||
separator: '\\n'
|
||||
};
|
||||
export default function SplitText() {
|
||||
const [result, setResult] = useState<string>('');
|
||||
|
||||
const validationSchema = Yup.object({
|
||||
// splitSeparator: Yup.string().required('The separator is required')
|
||||
});
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<ToolInputAndResult
|
||||
result={<ToolTextResult title={'Total'} value={result} />}
|
||||
/>
|
||||
<ToolOptions
|
||||
getGroups={({ values, setFieldValue }) => [
|
||||
{
|
||||
title: 'Arithmetic sequence option',
|
||||
component: (
|
||||
<Box>
|
||||
<TextFieldWithDesc
|
||||
description={'Start sequence from this number.'}
|
||||
value={values.firstValue}
|
||||
onChange={(val) => setFieldValue('firstValue', val)}
|
||||
type={'number'}
|
||||
/>
|
||||
<TextFieldWithDesc
|
||||
description={'Increase each element by this amount'}
|
||||
value={values.step}
|
||||
onChange={(val) => setFieldValue('step', val)}
|
||||
type={'number'}
|
||||
/>
|
||||
<TextFieldWithDesc
|
||||
description={'Number of elements in sequence.'}
|
||||
value={values.numberOfNumbers}
|
||||
onChange={(val) => setFieldValue('numberOfNumbers', val)}
|
||||
type={'number'}
|
||||
/>
|
||||
</Box>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Separator',
|
||||
component: (
|
||||
<TextFieldWithDesc
|
||||
description={
|
||||
'Separate elements in the arithmetic sequence by this character.'
|
||||
}
|
||||
value={values.separator}
|
||||
onChange={(val) => setFieldValue('separator', val)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
]}
|
||||
compute={(optionsValues) => {
|
||||
const { firstValue, numberOfNumbers, separator, step } =
|
||||
optionsValues;
|
||||
setResult(
|
||||
listOfIntegers(
|
||||
Number(firstValue),
|
||||
Number(numberOfNumbers),
|
||||
Number(step),
|
||||
separator
|
||||
)
|
||||
);
|
||||
}}
|
||||
initialValues={initialValues}
|
||||
validationSchema={validationSchema}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user