Checkbox
Ink that fills from the centre.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/checkbox.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/checkbox.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/checkbox.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/checkbox.jsonThis copies the component into components/fabricui. It's your code from then on. First time? Add the theme once: see Installation.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Copy the Checkbox files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/checkbox.tsx"use client"; import * as React from "react"; import "./checkbox.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type CheckboxProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & { /** Called when it's checked or unchecked. */ onCheckedChange?: (checked: boolean) => void; /** "some of these": a dash instead of the tick */ indeterminate?: boolean; /** a round one, for pills */ round?: boolean; /** 22px (default) or 18px, for dense lists and tables */ size?: "md" | "sm";components/fabricui/checkbox.css/* * Checkbox — shared by every page with a checkbox (checkbox.html, tables…). * The ink spreads from the centre inside the box, the tick draws itself in. * Indeterminate (input.indeterminate = true): a dash, for "some of these". * * <span class="gc"><input class="gc__input" type="checkbox" /><span class="gc__box"><span class="gc__ink"></span></span> * <svg class="gc__tick" viewBox="0 0 24 24" aria-hidden="true"><path pathLength="1" d="M5 14L8.5 17.5L19 6.5" /></svg><span class="gc__dash"></span></span> * * --round: a round one, for pills. --sm: 18px, for dense lists and tables. */ .gc.gc--round:where(.fui-checkbox, .fui-checkbox *) { width: 18px; height: 18px; } /* (two classes: beats the square box's 22px) */ .gc--round .gc__box:where(.fui-checkbox, .fui-checkbox *) { border-radius: 50%; background: var(--fabric-check-round); box-shadow: var(--fabric-check-round-edge); } /* a touch larger than the circle, so the fill covers the ring to its very edge */ .gc--round .gc__ink:where(.fui-checkbox, .fui-checkbox *) { width: 20px; height: 20px; margin: -10px 0 0 -10px; } .gc--round .gc__input:checked ~ .gc__box:where(.fui-checkbox, .fui-checkbox *) { box-shadow: inset 0 0 0 1.5px var(--fabric-text); } .gc--round .gc__tick:where(.fui-checkbox, .fui-checkbox *) { left: 3px; top: 3px; width: 12px; height: 12px; stroke-width: 2.8; }Step 3: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 4: Use it
Import it from @/components/fabricui/checkbox. The Usage example below shows it in a page.
Code
components/fabricui/checkbox.tsx
"use client";
import * as React from "react";
import "./checkbox.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type CheckboxProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
/** Called when it's checked or unchecked. */
onCheckedChange?: (checked: boolean) => void;
/** "some of these": a dash instead of the tick */
indeterminate?: boolean;
/** a round one, for pills */
round?: boolean;
/** 22px (default) or 18px, for dense lists and tables */
size?: "md" | "sm";components/fabricui/checkbox.css
/*
* Checkbox — shared by every page with a checkbox (checkbox.html, tables…).
* The ink spreads from the centre inside the box, the tick draws itself in.
* Indeterminate (input.indeterminate = true): a dash, for "some of these".
*
* <span class="gc"><input class="gc__input" type="checkbox" /><span class="gc__box"><span class="gc__ink"></span></span>
* <svg class="gc__tick" viewBox="0 0 24 24" aria-hidden="true"><path pathLength="1" d="M5 14L8.5 17.5L19 6.5" /></svg><span class="gc__dash"></span></span>
*
* --round: a round one, for pills. --sm: 18px, for dense lists and tables.
*/
.gc.gc--round:where(.fui-checkbox, .fui-checkbox *) { width: 18px; height: 18px; } /* (two classes: beats the square box's 22px) */
.gc--round .gc__box:where(.fui-checkbox, .fui-checkbox *) { border-radius: 50%; background: var(--fabric-check-round); box-shadow: var(--fabric-check-round-edge); }
/* a touch larger than the circle, so the fill covers the ring to its very edge */
.gc--round .gc__ink:where(.fui-checkbox, .fui-checkbox *) { width: 20px; height: 20px; margin: -10px 0 0 -10px; }
.gc--round .gc__input:checked ~ .gc__box:where(.fui-checkbox, .fui-checkbox *) { box-shadow: inset 0 0 0 1.5px var(--fabric-text); }
.gc--round .gc__tick:where(.fui-checkbox, .fui-checkbox *) { left: 3px; top: 3px; width: 12px; height: 12px; stroke-width: 2.8; }Usage
Usage
"use client";
import * as React from "react";
import { Checkbox } from "@/components/fabricui/checkbox";
export function Terms() {
const [agreed, setAgreed] = React.useState(false);
return (
<label style={{ display: "flex", alignItems: "center", gap: 12 }}>
<Checkbox checked={agreed} onCheckedChange={setAgreed} />
I agree to the terms
</label>
);
}Props
| Prop | Type | Default |
|---|---|---|
| checked Checked or not, if you control it. | boolean | — |
| defaultChecked The starting state when you don't. | boolean | false |
| onCheckedChange Called when it's checked or unchecked. | (checked: boolean) => void | — |
| indeterminate "Some of these": a dash instead of the tick. | boolean | false |
| round A round one, 18px, for pills. | boolean | false |
| size 22px, or 18px for dense lists and tables. | "md" | "sm" | "md" |