vue-toastflow 0.0.1 → 0.0.3
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 +169 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
https://github.com/adrianjanocko/toastflow
|
|
2
|
+
|
|
3
|
+
<h1 align="center">Toastflow</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
Framework-agnostic toast engine with a Vue 3 renderer. Typed core, smooth stack animations, CSS-first theming, and full control over layout and behavior.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Usage (Vue.js 3 Composition API)
|
|
11
|
+
|
|
12
|
+
### Quick start
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// main.ts
|
|
16
|
+
import {createApp} from "vue";
|
|
17
|
+
import App from "./App.vue";
|
|
18
|
+
import {createToastflow, ToastContainer} from "vue-toastflow";
|
|
19
|
+
|
|
20
|
+
const app = createApp(App);
|
|
21
|
+
|
|
22
|
+
app.use(
|
|
23
|
+
createToastflow({
|
|
24
|
+
// optional global defaults
|
|
25
|
+
position: "top-right",
|
|
26
|
+
duration: 5000,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// register globally or import locally where you render it
|
|
31
|
+
app.component("ToastContainer", ToastContainer);
|
|
32
|
+
|
|
33
|
+
// call toast.* only after the plugin is installed
|
|
34
|
+
app.mount("#app");
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Render a container and fire toasts anywhere:
|
|
38
|
+
|
|
39
|
+
```vue
|
|
40
|
+
<!-- App.vue -->
|
|
41
|
+
<template>
|
|
42
|
+
<ToastContainer/>
|
|
43
|
+
<RouterView/>
|
|
44
|
+
</template>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import {toast} from "vue-toastflow";
|
|
49
|
+
|
|
50
|
+
toast.success({title: "Saved", description: "Your changes are live."});
|
|
51
|
+
toast.warning({description: "Low balance"});
|
|
52
|
+
|
|
53
|
+
const id = toast.error({title: "Oops", description: "Check console."});
|
|
54
|
+
toast.update(id, {description: "Fixed. All good now."});
|
|
55
|
+
toast.dismiss(id);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Async flows
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const run = toast.loading(
|
|
62
|
+
() => fetch("/api/save").then((r) => r.json()),
|
|
63
|
+
{
|
|
64
|
+
loading: {title: "Saving", description: "Hang tight."},
|
|
65
|
+
success: (data) => ({
|
|
66
|
+
title: "Saved",
|
|
67
|
+
description: `Stored item ${data.id}.`,
|
|
68
|
+
}),
|
|
69
|
+
error: (err) => ({
|
|
70
|
+
title: "Error",
|
|
71
|
+
description: err instanceof Error ? err.message : "Please try again.",
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
await run;
|
|
77
|
+
console.log(run.toastId);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### HTML content
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
toast.info({
|
|
84
|
+
title: "<strong>New version</strong>",
|
|
85
|
+
description: "Release notes are <a href='/changelog'>here</a>.",
|
|
86
|
+
supportHtml: true,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Headless rendering
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
|
|
94
|
+
<ToastContainer
|
|
95
|
+
v-slot="{
|
|
96
|
+
toast,
|
|
97
|
+
dismiss,
|
|
98
|
+
bumpAnimationClass,
|
|
99
|
+
clearAllAnimationClass,
|
|
100
|
+
updateAnimationClass,
|
|
101
|
+
}"
|
|
102
|
+
>
|
|
103
|
+
<div
|
|
104
|
+
class="my-toast"
|
|
105
|
+
:class="[
|
|
106
|
+
toast.type,
|
|
107
|
+
bumpAnimationClass,
|
|
108
|
+
toast.phase === 'clear-all' && clearAllAnimationClass,
|
|
109
|
+
updateAnimationClass
|
|
110
|
+
]"
|
|
111
|
+
@click="toast.closeOnClick && dismiss(toast.id)"
|
|
112
|
+
>
|
|
113
|
+
<header>
|
|
114
|
+
<strong>{{ toast.title }}</strong>
|
|
115
|
+
<button @click.stop="dismiss(toast.id)">x</button>
|
|
116
|
+
</header>
|
|
117
|
+
<p v-if="toast.description">{{ toast.description }}</p>
|
|
118
|
+
<small v-if="toast.showCreatedAt">
|
|
119
|
+
Sent at {{ toast.createdAtFormatter(toast.createdAt) }}
|
|
120
|
+
</small>
|
|
121
|
+
</div>
|
|
122
|
+
</ToastContainer>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
Pass any [types.ts](../../packages/core/src/types.ts) fields to `createToastflow`; per-toast options override them:
|
|
128
|
+
|
|
129
|
+
- `position`: "top-right" (default), "top-left", "top-center", "bottom-*"
|
|
130
|
+
- `duration`: `5000` ms by default; `Infinity` or `0` disables auto-dismiss (progress bar auto-hides when disabled)
|
|
131
|
+
- `maxVisible`: `5` per stack; eviction respects `order`
|
|
132
|
+
- `order`: "newest" (default) or "oldest" per stack
|
|
133
|
+
- `preventDuplicates`: `false` by default; matches by position + type + title + description
|
|
134
|
+
- `progressBar`, `pauseOnHover`, `pauseStrategy` ("resume" | "reset")
|
|
135
|
+
- `animation`: class names for enter/leave/move (`name`), bump, clearAll, update (defaults use `Toastflow__*`)
|
|
136
|
+
- `closeButton` (`true`), `closeOnClick` (`false`)
|
|
137
|
+
- `offset` (`16px`), `gap` (`8px`), `width` (`350px`), `zIndex` (`9999`)
|
|
138
|
+
- `supportHtml`: `false` (opt-in)
|
|
139
|
+
- `showCreatedAt` and `createdAtFormatter` for timestamps
|
|
140
|
+
- lifecycle hooks: `onMount`, `onUnmount`, `onClick`, `onClose`
|
|
141
|
+
|
|
142
|
+
## Theming
|
|
143
|
+
|
|
144
|
+
- CSS variables live in [styles.css](../../packages/vue/src/styles.css) and are auto-imported with the Vue package.
|
|
145
|
+
- Key
|
|
146
|
+
variables: `--tf-toast-bg`, `--tf-toast-color`, `--tf-toast-border-color`, `--tf-toast-radius`, `--tf-toast-padding`, `--tf-toast-icon-size`, `--tf-toast-progress-height`,
|
|
147
|
+
plus per-type colors like `--success-bg` and `--error-text`.
|
|
148
|
+
- Animations are pure CSS class names; override them via the `animation` config or by redefining the `Toastflow__*`
|
|
149
|
+
keyframes. **Animations are implemented using [TransitionGroup](https://vuejs.org/guide/built-ins/transition-group).**
|
|
150
|
+
|
|
151
|
+
## Events and store access
|
|
152
|
+
|
|
153
|
+
- `toast.subscribeEvents(listener)` gets `duplicate`, `timer-reset`, and `update` events.
|
|
154
|
+
- `toast.getState()` returns the current snapshot; helper
|
|
155
|
+
methods: `toast.show`, `toast.success`, `toast.error`, `toast.warning`, `toast.info`, `toast.loading`, `toast.update`, `toast.dismiss`, `toast.dismissAll`, `toast.pause`, `toast.resume`, `toast.getConfig`.
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! Fork the repo, create a branch, and open a PR. For bigger changes, open an issue first.
|
|
160
|
+
|
|
161
|
+
1. Fork the project
|
|
162
|
+
2. Create your branch
|
|
163
|
+
3. Commit your changes
|
|
164
|
+
4. Push to the branch
|
|
165
|
+
5. Open a Pull Request
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT - see [LICENSE](../../LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-toastflow",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"module": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"vue": "^3.4.0"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"toastflow-core": "
|
|
15
|
+
"toastflow-core": "^0.0.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@vitejs/plugin-vue": "^6.0.2",
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
"vitest": "^4.0.13",
|
|
22
22
|
"vue": "^3.5.24"
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|