feat(FE-92-94): Slicing UI detail chickin & refactor number input chickin form

This commit is contained in:
randy-ar
2025-10-25 16:27:15 +07:00
parent f0f6ec53cb
commit 1e9d02b4b7
11 changed files with 595 additions and 48 deletions
+53
View File
@@ -0,0 +1,53 @@
'use client';
import { ChangeEvent } from 'react';
import { NumericFormat, OnValueChange } from 'react-number-format';
import TextInput, { TextInputProps } from '@/components/input/TextInput';
interface NumberInputProps extends Omit<TextInputProps, 'type'> {
thousandSeparator?: string;
decimalSeparator?: string;
decimalScale?: number;
allowNegative?: boolean;
prefix?: string;
suffix?: string;
fixedDecimalScale?: boolean;
}
const NumberInput = ({
thousandSeparator = ',',
decimalSeparator = '.',
decimalScale = 5,
allowNegative = true,
onChange,
...restProps
}: NumberInputProps) => {
const valueChangeHandler: OnValueChange = (
numberFormatValues,
sourceInfo
) => {
const newChangeEvent = sourceInfo.event as
| ChangeEvent<HTMLInputElement>
| undefined;
if (newChangeEvent) {
newChangeEvent.target.value = numberFormatValues.value;
onChange?.(newChangeEvent);
}
};
return (
<NumericFormat
thousandSeparator={thousandSeparator}
decimalSeparator={decimalSeparator}
customInput={TextInput}
onValueChange={valueChangeHandler}
decimalScale={decimalScale}
allowNegative={allowNegative}
{...restProps}
/>
);
};
export default NumberInput;