Checkbox
shadcn-lit-registry/checkboxFreeComponent
A control that allows the user to toggle between checked and not checked. Built with Lit and styled using Tailwind CSS. Supports form integration and indeterminate state.
Install it
npx shadcn@latest add https://lit-registry.lloydrichards.dev/r/checkbox.jsonSource
1import { cva } from "class-variance-authority";2import { html, LitElement, nothing, type PropertyValues } from "lit";3import { customElement, property, state } from "lit/decorators.js";4import { unsafeSVG } from "lit/directives/unsafe-svg.js";5import { Check, Minus } from "lucide-static";6import { TW } from "@/registry/lib/tailwindMixin";78export const checkboxVariants = cva(9 "peer size-4 shrink-0 rounded-sm border border-primary shadow-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground",10);1112export interface CheckboxChangeEvent extends CustomEvent {13 detail: { checked: boolean; indeterminate: boolean };14}1516export interface CheckboxProperties {17 checked?: boolean;18 defaultChecked?: boolean;19 indeterminate?: boolean;20 disabled?: boolean;21 required?: boolean;22 name?: string;23 value?: string;24 ariaLabel?: string | null;25 ariaLabelledby?: string | null;26 ariaDescribedby?: string | null;27}2829@customElement("ui-checkbox")30export class Checkbox extends TW(LitElement) implements CheckboxProperties {31 static formAssociated = true;32 private internals: ElementInternals;3334 @property({ type: Boolean }) checked: boolean | undefined = undefined;35 @property({ type: Boolean, attribute: "default-checked" })36 defaultChecked = false;37 @property({ type: Boolean }) indeterminate = false;38 @property({ type: Boolean }) disabled = false;39 @property({ type: Boolean }) required = false;40 @property({ type: String }) name = "";41 @property({ type: String }) value = "on";4243 @property({ type: String, attribute: "aria-label" }) accessor ariaLabel:44 | string45 | null = null;46 @property({ type: String, attribute: "aria-labelledby" })47 accessor ariaLabelledby: string | null = null;48 @property({ type: String, attribute: "aria-describedby" })49 accessor ariaDescribedby: string | null = null;5051 @state() private _checked = false;5253 private _labelClickHandler = (e: Event) => {54 const label = e.currentTarget as HTMLLabelElement;55 if (label.htmlFor === this.id && !this.disabled) {56 e.preventDefault();57 this._handleClick();58 }59 };6061 constructor() {62 super();63 this.internals = this.attachInternals();64 }6566 override connectedCallback() {67 super.connectedCallback();68 if (this.checked === undefined) {69// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn-lit-registry
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Avataravatar | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Badgebadge | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Buttonbutton | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Cardcard | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Collapsiblecollapsible | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Commandcommand | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Context Menucontext-menu | shadcn-lit-registry | Components | Free | 2 deps · 2 files |
