From e7e319ee041a4ee7bdde7a524fbbd724efd02344 Mon Sep 17 00:00:00 2001 From: Chesterkxng Date: Mon, 4 May 2026 22:09:48 +0200 Subject: [PATCH] chore: - level selection enabled - full i8n support --- src/pages/tools/string/text-compare/index.tsx | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/src/pages/tools/string/text-compare/index.tsx b/src/pages/tools/string/text-compare/index.tsx index 1c57dce..a3ee528 100644 --- a/src/pages/tools/string/text-compare/index.tsx +++ b/src/pages/tools/string/text-compare/index.tsx @@ -2,24 +2,57 @@ import { Box } from '@mui/material'; import { useState, useEffect } from 'react'; import ToolContent from '@components/ToolContent'; import { ToolComponentProps } from '@tools/defineTool'; +import { GetGroupsType } from '@components/options/ToolOptions'; import ToolTextInput from '@components/input/ToolTextInput'; import ToolDiffResult from '@components/result/ToolDiffResult'; +import SelectWithDesc from '@components/options/SelectWithDesc'; import { useTranslation } from 'react-i18next'; import { compareTextsHtml } from './service'; +import { level, InitialValuesType } from './types'; + +const initialValues: InitialValuesType = { + level: 'word' +}; export default function TextCompare({ title }: ToolComponentProps) { const { t } = useTranslation('string'); const [inputA, setInputA] = useState(''); const [inputB, setInputB] = useState(''); + const [level, setLevel] = useState('word'); const [result, setResult] = useState(''); const compute = () => { - setResult(compareTextsHtml(inputA, inputB)); + setResult(compareTextsHtml(inputA, inputB, level)); }; useEffect(() => { compute(); - }, [inputA, inputB]); + }, [inputA, inputB, level]); + + const getGroups: GetGroupsType = ({ + values, + updateField + }) => [ + { + title: t('textCompare.options.title'), + component: ( + + { + updateField('level', value); + setLevel(value); + }} + description={t('textCompare.options.levelDesc')} + /> + + ) + } + ]; return ( - - + + } - resultComponent={} - initialValues={{}} - getGroups={null} + resultComponent={ + + } + initialValues={initialValues} + getGroups={getGroups} setInput={() => { setInputA(''); setInputB(''); @@ -41,8 +88,8 @@ export default function TextCompare({ title }: ToolComponentProps) { }} compute={compute} toolInfo={{ - title: t('textCompare.toolInfo.title'), - description: t('textCompare.toolInfo.description') + title: t('textCompare.title'), + description: t('textCompare.longDescription') }} /> );