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