From 0257f2953d2cae7c707dcfc317d508b86be6554a Mon Sep 17 00:00:00 2001 From: saladday <1203511142@qq.com> Date: Thu, 6 Aug 2026 10:28:09 -0400 Subject: [PATCH] fix(ui): unify checkbox styles --- src/components/ui/checkbox.tsx | 81 +++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/src/components/ui/checkbox.tsx b/src/components/ui/checkbox.tsx index 3f2367da0..a87767f03 100644 --- a/src/components/ui/checkbox.tsx +++ b/src/components/ui/checkbox.tsx @@ -1,33 +1,62 @@ import * as React from "react"; -import * as CheckboxPrimitive from "@radix-ui/react-checkbox"; -import { Check, Minus } from "lucide-react"; import { cn } from "@/lib/utils"; -const Checkbox = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - , + "checked" | "type" + > { + checked?: CheckedState; + onCheckedChange?: (checked: boolean) => void; +} + +const Checkbox = React.forwardRef( + ( + { className, - )} - {...props} - > - - {props.checked === "indeterminate" ? ( - - ) : ( - - )} - - -)); -Checkbox.displayName = CheckboxPrimitive.Root.displayName; + checked, + onChange, + onCheckedChange, + "aria-checked": ariaChecked, + ...props + }, + ref, + ) => { + const inputRef = React.useRef(null); + const isIndeterminate = checked === "indeterminate"; + + React.useImperativeHandle(ref, () => inputRef.current as HTMLInputElement); + + React.useLayoutEffect(() => { + if (inputRef.current) { + inputRef.current.indeterminate = isIndeterminate; + } + }); + + return ( + { + onChange?.(event); + onCheckedChange?.(event.target.checked); + }} + className={cn( + "w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-border-default rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2", + className, + )} + /> + ); + }, +); + +Checkbox.displayName = "Checkbox"; export { Checkbox }; +export type { CheckboxProps, CheckedState };