2024-06-26 07:47:17 +01:00
|
|
|
import { Box } from '@mui/material';
|
|
|
|
|
import React, { useState } from 'react';
|
2024-06-25 02:07:57 +01:00
|
|
|
import ToolTextInput from '../../../components/input/ToolTextInput';
|
|
|
|
|
import ToolTextResult from '../../../components/result/ToolTextResult';
|
|
|
|
|
import ToolOptions from '../../../components/options/ToolOptions';
|
|
|
|
|
import { compute } from './service';
|
|
|
|
|
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
|
2024-06-25 07:15:42 +01:00
|
|
|
import ToolInputAndResult from '../../../components/ToolInputAndResult';
|
2024-06-25 02:07:57 +01:00
|
|
|
|
|
|
|
|
const initialValues = {
|
|
|
|
|
dotSymbol: '.',
|
|
|
|
|
dashSymbol: '-'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function ToMorse() {
|
|
|
|
|
const [input, setInput] = useState<string>('');
|
|
|
|
|
const [result, setResult] = useState<string>('');
|
|
|
|
|
// const formRef = useRef<FormikProps<typeof initialValues>>(null);
|
2024-06-26 07:47:17 +01:00
|
|
|
const computeOptions = (optionsValues: typeof initialValues, input: any) => {
|
|
|
|
|
const { dotSymbol, dashSymbol } = optionsValues;
|
|
|
|
|
setResult(compute(input, dotSymbol, dashSymbol));
|
2024-06-25 02:07:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
2024-06-25 07:15:42 +01:00
|
|
|
<ToolInputAndResult
|
|
|
|
|
input={<ToolTextInput value={input} onChange={setInput} />}
|
|
|
|
|
result={<ToolTextResult title={'Morse code'} value={result} />}
|
|
|
|
|
/>
|
2024-06-26 07:47:17 +01:00
|
|
|
<ToolOptions
|
|
|
|
|
compute={computeOptions}
|
2024-06-27 21:52:41 +01:00
|
|
|
getGroups={({ values, updateField }) => [
|
2024-06-26 07:47:17 +01:00
|
|
|
{
|
|
|
|
|
title: 'Short Signal',
|
|
|
|
|
component: (
|
|
|
|
|
<TextFieldWithDesc
|
|
|
|
|
description={
|
|
|
|
|
'Symbol that will correspond to the dot in Morse code.'
|
|
|
|
|
}
|
|
|
|
|
value={values.dotSymbol}
|
2024-06-27 21:52:41 +01:00
|
|
|
onOwnChange={(val) => updateField('dotSymbol', val)}
|
2024-06-26 07:47:17 +01:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Long Signal',
|
|
|
|
|
component: (
|
|
|
|
|
<TextFieldWithDesc
|
|
|
|
|
description={
|
|
|
|
|
'Symbol that will correspond to the dash in Morse code.'
|
|
|
|
|
}
|
|
|
|
|
value={values.dashSymbol}
|
2024-06-27 21:52:41 +01:00
|
|
|
onOwnChange={(val) => updateField('dashSymbol', val)}
|
2024-06-25 02:07:57 +01:00
|
|
|
/>
|
2024-06-26 07:47:17 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
]}
|
|
|
|
|
initialValues={initialValues}
|
|
|
|
|
input={input}
|
|
|
|
|
/>
|
2024-06-25 02:07:57 +01:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|