Toggle

Mute Toggle

A mute button with two state icons: both live in the markup and the one matching aria-pressed is shown.

  • toggle
  • mute
  • icon-state
  • audio

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

Звук включён

Громкость 64%

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-005" (Mute 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-005.json

Registry item: https://vibeui.ru/r/toggle-005.json
Installs to: components/vibeui/toggle-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 mute button with two state icons: both live in the markup and the one matching aria-pressed is shown.

A mute button with two state icons and a dimmed volume bar; the icon is selected by the same aria-pressed. One file, zero dependencies.

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

<Toggle005
  label="Mute"
  volume={64}
  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-005-* palette — do not swap it for your theme tokens
- picking the icon by an aria-pressed selector: the picture then cannot lie about the state
- the constant button name: the state changes, not the element's name
- the role="status" line: it states the condition in words, not by an icon
- the dimmed volume bar — a second cue for muted sound beyond the icon
- the card's own light surface: dark text must bring its own background

## 6. You may change
- the button name through label
- the volume level through volume
- the initial state through defaultPressed
- the bar and focus colour through accent

## 7. Rules
- Both icons always sit in the DOM — that is the price of switching without JS branching.
- volume is not reset to zero on mute: the level is remembered, as in media players.
- Do not replace the button with a switch: sound is muted instantly, not configured for later.
- 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-005.json
https://vibeui.ru/r/toggle-005.json

Один файл, ноль зависимостей, палитра --vibeui-toggle-005-*. Клиентский: useState. Приём: два <svg> всегда в разметке, а видимость выбирается селекторами button[aria-pressed="false"] [data-part="sound"] и button[aria-pressed="true"] [data-part="silent"] — значок не может разойтись с состоянием, потому что источник у них один атрибут. Имя кнопки остаётся постоянным, состояние проговаривает строка role="status". Полоса громкости гаснет через data-muted на корне: состояние обязано читаться не только по значку. Это toggle: звук выключается сразу, а не после подтверждения.

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

// Идея компонента: toggle с двумя значками состояния. Оба лежат в разметке,
// показывается тот, что совпал с aria-pressed, — картинка не может разойтись
// с состоянием, потому что источник у них один атрибут.
const STYLES = `
:where([data-vibeui-block="toggle-005"]){
--vibeui-toggle-005-bg:oklch(1 0 0);
--vibeui-toggle-005-fg:oklch(0.22 0.014 265);
--vibeui-toggle-005-muted:oklch(0.56 0.014 265);
--vibeui-toggle-005-border:oklch(0.9 0.006 265);
--vibeui-toggle-005-accent:oklch(0.55 0.17 285);
--vibeui-toggle-005-track:oklch(0.93 0.006 265);
--vibeui-toggle-005-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="toggle-005"]{
box-sizing:border-box;display:flex;align-items:center;gap:0.75rem;
width:100%;max-width:21rem;padding:0.75rem 0.875rem;
border:1px solid var(--vibeui-toggle-005-border);border-radius:0.875rem;
background:var(--vibeui-toggle-005-bg);color:var(--vibeui-toggle-005-fg);
font-family:var(--vibeui-toggle-005-font);
}
[data-vibeui-block="toggle-005"] *{box-sizing:border-box}
[data-vibeui-block="toggle-005"] button{
appearance:none;cursor:pointer;font:inherit;flex:none;
display:inline-flex;align-items:center;justify-content:center;
width:2.5rem;height:2.5rem;padding:0;
border:1px solid var(--vibeui-toggle-005-border);border-radius:0.75rem;
background:var(--vibeui-toggle-005-bg);color:var(--vibeui-toggle-005-fg);
transition:background-color .16s ease,color .16s ease,border-color .16s ease;
}
[data-vibeui-block="toggle-005"] button:focus-visible{
outline:2px solid var(--vibeui-toggle-005-accent);outline-offset:2px;
}
[data-vibeui-block="toggle-005"] button[aria-pressed="true"]{
background:var(--vibeui-toggle-005-fg);border-color:var(--vibeui-toggle-005-fg);
color:oklch(0.99 0 0);
}
[data-vibeui-block="toggle-005"] svg{width:1.1875rem;height:1.1875rem;display:none}
[data-vibeui-block="toggle-005"] button[aria-pressed="false"] [data-part="sound"]{display:block}
[data-vibeui-block="toggle-005"] button[aria-pressed="true"] [data-part="silent"]{display:block}
[data-vibeui-block="toggle-005"] [data-part="text"]{flex:1;min-width:0}
[data-vibeui-block="toggle-005"] [data-part="state"]{
margin:0;font-size:0.8125rem;font-weight:600;line-height:1.3;
}
[data-vibeui-block="toggle-005"] [data-part="meter"]{
display:block;margin-top:0.4375rem;height:0.375rem;border-radius:9999px;
background:var(--vibeui-toggle-005-track);overflow:hidden;
}
[data-vibeui-block="toggle-005"] [data-part="fill"]{
display:block;height:100%;border-radius:9999px;
background:var(--vibeui-toggle-005-accent);
transition:width .2s ease,background-color .2s ease;
}
/* Выключенный звук гасит и полосу: состояние обязано читаться не только по
   значку — иначе на беглом взгляде громкость выглядит рабочей. */
[data-vibeui-block="toggle-005"][data-muted="true"] [data-part="fill"]{
background:var(--vibeui-toggle-005-muted);opacity:.4;
}
[data-vibeui-block="toggle-005"] [data-part="value"]{
margin:0.25rem 0 0;font-size:0.75rem;color:var(--vibeui-toggle-005-muted);
font-variant-numeric:tabular-nums;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="toggle-005"] *{animation:none!important;transition:none!important}}
`

/**
 * Кнопка отключения звука с двумя значками состояния: показывается тот,
 * что совпал с aria-pressed. Один файл, ноль зависимостей.
 */
export function Toggle005({
  label = "Без звука",
  volume = 64,
  defaultPressed = false,
  onChange,
  accent,
  className,
  style,
  ...props
}: Toggle005Props) {
  const [pressed, setPressed] = useState(defaultPressed)

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

  return (
    <>
      <style href="vibeui-toggle-005" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="toggle-005"
        data-muted={pressed}
        className={className}
        style={palette}
      >
        <button
          type="button"
          aria-pressed={pressed}
          aria-label={label}
          title={label}
          onClick={() => {
            setPressed(!pressed)
            onChange?.(!pressed)
          }}
        >
          <svg
            data-part="sound"
            viewBox="0 0 20 20"
            fill="none"
            aria-hidden="true"
          >
            <path
              d="M4 7.5h2.5L10.5 4v12L6.5 12.5H4zM13.6 7a4 4 0 0 1 0 6M15.9 4.9a7 7 0 0 1 0 10.2"
              stroke="currentColor"
              strokeWidth="1.5"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
          </svg>
          <svg
            data-part="silent"
            viewBox="0 0 20 20"
            fill="none"
            aria-hidden="true"
          >
            <path
              d="M4 7.5h2.5L10.5 4v12L6.5 12.5H4zM14 8l4 4M18 8l-4 4"
              stroke="currentColor"
              strokeWidth="1.5"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
          </svg>
        </button>
        <div data-part="text">
          <p data-part="state" role="status">
            {pressed ? "Звук выключен" : "Звук включён"}
          </p>
          <span data-part="meter">
            <span data-part="fill" style={{ width: `${volume}%` }} />
          </span>
          <p data-part="value">
            {pressed ? "Громкость сохранена" : "Громкость"} {volume}%
          </p>
        </div>
      </div>
    </>
  )
}