# SoundToggle

> Opt-in interface sound: a `sound` controller that synthesises eleven short cues (hover, press, toggle-on, toggle-off, open, close, select, success, error, tick, copy) with the Web Audio API, a SoundToggle switch that keeps the preference and volume, and a soundFeedback action that wires cues to any element — silent until the user switches it on, nothing on import, mount, navigation or scroll.

- Package: `fancy-ui-vue` (Vue 3.5+ + Tailwind CSS v4)
- Category: Actions
- Tags: sound, audio, feedback, web-audio, cues, toggle, accessibility, opt-in
- Types: `SoundToggleProps`, `SoundToggleSize`, `SoundToggleVariant`, `SoundController`, `SoundFeedbackOptions`, `SoundCueResolver`, `SoundCueSpec`, `SoundControls`, `SoundState`, `SoundEngine`, `SoundEngineOptions`, `SoundCue`, `SoundThemeName`, `SoundPlayOptions`, `SoundPreferences`, `SoundPreferencesV1`, `SoundStatus`, `SoundEngineState`, `SoundThemeDefinition`, `CueRecipe`, `SoundLayer`, `SoundOscillatorLayer`, `SoundNoiseLayer`, `SoundEnvelope`, `SoundFilter`, `SoundWave`
- Docs: https://fancy-ui.rama.app/docs/components/sound
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/vue/src/sound

## Import

```vue
<script setup lang="ts">
import { SoundToggle } from 'fancy-ui-vue';
</script>
```

Setup (once per project): `npm install fancy-ui-vue`, then put these lines in your main CSS file (the stylesheet imports go right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-vue/tailwind.css";
@import "fancy-ui-vue/styles.css";
```

Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in a Vue template; when one differs from the Svelte name, the Svelte name follows in parentheses. Snippets become named slots (`#default` is the default snippet), a prop the Vue port declares as a model is a `v-model:<name>` (except `ref`, exposed via `defineExpose({ ref })`: put a template ref on the component and read `.ref`) and callbacks are listeners (`onclick` is `@click`). Every component sets `inheritAttrs: false`: `class` is a declared prop, merged where the Svelte component applies it (not always the root element), and only when the props table below lists it; other attributes do not fall through unless the package README lists the component as forwarding native attributes. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/vue#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Height of the control — md matches the other header-style triggers |
| `variant` | `"outline" \| "ghost"` | `"outline"` | Outline keeps a resting border; ghost shows one only on hover |
| `showLabel` | `boolean` | `false` | Renders the label and the On/Off word beside the icon; icon-only otherwise, with the label as the accessible name |
| `label` | `string` | `"Sound"` | Accessible name of the switch. Stays constant — the on/off state is announced through aria-checked |
| `labelOn` | `string` | `"On"` | Visible state word when showLabel is set |
| `labelOff` | `string` | `"Off"` | Visible state word when showLabel is set |
| `disabled` | `boolean` | `false` | Disables the control. A browser with no Web Audio also disables it, but only while sound is off, so a stored on preference can always be undone |
| `@enabled-change` (Svelte `onEnabledChange`) | `(enabled: boolean) => void` | — | Called after the preference flips, with the new value |
| `class` | `string` | — | Additional CSS classes for the button |
| `ref` | `HTMLButtonElement \| null` | `null` | Bindable reference to the button |
| `sound.play(cue, options?)` | `(cue: SoundCue, options?: SoundPlayOptions) => void` | — | Plays one cue. A no-op while sound is off or unsupported, so call sites never branch; options carry volume, pitch and playbackRate |
| `sound.enable() / disable() / toggle()` | `() => void \| boolean` | — | Flip the preference. Enabling creates and resumes the audio context inside the calling user gesture |
| `sound.setVolume(v)` | `(v: number) => void` | — | Master volume, 0 to 1, persisted with the preference |
| `sound.enabled / volume / status` | `boolean / number / SoundStatus` | — | Reactive preference and engine state (supported, engine, storage, lastCue, lastError) for your own UI |
| `sound.subscribe(run)` | `(run: (prefs: SoundPreferences) => void) => () => void` | — | Store contract for non-rune consumers; sound.enabled is the idiomatic path |
| `useSoundFeedback` (Svelte `use:soundFeedback`) | `SoundFeedbackOptions` | — | Action mapping element events to cues — defaults to click → press; add pointerenter → hover to opt in. Rebinds on update and unwires on destroy |
| `sound (on Button, CopyButton, Checkbox, Switch, RadioGroup, Select, DropdownMenu)` | `boolean` | `false` | Per-instance opt-in: the component plays its own matching cue (press, copy/error, toggle-on/off, select, open/close) once the user has enabled sound |

## Example

No Vue example is published for this component yet: start from the import above and the props table. The full examples are Svelte-only, on https://fancy-ui.rama.app/docs/components/sound.md.
