{description}
15 |
26 | {children}
27 |
28 | );
29 | };
30 |
31 | export default CodeBlock;
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Aedilic Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/website/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-sounds-website",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "rm -rf dist/ && npm run sync && vite build",
9 | "start": "serve -s dist",
10 | "sync": "cp ../src/manifest.json ./src/",
11 | "lint": "eslint .",
12 | "preview": "vite preview"
13 | },
14 | "dependencies": {
15 | "clsx": "^2.1.1",
16 | "howler": "^2.2.4",
17 | "prismjs": "^1.30.0",
18 | "react": "^19.0.0",
19 | "react-dom": "^19.0.0",
20 | "react-router-dom": "^7.5.2",
21 | "react-sounds": "^1.0.25",
22 | "serve": "^14.2.1",
23 | "tailwind-merge": "^3.2.0"
24 | },
25 | "devDependencies": {
26 | "@eslint/js": "^9.22.0",
27 | "@tailwindcss/vite": "^4.1.4",
28 | "@types/prismjs": "^1.26.5",
29 | "@types/react": "^19.0.10",
30 | "@types/react-dom": "^19.0.4",
31 | "@typescript-eslint/eslint-plugin": "^8.31.1",
32 | "@typescript-eslint/parser": "^8.31.1",
33 | "@typescript-eslint/utils": "^8.31.1",
34 | "@vitejs/plugin-react": "^4.3.4",
35 | "autoprefixer": "^10.4.21",
36 | "eslint": "^9.25.1",
37 | "eslint-plugin-react-hooks": "^5.2.0",
38 | "eslint-plugin-react-refresh": "^0.4.19",
39 | "globals": "^16.0.0",
40 | "picomatch": "^4.0.2",
41 | "postcss": "^8.5.3",
42 | "tailwindcss": "^4.1.4",
43 | "typescript": "^5.3.3",
44 | "vite": "^6.3.1"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/website/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
15 |
16 |
17 |
21 |
22 |
23 |
24 |
4 |
5 |
6 |
7 |
10 | Hundreds of ready-to-play sound effects for your React applications
11 | Add delight to your UI with just a few lines of code
12 |
15 | Demo • 16 | Documentation • 17 | Sound Explorer 18 |
19 | 20 | ## ✨ Why react-sounds? 21 | 22 | - 🪶 **Lightweight**: Only loads JS wrappers, audio files stay on CDN until needed 23 | - 🔄 **Lazy Loading**: Sounds are fetched only when they're used 24 | - 📦 **Offline Support**: Download sounds for self-hosting with the included CLI 25 | - 🎯 **Simple API**: Intuitive hooks and components 26 | - 🔊 **Extensive Library**: Hundreds of categorized sounds (UI, notification, game) 27 | 28 | ## 🚀 Quick Start 29 | 30 | ```bash 31 | npm install react-sounds howler 32 | # or 33 | yarn add react-sounds howler 34 | ``` 35 | 36 | ```tsx 37 | import { useSound } from 'react-sounds'; 38 | 39 | function Button() { 40 | const { play } = useSound('ui/button_1'); 41 | 42 | return ( 43 | 46 | ); 47 | } 48 | ``` 49 | 50 | ## 📚 Documentation 51 | 52 | For complete documentation including advanced usage, visit [reactsounds.com/docs](https://www.reactsounds.com/docs) 53 | 54 | ## 🎮 Live Demo 55 | 56 | Try the interactive demo at [reactsounds.com](https://www.reactsounds.com) 57 | 58 | ## 🔍 Explore All Sounds 59 | 60 | Browse and play all available sounds at [reactsounds.com/sounds](https://www.reactsounds.com/sounds) 61 | 62 | ## 💻 Browser Support 63 | 64 | Works in all modern browsers that support the Web Audio API (Chrome, Firefox, Safari, Edge) 65 | 66 | ## 📄 License 67 | 68 | MIT © Aedilic Inc. 69 | 70 | --- 71 | 72 |73 | Made with ♥ by Aedilic Inc 74 |
75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # vitepress build output 108 | **/.vitepress/dist 109 | 110 | # vitepress cache directory 111 | **/.vitepress/cache 112 | 113 | # Docusaurus cache and generated files 114 | .docusaurus 115 | 116 | # Serverless directories 117 | .serverless/ 118 | 119 | # FuseBox cache 120 | .fusebox/ 121 | 122 | # DynamoDB Local files 123 | .dynamodb/ 124 | 125 | # TernJS port file 126 | .tern-port 127 | 128 | # Stores VSCode versions used for testing VSCode extensions 129 | .vscode-test 130 | 131 | # yarn v2 132 | .yarn/cache 133 | .yarn/unplugged 134 | .yarn/build-state.yml 135 | .yarn/install-state.gz 136 | .pnp.* 137 | 138 | # custom 139 | .cursor/ 140 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Categories of sounds available in the library 4 | */ 5 | export type SoundCategory = 'ambient' | 'arcade' | 'game' | 'misc' | 'notification' | 'system' | 'ui'; 6 | 7 | /** 8 | * AmbientSoundName sound names 9 | */ 10 | export type AmbientSoundName = 'campfire' | 'heartbeat' | 'rain' | 'water_stream' | 'wind'; 11 | 12 | /** 13 | * ArcadeSoundName sound names 14 | */ 15 | export type ArcadeSoundName = 'coin' | 'coin_bling' | 'jump' | 'level_down' | 'level_up' | 'power_down' | 'power_up' | 'upgrade'; 16 | 17 | /** 18 | * GameSoundName sound names 19 | */ 20 | export type GameSoundName = 'coin' | 'hit' | 'miss' | 'portal_closing' | 'portal_opening' | 'void'; 21 | 22 | /** 23 | * MiscSoundName sound names 24 | */ 25 | export type MiscSoundName = 'silence'; 26 | 27 | /** 28 | * NotificationSoundName sound names 29 | */ 30 | export type NotificationSoundName = 'completed' | 'error' | 'info' | 'message' | 'notification' | 'popup' | 'reminder' | 'success' | 'warning'; 31 | 32 | /** 33 | * SystemSoundName sound names 34 | */ 35 | export type SystemSoundName = 'boot_down' | 'boot_up' | 'device_connect' | 'device_disconnect' | 'lock' | 'screenshot' | 'trash'; 36 | 37 | /** 38 | * UiSoundName sound names 39 | */ 40 | export type UiSoundName = 'blocked' | 'button_hard' | 'button_hard_double' | 'button_medium' | 'button_soft' | 'button_soft_double' | 'button_squishy' | 'buzz' | 'buzz_deep' | 'buzz_long' | 'copy' | 'input_blur' | 'input_focus' | 'item_deselect' | 'item_select' | 'keystroke_hard' | 'keystroke_medium' | 'keystroke_soft' | 'panel_collapse' | 'panel_expand' | 'pop_close' | 'pop_open' | 'popup_close' | 'popup_open' | 'radio_select' | 'send' | 'submit' | 'success_bling' | 'success_blip' | 'success_chime' | 'tab_close' | 'tab_open' | 'toggle_off' | 'toggle_on' | 'window_close' | 'window_open'; 41 | 42 | /** 43 | * All available sound names 44 | */ 45 | export type LibrarySoundName = 46 | | `ambient/${AmbientSoundName}` 47 | | `arcade/${ArcadeSoundName}` 48 | | `game/${GameSoundName}` 49 | | `misc/${MiscSoundName}` 50 | | `notification/${NotificationSoundName}` 51 | | `system/${SystemSoundName}` 52 | | `ui/${UiSoundName}`; 53 | 54 | /** 55 | * Sound options for playback 56 | */ 57 | export interface SoundOptions { 58 | /** 59 | * Volume of the sound (0.0 to 1.0) 60 | */ 61 | volume?: number; 62 | 63 | /** 64 | * Playback rate (1.0 is normal speed) 65 | */ 66 | rate?: number; 67 | 68 | /** 69 | * Sound should loop 70 | */ 71 | loop?: boolean; 72 | } 73 | 74 | /** 75 | * Return type for useSound hook 76 | */ 77 | export interface SoundHookReturn { 78 | /** 79 | * Play the sound with optional options 80 | */ 81 | play: (options?: SoundOptions) => Promise
103 | react-sounds provides a library of ready-to-play
104 | sound effects with a simple API, lazy loading, and offline support.
105 |
106 |
120 | MIT License
121 |
122 |
Check out the documentation or install the library now.
169 |Click the buttons to hear different sound effects.
46 |Try adjusting these parameters before playing the sound.
95 | 96 |{category.description}
203 |
49 | react-sounds provides a library of
50 | ready-to-play sound effects for your React applications, designed to be lightweight, easy to use, and
51 | flexible. It's built on top of Howler.js and provides a simple API for playing sounds in your React apps.
52 |
Install the library and its peer dependency, Howler.js:
90 |96 | Note:{" "} 97 | 103 | Howler.js 104 | {" "} 105 | is a required peer dependency. 106 |
107 |useSound Hook
115 |
117 | The useSound hook is the primary way to
118 | interact with sounds.
119 |
You can use your own custom sound files by requiring them directly:
136 |playSound
154 | For simple, one-off sound playback without needing state or controls.
156 |SoundProvider
182 |
184 | For best results, wrap your application with the{" "}
185 | SoundProvider component. This allows control
186 | of sound enabled state, preloads sounds, and establishes the sound context.
187 |
useSound Hook
213 |
215 | The useSound hook provides full control over
216 | sound playback. It works with both built-in sound names and custom sound files.
217 |
For declarative sound playback within your components.
254 |Additional hooks for specific sound use cases.
293 |330 | Configure where built-in sound files are loaded from. Note: This doesn't affect custom sound files that you 331 | import directly. 332 |
333 |345 | Globally enable or disable all sounds. The setting is automatically persisted in localStorage. 346 |
347 |Preload sounds to ensure they are ready for immediate playback.
362 |Customize sound playback with various options.
374 |406 | Use the CLI tool to download sounds for offline use or explore available sounds. 407 |
408 |424 | react-sounds provides TypeScript definitions for all exported functions, hooks, components, and types. 425 |
426 | 427 |Sounds can be either built-in sound names or custom imported sound files.
429 |
457 | Type definition for what useSound hook
458 | returns.
459 |
219 | {soundKey}
220 |
221 | 379 | Showing {paginatedSounds.length} of {filteredSounds.length} sounds 380 | {selectedCategory && ( 381 | 388 | {selectedCategory[0].toUpperCase() + selectedCategory.slice(1)} 389 | 390 | )} 391 |
392 | 393 | {/* Pagination controls */} 394 | {totalPages > 1 && ( 395 |Try adjusting your search or filter to find what you're looking for.
458 |