@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/README.md +101 -17
- package/dist/index.cjs.js +60 -9
- package/dist/index.esm.js +60 -9
- package/dist/notify.umd.js +60 -9
- package/docs/browser.md +65 -4
- package/docs/react.md +203 -4
- package/docs/svelte.md +203 -4
- package/docs/vanilla.md +207 -36
- package/docs/vue.md +209 -1
- package/package.json +2 -1
package/docs/react.md
CHANGED
|
@@ -26,9 +26,53 @@ export function App() {
|
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## Methods: Full Examples
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// Show a generic toast
|
|
33
|
+
notify.show({ title: 'Hello', description: 'Generic toast', type: 'info' });
|
|
34
|
+
|
|
35
|
+
// Success toast
|
|
36
|
+
notify.success({ title: 'Success!', description: 'Operation completed.' });
|
|
37
|
+
|
|
38
|
+
// Error toast
|
|
39
|
+
notify.error({ title: 'Error', description: 'Something went wrong.' });
|
|
40
|
+
|
|
41
|
+
// Info toast
|
|
42
|
+
notify.info({ title: 'Heads up!', description: 'This is an info toast.' });
|
|
43
|
+
|
|
44
|
+
// Warning toast
|
|
45
|
+
notify.warning({ title: 'Warning!', description: 'Be careful.' });
|
|
46
|
+
|
|
47
|
+
// Action toast with button
|
|
48
|
+
notify.action({
|
|
49
|
+
title: 'Action required',
|
|
50
|
+
description: 'Click the button to proceed.',
|
|
51
|
+
button: { title: 'Proceed', onClick: () => alert('Action!') }
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Promise toast (loading, success, error, action)
|
|
55
|
+
notify.promise(fetch('/api/save'), {
|
|
56
|
+
loading: { title: 'Saving...' },
|
|
57
|
+
success: { title: 'Saved!', description: 'Your data was saved.' },
|
|
58
|
+
error: { title: 'Failed', description: 'Could not save.' },
|
|
59
|
+
action: { title: 'Retry?', button: { title: 'Retry', onClick: () => {/* retry logic */} } }
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Dismiss a toast by id
|
|
63
|
+
const id = notify.success({ title: 'Dismiss me' });
|
|
64
|
+
notify.dismiss(id);
|
|
65
|
+
|
|
66
|
+
// Clear all toasts
|
|
67
|
+
notify.clear();
|
|
68
|
+
|
|
69
|
+
// Clear only a position
|
|
70
|
+
notify.clear('top-right');
|
|
71
|
+
```
|
|
72
|
+
|
|
29
73
|
> **Note:**
|
|
30
74
|
> Import `@samline/notify/dist/styles.css` in your main entrypoint or include it in your HTML for correct appearance.
|
|
31
|
-
|
|
75
|
+
|
|
32
76
|
|
|
33
77
|
|
|
34
78
|
## API
|
|
@@ -52,12 +96,167 @@ notify.clear()
|
|
|
52
96
|
|
|
53
97
|
### Options
|
|
54
98
|
|
|
99
|
+
All notification methods accept advanced options:
|
|
100
|
+
|
|
55
101
|
| Property | Type | Default | Description |
|
|
56
102
|
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
57
103
|
| `title` | string | — | Toast title |
|
|
58
|
-
| `description` | string
|
|
59
|
-
| `type` | `info\|success\|error\|warning
|
|
60
|
-
| `position` | string | `top-right` | One of
|
|
104
|
+
| `description` | string \| ReactNode | — | Optional body text (JSX or string) |
|
|
105
|
+
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
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
|
+
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
108
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
109
|
+
| `icon` | string \| ReactNode | — | Custom icon (SVG or JSX) |
|
|
110
|
+
| `fill` | string | — | Custom background color (SVG or badge) |
|
|
111
|
+
| `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
|
|
112
|
+
| `roundness` | number | 16 | Border radius in pixels |
|
|
113
|
+
| `autopilot` | boolean \| object | true | Auto expand/collapse timing |
|
|
114
|
+
|
|
115
|
+
#### Example: Advanced Toasts
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
// Custom icon (SVG string or JSX)
|
|
119
|
+
notify.success({
|
|
120
|
+
title: 'With Icon',
|
|
121
|
+
icon: <svg width="16" height="16" ...>...</svg>
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Custom fill color
|
|
125
|
+
notify.info({
|
|
126
|
+
title: 'Colored',
|
|
127
|
+
fill: '#2563eb'
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Custom styles for sub-elements
|
|
131
|
+
notify.success({
|
|
132
|
+
title: 'Styled',
|
|
133
|
+
styles: {
|
|
134
|
+
title: 'my-title-class',
|
|
135
|
+
badge: 'my-badge-class',
|
|
136
|
+
button: 'my-btn-class'
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Custom roundness
|
|
141
|
+
notify.success({
|
|
142
|
+
title: 'Rounded',
|
|
143
|
+
roundness: 32
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Autopilot off (manual expand/collapse)
|
|
147
|
+
notify.success({
|
|
148
|
+
title: 'Manual',
|
|
149
|
+
autopilot: false
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Custom duration (sticky)
|
|
153
|
+
notify.info({
|
|
154
|
+
title: 'Sticky',
|
|
155
|
+
duration: null
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
|
|
159
|
+
notify.success({
|
|
160
|
+
title: 'Bottom left',
|
|
161
|
+
position: 'bottom-left'
|
|
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.
|
|
170
|
+
|
|
171
|
+
// Description as ReactNode
|
|
172
|
+
notify.info({
|
|
173
|
+
title: 'JSX Description',
|
|
174
|
+
description: <span style={{ color: 'red' }}>Custom JSX content</span>
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### Example: Advanced Toast
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
notify.success({
|
|
182
|
+
title: "Styled!",
|
|
183
|
+
fill: "#222",
|
|
184
|
+
icon: '<svg>...</svg>',
|
|
185
|
+
styles: {
|
|
186
|
+
title: "text-white!",
|
|
187
|
+
badge: "bg-white/20!",
|
|
188
|
+
button: "bg-white/10!"
|
|
189
|
+
},
|
|
190
|
+
roundness: 24,
|
|
191
|
+
autopilot: false
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### Promise Toasts
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
notify.promise(fetchData(), {
|
|
199
|
+
loading: { title: "Loading..." },
|
|
200
|
+
success: (data) => ({ title: `Loaded ${data.name}` }),
|
|
201
|
+
error: (err) => ({ title: "Error", description: err.message }),
|
|
202
|
+
action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Toaster Component Props
|
|
207
|
+
|
|
208
|
+
The `<Toaster />` component accepts the following props:
|
|
209
|
+
|
|
210
|
+
| Prop | Type | Default | Description |
|
|
211
|
+
| --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
|
|
212
|
+
| `position`| string | top-right | Default toast position |
|
|
213
|
+
| `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
|
|
214
|
+
| `options` | Partial<Options> | — | Default options for all toasts |
|
|
215
|
+
| `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
|
|
216
|
+
|
|
217
|
+
#### Example: Custom Toaster
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
<Toaster position="bottom-center" offset={24} theme="dark" options={{ fill: '#222', roundness: 20 }} />
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Customizing Styles
|
|
224
|
+
|
|
225
|
+
- Override CSS variables in your stylesheet or inline:
|
|
226
|
+
|
|
227
|
+
```css
|
|
228
|
+
:root {
|
|
229
|
+
--sileo-bg: #18181b;
|
|
230
|
+
--sileo-success: #22c55e;
|
|
231
|
+
--sileo-error: #ef4444;
|
|
232
|
+
--sileo-info: #2563eb;
|
|
233
|
+
--sileo-warning: #f59e0b;
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- Add custom classes via the `styles` option for title, badge, button, description.
|
|
238
|
+
|
|
239
|
+
## Accessibility
|
|
240
|
+
|
|
241
|
+
- Toast containers use `role="status"` and `aria-live="polite"`.
|
|
242
|
+
- Respects `prefers-reduced-motion` for users with motion sensitivity.
|
|
243
|
+
|
|
244
|
+
## Common Errors & Troubleshooting
|
|
245
|
+
|
|
246
|
+
- **No styles?** Make sure to import or link `dist/styles.css`.
|
|
247
|
+
- **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
|
|
248
|
+
- **Button not working?** Ensure your `onClick` is a function and not a string.
|
|
249
|
+
- **Nothing appears?** Confirm you rendered `<Toaster />` and are using the correct import.
|
|
250
|
+
|
|
251
|
+
## Migration & Best Practices
|
|
252
|
+
|
|
253
|
+
- If migrating from Sileo, all options and methods are compatible.
|
|
254
|
+
- Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
|
|
255
|
+
- Use `notify.clear()` to remove all toasts, or pass a position to clear only one area.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
For other frameworks, see the Vue, Svelte, and Vanilla guides.
|
|
61
260
|
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
62
261
|
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
63
262
|
|
package/docs/svelte.md
CHANGED
|
@@ -26,9 +26,53 @@ Import and initialize in your root component:
|
|
|
26
26
|
<button on:click={show}>Show</button>
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## Methods: Full Examples
|
|
30
|
+
|
|
31
|
+
```svelte
|
|
32
|
+
// Show a generic toast
|
|
33
|
+
notify.show({ title: 'Hello', description: 'Generic toast', type: 'info' });
|
|
34
|
+
|
|
35
|
+
// Success toast
|
|
36
|
+
notify.success({ title: 'Success!', description: 'Operation completed.' });
|
|
37
|
+
|
|
38
|
+
// Error toast
|
|
39
|
+
notify.error({ title: 'Error', description: 'Something went wrong.' });
|
|
40
|
+
|
|
41
|
+
// Info toast
|
|
42
|
+
notify.info({ title: 'Heads up!', description: 'This is an info toast.' });
|
|
43
|
+
|
|
44
|
+
// Warning toast
|
|
45
|
+
notify.warning({ title: 'Warning!', description: 'Be careful.' });
|
|
46
|
+
|
|
47
|
+
// Action toast with button
|
|
48
|
+
notify.action({
|
|
49
|
+
title: 'Action required',
|
|
50
|
+
description: 'Click the button to proceed.',
|
|
51
|
+
button: { title: 'Proceed', onClick: () => alert('Action!') }
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Promise toast (loading, success, error, action)
|
|
55
|
+
notify.promise(fetch('/api/save'), {
|
|
56
|
+
loading: { title: 'Saving...' },
|
|
57
|
+
success: { title: 'Saved!', description: 'Your data was saved.' },
|
|
58
|
+
error: { title: 'Failed', description: 'Could not save.' },
|
|
59
|
+
action: { title: 'Retry?', button: { title: 'Retry', onClick: () => {/* retry logic */} } }
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Dismiss a toast by id
|
|
63
|
+
const id = notify.success({ title: 'Dismiss me' });
|
|
64
|
+
notify.dismiss(id);
|
|
65
|
+
|
|
66
|
+
// Clear all toasts
|
|
67
|
+
notify.clear();
|
|
68
|
+
|
|
69
|
+
// Clear only a position
|
|
70
|
+
notify.clear('top-right');
|
|
71
|
+
```
|
|
72
|
+
|
|
29
73
|
> **Note:**
|
|
30
74
|
> Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
|
|
31
|
-
|
|
75
|
+
|
|
32
76
|
|
|
33
77
|
|
|
34
78
|
## API
|
|
@@ -53,12 +97,167 @@ notify.clear()
|
|
|
53
97
|
|
|
54
98
|
### Options
|
|
55
99
|
|
|
100
|
+
All notification methods accept advanced options:
|
|
101
|
+
|
|
56
102
|
| Property | Type | Default | Description |
|
|
57
103
|
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
58
104
|
| `title` | string | — | Toast title |
|
|
59
|
-
| `description` | string
|
|
60
|
-
| `type` | `info\|success\|error\|warning
|
|
61
|
-
| `position` | string | `top-right` | One of
|
|
105
|
+
| `description` | string \| SvelteNode | — | Optional body text (HTML or string) |
|
|
106
|
+
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
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
|
+
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
109
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
110
|
+
| `icon` | string \| SvelteNode | — | Custom icon (SVG or node) |
|
|
111
|
+
| `fill` | string | — | Custom background color (SVG or badge) |
|
|
112
|
+
| `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
|
|
113
|
+
| `roundness` | number | 16 | Border radius in pixels |
|
|
114
|
+
| `autopilot` | boolean \| object | true | Auto expand/collapse timing |
|
|
115
|
+
|
|
116
|
+
#### Example: Advanced Toasts
|
|
117
|
+
|
|
118
|
+
```svelte
|
|
119
|
+
// Custom icon (SVG string or SvelteNode)
|
|
120
|
+
notify.success({
|
|
121
|
+
title: 'With Icon',
|
|
122
|
+
icon: '<svg width="16" height="16" ...>...</svg>'
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Custom fill color
|
|
126
|
+
notify.info({
|
|
127
|
+
title: 'Colored',
|
|
128
|
+
fill: '#2563eb'
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Custom styles for sub-elements
|
|
132
|
+
notify.success({
|
|
133
|
+
title: 'Styled',
|
|
134
|
+
styles: {
|
|
135
|
+
title: 'my-title-class',
|
|
136
|
+
badge: 'my-badge-class',
|
|
137
|
+
button: 'my-btn-class'
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Custom roundness
|
|
142
|
+
notify.success({
|
|
143
|
+
title: 'Rounded',
|
|
144
|
+
roundness: 32
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Autopilot off (manual expand/collapse)
|
|
148
|
+
notify.success({
|
|
149
|
+
title: 'Manual',
|
|
150
|
+
autopilot: false
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Custom duration (sticky)
|
|
154
|
+
notify.info({
|
|
155
|
+
title: 'Sticky',
|
|
156
|
+
duration: null
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Custom position (make sure you initialized that position with <Toaster position="bottom-left" />)
|
|
160
|
+
notify.success({
|
|
161
|
+
title: 'Bottom left',
|
|
162
|
+
position: 'bottom-left'
|
|
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.
|
|
171
|
+
|
|
172
|
+
// Description as SvelteNode
|
|
173
|
+
notify.info({
|
|
174
|
+
title: 'Node Description',
|
|
175
|
+
description: '<span style="color: red">Custom HTML content</span>'
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Example: Advanced Toast
|
|
180
|
+
|
|
181
|
+
```svelte
|
|
182
|
+
notify.success({
|
|
183
|
+
title: "Styled!",
|
|
184
|
+
fill: "#222",
|
|
185
|
+
icon: '<svg>...</svg>',
|
|
186
|
+
styles: {
|
|
187
|
+
title: "text-white!",
|
|
188
|
+
badge: "bg-white/20!",
|
|
189
|
+
button: "bg-white/10!"
|
|
190
|
+
},
|
|
191
|
+
roundness: 24,
|
|
192
|
+
autopilot: false
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Promise Toasts
|
|
197
|
+
|
|
198
|
+
```svelte
|
|
199
|
+
notify.promise(fetchData(), {
|
|
200
|
+
loading: { title: "Loading..." },
|
|
201
|
+
success: (data) => ({ title: `Loaded ${data.name}` }),
|
|
202
|
+
error: (err) => ({ title: "Error", description: err.message }),
|
|
203
|
+
action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Toaster Component Props
|
|
208
|
+
|
|
209
|
+
The `<Toaster />` component accepts the following props:
|
|
210
|
+
|
|
211
|
+
| Prop | Type | Default | Description |
|
|
212
|
+
| --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
|
|
213
|
+
| `position`| string | top-right | Default toast position |
|
|
214
|
+
| `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
|
|
215
|
+
| `options` | Partial<Options> | — | Default options for all toasts |
|
|
216
|
+
| `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
|
|
217
|
+
|
|
218
|
+
#### Example: Custom Toaster
|
|
219
|
+
|
|
220
|
+
```svelte
|
|
221
|
+
<Toaster position="bottom-center" offset={24} theme="dark" options={{ fill: '#222', roundness: 20 }} />
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Customizing Styles
|
|
225
|
+
|
|
226
|
+
- Override CSS variables in your stylesheet or inline:
|
|
227
|
+
|
|
228
|
+
```css
|
|
229
|
+
:root {
|
|
230
|
+
--sileo-bg: #18181b;
|
|
231
|
+
--sileo-success: #22c55e;
|
|
232
|
+
--sileo-error: #ef4444;
|
|
233
|
+
--sileo-info: #2563eb;
|
|
234
|
+
--sileo-warning: #f59e0b;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
- Add custom classes via the `styles` option for title, badge, button, description.
|
|
239
|
+
|
|
240
|
+
## Accessibility
|
|
241
|
+
|
|
242
|
+
- Toast containers use `role="status"` and `aria-live="polite"`.
|
|
243
|
+
- Respects `prefers-reduced-motion` for users with motion sensitivity.
|
|
244
|
+
|
|
245
|
+
## Common Errors & Troubleshooting
|
|
246
|
+
|
|
247
|
+
- **No styles?** Make sure to import or link `dist/styles.css`.
|
|
248
|
+
- **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
|
|
249
|
+
- **Button not working?** Ensure your `onClick` is a function and not a string.
|
|
250
|
+
- **Nothing appears?** Confirm you rendered `<Toaster />` and are using the correct import.
|
|
251
|
+
|
|
252
|
+
## Migration & Best Practices
|
|
253
|
+
|
|
254
|
+
- If migrating from Sileo, all options and methods are compatible.
|
|
255
|
+
- Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
|
|
256
|
+
- Use `notify.clear()` to remove all toasts, o pasar una posición para limpiar solo un área.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
For other frameworks, see the React, Vue, and Vanilla guides.
|
|
62
261
|
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
63
262
|
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
64
263
|
|