Files
ticketchain/components/custom/TicketButton.tsx
Ayush Acharjya aa5d92b9dd add num tickets
2024-10-27 00:07:26 +01:00

51 lines
1.0 KiB
TypeScript

import React from 'react';
import { Button } from '../ui/button';
interface NumberPickerProps {
initialCount?: number;
min?: number;
max?: number;
onChange?: (count: number) => void;
}
const NumberPicker: React.FC<NumberPickerProps> = ({
initialCount = 1,
min = 1,
max = 10,
onChange,
}) => {
const [count, setCount] = React.useState(initialCount);
React.useEffect(() => {
if (onChange) {
onChange(count);
}
}, [count, onChange]);
const increment = () => {
if (count < max) {
setCount(count + 1);
}
};
const decrement = () => {
if (count > min) {
setCount(count - 1);
}
};
return (
<div className="flex items-center space-x-2">
<Button variant="outline" onClick={decrement} disabled={count === min}>
-
</Button>
<span className="text-center w-8">{count}</span>
<Button variant="outline" onClick={increment} disabled={count === max}>
+
</Button>
</div>
);
};
export default NumberPicker;