Checkbox

Consent Checkbox

A consent checkbox: never pre-ticked, with the document link staying its own target.

  • checkbox
  • consent
  • legal
  • validation

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/checkbox-005?lang=en

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "checkbox-005" (Consent Checkbox) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/checkbox-005.json

Registry item: https://vibeui.ru/r/checkbox-005.json
Installs to: components/vibeui/checkbox-005.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A consent checkbox: never pre-ticked, with the document link staying its own target.

A consent checkbox: unchecked by default, the document link inside the label, and an error after the first interaction with role=alert. Zero dependencies, one file.

## 3. How to use it
import { Checkbox005 } from "@/components/vibeui/checkbox-005"

<Checkbox005 linkLabel="the privacy policy" linkHref="/terms" />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-checkbox-005-* palette — do not swap it for your theme tokens
- the unchecked default: pre-ticked consent is illegal in the EU and dishonest everywhere
- the link as its own target — clicking it must not toggle the box
- aria-invalid and aria-describedby on error
- role="alert" on the message: it has to be heard immediately
- showing the error only after interaction, not on first render

## 6. You may change
- text, linkLabel and linkHref
- error — the error wording
- the accent through the accent prop
- the block width

## 7. Rules
- One consent per checkbox: marketing and data processing never share a tick.
- The component does not block submission: the form validates, this only holds state.
- The consent text must be specific: "I accept the terms" without a link means nothing legally.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/checkbox-005.json
https://vibeui.ru/r/checkbox-005.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-checkbox-005-*. Клиентский: "use client". Состояние ошибки появляется только после первого касания, поле помечается aria-invalid и связывается с текстом ошибки через aria-describedby, сообщение объявлено role="alert". Клик по ссылке останавливает всплытие, чтобы не переключить галочку.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useId, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Checkbox005Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  text?: string
  linkLabel?: string
  linkHref?: string
  error?: string
  accent?: string
}

// Идея компонента: согласие с условиями. Галочка не проставлена заранее —
// предвыбранное согласие незаконно в ЕС и нечестно везде. Ссылка на документ
// живёт внутри подписи и остаётся отдельной целью: нажатие на неё не должно
// ставить галочку. Ошибка появляется под строкой и связана с полем.
const STYLES = `
:where([data-vibeui-block="checkbox-005"]){
--vibeui-checkbox-005-bg:oklch(1 0 0);
--vibeui-checkbox-005-fg:oklch(0.24 0.014 265);
--vibeui-checkbox-005-muted:oklch(0.56 0.014 265);
--vibeui-checkbox-005-border:oklch(0.88 0.008 265);
--vibeui-checkbox-005-accent:oklch(0.55 0.17 265);
--vibeui-checkbox-005-danger:oklch(0.56 0.19 25);
--vibeui-checkbox-005-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="checkbox-005"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-checkbox-005-bg);
border:1px solid var(--vibeui-checkbox-005-border);border-radius:0.875rem;
font-family:var(--vibeui-checkbox-005-font);color:var(--vibeui-checkbox-005-fg);
}
[data-vibeui-block="checkbox-005"] [data-part="row"]{display:flex;align-items:flex-start;gap:0.5rem}
[data-vibeui-block="checkbox-005"] input{
appearance:none;flex:none;cursor:pointer;position:relative;
width:1.125rem;height:1.125rem;margin:0.125rem 0 0;box-sizing:border-box;
border:1.5px solid var(--vibeui-checkbox-005-border);border-radius:0.3125rem;
background:var(--vibeui-checkbox-005-bg);
}
[data-vibeui-block="checkbox-005"] input:checked{border-color:transparent;background:var(--vibeui-checkbox-005-accent)}
[data-vibeui-block="checkbox-005"] input:checked::after{
content:"";position:absolute;left:50%;top:50%;
width:0.25rem;height:0.4375rem;margin:-0.3125rem 0 0 -0.125rem;
border-right:2px solid oklch(0.99 0.01 265);border-bottom:2px solid oklch(0.99 0.01 265);
transform:rotate(45deg);
}
[data-vibeui-block="checkbox-005"] input:focus-visible{outline:2px solid var(--vibeui-checkbox-005-accent);outline-offset:2px}
[data-vibeui-block="checkbox-005"][data-error="true"] input{border-color:var(--vibeui-checkbox-005-danger)}
[data-vibeui-block="checkbox-005"] label{font-size:0.8125rem;line-height:1.45;cursor:pointer}
/* Ссылка внутри подписи — отдельная цель: нажатие на неё не должно ставить
   галочку, поэтому клик по ней не всплывает до label. */
[data-vibeui-block="checkbox-005"] a{color:var(--vibeui-checkbox-005-accent);text-decoration:underline;text-underline-offset:2px}
[data-vibeui-block="checkbox-005"] a:focus-visible{outline:2px solid var(--vibeui-checkbox-005-accent);outline-offset:2px;border-radius:0.25rem}
[data-vibeui-block="checkbox-005"] [data-part="error"]{
display:flex;align-items:center;gap:0.375rem;padding-left:1.625rem;
font-size:0.75rem;font-weight:600;color:var(--vibeui-checkbox-005-danger);
}
[data-vibeui-block="checkbox-005"] [data-part="mark"]{
position:relative;flex:none;width:0.75rem;height:0.75rem;
border:1.5px solid currentColor;border-radius:9999px;
}
[data-vibeui-block="checkbox-005"] [data-part="mark"]::after{
content:"";position:absolute;left:50%;top:0.125rem;width:1.5px;height:0.3125rem;
margin-left:-0.75px;background:currentColor;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="checkbox-005"] *{animation:none!important;transition:none!important}}
`

/**
 * Согласие с условиями: галочка не проставлена заранее, ссылка отдельной целью.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Checkbox005({
  text = "Я прочитал и принимаю",
  linkLabel = "условия обработки данных",
  linkHref = "#",
  error = "Без согласия отправить форму не получится",
  accent,
  className,
  style,
  ...props
}: Checkbox005Props) {
  const id = useId()
  // Согласие никогда не проставлено заранее: предвыбранная галочка незаконна
  // в ЕС и нечестна везде.
  const [checked, setChecked] = useState(false)
  const [touched, setTouched] = useState(false)
  const invalid = touched && !checked

  const palette = {
    ...(accent ? { "--vibeui-checkbox-005-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-checkbox-005" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="checkbox-005"
        data-error={invalid}
        className={className}
        style={palette}
      >
        <div data-part="row">
          <input
            id={id}
            type="checkbox"
            checked={checked}
            aria-invalid={invalid}
            aria-describedby={invalid ? `${id}-error` : undefined}
            onChange={(event) => {
              setChecked(event.target.checked)
              setTouched(true)
            }}
          />
          <label htmlFor={id}>
            {text}{" "}
            <a href={linkHref} onClick={(event) => event.stopPropagation()}>
              {linkLabel}
            </a>
            .
          </label>
        </div>
        {invalid ? (
          <p data-part="error" id={`${id}-error`} role="alert">
            <span data-part="mark" aria-hidden="true" />
            {error}
          </p>
        ) : null}
      </div>
    </>
  )
}