From a422367a4098ce7687d1d6df7fa796cf610d622e Mon Sep 17 00:00:00 2001 From: chanx <1243304602@qq.com> Date: Thu, 17 Jul 2025 12:10:58 +0800 Subject: [PATCH] fix: Fix the problem that the custom footer of modal component (#8877) ### What problem does this PR solve? Fix the problem that the custom footer of modal component is not effective, specify the react and react-dom versions, and add the input-number component [#3221](https://github.com/infiniflow/ragflow/issues/3221) ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/package.json | 2 + web/src/components/originui/number-input.tsx | 92 ++++++++++++++++++++ web/src/components/ui/modal.tsx | 10 +-- 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 web/src/components/originui/number-input.tsx diff --git a/web/package.json b/web/package.json index 3bfe0e6c7..7a882019f 100644 --- a/web/package.json +++ b/web/package.json @@ -83,7 +83,9 @@ "openai-speech-stream-player": "^1.0.8", "pptx-preview": "^1.0.5", "rc-tween-one": "^3.0.6", + "react": "^18.2.0", "react-copy-to-clipboard": "^5.1.0", + "react-dom": "^18.2.0", "react-dropzone": "^14.3.5", "react-error-boundary": "^4.0.13", "react-hook-form": "^7.56.4", diff --git a/web/src/components/originui/number-input.tsx b/web/src/components/originui/number-input.tsx new file mode 100644 index 000000000..dfede7f4d --- /dev/null +++ b/web/src/components/originui/number-input.tsx @@ -0,0 +1,92 @@ +import { MinusIcon, PlusIcon } from 'lucide-react'; +import React, { useEffect, useMemo, useState } from 'react'; + +interface NumberInputProps { + className?: string; + value?: number; + onChange?: (value: number) => void; + height?: number | string; +} + +const NumberInput: React.FC = ({ + className, + value: initialValue, + onChange, + height, +}) => { + const [value, setValue] = useState(() => { + return initialValue ?? 0; + }); + + useEffect(() => { + if (initialValue !== undefined) { + setValue(initialValue); + } + }, [initialValue]); + + const handleDecrement = () => { + if (value > 0) { + setValue(value - 1); + onChange?.(value - 1); + } + }; + + const handleIncrement = () => { + setValue(value + 1); + onChange?.(value + 1); + }; + + const handleChange = (e: React.ChangeEvent) => { + const newValue = Number(e.target.value); + if (!isNaN(newValue)) { + setValue(newValue); + onChange?.(newValue); + } + }; + + const handleInput = (e: React.ChangeEvent) => { + // If the input value is not a number, the input is not allowed + if (!/^\d*$/.test(e.target.value)) { + e.preventDefault(); + } + }; + const style = useMemo( + () => ({ + height: height ? `${height.toString().replace('px', '')}px` : 'auto', + }), + [height], + ); + return ( +
+ + + +
+ ); +}; + +export default NumberInput; diff --git a/web/src/components/ui/modal.tsx b/web/src/components/ui/modal.tsx index 4962fb8ab..72221e54c 100644 --- a/web/src/components/ui/modal.tsx +++ b/web/src/components/ui/modal.tsx @@ -106,12 +106,12 @@ export const Modal: FC = ({ ); - return ( -
- {footerTemp} -
- ); } + return ( +
+ {footerTemp} +
+ ); }, [footer, cancelText, t, confirmLoading, okText, handleCancel, handleOk]); return (