@samline/notify 0.2.7 → 1.0.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.
Files changed (46) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +121 -150
  3. package/dist/browser-notify.js +69 -0
  4. package/dist/cc-2Yt7NqMX.mjs +21 -0
  5. package/dist/cc-B6peeNak.mjs +33 -0
  6. package/dist/cc-BWuAzFJ6.js +12 -0
  7. package/dist/cc-CaBHsjUt.js +34 -0
  8. package/dist/cc-DGff5sSY.js +21 -0
  9. package/dist/cc-he3fHS3P.mjs +12 -0
  10. package/dist/notify.d.mts +44 -0
  11. package/dist/notify.d.mts.map +1 -0
  12. package/dist/notify.d.ts +44 -0
  13. package/dist/notify.d.ts.map +1 -0
  14. package/dist/notify.js +90 -0
  15. package/dist/notify.mjs +87 -0
  16. package/dist/react-notify-12s-7LOZlSBi.js +1068 -0
  17. package/dist/react-notify-12s-BjWbwTu8.mjs +1066 -0
  18. package/dist/react.d.mts +66 -0
  19. package/dist/react.d.mts.map +1 -0
  20. package/dist/react.d.ts +66 -0
  21. package/dist/react.d.ts.map +1 -0
  22. package/dist/react.js +18 -0
  23. package/dist/react.mjs +10 -0
  24. package/dist/styles.css +477 -89
  25. package/dist/svelte.d.mts +45 -0
  26. package/dist/svelte.d.mts.map +1 -0
  27. package/dist/svelte.d.ts +45 -0
  28. package/dist/svelte.d.ts.map +1 -0
  29. package/dist/svelte.js +168 -0
  30. package/dist/svelte.mjs +165 -0
  31. package/dist/vue.d.mts +103 -0
  32. package/dist/vue.d.mts.map +1 -0
  33. package/dist/vue.d.ts +103 -0
  34. package/dist/vue.d.ts.map +1 -0
  35. package/dist/vue.js +2099 -0
  36. package/dist/vue.mjs +2096 -0
  37. package/package.json +95 -57
  38. package/dist/index.cjs.js +0 -1249
  39. package/dist/index.esm.js +0 -1242
  40. package/dist/notify.umd.js +0 -1255
  41. package/docs/browser.md +0 -92
  42. package/docs/react.md +0 -275
  43. package/docs/svelte.md +0 -267
  44. package/docs/vanilla.md +0 -256
  45. package/docs/vue.md +0 -301
  46. package/rollup.config.mjs +0 -56
