@samline/notify 0.1.15 → 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/docs/vanilla.md CHANGED
@@ -1,69 +1,240 @@
1
- # Vanilla JS
2
1
 
3
- Use the vanilla adapter for plain JavaScript projects, either with modules or directly via CDN.
2
+ # Vanilla JS (Bundler/Import)
3
+
4
+ Use the vanilla adapter for plain JavaScript projects with a bundler (Vite, Webpack, etc) or Node.js ESM/CJS. This entrypoint provides full API and advanced options.
4
5
 
5
6
  ## Quick start (ESM / npm)
6
7
 
7
- ```ts
8
+ ```js
8
9
  import { notify, initToasters } from '@samline/notify/vanilla';
9
- initToasters(document.body, ['top-right']);
10
- notify({ title: 'Saved', description: 'Your changes have been saved', type: 'success' });
10
+ // Always use an array of strings as the second argument
11
+ initToasters(document.body, ['top-left']);
12
+ notify.success({ title: 'Saved', description: 'Your changes have been saved' });
11
13
  ```
12
14
 
13
- ## Quick start (CDN / UMD)
15
+ ## Methods: Full Examples
14
16
 
15
- ```html
16
- <link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css">
17
- <script src="https://unpkg.com/@samline/notify@0.1.15/dist/notify.umd.js"></script>
18
- <script>
19
- document.addEventListener('DOMContentLoaded', () => {
20
- const api = window.notify;
21
- api.initToasters(document.body, ['top-right']);
22
- api.notify({ title: 'Saved', description: 'Your changes have been saved', type: 'success' });
23
- });
24
- </script>
17
+ ```js
18
+ // Show a generic toast
19
+ notify.show({ title: 'Hello', description: 'Generic toast', type: 'info' });
20
+
21
+ // Success toast
22
+ notify.success({ title: 'Success!', description: 'Operation completed.' });
23
+
24
+ // Error toast
25
+ notify.error({ title: 'Error', description: 'Something went wrong.' });
26
+
27
+ // Info toast
28
+ notify.info({ title: 'Heads up!', description: 'This is an info toast.' });
29
+
30
+ // Warning toast
31
+ notify.warning({ title: 'Warning!', description: 'Be careful.' });
32
+
33
+ // Action toast with button
34
+ notify.action({
35
+ title: 'Action required',
36
+ description: 'Click the button to proceed.',
37
+ button: { title: 'Proceed', onClick: () => alert('Action!') }
38
+ });
39
+
40
+ // Promise toast (loading, success, error, action)
41
+ notify.promise(fetch('/api/save'), {
42
+ loading: { title: 'Saving...' },
43
+ success: { title: 'Saved!', description: 'Your data was saved.' },
44
+ error: { title: 'Failed', description: 'Could not save.' },
45
+ action: { title: 'Retry?', button: { title: 'Retry', onClick: () => {/* retry logic */} } }
46
+ });
47
+
48
+ // Dismiss a toast by id
49
+ const id = notify.success({ title: 'Dismiss me' });
50
+ notify.dismiss(id);
51
+
52
+ // Clear all toasts
53
+ notify.clear();
54
+
55
+ // Clear only a position
56
+ notify.clear('top-right');
25
57
  ```
26
58
 
27
- ## API
59
+ ## Advanced Toaster Options
28
60
 
29
- ```ts
30
- // Core controller (primary: `notify`, compatibility alias: `sileo`)
31
- notify.show(options)
32
- notify.success(options)
61
+ You can pass advanced options to `initToasters`:
62
+
63
+ ```js
64
+ // Correct example with one position (dynamic fallback)
65
+ initToasters(document.body, ['bottom-left'], {
66
+ offset: { top: 32, right: 16 },
67
+ options: { fill: '#222', roundness: 20 },
68
+ theme: 'dark'
69
+ });
70
+ ```
71
+
72
+ ### Example: Multiple positions and custom offset
73
+
74
+ ```js
75
+ // Correct example with multiple positions (classic fallback)
76
+ initToasters(document.body, ['top-right', 'bottom-left'], {
77
+ offset: { top: 24, right: 24, bottom: 24, left: 24 },
78
+ theme: 'light',
79
+ options: { fill: '#0f1724', roundness: 18 }
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
+ });
88
+ ```
89
+
90
+ ---
91
+
92
+ ## ⚠️ Warnings and Best Practices
93
+
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.
33
99
  notify.error(options)
34
100
  notify.info(options)
35
101
  notify.warning(options)
36
102
  notify.action(options)
37
- notify.promise(promise, { loading, success, error })
103
+ notify.promise(promise, { loading, success, error, action })
38
104
  notify.dismiss(id)
39
105
  notify.clear()
40
106
  ```
