react-ui-sound-events 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,240 @@
1
+ # ðŸŽķ react-ui-sound-events
2
+
3
+ A lightweight and powerful sound-feedback system for **React & Next.js**
4
+ applications.\
5
+ Easily play different sounds for **login, logout, success, error, toast
6
+ notifications, and UI events** to enhance user experience and
7
+ accessibility.
8
+
9
+ ------------------------------------------------------------------------
10
+
11
+ ## 🚀 Why react-ui-sound-events?
12
+
13
+ Modern web apps rely heavily on visual feedback, but **audio feedback
14
+ adds clarity, delight, and accessibility**.
15
+
16
+ This package helps you: - Avoid rewriting sound logic in every project -
17
+ Centralize UI sound management - Improve UX with minimal effort - Add
18
+ premium, app-like interactions
19
+
20
+ ------------------------------------------------------------------------
21
+
22
+ ## âœĻ Features
23
+
24
+ - ðŸŽĩ Event-based sound playback
25
+ - ⚛ïļ Works with React & Next.js
26
+ - 🔔 Toastify sound integration
27
+ - 🧠 Centralized sound manager
28
+ - 🔊 Volume control
29
+ - â™ŧïļ Sound reuse & preload
30
+ - ðŸšŦ Browser autoplay-safe
31
+ - ðŸŠķ Lightweight & dependency-free
32
+
33
+ ------------------------------------------------------------------------
34
+
35
+ ## ðŸ“Ķ Installation
36
+
37
+ ``` bash
38
+ npm install react-ui-sound-events
39
+ ```
40
+
41
+ or
42
+
43
+ ``` bash
44
+ yarn add react-ui-sound-events
45
+ ```
46
+
47
+ ------------------------------------------------------------------------
48
+
49
+ ## ⚙ïļ Basic Setup (React)
50
+
51
+ Wrap your application once using `SoundProvider`.
52
+
53
+ ``` jsx
54
+ import { SoundProvider } from "react-ui-sound-events";
55
+
56
+ <SoundProvider
57
+ sounds={{
58
+ login: "/sounds/login.mp3",
59
+ logout: "/sounds/logout.mp3",
60
+ success: "/sounds/success.mp3",
61
+ error: "/sounds/error.mp3",
62
+ info: "/sounds/info.mp3",
63
+ }}
64
+ volume={0.8}
65
+ >
66
+ <App />
67
+ </SoundProvider>
68
+ ```
69
+
70
+ ------------------------------------------------------------------------
71
+
72
+ ## ðŸŽŪ Play Sounds Anywhere
73
+
74
+ Use the `useSound` hook inside any component.
75
+
76
+ ``` jsx
77
+ import { useSound } from "react-ui-sound-events";
78
+
79
+ const LoginButton = () => {
80
+ const { play } = useSound();
81
+
82
+ return (
83
+ <button onClick={() => play("login")}>
84
+ Login
85
+ </button>
86
+ );
87
+ };
88
+
89
+ export default LoginButton;
90
+ ```
91
+
92
+ ------------------------------------------------------------------------
93
+
94
+ ## 🔔 Toastify Integration (Auto Sound)
95
+
96
+ Automatically play sounds when using `react-toastify`.
97
+
98
+ ``` jsx
99
+ import { useSoundToast } from "react-ui-sound-events";
100
+
101
+ const Example = () => {
102
+ const toast = useSoundToast();
103
+
104
+ return (
105
+ <>
106
+ <button onClick={() => toast.success("Login successful!")}>
107
+ Success
108
+ </button>
109
+
110
+ <button onClick={() => toast.error("Something went wrong!")}>
111
+ Error
112
+ </button>
113
+ </>
114
+ );
115
+ };
116
+ ```
117
+
118
+ ------------------------------------------------------------------------
119
+
120
+ ## ⚛ïļ Next.js Usage
121
+
122
+ ### App Router (`app/layout.js`)
123
+
124
+ ``` jsx
125
+ "use client";
126
+
127
+ import { SoundProvider } from "react-ui-sound-events";
128
+
129
+ export default function RootLayout({ children }) {
130
+ return (
131
+ <SoundProvider
132
+ sounds={{
133
+ success: "/success.mp3",
134
+ error: "/error.mp3",
135
+ }}
136
+ >
137
+ {children}
138
+ </SoundProvider>
139
+ );
140
+ }
141
+ ```
142
+
143
+ ### Pages Router (`pages/_app.js`)
144
+
145
+ ``` jsx
146
+ import { SoundProvider } from "react-ui-sound-events";
147
+
148
+ function MyApp({ Component, pageProps }) {
149
+ return (
150
+ <SoundProvider sounds={{ success: "/success.mp3" }}>
151
+ <Component {...pageProps} />
152
+ </SoundProvider>
153
+ );
154
+ }
155
+
156
+ export default MyApp;
157
+ ```
158
+
159
+ ------------------------------------------------------------------------
160
+
161
+ ## 🧠 Supported Events
162
+
163
+ You can name sounds anything you want:
164
+
165
+ - login
166
+ - logout
167
+ - signup
168
+ - success
169
+ - error
170
+ - warning
171
+ - info
172
+ - click
173
+ - notification
174
+
175
+ ``` js
176
+ play("success");
177
+ play("error");
178
+ ```
179
+
180
+ ------------------------------------------------------------------------
181
+
182
+ ## 🔊 Volume Control
183
+
184
+ ``` jsx
185
+ <SoundProvider volume={0.5}>
186
+ <App />
187
+ </SoundProvider>
188
+ ```
189
+
190
+ Range: `0.0` -- `1.0`
191
+
192
+ ------------------------------------------------------------------------
193
+
194
+ ## ðŸšŦ Browser Autoplay Policy
195
+
196
+ Due to browser security rules: - Sounds play **only after user
197
+ interaction** - First click enables sound playback - Mobile browsers may
198
+ restrict autoplay
199
+
200
+ This package safely follows these rules.
201
+
202
+ ------------------------------------------------------------------------
203
+
204
+ ## 🛠ïļ Roadmap
205
+
206
+ - 🔕 Global mute toggle
207
+ - ðŸŽĻ Sound themes (minimal, game, iOS-style)
208
+ - ðŸ’ū Persist user preferences
209
+ - â™ŋ Accessibility mode
210
+
211
+ ------------------------------------------------------------------------
212
+
213
+ ## ðŸ’Ą Use Cases
214
+
215
+ - Login / Logout flows
216
+ - Admin dashboards
217
+ - Fintech & SaaS apps
218
+ - Toast notifications
219
+ - Games & kids apps
220
+ - Accessibility-focused UIs
221
+
222
+ ------------------------------------------------------------------------
223
+
224
+ ## 🧑‍ðŸ’ŧ Author
225
+
226
+ **Uttam Kumar**\
227
+ Frontend / MERN Stack Developer
228
+
229
+ ------------------------------------------------------------------------
230
+
231
+ ## ⭐ Support
232
+
233
+ If you like this project: - ⭐ Star it on GitHub - ðŸ“Ķ Use it in your
234
+ projects - 🐛 Report issues & suggest features
235
+
236
+ ------------------------------------------------------------------------
237
+
238
+ ## 📄 License
239
+
240
+ MIT License
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "react-ui-sound-events",
3
+ "version": "1.0.0",
4
+ "description": "Event based sound system for React & Next.js UI",
5
+ "main": "src/index.js",
6
+ "keywords": [
7
+ "react",
8
+ "nextjs",
9
+ "sound",
10
+ "toast",
11
+ "ui",
12
+ "ux"
13
+ ],
14
+ "author": "Uttam Kumar",
15
+ "license": "MIT",
16
+ "peerDependencies": {
17
+ "react": ">=16"
18
+ }
19
+ }
@@ -0,0 +1,21 @@
1
+ import { toast } from "react-toastify";
2
+ import { useSound } from "./SoundProvider";
3
+
4
+ export const useSoundToast = () => {
5
+ const { play } = useSound();
6
+
7
+ return {
8
+ success: (msg) => {
9
+ play("success");
10
+ toast.success(msg);
11
+ },
12
+ error: (msg) => {
13
+ play("error");
14
+ toast.error(msg);
15
+ },
16
+ info: (msg) => {
17
+ play("info");
18
+ toast.info(msg);
19
+ }
20
+ };
21
+ };
@@ -0,0 +1,27 @@
1
+ import React, { createContext, useContext, useRef } from "react";
2
+
3
+ const SoundContext = createContext();
4
+
5
+ export const SoundProvider = ({ sounds = {}, volume = 1, children }) => {
6
+ const audioMap = useRef({});
7
+
8
+ const play = (name) => {
9
+ if (!sounds[name]) return;
10
+
11
+ if (!audioMap.current[name]) {
12
+ audioMap.current[name] = new Audio(sounds[name]);
13
+ }
14
+
15
+ audioMap.current[name].volume = volume;
16
+ audioMap.current[name].currentTime = 0;
17
+ audioMap.current[name].play().catch(() => {});
18
+ };
19
+
20
+ return (
21
+ <SoundContext.Provider value={{ play }}>
22
+ {children}
23
+ </SoundContext.Provider>
24
+ );
25
+ };
26
+
27
+ export const useSound = () => useContext(SoundContext);
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SoundProvider } from "./SoundProvider";
2
+ export { useSound } from "./useSound";
3
+ export { useSoundToast } from "./SoundAutoToast";
@@ -0,0 +1 @@
1
+ export { useSound } from "./SoundProvider";