'use client' import PropTypes from 'prop-types' import React, { useCallback, useEffect, useRef, useState } from 'react' import classNames from 'classnames' import styles from './styles.module.css' import { getGlobalStyle } from '../../../../utils' interface CheckboxProps { checked?: boolean className?: string disabled?: boolean hideLabel?: boolean id?: any indeterminate?: boolean label?: any name?: any onChange?: (event: React.ChangeEvent, id: string) => void } export const Checkbox: React.FC = ({ checked = false, className = '', disabled = false, id, indeterminate = false, label, name, onChange = (event, id) => ({ event, id }), ...restProps }) => { const inputEl = useRef(null) const [clickCount, setClickCount] = useState(0) const [lastClickTime, setLastClickTime] = useState(0) const clickThreshold = 1000 const syncIndeterminateState = useCallback(() => { if (inputEl.current) { inputEl.current.indeterminate = indeterminate } }, [indeterminate]) useEffect(() => { syncIndeterminateState() }, [indeterminate, syncIndeterminateState]) const handleChange = (event: React.ChangeEvent) => { if (indeterminate) syncIndeterminateState() const now = Date.now() setClickCount(now - lastClickTime < clickThreshold ? prev => prev + 1 : 1) if (clickCount >= 7) setClickCount(0) setLastClickTime(now) onChange(event, id) } const disabledStyles = { color: getGlobalStyle('--color-text-inactive') } return ( ) } Checkbox.propTypes = { checked: PropTypes.bool, className: PropTypes.string, disabled: PropTypes.bool, hideLabel: PropTypes.bool, id: PropTypes.any, indeterminate: PropTypes.bool, label: PropTypes.any, name: PropTypes.any, onChange: PropTypes.func }