Checkbox
A native checkbox, flat and square.
Install
$ npx shadcn@latest add @nudgekit/checkboxOr with no config: npx shadcn@latest add https://ui.nudgekit.app/r/checkbox.json
Usage
usage.tsx
import { Checkbox } from "@/components/ui/checkbox"
<label className="flex items-center gap-2.5">
<Checkbox defaultChecked /> Full page
</label>Do
- Use in forms and lists where the choice is saved later.
Don't
- Use a checkbox without a label.
Code
What the CLI writes into your project. It is yours to change.
components/ui/checkbox.tsx
import * as React from "react";
import { cn } from "@/lib/utils";
/** A native checkbox, flat and square, with the brand colour when checked. */
function Checkbox({ className, ...props }: Omit<React.InputHTMLAttributes<HTMLInputElement>, "type">) {
return (
<input
type="checkbox"
data-slot="checkbox"
className={cn(
"size-4 shrink-0 cursor-pointer appearance-none rounded-[4px] border border-line-strong bg-background transition-colors duration-150",
"checked:border-brand checked:bg-brand checked:bg-[url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 8.5 2.5 2.5L12 5.5'/%3E%3C/svg%3E\")] checked:bg-center checked:bg-no-repeat",
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
{...props}
/>
);
}
export { Checkbox };