Files
omni-tools/src/pages/tools/string/to-morse/index.tsx

59 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-03-09 17:22:14 +00:00
import ToolContent from '@components/ToolContent';
2024-06-26 07:47:17 +01:00
import React, { useState } from 'react';
2025-02-23 01:38:42 +01:00
import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult';
2024-06-25 02:07:57 +01:00
import { compute } from './service';
2025-02-23 01:38:42 +01:00
import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
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>('');
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 (
2025-03-09 17:22:14 +00:00
<ToolContent
title="To Morse"
initialValues={initialValues}
compute={computeOptions}
input={input}
setInput={setInput}
inputComponent={<ToolTextInput value={input} onChange={setInput} />}
resultComponent={<ToolTextResult title={'Morse code'} value={result} />}
getGroups={({ values, updateField }) => [
{
title: 'Short Signal',
component: (
<TextFieldWithDesc
description={
'Symbol that will correspond to the dot in Morse code.'
}
value={values.dotSymbol}
onOwnChange={(val) => updateField('dotSymbol', val)}
/>
)
},
{
title: 'Long Signal',
component: (
<TextFieldWithDesc
description={
'Symbol that will correspond to the dash in Morse code.'
}
value={values.dashSymbol}
onOwnChange={(val) => updateField('dashSymbol', val)}
/>
)
}
]}
/>
2024-06-25 02:07:57 +01:00
);
}