import { ActionIcon, Badge, Box, Flex, Text, useMantineTheme } from '@mantine/core'; import { useCounter, useDisclosure } from '@mantine/hooks'; import { IconMinus, IconPlus, IconX } from '@tabler/icons-react'; import InputModal from '../InputModal'; import { v4 as uuidv4 } from 'uuid' import { useEffect } from 'react'; interface RowCounterProps { counter?: number setValue?(value: number): void, showDelete?: boolean onDelete?(): void } const RowCounter = ({ counter, setValue, showDelete, onDelete }: RowCounterProps) => { const [opened, { open, close }] = useDisclosure(false) // const [count, handlers] = useCounter(counter, { min: 0 }) const count = counter || 0 const handleSetValue = (value: number) => { if (setValue) setValue(value) // else handlers.set(value) } const handleOpen = (e: React.MouseEvent) => { e.stopPropagation() open() } const handleInrease = (e: React.MouseEvent) => { e.stopPropagation() handleSetValue(count + 1) } const handleDerease = (e: React.MouseEvent) => { e.stopPropagation() handleSetValue(count - 1) } const handleDelete = (e: React.MouseEvent) => { e.stopPropagation() if (onDelete) onDelete() } return ( <> {count} { showDelete ? : <> } ); }; export default RowCounter;