diff --git a/packages/smarthr-ui/src/components/CheckBox/CheckBox.tsx b/packages/smarthr-ui/src/components/CheckBox/CheckBox.tsx index 64699db917..778dee75a9 100644 --- a/packages/smarthr-ui/src/components/CheckBox/CheckBox.tsx +++ b/packages/smarthr-ui/src/components/CheckBox/CheckBox.tsx @@ -1,11 +1,9 @@ 'use client' import React, { - ChangeEventHandler, ComponentPropsWithRef, PropsWithChildren, forwardRef, - useCallback, useEffect, useId, useImperativeHandle, @@ -25,7 +23,7 @@ export type Props = PropsWithChildren< } > -const checkbox = tv({ +const classNameGenerator = tv({ slots: { wrapper: 'smarthr-ui-CheckBox shr-inline-flex shr-items-baseline', box: [ @@ -59,48 +57,29 @@ const checkbox = tv({ 'shr-relative shr-box-border shr-inline-block shr-h-[theme(fontSize.base)] shr-w-[theme(fontSize.base)] shr-shrink-0 shr-translate-y-[0.125em] shr-leading-none', label: [ 'smarthr-ui-CheckBox-label shr-ms-0.5 shr-cursor-pointer shr-text-base shr-leading-tight', + '[[data-disabled=true]>&]:shr-pointer-events-none [[data-disabled=true]>&]:shr-cursor-not-allowed [[data-disabled=true]>&]:shr-text-disabled', ], }, - variants: { - disabled: { - true: { - label: 'shr-pointer-events-none shr-cursor-not-allowed shr-text-disabled', - }, - }, - }, }) export const CheckBox = forwardRef( - ({ checked, mixed = false, error, onChange, className, children, ...props }, ref) => { - const { - wrapperStyle, - innerWrapperStyle, - boxStyle, - inputStyle, - iconWrapStyle, - iconStyle, - labelStyle, - } = useMemo(() => { - const { wrapper, innerWrapper, box, input, iconWrap, icon, label } = checkbox() + ({ checked, mixed, error, className, children, disabled, ...props }, ref) => { + const classNames = useMemo(() => { + const { wrapper, innerWrapper, box, input, iconWrap, icon, label } = classNameGenerator() + return { - wrapperStyle: wrapper({ className }), - innerWrapperStyle: innerWrapper(), - boxStyle: box(), - inputStyle: input(), - iconWrapStyle: iconWrap(), - iconStyle: icon(), - labelStyle: label({ disabled: props.disabled }), + wrapper: wrapper({ className }), + innerWrapper: innerWrapper(), + box: box(), + input: input(), + iconWrap: iconWrap(), + icon: icon(), + label: label(), } - }, [className, props.disabled]) - - const handleChange = useCallback>( - (e) => { - if (onChange) onChange(e) - }, - [onChange], - ) + }, [className]) const inputRef = useRef(null) + useImperativeHandle( ref, () => inputRef.current, @@ -116,31 +95,52 @@ export const CheckBox = forwardRef( const checkBoxId = props.id || defaultId return ( - - + + + + - - {children && ( - - )} + + {children} + ) }, ) + +const AriaHiddenBox = React.memo<{ className: string }>(({ className }) => ( +