'use client' import * as React from 'react' import { Checkbox as BaseCheckbox } from '@base-ui/react/checkbox' import { LazyMotion, domAnimation, m, useAnimate } from 'motion/react' import { useReducedMotion } from '../../hooks/use-reduced-motion' import { cn, useComposedRefs } from '../../internal/utils' const SQUISH_TRANSITION = { duration: 0.3, ease: [0.4, 0, 0.2, 1] satisfies [number, number, number, number], } const ZERO_TRANSITION = { duration: 0 } as const function CheckboxIndicator({ checked, indeterminate, reduced, }: { checked: boolean indeterminate: boolean reduced: boolean }) { const showCheck = checked && !indeterminate const showDash = indeterminate return ( ) } function CheckboxRoot({ renderProps, state, reduced, }: { renderProps: React.ComponentPropsWithRef<'span'> state: { checked: boolean; indeterminate: boolean } reduced: boolean }) { const { checked, indeterminate } = state const { ref, ...htmlProps } = renderProps const [scope, animate] = useAnimate() const composedRef = useComposedRefs(ref, scope) const prevState = React.useRef({ checked, indeterminate }) React.useEffect(() => { const toggled = prevState.current.checked !== checked || prevState.current.indeterminate !== indeterminate prevState.current = { checked, indeterminate } if (toggled && !reduced) { animate(scope.current, { scale: [1, 0.8, 1.1, 1] }, SQUISH_TRANSITION) } }, [checked, indeterminate, animate, scope, reduced]) return ( ) } type CheckboxProps = React.ComponentProps function Checkbox({ className, ...props }: CheckboxProps) { const reduced = useReducedMotion() const ariaInvalid = props['aria-invalid'] const invalid = ariaInvalid === true || ariaInvalid === 'true' return ( } /> ) } export { Checkbox } export type { CheckboxProps }