@appius-fr/apx 2.4.0 → 2.5.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/APX.mjs +2 -0
- package/README.md +35 -0
- package/dist/APX.dev.mjs +1189 -3
- package/dist/APX.mjs +1 -1
- package/dist/APX.prod.mjs +1 -1
- package/dist/APX.standalone.js +3170 -0
- package/dist/APX.standalone.js.map +1 -0
- package/modules/toast/README.md +127 -0
- package/modules/toast/css/toast.css +60 -0
- package/modules/toast/toast.mjs +1025 -0
- package/package.json +3 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# APX Toast
|
|
2
|
+
|
|
3
|
+
A tiny, framework‑agnostic toast library for APX. Minimal CSS, ESM‑first, no globals. DOM is only touched when you actually show a toast (SSR‑safe to import).
|
|
4
|
+
|
|
5
|
+
## Install / Import
|
|
6
|
+
|
|
7
|
+
Just import `APX` — the toast CSS is automatically loaded by `modules/toast/toast.mjs`.
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script type="module">
|
|
11
|
+
import APX from './APX.mjs';
|
|
12
|
+
// CSS is auto‑imported; no <link> tag required.
|
|
13
|
+
// ...
|
|
14
|
+
APX.toast.success('Ready!');
|
|
15
|
+
</script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
// Default manager (lazy)
|
|
22
|
+
APX.toast.success('Saved!');
|
|
23
|
+
APX.toast.warning('Heads up', { durationMs: 4000 });
|
|
24
|
+
APX.toast.danger('Something failed', { durationMs: 0 }); // sticky
|
|
25
|
+
|
|
26
|
+
// Custom toast
|
|
27
|
+
const ref = APX.toast.show({ message: 'Processing…', type: 'info', durationMs: 0 });
|
|
28
|
+
// Callable shorthand for show:
|
|
29
|
+
APX.toast({ message: 'Hello', type: 'success' });
|
|
30
|
+
ref.update({ message: 'Done', type: 'success', durationMs: 1800 });
|
|
31
|
+
ref.whenClosed().then(() => console.log('closed'));
|
|
32
|
+
|
|
33
|
+
// Configure defaults at runtime
|
|
34
|
+
APX.toast.configure({ position: 'top-right', maxToasts: 4, dedupe: true });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Named managers (profiles)
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// Register a named manager
|
|
41
|
+
APX.toast.create('admin', { position: 'bottom-left', ariaLive: 'polite' });
|
|
42
|
+
|
|
43
|
+
// Use it later
|
|
44
|
+
APX.toast.use('admin').info('Admin ready');
|
|
45
|
+
APX.toast.use('admin').closeAll();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API overview
|
|
49
|
+
|
|
50
|
+
- Top‑level (default manager):
|
|
51
|
+
- `APX.toast.show(opts)`
|
|
52
|
+
- `APX.toast.info|success|warning|danger(message, opts?)`
|
|
53
|
+
- `APX.toast.configure(config)`
|
|
54
|
+
- `APX.toast.closeAll(reason?)`
|
|
55
|
+
- `APX.toast.create(name, config)` → registers named manager
|
|
56
|
+
- `APX.toast.use(name)` → returns named manager
|
|
57
|
+
|
|
58
|
+
- Named manager instance (same surface):
|
|
59
|
+
- `.show(opts)`, `.info|success|warning|danger(message, opts?)`
|
|
60
|
+
- `.configure(config)`, `.closeAll(reason?)`
|
|
61
|
+
|
|
62
|
+
## Options and types
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// ToastConfig (global/manager defaults)
|
|
66
|
+
{
|
|
67
|
+
position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left', // default 'bottom-right'
|
|
68
|
+
maxToasts: number, // default 5
|
|
69
|
+
defaultDurationMs: number, // default 5000
|
|
70
|
+
zIndex: number, // default 11000
|
|
71
|
+
ariaLive: 'polite'|'assertive'|'off', // default 'polite'
|
|
72
|
+
gap: number, // default 8
|
|
73
|
+
dedupe: boolean, // default false
|
|
74
|
+
containerClass: string, // extra class on container
|
|
75
|
+
offset: number // px offset from screen edges
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ToastOptions (per toast)
|
|
79
|
+
{
|
|
80
|
+
message: string | Node,
|
|
81
|
+
type: 'info'|'success'|'warning'|'danger', // default 'info'
|
|
82
|
+
durationMs: number, // default from config; 0 = sticky
|
|
83
|
+
dismissible: boolean, // default true
|
|
84
|
+
id: string, // stable id for dedupe updates
|
|
85
|
+
className: string, // extra classes on the toast element
|
|
86
|
+
onClick: (ref, ev) => void,
|
|
87
|
+
onClose: (ref, reason) => void // reason: 'timeout'|'close'|'api'|'overflow'
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Theming (minimal CSS)
|
|
92
|
+
|
|
93
|
+
Override CSS variables to theme without touching markup:
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
:root {
|
|
97
|
+
--apx-toast-gap: 10px;
|
|
98
|
+
--apx-toast-min-width: 280px;
|
|
99
|
+
--apx-toast-radius: 8px;
|
|
100
|
+
--apx-toast-success-bg: #16a34a;
|
|
101
|
+
--apx-toast-success-fg: #fff;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Class structure (BEM‑like):
|
|
106
|
+
- Container: `APX-toast-container APX-toast-container--{corner}`
|
|
107
|
+
- Toast: `APX-toast APX-toast--{type}`
|
|
108
|
+
- Children: `APX-toast__content`, optional `APX-toast__close`
|
|
109
|
+
- Animations: `APX-toast--enter/--enter-active`, `APX-toast--exit/--exit-active`
|
|
110
|
+
|
|
111
|
+
## Behavior
|
|
112
|
+
|
|
113
|
+
- Lazy container creation (first `show`).
|
|
114
|
+
- `maxToasts` enforced; oldest removed with reason `'overflow'`.
|
|
115
|
+
- Hover pauses timer; resumes on mouse leave.
|
|
116
|
+
- `durationMs = 0` makes the toast sticky.
|
|
117
|
+
- If `dedupe: true` and `id` matches an open toast, it updates instead of creating a new one.
|
|
118
|
+
|
|
119
|
+
## Accessibility & SSR
|
|
120
|
+
|
|
121
|
+
- Container uses `aria-live` (configurable).
|
|
122
|
+
- Each toast has `role="status"`.
|
|
123
|
+
- ESM only; no DOM access at import time. Safe to import in SSR; DOM is touched only when showing toasts in the browser.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Copyright Appius.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
.APX-toast-container {
|
|
2
|
+
position: fixed;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: var(--apx-toast-gap, 8px);
|
|
6
|
+
z-index: var(--apx-toast-z-index, 11000);
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.APX-toast-container--bottom-right { right: 12px; bottom: 12px; align-items: flex-end; }
|
|
11
|
+
.APX-toast-container--bottom-left { left: 12px; bottom: 12px; align-items: flex-start; }
|
|
12
|
+
.APX-toast-container--top-right { right: 12px; top: 12px; align-items: flex-end; }
|
|
13
|
+
.APX-toast-container--top-left { left: 12px; top: 12px; align-items: flex-start; }
|
|
14
|
+
|
|
15
|
+
.APX-toast {
|
|
16
|
+
min-width: var(--apx-toast-min-width, 260px);
|
|
17
|
+
max-width: var(--apx-toast-max-width, 420px);
|
|
18
|
+
font-size: var(--apx-toast-font-size, 14px);
|
|
19
|
+
border-radius: var(--apx-toast-radius, 6px);
|
|
20
|
+
box-shadow: var(--apx-toast-shadow, 0 6px 24px rgba(0,0,0,0.2));
|
|
21
|
+
padding: var(--apx-toast-padding, 10px 42px 10px 14px);
|
|
22
|
+
color: #111;
|
|
23
|
+
background: #eee;
|
|
24
|
+
pointer-events: auto;
|
|
25
|
+
position: relative;
|
|
26
|
+
transition: opacity 180ms ease, transform 180ms ease;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.APX-toast--info { background: var(--apx-toast-info-bg, #0dcaf0); color: var(--apx-toast-info-fg, #052c65); }
|
|
30
|
+
.APX-toast--success { background: var(--apx-toast-success-bg, #198754); color: var(--apx-toast-success-fg, #ffffff); }
|
|
31
|
+
.APX-toast--warning { background: var(--apx-toast-warning-bg, #ffc107); color: var(--apx-toast-warning-fg, #664d03); }
|
|
32
|
+
.APX-toast--danger { background: var(--apx-toast-danger-bg, #dc3545); color: var(--apx-toast-danger-fg, #ffffff); }
|
|
33
|
+
|
|
34
|
+
.APX-toast__content { line-height: 1.35; }
|
|
35
|
+
|
|
36
|
+
.APX-toast__close {
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 50%; right: 10px;
|
|
39
|
+
width: 24px; height: 24px;
|
|
40
|
+
transform: translateY(-50%);
|
|
41
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
42
|
+
background: transparent; color: currentColor;
|
|
43
|
+
border: 0; border-radius: 4px; padding: 0; margin: 0;
|
|
44
|
+
cursor: pointer; appearance: none; -webkit-appearance: none;
|
|
45
|
+
opacity: .75; transition: opacity 120ms ease;
|
|
46
|
+
}
|
|
47
|
+
.APX-toast__close:hover { opacity: 1; }
|
|
48
|
+
.APX-toast__close:focus { outline: 2px solid rgba(0,0,0,.2); outline-offset: 2px; }
|
|
49
|
+
.APX-toast__close::before {
|
|
50
|
+
content: '×';
|
|
51
|
+
font-size: 16px; line-height: 1; text-align: center;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Animations */
|
|
55
|
+
.APX-toast--enter { opacity: 0; transform: translateY(8px); }
|
|
56
|
+
.APX-toast--enter.APX-toast--enter-active { opacity: 1; transform: translateY(0); }
|
|
57
|
+
.APX-toast--exit { opacity: 1; transform: translateY(0); }
|
|
58
|
+
.APX-toast--exit.APX-toast--exit-active { opacity: 0; transform: translateY(8px); }
|
|
59
|
+
|
|
60
|
+
|