|
|
|
|
@ -8,7 +8,7 @@ export type InputNumberProps = {
|
|
|
|
|
value?: number
|
|
|
|
|
onChange: (value?: number) => void
|
|
|
|
|
amount?: number
|
|
|
|
|
size?: 'sm' | 'md'
|
|
|
|
|
size?: 'regular' | 'large'
|
|
|
|
|
max?: number
|
|
|
|
|
min?: number
|
|
|
|
|
defaultValue?: number
|
|
|
|
|
@ -19,7 +19,7 @@ export type InputNumberProps = {
|
|
|
|
|
} & Omit<InputProps, 'value' | 'onChange' | 'size' | 'min' | 'max' | 'defaultValue'>
|
|
|
|
|
|
|
|
|
|
export const InputNumber: FC<InputNumberProps> = (props) => {
|
|
|
|
|
const { unit, className, onChange, amount = 1, value, size = 'md', max, min, defaultValue, wrapClassName, controlWrapClassName, controlClassName, disabled, ...rest } = props
|
|
|
|
|
const { unit, className, onChange, amount = 1, value, size = 'regular', max, min, defaultValue, wrapClassName, controlWrapClassName, controlClassName, disabled, ...rest } = props
|
|
|
|
|
|
|
|
|
|
const isValidValue = (v: number) => {
|
|
|
|
|
if (max && v > max)
|
|
|
|
|
@ -76,29 +76,37 @@ export const InputNumber: FC<InputNumberProps> = (props) => {
|
|
|
|
|
onChange(parsed)
|
|
|
|
|
}}
|
|
|
|
|
unit={unit}
|
|
|
|
|
size={size}
|
|
|
|
|
/>
|
|
|
|
|
<div className={classNames(
|
|
|
|
|
'flex flex-col bg-components-input-bg-normal rounded-r-md border-l border-divider-subtle text-text-tertiary focus:shadow-xs',
|
|
|
|
|
disabled && 'opacity-50 cursor-not-allowed',
|
|
|
|
|
controlWrapClassName)}
|
|
|
|
|
>
|
|
|
|
|
<button onClick={inc} disabled={disabled} className={classNames(
|
|
|
|
|
size === 'sm' ? 'pt-1' : 'pt-1.5',
|
|
|
|
|
'px-1.5 hover:bg-components-input-bg-hover',
|
|
|
|
|
disabled && 'cursor-not-allowed hover:bg-transparent',
|
|
|
|
|
controlClassName,
|
|
|
|
|
)}>
|
|
|
|
|
<button
|
|
|
|
|
type='button'
|
|
|
|
|
onClick={inc}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
className={classNames(
|
|
|
|
|
size === 'regular' ? 'pt-1' : 'pt-1.5',
|
|
|
|
|
'px-1.5 hover:bg-components-input-bg-hover',
|
|
|
|
|
disabled && 'cursor-not-allowed hover:bg-transparent',
|
|
|
|
|
controlClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowUpSLine className='size-3' />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type='button'
|
|
|
|
|
onClick={dec}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
className={classNames(
|
|
|
|
|
size === 'sm' ? 'pb-1' : 'pb-1.5',
|
|
|
|
|
size === 'regular' ? 'pb-1' : 'pb-1.5',
|
|
|
|
|
'px-1.5 hover:bg-components-input-bg-hover',
|
|
|
|
|
disabled && 'cursor-not-allowed hover:bg-transparent',
|
|
|
|
|
controlClassName,
|
|
|
|
|
)}>
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowDownSLine className='size-3' />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|