d9-toast 2.5.37 → 2.5.39

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
@@ -75,7 +75,11 @@ export default function Root() {
75
75
  ```jsx
76
76
  import { toast } from "d9-toast";
77
77
 
78
- toast.success("Saved successfully!");
78
+ // You can call it directly!
79
+ const notify = () => toast("Simple notification");
80
+
81
+ // Or use specific types
82
+ const success = () => toast.success("Saved!");
79
83
  ```
80
84
 
81
85
  ✅ Works inside
@@ -97,6 +101,7 @@ import { toast } from "d9-toast";
97
101
 
98
102
  | Method | Description |
99
103
  | ------------------------------------------- | ------------------- |
104
+ | `toast(msg, options)` | Show default toast |
100
105
  | `toast.success(msg, options)` | Show success toast |
101
106
  | `toast.error(msg, options)` | Show error toast |
102
107
  | `toast.info(msg, options)` | Show info toast |
package/dist/Toast.js CHANGED
@@ -110,7 +110,7 @@ var Toast = function Toast(_ref) {
110
110
  return actions.slice(0, 2).map(function (a, idx) {
111
111
  // Dynamic class names..
112
112
  var btnType = actions.length === 1 ? "action-btnA__".concat(type) : idx === 0 ? "action-btnB__".concat(type) : "action-btnA__".concat(type);
113
- var classNameStr = "action-btn ".concat(theme === "colored" ? "" : btnType, " ").concat(a.className || "").trim();
113
+ var classNameStr = "action-btn ".concat(theme === "colored" ? theme : btnType, " ").concat(a.className || "").trim();
114
114
  return /*#__PURE__*/_jsx("button", {
115
115
  "aria-label": "Action ".concat(a.text),
116
116
  onClick: function onClick() {
@@ -129,8 +129,6 @@ var Toast = function Toast(_ref) {
129
129
 
130
130
  // Start auto-close timer.
131
131
  useEffect(function () {
132
- // startTimer();
133
-
134
132
  // pause/resume when window focus changes.
135
133
  var handleBlur = function handleBlur() {
136
134
  return pauseOnFocusLoss && handlePause();
@@ -155,7 +153,6 @@ var Toast = function Toast(_ref) {
155
153
  dir: rtl ? "rtl" : "ltr",
156
154
  style: {
157
155
  bottom: position.includes("bottom") ? "0%" : ""
158
- // zIndex: shouldExpand ? 9999 : 10 - stackIndex, // Dynamic Z-index for stacking...
159
156
  },
160
157
  children: /*#__PURE__*/_jsxs("div", {
161
158
  "data-stack": shouldExpand ? 0 : stackIndex,
@@ -174,7 +171,7 @@ var Toast = function Toast(_ref) {
174
171
  className: "toastHeader ".concat(type),
175
172
  children: [/*#__PURE__*/_jsxs("div", {
176
173
  className: "title",
177
- children: [/*#__PURE__*/_jsx(Icons, {
174
+ children: [type !== "default" && /*#__PURE__*/_jsx(Icons, {
178
175
  name: type || "success"
179
176
  }), " ", /*#__PURE__*/_jsx("p", {
180
177
  children: type.toUpperCase()
@@ -193,11 +190,11 @@ var Toast = function Toast(_ref) {
193
190
  className: "toast-message__container",
194
191
  children: [/*#__PURE__*/_jsxs("div", {
195
192
  className: "toast-message",
196
- children: [!title && /*#__PURE__*/_jsx(Icons, {
193
+ children: [!title && type !== "default" && /*#__PURE__*/_jsx(Icons, {
197
194
  name: type || "success",
198
195
  className: type
199
196
  }), /*#__PURE__*/_jsx("p", {
200
- children: message
197
+ children: message || "No messages"
201
198
  })]
202
199
  }), closable && !title && /*#__PURE__*/_jsx("button", {
203
200
  className: "close-button",
@@ -213,19 +210,23 @@ var Toast = function Toast(_ref) {
213
210
  style: {
214
211
  padding: "4px"
215
212
  },
216
- children: message
213
+ children: message || "No messages"
217
214
  }), actions.length > 0 && /*#__PURE__*/_jsx("div", {
218
215
  className: "toastActions",
219
216
  children: actionButtons
220
- }), progress && duration !== 0 && autoClose && /*#__PURE__*/_jsx("div", {
217
+ }), duration !== 0 && autoClose && /*#__PURE__*/_jsx("div", {
221
218
  className: "progress-container ".concat(type),
219
+ style: {
220
+ opacity: progress ? 1 : 0,
221
+ height: progress ? "4px" : "0px"
222
+ },
222
223
  children: /*#__PURE__*/_jsx("div", {
223
224
  className: "toast-progress ".concat(type),
224
225
  onAnimationEnd: triggerExit,
225
226
  style: {
226
227
  animationDuration: "".concat(duration, "ms"),
227
228
  animationPlayState: isPaused ? "paused" : "running",
228
- animationFillMode: rtl ? "backwards" : "forwards"
229
+ transformOrigin: rtl ? "right" : "left"
229
230
  }
230
231
  })
231
232
  })]
@@ -42,59 +42,70 @@ var toastRef = null;
42
42
 
43
43
  // For public toast API.
44
44
  var warn = function warn() {
45
- console.warn("ToastProvider is not mounted");
45
+ console.warn("D9-Toast: ToastProvider is not mounted. Ensure it wraps your app.");
46
46
  return undefined;
47
47
  };
48
- export var toast = {
49
- sounds: sounds,
50
- success: function success(msg) {
51
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
52
- return toastRef ? toastRef.showToast(_objectSpread({
53
- type: "success",
54
- message: msg !== null && msg !== void 0 ? msg : "No messages"
55
- }, opts)) : warn();
56
- },
57
- error: function error(msg) {
58
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
59
- return toastRef ? toastRef.showToast(_objectSpread({
60
- type: "error",
61
- message: msg !== null && msg !== void 0 ? msg : "No messages"
62
- }, opts)) : warn();
63
- },
64
- info: function info(msg) {
65
- var _toastRef;
66
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
67
- return (_toastRef = toastRef) === null || _toastRef === void 0 ? void 0 : _toastRef.showToast(_objectSpread({
68
- type: "info",
69
- message: msg !== null && msg !== void 0 ? msg : "No messages"
70
- }, opts));
71
- },
72
- warning: function warning(msg) {
73
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
74
- return toastRef ? toastRef.showToast(_objectSpread({
75
- type: "warning",
76
- message: msg !== null && msg !== void 0 ? msg : "No messages"
77
- }, opts)) : warn();
78
- },
79
- promise: function promise(_promise, messages) {
80
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
81
- var defaultMessages = {
82
- loading: "Loading...",
83
- success: "Success",
84
- error: "Error"
85
- };
86
- var finalMessages = messages && _typeof(messages) === "object" ? messages : defaultMessages;
87
- return toastRef ? toastRef.promiseToast(_promise, finalMessages, opts) : warn();
88
- },
89
- dismiss: function dismiss(id) {
90
- var _toastRef2;
91
- return (_toastRef2 = toastRef) === null || _toastRef2 === void 0 ? void 0 : _toastRef2.removeToast(id);
92
- },
93
- dismissAll: function dismissAll() {
94
- var _toastRef3;
95
- return (_toastRef3 = toastRef) === null || _toastRef3 === void 0 ? void 0 : _toastRef3.removeToastAll();
96
- }
48
+
49
+ /** * CALLABLE API CORE */
50
+ var toastBase = function toastBase(msg) {
51
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
52
+ return toastRef ? toastRef.showToast(_objectSpread({
53
+ type: "default",
54
+ title: false,
55
+ progress: false,
56
+ duration: 3000,
57
+ message: msg
58
+ }, opts)) : warn();
59
+ };
60
+ toastBase.sounds = sounds;
61
+ toastBase.success = function (msg) {
62
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
63
+ return toastRef ? toastRef.showToast(_objectSpread({
64
+ type: "success",
65
+ message: msg,
66
+ progress: true
67
+ }, opts)) : warn();
68
+ };
69
+ toastBase.error = function (msg) {
70
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
71
+ return toastRef ? toastRef.showToast(_objectSpread({
72
+ type: "error",
73
+ message: msg
74
+ }, opts)) : warn();
75
+ };
76
+ toastBase.info = function (msg) {
77
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
78
+ return toastRef ? toastRef.showToast(_objectSpread({
79
+ type: "info",
80
+ message: msg
81
+ }, opts)) : warn();
82
+ };
83
+ toastBase.warning = function (msg) {
84
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
85
+ return toastRef ? toastRef.showToast(_objectSpread({
86
+ type: "warning",
87
+ message: msg
88
+ }, opts)) : warn();
89
+ };
90
+ toastBase.promise = function (promise, messages) {
91
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
92
+ var defaultMessages = {
93
+ loading: "Loading...",
94
+ success: "Success",
95
+ error: "Error"
96
+ };
97
+ var finalMessages = messages && _typeof(messages) === "object" ? messages : defaultMessages;
98
+ return toastRef ? toastRef.promiseToast(promise, finalMessages, opts) : warn();
99
+ };
100
+ toastBase.dismiss = function (id) {
101
+ var _toastRef;
102
+ return (_toastRef = toastRef) === null || _toastRef === void 0 ? void 0 : _toastRef.removeToast(id);
103
+ };
104
+ toastBase.dismissAll = function () {
105
+ var _toastRef2;
106
+ return (_toastRef2 = toastRef) === null || _toastRef2 === void 0 ? void 0 : _toastRef2.removeToastAll();
97
107
  };
108
+ export var toast = toastBase;
98
109
  export var ToastProvider = function ToastProvider(_ref) {
99
110
  var children = _ref.children;
100
111
  var _useState = useState([]),
@@ -10,6 +10,7 @@ declare module "d9-toast" {
10
10
  * Controls icon, color, and default sound.
11
11
  */
12
12
  export type ToastType =
13
+ | "default"
13
14
  | "success"
14
15
  | "error"
15
16
  | "info"
@@ -178,16 +179,18 @@ declare module "d9-toast" {
178
179
  }
179
180
 
180
181
  /* =========================================
181
- * Toast API (PUBLIC)
182
- * ========================================= */
182
+ * Toast API (PUBLIC)
183
+ * ========================================= */
183
184
 
184
- /**
185
- * Public toast API used to trigger notifications.
186
- */
187
- export const toast: {
185
+ export interface ToastCallable {
188
186
  /**
189
- * Default sound URLs used by the toast system.
190
- */
187
+ * Show a default notification.
188
+ * Defaults: type="default", progress=false, duration=3000
189
+ * Usage: toast("Simple message")
190
+ */
191
+ (message: string | React.ReactNode, options?: ToastOptions): string | undefined;
192
+
193
+ /** Default sound URLs */
191
194
  sounds: {
192
195
  default: string;
193
196
  success: string;
@@ -196,73 +199,43 @@ declare module "d9-toast" {
196
199
  info: string;
197
200
  };
198
201
 
199
- /**
200
- * Show a success toast.
201
- */
202
- success(
203
- message: string | React.ReactNode,
204
- options?: ToastOptions
205
- ): string | undefined;
202
+ /** Show a success toast */
203
+ success(message: string | React.ReactNode, options?: ToastOptions): string | undefined;
206
204
 
207
- /**
208
- * Show an error toast.
209
- */
210
- error(
211
- message: string | React.ReactNode,
212
- options?: ToastOptions
213
- ): string | undefined;
205
+ /** Show an error toast */
206
+ error(message: string | React.ReactNode, options?: ToastOptions): string | undefined;
214
207
 
215
- /**
216
- * Show an info toast.
217
- */
218
- info(
219
- message: string | React.ReactNode,
220
- options?: ToastOptions
221
- ): string | undefined;
208
+ /** Show an info toast */
209
+ info(message: string | React.ReactNode, options?: ToastOptions): string | undefined;
222
210
 
223
- /**
224
- * Show a warning toast.
225
- */
226
- warning(
227
- message: string | React.ReactNode,
228
- options?: ToastOptions
229
- ): string | undefined;
211
+ /** Show a warning toast */
212
+ warning(message: string | React.ReactNode, options?: ToastOptions): string | undefined;
230
213
 
231
214
  /**
232
- * Wraps a promise and updates the toast automatically.
233
- */
215
+ * Wraps a promise and updates the toast automatically.
216
+ */
234
217
  promise<T>(
235
218
  promise: Promise<T> | (() => Promise<T>),
236
219
  messages: {
237
- /**
238
- * Message shown while the promise is pending.
239
- */
240
220
  loading: string | React.ReactNode;
241
-
242
- /**
243
- * Message shown when the promise resolves.
244
- */
245
221
  success: string | React.ReactNode | ((value: T) => string | React.ReactNode);
246
-
247
- /**
248
- * Message shown when the promise rejects.
249
- */
250
222
  error: string | React.ReactNode | ((error: any) => string | React.ReactNode);
251
223
  },
252
224
  options?: ToastOptions
253
225
  ): Promise<T>;
254
226
 
255
- /**
256
- * Dismiss a toast by its id.
257
- */
227
+ /** Dismiss a specific toast */
258
228
  dismiss(id: string): void;
259
229
 
260
- /**
261
- * Dismiss all active toasts.
262
- */
230
+ /** Dismiss all toasts */
263
231
  dismissAll(): void;
264
- };
232
+ }
265
233
 
234
+ /**
235
+ * Public toast API used to trigger notifications.
236
+ * Can be called directly as a function or via type-specific methods.
237
+ */
238
+ export const toast: ToastCallable;
266
239
  /* =========================================
267
240
  * Provider
268
241
  * ========================================= */
package/dist/toast.css CHANGED
@@ -26,7 +26,6 @@
26
26
 
27
27
  --line-height-base: 1.5;
28
28
  --font-size-base: 14px;
29
-
30
29
  }
31
30
 
32
31
  /* Theme colors */
@@ -50,7 +49,6 @@
50
49
  --loading-bg: rgba(106, 31, 176, 0.1);
51
50
 
52
51
  --border-color: lch(91.6% 2.18 271.57);
53
-
54
52
  }
55
53
 
56
54
  .d9-toast.dark {
@@ -73,7 +71,6 @@
73
71
  --loading-bg: #ab4fff25;
74
72
 
75
73
  --border-color: #ffffff15;
76
-
77
74
  }
78
75
 
79
76
  /* Defaults */
@@ -143,7 +140,7 @@
143
140
  .toastContainer {
144
141
  position: relative;
145
142
  width: 100vw;
146
- max-width: 425px;
143
+ max-width: 375px;
147
144
  min-height: 60px;
148
145
  pointer-events: none;
149
146
  }
@@ -171,7 +168,7 @@
171
168
  position: relative;
172
169
  top: 0;
173
170
  min-width: 250px;
174
- max-width: 425px;
171
+ max-width: 375px;
175
172
  max-height: 425px;
176
173
  display: flex;
177
174
  flex-direction: column;
@@ -183,13 +180,24 @@
183
180
  font-size: var(--font-size-base);
184
181
  line-height: var(--line-height-base);
185
182
  text-align: start;
186
- font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
187
- Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
183
+ font-family:
184
+ system-ui,
185
+ -apple-system,
186
+ BlinkMacSystemFont,
187
+ "Segoe UI",
188
+ Roboto,
189
+ Oxygen,
190
+ Ubuntu,
191
+ Cantarell,
192
+ "Open Sans",
193
+ "Helvetica Neue",
194
+ sans-serif;
188
195
  will-change: transform, opacity;
189
196
  background-color: var(--primary-bg);
190
197
  color: var(--primary-color);
191
198
  border: 1px solid var(--border-color);
192
- transition: transform 650ms cubic-bezier(0.165, 0.84, 0.44, 1),
199
+ transition:
200
+ transform 650ms cubic-bezier(0.165, 0.84, 0.44, 1),
193
201
  opacity 300ms ease;
194
202
  pointer-events: auto;
195
203
  }
@@ -316,6 +324,11 @@
316
324
  filter: grayscale(1);
317
325
  }
318
326
 
327
+ .colored {
328
+ color: #000000;
329
+ background-color: #ffffff;
330
+ }
331
+
319
332
  /* Action button 1 */
320
333
  .action-btnA__success {
321
334
  color: var(--primary-bg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d9-toast",
3
- "version": "2.5.37",
3
+ "version": "2.5.39",
4
4
  "description": "Customizable toast notifications for React",
5
5
  "homepage": "https://psathul073.github.io/d9-toast-docs/",
6
6
  "repository": {