@samline/notify 0.3.0 → 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.
- package/LICENSE +22 -0
- package/README.md +121 -150
- package/dist/browser-notify.js +69 -0
- package/dist/cc-2Yt7NqMX.mjs +21 -0
- package/dist/cc-B6peeNak.mjs +33 -0
- package/dist/cc-BWuAzFJ6.js +12 -0
- package/dist/cc-CaBHsjUt.js +34 -0
- package/dist/cc-DGff5sSY.js +21 -0
- package/dist/cc-he3fHS3P.mjs +12 -0
- package/dist/notify.d.mts +44 -0
- package/dist/notify.d.mts.map +1 -0
- package/dist/notify.d.ts +44 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +90 -0
- package/dist/notify.mjs +87 -0
- package/dist/react-notify-12s-7LOZlSBi.js +1068 -0
- package/dist/react-notify-12s-BjWbwTu8.mjs +1066 -0
- package/dist/react.d.mts +66 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.d.ts +66 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +18 -0
- package/dist/react.mjs +10 -0
- package/dist/styles.css +477 -63
- package/dist/svelte.d.mts +45 -0
- package/dist/svelte.d.mts.map +1 -0
- package/dist/svelte.d.ts +45 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +168 -0
- package/dist/svelte.mjs +165 -0
- package/dist/vue.d.mts +103 -0
- package/dist/vue.d.mts.map +1 -0
- package/dist/vue.d.ts +103 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +2099 -0
- package/dist/vue.mjs +2096 -0
- package/package.json +95 -57
- package/dist/index.cjs.js +0 -1171
- package/dist/index.esm.js +0 -1164
- package/dist/notify.umd.js +0 -1177
- package/docs/browser.md +0 -99
- package/docs/react.md +0 -275
- package/docs/svelte.md +0 -267
- package/docs/vanilla.md +0 -256
- package/docs/vue.md +0 -301
- package/rollup.config.mjs +0 -56
- package/samline-notify-0.1.9.tgz +0 -0
package/docs/browser.md
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# Browser / CDN usage
|
|
3
|
-
|
|
4
|
-
```html
|
|
5
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.3.0/dist/styles.css">
|
|
6
|
-
<script src="https://unpkg.com/@samline/notify@0.3.0/dist/notify.umd.js"></script>
|
|
7
|
-
Use this package directly in the browser when you cannot use npm modules or a bundler (e.g. Shopify, WordPress, static HTML).
|
|
8
|
-
|
|
9
|
-
## Quick start
|
|
10
|
-
|
|
11
|
-
Add the stylesheet and UMD bundle to your HTML:
|
|
12
|
-
|
|
13
|
-
```html
|
|
14
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.2.3/dist/styles.css">
|
|
15
|
-
<script src="https://unpkg.com/@samline/notify@0.2.3/dist/notify.umd.js"></script>
|
|
16
|
-
<script>
|
|
17
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
18
|
-
const api = window.notify; // or window.notifications for legacy
|
|
19
|
-
// Always use an array of strings as the second argument
|
|
20
|
-
// Correct usage:
|
|
21
|
-
api.initToasters(document.body, ['top-left']);
|
|
22
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.3.0/dist/styles.css">
|
|
23
|
-
<script src="https://unpkg.com/@samline/notify@0.3.0/dist/notify.umd.js"></script>
|
|
24
|
-
api.notify({ title: 'Hello', description: 'No-bundler usage', type: 'info' });
|
|
25
|
-
});
|
|
26
|
-
</script>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
<script src="https://unpkg.com/@samline/notify@0.3.0/dist/notify.umd.js"></script>
|
|
30
|
-
<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.3.0/dist/styles.css" />
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## API
|
|
34
|
-
|
|
35
|
-
- The UMD bundle exposes `window.notify` (recommended) and `window.notifications` (legacy/compatibility).
|
|
36
|
-
- Always include `dist/styles.css` for correct appearance and animations.
|
|
37
|
-
- Use `api.initToasters(container, positions, { offset, options, theme })` to mount containers (usually `document.body`).
|
|
38
|
-
- Use `api.notify({...})` to show a notification.
|
|
39
|
-
|
|
40
|
-
### ⚠️ Warnings and Best Practices
|
|
41
|
-
|
|
42
|
-
- The second argument to `initToasters` **must be an array of strings** (e.g. `['top-left']`).
|
|
43
|
-
- **Do not use** `document.body['top-left']` (this is `undefined` and will not work).
|
|
44
|
-
- If you initialize only one position, toasts without an explicit position will go there automatically (dynamic fallback).
|
|
45
|
-
- If you initialize multiple positions, toasts without an explicit position will go to `'top-right'` by default.
|
|
46
|
-
- 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.
|
|
47
|
-
|
|
48
|
-
### Advanced Options
|
|
49
|
-
|
|
50
|
-
All notification methods accept advanced options:
|
|
51
|
-
|
|
52
|
-
| Property | Type | Default | Description |
|
|
53
|
-
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
54
|
-
| `title` | string | — | Toast title |
|
|
55
|
-
| `description` | string | — | Optional body text (HTML or string) |
|
|
56
|
-
| `type` | `info\|success\|error\|warning\|action`| `info` | Visual intent |
|
|
57
|
-
| `position` | string | `top-right` | One of toast positions |
|
|
58
|
-
| `duration` | number \| null | `4000` | Auto-dismiss timeout in ms (null = sticky) |
|
|
59
|
-
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
60
|
-
| `icon` | string | — | Custom icon (SVG or HTML) |
|
|
61
|
-
| `fill` | string | — | Custom background color (SVG or badge) |
|
|
62
|
-
| `styles` | { title, description, badge, button } | — | Custom class overrides for sub-elements |
|
|
63
|
-
| `roundness` | number | 16 | Border radius in pixels |
|
|
64
|
-
| `autopilot` | boolean \| object | true | Auto expand/collapse timing |
|
|
65
|
-
|
|
66
|
-
#### Example: Advanced Toast
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
api.success({
|
|
70
|
-
title: "Styled!",
|
|
71
|
-
fill: "#222",
|
|
72
|
-
icon: '<svg>...</svg>',
|
|
73
|
-
styles: {
|
|
74
|
-
title: "text-white!",
|
|
75
|
-
badge: "bg-white/20!",
|
|
76
|
-
button: "bg-white/10!"
|
|
77
|
-
},
|
|
78
|
-
roundness: 24,
|
|
79
|
-
autopilot: false
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Toaster Options
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
You can pass advanced options to `initToasters`:
|
|
87
|
-
|
|
88
|
-
```js
|
|
89
|
-
// Correct example with multiple positions
|
|
90
|
-
api.initToasters(document.body, ['top-right', 'bottom-left'], {
|
|
91
|
-
offset: { top: 32, right: 16 },
|
|
92
|
-
options: { fill: '#222', roundness: 20 },
|
|
93
|
-
theme: 'dark'
|
|
94
|
-
});
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Notes
|
|
98
|
-
|
|
99
|
-
- If you need more control or want to avoid global variables, use the ESM/CJS builds with a bundler.
|
package/docs/react.md
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# React
|
|
3
|
-
|
|
4
|
-
## Quick start
|
|
5
|
-
|
|
6
|
-
Install the package and peer dependencies:
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
npm install @samline/notify react react-dom
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Import and render the `Toaster` component in your app root:
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
import React from 'react';
|
|
16
|
-
|
|
17
|
-
import { Toaster, notify } from '@samline/notify/react';
|
|
18
|
-
|
|
19
|
-
export function App() {
|
|
20
|
-
return (
|
|
21
|
-
<>
|
|
22
|
-
<Toaster />
|
|
23
|
-
<button onClick={() => notify.show({ title: 'Done', type: 'success' })}>Show</button>
|
|
24
|
-
</>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
```
|
|
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
|
-
|
|
73
|
-
> **Note:**
|
|
74
|
-
> Import `@samline/notify/dist/styles.css` in your main entrypoint or include it in your HTML for correct appearance.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
## API
|
|
79
|
-
|
|
80
|
-
- `<Toaster />` subscribes to the notification controller and renders toasts.
|
|
81
|
-
- Use `notify.show({...})` or shortcut methods (`notify.success`, `notify.error`, `notify.info`, `notify.warning`, `notify.action`, `notify.promise`, `notify.dismiss`, `notify.clear`) to trigger notifications. Import from `@samline/notify/react`.
|
|
82
|
-
|
|
83
|
-
### Methods
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
notify.show(options)
|
|
87
|
-
notify.success(options)
|
|
88
|
-
notify.error(options)
|
|
89
|
-
notify.info(options)
|
|
90
|
-
notify.warning(options)
|
|
91
|
-
notify.action(options)
|
|
92
|
-
notify.promise(promise, { loading, success, error })
|
|
93
|
-
notify.dismiss(id)
|
|
94
|
-
notify.clear()
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Options
|
|
98
|
-
|
|
99
|
-
All notification methods accept advanced options:
|
|
100
|
-
|
|
101
|
-
| Property | Type | Default | Description |
|
|
102
|
-
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
103
|
-
| `title` | string | — | Toast title |
|
|
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.
|
|
260
|
-
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
261
|
-
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
262
|
-
|
|
263
|
-
## Tips
|
|
264
|
-
|
|
265
|
-
- You can customize positions and styles by overriding CSS variables or importing the stylesheet in your preferred way.
|
|
266
|
-
|
|
267
|
-
## API
|
|
268
|
-
|
|
269
|
-
- `Toaster` component: mounts a toast container and subscribes to the core controller.
|
|
270
|
-
- Primary API: use `notify` (e.g. `notify.show(...)`). A backward-compatible `sileo` alias is also available: `sileo.show(...)`.
|
|
271
|
-
|
|
272
|
-
## Notes
|
|
273
|
-
|
|
274
|
-
- The React adapter renders toasts in a React-friendly way and is SSR-safe when used with client-only mounting.
|
|
275
|
-
- To customize styles, import `dist/styles.css` or override the CSS variables defined in the stylesheet.
|
package/docs/svelte.md
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# Svelte
|
|
3
|
-
|
|
4
|
-
## Quick start
|
|
5
|
-
|
|
6
|
-
Install the package:
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
npm install @samline/notify svelte
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Import and initialize in your root component:
|
|
13
|
-
|
|
14
|
-
```svelte
|
|
15
|
-
<script>
|
|
16
|
-
import Toaster, { initSileoStore } from '@samline/notify/svelte';
|
|
17
|
-
initSileoStore(); // Call once in your app root
|
|
18
|
-
|
|
19
|
-
import { notify } from '@samline/notify/svelte';
|
|
20
|
-
function show() {
|
|
21
|
-
notify.show({ title: 'From Svelte' });
|
|
22
|
-
}
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<Toaster />
|
|
26
|
-
<button on:click={show}>Show</button>
|
|
27
|
-
```
|
|
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
|
-
|
|
73
|
-
> **Note:**
|
|
74
|
-
> Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
## API
|
|
79
|
-
|
|
80
|
-
- `Toaster.svelte`: Renders notifications and subscribes to the core controller.
|
|
81
|
-
- `initSileoStore()`: Wires the notification controller to a Svelte store (call once in your app root).
|
|
82
|
-
- Use `notify.show({...})` or shortcut methods to trigger notifications. Import from `@samline/notify/svelte` (now available directly).
|
|
83
|
-
|
|
84
|
-
### Methods
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
notify.show(options)
|
|
88
|
-
notify.success(options)
|
|
89
|
-
notify.error(options)
|
|
90
|
-
notify.info(options)
|
|
91
|
-
notify.warning(options)
|
|
92
|
-
notify.action(options)
|
|
93
|
-
notify.promise(promise, { loading, success, error })
|
|
94
|
-
notify.dismiss(id)
|
|
95
|
-
notify.clear()
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Options
|
|
99
|
-
|
|
100
|
-
All notification methods accept advanced options:
|
|
101
|
-
|
|
102
|
-
| Property | Type | Default | Description |
|
|
103
|
-
| ------------- | -------------------------------------- | ----------- | ------------------------------------------- |
|
|
104
|
-
| `title` | string | — | Toast title |
|
|
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.
|
|
261
|
-
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
262
|
-
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
263
|
-
|
|
264
|
-
## Tips
|
|
265
|
-
|
|
266
|
-
- For TypeScript, use `npx svelte-check` and `npm run typecheck` during development.
|
|
267
|
-
- You can customize styles by overriding CSS variables or importing the stylesheet as needed.
|