UNPKG

react-sounds

Version:

A library of ready-to-play sound effects for React applications.

107 lines (106 loc) 2.95 kB
import React, { ReactNode } from "react"; import { SoundName } from "./runtime"; import { SoundOptions } from "./types"; /** * Props for the Sound component */ interface SoundProps { /** * The sound to play (will use local bundled sounds if available) */ name: SoundName; /** * When to play the sound */ trigger?: "mount" | "unmount" | "none"; /** * Sound playback options */ options?: SoundOptions; /** * Children components */ children?: ReactNode; /** * Event handler for when the sound is loaded */ onLoad?: () => void; /** * Event handler for when the sound is played */ onPlay?: () => void; /** * Event handler for when the sound is stopped */ onStop?: () => void; /** * Event handler for when the sound fails to play */ onError?: (error: Error) => void; } /** * A component for playing a sound. * Will use locally downloaded sounds if available before falling back to CDN. */ export declare function Sound({ name, trigger, options, children, onLoad, onPlay, onStop, onError, }: SoundProps): React.ReactElement; /** * Props for the SoundButton component */ interface SoundButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { /** * The sound to play when clicked (will use local bundled sounds if available) */ sound: SoundName; /** * Sound playback options */ soundOptions?: SoundOptions; /** * Children components */ children?: ReactNode; /** * Event handler for when the sound fails to play */ onSoundError?: (error: Error) => void; } /** * A button that plays a sound when clicked. * Will use locally downloaded sounds if available before falling back to CDN. */ export declare function SoundButton({ sound, soundOptions, children, onClick, onSoundError, ...props }: SoundButtonProps): React.ReactElement; /** * Sound context for managing sound state */ interface SoundContextType { enabled: boolean; setEnabled: (enabled: boolean) => void; } export declare const SoundContext: React.Context<SoundContextType | null>; /** * Props for the SoundProvider component */ interface SoundProviderProps { /** * Sounds to preload (will use local bundled sounds if available) */ preload?: SoundName[]; /** * Initial sound enabled state (uses localStorage if not provided) */ initialEnabled?: boolean; /** * How often to clean up unused sounds (in ms), set to 0 to disable */ cleanupInterval?: number; /** * Children components */ children: ReactNode; } /** * A provider that manages sound state and preloads sounds. * Will use locally downloaded sounds if available before falling back to CDN. */ export declare function SoundProvider({ preload, initialEnabled, children }: SoundProviderProps): React.ReactElement; export {};