d9-toast 1.4.28 → 1.4.30

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 CHANGED
@@ -94,11 +94,12 @@ function MyComponent() {
94
94
  ### `useToast()`
95
95
 
96
96
  ```ts
97
- const { showToast, removeToast, removeToastAll } = useToast();
97
+ const { sounds, showToast, removeToast, removeToastAll } = useToast();
98
98
  ```
99
99
 
100
100
  | Method | Description |
101
101
  | -------------------- | --------------------------------- |
102
+ | `sounds` | Available toast sounds `"success" \| "error" \| "info" \| "warning"` |
102
103
  | `showToast(options)` | Show a toast and returns its `id` |
103
104
  | `removeToast(id)` | Remove toast by ID |
104
105
  | `removeToastAll()` | Clear all toasts |
@@ -139,6 +140,7 @@ actions?: {
139
140
  **Example**
140
141
 
141
142
  ```jsx
143
+
142
144
  showToast({
143
145
  message: "File uploaded",
144
146
  actions: [
@@ -168,6 +170,8 @@ audio?: {
168
170
  ### Example
169
171
 
170
172
  ```jsx
173
+ const { sounds, showToast } = useToast();
174
+
171
175
  showToast({
172
176
  message: "Message sent",
173
177
  type: "success",
@@ -175,6 +179,7 @@ showToast({
175
179
  enabled: true,
176
180
  volume: 0.8,
177
181
  cooldown: 500,
182
+ audioFile: sounds.success,
178
183
  },
179
184
  });
180
185
  ```
@@ -20,14 +20,20 @@ import React, { createContext, useCallback, useContext, useRef, useState } from
20
20
  import Toast from "./Toast";
21
21
  import "./toast.css";
22
22
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
- export var DEFAULT_TOAST_SOUND = "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/toast.m4a";
23
+ var sounds = {
24
+ "default": "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/default.mp3",
25
+ success: "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/success.mp3",
26
+ warning: "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/warning.mp3",
27
+ error: "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/errors.mp3",
28
+ info: "https://cdn.jsdelivr.net/gh/psathul073/d9-toast-assets@main/info.mp3"
29
+ };
24
30
  var ToastContext = /*#__PURE__*/createContext();
25
31
  export var useToast = function useToast() {
26
32
  return useContext(ToastContext);
27
33
  };
28
34
  var audioSettings = {
29
- audioFile: DEFAULT_TOAST_SOUND,
30
- volume: 0.8,
35
+ audioFile: sounds["default"],
36
+ volume: 0.6,
31
37
  enabled: true,
32
38
  cooldown: 500
33
39
  };
@@ -43,7 +49,7 @@ export var ToastProvider = function ToastProvider(_ref) {
43
49
  var playAudio = useCallback(function (_ref2) {
44
50
  var audioFile = _ref2.audioFile,
45
51
  _ref2$volume = _ref2.volume,
46
- volume = _ref2$volume === void 0 ? 0.8 : _ref2$volume;
52
+ volume = _ref2$volume === void 0 ? 0.6 : _ref2$volume;
47
53
  if (!audioFile || typeof window === "undefined") return;
48
54
  try {
49
55
  var audio = new Audio(audioFile);
@@ -128,6 +134,7 @@ export var ToastProvider = function ToastProvider(_ref) {
128
134
  }, {});
129
135
  return /*#__PURE__*/_jsxs(ToastContext.Provider, {
130
136
  value: {
137
+ sounds: sounds,
131
138
  showToast: showToast,
132
139
  removeToast: removeToast,
133
140
  removeToastAll: removeToastAll
@@ -23,6 +23,15 @@ declare module "d9-toast" {
23
23
  | "center-top"
24
24
  | "center-bottom";
25
25
 
26
+ /** Available toast sounds */
27
+ export interface ToastSounds {
28
+ default: string;
29
+ success: string;
30
+ warning: string;
31
+ error: string;
32
+ info: string;
33
+ }
34
+
26
35
  /** Single button/action displayed inside a toast */
27
36
  export interface ToastAction {
28
37
  /** Text label for the action button */
@@ -84,6 +93,8 @@ declare module "d9-toast" {
84
93
 
85
94
  /** Context value shape */
86
95
  export interface ToastContextValue {
96
+ /** Default toast sounds */
97
+ sounds: ToastSounds,
87
98
  /** Show a toast with given options and return toast id */
88
99
  showToast: (toast: ToastOptions) => number;
89
100
  /** Remove a toast by ID */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d9-toast",
3
- "version": "1.4.28",
3
+ "version": "1.4.30",
4
4
  "description": "Customizable toast notifications for React",
5
5
  "homepage": "https://codesandbox.io/embed/cqkyzm?view=preview",
6
6
  "repository": {