import PropTypes from 'prop-types' import React from 'react' import { ButtonDecrement, ButtonIncrement, ContainerQuantity, MarmitaCounter } from './styled' import { type QuantityButtonProps } from './types' import { Icon } from '../../atoms' import { getGlobalStyle } from '../../../helpers' import { handleAnimationQuantity } from './helpers/index' import styles from './styles.module.css' export const QuantityButton: React.FC = ({ border, margin, padding, label = '', quantity = 0, disabled = false, showNegativeButton = false, showPositiveButton = false, validationOne = false, classNameQuantity = '', validationZero = false, width, handleDecrement = () => { }, handleIncrement = () => { }, ...props }) => { const validateZero = validationZero && quantity >= 0 const [animation, setAnimation] = React.useState('') return (
{Number(quantity) !== 0 && ( { if (!validationOne) { handleDecrement() handleAnimationQuantity('down', setAnimation) } }} type='button' > )} {label} {Number(quantity) !== 0 &&
{validateZero ? null : quantity}
} { { handleAnimationQuantity('up', setAnimation) return handleIncrement() }} type='button' > }
) } QuantityButton.propTypes = { border: PropTypes.any, classNameQuantity: PropTypes.string, disabled: PropTypes.bool, handleDecrement: PropTypes.func, handleIncrement: PropTypes.func, label: PropTypes.string, margin: PropTypes.any, padding: PropTypes.any, quantity: PropTypes.number.isRequired, showNegativeButton: PropTypes.bool, showPositiveButton: PropTypes.bool, validationOne: PropTypes.any, validationZero: PropTypes.bool, width: PropTypes.string }