Checkbox
A boolean input component.
Installation
npx @rahimstack@latest add checkbox
Usage
State
API Reference
const CheckboxAnatomy = defineStyleAnatomy({
container: cva("UI-Checkbox__container inline-flex gap-2 items-center"),
root: cva([
"UI-Checkbox__root",
"appearance-none peer block relative overflow-hidden transition h-5 w-5 shrink-0 text-white rounded-md ring-offset-1 border ring-offset-[--background]",
"border-gray-300 dark:border-gray-700",
"outline-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[--ring] disabled:cursor-not-allowed data-[disabled=true]:opacity-50",
"data-[state=unchecked]:bg-white dark:data-[state=unchecked]:bg-gray-700", // Unchecked
"data-[state=unchecked]:hover:bg-gray-100 dark:data-[state=unchecked]:hover:bg-gray-600", // Unchecked hover
"data-[state=checked]:bg-brand dark:data-[state=checked]:bg-brand data-[state=checked]:border-brand", // Checked
"data-[state=indeterminate]:bg-[--muted] dark:data-[state=indeterminate]:bg-gray-700 data-[state=indeterminate]:text-white data-[state=indeterminate]:border-transparent", // Checked
"data-[error=true]:border-red-500 data-[error=true]:dark:border-red-500 data-[error=true]:data-[state=checked]:border-red-500 data-[error=true]:dark:data-[state=checked]:border-red-500", // Error
], {
variants: {
size: {
md: "h-5 w-5",
lg: "h-6 w-6",
},
},
defaultVariants: {
size: "md",
},
}),
label: cva([
"UI-Checkbox_label",
"font-normal",
"data-[disabled=true]:opacity-50",
], {
variants: {
size: {
md: "text-md",
lg: "text-lg",
},
},
defaultVariants: {
size: "md",
},
}),
indicator: cva([
"UI-Checkbox__indicator",
"flex h-full w-full items-center justify-center relative",
]),
checkIcon: cva("UI-Checkbox__checkIcon absolute", {
variants: {
size: {
md: "h-4 w-4",
lg: "h-5 w-5",
},
},
defaultVariants: {
size: "md",
},
}),
})