- Accordion
- Agent Thinking
- Alert
- Alert Dialog
- Announcement
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Checkbox Card
- Code Block
- Collapsible
- Color Picker
- Combobox
- Command
- Composer
- Composer Loader
- Context Menu
- Data Grid
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- File Upload
- Hover Card
- Input
- Input Group
- Input Otp
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Meter
- Native Select
- Navigation Menu
- Number Field
- Pagination
- Period Switcher
- Popover
- Progress
- Questionnaire
- Radio Card
- Radio Group
- Resizable
- Reveal
- Scroll Area
- Search Field
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Social Button
- Sonner
- Spinner
- Status Dot
- Switch
- Switch Card
- Table
- Tabs
- Tag Group
- Textarea
- Theme Toggle
- Time Field
- Toggle
- Toggle Group
- Tooltip
- Trace
- Tree View
- Agent Creator 01
- Agent Limits Card 01
- Agent Progress 01
- AI Chat 01
- AI Image Generation 01
- AI Profile 01
- Alerts Card 01
- Auth Card 01
- Calendar 01
- Composer 01
- Composer Attachments 01
- Composer Panel 01
- Finance Dashboard 01
- Home Dashboard 01
- Marketing Dashboard 01
- Medical Profile 01
- Meeting Scheduler 01
- Multi Agent Chat 01
- Notification Center 01
- Patient Info Card 01
- Project Board 01
- Questionnaire 01
- Settings Modal 01
- Sidebar 01
- Stat Cards 01
- Task List 01
- Web Search 01
- Activity Rings Card 01
- Area Chart Card 01
- Bar List Card 01
- Combo Chart Card 01
- Contributions Card 01
- Earnings Chart Card 01
- Funnel Chart Card 01
- Heatmap Chart Card 01
- Line Chart Card 01
- Most Active Days Card 01
- Orders Chart Card 01
- Radar Chart Card 01
- Radial Chart Card 01
- Revenue Chart Card 01
- Sankey Chart Card 01
- Scatter Chart Card 01
- Sleep Score Card 01
- Stage Bars Card 01
- Steps Card 01
Installation
$ pnpm dlx shadcn@latest add @cobalt/checkbox
Sizes
default is 16px and sm is 14px, for dense tables.
md - 16px
sm - 14px
Label and control
Pair a Checkbox with a FieldLabel through htmlFor, so clicking the label toggles the box. Use checked with onCheckedChange to control it, or defaultChecked to leave it uncontrolled.
Source
"use client";
import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
import { cn } from "cn";
function Checkbox({
className,
size = "default",
...props
}: CheckboxPrimitive.Root.Props & { size?: "default" | "sm" }) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"group/checkbox peer relative isolate flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border border-[var(--border-strong,var(--input))] bg-popover shadow-[shadow:var(--shadow-control,0_1px_2px_0_rgb(0_0_0/0.05))] outline-none transition-[background-color,border-color,box-shadow] duration-150 ease-[ease] hover:not-data-disabled:border-[var(--checkbox-border-hover,var(--ring))] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 motion-reduce:transition-none after:absolute after:-inset-x-3 after:-inset-y-2",
"data-checked:border-0 data-indeterminate:border-0 data-checked:bg-[image:var(--gradient-button-primary-default,linear-gradient(180deg,oklch(from_var(--primary)_calc(l_+_0.08)_c_h),var(--primary)))] data-indeterminate:bg-[image:var(--gradient-button-primary-default,linear-gradient(180deg,oklch(from_var(--primary)_calc(l_+_0.08)_c_h),var(--primary)))] data-checked:shadow-[inset_0_2px_0_0_rgb(255_255_255/0.25),inset_0_0_0_1px_oklch(from_var(--primary)_calc(l_+_0.08)_c_h)] data-indeterminate:shadow-[inset_0_2px_0_0_rgb(255_255_255/0.25),inset_0_0_0_1px_oklch(from_var(--primary)_calc(l_+_0.08)_c_h)]",
"before:pointer-events-none before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:bg-[image:var(--gradient-button-primary-hover,linear-gradient(180deg,oklch(from_var(--primary)_calc(l_+_0.16)_c_h),oklch(from_var(--primary)_calc(l_+_0.08)_c_h)))] before:opacity-0 before:transition-opacity before:duration-150 hover:not-data-disabled:data-checked:before:opacity-100 hover:not-data-disabled:data-indeterminate:before:opacity-100 motion-reduce:before:transition-none",
size === "sm" && "size-3.5",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="flex size-full items-center justify-center text-[color:var(--checkbox-glyph,var(--primary-foreground))]"
>
<svg
viewBox="0 0 16 16"
fill="none"
className="size-full"
aria-hidden="true"
>
<path
d="M4.5 8H8H11.5"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
className="hidden group-data-indeterminate/checkbox:block"
/>
<path
d="M4 7.7002L6.64645 10.3466C6.84171 10.5419 7.15829 10.5419 7.35355 10.3466L12 5.7002"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
pathLength={1}
className="[stroke-dasharray:1] [animation:check-draw_200ms_cubic-bezier(0.65,0,0.35,1)_forwards] group-data-indeterminate/checkbox:hidden motion-reduce:animate-none motion-reduce:[stroke-dashoffset:0]"
/>
</svg>
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
);
}
export { Checkbox }; On this page