@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/README.md +81 -37
- package/dist/index.cjs.js +46 -4
- package/dist/index.esm.js +46 -4
- package/dist/notify.umd.js +46 -4
- package/docs/browser.md +63 -28
- package/docs/react.md +228 -24
- package/docs/svelte.md +231 -21
- package/docs/vanilla.md +195 -32
- package/docs/vue.md +267 -14
- package/package.json +1 -1
package/docs/react.md
CHANGED
|
@@ -1,58 +1,262 @@
|
|
|
1
|
+
|
|
1
2
|
# React
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
## Quick start
|
|
5
|
+
|
|
6
|
+
Install the package and peer dependencies:
|
|
4
7
|
|
|
5
8
|
```bash
|
|
6
9
|
npm install @samline/notify react react-dom
|
|
7
10
|
```
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
Import and render the `Toaster` component in your app root:
|
|
10
13
|
|
|
11
14
|
```tsx
|
|
12
15
|
import React from 'react';
|
|
13
|
-
import { notify, sileo } from '@samline/notify';
|
|
14
|
-
import { Toaster } from '@samline/notify/react';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
import { Toaster, notify } from '@samline/notify/react';
|
|
18
|
+
|
|
19
|
+
export function App() {
|
|
17
20
|
return (
|
|
18
21
|
<>
|
|
19
22
|
<Toaster />
|
|
20
23
|
<button onClick={() => notify.show({ title: 'Done', type: 'success' })}>Show</button>
|
|
21
24
|
</>
|
|
22
|
-
)
|
|
25
|
+
);
|
|
23
26
|
}
|
|
24
27
|
```
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
## Methods: Full Examples
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
```tsx
|
|
32
|
+
// Show a generic toast
|
|
33
|
+
notify.show({ title: 'Hello', description: 'Generic toast', type: 'info' });
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
// Success toast
|
|
36
|
+
notify.success({ title: 'Success!', description: 'Operation completed.' });
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
// Error toast
|
|
39
|
+
notify.error({ title: 'Error', description: 'Something went wrong.' });
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
> CDN: `<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css">`
|
|
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()
|
|
37
95
|
```
|
|
38
96
|
|
|
39
|
-
|
|
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 toast positions |
|
|
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
|
|
40
116
|
|
|
41
117
|
```tsx
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
118
|
+
// Custom icon (SVG string or JSX)
|
|
119
|
+
notify.success({
|
|
120
|
+
title: 'With Icon',
|
|
121
|
+
icon: <svg width="16" height="16" ...>...</svg>
|
|
122
|
+
});
|
|
45
123
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
159
|
+
notify.success({
|
|
160
|
+
title: 'Bottom left',
|
|
161
|
+
position: 'bottom-left'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Description as ReactNode
|
|
165
|
+
notify.info({
|
|
166
|
+
title: 'JSX Description',
|
|
167
|
+
description: <span style={{ color: 'red' }}>Custom JSX content</span>
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Example: Advanced Toast
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
notify.success({
|
|
175
|
+
title: "Styled!",
|
|
176
|
+
fill: "#222",
|
|
177
|
+
icon: '<svg>...</svg>',
|
|
178
|
+
styles: {
|
|
179
|
+
title: "text-white!",
|
|
180
|
+
badge: "bg-white/20!",
|
|
181
|
+
button: "bg-white/10!"
|
|
182
|
+
},
|
|
183
|
+
roundness: 24,
|
|
184
|
+
autopilot: false
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### Promise Toasts
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
notify.promise(fetchData(), {
|
|
192
|
+
loading: { title: "Loading..." },
|
|
193
|
+
success: (data) => ({ title: `Loaded ${data.name}` }),
|
|
194
|
+
error: (err) => ({ title: "Error", description: err.message }),
|
|
195
|
+
action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Toaster Component Props
|
|
200
|
+
|
|
201
|
+
The `<Toaster />` component accepts the following props:
|
|
202
|
+
|
|
203
|
+
| Prop | Type | Default | Description |
|
|
204
|
+
| --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
|
|
205
|
+
| `position`| string | top-right | Default toast position |
|
|
206
|
+
| `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
|
|
207
|
+
| `options` | Partial<Options> | — | Default options for all toasts |
|
|
208
|
+
| `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
|
|
209
|
+
|
|
210
|
+
#### Example: Custom Toaster
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
<Toaster position="bottom-center" offset={24} theme="dark" options={{ fill: '#222', roundness: 20 }} />
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Customizing Styles
|
|
217
|
+
|
|
218
|
+
- Override CSS variables in your stylesheet or inline:
|
|
219
|
+
|
|
220
|
+
```css
|
|
221
|
+
:root {
|
|
222
|
+
--sileo-bg: #18181b;
|
|
223
|
+
--sileo-success: #22c55e;
|
|
224
|
+
--sileo-error: #ef4444;
|
|
225
|
+
--sileo-info: #2563eb;
|
|
226
|
+
--sileo-warning: #f59e0b;
|
|
53
227
|
}
|
|
54
228
|
```
|
|
55
229
|
|
|
230
|
+
- Add custom classes via the `styles` option for title, badge, button, description.
|
|
231
|
+
|
|
232
|
+
## Accessibility
|
|
233
|
+
|
|
234
|
+
- Toast containers use `role="status"` and `aria-live="polite"`.
|
|
235
|
+
- Respects `prefers-reduced-motion` for users with motion sensitivity.
|
|
236
|
+
|
|
237
|
+
## Common Errors & Troubleshooting
|
|
238
|
+
|
|
239
|
+
- **No styles?** Make sure to import or link `dist/styles.css`.
|
|
240
|
+
- **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
|
|
241
|
+
- **Button not working?** Ensure your `onClick` is a function and not a string.
|
|
242
|
+
- **Nothing appears?** Confirm you rendered `<Toaster />` and are using the correct import.
|
|
243
|
+
|
|
244
|
+
## Migration & Best Practices
|
|
245
|
+
|
|
246
|
+
- If migrating from Sileo, all options and methods are compatible.
|
|
247
|
+
- Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
|
|
248
|
+
- Use `notify.clear()` to remove all toasts, or pass a position to clear only one area.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
For other frameworks, see the Vue, Svelte, and Vanilla guides.
|
|
253
|
+
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
254
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
255
|
+
|
|
256
|
+
## Tips
|
|
257
|
+
|
|
258
|
+
- You can customize positions and styles by overriding CSS variables or importing the stylesheet in your preferred way.
|
|
259
|
+
|
|
56
260
|
## API
|
|
57
261
|
|
|
58
262
|
- `Toaster` component: mounts a toast container and subscribes to the core controller.
|
package/docs/svelte.md
CHANGED
|
@@ -1,50 +1,260 @@
|
|
|
1
|
-
# Svelte
|
|
2
1
|
|
|
3
|
-
Quick start
|
|
4
2
|
# Svelte
|
|
5
3
|
|
|
6
|
-
Quick start
|
|
4
|
+
## Quick start
|
|
5
|
+
|
|
6
|
+
Install the package:
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
9
|
npm install @samline/notify svelte
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Import and initialize in your root component:
|
|
13
13
|
|
|
14
14
|
```svelte
|
|
15
15
|
<script>
|
|
16
16
|
import Toaster, { initSileoStore } from '@samline/notify/svelte';
|
|
17
|
-
initSileoStore();
|
|
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
|
+
}
|
|
18
23
|
</script>
|
|
19
24
|
|
|
20
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();
|
|
21
68
|
|
|
22
|
-
|
|
69
|
+
// Clear only a position
|
|
70
|
+
notify.clear('top-right');
|
|
23
71
|
```
|
|
24
72
|
|
|
25
|
-
|
|
73
|
+
> **Note:**
|
|
74
|
+
> Import `@samline/notify/dist/styles.css` in your main entrypoint or HTML for correct appearance.
|
|
75
|
+
> CDN: `<link rel="stylesheet" href="https://unpkg.com/@samline/notify@0.1.15/dist/styles.css">`
|
|
26
76
|
|
|
27
|
-
If you use TypeScript, run `npm run typecheck` and `npx svelte-check` during development.
|
|
28
77
|
|
|
29
78
|
## API
|
|
30
79
|
|
|
31
|
-
- `Toaster.svelte
|
|
32
|
-
- `initSileoStore()
|
|
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).
|
|
33
83
|
|
|
34
|
-
|
|
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 toast positions |
|
|
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
|
|
35
117
|
|
|
36
118
|
```svelte
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
119
|
+
// Custom icon (SVG string or SvelteNode)
|
|
120
|
+
notify.success({
|
|
121
|
+
title: 'With Icon',
|
|
122
|
+
icon: '<svg width="16" height="16" ...>...</svg>'
|
|
123
|
+
});
|
|
42
124
|
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
160
|
+
notify.success({
|
|
161
|
+
title: 'Bottom left',
|
|
162
|
+
position: 'bottom-left'
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Description as SvelteNode
|
|
166
|
+
notify.info({
|
|
167
|
+
title: 'Node Description',
|
|
168
|
+
description: '<span style="color: red">Custom HTML content</span>'
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Example: Advanced Toast
|
|
173
|
+
|
|
174
|
+
```svelte
|
|
175
|
+
notify.success({
|
|
176
|
+
title: "Styled!",
|
|
177
|
+
fill: "#222",
|
|
178
|
+
icon: '<svg>...</svg>',
|
|
179
|
+
styles: {
|
|
180
|
+
title: "text-white!",
|
|
181
|
+
badge: "bg-white/20!",
|
|
182
|
+
button: "bg-white/10!"
|
|
183
|
+
},
|
|
184
|
+
roundness: 24,
|
|
185
|
+
autopilot: false
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Promise Toasts
|
|
190
|
+
|
|
191
|
+
```svelte
|
|
192
|
+
notify.promise(fetchData(), {
|
|
193
|
+
loading: { title: "Loading..." },
|
|
194
|
+
success: (data) => ({ title: `Loaded ${data.name}` }),
|
|
195
|
+
error: (err) => ({ title: "Error", description: err.message }),
|
|
196
|
+
action: (data) => ({ title: "Action required", button: { title: "Retry", onClick: () => retry() } })
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Toaster Component Props
|
|
201
|
+
|
|
202
|
+
The `<Toaster />` component accepts the following props:
|
|
203
|
+
|
|
204
|
+
| Prop | Type | Default | Description |
|
|
205
|
+
| --------- | ----------------------------------------- | ------------ | ------------------------------------------- |
|
|
206
|
+
| `position`| string | top-right | Default toast position |
|
|
207
|
+
| `offset` | number \| string \| {top,right,bottom,left}| 0 | Distance from viewport edges |
|
|
208
|
+
| `options` | Partial<Options> | — | Default options for all toasts |
|
|
209
|
+
| `theme` | "light" \| "dark" \| "system" | system | Color scheme (auto, light, dark) |
|
|
210
|
+
|
|
211
|
+
#### Example: Custom Toaster
|
|
212
|
+
|
|
213
|
+
```svelte
|
|
214
|
+
<Toaster position="bottom-center" offset={24} theme="dark" options={{ fill: '#222', roundness: 20 }} />
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Customizing Styles
|
|
218
|
+
|
|
219
|
+
- Override CSS variables in your stylesheet or inline:
|
|
220
|
+
|
|
221
|
+
```css
|
|
222
|
+
:root {
|
|
223
|
+
--sileo-bg: #18181b;
|
|
224
|
+
--sileo-success: #22c55e;
|
|
225
|
+
--sileo-error: #ef4444;
|
|
226
|
+
--sileo-info: #2563eb;
|
|
227
|
+
--sileo-warning: #f59e0b;
|
|
228
|
+
}
|
|
45
229
|
```
|
|
46
230
|
|
|
47
|
-
|
|
231
|
+
- Add custom classes via the `styles` option for title, badge, button, description.
|
|
232
|
+
|
|
233
|
+
## Accessibility
|
|
234
|
+
|
|
235
|
+
- Toast containers use `role="status"` and `aria-live="polite"`.
|
|
236
|
+
- Respects `prefers-reduced-motion` for users with motion sensitivity.
|
|
237
|
+
|
|
238
|
+
## Common Errors & Troubleshooting
|
|
239
|
+
|
|
240
|
+
- **No styles?** Make sure to import or link `dist/styles.css`.
|
|
241
|
+
- **No animation?** Check that the `motion` dependency is installed for ESM/bundler usage.
|
|
242
|
+
- **Button not working?** Ensure your `onClick` is a function and not a string.
|
|
243
|
+
- **Nothing appears?** Confirm you rendered `<Toaster />` and are using the correct import.
|
|
244
|
+
|
|
245
|
+
## Migration & Best Practices
|
|
246
|
+
|
|
247
|
+
- If migrating from Sileo, all options and methods are compatible.
|
|
248
|
+
- Prefer using `notify.success`, `notify.error`, etc. for intent clarity.
|
|
249
|
+
- Use `notify.clear()` to remove all toasts, o pasar una posición para limpiar solo un área.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
For other frameworks, see the React, Vue, and Vanilla guides.
|
|
254
|
+
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
255
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
256
|
+
|
|
257
|
+
## Tips
|
|
48
258
|
|
|
49
|
-
-
|
|
50
|
-
-
|
|
259
|
+
- For TypeScript, use `npx svelte-check` and `npm run typecheck` during development.
|
|
260
|
+
- You can customize styles by overriding CSS variables or importing the stylesheet as needed.
|