package/docs/vanilla.md DELETED
@@ -1,256 +0,0 @@
1
-
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.
5
-
6
- ## Quick start (ESM / npm)
7
-
8
- ```js
9
- import { notify, initToasters } from '@samline/notify/vanilla';
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' });
13
- ```
14
-
15
- ## Methods: Full Examples
16
-
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');
57
- ```
58
-
59
- ## Advanced Toaster Options
60
-
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.
99
- notify.error(options)
100
- notify.info(options)
101
- notify.warning(options)
102
- notify.action(options)
103
- notify.promise(promise, { loading, success, error, action })
104
- notify.dismiss(id)
105
- notify.clear()
106
- ```
107
-
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
159
-
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 |
173
-
174
- ---
175
-
176
- # Browser / CDN (No Bundler)
177
-
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.7/dist/styles.css">
182
- <script src="https://unpkg.com/@samline/notify@0.2.7/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
- ```
191
-
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.
193
- | `button` | `{ title, onClick }` | — | Optional action button |
194
-
195
- ## Tips
196
-
197
- - Always include the stylesheet for correct appearance.
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.
238
- ```
239
-
240
- ### Promise flow
241
-
242
- ```ts
243
- notify.promise(fetch('/api/save'), {
244
- loading: { title: 'Saving...' },
245
- success: { title: 'Done', type: 'success' },
246
- error: { title: 'Failed', type: 'error' }
247
- import { notify, initToasters } from '@samline/notify/vanilla'; // Import from '@samline/notify/vanilla'
248
- ```
249
-
250
- ## When to use
251
-
252
- Use the vanilla entry when you interact directly with DOM nodes or need a framework-agnostic API.
253
-
254
- ## Accessibility
255
-
256
- Toaster containers use `role="status"` and `aria-live="polite"` by default. Respect `prefers-reduced-motion` in your UI.
package/docs/vue.md DELETED
@@ -1,301 +0,0 @@
1
- # Vue 3
2
-
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:
12
-
13
- ```js
14
- import { createApp } from 'vue';
15
- import App from './App.vue';
16
- import { Toaster } from '@samline/notify/vue';
17
-
18
- const app = createApp(App);
19
- app.component('Toaster', Toaster);
20
- app.mount('#app');
21
- ```
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
-
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):
77
-
78
- ```js
79
- this.$notify.show({ title: 'From global' });
80
- ```
81
-
82
- In your template:
83
-
84
- ```vue
85
- <template>
86
- <Toaster />
87
- <button @click="show">Show</button>
88
- </template>
89
-
90
- <script setup>
91
- import { notify } from '@samline/notify/vue';
92
- function show(){ notify.show({ title: 'Hello from Vue' }); }
93
- </script>
94
- ```
95
-
96
- > **Note:**
97
- > Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
98
-
99
-
100
-
101
- ## API
102
-
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 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.
269
- - Advanced: The `Notifications` plugin is available for global/legacy registration, but direct use of `Toaster` is recommended for most apps.
270
- - `useSileo()`: Composable that returns the `sileo` controller if you prefer.
271
-
272
- ### Methods
273
-
274
- ```ts
275
- notify.show(options)
276
- notify.success(options)
277
- notify.error(options)
278
- notify.info(options)
279
- notify.warning(options)
280
- notify.action(options)
281
- notify.promise(promise, { loading, success, error })
282
- notify.dismiss(id)
283
- notify.clear()
284
- ```
285
-
286
- ### Options
287
-
288
- | Property | Type | Default | Description |
289
- | ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
290
- | `title` | string | — | Toast title |
291
- | `description` | string | — | Optional body text |
292
- | `type` | `info\|success\|error\|warning` | `info` | Visual intent |
293
- | `position` | string | `top-right` | One of toast positions |
294
- | `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
295
- | `button` | { title: string, onClick: () => void } | — | Optional action button |
296
-
297
- ## Tips
298
-
299
- - The Vue adapter integrates with the Vue lifecycle and works with Vue 3's Composition API.
300
- - You can customize appearance by importing the stylesheet or overriding CSS variables.
301
- ```
package/rollup.config.mjs DELETED
@@ -1,56 +0,0 @@
1
- import resolve from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import typescript from '@rollup/plugin-typescript';
4
- import copy from 'rollup-plugin-copy';
5
- import replace from '@rollup/plugin-replace';
6
-
7
- export default [
8
- // ESM + CJS
9
- {
10
- input: 'src/vanilla/index.ts',
11
- output: [
12
- { file: 'dist/index.esm.js', format: 'es', exports: 'named' },
13
- { file: 'dist/index.cjs.js', format: 'cjs', exports: 'named' }
14
- ],
15
- plugins: [
16
- replace({
17
- 'process.env.NODE_ENV': JSON.stringify('production'),
18
- preventAssignment: true
19
- }),
20
- resolve(),
21
- commonjs(),
22
- typescript({ tsconfig: './tsconfig.json' }),
23
- copy({
24
- targets: [
25
- { src: 'src/styles/sileo.css', dest: 'dist', rename: 'styles.css' }
26
- ],
27
- verbose: true
28
- })
29
- ]
30
- },
31
- // UMD build for browser (vanilla DOM use)
32
- {
33
- input: 'src/vanilla/index.ts',
34
- output: {
35
- file: 'dist/notify.umd.js',
36
- format: 'umd',
37
- exports: 'named',
38
- name: 'notify'
39
- },
40
- plugins: [
41
- replace({
42
- 'process.env.NODE_ENV': JSON.stringify('production'),
43
- preventAssignment: true
44
- }),
45
- resolve(),
46
- commonjs(),
47
- typescript({ tsconfig: './tsconfig.json' }),
48
- copy({
49
- targets: [
50
- { src: 'src/styles/sileo.css', dest: 'dist', rename: 'styles.css' }
51
- ],
52
- verbose: true
53
- })
54
- ]
55
- }
56
- ];