Toggle

Hinted Toggle

A toggle with a hint about the current state: it is tied in with aria-describedby, appears on hover and on focus, and the button caption never changes.

  • toggle
  • tooltip
  • aria-describedby
  • hint

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

Notifications are hidden until morning

Подсказка объясняет состояние, а подпись кнопки не меняется.

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-008" (Hinted 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-008.json

Registry item: https://vibeui.ru/r/toggle-008.json
Installs to: components/vibeui/toggle-008.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 a hint about the current state: it is tied in with aria-describedby, appears on hover and on focus, and the button caption never changes.

A toggle with a hint about its current state: the hint lives in the markup, is tied in with aria-describedby and appears on hover and on focus. One file, zero dependencies.

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

<Toggle008
  label="Do not disturb"
  onHint="Notifications are hidden until morning"
  offHint="Notifications arrive as usual"
/>

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-008-* palette — do not swap it for your theme tokens
- aria-describedby on the hint: without it only the cursor ever sees the text
- showing the hint on both :hover and :focus-visible — the keyboard must not lose it
- the constant button caption: an element's name does not change with its state
- the panel's top padding: the hint floats above the button and must not be clipped
- the panel's own light surface: dark text must bring its own background

## 6. You may change
- the button caption through label
- the pressed-state hint through onHint
- the released-state hint through offHint
- the initial state through defaultPressed

## 7. Rules
- The hint lives inside the panel's flow: in a tight header it may lack room above.
- Do not move the text into title — the browser will not show it when tabbing.
- The hint describes the state, not a command: "Press to…" breaks the match between name and role.
- 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-008.json
https://vibeui.ru/r/toggle-008.json

Один файл, ноль зависимостей, палитра --vibeui-toggle-008-*. Клиентский: useState и useId для связи aria-describedby. Подсказка — обычный элемент разметки с role="tooltip", спрятанный видимостью и прозрачностью; показывается правилами button:hover + [data-part="tip"] и button:focus-visible + [data-part="tip"], поэтому доступна и мыши, и клавиатуре. Атрибут title тут не подошёл бы: браузер не показывает его по фокусу. Подпись кнопки постоянна, состояние несут aria-pressed и текст подсказки; сверху у панели есть запас на всплывающий слой.

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

// Идея компонента: toggle с подсказкой о текущем состоянии. Подсказка живёт
// в разметке всегда и привязана через aria-describedby, поэтому её слышит
// скринридер, а не только видит курсор. Всплывает она и по наведению, и по
// фокусу: подсказка, доступная одной мыши, — это подсказка для половины людей.
const STYLES = `
:where([data-vibeui-block="toggle-008"]){
--vibeui-toggle-008-bg:oklch(1 0 0);
--vibeui-toggle-008-fg:oklch(0.22 0.014 265);
--vibeui-toggle-008-muted:oklch(0.55 0.014 265);
--vibeui-toggle-008-border:oklch(0.9 0.006 265);
--vibeui-toggle-008-accent:oklch(0.55 0.16 25);
--vibeui-toggle-008-tip:oklch(0.24 0.02 265);
--vibeui-toggle-008-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="toggle-008"]{
box-sizing:border-box;display:flex;flex-direction:column;gap:0.5rem;align-items:flex-start;
width:100%;max-width:20rem;padding:2.75rem 0.875rem 0.875rem;
border:1px solid var(--vibeui-toggle-008-border);border-radius:0.875rem;
background:var(--vibeui-toggle-008-bg);color:var(--vibeui-toggle-008-fg);
font-family:var(--vibeui-toggle-008-font);
}
[data-vibeui-block="toggle-008"] *{box-sizing:border-box}
[data-vibeui-block="toggle-008"] [data-part="anchor"]{position:relative;display:inline-flex}
[data-vibeui-block="toggle-008"] 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-008-border);border-radius:0.625rem;
background:var(--vibeui-toggle-008-bg);color:var(--vibeui-toggle-008-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-008"] button:focus-visible{
outline:2px solid var(--vibeui-toggle-008-accent);outline-offset:2px;
}
[data-vibeui-block="toggle-008"] button[aria-pressed="true"]{
background:var(--vibeui-toggle-008-accent);border-color:var(--vibeui-toggle-008-accent);
color:oklch(0.99 0 0);
}
[data-vibeui-block="toggle-008"] [data-part="dot"]{
width:0.5rem;height:0.5rem;border-radius:50%;flex:none;
background:var(--vibeui-toggle-008-muted);
}
[data-vibeui-block="toggle-008"] button[aria-pressed="true"] [data-part="dot"]{background:oklch(0.99 0 0)}
/* Подсказка лежит в потоке разметки и просто прячется: вынести её в title
   значило бы отдать текст браузеру — с клавиатуры он не показывается. */
[data-vibeui-block="toggle-008"] [data-part="tip"]{
position:absolute;bottom:calc(100% + 0.5rem);left:0;
max-width:15rem;padding:0.375rem 0.5rem;border-radius:0.5rem;
background:var(--vibeui-toggle-008-tip);color:oklch(0.98 0 0);
font-size:0.75rem;line-height:1.35;white-space:normal;
opacity:0;visibility:hidden;transform:translateY(0.25rem);
transition:opacity .14s ease,transform .14s ease,visibility .14s;
}
[data-vibeui-block="toggle-008"] [data-part="tip"]::after{
content:"";position:absolute;top:100%;left:0.875rem;
border:0.3125rem solid transparent;border-top-color:var(--vibeui-toggle-008-tip);
}
[data-vibeui-block="toggle-008"] button:hover + [data-part="tip"],
[data-vibeui-block="toggle-008"] button:focus-visible + [data-part="tip"]{
opacity:1;visibility:visible;transform:translateY(0);
}
[data-vibeui-block="toggle-008"] [data-part="note"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-toggle-008-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="toggle-008"] *{animation:none!important;transition:none!important}}
`

/**
 * Toggle с подсказкой о текущем состоянии: она привязана через
 * aria-describedby и всплывает по наведению и по фокусу. Один файл.
 */
export function Toggle008({
  label = "Не беспокоить",
  onHint = "Сейчас уведомления скрыты до утра",
  offHint = "Сейчас уведомления приходят как обычно",
  defaultPressed = true,
  onChange,
  accent,
  className,
  style,
  ...props
}: Toggle008Props) {
  const [pressed, setPressed] = useState(defaultPressed)
  const tipId = useId()

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

  return (
    <>
      <style href="vibeui-toggle-008" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="toggle-008"
        className={className}
        style={palette}
      >
        <span data-part="anchor">
          <button
            type="button"
            aria-pressed={pressed}
            aria-describedby={tipId}
            onClick={() => {
              setPressed(!pressed)
              onChange?.(!pressed)
            }}
          >
            <span data-part="dot" aria-hidden="true" />
            {label}
          </button>
          <span data-part="tip" id={tipId} role="tooltip">
            {pressed ? onHint : offHint}
          </span>
        </span>
        <p data-part="note">
          Подсказка объясняет состояние, а подпись кнопки не меняется.
        </p>
      </div>
    </>
  )
}