@poadio/ui-elements 0.0.0-stage → 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/CHANGELOG.md +54 -0
- package/LICENSE +22 -0
- package/README.md +151 -2
- package/dist/accordion.d.ts +31 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +67 -0
- package/dist/accordion.js.map +1 -0
- package/dist/avatar.d.ts +56 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +49 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +19 -0
- package/dist/badge.js.map +1 -0
- package/dist/button-group.d.ts +43 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +63 -0
- package/dist/button-group.js.map +1 -0
- package/dist/button.d.ts +44 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +29 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.d.ts +32 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +46 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/chip.d.ts +37 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +46 -0
- package/dist/chip.js.map +1 -0
- package/dist/colorpicker.d.ts +63 -0
- package/dist/colorpicker.d.ts.map +1 -0
- package/dist/colorpicker.js +164 -0
- package/dist/colorpicker.js.map +1 -0
- package/dist/combo.d.ts +88 -0
- package/dist/combo.d.ts.map +1 -0
- package/dist/combo.js +238 -0
- package/dist/combo.js.map +1 -0
- package/dist/confirm.d.ts +35 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +94 -0
- package/dist/confirm.js.map +1 -0
- package/dist/datepicker.d.ts +146 -0
- package/dist/datepicker.d.ts.map +1 -0
- package/dist/datepicker.js +468 -0
- package/dist/datepicker.js.map +1 -0
- package/dist/declaration.d.ts +25 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +35 -0
- package/dist/declaration.js.map +1 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/dialog.d.ts +137 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +174 -0
- package/dist/dialog.js.map +1 -0
- package/dist/divider.d.ts +15 -0
- package/dist/divider.d.ts.map +1 -0
- package/dist/divider.js +17 -0
- package/dist/divider.js.map +1 -0
- package/dist/dom.d.ts +20 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +99 -0
- package/dist/dom.js.map +1 -0
- package/dist/element.d.ts +88 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +169 -0
- package/dist/element.js.map +1 -0
- package/dist/field.d.ts +50 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +90 -0
- package/dist/field.js.map +1 -0
- package/dist/floating.d.ts +134 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +311 -0
- package/dist/floating.js.map +1 -0
- package/dist/i18n.d.ts +32 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +49 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icon.d.ts +37 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +32 -0
- package/dist/icon.js.map +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/inplace.d.ts +25 -0
- package/dist/inplace.d.ts.map +1 -0
- package/dist/inplace.js +61 -0
- package/dist/inplace.js.map +1 -0
- package/dist/mask.d.ts +76 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +150 -0
- package/dist/mask.js.map +1 -0
- package/dist/menu.d.ts +121 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +245 -0
- package/dist/menu.js.map +1 -0
- package/dist/message.d.ts +31 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +28 -0
- package/dist/message.js.map +1 -0
- package/dist/meter.d.ts +43 -0
- package/dist/meter.d.ts.map +1 -0
- package/dist/meter.js +46 -0
- package/dist/meter.js.map +1 -0
- package/dist/multiselect.d.ts +133 -0
- package/dist/multiselect.d.ts.map +1 -0
- package/dist/multiselect.js +230 -0
- package/dist/multiselect.js.map +1 -0
- package/dist/number.d.ts +63 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/number.js +72 -0
- package/dist/number.js.map +1 -0
- package/dist/option-list.d.ts +28 -0
- package/dist/option-list.d.ts.map +1 -0
- package/dist/option-list.js +31 -0
- package/dist/option-list.js.map +1 -0
- package/dist/password.d.ts +30 -0
- package/dist/password.d.ts.map +1 -0
- package/dist/password.js +47 -0
- package/dist/password.js.map +1 -0
- package/dist/popover.d.ts +62 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +109 -0
- package/dist/popover.js.map +1 -0
- package/dist/progress.d.ts +48 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +42 -0
- package/dist/progress.js.map +1 -0
- package/dist/radio.d.ts +44 -0
- package/dist/radio.d.ts.map +1 -0
- package/dist/radio.js +70 -0
- package/dist/radio.js.map +1 -0
- package/dist/rating.d.ts +52 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +77 -0
- package/dist/rating.js.map +1 -0
- package/dist/segmented.d.ts +52 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +67 -0
- package/dist/segmented.js.map +1 -0
- package/dist/select.d.ts +119 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +185 -0
- package/dist/select.js.map +1 -0
- package/dist/services.d.ts +3 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +10 -0
- package/dist/services.js.map +1 -0
- package/dist/skeleton.d.ts +19 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +16 -0
- package/dist/skeleton.js.map +1 -0
- package/dist/slider.d.ts +77 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +136 -0
- package/dist/slider.js.map +1 -0
- package/dist/split-button.d.ts +47 -0
- package/dist/split-button.d.ts.map +1 -0
- package/dist/split-button.js +64 -0
- package/dist/split-button.js.map +1 -0
- package/dist/stepper.d.ts +56 -0
- package/dist/stepper.d.ts.map +1 -0
- package/dist/stepper.js +69 -0
- package/dist/stepper.js.map +1 -0
- package/dist/switch.d.ts +32 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +42 -0
- package/dist/switch.js.map +1 -0
- package/dist/tabs.d.ts +62 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +118 -0
- package/dist/tabs.js.map +1 -0
- package/dist/tag.d.ts +27 -0
- package/dist/tag.d.ts.map +1 -0
- package/dist/tag.js +21 -0
- package/dist/tag.js.map +1 -0
- package/dist/toast.d.ts +79 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +176 -0
- package/dist/toast.js.map +1 -0
- package/dist/toggle-button.d.ts +46 -0
- package/dist/toggle-button.d.ts.map +1 -0
- package/dist/toggle-button.js +39 -0
- package/dist/toggle-button.js.map +1 -0
- package/dist/tooltip.d.ts +48 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +105 -0
- package/dist/tooltip.js.map +1 -0
- package/package.json +66 -4
- package/src/accordion.ts +80 -0
- package/src/avatar.ts +78 -0
- package/src/badge.ts +26 -0
- package/src/button-group.ts +66 -0
- package/src/button.ts +44 -0
- package/src/checkbox.ts +57 -0
- package/src/chip.ts +54 -0
- package/src/colorpicker.ts +173 -0
- package/src/combo.ts +220 -0
- package/src/confirm.ts +106 -0
- package/src/datepicker.ts +413 -0
- package/src/declaration.ts +37 -0
- package/src/define.ts +4 -0
- package/src/dialog.ts +217 -0
- package/src/divider.ts +22 -0
- package/src/dom.ts +102 -0
- package/src/element.ts +187 -0
- package/src/field.ts +91 -0
- package/src/floating.ts +316 -0
- package/src/i18n.ts +61 -0
- package/src/icon.ts +42 -0
- package/src/index.ts +128 -0
- package/src/inplace.ts +69 -0
- package/src/mask.ts +170 -0
- package/src/menu.ts +281 -0
- package/src/message.ts +37 -0
- package/src/meter.ts +64 -0
- package/src/multiselect.ts +273 -0
- package/src/number.ts +94 -0
- package/src/option-list.ts +51 -0
- package/src/password.ts +59 -0
- package/src/popover.ts +118 -0
- package/src/progress.ts +62 -0
- package/src/radio.ts +84 -0
- package/src/rating.ts +91 -0
- package/src/segmented.ts +82 -0
- package/src/select.ts +226 -0
- package/src/services.ts +10 -0
- package/src/skeleton.ts +24 -0
- package/src/slider.ts +145 -0
- package/src/split-button.ts +76 -0
- package/src/stepper.ts +86 -0
- package/src/switch.ts +52 -0
- package/src/tabs.ts +129 -0
- package/src/tag.ts +29 -0
- package/src/toast.ts +203 -0
- package/src/toggle-button.ts +52 -0
- package/src/tooltip.ts +101 -0
package/src/toast.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* poadToast.success('Deployed', 'api v1.4 is live'); n'importe où dans la page
|
|
3
|
+
* poadToast({ severity: 'warn', summary: 'Careful', life: 8000 });
|
|
4
|
+
* <poad-toast position="bottom-right" show-progress></poad-toast> facultatif : où et comment les montrer
|
|
5
|
+
*
|
|
6
|
+
* Toasts : le pendant de `PoadToastService` + `<poad-toast>` d'ui-angular. `poadToast` est une fonction (elle ajoute un
|
|
7
|
+
* message) et une file (`createToastStore` d'ui-core) : `add`, `success`, `info`, `warn`, `error`, `remove`,
|
|
8
|
+
* `clear(key?)`, `messages()`, `subscribe()`. `<poad-toast>` montre les messages de sa clé (`toast-key`) :
|
|
9
|
+
* synchronisation avec la file, doublons (`prevent-duplicates`), trop-plein (`max-visible`), durée de vie, pause au
|
|
10
|
+
* survol, sortie animée — machine `toast` d'ui-core. Un message ajouté à la file par défaut sans `<poad-toast>` sans clé
|
|
11
|
+
* dans la page en fait poser un en fin de `body` (en haut à droite). Une autre file : `createPoadToastService()` et la
|
|
12
|
+
* propriété `service`. Évènements : `close` (detail : le message fermé), `toastclick`. Même DOM, mêmes classes, même
|
|
13
|
+
* ARIA (`role="status"` / `alert`, `aria-live`) que `poad-toast`. Style : `toast.css` (et `icon.css`, `button.css`).
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
TOAST_LIFE, TOAST_MAX_VISIBLE, TOAST_OUT_MS, createToastStore, toastForKey, toastIcon, toastItemProps, toastLife, toastPause, toastResume, toastRootClass,
|
|
17
|
+
toastSync, type ToastItem, type ToastMessageLike, type ToastPosition, type ToastStore,
|
|
18
|
+
} from '@poadio/ui-core';
|
|
19
|
+
import { button } from './button.js';
|
|
20
|
+
import { h, type Child } from './dom.js';
|
|
21
|
+
import { PoadElement } from './element.js';
|
|
22
|
+
import { icon } from './icon.js';
|
|
23
|
+
import { servicePrefix } from './services.js';
|
|
24
|
+
|
|
25
|
+
export interface PoadToastAction {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly click: (msg: PoadToastMessage) => void;
|
|
28
|
+
readonly severity?: 'primary' | 'secondary' | 'danger';
|
|
29
|
+
}
|
|
30
|
+
export interface PoadToastMessage extends ToastMessageLike {
|
|
31
|
+
data?: unknown;
|
|
32
|
+
actions?: readonly PoadToastAction[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type Shortcut = (summary: string, detail?: string, opts?: Partial<PoadToastMessage>) => PoadToastMessage;
|
|
36
|
+
|
|
37
|
+
/** Une file de toasts, appelable : `service(message)` = `service.add(message)`. */
|
|
38
|
+
export interface PoadToastService extends ToastStore<PoadToastMessage> {
|
|
39
|
+
(message: PoadToastMessage): PoadToastMessage;
|
|
40
|
+
success: Shortcut;
|
|
41
|
+
info: Shortcut;
|
|
42
|
+
warn: Shortcut;
|
|
43
|
+
error: Shortcut;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function service(onAdd?: () => void): PoadToastService {
|
|
47
|
+
const store = createToastStore<PoadToastMessage>(() => Date.now());
|
|
48
|
+
const add = (m: PoadToastMessage) => { const out = store.add(m); onAdd?.(); return out; };
|
|
49
|
+
const sev = (severity: PoadToastMessage['severity']): Shortcut => (summary, detail, opts = {}) => add({ severity, summary, detail, ...opts });
|
|
50
|
+
return Object.assign(add, {
|
|
51
|
+
add, messages: store.messages, remove: store.remove, clear: store.clear, subscribe: store.subscribe,
|
|
52
|
+
success: sev('success'), info: sev('info'), warn: sev('warn'), error: sev('error'),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Une autre file de toasts (la bibliothèque en a une par défaut : `poadToast`). */
|
|
57
|
+
export const createPoadToastService = (): PoadToastService => service();
|
|
58
|
+
|
|
59
|
+
/** `<poad-toast>` sans clé connectés à la file par défaut. */
|
|
60
|
+
const defaultHosts = new Set<Element>();
|
|
61
|
+
|
|
62
|
+
/** La file par défaut ; sans `<poad-toast>` qui la montre, le premier message en fait poser un. */
|
|
63
|
+
export const poadToast: PoadToastService = service(() => {
|
|
64
|
+
const tag = `${servicePrefix()}-toast`;
|
|
65
|
+
if (typeof document === 'undefined' || defaultHosts.size || !customElements.get(tag)) return;
|
|
66
|
+
document.body.append(document.createElement(tag));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export class PoadToastElement extends PoadElement {
|
|
70
|
+
static override props = {
|
|
71
|
+
position: 'string', toastKey: 'string', life: 'number', maxVisible: 'number', preventDuplicates: 'boolean', showProgress: 'boolean', zIndex: 'string',
|
|
72
|
+
} as const;
|
|
73
|
+
static override functions = ['service', 'renderItem'] as const;
|
|
74
|
+
declare position?: ToastPosition;
|
|
75
|
+
declare toastKey?: string;
|
|
76
|
+
declare life?: number;
|
|
77
|
+
declare maxVisible?: number;
|
|
78
|
+
declare preventDuplicates?: boolean;
|
|
79
|
+
declare showProgress?: boolean;
|
|
80
|
+
declare zIndex?: string;
|
|
81
|
+
/** La file montrée (défaut : `poadToast`). */
|
|
82
|
+
declare service?: PoadToastService;
|
|
83
|
+
/** Rendu d'un toast (contenu à la place de l'icône, des textes et de la croix). */
|
|
84
|
+
declare renderItem?: (msg: PoadToastMessage, close: () => void) => string | Node;
|
|
85
|
+
|
|
86
|
+
private items: ToastItem<PoadToastMessage>[] = [];
|
|
87
|
+
private readonly known = new Set<string>();
|
|
88
|
+
private readonly timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
89
|
+
private subscribed: PoadToastService | null = null;
|
|
90
|
+
private unsubscribe: (() => void) | null = null;
|
|
91
|
+
|
|
92
|
+
private get queue(): PoadToastService { return this.service ?? poadToast; }
|
|
93
|
+
override disconnectedCallback(): void {
|
|
94
|
+
super.disconnectedCallback();
|
|
95
|
+
defaultHosts.delete(this);
|
|
96
|
+
this.unsubscribe?.();
|
|
97
|
+
this.unsubscribe = null;
|
|
98
|
+
this.subscribed = null;
|
|
99
|
+
this.timers.forEach(clearTimeout);
|
|
100
|
+
this.timers.clear();
|
|
101
|
+
this.items = [];
|
|
102
|
+
this.known.clear();
|
|
103
|
+
}
|
|
104
|
+
protected override updated(): void {
|
|
105
|
+
const queue = this.queue;
|
|
106
|
+
if (queue === poadToast && !this.toastKey) defaultHosts.add(this); else defaultHosts.delete(this);
|
|
107
|
+
if (queue === this.subscribed) return;
|
|
108
|
+
this.unsubscribe?.();
|
|
109
|
+
this.subscribed = queue;
|
|
110
|
+
this.unsubscribe = queue.subscribe(() => this.sync());
|
|
111
|
+
this.sync();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private clearTimer(id: string) {
|
|
115
|
+
const t = this.timers.get(id);
|
|
116
|
+
if (t) clearTimeout(t);
|
|
117
|
+
this.timers.delete(id);
|
|
118
|
+
}
|
|
119
|
+
private animateOut(msg: PoadToastMessage, notify: boolean) {
|
|
120
|
+
const it = this.items.find((x) => x.msg === msg);
|
|
121
|
+
if (!it || it.state === 'out') return;
|
|
122
|
+
this.clearTimer(msg.id!);
|
|
123
|
+
this.items = this.items.map((x) => (x.msg === msg ? { ...x, state: 'out' } : x));
|
|
124
|
+
this.update();
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
this.items = this.items.filter((x) => x.msg !== msg);
|
|
127
|
+
this.known.delete(msg.id!);
|
|
128
|
+
this.update();
|
|
129
|
+
if (notify) this.queue.remove(msg);
|
|
130
|
+
this.emit('close', msg);
|
|
131
|
+
}, TOAST_OUT_MS);
|
|
132
|
+
}
|
|
133
|
+
private arm(it: ToastItem<PoadToastMessage>) {
|
|
134
|
+
this.clearTimer(it.msg.id!);
|
|
135
|
+
this.timers.set(it.msg.id!, setTimeout(() => this.animateOut(it.msg, true), it.remaining));
|
|
136
|
+
}
|
|
137
|
+
private sync() {
|
|
138
|
+
const queue = this.queue;
|
|
139
|
+
const r = toastSync(this.items, toastForKey(queue.messages(), this.toastKey), this.known, {
|
|
140
|
+
life: this.life ?? TOAST_LIFE, maxVisible: this.maxVisible ?? TOAST_MAX_VISIBLE, preventDuplicates: this.preventDuplicates, now: Date.now(),
|
|
141
|
+
});
|
|
142
|
+
for (const m of r.rejected) queue.remove(m);
|
|
143
|
+
const fresh = r.items.filter((it) => !this.items.includes(it));
|
|
144
|
+
if (fresh.length) {
|
|
145
|
+
fresh.forEach((it) => this.known.add(it.msg.id!));
|
|
146
|
+
this.items = [...this.items, ...fresh];
|
|
147
|
+
this.update();
|
|
148
|
+
for (const it of fresh) if (r.arm.includes(it.msg)) this.arm(it);
|
|
149
|
+
}
|
|
150
|
+
for (const d of r.dismiss) this.animateOut(d.msg, d.notify);
|
|
151
|
+
}
|
|
152
|
+
private hover(m: PoadToastMessage, on: boolean) {
|
|
153
|
+
const it = this.items.find((x) => x.msg === m);
|
|
154
|
+
if (it) { if (on) this.pause(it); else this.resume(it); }
|
|
155
|
+
}
|
|
156
|
+
private pause(it: ToastItem<PoadToastMessage>) {
|
|
157
|
+
const next = toastPause(it, Date.now());
|
|
158
|
+
if (next === it) return;
|
|
159
|
+
this.clearTimer(it.msg.id!);
|
|
160
|
+
this.items = this.items.map((x) => (x === it ? next : x));
|
|
161
|
+
this.update();
|
|
162
|
+
}
|
|
163
|
+
private resume(it: ToastItem<PoadToastMessage>) {
|
|
164
|
+
const next = toastResume(it, Date.now());
|
|
165
|
+
if (next === it) return;
|
|
166
|
+
this.items = this.items.map((x) => (x === it ? next : x));
|
|
167
|
+
this.update();
|
|
168
|
+
this.arm(next);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected render() {
|
|
172
|
+
const { t } = this.i18n();
|
|
173
|
+
const registry = this.icons();
|
|
174
|
+
const life = this.life ?? TOAST_LIFE;
|
|
175
|
+
return h('div', { class: toastRootClass(this.position ?? 'top-right'), style: { zIndex: this.zIndex ?? 'var(--poad-z-overlay)' } }, this.items.map((it): Child => {
|
|
176
|
+
const a = toastItemProps(it.msg, it.state === 'out');
|
|
177
|
+
const close = () => this.animateOut(it.msg, true);
|
|
178
|
+
const m = it.msg;
|
|
179
|
+
return h('div', {
|
|
180
|
+
class: a.className, role: a.role, 'aria-live': a['aria-live'], onmouseenter: () => this.hover(m, true),
|
|
181
|
+
onmouseleave: () => this.hover(m, false), onclick: () => this.emit('toastclick', m),
|
|
182
|
+
}, [
|
|
183
|
+
this.renderItem ? this.renderItem(m, close) : [
|
|
184
|
+
icon(registry, toastIcon(m), { size: 16, class: 'poad-toast__icon' }),
|
|
185
|
+
h('div', { class: 'poad-toast__text' }, [
|
|
186
|
+
m.summary && h('b', {}, m.summary),
|
|
187
|
+
m.detail && h('span', {}, m.detail),
|
|
188
|
+
!!m.actions?.length && h('div', { class: 'poad-toast__actions' }, m.actions.map((ac) => button(
|
|
189
|
+
{ size: 'sm', variant: 'text', severity: ac.severity || 'primary' },
|
|
190
|
+
{ type: 'button', onclick: (e: MouseEvent) => { e.stopPropagation(); ac.click(m); } }, ac.label,
|
|
191
|
+
))),
|
|
192
|
+
]),
|
|
193
|
+
m.closable !== false && h('button', {
|
|
194
|
+
type: 'button', class: 'poad-toast__close', 'aria-label': t('common.close'), onclick: (e: MouseEvent) => { e.stopPropagation(); close(); },
|
|
195
|
+
}, icon(registry, 'x', { size: 14 })),
|
|
196
|
+
],
|
|
197
|
+
this.showProgress && !m.sticky && h('i', {
|
|
198
|
+
class: 'poad-toast__progress', style: { animationDuration: `${toastLife(m, life)}ms`, animationPlayState: it.paused ? 'paused' : 'running' },
|
|
199
|
+
}),
|
|
200
|
+
]);
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-toggle-button on-label="Active" off-label="Inactive" on-icon="check" off-icon="x" pressed></poad-toggle-button>
|
|
3
|
+
*
|
|
4
|
+
* Un bouton de la bibliothèque qui garde un état : machine `toggle-button` de @poadio/ui-core (geste refusé désactivé
|
|
5
|
+
* ou en lecture seule ; allumé = plein de la sévérité, éteint = contour `secondary` ; libellé et icône de chaque état ;
|
|
6
|
+
* `aria-pressed`). Même DOM que `poad-toggle-button` d'ui-angular. Propriété `pressed`, évènements `input` / `change`.
|
|
7
|
+
* Formulaire : `name`, `value` (défaut `on`, soumis quand il est enfoncé). Style : `toggle-button.css`, `button.css`.
|
|
8
|
+
*/
|
|
9
|
+
import { toggleButtonTransition, toggleButtonView, type ButtonSeverity, type ButtonSize, type ToggleButtonState } from '@poadio/ui-core';
|
|
10
|
+
import { button } from './button.js';
|
|
11
|
+
import { h } from './dom.js';
|
|
12
|
+
import { PoadFormElement } from './element.js';
|
|
13
|
+
import { icon } from './icon.js';
|
|
14
|
+
|
|
15
|
+
export class PoadToggleButtonElement extends PoadFormElement {
|
|
16
|
+
static override props = {
|
|
17
|
+
pressed: 'boolean', onLabel: 'string', offLabel: 'string', onIcon: 'string', offIcon: 'string', severity: 'string', size: 'string',
|
|
18
|
+
disabled: 'boolean', readonly: 'boolean', ariaLabel: 'string', name: 'string', value: 'string',
|
|
19
|
+
} as const;
|
|
20
|
+
declare pressed?: boolean;
|
|
21
|
+
declare onLabel?: string;
|
|
22
|
+
declare offLabel?: string;
|
|
23
|
+
declare onIcon?: string;
|
|
24
|
+
declare offIcon?: string;
|
|
25
|
+
/** Sévérité à l'état allumé. */
|
|
26
|
+
declare severity?: ButtonSeverity;
|
|
27
|
+
declare size?: ButtonSize;
|
|
28
|
+
declare disabled?: boolean;
|
|
29
|
+
declare readonly?: boolean;
|
|
30
|
+
declare ariaLabel: string | null;
|
|
31
|
+
declare name?: string;
|
|
32
|
+
declare value?: string;
|
|
33
|
+
protected readonly resetProps = ['pressed'];
|
|
34
|
+
|
|
35
|
+
protected formValue() {
|
|
36
|
+
return { value: this.pressed ? (this.value ?? 'on') : null, missing: false };
|
|
37
|
+
}
|
|
38
|
+
protected render() {
|
|
39
|
+
const state: ToggleButtonState = { on: !!this.pressed, disabled: this.inactive, readonly: !!this.readonly };
|
|
40
|
+
const { onLabel, offLabel, onIcon, offIcon, severity, size, ariaLabel } = this;
|
|
41
|
+
const view = toggleButtonView(state, { onLabel, offLabel, onIcon, offIcon, severity, size, ariaLabel });
|
|
42
|
+
const toggle = () => {
|
|
43
|
+
const next = toggleButtonTransition(state, { type: 'toggle' });
|
|
44
|
+
if (next === state) return; // désactivé ou en lecture seule : le socle refuse le geste
|
|
45
|
+
this.pressed = next.on;
|
|
46
|
+
this.changed(next.on);
|
|
47
|
+
};
|
|
48
|
+
return h('span', { class: ['poad-toggle-button', { 'is-on': state.on }] }, button(view.button, {
|
|
49
|
+
type: 'button', 'aria-pressed': view['aria-pressed'], 'aria-label': view['aria-label'], onclick: toggle,
|
|
50
|
+
}, [view.icon && icon(this.icons(), view.icon, { size: view.iconSize }), view.label && h('span', view.label), this.content]));
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/tooltip.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-tooltip text="Redémarre les pods" placement="bottom"><button>Restart</button></poad-tooltip>
|
|
3
|
+
*
|
|
4
|
+
* Info-bulle sur le premier élément écrit dans `<poad-tooltip>` (son ancre : il reçoit les écouteurs et
|
|
5
|
+
* `aria-describedby`) : survol ET focus clavier (`event`), délais d'apparition et de disparition (`delay`,
|
|
6
|
+
* `hide-delay`), retournement, Échap ferme. Logique : machine `tooltip` d'ui-core (l'élément ne tient que les
|
|
7
|
+
* minuteries) ; placement : couche flottante interne. Même DOM, mêmes classes, même ARIA que `[poadTooltip]`
|
|
8
|
+
* d'ui-angular. Texte : attribut `text` (`content` est, sur tous nos éléments, le contenu écrit dans l'élément).
|
|
9
|
+
* Style : `tooltip.css`, `floating.css`.
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
TOOLTIP_ARROW, TOOLTIP_INITIAL, TOOLTIP_MARGIN, TOOLTIP_OFFSET, tooltipAnchorProps, tooltipCandidates, tooltipProps, tooltipTransition,
|
|
13
|
+
type FloatingSide, type TooltipEffect, type TooltipEvent, type TooltipTrigger,
|
|
14
|
+
} from '@poadio/ui-core';
|
|
15
|
+
import { h } from './dom.js';
|
|
16
|
+
import { PoadElement } from './element.js';
|
|
17
|
+
import { FloatingTracker, Presence, arrowStyle, controlOf } from './floating.js';
|
|
18
|
+
|
|
19
|
+
export class PoadTooltipElement extends PoadElement {
|
|
20
|
+
static override props = {
|
|
21
|
+
text: 'string', placement: 'string', delay: 'number', hideDelay: 'number', disabled: 'boolean', maxWidth: 'number', event: 'string',
|
|
22
|
+
} as const;
|
|
23
|
+
/** Texte de l'info-bulle. Vide : pas d'info-bulle. */
|
|
24
|
+
declare text?: string;
|
|
25
|
+
/** Côté voulu (défaut `top`), retourné s'il ne tient pas. */
|
|
26
|
+
declare placement?: FloatingSide;
|
|
27
|
+
declare delay?: number;
|
|
28
|
+
declare hideDelay?: number;
|
|
29
|
+
declare disabled?: boolean;
|
|
30
|
+
declare maxWidth?: number;
|
|
31
|
+
declare event?: TooltipTrigger;
|
|
32
|
+
private state = TOOLTIP_INITIAL;
|
|
33
|
+
private open = false;
|
|
34
|
+
private timer: ReturnType<typeof setTimeout> | null = null;
|
|
35
|
+
private wired: Element | null = null;
|
|
36
|
+
private ownDescribedBy: string | null = null;
|
|
37
|
+
private blocked = false;
|
|
38
|
+
private readonly presence = new Presence(130, () => this.update()); // disparition en fondu, comme ui-angular
|
|
39
|
+
private readonly tracker = new FloatingTracker(() => this.update());
|
|
40
|
+
|
|
41
|
+
/** L'élément décrit. */
|
|
42
|
+
get anchor(): HTMLElement | null {
|
|
43
|
+
return (this.content ?? []).find((n): n is HTMLElement => n instanceof HTMLElement) ?? null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private send(e: TooltipEvent) {
|
|
47
|
+
const step = tooltipTransition(this.state, e, {
|
|
48
|
+
disabled: this.disabled, hasContent: !!this.text, event: this.event, delay: this.delay, hideDelay: this.hideDelay,
|
|
49
|
+
});
|
|
50
|
+
this.state = step.state;
|
|
51
|
+
step.effects.forEach((effect) => this.run(effect));
|
|
52
|
+
}
|
|
53
|
+
private run(effect: TooltipEffect) {
|
|
54
|
+
const clear = () => { if (this.timer) { clearTimeout(this.timer); this.timer = null; } };
|
|
55
|
+
if (effect.type === 'schedule') { clear(); this.timer = setTimeout(() => { this.timer = null; this.send({ type: 'timer' }); }, effect.delay); }
|
|
56
|
+
else if (effect.type === 'cancel') clear();
|
|
57
|
+
else { this.open = effect.type === 'shown'; this.update(); }
|
|
58
|
+
}
|
|
59
|
+
override disconnectedCallback(): void {
|
|
60
|
+
super.disconnectedCallback();
|
|
61
|
+
if (this.timer) clearTimeout(this.timer);
|
|
62
|
+
this.tracker.sync(null, null);
|
|
63
|
+
}
|
|
64
|
+
protected render() {
|
|
65
|
+
this.presence.set(this.open);
|
|
66
|
+
const side = this.tracker.placement?.side ?? this.placement ?? 'top';
|
|
67
|
+
const attrs = tooltipProps({ id: `${this.uid}-tip`, side, visible: this.presence.shown, maxWidth: this.maxWidth });
|
|
68
|
+
return [
|
|
69
|
+
this.content,
|
|
70
|
+
this.presence.mounted && h('div', { class: 'poad-floating poad-tooltip-pane', style: this.tracker.style }, h('div', {
|
|
71
|
+
id: attrs.id, role: attrs.role, 'data-placement': attrs['data-placement'], class: ['poad-tooltip', attrs.classes], style: { maxWidth: `${attrs.maxWidth}px` },
|
|
72
|
+
}, [this.text, h('span', { class: 'poad-tooltip__arrow', 'aria-hidden': 'true', style: arrowStyle(this.tracker.placement) })])),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
protected override updated(): void {
|
|
76
|
+
// désactivée ou vidée : la machine le sait (et se cache) — `sync` à chaque changement de ce contexte
|
|
77
|
+
const blocked = !!this.disabled || !this.text;
|
|
78
|
+
if (blocked !== this.blocked) { this.blocked = blocked; this.send({ type: 'sync' }); }
|
|
79
|
+
const anchor = this.anchor;
|
|
80
|
+
if (anchor && anchor !== this.wired) {
|
|
81
|
+
this.wired = anchor;
|
|
82
|
+
this.ownDescribedBy = controlOf(anchor).getAttribute('aria-describedby');
|
|
83
|
+
anchor.addEventListener('mouseenter', () => this.send({ type: 'enter' }));
|
|
84
|
+
anchor.addEventListener('mouseleave', () => this.send({ type: 'leave' }));
|
|
85
|
+
// focusin / focusout (qui remontent) : l'ancre peut être un de nos éléments, dont le contrôle intérieur a le focus
|
|
86
|
+
anchor.addEventListener('focusin', (e) => this.send({ type: 'focus', visible: (e.target as HTMLElement).matches(':focus-visible') || anchor.matches(':focus-visible, :focus-within') }));
|
|
87
|
+
anchor.addEventListener('focusout', () => this.send({ type: 'leave' }));
|
|
88
|
+
anchor.addEventListener('keydown', (e) => { if (e.key === 'Escape') this.send({ type: 'hide', delay: 0 }); });
|
|
89
|
+
anchor.addEventListener('touchstart', () => this.send({ type: 'enter' }), { passive: true });
|
|
90
|
+
anchor.addEventListener('touchend', () => this.send({ type: 'leave' }));
|
|
91
|
+
}
|
|
92
|
+
if (anchor) {
|
|
93
|
+
const described = [this.ownDescribedBy, tooltipAnchorProps({ open: this.open, pending: null }, `${this.uid}-tip`)['aria-describedby']].filter(Boolean).join(' ');
|
|
94
|
+
const control = controlOf(anchor);
|
|
95
|
+
if (described) control.setAttribute('aria-describedby', described); else control.removeAttribute('aria-describedby');
|
|
96
|
+
}
|
|
97
|
+
this.tracker.sync(this.presence.mounted ? anchor : null, this.querySelector<HTMLElement>(':scope > .poad-tooltip-pane'), {
|
|
98
|
+
candidates: tooltipCandidates(this.placement ?? 'top'), offset: TOOLTIP_OFFSET, margin: TOOLTIP_MARGIN, arrow: TOOLTIP_ARROW,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|