chore: update CheckboxInput component

This commit is contained in:
ValdiANS
2025-12-04 22:45:13 +07:00
parent fd024fdb8f
commit 2bb2da74e6
+13 -2
View File
@@ -2,8 +2,9 @@
import { HTMLProps, useEffect, useRef } from 'react'; import { HTMLProps, useEffect, useRef } from 'react';
import { cn } from '@/lib/helper'; import { cn } from '@/lib/helper';
import { Size } from '@/types/theme';
interface CheckboxInputProps extends HTMLProps<HTMLInputElement> { interface CheckboxInputProps extends Omit<HTMLProps<HTMLInputElement>, 'size'> {
name: string; name: string;
label?: string; label?: string;
indeterminate?: boolean; indeterminate?: boolean;
@@ -16,6 +17,7 @@ interface CheckboxInputProps extends HTMLProps<HTMLInputElement> {
isError?: boolean; isError?: boolean;
isValid?: boolean; isValid?: boolean;
errorMessage?: string; errorMessage?: string;
size?: Size;
} }
const CheckboxInput = ({ const CheckboxInput = ({
@@ -27,10 +29,19 @@ const CheckboxInput = ({
isValid, isValid,
isError, isError,
errorMessage, errorMessage,
size = 'sm',
...rest ...rest
}: CheckboxInputProps) => { }: CheckboxInputProps) => {
const ref = useRef<HTMLInputElement>(null!); const ref = useRef<HTMLInputElement>(null!);
const checkboxBaseClassName = cn('checkbox cursor-pointer rounded-md', {
'checkbox-xs': size === 'xs',
'checkbox-sm': size === 'sm',
'checkbox-md': size === 'md',
'checkbox-lg': size === 'lg',
'checkbox-xl': size === 'xl',
});
useEffect(() => { useEffect(() => {
if (typeof indeterminate === 'boolean') { if (typeof indeterminate === 'boolean') {
ref.current.indeterminate = !rest.checked && indeterminate; ref.current.indeterminate = !rest.checked && indeterminate;
@@ -53,7 +64,7 @@ const CheckboxInput = ({
id={name} id={name}
name={name} name={name}
className={cn( className={cn(
'checkbox cursor-pointer', checkboxBaseClassName,
{ {
'border-error': isError, 'border-error': isError,
'border-success': isValid, 'border-success': isValid,