Tone checkboxes
Five checkboxes that carry a semantic tone in their checked state: info, success, warning, danger and muted. This is a separate styled component, so the base checkbox tone axis stays untouched. Each root exposes data-tone, is sized, token-driven, keeps the small-control touch target, and works controlled or uncontrolled.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/checkbox-toneDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/checkbox-tone.tsx"use client"
import * as React from "react"
import { Check } from "lucide-react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Tone checkbox family: 5 semantically toned checkboxes (info, success, warning,
danger, muted). This is a SEPARATE styled component; the base checkbox's
CONTROL tone axis (neutral/brand/success/danger) does not change and is not
extended here. Every root carries data-tone. Because the box is under 24px the
invisible touch-area extension (after:-inset-1.5) is mandatory in every
variant. The label is visible and bound with aria-labelledby; the ids are
produced by React.useId(). Color comes ONLY from tokens, via alpha color-mix.
framer-motion switches instantly under reduced-motion. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const boxSize: Record<StyledSize, string> = {
sm: "size-4",
md: "size-5",
lg: "size-6",
xl: "size-7",
}
const iconSize: Record<StyledSize, string> = {
sm: "size-3",
md: "size-3.5",
lg: "size-4",
xl: "size-5",
}
const textSize: Record<StyledSize, string> = {
sm: "text-xs",
md: "text-sm",
lg: "text-sm",
xl: "text-base",
}
/* Kutu: kucuk kontrol, dokunma alani uzantisi + focus halkasi + gecerlilik. */
const boxBase =
"relative inline-flex shrink-0 cursor-pointer items-center justify-center rounded-md border outline-none transition-colors after:absolute after:-inset-1.5 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger aria-invalid:ring-danger/20 dark:aria-invalid:ring-danger/40 [&_svg]:shrink-0 [&_i]:leading-none"
const rowBase = "inline-flex items-center gap-2.5"
type CheckboxProps = Omit<React.ComponentProps<"button">, "onChange"> & {
size?: StyledSize
label?: string
checked?: boolean
defaultChecked?: boolean
onCheckedChange?: (checked: boolean) => void
}
function useCheckbox(props: {
checked?: boolean
defaultChecked?: boolean
onCheckedChange?: (checked: boolean) => void
}) {
const { checked, defaultChecked, onCheckedChange } = props
const reduce = useReducedMotion()
const [internal, setInternal] = React.useState(defaultChecked ?? false)
const on = checked ?? internal
const toggle = () => {
if (checked === undefined) setInternal((v) => !v)
onCheckedChange?.(!on)
}
const spring = reduce
? { duration: 0 }
: { type: "spring" as const, stiffness: 500, damping: 30 }
return { on, toggle, spring }
}
/* Shared shell: box plus a visible label. onClass carries each tone's on appearance. */
function ToneCheckbox({
tone,
onClass,
props,
}: {
tone: string
onClass: string
props: CheckboxProps
}) {
const {
className,
size = "md",
label = "Tone option",
checked,
defaultChecked,
onCheckedChange,
...rest
} = props
const { on, toggle, spring } = useCheckbox({ checked, defaultChecked, onCheckedChange })
const labelId = React.useId()
return (
<span className={rowBase}>
<button
type="button"
role="checkbox"
aria-checked={on}
aria-labelledby={labelId}
data-slot="styled-checkbox"
data-tone={tone}
onClick={toggle}
className={cn(boxBase, boxSize[size], on ? onClass : "border-field-border text-transparent", className)}
{...rest}
>
<motion.span
initial={false}
animate={{ scale: on ? 1 : 0, opacity: on ? 1 : 0 }}
transition={spring}
className="flex items-center justify-center"
>
<Check className={cn(iconSize[size], "stroke-[3]")} />
</motion.span>
</button>
<span
id={labelId}
onClick={toggle}
className={cn(textSize[size], "cursor-pointer select-none font-medium text-foreground")}
>
{label}
</span>
</span>
)
}
/* Info: bilgilendirme tonu. */
export function InfoCheckbox(props: CheckboxProps) {
return (
<ToneCheckbox
tone="info"
onClass="border-info bg-info text-info-foreground"
props={{ label: "Send me product news", ...props }}
/>
)
}
/* Success: onay/olumlu ton. */
export function SuccessCheckbox(props: CheckboxProps) {
return (
<ToneCheckbox
tone="success"
onClass="border-success bg-success text-success-foreground"
props={{ label: "Task completed", ...props }}
/>
)
}
/* Warning: dikkat tonu. */
export function WarningCheckbox(props: CheckboxProps) {
return (
<ToneCheckbox
tone="warning"
onClass="border-warning bg-warning text-warning-foreground"
props={{ label: "Acknowledge the risk", ...props }}
/>
)
}
/* Danger: yikici islem tonu. */
export function DangerCheckbox(props: CheckboxProps) {
return (
<ToneCheckbox
tone="danger"
onClass="border-danger bg-danger text-danger-foreground"
props={{ label: "Delete on confirm", ...props }}
/>
)
}
/* Muted: a quiet/secondary tone, with the marker on a muted surface. */
export function MutedCheckbox(props: CheckboxProps) {
return (
<ToneCheckbox
tone="muted"
onClass="border-muted-foreground bg-muted-foreground text-background"
props={{ label: "Hide from the list", ...props }}
/>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Info
The info tone for neutral, informational options.
import { InfoCheckbox } from "@/components/ui/checkbox-tone"
<InfoCheckbox defaultChecked={true} />Success
The success tone for completed or positive options.
import { SuccessCheckbox } from "@/components/ui/checkbox-tone"
<SuccessCheckbox defaultChecked={true} />Warning
The warning tone for options that need attention.
import { WarningCheckbox } from "@/components/ui/checkbox-tone"
<WarningCheckbox defaultChecked={true} />Danger
The danger tone for destructive confirmations.
import { DangerCheckbox } from "@/components/ui/checkbox-tone"
<DangerCheckbox defaultChecked={true} />Muted
The muted tone for quiet, secondary options.
import { MutedCheckbox } from "@/components/ui/checkbox-tone"
<MutedCheckbox defaultChecked={true} />ai2 Tone checkboxes: 5 styled variations on the token system
The ai2 Tone checkboxes are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around checkboxes coloured by semantic tone. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion scales the checkmark in with a spring. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the checkmark appears instantly with no animation.
What is in the ai2 Tone checkboxes?
5 exports in one file: Info, Success, Warning, Danger and Muted. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion scales the checkmark in with a spring.
- Reduced-motion aware: Under prefers-reduced-motion, the checkmark appears instantly with no animation.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Tone checkboxes sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.