"use client"; import * as React from "react"; import * as CheckboxPrimitive from "@radix-ui/react-checkbox"; import { Check, Minus } from "lucide-react"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "../../lib/utils"; /** * Checkbox Bileşeni * * Erişilebilir, özelleştirilebilir ve tema sistemiyle tam entegre checkbox bileşeni. * Form elemanları ve seçim listeleri için kullanılır. */ const checkboxVariants = cva( "peer shrink-0 border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:text-primary-foreground", { variants: { variant: { default: "border-border bg-background data-[state=checked]:bg-primary data-[state=checked]:border-primary", outline: "border-border bg-transparent data-[state=checked]:bg-primary data-[state=checked]:border-primary", muted: "border-border bg-accent data-[state=checked]:bg-primary data-[state=checked]:border-primary", ghost: "border-transparent bg-transparent hover:bg-accent data-[state=checked]:bg-primary data-[state=checked]:border-primary", }, size: { sm: "h-3.5 w-3.5", default: "h-4 w-4", md: "h-5 w-5", lg: "h-6 w-6", }, radius: { none: "rounded-none", sm: "rounded-sm", default: "rounded-sm", md: "rounded-md", full: "rounded-full", }, animation: { none: "", subtle: "transition-all duration-200", default: "transition-all duration-200", bounce: "transition-all duration-200", }, }, defaultVariants: { variant: "default", size: "default", radius: "default", animation: "default", }, } ); export interface CheckboxProps extends React.ComponentPropsWithoutRef, VariantProps { /** * İndeterminate durumu - grup seçimlerinde bazı öğeler seçilmişse kullanılır */ indeterminate?: boolean; /** * Özel ikon komponenti */ icon?: React.ReactNode; } const Checkbox = React.forwardRef< React.ElementRef, CheckboxProps >(({ className, variant, size, radius, animation, indeterminate = false, icon, checked, ...props }, ref) => { // Indeterminate state yönetimi const [isIndeterminate, setIsIndeterminate] = React.useState(indeterminate); React.useEffect(() => { setIsIndeterminate(indeterminate); }, [indeterminate]); // Checked state override, indeterminate olduğunda const effectiveChecked = isIndeterminate ? false : checked; return ( {isIndeterminate ? ( ) : icon ? ( icon ) : ( )} ); }); Checkbox.displayName = CheckboxPrimitive.Root.displayName; // CheckboxGroup bileşeni interface CheckboxGroupProps extends React.HTMLAttributes { /** * Grup içi yerleşim - dikey veya yatay */ orientation?: "horizontal" | "vertical"; /** * Öğeler arasındaki boşluk (piksel) */ spacing?: number | string; /** * Alt bileşenler */ children: React.ReactNode; } const CheckboxGroup = React.forwardRef( ({ className, orientation = "vertical", spacing = "1rem", children, ...props }, ref) => { return (
{children}
); } ); CheckboxGroup.displayName = "CheckboxGroup"; // CheckboxLabel bileşeni interface CheckboxLabelProps extends React.HTMLAttributes { /** * Checkbox bileşeni için HTML id */ htmlFor?: string; /** * Label içeriği */ children: React.ReactNode; /** * Checkbox öncesi veya sonrası */ position?: "start" | "end"; /** * Devre dışı durum stili */ disabled?: boolean; } const CheckboxLabel = React.forwardRef( ({ className, htmlFor, children, position = "end", disabled = false, ...props }, ref) => { return ( ); } ); CheckboxLabel.displayName = "CheckboxLabel"; // Checkbox ve Label içeren bileşen interface CheckboxWithLabelProps extends CheckboxProps { /** * Label içeriği */ label: React.ReactNode; /** * Label pozisyonu */ labelPosition?: "start" | "end"; /** * Label için HTML sınıfları */ labelClassName?: string; } const CheckboxWithLabel = React.forwardRef< React.ElementRef, CheckboxWithLabelProps >(({ id, label, labelPosition = "end", labelClassName, ...checkboxProps }, ref) => { const generatedId = React.useId(); const checkboxId = id || generatedId; return (
{labelPosition === "start" && ( {label} )} {labelPosition === "end" && ( {label} )}
); }); CheckboxWithLabel.displayName = "CheckboxWithLabel"; export { Checkbox, CheckboxGroup, CheckboxLabel, CheckboxWithLabel };