@samline/notify 0.2.0 → 0.2.2
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 +45 -11
- package/dist/index.cjs.js +14 -5
- package/dist/index.esm.js +14 -5
- package/dist/notify.umd.js +14 -5
- package/docs/browser.md +17 -4
- package/docs/react.md +10 -3
- package/docs/svelte.md +10 -3
- package/docs/vanilla.md +22 -8
- package/docs/vue.md +10 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
# Notify
|
|
3
3
|
|
|
4
4
|
A universal toast notification library powered by Sileo, designed to bring the same beautiful, animated experience to React, Vue, Svelte, and Vanilla JS. Built for teams who need Sileo’s quality and API, but require seamless integration across multiple frameworks.
|
|
5
5
|
|
|
@@ -48,20 +48,32 @@ CDN / Browser
|
|
|
48
48
|
|
|
49
49
|
Use the browser build when your project loads scripts directly and cannot compile npm modules (Shopify, WordPress, plain HTML). Example CDN usage (replace version):
|
|
50
50
|
|
|
51
|
+
|
|
51
52
|
```html
|
|
52
|
-
<script src="https://unpkg.com/@samline/notify@0.1
|
|
53
|
-
<link
|
|
54
|
-
rel="stylesheet"
|
|
55
|
-
href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css"
|
|
56
|
-
/>
|
|
53
|
+
<script src="https://unpkg.com/@samline/notify@0.2.1/dist/notify.umd.js"></script>
|
|
54
|
+
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.2.1/dist/styles.css" />
|
|
57
55
|
|
|
58
56
|
<script>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
api.notify
|
|
57
|
+
// Always use an array of strings as the second argument
|
|
58
|
+
// Correct usage:
|
|
59
|
+
const api = window.notify || window.notifications;
|
|
60
|
+
api.initToasters(document.body, ['top-left']);
|
|
61
|
+
api.notify({
|
|
62
|
+
title: 'Saved',
|
|
63
|
+
description: 'Changes saved',
|
|
64
|
+
type: 'success'
|
|
65
|
+
// You can omit position if you only initialized one position
|
|
66
|
+
});
|
|
62
67
|
</script>
|
|
63
68
|
```
|
|
64
69
|
|
|
70
|
+
|
|
71
|
+
> ⚠️ **Important:**
|
|
72
|
+
> - The second argument to `initToasters` **must be an array of strings** with the positions (e.g. `['top-left']`).
|
|
73
|
+
> - **Do not use** `document.body['top-left']` (this is `undefined` and will not work).
|
|
74
|
+
> - If you initialize only one position, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
75
|
+
> - If you initialize multiple positions, toasts without an explicit position will go to `'top-right'` by default.
|
|
76
|
+
|
|
65
77
|
Entry Points
|
|
66
78
|
|
|
67
79
|
Choose the entrypoint matching your stack so you only import what you need.
|
|
@@ -69,7 +81,7 @@ Choose the entrypoint matching your stack so you only import what you need.
|
|
|
69
81
|
| Use case | Import | Guide |
|
|
70
82
|
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
|
|
71
83
|
| Vanilla JS | `import { notify, initToasters } from '@samline/notify/vanilla'` | [docs/vanilla.md](docs/vanilla.md) |
|
|
72
|
-
| Browser / CDN | `<script src="https://unpkg.com/@samline/notify@0.1
|
|
84
|
+
| Browser / CDN | `<script src="https://unpkg.com/@samline/notify@0.2.1/dist/notify.umd.js"></script>`<br/>`const api = window.notify; api.initToasters(...);` | [docs/browser.md](docs/browser.md) |
|
|
73
85
|
| React | `import { Toaster, notify } from '@samline/notify/react'` | [docs/react.md](docs/react.md) |
|
|
74
86
|
| Vue | `import { Toaster, notify } from '@samline/notify/vue'` | [docs/vue.md](docs/vue.md) |
|
|
75
87
|
| Svelte | `import Toaster, { notify } from '@samline/notify/svelte'` | [docs/svelte.md](docs/svelte.md) |
|
|
@@ -102,9 +114,31 @@ notify.clear()
|
|
|
102
114
|
When using the UMD/browser bundle the global is exposed as `window.notify` (preferred). For compatibility the API object also exposes `window.notifications` which maintains the previous shape.
|
|
103
115
|
|
|
104
116
|
|
|
117
|
+
|
|
105
118
|
Shared Options (All Entrypoints)
|
|
106
119
|
|
|
107
|
-
All notification methods accept a rich set of options for full customization
|
|
120
|
+
All notification methods accept a rich set of options for full customization. **Position fallback note:**
|
|
121
|
+
|
|
122
|
+
- If you initialize only one position with `initToasters`, toasts without an explicit `position` will go there (dynamic fallback).
|
|
123
|
+
- If you initialize multiple positions, the fallback will be `'top-right'`.
|
|
124
|
+
- If you notify to a position that was not initialized, a warning will appear in the console and the toast will not be shown. This warning is now always triggered, incluso si la posición no existe en el DOM.
|
|
125
|
+
|
|
126
|
+
Example:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// Only one position (dynamic fallback)
|
|
130
|
+
api.initToasters(document.body, ['bottom-left']);
|
|
131
|
+
api.notify({ title: 'Will go to bottom-left' });
|
|
132
|
+
|
|
133
|
+
// Multiple positions (classic fallback)
|
|
134
|
+
api.initToasters(document.body, ['top-right', 'bottom-left']);
|
|
135
|
+
api.notify({ title: 'Will go to top-right' });
|
|
136
|
+
api.notify({ title: 'Will go to bottom-left', position: 'bottom-left' });
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
All options:
|
|
108
142
|
|
|
109
143
|
| Property | Type | Default | Description |
|
|
110
144
|
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
package/dist/index.cjs.js
CHANGED
|
@@ -1114,26 +1114,35 @@ function initToasters(root = document.body, positions = ['top-right'], opts) {
|
|
|
1114
1114
|
window.sileo._globalOptions = opts.options;
|
|
1115
1115
|
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1116
1116
|
window.sileo._theme = opts.theme;
|
|
1117
|
+
// fallback dinámico: si solo hay una posición, usarla como default
|
|
1118
|
+
const fallbackPosition = positions.length === 1 ? positions[0] : 'top-right';
|
|
1117
1119
|
function rerender(items) {
|
|
1120
|
+
// Lanzar advertencia para todos los toasts con posición no inicializada
|
|
1121
|
+
items.forEach((t) => {
|
|
1122
|
+
if (t.options.position && !containers[t.options.position]) {
|
|
1123
|
+
console.warn(`[sileo] Toast con posición "${t.options.position}" pero no se inicializó ningún contenedor para esa posición. Inicializa con initToasters(..., ['${t.options.position}']) para mostrarlo.`);
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1118
1126
|
positions.forEach((pos) => {
|
|
1119
1127
|
const container = containers[pos];
|
|
1120
|
-
|
|
1121
|
-
|
|
1128
|
+
// fallback dinámico
|
|
1129
|
+
const visible = items.filter((t) => (t.options.position || fallbackPosition) === pos);
|
|
1130
|
+
// Diff existing children y animar salida de toasts removidos
|
|
1122
1131
|
const visibleIds = new Set(visible.map((v) => v.id));
|
|
1123
1132
|
const existing = Array.from(container.children);
|
|
1124
1133
|
existing.forEach((child) => {
|
|
1125
1134
|
const id = child.dataset.id;
|
|
1126
1135
|
if (!id || !visibleIds.has(id)) {
|
|
1127
|
-
//
|
|
1136
|
+
// animar salida y luego remover
|
|
1128
1137
|
animate(child, { opacity: 0, y: -8 }, { duration: 0.18 }).finished.then(() => child.remove());
|
|
1129
1138
|
}
|
|
1130
1139
|
});
|
|
1131
|
-
//
|
|
1140
|
+
// Añadir nuevos toasts
|
|
1132
1141
|
visible.forEach((t) => {
|
|
1133
1142
|
if (!container.querySelector(`[data-id="${t.id}"]`)) {
|
|
1134
1143
|
const node = renderToast(t);
|
|
1135
1144
|
container.appendChild(node);
|
|
1136
|
-
//
|
|
1145
|
+
// animar entrada
|
|
1137
1146
|
requestAnimationFrame(() => {
|
|
1138
1147
|
animate(node, { opacity: [0, 1], y: [-6, 0] }, { duration: 0.24 });
|
|
1139
1148
|
});
|
package/dist/index.esm.js
CHANGED
|
@@ -1110,26 +1110,35 @@ function initToasters(root = document.body, positions = ['top-right'], opts) {
|
|
|
1110
1110
|
window.sileo._globalOptions = opts.options;
|
|
1111
1111
|
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1112
1112
|
window.sileo._theme = opts.theme;
|
|
1113
|
+
// fallback dinámico: si solo hay una posición, usarla como default
|
|
1114
|
+
const fallbackPosition = positions.length === 1 ? positions[0] : 'top-right';
|
|
1113
1115
|
function rerender(items) {
|
|
1116
|
+
// Lanzar advertencia para todos los toasts con posición no inicializada
|
|
1117
|
+
items.forEach((t) => {
|
|
1118
|
+
if (t.options.position && !containers[t.options.position]) {
|
|
1119
|
+
console.warn(`[sileo] Toast con posición "${t.options.position}" pero no se inicializó ningún contenedor para esa posición. Inicializa con initToasters(..., ['${t.options.position}']) para mostrarlo.`);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1114
1122
|
positions.forEach((pos) => {
|
|
1115
1123
|
const container = containers[pos];
|
|
1116
|
-
|
|
1117
|
-
|
|
1124
|
+
// fallback dinámico
|
|
1125
|
+
const visible = items.filter((t) => (t.options.position || fallbackPosition) === pos);
|
|
1126
|
+
// Diff existing children y animar salida de toasts removidos
|
|
1118
1127
|
const visibleIds = new Set(visible.map((v) => v.id));
|
|
1119
1128
|
const existing = Array.from(container.children);
|
|
1120
1129
|
existing.forEach((child) => {
|
|
1121
1130
|
const id = child.dataset.id;
|
|
1122
1131
|
if (!id || !visibleIds.has(id)) {
|
|
1123
|
-
//
|
|
1132
|
+
// animar salida y luego remover
|
|
1124
1133
|
animate(child, { opacity: 0, y: -8 }, { duration: 0.18 }).finished.then(() => child.remove());
|
|
1125
1134
|
}
|
|
1126
1135
|
});
|
|
1127
|
-
//
|
|
1136
|
+
// Añadir nuevos toasts
|
|
1128
1137
|
visible.forEach((t) => {
|
|
1129
1138
|
if (!container.querySelector(`[data-id="${t.id}"]`)) {
|
|
1130
1139
|
const node = renderToast(t);
|
|
1131
1140
|
container.appendChild(node);
|
|
1132
|
-
//
|
|
1141
|
+
// animar entrada
|
|
1133
1142
|
requestAnimationFrame(() => {
|
|
1134
1143
|
animate(node, { opacity: [0, 1], y: [-6, 0] }, { duration: 0.24 });
|
|
1135
1144
|
});
|
package/dist/notify.umd.js
CHANGED
|
@@ -1116,26 +1116,35 @@
|
|
|
1116
1116
|
window.sileo._globalOptions = opts.options;
|
|
1117
1117
|
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1118
1118
|
window.sileo._theme = opts.theme;
|
|
1119
|
+
// fallback dinámico: si solo hay una posición, usarla como default
|
|
1120
|
+
const fallbackPosition = positions.length === 1 ? positions[0] : 'top-right';
|
|
1119
1121
|
function rerender(items) {
|
|
1122
|
+
// Lanzar advertencia para todos los toasts con posición no inicializada
|
|
1123
|
+
items.forEach((t) => {
|
|
1124
|
+
if (t.options.position && !containers[t.options.position]) {
|
|
1125
|
+
console.warn(`[sileo] Toast con posición "${t.options.position}" pero no se inicializó ningún contenedor para esa posición. Inicializa con initToasters(..., ['${t.options.position}']) para mostrarlo.`);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1120
1128
|
positions.forEach((pos) => {
|
|
1121
1129
|
const container = containers[pos];
|
|
1122
|
-
|
|
1123
|
-
|
|
1130
|
+
// fallback dinámico
|
|
1131
|
+
const visible = items.filter((t) => (t.options.position || fallbackPosition) === pos);
|
|
1132
|
+
// Diff existing children y animar salida de toasts removidos
|
|
1124
1133
|
const visibleIds = new Set(visible.map((v) => v.id));
|
|
1125
1134
|
const existing = Array.from(container.children);
|
|
1126
1135
|
existing.forEach((child) => {
|
|
1127
1136
|
const id = child.dataset.id;
|
|
1128
1137
|
if (!id || !visibleIds.has(id)) {
|
|
1129
|
-
//
|
|
1138
|
+
// animar salida y luego remover
|
|
1130
1139
|
animate(child, { opacity: 0, y: -8 }, { duration: 0.18 }).finished.then(() => child.remove());
|
|
1131
1140
|
}
|
|
1132
1141
|
});
|
|
1133
|
-
//
|
|
1142
|
+
// Añadir nuevos toasts
|
|
1134
1143
|
visible.forEach((t) => {
|
|
1135
1144
|
if (!container.querySelector(`[data-id="${t.id}"]`)) {
|
|
1136
1145
|
const node = renderToast(t);
|
|
1137
1146
|
container.appendChild(node);
|
|
1138
|
-
//
|
|
1147
|
+
// animar entrada
|
|
1139
1148
|
requestAnimationFrame(() => {
|
|
1140
1149
|
animate(node, { opacity: [0, 1], y: [-6, 0] }, { duration: 0.24 });
|
|
1141
1150
|
});
|
package/docs/browser.md
CHANGED
|
@@ -8,18 +8,21 @@ Use this package directly in the browser when you cannot use npm modules or a bu
|
|
|
8
8
|
Add the stylesheet and UMD bundle to your HTML:
|
|
9
9
|
|
|
10
10
|
```html
|
|
11
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1
|
|
12
|
-
<script src="https://unpkg.com/@samline/notify@0.1
|
|
11
|
+
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.2.1/dist/styles.css">
|
|
12
|
+
<script src="https://unpkg.com/@samline/notify@0.2.1/dist/notify.umd.js"></script>
|
|
13
13
|
<script>
|
|
14
14
|
document.addEventListener('DOMContentLoaded', () => {
|
|
15
15
|
const api = window.notify; // or window.notifications for legacy
|
|
16
|
-
|
|
16
|
+
// Always use an array of strings as the second argument
|
|
17
|
+
// Correct usage:
|
|
18
|
+
api.initToasters(document.body, ['top-left']);
|
|
17
19
|
api.notify({ title: 'Hello', description: 'No-bundler usage', type: 'info' });
|
|
18
20
|
});
|
|
19
21
|
</script>
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
|
|
25
|
+
|
|
23
26
|
## API
|
|
24
27
|
|
|
25
28
|
- The UMD bundle exposes `window.notify` (recommended) and `window.notifications` (legacy/compatibility).
|
|
@@ -27,6 +30,14 @@ Add the stylesheet and UMD bundle to your HTML:
|
|
|
27
30
|
- Use `api.initToasters(container, positions, { offset, options, theme })` to mount containers (usually `document.body`).
|
|
28
31
|
- Use `api.notify({...})` to show a notification.
|
|
29
32
|
|
|
33
|
+
### ⚠️ Warnings and Best Practices
|
|
34
|
+
|
|
35
|
+
- The second argument to `initToasters` **must be an array of strings** (e.g. `['top-left']`).
|
|
36
|
+
- **Do not use** `document.body['top-left']` (this is `undefined` and will not work).
|
|
37
|
+
- If you initialize only one position, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
38
|
+
- If you initialize multiple positions, toasts without an explicit position will go to `'top-right'` by default.
|
|
39
|
+
- If you notify to a position that was not initialized, you will see a warning in the console and the toast will not be shown.
|
|
40
|
+
|
|
30
41
|
### Advanced Options
|
|
31
42
|
|
|
32
43
|
All notification methods accept advanced options:
|
|
@@ -64,10 +75,12 @@ api.success({
|
|
|
64
75
|
|
|
65
76
|
### Toaster Options
|
|
66
77
|
|
|
78
|
+
|
|
67
79
|
You can pass advanced options to `initToasters`:
|
|
68
80
|
|
|
69
81
|
```js
|
|
70
|
-
|
|
82
|
+
// Correct example with multiple positions
|
|
83
|
+
api.initToasters(document.body, ['top-right', 'bottom-left'], {
|
|
71
84
|
offset: { top: 32, right: 16 },
|
|
72
85
|
options: { fill: '#222', roundness: 20 },
|
|
73
86
|
theme: 'dark'
|
package/docs/react.md
CHANGED
|
@@ -72,7 +72,7 @@ notify.clear('top-right');
|
|
|
72
72
|
|
|
73
73
|
> **Note:**
|
|
74
74
|
> Import `@samline/notify/dist/styles.css` in your main entrypoint or include it in your HTML for correct appearance.
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
## API
|
|
@@ -103,7 +103,7 @@ All notification methods accept advanced options:
|
|
|
103
103
|
| `title` | string | — | Toast title |
|
|
104
104
|
| `description` | string \| ReactNode | — | Optional body text (JSX or string) |
|
|
105
105
|
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
106
|
-
| `position` | string | `top-right` | One of
|
|
106
|
+
| `position` | string | `top-right` | One of the valid positions. If you only initialize one position with `<Toaster position="..." />`, toasts without an explicit position will go there (dynamic fallback). If you initialize multiple, the fallback is `top-right`. |
|
|
107
107
|
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
108
108
|
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
109
109
|
| `icon` | string \| ReactNode | — | Custom icon (SVG or JSX) |
|
|
@@ -155,11 +155,18 @@ notify.info({
|
|
|
155
155
|
duration: null
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
// Custom position
|
|
158
|
+
// Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
|
|
159
159
|
notify.success({
|
|
160
160
|
title: 'Bottom left',
|
|
161
161
|
position: 'bottom-left'
|
|
162
162
|
});
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## ⚠️ Warnings and Best Practices
|
|
166
|
+
|
|
167
|
+
- If you only use one `<Toaster position="..." />`, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
168
|
+
- If you use multiple `<Toaster position="..." />`, the fallback will be `top-right`.
|
|
169
|
+
- If you notify to a position that was not initialized, you will see a warning in the console and the toast will not be shown.
|
|
163
170
|
|
|
164
171
|
// Description as ReactNode
|
|
165
172
|
notify.info({
|
package/docs/svelte.md
CHANGED
|
@@ -72,7 +72,7 @@ notify.clear('top-right');
|
|
|
72
72
|
|
|
73
73
|
> **Note:**
|
|
74
74
|
> Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
## API
|
|
@@ -104,7 +104,7 @@ All notification methods accept advanced options:
|
|
|
104
104
|
| `title` | string | — | Toast title |
|
|
105
105
|
| `description` | string \| SvelteNode | — | Optional body text (HTML or string) |
|
|
106
106
|
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
107
|
-
| `position` | string | `top-right` | One of
|
|
107
|
+
| `position` | string | `top-right` | One of the valid positions. If you only initialize one position with `<Toaster position="..." />`, toasts without an explicit position will go there (dynamic fallback). If you initialize multiple, the fallback is `top-right`. |
|
|
108
108
|
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
109
109
|
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
110
110
|
| `icon` | string \| SvelteNode | — | Custom icon (SVG or node) |
|
|
@@ -156,11 +156,18 @@ notify.info({
|
|
|
156
156
|
duration: null
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
// Custom position
|
|
159
|
+
// Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
|
|
160
160
|
notify.success({
|
|
161
161
|
title: 'Bottom left',
|
|
162
162
|
position: 'bottom-left'
|
|
163
163
|
});
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## ⚠️ Warnings and Best Practices
|
|
167
|
+
|
|
168
|
+
- If you only use one `<Toaster position="..." />`, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
169
|
+
- If you use multiple `<Toaster position="..." />`, the fallback will be `top-right`.
|
|
170
|
+
- If you notify to a position that was not initialized, you will see a warning in the console and the toast will not be shown.
|
|
164
171
|
|
|
165
172
|
// Description as SvelteNode
|
|
166
173
|
notify.info({
|
package/docs/vanilla.md
CHANGED
|
@@ -7,7 +7,8 @@ Use the vanilla adapter for plain JavaScript projects with a bundler (Vite, Webp
|
|
|
7
7
|
|
|
8
8
|
```js
|
|
9
9
|
import { notify, initToasters } from '@samline/notify/vanilla';
|
|
10
|
-
|
|
10
|
+
// Always use an array of strings as the second argument
|
|
11
|
+
initToasters(document.body, ['top-left']);
|
|
11
12
|
notify.success({ title: 'Saved', description: 'Your changes have been saved' });
|
|
12
13
|
```
|
|
13
14
|
|
|
@@ -60,7 +61,8 @@ notify.clear('top-right');
|
|
|
60
61
|
You can pass advanced options to `initToasters`:
|
|
61
62
|
|
|
62
63
|
```js
|
|
63
|
-
|
|
64
|
+
// Correct example with one position (dynamic fallback)
|
|
65
|
+
initToasters(document.body, ['bottom-left'], {
|
|
64
66
|
offset: { top: 32, right: 16 },
|
|
65
67
|
options: { fill: '#222', roundness: 20 },
|
|
66
68
|
theme: 'dark'
|
|
@@ -70,18 +72,30 @@ initToasters(document.body, ['top-right'], {
|
|
|
70
72
|
### Example: Multiple positions and custom offset
|
|
71
73
|
|
|
72
74
|
```js
|
|
75
|
+
// Correct example with multiple positions (classic fallback)
|
|
73
76
|
initToasters(document.body, ['top-right', 'bottom-left'], {
|
|
74
77
|
offset: { top: 24, right: 24, bottom: 24, left: 24 },
|
|
75
78
|
theme: 'light',
|
|
76
79
|
options: { fill: '#0f1724', roundness: 18 }
|
|
77
80
|
});
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
// Custom position (make sure you initialized that position)
|
|
84
|
+
notify.success({
|
|
85
|
+
title: 'Bottom left',
|
|
86
|
+
position: 'bottom-left'
|
|
87
|
+
});
|
|
78
88
|
```
|
|
79
89
|
|
|
80
|
-
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## ⚠️ Warnings and Best Practices
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
- The second argument to `initToasters` **must be an array of strings** (e.g. `['top-left']`).
|
|
95
|
+
- **Do not use** `document.body['top-left']` (this is `undefined` and will not work).
|
|
96
|
+
- If you initialize only one position, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
97
|
+
- If you initialize multiple positions, toasts without an explicit position will go to `'top-right'` by default.
|
|
98
|
+
- If you notify to a position that was not initialized, you will see a warning in the console and the toast will not be shown.
|
|
85
99
|
notify.error(options)
|
|
86
100
|
notify.info(options)
|
|
87
101
|
notify.warning(options)
|
|
@@ -164,8 +178,8 @@ notify.success({
|
|
|
164
178
|
If you are not using a bundler, use the [Browser guide](./browser.md) for CDN usage. Example:
|
|
165
179
|
|
|
166
180
|
```html
|
|
167
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.
|
|
168
|
-
<script src="https://unpkg.com/@samline/notify@0.
|
|
181
|
+
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.2.0/dist/styles.css">
|
|
182
|
+
<script src="https://unpkg.com/@samline/notify@0.2.0/dist/notify.umd.js"></script>
|
|
169
183
|
<script>
|
|
170
184
|
document.addEventListener('DOMContentLoaded', () => {
|
|
171
185
|
const api = window.notify;
|
package/docs/vue.md
CHANGED
|
@@ -95,7 +95,7 @@ function show(){ notify.show({ title: 'Hello from Vue' }); }
|
|
|
95
95
|
|
|
96
96
|
> **Note:**
|
|
97
97
|
> Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
## API
|
|
@@ -112,7 +112,7 @@ All notification methods accept advanced options:
|
|
|
112
112
|
| `title` | string | — | Toast title |
|
|
113
113
|
| `description` | string \| VNode | — | Optional body text (HTML or string) |
|
|
114
114
|
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
115
|
-
| `position` | string | `top-right` | One of
|
|
115
|
+
| `position` | string | `top-right` | One of the valid positions. If you only initialize one position with `<Toaster position="..." />`, toasts without an explicit position will go there (dynamic fallback). If you initialize multiple, the fallback is `top-right`. |
|
|
116
116
|
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
117
117
|
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
118
118
|
| `icon` | string \| VNode | — | Custom icon (SVG or node) |
|
|
@@ -164,11 +164,18 @@ notify.info({
|
|
|
164
164
|
duration: null
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
// Custom position
|
|
167
|
+
// Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
|
|
168
168
|
notify.success({
|
|
169
169
|
title: 'Bottom left',
|
|
170
170
|
position: 'bottom-left'
|
|
171
171
|
});
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## ⚠️ Warnings and Best Practices
|
|
175
|
+
|
|
176
|
+
- If you only use one `<Toaster position="..." />`, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
177
|
+
- If you use multiple `<Toaster position="..." />`, the fallback will be `top-right`.
|
|
178
|
+
- If you notify to a position that was not initialized, you will see a warning in the console and the toast will not be shown.
|
|
172
179
|
|
|
173
180
|
// Description as VNode
|
|
174
181
|
notify.info({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samline/notify",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Notifications engine inspired by Sileo, with adapters for vanilla, React, Vue and Svelte.",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@types/node": "^20.0.0",
|
|
38
38
|
"@types/react": "^18.2.0",
|
|
39
39
|
"@types/react-dom": "^18.2.0",
|
|
40
|
+
"jsdom": "^29.0.1",
|
|
40
41
|
"rollup": "^3.0.0",
|
|
41
42
|
"rollup-plugin-copy": "^3.4.0",
|
|
42
43
|
"svelte-check": "^3.3.0",
|