Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Shared
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Hooks
Resources
useSound
Named sound effects with mute toggle.
A React hook that plays named sound effects from a { name: src } library. Caches Audio elements, resets playback per trigger, and persists mute state (via use-local-storage).
Installation
pnpm dlx shadcn@latest add @frontal-labs/use-sound
Usage
import { useSound } from "@/hooks/use-sound";
const sounds = {
pop: "/sounds/pop.mp3",
success: "/sounds/success.mp3",
} as const;
function Toolbar() {
const { play, muted, setMuted } = useSound(sounds);
return (
<>
<button onClick={() => play("pop")}>Pop</button>
<button onClick={() => play("success", { volume: 0.5 })}>Quiet success</button>
<button onClick={() => setMuted(!muted)}>{muted ? "Unmute" : "Mute"}</button>
</>
);
}Playback failures (autoplay policy, missing file) are swallowed. volume is clamped to 0–1.
API
function useSound<TLibrary extends Record<string, string>>(
library: TLibrary,
): {
play: (name: keyof TLibrary & string, opts?: { volume?: number }) => void;
muted: boolean;
setMuted: Dispatch<SetStateAction<boolean>>;
};Parameters
| Property | Type | Description |
|---|---|---|
library | Record<string, string> | Map of sound name to audio src. Use as const for typed play names. |
Return value
| Property | Type | Description |
|---|---|---|
play | (name, opts?) => void | Plays the sound. No-op when muted. Restarts the cached element from currentTime = 0. |
muted | boolean | Persisted under frontal:sound-muted. |
setMuted | Dispatch<SetStateAction<boolean>> | Toggles mute. |
On This Page