2024-12-31 10:30:14 +05:30
|
|
|
import { PlusIcon, DashIcon } from '@primer/octicons-react';
|
2024-12-31 10:31:50 +05:30
|
|
|
import type { Dispatch, SetStateAction } from 'react';
|
2024-10-11 03:02:33 -04:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Group,
|
|
|
|
|
Input,
|
2024-12-31 10:30:14 +05:30
|
|
|
NumberField as AriaNumberField,
|
|
|
|
|
} from 'react-aria-components';
|
|
|
|
|
import { cn } from '~/utils/cn';
|
2024-10-11 03:02:33 -04:00
|
|
|
|
|
|
|
|
type NumberFieldProps = Parameters<typeof AriaNumberField>[0] & {
|
|
|
|
|
label: string;
|
|
|
|
|
state?: [number, Dispatch<SetStateAction<number>>];
|
2024-12-31 10:30:14 +05:30
|
|
|
};
|
2024-10-11 03:02:33 -04:00
|
|
|
|
|
|
|
|
export default function NumberField(props: NumberFieldProps) {
|
|
|
|
|
return (
|
|
|
|
|
<AriaNumberField
|
|
|
|
|
{...props}
|
|
|
|
|
aria-label={props.label}
|
|
|
|
|
className="w-full"
|
|
|
|
|
value={props.state?.[0]}
|
2024-12-31 10:30:14 +05:30
|
|
|
onChange={(value) => {
|
|
|
|
|
props.state?.[1](value);
|
2024-10-11 03:02:33 -04:00
|
|
|
}}
|
|
|
|
|
>
|
2024-12-31 10:30:14 +05:30
|
|
|
<Group
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex px-2.5 py-1.5 w-full rounded-lg my-1',
|
|
|
|
|
'border border-ui-200 dark:border-ui-600',
|
|
|
|
|
'dark:bg-ui-800 dark:text-ui-300 gap-2',
|
|
|
|
|
'focus-within:ring-2 focus-within:ring-blue-600',
|
|
|
|
|
props.className,
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Input className="w-full bg-transparent focus:outline-none" />
|
2024-10-11 03:02:33 -04:00
|
|
|
<Button slot="decrement">
|
|
|
|
|
<DashIcon className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button slot="increment">
|
|
|
|
|
<PlusIcon className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</AriaNumberField>
|
2024-12-31 10:30:14 +05:30
|
|
|
);
|
2024-10-11 03:02:33 -04:00
|
|
|
}
|