# Checkbox

shadcn checkbox with a pixel check.

Source: https://www.ui95.dev/ui/checkbox

## Examples

```tsx
import { Checkbox } from "@/components/ui/checkbox"

import type { ShowcaseDemo } from "../types"

type CheckboxState = {
  label: string
  checked: boolean | "indeterminate"
  isDisabled: boolean
}

const STATES: readonly CheckboxState[] = [
  { label: "unchecked", checked: false, isDisabled: false },
  { label: "checked", checked: true, isDisabled: false },
  { label: "indeterminate", checked: "indeterminate", isDisabled: false },
  { label: "disabled", checked: false, isDisabled: true },
  { label: "disabled checked", checked: true, isDisabled: true },
]

function renderCheckbox({ label, checked, isDisabled }: CheckboxState) {
  return (
    <label className="flex items-center gap-3 text-xl has-disabled:text-muted-foreground">
      <Checkbox defaultChecked={checked} disabled={isDisabled} />
      Autosave.exe
      <span className="sr-only">{label}</span>
    </label>
  )
}

export const demo: ShowcaseDemo = {
  span: "single",
  variants: STATES.map((state) => ({ label: state.label, render: () => renderCheckbox(state) })),
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/checkbox.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/checkbox.tsx`

```tsx
"use client"

import { cn } from "cn"
import { Checkbox as CheckboxPrimitive } from "radix-ui"
import * as React from "react"

import { CheckGlyph, MinusGlyph } from "@/components/ui/pixel-glyphs"

function Checkbox({
  className,
  ...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
  return (
    <CheckboxPrimitive.Root
      data-slot="checkbox"
      className={cn(
        "peer relative flex size-5 shrink-0 items-center justify-center pixel-border border-border well outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:text-muted-foreground aria-invalid:border-destructive",
        className
      )}
      {...props}
    >
      <CheckboxPrimitive.Indicator
        data-slot="checkbox-indicator"
        className="group/indicator grid place-content-center text-well-fill"
      >
        <CheckGlyph className="group-data-[state=indeterminate]/indicator:hidden" />
        <MinusGlyph className="hidden group-data-[state=indeterminate]/indicator:block" />
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  )
}

export { Checkbox }
```

## API reference

### Checkbox

No props of its own. It forwards the props of the element or primitive it wraps.

## Sounds

- `checkbox.on`
- `checkbox.off`
