Toggles & Switches
Ink Checkbox
A checkbox where ink bleeds out from your click, then the check draws itself.
Installation
npx shadcn@latest add https://relic-ui.vercel.app/r/ink-checkbox.jsonOr straight from GitHub: npx shadcn@latest add relicui/relic-ui/ink-checkbox
Manual installation
1. Install the dependencies:
npm install motion2. Copy this code into components/ui/ink-checkbox.tsx:
"use client"
/**
* Relic UI · Ink Checkbox
* https://relic-ui.vercel.app/docs/ink-checkbox
*
* Copyright (c) 2026 Shubham Tambe
* Open source under the MIT License: https://relic-ui.vercel.app/license
*/
import { useRef, useState } from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
const SIZES = {
sm: { box: 16, className: "size-4" },
default: { box: 20, className: "size-5" },
lg: { box: 24, className: "size-6" },
} as const
const SHAPES = {
rounded: "rounded-[30%]",
square: "rounded-[3px]",
circle: "rounded-full",
} as const
export interface InkCheckboxProps
extends Omit<React.ComponentProps<"button">, "onChange" | "value"> {
/** Checked or not (controlled). */
checked?: boolean
/** Checked at first (uncontrolled). */
defaultChecked?: boolean
onCheckedChange?: (checked: boolean) => void
/** Text next to the box. Clicking it toggles the box too. */
label?: React.ReactNode
size?: keyof typeof SIZES
/** Shape of the box. */
shape?: keyof typeof SHAPES
/** Where the ink starts: where you clicked, the center, or a corner. */
inkFrom?: "pointer" | "center" | "corner"
/** Seconds the ink takes to fill the box. */
inkDuration?: number
/** Name for form submission. Sends "on" when checked. */
name?: string
}
/**
* Ink bleeds out from exactly where you clicked until it fills the box,
* then the check mark draws itself. Unchecking drains the ink away.
*/
export function InkCheckbox({
checked: checkedProp,
defaultChecked = false,
onCheckedChange,
label,
size = "default",
shape = "rounded",
inkFrom = "pointer",
inkDuration = 0.4,
name,
disabled,
className,
onClick,
onPointerDown,
...props
}: InkCheckboxProps) {
const [internal, setInternal] = useState(defaultChecked)
const checked = checkedProp ?? internal
const reduceMotion = useReducedMotion()
const { box, className: boxClass } = SIZES[size]
// Where the ink starts. Clicks remember the pointer; keyboard uses the center.
const pointer = useRef<{ x: number; y: number } | null>(null)
const [origin, setOrigin] = useState({ x: box / 2, y: box / 2 })
// Big enough to cover the box from any starting point.
const diameter = box * 3
function toggle() {
const center = { x: box / 2, y: box / 2 }
setOrigin(
inkFrom === "corner"
? { x: 0, y: box }
: inkFrom === "center"
? center
: (pointer.current ?? center)
)
pointer.current = null
const next = !checked
if (checkedProp === undefined) setInternal(next)
onCheckedChange?.(next)
}
const control = (
<button
type="button"
role="checkbox"
aria-checked={checked}
data-state={checked ? "checked" : "unchecked"}
data-slot="ink-checkbox"
disabled={disabled}
onPointerDown={(e) => {
onPointerDown?.(e)
const rect = e.currentTarget.getBoundingClientRect()
pointer.current = { x: e.clientX - rect.left, y: e.clientY - rect.top }
}}
onClick={(e) => {
onClick?.(e)
if (!e.defaultPrevented) toggle()
}}
className={cn(
"relative isolate inline-flex shrink-0 overflow-hidden border shadow-xs transition-colors duration-300",
"outline-none focus-visible:ring-3 focus-visible:ring-ring/50",
"disabled:cursor-not-allowed disabled:opacity-50",
checked ? "border-primary" : "border-input bg-background",
boxClass,
SHAPES[shape],
!label && className
)}
{...props}
>
<AnimatePresence initial={false}>
{checked && (
<motion.span
key="ink"
aria-hidden
className="absolute -z-10 rounded-full bg-primary"
style={{
left: origin.x - diameter / 2,
top: origin.y - diameter / 2,
width: diameter,
height: diameter,
}}
initial={reduceMotion ? false : { scale: 0, filter: "blur(2px)" }}
animate={{ scale: 1, filter: "blur(0px)" }}
exit={reduceMotion ? { opacity: 0, transition: { duration: 0 } } : { scale: 0, transition: { duration: 0.25, ease: [0.4, 0, 1, 1] } }}
transition={{ duration: inkDuration, ease: [0.22, 1, 0.36, 1] }}
/>
)}
</AnimatePresence>
<svg
aria-hidden
viewBox="0 0 16 16"
fill="none"
className="size-full p-[18%] text-primary-foreground"
>
<motion.path
d="M3 8.5l3.2 3.2L13 4.8"
stroke="currentColor"
strokeWidth={2.2}
strokeLinecap="round"
strokeLinejoin="round"
initial={false}
animate={{ pathLength: checked ? 1 : 0, opacity: checked ? 1 : 0 }}
transition={
reduceMotion
? { duration: 0 }
: { duration: 0.25, delay: checked ? inkDuration * 0.4 : 0, ease: "easeOut" }
}
/>
</svg>
{name && <input type="hidden" name={name} value={checked ? "on" : ""} />}
</button>
)
if (!label) return control
return (
<label
className={cn(
"inline-flex cursor-pointer items-center gap-2.5 text-sm select-none",
disabled && "cursor-not-allowed opacity-50",
className
)}
>
{control}
<span>{label}</span>
</label>
)
}Usage
import { InkCheckbox } from "@/components/ui/ink-checkbox"
export default function InkCheckboxDemo() {
return (
<div className="flex flex-col gap-3">
<InkCheckbox label="Ship the new components" defaultChecked />
<InkCheckbox label="Write the docs" />
<InkCheckbox label="Tell the world" />
</div>
)
}Customize
Try the options below, then copy the code.
size
shape
inkFrom
<InkCheckbox
label="Accept the terms"
/>Props
| Prop | Type | Default |
|---|---|---|
checkedOn or off, when you control the state yourself. | boolean | — |
defaultCheckedOn or off at first, when the component manages state. | boolean | false |
onCheckedChangeCalled when the user toggles it. | (checked: boolean) => void | — |
labelText next to the box. Clicking it toggles the box too. | React.ReactNode | — |
sizeSize of the control. | "sm" | "default" | "lg" | "default" |
shapeShape of the box. | "rounded" | "square" | "circle" | "rounded" |
inkFromWhere the ink starts: where you clicked, the center, or the bottom-left corner. | "pointer" | "center" | "corner" | "pointer" |
inkDurationSeconds the ink takes to fill the box. | number | 0.4 |
nameName for form submission. Sends "on" when checked. | string | — |
...propsAll native button props. | React.ComponentProps<"button"> | — |
Accessibility
- A real button with role="checkbox" and aria-checked.
- The label is a real <label>, so clicking the text toggles it and screen readers read it.
- Keyboard toggles start the ink from the center of the box.
- Animation turns off automatically for users who enable reduced motion in their system settings.