@poadio/ui-elements 0.1.0 → 0.3.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 +42 -0
- package/README.md +47 -1
- 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/checkbox.d.ts +15 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +18 -0
- package/dist/checkbox.js.map +1 -1
- 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/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/element.d.ts +4 -0
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +5 -2
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +40 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- 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/meter.d.ts +1 -0
- package/dist/meter.d.ts.map +1 -1
- package/dist/meter.js +1 -2
- package/dist/meter.js.map +1 -1
- 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/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/paginator.d.ts +65 -0
- package/dist/paginator.d.ts.map +1 -0
- package/dist/paginator.js +110 -0
- package/dist/paginator.js.map +1 -0
- package/dist/segmented.d.ts +1 -0
- package/dist/segmented.d.ts.map +1 -1
- package/dist/segmented.js +1 -2
- package/dist/segmented.js.map +1 -1
- package/dist/select.d.ts +3 -6
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +8 -24
- package/dist/select.js.map +1 -1
- 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/slider.d.ts +1 -0
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +1 -2
- package/dist/slider.js.map +1 -1
- 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/table.d.ts +176 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +293 -0
- package/dist/table.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/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/package.json +3 -3
- package/src/accordion.ts +80 -0
- package/src/checkbox.ts +21 -1
- 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/dialog.ts +217 -0
- package/src/element.ts +7 -2
- package/src/index.ts +33 -2
- package/src/menu.ts +281 -0
- package/src/meter.ts +2 -1
- package/src/multiselect.ts +273 -0
- package/src/option-list.ts +51 -0
- package/src/paginator.ts +151 -0
- package/src/segmented.ts +2 -1
- package/src/select.ts +14 -30
- package/src/services.ts +10 -0
- package/src/slider.ts +2 -1
- package/src/split-button.ts +76 -0
- package/src/stepper.ts +86 -0
- package/src/table.ts +364 -0
- package/src/tabs.ts +129 -0
- package/src/toast.ts +203 -0
package/dist/tabs.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-tabs value="res" variant="pill">
|
|
3
|
+
* <poad-tab value="res" label="Resources" count="12" icon="database">…contenu…</poad-tab>
|
|
4
|
+
* <poad-tab value="logs" label="Logs" closable>…</poad-tab>
|
|
5
|
+
* <button slot="end">+</button>
|
|
6
|
+
* </poad-tabs>
|
|
7
|
+
*
|
|
8
|
+
* Onglets : machine `tabs` de @poadio/ui-core (onglet actif par `value`, sinon par rang `active-index` ; ← → dans le
|
|
9
|
+
* sens de lecture, Début, Fin, qui activent et focalisent ; attributs `tablist` / `tab` / `tabpanel` ; panneaux
|
|
10
|
+
* paresseux, `keep-alive`). Les `<poad-tab>` sont des DÉCLARATIONS : le groupe lit leurs attributs et pose leur contenu
|
|
11
|
+
* dans le panneau. Évènements : `change` (detail : la valeur de l'onglet choisi par l'utilisateur, son rang s'il n'a
|
|
12
|
+
* pas de valeur), `tabclose` (detail : la valeur, croix d'un onglet `closable`). Même DOM, mêmes classes, même ARIA
|
|
13
|
+
* que `poad-tabs` d'ui-angular. Style : `@poadio/ui-core/tabs.css` (et `icon.css`).
|
|
14
|
+
*/
|
|
15
|
+
import { elementIsRtl, tabsActiveIndex, tabsKeydown, tabsOverflow, tabsPanelProps, tabsPanelRendered, tabsRootClasses, tabsScrollBy, tabsSelect, tabsTabProps, } from '@poadio/ui-core';
|
|
16
|
+
import { PoadDeclarationElement, declarations } from './declaration.js';
|
|
17
|
+
import { h } from './dom.js';
|
|
18
|
+
import { PoadElement } from './element.js';
|
|
19
|
+
import { icon } from './icon.js';
|
|
20
|
+
/** Déclaration d'un onglet dans un `<poad-tabs>` ; ses enfants sont le contenu de son panneau. */
|
|
21
|
+
export class PoadTabElement extends PoadDeclarationElement {
|
|
22
|
+
static props = { value: 'json', label: 'string', count: 'json', icon: 'string', disabled: 'boolean', closable: 'boolean' };
|
|
23
|
+
}
|
|
24
|
+
const isEnd = (n) => n instanceof Element && n.getAttribute('slot') === 'end';
|
|
25
|
+
export class PoadTabsElement extends PoadElement {
|
|
26
|
+
static props = {
|
|
27
|
+
value: 'json', activeIndex: 'number', variant: 'string', size: 'string', stretch: 'boolean', scrollable: 'boolean', keepAlive: 'boolean',
|
|
28
|
+
};
|
|
29
|
+
rendered = new Set();
|
|
30
|
+
overflow = false;
|
|
31
|
+
get tabs() {
|
|
32
|
+
return declarations(this, this.content, this.tag('tab'), PoadTabElement.props);
|
|
33
|
+
}
|
|
34
|
+
list() {
|
|
35
|
+
return this.querySelector(':scope > .poad-tabs > .poad-tabs__bar > .poad-tabs__list');
|
|
36
|
+
}
|
|
37
|
+
select(i, focus) {
|
|
38
|
+
const tabs = this.tabs;
|
|
39
|
+
const items = tabs.map((t) => ({ value: t.data.value, disabled: !!t.data.disabled }));
|
|
40
|
+
const active = tabsActiveIndex(items, this.value, this.activeIndex ?? 0);
|
|
41
|
+
const pick = tabsSelect(items, active, i, this.value);
|
|
42
|
+
if (!pick)
|
|
43
|
+
return;
|
|
44
|
+
this.activeIndex = i;
|
|
45
|
+
if (pick.writeValue)
|
|
46
|
+
this.value = pick.value;
|
|
47
|
+
this.emit('change', pick.value === undefined ? i : pick.value);
|
|
48
|
+
const button = this.list()?.querySelectorAll(':scope > [role="tab"]')[i];
|
|
49
|
+
button?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
|
|
50
|
+
if (focus)
|
|
51
|
+
button?.focus();
|
|
52
|
+
}
|
|
53
|
+
updated() {
|
|
54
|
+
const el = this.list();
|
|
55
|
+
const over = !!el && tabsOverflow(el.scrollWidth, el.clientWidth);
|
|
56
|
+
if (over !== this.overflow) {
|
|
57
|
+
this.overflow = over;
|
|
58
|
+
this.update();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
render() {
|
|
62
|
+
const { t } = this.i18n();
|
|
63
|
+
const registry = this.icons();
|
|
64
|
+
const tabs = this.tabs;
|
|
65
|
+
const items = tabs.map((tb) => ({ value: tb.data.value, disabled: !!tb.data.disabled }));
|
|
66
|
+
const active = tabsActiveIndex(items, this.value, this.activeIndex ?? 0);
|
|
67
|
+
this.rendered.add(active);
|
|
68
|
+
const ids = tabs.map((_, i) => `${this.uid}-tab-${i}`);
|
|
69
|
+
const arrows = this.scrollable && this.overflow;
|
|
70
|
+
const scroll = (dir) => { const el = this.list(); if (el)
|
|
71
|
+
el.scrollBy({ left: tabsScrollBy(el.clientWidth, dir) }); };
|
|
72
|
+
const onkeydown = (e) => {
|
|
73
|
+
const next = tabsKeydown(items, active, e.key, elementIsRtl(this.list()));
|
|
74
|
+
if (next === null)
|
|
75
|
+
return;
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
this.select(next, true);
|
|
78
|
+
};
|
|
79
|
+
return h('div', { class: ['poad-tabs', tabsRootClasses({ variant: this.variant, size: this.size, stretch: this.stretch })] }, [
|
|
80
|
+
h('div', { class: 'poad-tabs__bar' }, [
|
|
81
|
+
arrows && h('button', { type: 'button', class: 'poad-tabs__arrow', 'aria-label': t('nav.scrollLeft'), onclick: () => scroll(-1) }, icon(registry, 'chevron-left', { size: 14 })),
|
|
82
|
+
h('div', {
|
|
83
|
+
class: ['poad-tabs__list', { 'is-scrollable': !!this.scrollable }], role: 'tablist', onkeydown,
|
|
84
|
+
onscroll: () => { const el = this.list(); const over = !!el && tabsOverflow(el.scrollWidth, el.clientWidth); if (over !== this.overflow) {
|
|
85
|
+
this.overflow = over;
|
|
86
|
+
this.update();
|
|
87
|
+
} },
|
|
88
|
+
}, [
|
|
89
|
+
tabs.map((tb, i) => {
|
|
90
|
+
const p = tb.data;
|
|
91
|
+
const a = tabsTabProps(ids[i], i === active, !!p.disabled);
|
|
92
|
+
return h('button', {
|
|
93
|
+
type: 'button', role: a.role, id: a.id, 'aria-selected': a['aria-selected'], 'aria-controls': a['aria-controls'], tabindex: a.tabindex,
|
|
94
|
+
class: a.classes['is-active'] ? 'is-active' : undefined, disabled: a.disabled, onclick: () => this.select(i, false),
|
|
95
|
+
}, [
|
|
96
|
+
p.icon && icon(registry, p.icon, { size: 14 }),
|
|
97
|
+
h('span', {}, p.label ?? ''),
|
|
98
|
+
p.count != null && h('span', { class: 'poad-tabs__count' }, String(p.count)),
|
|
99
|
+
p.closable && h('span', {
|
|
100
|
+
class: 'poad-tabs__close', role: 'button', 'aria-label': t('nav.closeTab', { label: p.label ?? '' }),
|
|
101
|
+
onclick: (e) => { e.stopPropagation(); this.emit('tabclose', p.value === undefined ? i : p.value); },
|
|
102
|
+
}, icon(registry, 'x', { size: 11 })),
|
|
103
|
+
]);
|
|
104
|
+
}),
|
|
105
|
+
(this.content ?? []).filter(isEnd),
|
|
106
|
+
]),
|
|
107
|
+
arrows && h('button', { type: 'button', class: 'poad-tabs__arrow', 'aria-label': t('nav.scrollRight'), onclick: () => scroll(1) }, icon(registry, 'chevron-right', { size: 14 })),
|
|
108
|
+
]),
|
|
109
|
+
tabs.map((tb, i) => {
|
|
110
|
+
if (!tabsPanelRendered(i, active, { keepAlive: this.keepAlive, rendered: this.rendered.has(i) }))
|
|
111
|
+
return null;
|
|
112
|
+
const a = tabsPanelProps(ids[i]);
|
|
113
|
+
return h('div', { class: 'poad-tabs__panel', role: a.role, id: a.id, 'aria-labelledby': a['aria-labelledby'], hidden: i !== active, tabindex: a.tabindex }, tb.content);
|
|
114
|
+
}),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=tabs.js.map
|
package/dist/tabs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab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,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;aAClL,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;gBACjB,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAC9G,MAAM,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC;gBAClC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;YAC1K,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC"}
|
package/dist/toast.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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 { type ToastMessageLike, type ToastPosition, type ToastStore } from '@poadio/ui-core';
|
|
16
|
+
import { PoadElement } from './element.js';
|
|
17
|
+
export interface PoadToastAction {
|
|
18
|
+
readonly label: string;
|
|
19
|
+
readonly click: (msg: PoadToastMessage) => void;
|
|
20
|
+
readonly severity?: 'primary' | 'secondary' | 'danger';
|
|
21
|
+
}
|
|
22
|
+
export interface PoadToastMessage extends ToastMessageLike {
|
|
23
|
+
data?: unknown;
|
|
24
|
+
actions?: readonly PoadToastAction[];
|
|
25
|
+
}
|
|
26
|
+
type Shortcut = (summary: string, detail?: string, opts?: Partial<PoadToastMessage>) => PoadToastMessage;
|
|
27
|
+
/** Une file de toasts, appelable : `service(message)` = `service.add(message)`. */
|
|
28
|
+
export interface PoadToastService extends ToastStore<PoadToastMessage> {
|
|
29
|
+
(message: PoadToastMessage): PoadToastMessage;
|
|
30
|
+
success: Shortcut;
|
|
31
|
+
info: Shortcut;
|
|
32
|
+
warn: Shortcut;
|
|
33
|
+
error: Shortcut;
|
|
34
|
+
}
|
|
35
|
+
/** Une autre file de toasts (la bibliothèque en a une par défaut : `poadToast`). */
|
|
36
|
+
export declare const createPoadToastService: () => PoadToastService;
|
|
37
|
+
/** La file par défaut ; sans `<poad-toast>` qui la montre, le premier message en fait poser un. */
|
|
38
|
+
export declare const poadToast: PoadToastService;
|
|
39
|
+
export declare class PoadToastElement extends PoadElement {
|
|
40
|
+
static props: {
|
|
41
|
+
readonly position: "string";
|
|
42
|
+
readonly toastKey: "string";
|
|
43
|
+
readonly life: "number";
|
|
44
|
+
readonly maxVisible: "number";
|
|
45
|
+
readonly preventDuplicates: "boolean";
|
|
46
|
+
readonly showProgress: "boolean";
|
|
47
|
+
readonly zIndex: "string";
|
|
48
|
+
};
|
|
49
|
+
static functions: readonly ["service", "renderItem"];
|
|
50
|
+
position?: ToastPosition;
|
|
51
|
+
toastKey?: string;
|
|
52
|
+
life?: number;
|
|
53
|
+
maxVisible?: number;
|
|
54
|
+
preventDuplicates?: boolean;
|
|
55
|
+
showProgress?: boolean;
|
|
56
|
+
zIndex?: string;
|
|
57
|
+
/** La file montrée (défaut : `poadToast`). */
|
|
58
|
+
service?: PoadToastService;
|
|
59
|
+
/** Rendu d'un toast (contenu à la place de l'icône, des textes et de la croix). */
|
|
60
|
+
renderItem?: (msg: PoadToastMessage, close: () => void) => string | Node;
|
|
61
|
+
private items;
|
|
62
|
+
private readonly known;
|
|
63
|
+
private readonly timers;
|
|
64
|
+
private subscribed;
|
|
65
|
+
private unsubscribe;
|
|
66
|
+
private get queue();
|
|
67
|
+
disconnectedCallback(): void;
|
|
68
|
+
protected updated(): void;
|
|
69
|
+
private clearTimer;
|
|
70
|
+
private animateOut;
|
|
71
|
+
private arm;
|
|
72
|
+
private sync;
|
|
73
|
+
private hover;
|
|
74
|
+
private pause;
|
|
75
|
+
private resume;
|
|
76
|
+
protected render(): import("./dom.js").VNode;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../src/toast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEsB,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EACtF,MAAM,iBAAiB,CAAC;AAGzB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E,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IACxB,8CAA8C;IACtC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACnC,mFAAmF;IAC3E,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,MAAM,GAAG,IAAI,CAAC;IAEjF,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoD;IAC3E,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,WAAW,CAA6B;IAEhD,OAAO,KAAK,KAAK,GAA0D;IAClE,oBAAoB,IAAI,IAAI;cAWlB,OAAO,IAAI,IAAI;IAUlC,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,IAAI;IAeZ,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,MAAM;IAQd,SAAS,CAAC,MAAM;CAgCjB"}
|
package/dist/toast.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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 { TOAST_LIFE, TOAST_MAX_VISIBLE, TOAST_OUT_MS, createToastStore, toastForKey, toastIcon, toastItemProps, toastLife, toastPause, toastResume, toastRootClass, toastSync, } from '@poadio/ui-core';
|
|
16
|
+
import { button } from './button.js';
|
|
17
|
+
import { h } from './dom.js';
|
|
18
|
+
import { PoadElement } from './element.js';
|
|
19
|
+
import { icon } from './icon.js';
|
|
20
|
+
import { servicePrefix } from './services.js';
|
|
21
|
+
function service(onAdd) {
|
|
22
|
+
const store = createToastStore(() => Date.now());
|
|
23
|
+
const add = (m) => { const out = store.add(m); onAdd?.(); return out; };
|
|
24
|
+
const sev = (severity) => (summary, detail, opts = {}) => add({ severity, summary, detail, ...opts });
|
|
25
|
+
return Object.assign(add, {
|
|
26
|
+
add, messages: store.messages, remove: store.remove, clear: store.clear, subscribe: store.subscribe,
|
|
27
|
+
success: sev('success'), info: sev('info'), warn: sev('warn'), error: sev('error'),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** Une autre file de toasts (la bibliothèque en a une par défaut : `poadToast`). */
|
|
31
|
+
export const createPoadToastService = () => service();
|
|
32
|
+
/** `<poad-toast>` sans clé connectés à la file par défaut. */
|
|
33
|
+
const defaultHosts = new Set();
|
|
34
|
+
/** La file par défaut ; sans `<poad-toast>` qui la montre, le premier message en fait poser un. */
|
|
35
|
+
export const poadToast = service(() => {
|
|
36
|
+
const tag = `${servicePrefix()}-toast`;
|
|
37
|
+
if (typeof document === 'undefined' || defaultHosts.size || !customElements.get(tag))
|
|
38
|
+
return;
|
|
39
|
+
document.body.append(document.createElement(tag));
|
|
40
|
+
});
|
|
41
|
+
export class PoadToastElement extends PoadElement {
|
|
42
|
+
static props = {
|
|
43
|
+
position: 'string', toastKey: 'string', life: 'number', maxVisible: 'number', preventDuplicates: 'boolean', showProgress: 'boolean', zIndex: 'string',
|
|
44
|
+
};
|
|
45
|
+
static functions = ['service', 'renderItem'];
|
|
46
|
+
items = [];
|
|
47
|
+
known = new Set();
|
|
48
|
+
timers = new Map();
|
|
49
|
+
subscribed = null;
|
|
50
|
+
unsubscribe = null;
|
|
51
|
+
get queue() { return this.service ?? poadToast; }
|
|
52
|
+
disconnectedCallback() {
|
|
53
|
+
super.disconnectedCallback();
|
|
54
|
+
defaultHosts.delete(this);
|
|
55
|
+
this.unsubscribe?.();
|
|
56
|
+
this.unsubscribe = null;
|
|
57
|
+
this.subscribed = null;
|
|
58
|
+
this.timers.forEach(clearTimeout);
|
|
59
|
+
this.timers.clear();
|
|
60
|
+
this.items = [];
|
|
61
|
+
this.known.clear();
|
|
62
|
+
}
|
|
63
|
+
updated() {
|
|
64
|
+
const queue = this.queue;
|
|
65
|
+
if (queue === poadToast && !this.toastKey)
|
|
66
|
+
defaultHosts.add(this);
|
|
67
|
+
else
|
|
68
|
+
defaultHosts.delete(this);
|
|
69
|
+
if (queue === this.subscribed)
|
|
70
|
+
return;
|
|
71
|
+
this.unsubscribe?.();
|
|
72
|
+
this.subscribed = queue;
|
|
73
|
+
this.unsubscribe = queue.subscribe(() => this.sync());
|
|
74
|
+
this.sync();
|
|
75
|
+
}
|
|
76
|
+
clearTimer(id) {
|
|
77
|
+
const t = this.timers.get(id);
|
|
78
|
+
if (t)
|
|
79
|
+
clearTimeout(t);
|
|
80
|
+
this.timers.delete(id);
|
|
81
|
+
}
|
|
82
|
+
animateOut(msg, notify) {
|
|
83
|
+
const it = this.items.find((x) => x.msg === msg);
|
|
84
|
+
if (!it || it.state === 'out')
|
|
85
|
+
return;
|
|
86
|
+
this.clearTimer(msg.id);
|
|
87
|
+
this.items = this.items.map((x) => (x.msg === msg ? { ...x, state: 'out' } : x));
|
|
88
|
+
this.update();
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
this.items = this.items.filter((x) => x.msg !== msg);
|
|
91
|
+
this.known.delete(msg.id);
|
|
92
|
+
this.update();
|
|
93
|
+
if (notify)
|
|
94
|
+
this.queue.remove(msg);
|
|
95
|
+
this.emit('close', msg);
|
|
96
|
+
}, TOAST_OUT_MS);
|
|
97
|
+
}
|
|
98
|
+
arm(it) {
|
|
99
|
+
this.clearTimer(it.msg.id);
|
|
100
|
+
this.timers.set(it.msg.id, setTimeout(() => this.animateOut(it.msg, true), it.remaining));
|
|
101
|
+
}
|
|
102
|
+
sync() {
|
|
103
|
+
const queue = this.queue;
|
|
104
|
+
const r = toastSync(this.items, toastForKey(queue.messages(), this.toastKey), this.known, {
|
|
105
|
+
life: this.life ?? TOAST_LIFE, maxVisible: this.maxVisible ?? TOAST_MAX_VISIBLE, preventDuplicates: this.preventDuplicates, now: Date.now(),
|
|
106
|
+
});
|
|
107
|
+
for (const m of r.rejected)
|
|
108
|
+
queue.remove(m);
|
|
109
|
+
const fresh = r.items.filter((it) => !this.items.includes(it));
|
|
110
|
+
if (fresh.length) {
|
|
111
|
+
fresh.forEach((it) => this.known.add(it.msg.id));
|
|
112
|
+
this.items = [...this.items, ...fresh];
|
|
113
|
+
this.update();
|
|
114
|
+
for (const it of fresh)
|
|
115
|
+
if (r.arm.includes(it.msg))
|
|
116
|
+
this.arm(it);
|
|
117
|
+
}
|
|
118
|
+
for (const d of r.dismiss)
|
|
119
|
+
this.animateOut(d.msg, d.notify);
|
|
120
|
+
}
|
|
121
|
+
hover(m, on) {
|
|
122
|
+
const it = this.items.find((x) => x.msg === m);
|
|
123
|
+
if (it) {
|
|
124
|
+
if (on)
|
|
125
|
+
this.pause(it);
|
|
126
|
+
else
|
|
127
|
+
this.resume(it);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
pause(it) {
|
|
131
|
+
const next = toastPause(it, Date.now());
|
|
132
|
+
if (next === it)
|
|
133
|
+
return;
|
|
134
|
+
this.clearTimer(it.msg.id);
|
|
135
|
+
this.items = this.items.map((x) => (x === it ? next : x));
|
|
136
|
+
this.update();
|
|
137
|
+
}
|
|
138
|
+
resume(it) {
|
|
139
|
+
const next = toastResume(it, Date.now());
|
|
140
|
+
if (next === it)
|
|
141
|
+
return;
|
|
142
|
+
this.items = this.items.map((x) => (x === it ? next : x));
|
|
143
|
+
this.update();
|
|
144
|
+
this.arm(next);
|
|
145
|
+
}
|
|
146
|
+
render() {
|
|
147
|
+
const { t } = this.i18n();
|
|
148
|
+
const registry = this.icons();
|
|
149
|
+
const life = this.life ?? TOAST_LIFE;
|
|
150
|
+
return h('div', { class: toastRootClass(this.position ?? 'top-right'), style: { zIndex: this.zIndex ?? 'var(--poad-z-overlay)' } }, this.items.map((it) => {
|
|
151
|
+
const a = toastItemProps(it.msg, it.state === 'out');
|
|
152
|
+
const close = () => this.animateOut(it.msg, true);
|
|
153
|
+
const m = it.msg;
|
|
154
|
+
return h('div', {
|
|
155
|
+
class: a.className, role: a.role, 'aria-live': a['aria-live'], onmouseenter: () => this.hover(m, true),
|
|
156
|
+
onmouseleave: () => this.hover(m, false), onclick: () => this.emit('toastclick', m),
|
|
157
|
+
}, [
|
|
158
|
+
this.renderItem ? this.renderItem(m, close) : [
|
|
159
|
+
icon(registry, toastIcon(m), { size: 16, class: 'poad-toast__icon' }),
|
|
160
|
+
h('div', { class: 'poad-toast__text' }, [
|
|
161
|
+
m.summary && h('b', {}, m.summary),
|
|
162
|
+
m.detail && h('span', {}, m.detail),
|
|
163
|
+
!!m.actions?.length && h('div', { class: 'poad-toast__actions' }, m.actions.map((ac) => button({ size: 'sm', variant: 'text', severity: ac.severity || 'primary' }, { type: 'button', onclick: (e) => { e.stopPropagation(); ac.click(m); } }, ac.label))),
|
|
164
|
+
]),
|
|
165
|
+
m.closable !== false && h('button', {
|
|
166
|
+
type: 'button', class: 'poad-toast__close', 'aria-label': t('common.close'), onclick: (e) => { e.stopPropagation(); close(); },
|
|
167
|
+
}, icon(registry, 'x', { size: 14 })),
|
|
168
|
+
],
|
|
169
|
+
this.showProgress && !m.sticky && h('i', {
|
|
170
|
+
class: 'poad-toast__progress', style: { animationDuration: `${toastLife(m, life)}ms`, animationPlayState: it.paused ? 'paused' : 'running' },
|
|
171
|
+
}),
|
|
172
|
+
]);
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.js","sourceRoot":"","sources":["../src/toast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EACzJ,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,CAAC,EAAc,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAuB9C,SAAS,OAAO,CAAC,KAAkB;IACjC,MAAM,KAAK,GAAG,gBAAgB,CAAmB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,CAAC,CAAmB,EAAE,EAAE,GAAG,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAA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-
"description": "Framework-free web components of the poad UI library (<poad-switch>, <poad-button>, <poad-field>, <poad-select>, named icons, badge, tag, chip, avatar, divider, skeleton, progress, meter, message, checkbox, radio, toggle button, segmented, button group) built on @poadio/ui-core (state machines, shared CSS, message catalogue). Light DOM (one CSS for every renderer), form-associated through ElementInternals, safe to import on a server. For vanilla pages, Svelte, Solid or server-rendered HTML.",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Framework-free web components of the poad UI library (<poad-switch>, <poad-button>, <poad-field>, <poad-select>, named icons, badge, tag, chip, avatar, divider, skeleton, progress, meter, message, checkbox, radio, toggle button, segmented, button group, fields, tooltip, popover, colorpicker, tabs, accordion, stepper, menu, split button, multiselect, combo, datepicker, dialog, drawer, poadConfirm(), poadToast()) built on @poadio/ui-core (state machines, shared CSS, message catalogue). Light DOM (one CSS for every renderer), form-associated through ElementInternals, safe to import on a server. For vanilla pages, Svelte, Solid or server-rendered HTML.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "poad — Stéphane Zuccatti",
|
|
7
7
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"i18n:check": "node ../../tools/check-i18n.mjs ui-elements"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@poadio/ui-core": "^0.
|
|
40
|
+
"@poadio/ui-core": "^0.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^24.0.0",
|
package/src/accordion.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-accordion value="db">
|
|
3
|
+
* <poad-accordion-panel value="db" header="Database" icon="database">…contenu…</poad-accordion-panel>
|
|
4
|
+
* <poad-accordion-panel value="net" header="Network" disabled>…</poad-accordion-panel>
|
|
5
|
+
* </poad-accordion>
|
|
6
|
+
* <poad-accordion multiple value='["db"]'>…</poad-accordion>
|
|
7
|
+
*
|
|
8
|
+
* Accordéon : machine `accordion` de @poadio/ui-core (un panneau ouvert, ou plusieurs avec `multiple` ; ↓ ↑ Début Fin
|
|
9
|
+
* entre en-têtes ; attributs `aria-expanded` / `region` ; panneau fermé `inert`). Les `<poad-accordion-panel>` sont
|
|
10
|
+
* des DÉCLARATIONS (sans `value`, un panneau vaut son rang : `"0"`, `"1"`…). Propriété `value` (valeur d'un panneau, un
|
|
11
|
+
* tableau en `multiple`, ou `null`) ; évènement `change` (detail : la nouvelle valeur) quand l'utilisateur ouvre ou
|
|
12
|
+
* ferme. Même DOM, mêmes classes, même ARIA que `poad-accordion` d'ui-angular. Style : `accordion.css`, `icon.css`.
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
accordionHeaderProps, accordionIsOpen, accordionKeydown, accordionPanelClasses, accordionRegionProps, accordionRootClasses, accordionSet, type AccordionValue,
|
|
16
|
+
} from '@poadio/ui-core';
|
|
17
|
+
import { PoadDeclarationElement, declarations } from './declaration.js';
|
|
18
|
+
import { h } from './dom.js';
|
|
19
|
+
import { PoadElement } from './element.js';
|
|
20
|
+
import { icon } from './icon.js';
|
|
21
|
+
|
|
22
|
+
export interface AccordionPanelData {
|
|
23
|
+
readonly value?: string;
|
|
24
|
+
readonly header?: string;
|
|
25
|
+
readonly icon?: string;
|
|
26
|
+
readonly disabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Déclaration d'un panneau dans un `<poad-accordion>` ; ses enfants sont son contenu. */
|
|
30
|
+
export class PoadAccordionPanelElement extends PoadDeclarationElement {
|
|
31
|
+
static override props = { value: 'string', header: 'string', icon: 'string', disabled: 'boolean' } as const;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class PoadAccordionElement extends PoadElement {
|
|
35
|
+
static override props = { value: 'json', multiple: 'boolean', expandIcon: 'string', flush: 'boolean' } as const;
|
|
36
|
+
declare value?: string | string[] | null;
|
|
37
|
+
declare multiple?: boolean;
|
|
38
|
+
declare expandIcon?: string;
|
|
39
|
+
declare flush?: boolean;
|
|
40
|
+
|
|
41
|
+
protected render() {
|
|
42
|
+
const registry = this.icons();
|
|
43
|
+
const panels = declarations<AccordionPanelData>(this, this.content, this.tag('accordion-panel'), PoadAccordionPanelElement.props);
|
|
44
|
+
const keyOf = (p: AccordionPanelData, i: number) => p.value ?? String(i);
|
|
45
|
+
const toggle = (p: AccordionPanelData, i: number) => {
|
|
46
|
+
if (p.disabled) return;
|
|
47
|
+
const v = keyOf(p, i);
|
|
48
|
+
const open = !accordionIsOpen(this.value, v);
|
|
49
|
+
const next = accordionSet((this.value ?? null) as AccordionValue, v, open, this.multiple);
|
|
50
|
+
if (next === this.value) return;
|
|
51
|
+
this.value = next as string | string[] | null;
|
|
52
|
+
this.emit('change', next);
|
|
53
|
+
};
|
|
54
|
+
const onkeydown = (e: KeyboardEvent, i: number) => {
|
|
55
|
+
const to = accordionKeydown(panels.map((p) => ({ disabled: !!p.data.disabled })), i, e.key);
|
|
56
|
+
if (to === null) return;
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
this.querySelectorAll<HTMLElement>(':scope > .poad-accordion > .poad-accordion-panel > h3 > button')[to]?.focus();
|
|
59
|
+
};
|
|
60
|
+
return h('div', { class: ['poad-accordion', accordionRootClasses(this.flush)] }, panels.map(({ data: p, content }, i) => {
|
|
61
|
+
const id = `${this.uid}-acc-${i}`;
|
|
62
|
+
const open = accordionIsOpen(this.value, keyOf(p, i));
|
|
63
|
+
const hd = accordionHeaderProps(id, open, !!p.disabled);
|
|
64
|
+
const rg = accordionRegionProps(id, open);
|
|
65
|
+
return h('div', { class: ['poad-accordion-panel', accordionPanelClasses(open, !!p.disabled)] }, [
|
|
66
|
+
h('h3', { class: 'poad-acc__h' }, h('button', {
|
|
67
|
+
type: 'button', class: 'poad-acc__hd', id: hd.id, 'aria-expanded': hd['aria-expanded'], 'aria-controls': hd['aria-controls'], disabled: hd.disabled,
|
|
68
|
+
onclick: () => toggle(p, i), onkeydown: (e: KeyboardEvent) => onkeydown(e, i),
|
|
69
|
+
}, [
|
|
70
|
+
icon(registry, this.expandIcon ?? 'chevron-right', { size: 13, class: 'poad-acc__chev' }),
|
|
71
|
+
p.icon && icon(registry, p.icon, { size: 14 }),
|
|
72
|
+
h('span', { class: 'poad-acc__title' }, p.header ?? ''),
|
|
73
|
+
h('span', { class: 'poad-acc__extra' }),
|
|
74
|
+
])),
|
|
75
|
+
h('div', { class: 'poad-acc__wrap', role: rg.role, id: rg.id, 'aria-labelledby': rg['aria-labelledby'], inert: rg.inert },
|
|
76
|
+
h('div', { class: 'poad-acc__inner' }, h('div', { class: 'poad-acc__bd' }, content))),
|
|
77
|
+
]);
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/checkbox.ts
CHANGED
|
@@ -7,10 +7,30 @@
|
|
|
7
7
|
* valeur) aux seuls gestes. Formulaire : `name`, `value` (défaut `on`), `required`. Style : `checkbox.css`.
|
|
8
8
|
*/
|
|
9
9
|
import { checkboxControlProps, checkboxLabelProps, checkboxMark, checkboxRootClasses, checkboxTransition, type CheckboxState } from '@poadio/ui-core';
|
|
10
|
-
import {
|
|
10
|
+
import type { IconRegistry } from '@poadio/ui-core';
|
|
11
|
+
import { h, type VNode } from './dom.js';
|
|
11
12
|
import { PoadFormElement } from './element.js';
|
|
12
13
|
import { icon } from './icon.js';
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Une case dessinée DANS un autre élément (cases de la table), sans élément `<poad-checkbox>` à elle : même DOM, mêmes
|
|
17
|
+
* classes, même ARIA ; `onToggle` reçoit l'état suivant (geste refusé : rien). Interne au paquet.
|
|
18
|
+
*/
|
|
19
|
+
export function checkboxNode(registry: IconRegistry, o: { readonly id: string; readonly checked: boolean; readonly indeterminate?: boolean; readonly ariaLabel: string; readonly disabled?: boolean; readonly onToggle: (checked: boolean) => void }): VNode {
|
|
20
|
+
const state: CheckboxState = { checked: o.checked, indeterminate: !!o.indeterminate, disabled: !!o.disabled, readonly: false };
|
|
21
|
+
const element = { id: o.id, label: '', ariaLabel: o.ariaLabel, invalid: false };
|
|
22
|
+
const control = checkboxControlProps(state, element);
|
|
23
|
+
const mark = checkboxMark(state);
|
|
24
|
+
const toggle = () => {
|
|
25
|
+
const next = checkboxTransition(state, { type: 'toggle' });
|
|
26
|
+
if (next !== state) o.onToggle(next.checked);
|
|
27
|
+
};
|
|
28
|
+
return h('span', { class: ['poad-checkbox', checkboxRootClasses(state, element)] }, h('button', {
|
|
29
|
+
type: 'button', role: control.role, id: control.id, 'aria-checked': control['aria-checked'], disabled: control.disabled, 'aria-label': control['aria-label'], onclick: toggle,
|
|
30
|
+
}, h('span', { class: 'poad-checkbox__box' },
|
|
31
|
+
mark === 'dash' ? h('span', { class: 'poad-checkbox__dash' }) : mark === 'check' && icon(registry, 'check', { size: 11, strokeWidth: 3.2 }))));
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
export class PoadCheckboxElement extends PoadFormElement {
|
|
15
35
|
static override props = {
|
|
16
36
|
checked: 'boolean', indeterminate: 'boolean', disabled: 'boolean', readonly: 'boolean', invalid: 'boolean', label: 'string', ariaLabel: 'string',
|