Toggle

Bold Toggle

A bold toggle above a text sample: pressing it restyles the sample at once, so it reads as an action on an object rather than a form setting.

  • toggle
  • aria-pressed
  • formatting
  • editor

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/toggle-001?lang=en

Bold

Draft letter to the client

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 "toggle-001" (Bold Toggle) 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/toggle-001.json

Registry item: https://vibeui.ru/r/toggle-001.json
Installs to: components/vibeui/toggle-001.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 bold toggle above a text sample: pressing it restyles the sample at once, so it reads as an action on an object rather than a form setting.

A bold toggle button with the sample text next to it: aria-pressed drives both the state and the look, and the sample changes instantly. One file, zero dependencies, client component.

## 3. How to use it
import { Toggle001 } from "@/components/vibeui/toggle-001"

<Toggle001
  text="Draft letter to the client"
  label="Bold"
  defaultPressed={false}
/>

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-toggle-001-* palette — do not swap it for your theme tokens
- aria-pressed as the only source of state: without it the button sounds like a plain action
- styling through button[aria-pressed="true"], otherwise the look and the markup drift apart
- the instant effect on the sample: a toggle does not queue changes until a Save button
- the visible focus ring: this button is used from the keyboard more often than it seems
- the panel's own light surface: without it the dark text disappears on a dark background

## 6. You may change
- the sample text through text
- the button name through label — it also becomes aria-label and title
- the initial state through defaultPressed
- the pressed colour through accent

## 7. Rules
- Do not replace aria-pressed with a checkbox: a form checkbox means a choice, not an action on text.
- Do not change the caption on press — a screen reader reads the new name together with the old state.
- For a setting that turns on a mode for later, use a switch instead of this component.
- 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/toggle-001.json
https://vibeui.ru/r/toggle-001.json

Один файл, ноль зависимостей, собственная палитра --vibeui-toggle-001-*. Клиентский: состояние держит useState. Кнопка объявляет состояние через aria-pressed, а не через checked: toggle — мгновенное действие над видом или объектом (сделать выделение жирным), switch — настройка, которая включает режим, checkbox — поле формы, которое уедет на сервер при отправке. Вид нажатой кнопки выбирается селектором button[aria-pressed="true"], поэтому разметка и стиль не могут разойтись. Образец текста лежит рядом и получает font-weight через data-bold на корне — эффект виден в тот же миг.

Component source

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

"use client"

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

export type Toggle001Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  text?: string
  label?: string
  defaultPressed?: boolean
  onChange?: (pressed: boolean) => void
  accent?: string
}

// Идея компонента: показать toggle рядом с тем, чем он управляет. Кнопка
// начертания меняет образец текста в тот же миг — это действие над объектом,
// а не настройка, которую применяют кнопкой «Сохранить». Состояние объявлено
// через aria-pressed, потому что чекбокс здесь означал бы поле формы.
const STYLES = `
:where([data-vibeui-block="toggle-001"]){
--vibeui-toggle-001-bg:oklch(1 0 0);
--vibeui-toggle-001-fg:oklch(0.22 0.014 265);
--vibeui-toggle-001-muted:oklch(0.55 0.014 265);
--vibeui-toggle-001-border:oklch(0.9 0.006 265);
--vibeui-toggle-001-hover:oklch(0.97 0.004 265);
--vibeui-toggle-001-accent:oklch(0.5 0.02 265);
--vibeui-toggle-001-on:oklch(0.99 0 0);
--vibeui-toggle-001-radius:0.5rem;
--vibeui-toggle-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="toggle-001"]{
box-sizing:border-box;display:flex;flex-direction:column;gap:0.75rem;
width:100%;max-width:22rem;padding:0.875rem;
border:1px solid var(--vibeui-toggle-001-border);border-radius:0.875rem;
background:var(--vibeui-toggle-001-bg);color:var(--vibeui-toggle-001-fg);
font-family:var(--vibeui-toggle-001-font);
}
[data-vibeui-block="toggle-001"] *{box-sizing:border-box}
[data-vibeui-block="toggle-001"] [data-part="bar"]{
display:flex;align-items:center;gap:0.625rem;
}
[data-vibeui-block="toggle-001"] button{
appearance:none;cursor:pointer;font:inherit;flex:none;
display:inline-flex;align-items:center;justify-content:center;
width:2.125rem;height:2.125rem;padding:0;
border:1px solid var(--vibeui-toggle-001-border);
border-radius:var(--vibeui-toggle-001-radius);
background:var(--vibeui-toggle-001-bg);color:var(--vibeui-toggle-001-fg);
transition:background-color .15s ease,color .15s ease,border-color .15s ease;
}
[data-vibeui-block="toggle-001"] button svg{width:1.0625rem;height:1.0625rem}
[data-vibeui-block="toggle-001"] button:hover{background:var(--vibeui-toggle-001-hover)}
[data-vibeui-block="toggle-001"] button:focus-visible{
outline:2px solid var(--vibeui-toggle-001-accent);outline-offset:2px;
}
/* Вид берётся из того же атрибута, который читает скринридер: разойтись
   картинке и разметке негде. */
[data-vibeui-block="toggle-001"] button[aria-pressed="true"]{
background:var(--vibeui-toggle-001-accent);
border-color:var(--vibeui-toggle-001-accent);
color:var(--vibeui-toggle-001-on);
}
[data-vibeui-block="toggle-001"] [data-part="hint"]{
margin:0;font-size:0.75rem;color:var(--vibeui-toggle-001-muted);
}
[data-vibeui-block="toggle-001"] [data-part="sample"]{
margin:0;padding:0.625rem 0.75rem;border-radius:0.625rem;
background:var(--vibeui-toggle-001-hover);
font-size:0.9375rem;line-height:1.5;font-weight:400;
}
[data-vibeui-block="toggle-001"][data-bold="true"] [data-part="sample"]{font-weight:700}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="toggle-001"] *{animation:none!important;transition:none!important}}
`

/**
 * Кнопка начертания над образцом текста: нажатие меняет образец сразу.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Toggle001({
  text = "Черновик письма клиенту",
  label = "Полужирный",
  defaultPressed = false,
  onChange,
  accent,
  className,
  style,
  ...props
}: Toggle001Props) {
  const [pressed, setPressed] = useState(defaultPressed)

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

  return (
    <>
      <style href="vibeui-toggle-001" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="toggle-001"
        data-bold={pressed}
        className={className}
        style={palette}
      >
        <div data-part="bar">
          <button
            type="button"
            aria-pressed={pressed}
            aria-label={label}
            title={label}
            onClick={() => {
              setPressed(!pressed)
              onChange?.(!pressed)
            }}
          >
            <svg viewBox="0 0 18 18" aria-hidden="true">
              <path
                d="M5.4 2.8h4.3a2.9 2.9 0 0 1 0 5.8H5.4zm0 5.8h5a3.1 3.1 0 0 1 0 6.2h-5z"
                fill="currentColor"
              />
            </svg>
          </button>
          <p data-part="hint">{label}</p>
        </div>
        <p data-part="sample">{text}</p>
      </div>
    </>
  )
}