41
107
 
42
- ### Parameters
108
+ ## Options: Full Examples
109
+
110
+ ```js
111
+ // Custom icon (SVG string)
112
+ notify.success({
113
+ title: 'With Icon',
114
+ icon: '<svg width="16" height="16" ...>...</svg>'
115
+ });
116
+
117
+ // Custom fill color
118
+ notify.info({
119
+ title: 'Colored',
120
+ fill: '#2563eb'
121
+ });
122
+
123
+ // Custom styles for sub-elements
124
+ notify.success({
125
+ title: 'Styled',
126
+ styles: {
127
+ title: 'my-title-class',
128
+ badge: 'my-badge-class',
129
+ button: 'my-btn-class'
130
+ }
131
+ });
132
+
133
+ // Custom roundness
134
+ notify.success({
135
+ title: 'Rounded',
136
+ roundness: 32
137
+ });
138
+
139
+ // Autopilot off (manual expand/collapse)
140
+ notify.success({
141
+ title: 'Manual',
142
+ autopilot: false
143
+ });
144
+
145
+ // Custom duration (sticky)
146
+ notify.info({
147
+ title: 'Sticky',
148
+ duration: null
149
+ });
150
+
151
+ // Custom position
152
+ notify.success({
153
+ title: 'Bottom left',
154
+ position: 'bottom-left'
155
+ });
156
+ ```
157
+
158
+ ### Options
43
159
 
44
- | Parameter | Type | Description |
45
- | --- | --- | --- |
46
- | `options` | object | Toast creation options (see Options below) |
160
+ | Property | Type | Default | Description |
161
+ | ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
162
+ | `title` | string | | Toast title |
163
+ | `description` | string | — | Optional body text |
164
+ | `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
165
+ | `position` | string | `top-right` | Container position |
166
+ | `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (`null` = sticky)|
167
+ | `button` | { title: string, onClick: () => void } | — | Optional action button |
168
+ | `icon` | string | — | Custom icon (SVG or HTML) |
169
+ | `fill` | string | — | Custom background color (SVG or badge) |
170
+ | `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
171
+ | `roundness` | number | 16 | Border radius in pixels |
172
+ | `autopilot` | boolean \| object | true | Auto expand/collapse timing |
47
173
 
48
- ### Returns
174
+ ---
49
175
 
50
- `string | void` `show` returns a toast id when created.
176
+ # Browser / CDN (No Bundler)
51
177
 
52
- ## Options
178
+ If you are not using a bundler, use the [Browser guide](./browser.md) for CDN usage. Example:
179
+
180
+ ```html
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>
183
+ <script>
184
+ document.addEventListener('DOMContentLoaded', () => {
185
+ const api = window.notify;
186
+ api.initToasters(document.body, ['top-right']);
187
+ api.notify({ title: 'Saved', description: 'Your changes have been saved', type: 'success' });
188
+ });
189
+ </script>
190
+ ```
53
191
 
54
- | Property | Type | Default | Description |
55
- | --- | --- | --- | --- |
56
- | `title` | `string` | — | Toast title |
57
- | `description` | `string` | — | Optional body text |
58
- | `type` | `info\|success\|error\|warning` | `info` | Visual intent |
59
- | `position` | `string` | `top-right` | Container position |
60
- | `duration` | `number` | `4000` | Auto-dismiss timeout in ms (`null` = sticky) |
192
+ > The CDN/UMD build exposes `window.notify` and only supports string/HTML for icons and content. For advanced options, use the import/bundler version.
61
193
  | `button` | `{ title, onClick }` | — | Optional action button |
62
194
 
63
195
  ## Tips
64
196
 
65
197
  - Always include the stylesheet for correct appearance.
66
198
  - Use the ESM build for modern projects, or the UMD build for legacy/static sites.
199
+
200
+ ## Customizing Styles
201
+
202
+ - Override CSS variables in your stylesheet or inline:
203
+
204
+ ```css
205
+ :root {
206
+ --sileo-bg: #18181b;
207
+ --sileo-success: #22c55e;
208
+ --sileo-error: #ef4444;
209
+ --sileo-info: #2563eb;
210
+ --sileo-warning: #f59e0b;
211
+ }
212
+ ```
213
+
214
+ - Add custom classes via the `styles` option for title, badge, button, description.
215
+
216
+ ## Accessibility
217
+
218
+ - Toast containers use `role="status"` and `aria-live="polite"`.
219
+ - Respects `prefers-reduced-motion` for users with motion sensitivity.
220
+
221
+ ## Common Errors & Troubleshooting
222
+
223
+ - **No styles?** Make sure to import or link `dist/styles.css`.
224
+ - **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
225
+ - **Button not working?** Ensure your `onClick` is a function and not a string.
226
+ - **Nothing appears?** Confirm you called `initToasters` and are using the correct container.
227
+
228
+ ## Migration & Best Practices
229
+
230
+ - If migrating from Sileo, all options and methods are compatible.
231
+ - Use the ESM/bundler version for full feature support.
232
+ - Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
233
+ - Use `notify.clear()` to remove all toasts, or pass a position to clear only one area.
234
+
235
+ ---
236
+
237
+ For framework-specific usage, see the React, Vue, and Svelte guides.
67
238
  ```
