Toggle

Pin Toggle

A toggle with an icon and a stable caption: the caption stays the name of the action, and the result is announced by a live line under the button.

  • toggle
  • aria-pressed
  • pin
  • icon

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-002?lang=en

Pinned to the top of the list

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-002" (Pin 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-002.json

Registry item: https://vibeui.ru/r/toggle-002.json
Installs to: components/vibeui/toggle-002.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 toggle with an icon and a stable caption: the caption stays the name of the action, and the result is announced by a live line under the button.

A toggle with an icon and an unchanging caption: aria-pressed declares the state, a role="status" line reports the result. One file, zero dependencies, client component.

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

<Toggle002
  label="Pin"
  onLabel="Pinned to the top of the list"
  defaultPressed
/>

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-002-* palette — do not swap it for your theme tokens
- the unchanging caption: an element's name must not change along with its state
- the role="status" line under the button — it speaks the result the name cannot carry
- three simultaneous cues for the pressed state (filled icon, background, text): one colour is not read by everyone
- aria-pressed instead of checked: pinning applies at once, not on form submit
- the card's own light surface: dark text must bring its own background

## 6. You may change
- the button name through label
- the result text through onLabel
- the initial state through defaultPressed
- the pressed colour through accent

## 7. Rules
- Do not turn the button into a switch: a switch is a setting for later, pinning changes the object now.
- The result line is announced on every change — keep it short.
- The icon is decorative (aria-hidden): meaning is carried by the caption and aria-pressed.
- 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-002.json
https://vibeui.ru/r/toggle-002.json

Один файл, ноль зависимостей, палитра --vibeui-toggle-002-*. Клиентский: useState. Подпись кнопки не меняется при нажатии — меняется только aria-pressed и живая строка role="status" под ней. Это осознанное решение: подпись — имя кнопки, и если её переписать на «Открепить», скринридер прочитает новое имя вместе с состоянием и получится «Открепить, нажато». Нажатое состояние показано тремя признаками сразу — заливкой значка (fill:currentColor у path), фоном и словом в строке, — потому что один цвет не читается при дальтонизме. В отличие от switch, действие применяется мгновенно и к конкретному объекту.

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 Toggle002Props = Omit<
  ComponentPropsWithoutRef<"button">,
  "children" | "onChange"
> & {
  label?: string
  onLabel?: string
  defaultPressed?: boolean
  onChange?: (pressed: boolean) => void
  accent?: string
}

// Идея компонента: toggle с иконкой и подписью, у которого подпись остаётся
// именем действия, а результат объявляется отдельной живой строкой. Менять
// подпись на «Откреплено» нельзя: скринридер прочитает новое имя и старое
// aria-pressed вместе, и получится «Откреплено, нажато».
const STYLES = `
:where([data-vibeui-block="toggle-002"]){
--vibeui-toggle-002-bg:oklch(1 0 0);
--vibeui-toggle-002-fg:oklch(0.24 0.014 265);
--vibeui-toggle-002-muted:oklch(0.55 0.014 265);
--vibeui-toggle-002-border:oklch(0.9 0.006 265);
--vibeui-toggle-002-accent:oklch(0.56 0.16 255);
--vibeui-toggle-002-soft:oklch(0.95 0.03 255);
--vibeui-toggle-002-radius:0.625rem;
--vibeui-toggle-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="toggle-002"]{
box-sizing:border-box;display:inline-flex;flex-direction:column;align-items:flex-start;gap:0.5rem;
padding:0.75rem;max-width:18rem;
border:1px solid var(--vibeui-toggle-002-border);border-radius:0.875rem;
background:var(--vibeui-toggle-002-bg);color:var(--vibeui-toggle-002-fg);
font-family:var(--vibeui-toggle-002-font);
}
[data-vibeui-block="toggle-002"] *{box-sizing:border-box}
[data-vibeui-block="toggle-002"] [data-part="button"]{
appearance:none;cursor:pointer;font:inherit;
display:inline-flex;align-items:center;gap:0.5rem;
height:2.25rem;padding:0 0.875rem;
border:1px solid var(--vibeui-toggle-002-border);
border-radius:var(--vibeui-toggle-002-radius);
background:var(--vibeui-toggle-002-bg);color:var(--vibeui-toggle-002-fg);
font-size:0.875rem;font-weight:600;line-height:1;
transition:background-color .16s ease,border-color .16s ease,color .16s ease;
}
[data-vibeui-block="toggle-002"] [data-part="button"]:hover{border-color:var(--vibeui-toggle-002-accent)}
[data-vibeui-block="toggle-002"] [data-part="button"]:focus-visible{
outline:2px solid var(--vibeui-toggle-002-accent);outline-offset:2px;
}
[data-vibeui-block="toggle-002"] svg{width:1rem;height:1rem;flex:none}
[data-vibeui-block="toggle-002"] [data-part="button"] svg path{
fill:none;stroke:currentColor;stroke-width:1.5;stroke-linejoin:round;stroke-linecap:round;
transition:fill .16s ease;
}
/* Нажатое состояние читается тремя способами разом: заливкой значка, фоном
   и словом в строке ниже. Один цвет на тёмном фоне карточки не читается. */
[data-vibeui-block="toggle-002"] [data-part="button"][aria-pressed="true"]{
background:var(--vibeui-toggle-002-soft);
border-color:var(--vibeui-toggle-002-accent);
color:var(--vibeui-toggle-002-accent);
}
[data-vibeui-block="toggle-002"] [data-part="button"][aria-pressed="true"] svg path{fill:currentColor}
[data-vibeui-block="toggle-002"] [data-part="state"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-toggle-002-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="toggle-002"] *{animation:none!important;transition:none!important}}
`

/**
 * Toggle с иконкой и постоянной подписью: состояние объявляет aria-pressed,
 * а результат — живая строка под кнопкой. Один файл, ноль зависимостей.
 */
export function Toggle002({
  label = "Закрепить",
  onLabel = "Закреплено вверху списка",
  defaultPressed = true,
  onChange,
  accent,
  className,
  style,
  ...props
}: Toggle002Props) {
  const [pressed, setPressed] = useState(defaultPressed)

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

  return (
    <>
      <style href="vibeui-toggle-002" precedence="medium">
        {STYLES}
      </style>
      <div data-vibeui-block="toggle-002" className={className} style={palette}>
        <button
          {...props}
          type="button"
          data-part="button"
          aria-pressed={pressed}
          onClick={() => {
            setPressed(!pressed)
            onChange?.(!pressed)
          }}
        >
          <svg viewBox="0 0 24 24" aria-hidden="true">
            <path d="M16 3H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1v2.8a2 2 0 0 1-1.1 1.8l-1.8.9A2 2 0 0 0 5 15.3V16h14v-.7a2 2 0 0 0-1.1-1.8l-1.8-.9A2 2 0 0 1 15 10.8V8a1 1 0 0 1 1-1 2 2 0 0 0 0-4Z" />
            <path d="M12 16v5" />
          </svg>
          {label}
        </button>
        <p data-part="state" role="status">
          {pressed ? onLabel : "Не закреплено"}
        </p>
      </div>
    </>
  )
}