@samline/notify 0.1.10 → 0.2.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 +81 -37
- package/dist/index.cjs.js +46 -4
- package/dist/index.esm.js +46 -4
- package/dist/notify.umd.js +46 -4
- package/docs/browser.md +63 -28
- package/docs/react.md +228 -24
- package/docs/svelte.md +231 -21
- package/docs/vanilla.md +195 -32
- package/docs/vue.md +267 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
|
|
1
2
|
## @samline/notify
|
|
2
|
-
A Sileo-inspired notifications engine providing a framework-agnostic core and lightweight adapters for Vanilla JS, React, Vue and Svelte.
|
|
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
|
+
|
|
6
|
+
Powered by Sileo — see the original project: https://github.com/hiaaryan/sileo
|
|
5
7
|
|
|
6
8
|
Table of Contents
|
|
7
9
|
|
|
@@ -47,36 +49,30 @@ CDN / Browser
|
|
|
47
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):
|
|
48
50
|
|
|
49
51
|
```html
|
|
50
|
-
<script src="https://unpkg.com/@samline/notify@0.1.
|
|
51
|
-
<link
|
|
52
|
+
<script src="https://unpkg.com/@samline/notify@0.1.15/dist/notify.umd.js"></script>
|
|
53
|
+
<link
|
|
54
|
+
rel="stylesheet"
|
|
55
|
+
href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css"
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
<script>
|
|
59
|
+
const api = window.notify || window.notifications
|
|
60
|
+
api.initToasters(document.body, ['top-right'])
|
|
61
|
+
api.notify({ title: 'Saved', description: 'Changes saved', type: 'success' })
|
|
62
|
+
</script>
|
|
52
63
|
```
|
|
53
64
|
|
|
54
65
|
Entry Points
|
|
55
66
|
|
|
56
67
|
Choose the entrypoint matching your stack so you only import what you need.
|
|
57
68
|
|
|
58
|
-
| Use case
|
|
59
|
-
|
|
|
60
|
-
| Vanilla JS
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
| Svelte | `import Toaster from '@samline/notify/svelte'` | [docs/svelte.md](docs/svelte.md) |
|
|
66
|
-
|
|
67
|
-
Quick Start
|
|
68
|
-
|
|
69
|
-
Vanilla example (UMD / modules):
|
|
70
|
-
|
|
71
|
-
```html
|
|
72
|
-
<script src="https://unpkg.com/@samline/notify@0.1.10/dist/notify.umd.js"></script>
|
|
73
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.10/dist/styles.css">
|
|
74
|
-
<script>
|
|
75
|
-
const api = window.notify || window.notifications;
|
|
76
|
-
api.initToasters(document.body, ['top-right']);
|
|
77
|
-
api.notify({ title: 'Saved', description: 'Changes saved', type: 'success' });
|
|
78
|
-
</script>
|
|
79
|
-
```
|
|
69
|
+
| Use case | Import | Guide |
|
|
70
|
+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
|
|
71
|
+
| 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.13/dist/notify.umd.js"></script>`<br/>`const api = window.notify; api.initToasters(...);` | [docs/browser.md](docs/browser.md) |
|
|
73
|
+
| React | `import { Toaster, notify } from '@samline/notify/react'` | [docs/react.md](docs/react.md) |
|
|
74
|
+
| Vue | `import { Toaster, notify } from '@samline/notify/vue'` | [docs/vue.md](docs/vue.md) |
|
|
75
|
+
| Svelte | `import Toaster, { notify } from '@samline/notify/svelte'` | [docs/svelte.md](docs/svelte.md) |
|
|
80
76
|
|
|
81
77
|
Documentation Guides
|
|
82
78
|
|
|
@@ -105,18 +101,67 @@ notify.clear()
|
|
|
105
101
|
|
|
106
102
|
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.
|
|
107
103
|
|
|
108
|
-
Shared Options
|
|
109
104
|
|
|
110
|
-
|
|
105
|
+
Shared Options (All Entrypoints)
|
|
106
|
+
|
|
107
|
+
All notification methods accept a rich set of options for full customization:
|
|
108
|
+
|
|
109
|
+
| Property | Type | Default | Description |
|
|
110
|
+
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
111
|
+
| `title` | string | — | Toast title |
|
|
112
|
+
| `description` | string \| ReactNode \| SvelteNode | — | Optional body text (JSX, HTML, or string) |
|
|
113
|
+
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
114
|
+
| `position` | string | `top-right` | One of toast positions |
|
|
115
|
+
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
116
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
117
|
+
| `icon` | string \| ReactNode \| SvelteNode | — | Custom icon (SVG, JSX, or node) |
|
|
118
|
+
| `fill` | string | — | Custom background color (SVG or badge) |
|
|
119
|
+
| `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
|
|
120
|
+
| `roundness` | number | 16 | Border radius in pixels |
|
|
121
|
+
| `autopilot` | boolean \| object | true | Auto expand/collapse timing |
|
|
122
|
+
|
|
123
|
+
#### Example: Advanced Toast
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
notify.success({
|
|
127
|
+
title: "Styled!",
|
|
128
|
+
fill: "#222",
|
|
129
|
+
icon: '<svg>...</svg>',
|
|
130
|
+
styles: {
|
|
131
|
+
title: "text-white!",
|
|
132
|
+
badge: "bg-white/20!",
|
|
133
|
+
button: "bg-white/10!"
|
|
134
|
+
},
|
|
135
|
+
roundness: 24,
|
|
136
|
+
autopilot: false
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### SileoPromiseOptions
|
|
141
|
+
|
|
142
|
+
The `promise` method supports advanced flows:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
notify.promise(fetchData(), {
|
|
146
|
+
loading: { title: "Loading..." },
|
|
147
|
+
success: (data) => ({ title: `Loaded ${data.name}` }),
|
|
148
|
+
error: (err) => ({ title: "Error", description: err.message }),
|
|
149
|
+
action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Toaster Component Props (React, Svelte, Vue, Vanilla)
|
|
154
|
+
|
|
155
|
+
All Toaster components accept the following props for global control:
|
|
111
156
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
| Prop | Type | Default | Description |
|
|
158
|
+
| --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
|
|
159
|
+
| `position`| string | top-right | Default toast position |
|
|
160
|
+
| `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
|
|
161
|
+
| `options` | Partial<Options> | — | Default options for all toasts |
|
|
162
|
+
| `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
|
|
163
|
+
|
|
164
|
+
See framework-specific guides for more examples.
|
|
120
165
|
|
|
121
166
|
Notes
|
|
122
167
|
|
|
@@ -127,4 +172,3 @@ Notes
|
|
|
127
172
|
License
|
|
128
173
|
|
|
129
174
|
MIT
|
|
130
|
-
|
package/dist/index.cjs.js
CHANGED
|
@@ -24,8 +24,21 @@ class NotifyController {
|
|
|
24
24
|
return this.toasts.slice();
|
|
25
25
|
}
|
|
26
26
|
show(opts) {
|
|
27
|
+
// Normalizar props avanzadas
|
|
28
|
+
const { icon, fill, styles, roundness, autopilot, ...rest } = opts;
|
|
27
29
|
const id = this.nextId();
|
|
28
|
-
const item = {
|
|
30
|
+
const item = {
|
|
31
|
+
id,
|
|
32
|
+
options: {
|
|
33
|
+
...rest,
|
|
34
|
+
...(icon !== undefined ? { icon } : {}),
|
|
35
|
+
...(fill !== undefined ? { fill } : {}),
|
|
36
|
+
...(styles !== undefined ? { styles } : {}),
|
|
37
|
+
...(roundness !== undefined ? { roundness } : {}),
|
|
38
|
+
...(autopilot !== undefined ? { autopilot } : {}),
|
|
39
|
+
},
|
|
40
|
+
createdAt: Date.now(),
|
|
41
|
+
};
|
|
29
42
|
this.toasts.push(item);
|
|
30
43
|
this.notify();
|
|
31
44
|
return id;
|
|
@@ -65,6 +78,13 @@ class NotifyController {
|
|
|
65
78
|
const loadingId = this.show({ ...(opts.loading || {}), type: 'loading', position: opts.position });
|
|
66
79
|
p.then((res) => {
|
|
67
80
|
this.dismiss(loadingId);
|
|
81
|
+
if (opts.action) {
|
|
82
|
+
const actionOpt = typeof opts.action === 'function' ? opts.action(res) : opts.action;
|
|
83
|
+
if (actionOpt) {
|
|
84
|
+
this.show({ ...(actionOpt || {}), type: 'action', position: opts.position });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
68
88
|
const successOpt = typeof opts.success === 'function' ? opts.success(res) : opts.success;
|
|
69
89
|
if (successOpt)
|
|
70
90
|
this.show({ ...(successOpt || {}), type: 'success', position: opts.position });
|
|
@@ -1006,12 +1026,30 @@ const POSITIONS = [
|
|
|
1006
1026
|
'bottom-center',
|
|
1007
1027
|
'bottom-right'
|
|
1008
1028
|
];
|
|
1009
|
-
function createContainer(position, root) {
|
|
1029
|
+
function createContainer(position, root, opts) {
|
|
1010
1030
|
const c = document.createElement('div');
|
|
1011
1031
|
c.className = 'sileo-toaster';
|
|
1012
1032
|
c.setAttribute('data-position', position);
|
|
1013
1033
|
c.setAttribute('role', 'status');
|
|
1014
1034
|
c.setAttribute('aria-live', 'polite');
|
|
1035
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1036
|
+
c.setAttribute('data-theme', opts.theme);
|
|
1037
|
+
// offset
|
|
1038
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.offset) !== undefined) {
|
|
1039
|
+
if (typeof opts.offset === 'number' || typeof opts.offset === 'string') {
|
|
1040
|
+
c.style.margin = typeof opts.offset === 'number' ? `${opts.offset}px` : opts.offset;
|
|
1041
|
+
}
|
|
1042
|
+
else if (typeof opts.offset === 'object') {
|
|
1043
|
+
if (opts.offset.top !== undefined)
|
|
1044
|
+
c.style.marginTop = `${opts.offset.top}px`;
|
|
1045
|
+
if (opts.offset.right !== undefined)
|
|
1046
|
+
c.style.marginRight = `${opts.offset.right}px`;
|
|
1047
|
+
if (opts.offset.bottom !== undefined)
|
|
1048
|
+
c.style.marginBottom = `${opts.offset.bottom}px`;
|
|
1049
|
+
if (opts.offset.left !== undefined)
|
|
1050
|
+
c.style.marginLeft = `${opts.offset.left}px`;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1015
1053
|
return c;
|
|
1016
1054
|
}
|
|
1017
1055
|
function renderToast(item) {
|
|
@@ -1065,13 +1103,17 @@ function renderToast(item) {
|
|
|
1065
1103
|
}
|
|
1066
1104
|
return el;
|
|
1067
1105
|
}
|
|
1068
|
-
function initToasters(root = document.body, positions = ['top-right']) {
|
|
1106
|
+
function initToasters(root = document.body, positions = ['top-right'], opts) {
|
|
1069
1107
|
const containers = {};
|
|
1070
1108
|
positions.forEach((pos) => {
|
|
1071
|
-
const c = createContainer(pos);
|
|
1109
|
+
const c = createContainer(pos, root, opts);
|
|
1072
1110
|
root.appendChild(c);
|
|
1073
1111
|
containers[pos] = c;
|
|
1074
1112
|
});
|
|
1113
|
+
if (opts === null || opts === void 0 ? void 0 : opts.options)
|
|
1114
|
+
window.sileo._globalOptions = opts.options;
|
|
1115
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1116
|
+
window.sileo._theme = opts.theme;
|
|
1075
1117
|
function rerender(items) {
|
|
1076
1118
|
positions.forEach((pos) => {
|
|
1077
1119
|
const container = containers[pos];
|
package/dist/index.esm.js
CHANGED
|
@@ -20,8 +20,21 @@ class NotifyController {
|
|
|
20
20
|
return this.toasts.slice();
|
|
21
21
|
}
|
|
22
22
|
show(opts) {
|
|
23
|
+
// Normalizar props avanzadas
|
|
24
|
+
const { icon, fill, styles, roundness, autopilot, ...rest } = opts;
|
|
23
25
|
const id = this.nextId();
|
|
24
|
-
const item = {
|
|
26
|
+
const item = {
|
|
27
|
+
id,
|
|
28
|
+
options: {
|
|
29
|
+
...rest,
|
|
30
|
+
...(icon !== undefined ? { icon } : {}),
|
|
31
|
+
...(fill !== undefined ? { fill } : {}),
|
|
32
|
+
...(styles !== undefined ? { styles } : {}),
|
|
33
|
+
...(roundness !== undefined ? { roundness } : {}),
|
|
34
|
+
...(autopilot !== undefined ? { autopilot } : {}),
|
|
35
|
+
},
|
|
36
|
+
createdAt: Date.now(),
|
|
37
|
+
};
|
|
25
38
|
this.toasts.push(item);
|
|
26
39
|
this.notify();
|
|
27
40
|
return id;
|
|
@@ -61,6 +74,13 @@ class NotifyController {
|
|
|
61
74
|
const loadingId = this.show({ ...(opts.loading || {}), type: 'loading', position: opts.position });
|
|
62
75
|
p.then((res) => {
|
|
63
76
|
this.dismiss(loadingId);
|
|
77
|
+
if (opts.action) {
|
|
78
|
+
const actionOpt = typeof opts.action === 'function' ? opts.action(res) : opts.action;
|
|
79
|
+
if (actionOpt) {
|
|
80
|
+
this.show({ ...(actionOpt || {}), type: 'action', position: opts.position });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
64
84
|
const successOpt = typeof opts.success === 'function' ? opts.success(res) : opts.success;
|
|
65
85
|
if (successOpt)
|
|
66
86
|
this.show({ ...(successOpt || {}), type: 'success', position: opts.position });
|
|
@@ -1002,12 +1022,30 @@ const POSITIONS = [
|
|
|
1002
1022
|
'bottom-center',
|
|
1003
1023
|
'bottom-right'
|
|
1004
1024
|
];
|
|
1005
|
-
function createContainer(position, root) {
|
|
1025
|
+
function createContainer(position, root, opts) {
|
|
1006
1026
|
const c = document.createElement('div');
|
|
1007
1027
|
c.className = 'sileo-toaster';
|
|
1008
1028
|
c.setAttribute('data-position', position);
|
|
1009
1029
|
c.setAttribute('role', 'status');
|
|
1010
1030
|
c.setAttribute('aria-live', 'polite');
|
|
1031
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1032
|
+
c.setAttribute('data-theme', opts.theme);
|
|
1033
|
+
// offset
|
|
1034
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.offset) !== undefined) {
|
|
1035
|
+
if (typeof opts.offset === 'number' || typeof opts.offset === 'string') {
|
|
1036
|
+
c.style.margin = typeof opts.offset === 'number' ? `${opts.offset}px` : opts.offset;
|
|
1037
|
+
}
|
|
1038
|
+
else if (typeof opts.offset === 'object') {
|
|
1039
|
+
if (opts.offset.top !== undefined)
|
|
1040
|
+
c.style.marginTop = `${opts.offset.top}px`;
|
|
1041
|
+
if (opts.offset.right !== undefined)
|
|
1042
|
+
c.style.marginRight = `${opts.offset.right}px`;
|
|
1043
|
+
if (opts.offset.bottom !== undefined)
|
|
1044
|
+
c.style.marginBottom = `${opts.offset.bottom}px`;
|
|
1045
|
+
if (opts.offset.left !== undefined)
|
|
1046
|
+
c.style.marginLeft = `${opts.offset.left}px`;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1011
1049
|
return c;
|
|
1012
1050
|
}
|
|
1013
1051
|
function renderToast(item) {
|
|
@@ -1061,13 +1099,17 @@ function renderToast(item) {
|
|
|
1061
1099
|
}
|
|
1062
1100
|
return el;
|
|
1063
1101
|
}
|
|
1064
|
-
function initToasters(root = document.body, positions = ['top-right']) {
|
|
1102
|
+
function initToasters(root = document.body, positions = ['top-right'], opts) {
|
|
1065
1103
|
const containers = {};
|
|
1066
1104
|
positions.forEach((pos) => {
|
|
1067
|
-
const c = createContainer(pos);
|
|
1105
|
+
const c = createContainer(pos, root, opts);
|
|
1068
1106
|
root.appendChild(c);
|
|
1069
1107
|
containers[pos] = c;
|
|
1070
1108
|
});
|
|
1109
|
+
if (opts === null || opts === void 0 ? void 0 : opts.options)
|
|
1110
|
+
window.sileo._globalOptions = opts.options;
|
|
1111
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1112
|
+
window.sileo._theme = opts.theme;
|
|
1071
1113
|
function rerender(items) {
|
|
1072
1114
|
positions.forEach((pos) => {
|
|
1073
1115
|
const container = containers[pos];
|
package/dist/notify.umd.js
CHANGED
|
@@ -26,8 +26,21 @@
|
|
|
26
26
|
return this.toasts.slice();
|
|
27
27
|
}
|
|
28
28
|
show(opts) {
|
|
29
|
+
// Normalizar props avanzadas
|
|
30
|
+
const { icon, fill, styles, roundness, autopilot, ...rest } = opts;
|
|
29
31
|
const id = this.nextId();
|
|
30
|
-
const item = {
|
|
32
|
+
const item = {
|
|
33
|
+
id,
|
|
34
|
+
options: {
|
|
35
|
+
...rest,
|
|
36
|
+
...(icon !== undefined ? { icon } : {}),
|
|
37
|
+
...(fill !== undefined ? { fill } : {}),
|
|
38
|
+
...(styles !== undefined ? { styles } : {}),
|
|
39
|
+
...(roundness !== undefined ? { roundness } : {}),
|
|
40
|
+
...(autopilot !== undefined ? { autopilot } : {}),
|
|
41
|
+
},
|
|
42
|
+
createdAt: Date.now(),
|
|
43
|
+
};
|
|
31
44
|
this.toasts.push(item);
|
|
32
45
|
this.notify();
|
|
33
46
|
return id;
|
|
@@ -67,6 +80,13 @@
|
|
|
67
80
|
const loadingId = this.show({ ...(opts.loading || {}), type: 'loading', position: opts.position });
|
|
68
81
|
p.then((res) => {
|
|
69
82
|
this.dismiss(loadingId);
|
|
83
|
+
if (opts.action) {
|
|
84
|
+
const actionOpt = typeof opts.action === 'function' ? opts.action(res) : opts.action;
|
|
85
|
+
if (actionOpt) {
|
|
86
|
+
this.show({ ...(actionOpt || {}), type: 'action', position: opts.position });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
70
90
|
const successOpt = typeof opts.success === 'function' ? opts.success(res) : opts.success;
|
|
71
91
|
if (successOpt)
|
|
72
92
|
this.show({ ...(successOpt || {}), type: 'success', position: opts.position });
|
|
@@ -1008,12 +1028,30 @@
|
|
|
1008
1028
|
'bottom-center',
|
|
1009
1029
|
'bottom-right'
|
|
1010
1030
|
];
|
|
1011
|
-
function createContainer(position, root) {
|
|
1031
|
+
function createContainer(position, root, opts) {
|
|
1012
1032
|
const c = document.createElement('div');
|
|
1013
1033
|
c.className = 'sileo-toaster';
|
|
1014
1034
|
c.setAttribute('data-position', position);
|
|
1015
1035
|
c.setAttribute('role', 'status');
|
|
1016
1036
|
c.setAttribute('aria-live', 'polite');
|
|
1037
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1038
|
+
c.setAttribute('data-theme', opts.theme);
|
|
1039
|
+
// offset
|
|
1040
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.offset) !== undefined) {
|
|
1041
|
+
if (typeof opts.offset === 'number' || typeof opts.offset === 'string') {
|
|
1042
|
+
c.style.margin = typeof opts.offset === 'number' ? `${opts.offset}px` : opts.offset;
|
|
1043
|
+
}
|
|
1044
|
+
else if (typeof opts.offset === 'object') {
|
|
1045
|
+
if (opts.offset.top !== undefined)
|
|
1046
|
+
c.style.marginTop = `${opts.offset.top}px`;
|
|
1047
|
+
if (opts.offset.right !== undefined)
|
|
1048
|
+
c.style.marginRight = `${opts.offset.right}px`;
|
|
1049
|
+
if (opts.offset.bottom !== undefined)
|
|
1050
|
+
c.style.marginBottom = `${opts.offset.bottom}px`;
|
|
1051
|
+
if (opts.offset.left !== undefined)
|
|
1052
|
+
c.style.marginLeft = `${opts.offset.left}px`;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1017
1055
|
return c;
|
|
1018
1056
|
}
|
|
1019
1057
|
function renderToast(item) {
|
|
@@ -1067,13 +1105,17 @@
|
|
|
1067
1105
|
}
|
|
1068
1106
|
return el;
|
|
1069
1107
|
}
|
|
1070
|
-
function initToasters(root = document.body, positions = ['top-right']) {
|
|
1108
|
+
function initToasters(root = document.body, positions = ['top-right'], opts) {
|
|
1071
1109
|
const containers = {};
|
|
1072
1110
|
positions.forEach((pos) => {
|
|
1073
|
-
const c = createContainer(pos);
|
|
1111
|
+
const c = createContainer(pos, root, opts);
|
|
1074
1112
|
root.appendChild(c);
|
|
1075
1113
|
containers[pos] = c;
|
|
1076
1114
|
});
|
|
1115
|
+
if (opts === null || opts === void 0 ? void 0 : opts.options)
|
|
1116
|
+
window.sileo._globalOptions = opts.options;
|
|
1117
|
+
if (opts === null || opts === void 0 ? void 0 : opts.theme)
|
|
1118
|
+
window.sileo._theme = opts.theme;
|
|
1077
1119
|
function rerender(items) {
|
|
1078
1120
|
positions.forEach((pos) => {
|
|
1079
1121
|
const container = containers[pos];
|
package/docs/browser.md
CHANGED
|
@@ -1,44 +1,79 @@
|
|
|
1
|
-
# Browser (UMD / no-bundler)
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Browser / CDN usage
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
Use this package directly in the browser when you cannot use npm modules or a bundler (e.g. Shopify, WordPress, static HTML).
|
|
5
|
+
|
|
6
|
+
## Quick start
|
|
7
|
+
|
|
8
|
+
Add the stylesheet and UMD bundle to your HTML:
|
|
6
9
|
|
|
7
10
|
```html
|
|
8
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.
|
|
9
|
-
<script src="https://unpkg.com/@samline/notify@0.1.
|
|
11
|
+
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css">
|
|
12
|
+
<script src="https://unpkg.com/@samline/notify@0.1.15/dist/notify.umd.js"></script>
|
|
10
13
|
<script>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
15
|
+
const api = window.notify; // or window.notifications for legacy
|
|
16
|
+
api.initToasters(document.body, ['top-right']);
|
|
17
|
+
api.notify({ title: 'Hello', description: 'No-bundler usage', type: 'info' });
|
|
18
|
+
});
|
|
15
19
|
</script>
|
|
16
20
|
```
|
|
17
21
|
|
|
18
|
-
Notes
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
- Make sure to load `dist/styles.css` for styles and animations.
|
|
23
|
+
## API
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
- The UMD bundle exposes `window.notify` (recommended) and `window.notifications` (legacy/compatibility).
|
|
26
|
+
- Always include `dist/styles.css` for correct appearance and animations.
|
|
27
|
+
- Use `api.initToasters(container, positions, { offset, options, theme })` to mount containers (usually `document.body`).
|
|
28
|
+
- Use `api.notify({...})` to show a notification.
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
### Advanced Options
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
All notification methods accept advanced options:
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
| Property | Type | Default | Description |
|
|
35
|
+
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
36
|
+
| `title` | string | — | Toast title |
|
|
37
|
+
| `description` | string | — | Optional body text (HTML or string) |
|
|
38
|
+
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
39
|
+
| `position` | string | `top-right` | One of toast positions |
|
|
40
|
+
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
41
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
42
|
+
| `icon` | string | — | Custom icon (SVG or HTML) |
|
|
43
|
+
| `fill` | string | — | Custom background color (SVG or badge) |
|
|
44
|
+
| `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
|
|
45
|
+
| `roundness` | number | 16 | Border radius in pixels |
|
|
46
|
+
| `autopilot` | boolean \| object | true | Auto expand/collapse timing |
|
|
47
|
+
|
|
48
|
+
#### Example: Advanced Toast
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
api.success({
|
|
52
|
+
title: "Styled!",
|
|
53
|
+
fill: "#222",
|
|
54
|
+
icon: '<svg>...</svg>',
|
|
55
|
+
styles: {
|
|
56
|
+
title: "text-white!",
|
|
57
|
+
badge: "bg-white/20!",
|
|
58
|
+
button: "bg-white/10!"
|
|
59
|
+
},
|
|
60
|
+
roundness: 24,
|
|
61
|
+
autopilot: false
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Toaster Options
|
|
66
|
+
|
|
67
|
+
You can pass advanced options to `initToasters`:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
api.initToasters(document.body, ['top-right'], {
|
|
71
|
+
offset: { top: 32, right: 16 },
|
|
72
|
+
options: { fill: '#222', roundness: 20 },
|
|
73
|
+
theme: 'dark'
|
|
74
|
+
});
|
|
39
75
|
```
|
|
40
76
|
|
|
41
|
-
|
|
77
|
+
## Notes
|
|
42
78
|
|
|
43
|
-
|
|
44
|
-
Include `dist/styles.css` for styles and animations when using the UMD/browser bundle.
|
|
79
|
+
- If you need more control or want to avoid global variables, use the ESM/CJS builds with a bundler.
|