68
239
 
69
240
  ### Promise flow
package/docs/vue.md CHANGED
@@ -20,6 +20,50 @@ app.component('Toaster', Toaster);
20
20
  app.mount('#app');
21
21
  ```
22
22
 
23
+ ## Methods: Full Examples
24
+
25
+ ```js
26
+ // Show a generic toast
27
+ notify.show({ title: 'Hello', description: 'Generic toast', type: 'info' });
28
+
29
+ // Success toast
30
+ notify.success({ title: 'Success!', description: 'Operation completed.' });
31
+
32
+ // Error toast
33
+ notify.error({ title: 'Error', description: 'Something went wrong.' });
34
+
35
+ // Info toast
36
+ notify.info({ title: 'Heads up!', description: 'This is an info toast.' });
37
+
38
+ // Warning toast
39
+ notify.warning({ title: 'Warning!', description: 'Be careful.' });
40
+
41
+ // Action toast with button
42
+ notify.action({
43
+ title: 'Action required',
44
+ description: 'Click the button to proceed.',
45
+ button: { title: 'Proceed', onClick: () => alert('Action!') }
46
+ });
47
+
48
+ // Promise toast (loading, success, error, action)
49
+ notify.promise(fetch('/api/save'), {
50
+ loading: { title: 'Saving...' },
51
+ success: { title: 'Saved!', description: 'Your data was saved.' },
52
+ error: { title: 'Failed', description: 'Could not save.' },
53
+ action: { title: 'Retry?', button: { title: 'Retry', onClick: () => {/* retry logic */} } }
54
+ });
55
+
56
+ // Dismiss a toast by id
57
+ const id = notify.success({ title: 'Dismiss me' });
58
+ notify.dismiss(id);
59
+
60
+ // Clear all toasts
61
+ notify.clear();
62
+
63
+ // Clear only a position
64
+ notify.clear('top-right');
65
+ ```
66
+
23
67
 
24
68
 
25
69
  Use the `notify` controller to show notifications:
@@ -51,13 +95,177 @@ function show(){ notify.show({ title: 'Hello from Vue' }); }
51
95
 
52
96
  > **Note:**
53
97
  > Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
54
- > CDN: `<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css">`
98
+
55
99
 
56
100
 
57
101
  ## API
58
102
 
59
103
  - `Toaster`: Main visual component (same as in React and Svelte).
60
104
  - `notify`: Programmatic controller for showing notifications. Import from `@samline/notify/vue` or use `this.$notify` if using the plugin.
