Actions Core Stable

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

Preview

Installation

pnpm add fancy-ui-svelte
import { SoundToggle } from 'fancy-ui-svelte'

Usage

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

<SoundToggle />

Examples

Sound Lab

Every cue, its volume, and when to reach for it. Nothing plays until you switch sound on.

Programmatic Play

sound.play() from an async handler — a no-op while sound is off, so call sites never branch on it.

The soundFeedback Action

use:soundFeedback on any element, with cues swapped at runtime through the action's update path.

With Buttons

Button and CopyButton playing their own press and copy cues through the opt-in prop.

With Form Controls

Checkbox, Switch and RadioGroup — toggle-on, toggle-off and select.

With Menus

Select and DropdownMenu — open, close and select, one cue per interaction.

Props

PropTypeDefaultDescription
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 booleanfalseRenders 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 booleanfalseDisables 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
onEnabledChange (enabled: boolean) => void-Called after the preference flips, with the new value
class string-Additional CSS classes for the button
ref HTMLButtonElement | nullnullBindable 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
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) booleanfalsePer-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