'use client'; import { bool } from 'prop-types'; import { CheckboxProps } from './checkbox.types'; import { RippleEffect } from '../../ripple/ripple-effect'; import { InputLayout } from '../input-layout/input-layout'; import useRippleEffect from '../../ripple/hooks/useRippleEffect'; import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react'; /** * Checkbox component ** description */ export const Checkbox = forwardRef( ({ centralRipple = true, ...props }, ref) => { const [isActive, setIsActive] = useState(false), [checked, setChecked] = useState(props.checked ?? false), ripplesRef = useRef(null), checkboxRef = useRef(null), events = useRippleEffect(ripplesRef, setIsActive); const extraClassStyles = `m3 m3-checkbox-container ${isActive === true ? 'visible' : ''}`.trimEnd(); useImperativeHandle(ref, () => checkboxRef.current); useEffect(() => { setChecked(!checked); }, [checkboxRef.current?.checked]); return (
); }, ); Checkbox.propTypes = { indeterminate: bool, centralRipple: bool, };