105
+
106
+ ### Options
107
+
108
+ All notification methods accept advanced options:
109
+
110
+ | Property | Type | Default | Description |
111
+ | ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
112
+ | `title` | string | — | Toast title |
113
+ | `description` | string \| VNode | — | Optional body text (HTML or string) |
114
+ | `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
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
+ | `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
117
+ | `button` | { title: string, onClick: () => void } | — | Optional action button |
118
+ | `icon` | string \| VNode | — | Custom icon (SVG or node) |
119
+ | `fill` | string | — | Custom background color (SVG or badge) |
120
+ | `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
121
+ | `roundness` | number | 16 | Border radius in pixels |
122
+ | `autopilot` | boolean \| object | true | Auto expand/collapse timing |
123
+
124
+ #### Example: Advanced Toasts
125
+
126
+ ```js
127
+ // Custom icon (SVG string or VNode)
128
+ notify.success({
129
+ title: 'With Icon',
130
+ icon: '<svg width="16" height="16" ...>...</svg>'
131
+ });
132
+
133
+ // Custom fill color
134
+ notify.info({
135
+ title: 'Colored',
136
+ fill: '#2563eb'
137
+ });
138
+
139
+ // Custom styles for sub-elements
140
+ notify.success({
141
+ title: 'Styled',
142
+ styles: {
143
+ title: 'my-title-class',
144
+ badge: 'my-badge-class',
145
+ button: 'my-btn-class'
146
+ }
147
+ });
148
+
149
+ // Custom roundness
150
+ notify.success({
151
+ title: 'Rounded',
152
+ roundness: 32
153
+ });
154
+
155
+ // Autopilot off (manual expand/collapse)
156
+ notify.success({
157
+ title: 'Manual',
158
+ autopilot: false
159
+ });
160
+
161
+ // Custom duration (sticky)
162
+ notify.info({
163
+ title: 'Sticky',
164
+ duration: null
165
+ });
166
+
167
+ // Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
168
+ notify.success({
169
+ title: 'Bottom left',
170
+ position: 'bottom-left'
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.
179
+
180
+ // Description as VNode
181
+ notify.info({
182
+ title: 'VNode Description',
183
+ description: h('span', { style: 'color: red' }, 'Custom VNode content')
184
+ });
185
+ ```
186
+
187
+ #### Example: Advanced Toast
188
+
189
+ ```js
190
+ notify.success({
191
+ title: "Styled!",
192
+ fill: "#222",
193
+ icon: '<svg>...</svg>',
194
+ styles: {
195
+ title: "text-white!",
196
+ badge: "bg-white/20!",
197
+ button: "bg-white/10!"
198
+ },
199
+ roundness: 24,
200
+ autopilot: false
201
+ });
202
+ ```
203
+
204
+ #### Promise Toasts
205
+
206
+ ```js
207
+ notify.promise(fetchData(), {
208
+ loading: { title: "Loading..." },
209
+ success: (data) => ({ title: `Loaded ${data.name}` }),
210
+ error: (err) => ({ title: "Error", description: err.message }),
211
+ action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
212
+ });
213
+ ```
214
+
215
+ ### Toaster Component Props
216
+
217
+ The `<Toaster />` component accepts the following props:
218
+
219
+ | Prop | Type | Default | Description |
220
+ | --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
221
+ | `position`| string | top-right | Default toast position |
222
+ | `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
223
+ | `options` | Partial<Options> | — | Default options for all toasts |
224
+ | `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
225
+
226
+ #### Example: Custom Toaster
227
+
228
+ ```vue
229
+ <Toaster position="bottom-center" :offset="24" theme="dark" :options="{ fill: '#222', roundness: 20 }" />
230
+ ```
231
+
232
+ ## Customizing Styles
233
+
234
+ - Override CSS variables in your stylesheet or inline:
235
+
236
+ ```css
237
+ :root {
238
+ --sileo-bg: #18181b;
239
+ --sileo-success: #22c55e;
240
+ --sileo-error: #ef4444;
241
+ --sileo-info: #2563eb;
242
+ --sileo-warning: #f59e0b;
243
+ }
244
+ ```
245
+
246
+ - Add custom classes via the `styles` option for title, badge, button, description.
247
+
248
+ ## Accessibility
249
+
250
+ - Toast containers use `role="status"` and `aria-live="polite"`.
251
+ - Respects `prefers-reduced-motion` for users with motion sensitivity.
252
+
253
+ ## Common Errors & Troubleshooting
254
+
255
+ - **No styles?** Make sure to import or link `dist/styles.css`.
256
+ - **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
257
+ - **Button not working?** Ensure your `onClick` is a function and not a string.
258
+ - **Nothing appears?** Confirm you rendered `<Toaster />` and are using the correct import.
259
+
260
+ ## Migration & Best Practices
261
+
262
+ - If migrating from Sileo, all options and methods are compatible.
263
+ - Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
264
+ - Use `notify.clear()` to remove all toasts, o pasar una posición para limpiar solo un área.
265
+
266
+ ---
267
+
268
+ For other frameworks, see the React, Svelte, and Vanilla guides.
61
269
  - Advanced: The `Notifications` plugin is available for global/legacy registration, but direct use of `Toaster` is recommended for most apps.
62
270
  - `useSileo()`: Composable that returns the `sileo` controller if you prefer.
63
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samline/notify",
3
- "version": "0.1.15",
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",