@poadio/ui-elements 0.0.0-stage → 0.1.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 +35 -0
- package/LICENSE +22 -0
- package/README.md +119 -2
- 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/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/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 +84 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +166 -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 +98 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -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/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 +42 -0
- package/dist/meter.d.ts.map +1 -0
- package/dist/meter.js +47 -0
- package/dist/meter.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/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 +51 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +68 -0
- package/dist/segmented.js.map +1 -0
- package/dist/select.d.ts +122 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +201 -0
- package/dist/select.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 +76 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +137 -0
- package/dist/slider.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/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/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/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/define.ts +4 -0
- package/src/divider.ts +22 -0
- package/src/dom.ts +102 -0
- package/src/element.ts +182 -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 +101 -0
- package/src/inplace.ts +69 -0
- package/src/mask.ts +170 -0
- package/src/message.ts +37 -0
- package/src/meter.ts +63 -0
- package/src/number.ts +94 -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 +81 -0
- package/src/select.ts +242 -0
- package/src/skeleton.ts +24 -0
- package/src/slider.ts +144 -0
- package/src/switch.ts +52 -0
- package/src/tag.ts +29 -0
- package/src/toggle-button.ts +52 -0
- package/src/tooltip.ts +101 -0
package/src/inplace.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-inplace display="Paris" closable><input name="city" value="Paris"></poad-inplace>
|
|
3
|
+
* <poad-inplace><b slot="display">Paris</b><input value="Paris"></poad-inplace>
|
|
4
|
+
*
|
|
5
|
+
* Affichage (un bouton qui montre `display` ou les enfants `slot="display"`, crayon au survol) → éditeur (les autres
|
|
6
|
+
* enfants, posés seulement en édition) au clic ; le focus va au premier champ de l'éditeur. Échap referme
|
|
7
|
+
* (`close-on-escape`, défaut oui), la sortie du focus aussi (`close-on-blur`). Logique : machine `inplace` de
|
|
8
|
+
* @poadio/ui-core ; même DOM, mêmes classes, même ARIA que `poad-inplace` d'ui-angular. Propriété `active` ;
|
|
9
|
+
* évènements `activate`, `deactivate`. Style : `inplace.css`. (Hors édition, l'éditeur n'est pas dans le document :
|
|
10
|
+
* un champ nommé n'est donc soumis qu'en édition.)
|
|
11
|
+
*/
|
|
12
|
+
import { INPLACE_FOCUS_SELECTOR, inplaceRootClasses, inplaceTransition, type InplaceEvent, type InplaceState } from '@poadio/ui-core';
|
|
13
|
+
import { h } from './dom.js';
|
|
14
|
+
import { PoadElement } from './element.js';
|
|
15
|
+
import { icon } from './icon.js';
|
|
16
|
+
|
|
17
|
+
export class PoadInplaceElement extends PoadElement {
|
|
18
|
+
static override props = {
|
|
19
|
+
active: 'boolean', display: 'string', closable: 'boolean', disabled: 'boolean', closeOnEscape: 'boolean', closeOnBlur: 'boolean', showIcon: 'boolean',
|
|
20
|
+
ariaLabel: 'string',
|
|
21
|
+
} as const;
|
|
22
|
+
declare active?: boolean;
|
|
23
|
+
declare display?: string;
|
|
24
|
+
declare closable?: boolean;
|
|
25
|
+
declare disabled?: boolean;
|
|
26
|
+
declare closeOnEscape?: boolean;
|
|
27
|
+
declare closeOnBlur?: boolean;
|
|
28
|
+
/** Crayon au survol (défaut : oui ; `show-icon="false"`). */
|
|
29
|
+
declare showIcon?: boolean;
|
|
30
|
+
declare ariaLabel: string | null;
|
|
31
|
+
|
|
32
|
+
private send(event: InplaceEvent): boolean {
|
|
33
|
+
const state: InplaceState = { active: !!this.active, disabled: !!this.disabled };
|
|
34
|
+
const next = inplaceTransition(state, event, { closeOnEscape: this.closeOnEscape !== false, closeOnBlur: this.closeOnBlur });
|
|
35
|
+
if (next === state) return false;
|
|
36
|
+
this.active = next.active;
|
|
37
|
+
this.emit(next.active ? 'activate' : 'deactivate');
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
protected render() {
|
|
41
|
+
const { t } = this.i18n();
|
|
42
|
+
const state: InplaceState = { active: !!this.active, disabled: !!this.disabled };
|
|
43
|
+
const isDisplay = (n: Node) => n instanceof Element && n.getAttribute('slot') === 'display';
|
|
44
|
+
const content = this.content ?? [];
|
|
45
|
+
return h('span', { class: ['poad-inplace', inplaceRootClasses(state)] }, !state.active
|
|
46
|
+
? h('button', {
|
|
47
|
+
type: 'button', class: 'poad-inplace__display', disabled: state.disabled, 'aria-label': this.ariaLabel || t('common.edit'),
|
|
48
|
+
onclick: () => {
|
|
49
|
+
if (this.send({ type: 'activate' })) this.querySelector<HTMLElement>(`.poad-inplace__content :is(${INPLACE_FOCUS_SELECTOR})`)?.focus();
|
|
50
|
+
},
|
|
51
|
+
}, [
|
|
52
|
+
h('span', { class: 'poad-inplace__txt' }, content.some(isDisplay) ? content.filter(isDisplay) : this.display),
|
|
53
|
+
this.showIcon !== false && icon(this.icons(), 'edit', { size: 12, class: 'poad-inplace__ic' }),
|
|
54
|
+
])
|
|
55
|
+
: h('div', {
|
|
56
|
+
class: 'poad-inplace__content',
|
|
57
|
+
onkeydown: (e: KeyboardEvent) => this.send({ type: 'keydown', key: e.key }),
|
|
58
|
+
onfocusout: (e: FocusEvent) => {
|
|
59
|
+
const next = e.relatedTarget as Node | null;
|
|
60
|
+
const inside = !!next && (e.currentTarget as HTMLElement).contains(next);
|
|
61
|
+
if (this.closeOnBlur && !inside) setTimeout(() => this.send({ type: 'focusOut', inside }));
|
|
62
|
+
},
|
|
63
|
+
}, [
|
|
64
|
+
content.filter((n) => !isDisplay(n)),
|
|
65
|
+
this.closable && h('button', { type: 'button', class: 'poad-inplace__close', 'aria-label': t('common.close'), onclick: () => this.send({ type: 'deactivate' }) },
|
|
66
|
+
icon(this.icons(), 'x', { size: 13 })),
|
|
67
|
+
]));
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/mask.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masque de saisie et filtre de touches, sans framework : deux CONTRÔLEURS posés sur un `<input>` natif, et deux
|
|
3
|
+
* éléments qui les posent sur le champ qu'ils entourent (comme `<poad-field>`). Logique : `mask` de @poadio/ui-core,
|
|
4
|
+
* la même que `input[poadMask]` / `input[poadKeyFilter]` d'ui-angular.
|
|
5
|
+
*
|
|
6
|
+
* <poad-mask preset="phone"><input name="tel"></poad-mask> <poad-key-filter filter="int"><input></poad-key-filter>
|
|
7
|
+
* const tel = attachMask(input, { mask: '99/99/9999', unmask: true, onValueChange: (v, complete) => … }); tel.detach();
|
|
8
|
+
*
|
|
9
|
+
* Pourquoi des éléments enveloppes plutôt qu'un attribut sur l'`<input>` : un attribut demanderait d'observer tout le
|
|
10
|
+
* document ; l'enveloppe se définit comme les autres éléments, garde ses attributs ↔ propriétés, et laisse le champ
|
|
11
|
+
* natif à sa place dans le formulaire (il soumet son texte masqué). Les contrôleurs restent utilisables seuls.
|
|
12
|
+
* `<poad-mask>` : propriétés `value` (lecture : valeur ; écriture : imposée) et `complete` ; évènement `valuechange`
|
|
13
|
+
* (detail : la valeur — texte masqué, ou caractères utiles avec `unmask` ; `null` si vide). Le `input` natif du champ
|
|
14
|
+
* remonte aussi, avec le texte affiché.
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
MASK_SLOT, keyFilterBlocks, keyFilterPaste, maskFirstSlot, maskInput, maskInputMode, maskPlaceholder, maskResolve, maskWrite, type KeyFilter,
|
|
18
|
+
} from '@poadio/ui-core';
|
|
19
|
+
import { PoadElement } from './element.js';
|
|
20
|
+
|
|
21
|
+
export interface MaskControllerOptions {
|
|
22
|
+
readonly mask?: string;
|
|
23
|
+
readonly preset?: string;
|
|
24
|
+
readonly slotChar?: string;
|
|
25
|
+
readonly unmask?: boolean;
|
|
26
|
+
readonly autoClear?: boolean;
|
|
27
|
+
readonly onValueChange?: (value: string | null, complete: boolean) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface MaskController {
|
|
30
|
+
/** Toutes les places remplies (ou champ vide). */
|
|
31
|
+
readonly complete: boolean;
|
|
32
|
+
readonly value: string | null;
|
|
33
|
+
/** Valeur imposée (sans évènement). */
|
|
34
|
+
write(value: string | null | undefined): void;
|
|
35
|
+
/** Nouvelles options (masque, préréglage…). */
|
|
36
|
+
configure(options: MaskControllerOptions): void;
|
|
37
|
+
detach(): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function attachMask(input: HTMLInputElement, initial: MaskControllerOptions): MaskController {
|
|
41
|
+
let o = initial, complete = true, value: string | null = null;
|
|
42
|
+
const mask = () => maskResolve(o.mask, o.preset), slot = () => o.slotChar ?? MASK_SLOT;
|
|
43
|
+
const decorate = () => {
|
|
44
|
+
input.placeholder = maskPlaceholder(mask(), slot());
|
|
45
|
+
const mode = maskInputMode(mask());
|
|
46
|
+
if (mode) input.inputMode = mode; else input.removeAttribute('inputmode');
|
|
47
|
+
};
|
|
48
|
+
const emit = (next: string | null) => { value = next; o.onValueChange?.(next, complete); };
|
|
49
|
+
const onInput = (e: Event) => {
|
|
50
|
+
const r = maskInput(mask(), input.value, input.selectionStart ?? input.value.length, { slot: slot(), unmask: o.unmask, deleting: !!(e as InputEvent).inputType?.startsWith('delete') });
|
|
51
|
+
input.value = r.display;
|
|
52
|
+
input.setSelectionRange(r.caret, r.caret);
|
|
53
|
+
complete = r.complete;
|
|
54
|
+
emit(r.value);
|
|
55
|
+
};
|
|
56
|
+
const onFocus = () => setTimeout(() => { const p = maskFirstSlot(input.value, slot()); if (input.value) input.setSelectionRange(p, p); });
|
|
57
|
+
const onBlur = () => {
|
|
58
|
+
if (!o.autoClear || complete) return;
|
|
59
|
+
input.value = '';
|
|
60
|
+
complete = true;
|
|
61
|
+
emit(null);
|
|
62
|
+
};
|
|
63
|
+
input.addEventListener('input', onInput);
|
|
64
|
+
input.addEventListener('focus', onFocus);
|
|
65
|
+
input.addEventListener('blur', onBlur);
|
|
66
|
+
decorate();
|
|
67
|
+
return {
|
|
68
|
+
get complete() { return complete; },
|
|
69
|
+
get value() { return value; },
|
|
70
|
+
write(next) {
|
|
71
|
+
const r = maskWrite(mask(), next, slot());
|
|
72
|
+
input.value = r.display;
|
|
73
|
+
complete = r.complete;
|
|
74
|
+
value = next ?? null;
|
|
75
|
+
},
|
|
76
|
+
configure(options) { o = options; decorate(); },
|
|
77
|
+
detach() { input.removeEventListener('input', onInput); input.removeEventListener('focus', onFocus); input.removeEventListener('blur', onBlur); },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function attachKeyFilter(field: HTMLInputElement | HTMLTextAreaElement, initial: KeyFilter, validateOnly = false): {
|
|
82
|
+
configure(filter: KeyFilter, validateOnly?: boolean): void;
|
|
83
|
+
detach(): void;
|
|
84
|
+
} {
|
|
85
|
+
let filter = initial, only = validateOnly;
|
|
86
|
+
const onKeydown = (e: KeyboardEvent) => { if (keyFilterBlocks(filter, e, only)) e.preventDefault(); };
|
|
87
|
+
const onPaste = (e: ClipboardEvent) => {
|
|
88
|
+
const clean = keyFilterPaste(filter, e.clipboardData?.getData('text') ?? '', only);
|
|
89
|
+
if (clean == null) return;
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
const start = field.selectionStart ?? field.value.length, end = field.selectionEnd ?? start;
|
|
92
|
+
field.setRangeText(clean, start, end, 'end');
|
|
93
|
+
field.dispatchEvent(new Event('input', { bubbles: true }));
|
|
94
|
+
};
|
|
95
|
+
field.addEventListener('keydown', onKeydown as EventListener);
|
|
96
|
+
field.addEventListener('paste', onPaste as EventListener);
|
|
97
|
+
return {
|
|
98
|
+
configure(next, v = only) { filter = next; only = v; },
|
|
99
|
+
detach() { field.removeEventListener('keydown', onKeydown as EventListener); field.removeEventListener('paste', onPaste as EventListener); },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Le premier `<input>` (ou `<textarea>`) du contenu écrit dans l'élément. */
|
|
104
|
+
function fieldIn(content: readonly Node[] | null, selector: string): HTMLInputElement | null {
|
|
105
|
+
for (const node of content ?? []) {
|
|
106
|
+
if (!(node instanceof Element)) continue;
|
|
107
|
+
const found = node.matches(selector) ? node : node.querySelector(selector);
|
|
108
|
+
if (found) return found as HTMLInputElement;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class PoadMaskElement extends PoadElement {
|
|
114
|
+
static override props = { mask: 'string', preset: 'string', slotChar: 'string', unmask: 'boolean', autoClear: 'boolean' } as const;
|
|
115
|
+
declare mask?: string;
|
|
116
|
+
declare preset?: string;
|
|
117
|
+
declare slotChar?: string;
|
|
118
|
+
declare unmask?: boolean;
|
|
119
|
+
declare autoClear?: boolean;
|
|
120
|
+
private controller: MaskController | null = null;
|
|
121
|
+
private pending: string | null | undefined = undefined;
|
|
122
|
+
|
|
123
|
+
get complete(): boolean { return this.controller?.complete ?? true; }
|
|
124
|
+
get value(): string | null { return this.controller?.value ?? null; }
|
|
125
|
+
set value(next: string | null) {
|
|
126
|
+
if (this.controller) this.controller.write(next); else this.pending = next;
|
|
127
|
+
}
|
|
128
|
+
protected render() {
|
|
129
|
+
return this.content;
|
|
130
|
+
}
|
|
131
|
+
protected override updated(): void {
|
|
132
|
+
const input = fieldIn(this.content, 'input');
|
|
133
|
+
if (!input) return;
|
|
134
|
+
const options: MaskControllerOptions = {
|
|
135
|
+
mask: this.mask, preset: this.preset, slotChar: this.slotChar, unmask: this.unmask, autoClear: this.autoClear,
|
|
136
|
+
onValueChange: (value) => this.emit('valuechange', value),
|
|
137
|
+
};
|
|
138
|
+
if (this.controller) return this.controller.configure(options);
|
|
139
|
+
this.controller = attachMask(input, options);
|
|
140
|
+
if (this.pending !== undefined || input.value) this.controller.write(this.pending ?? input.value);
|
|
141
|
+
}
|
|
142
|
+
override disconnectedCallback(): void {
|
|
143
|
+
super.disconnectedCallback();
|
|
144
|
+
this.controller?.detach();
|
|
145
|
+
this.controller = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export class PoadKeyFilterElement extends PoadElement {
|
|
150
|
+
static override props = { filter: 'string', validateOnly: 'boolean' } as const;
|
|
151
|
+
/** `int`, `num`, `alpha`, `alphanum`, `hex`, `email`, ou une expression (propriété : `RegExp`). */
|
|
152
|
+
declare filter?: KeyFilter;
|
|
153
|
+
declare validateOnly?: boolean;
|
|
154
|
+
private controller: ReturnType<typeof attachKeyFilter> | null = null;
|
|
155
|
+
|
|
156
|
+
protected render() {
|
|
157
|
+
return this.content;
|
|
158
|
+
}
|
|
159
|
+
protected override updated(): void {
|
|
160
|
+
const field = fieldIn(this.content, 'input, textarea');
|
|
161
|
+
if (!field) return;
|
|
162
|
+
if (this.controller) this.controller.configure(this.filter ?? 'alphanum', !!this.validateOnly);
|
|
163
|
+
else this.controller = attachKeyFilter(field, this.filter ?? 'alphanum', !!this.validateOnly);
|
|
164
|
+
}
|
|
165
|
+
override disconnectedCallback(): void {
|
|
166
|
+
super.disconnectedCallback();
|
|
167
|
+
this.controller?.detach();
|
|
168
|
+
this.controller = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/message.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-message severity="warning" closable>The certificate expires in 6 days.</poad-message>
|
|
3
|
+
* <poad-message text="Saved" severity="success" variant="outline" size="sm" icon=""></poad-message> sans icône
|
|
4
|
+
*
|
|
5
|
+
* Message en ligne : classes et icône de @poadio/ui-core (`messageClasses`, `messageIcon`) — même DOM que
|
|
6
|
+
* `poad-message` d'ui-angular (`role="status"`). Propriété `open` (défaut : vrai ; `open="false"` le cache). Fermé
|
|
7
|
+
* par l'utilisateur : évènement `close`, il reste dans le DOM avec `is-hidden`. Bouton nommé par le catalogue.
|
|
8
|
+
*/
|
|
9
|
+
import { messageClasses, messageIcon, messageIconSize, type MessageSeverity } from '@poadio/ui-core';
|
|
10
|
+
import { h } from './dom.js';
|
|
11
|
+
import { PoadElement } from './element.js';
|
|
12
|
+
import { icon } from './icon.js';
|
|
13
|
+
|
|
14
|
+
export class PoadMessageElement extends PoadElement {
|
|
15
|
+
static override props = { severity: 'string', text: 'string', icon: 'string', closable: 'boolean', variant: 'string', size: 'string', open: 'boolean' } as const;
|
|
16
|
+
declare severity?: MessageSeverity;
|
|
17
|
+
declare text?: string;
|
|
18
|
+
/** Nom d'icône ; absent : celle de la sévérité ; `""` : aucune. */
|
|
19
|
+
declare icon?: string | null;
|
|
20
|
+
declare closable?: boolean;
|
|
21
|
+
declare variant?: 'soft' | 'outline';
|
|
22
|
+
declare size?: 'sm' | 'md';
|
|
23
|
+
declare open?: boolean;
|
|
24
|
+
|
|
25
|
+
protected render() {
|
|
26
|
+
const options = { severity: this.severity, variant: this.variant, size: this.size, icon: this.icon, hidden: this.open === false };
|
|
27
|
+
const name = messageIcon(options);
|
|
28
|
+
return h('div', { class: messageClasses(options), role: 'status' }, [
|
|
29
|
+
name && icon(this.icons(), name, { size: messageIconSize(options), class: 'poad-message__icon' }),
|
|
30
|
+
h('div', { class: 'poad-message__body' }, [this.text, this.content]),
|
|
31
|
+
this.closable && h('button', {
|
|
32
|
+
type: 'button', class: 'poad-message__close', 'aria-label': this.i18n().t('common.close'),
|
|
33
|
+
onclick: () => { this.open = false; this.emit('close'); },
|
|
34
|
+
}, icon(this.icons(), 'x', { size: 13 })),
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/meter.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-meter values='[{"label":"Used","value":62,"severity":"primary"}]' unit="Gi" show-remaining></poad-meter>
|
|
3
|
+
* meter.values = [...]; meter.renderLabel = (segment, percent) => `${segment.label} ${percent}%`;
|
|
4
|
+
*
|
|
5
|
+
* Jauge segmentée : segments, couleurs, total, reste, attributs (`role="meter"`) et textes de @poadio/ui-core — même
|
|
6
|
+
* DOM que `poad-meter` d'ui-angular. Nombres mis en forme dans la langue de l'élément (`Intl.NumberFormat`) ; titres
|
|
7
|
+
* et « reste » viennent du catalogue. `renderLabel` (propriété) : le contenu d'une entrée de la légende, en texte ou
|
|
8
|
+
* en nœud du DOM — `poadMeterLabel` en Angular. Style : `@poadio/ui-core/meter.css`.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
meterBarProps, meterPercentText, meterRemaining, meterRootClasses, meterSegments, meterValueText,
|
|
12
|
+
type MeterNumberFormat, type MeterSegment, type MeterValue,
|
|
13
|
+
} from '@poadio/ui-core';
|
|
14
|
+
import { h } from './dom.js';
|
|
15
|
+
import { PoadElement } from './element.js';
|
|
16
|
+
|
|
17
|
+
export class PoadMeterElement extends PoadElement {
|
|
18
|
+
static override props = {
|
|
19
|
+
values: 'json', min: 'number', max: 'number', unit: 'string', orientation: 'string', size: 'string', labelPosition: 'string',
|
|
20
|
+
showLabels: 'boolean', showRemaining: 'boolean', remainingLabel: 'string', ariaLabel: 'string',
|
|
21
|
+
} as const;
|
|
22
|
+
declare values?: readonly MeterValue[];
|
|
23
|
+
declare min?: number;
|
|
24
|
+
declare max?: number;
|
|
25
|
+
declare unit?: string;
|
|
26
|
+
declare orientation?: 'horizontal' | 'vertical';
|
|
27
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
28
|
+
declare labelPosition?: 'start' | 'end';
|
|
29
|
+
/** Légende (défaut : oui ; `show-labels="false"` la retire). */
|
|
30
|
+
declare showLabels?: boolean;
|
|
31
|
+
declare showRemaining?: boolean;
|
|
32
|
+
declare remainingLabel?: string;
|
|
33
|
+
declare ariaLabel: string | null;
|
|
34
|
+
/** Contenu d'une entrée de la légende. */
|
|
35
|
+
renderLabel?: (segment: MeterSegment, percent: number) => string | Node;
|
|
36
|
+
|
|
37
|
+
protected render() {
|
|
38
|
+
const i18n = this.i18n();
|
|
39
|
+
const format: MeterNumberFormat = (v, o) => new Intl.NumberFormat(i18n.locale, o).format(v);
|
|
40
|
+
const values = this.values ?? [], min = this.min ?? 0, max = this.max ?? 100, position = this.labelPosition ?? 'end';
|
|
41
|
+
const segments = meterSegments(values, min, max);
|
|
42
|
+
const remaining = meterRemaining(values, min, max);
|
|
43
|
+
const bar = meterBarProps({ values, min, max, ariaLabel: this.ariaLabel });
|
|
44
|
+
const val = (v: number) => meterValueText(format, v, this.unit ?? '');
|
|
45
|
+
const pct = (p: number) => meterPercentText(format, p);
|
|
46
|
+
const legend = this.showLabels !== false && h('div', { class: 'mt__legend' }, [
|
|
47
|
+
segments.map((s) => h('div', { class: 'mt__li' }, this.renderLabel ? this.renderLabel(s, s.percent) : [
|
|
48
|
+
h('i', { style: { background: s.color } }), h('span', { class: 'lb' }, s.label), h('span', { class: 'v' }, [`${val(s.value)} `, h('small', `(${pct(s.percent)})`)]),
|
|
49
|
+
])),
|
|
50
|
+
this.showRemaining && remaining > 0 && h('div', { class: 'mt__li is-rest' }, [
|
|
51
|
+
h('i'), h('span', { class: 'lb' }, i18n.text(this.remainingLabel, 'display.remaining')), h('span', { class: 'v' }, val(remaining)),
|
|
52
|
+
]),
|
|
53
|
+
]);
|
|
54
|
+
return h('div', { class: ['poad-meter', meterRootClasses({ orientation: this.orientation, size: this.size, labelPosition: position })] }, [
|
|
55
|
+
position === 'start' && legend,
|
|
56
|
+
h('div', { class: 'mt__bar', ...bar }, segments.map((s) => h('div', {
|
|
57
|
+
class: 'mt__seg', style: { flexBasis: `${s.percent}%`, background: s.color },
|
|
58
|
+
title: i18n.t('display.meterSegment', { label: s.label, value: val(s.value), percent: pct(s.percent) }),
|
|
59
|
+
}))),
|
|
60
|
+
position === 'end' && legend,
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/number.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-number name="port" value="8080" min="1" max="65535" suffix=" ms" show-buttons></poad-number>
|
|
3
|
+
*
|
|
4
|
+
* Machine `number` de @poadio/ui-core (texte en cours de frappe, lecture `,` ou `.`, bornes, arrondi, mise en forme
|
|
5
|
+
* `Intl` dans la langue de l'élément ou `locale`, ↑ / ↓ ± pas, Maj × 10, Home / End, Entrée, boutons, `spinbutton`) ;
|
|
6
|
+
* même DOM, mêmes classes, même ARIA que `poad-number` d'ui-angular. Propriété `value` (nombre ou `null`) ; évènements
|
|
7
|
+
* `input` / `change` (detail : la valeur) quand l'utilisateur la valide (sortie, touches, boutons) — les évènements
|
|
8
|
+
* natifs du champ intérieur, qui ne portent que du texte, ne sortent pas. Formulaire : `name` (la valeur en nombre,
|
|
9
|
+
* pas le texte mis en forme), `required`. Style : `number.css`.
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
numberButtons, numberControlProps, numberDisplay, numberHandlesKey, numberRootClasses, numberTransition,
|
|
13
|
+
type NumberElementOptions, type NumberEvent, type NumberSize, type NumberState,
|
|
14
|
+
} from '@poadio/ui-core';
|
|
15
|
+
import { h } from './dom.js';
|
|
16
|
+
import { PoadFormElement } from './element.js';
|
|
17
|
+
import { icon } from './icon.js';
|
|
18
|
+
|
|
19
|
+
const stop = (e: Event) => e.stopPropagation();
|
|
20
|
+
|
|
21
|
+
export class PoadNumberElement extends PoadFormElement {
|
|
22
|
+
static override props = {
|
|
23
|
+
value: 'number', min: 'number', max: 'number', step: 'number', decimals: 'number', locale: 'string', prefixText: 'string', suffix: 'string',
|
|
24
|
+
placeholder: 'string', showButtons: 'boolean', disabled: 'boolean', readonly: 'boolean', invalid: 'boolean', size: 'string', ariaLabel: 'string',
|
|
25
|
+
name: 'string', required: 'boolean',
|
|
26
|
+
} as const;
|
|
27
|
+
declare value?: number | null;
|
|
28
|
+
declare min?: number;
|
|
29
|
+
declare max?: number;
|
|
30
|
+
declare step?: number;
|
|
31
|
+
declare decimals?: number;
|
|
32
|
+
/** Langue de mise en forme ; défaut : celle de l'élément. */
|
|
33
|
+
declare locale?: string;
|
|
34
|
+
/** Texte avant le champ (`prefix-text` : `prefix` est déjà une propriété de tout élément du DOM). */
|
|
35
|
+
declare prefixText?: string;
|
|
36
|
+
declare suffix?: string;
|
|
37
|
+
declare placeholder?: string;
|
|
38
|
+
declare showButtons?: boolean;
|
|
39
|
+
declare disabled?: boolean;
|
|
40
|
+
declare readonly?: boolean;
|
|
41
|
+
declare invalid?: boolean;
|
|
42
|
+
declare size?: NumberSize;
|
|
43
|
+
declare ariaLabel: string | null;
|
|
44
|
+
declare name?: string;
|
|
45
|
+
declare required?: boolean;
|
|
46
|
+
protected readonly resetProps = ['value'];
|
|
47
|
+
private editing: string | null = null;
|
|
48
|
+
|
|
49
|
+
private get options(): NumberElementOptions {
|
|
50
|
+
return { min: this.min, max: this.max, step: this.step, decimals: this.decimals, invalid: this.invalid, size: this.size };
|
|
51
|
+
}
|
|
52
|
+
private get state(): NumberState {
|
|
53
|
+
return { value: this.value ?? null, editing: this.editing, disabled: this.inactive, readonly: !!this.readonly };
|
|
54
|
+
}
|
|
55
|
+
private send(event: NumberEvent) {
|
|
56
|
+
const state = this.state;
|
|
57
|
+
const next = numberTransition(state, event, this.options);
|
|
58
|
+
if (next === state) return;
|
|
59
|
+
this.editing = next.editing;
|
|
60
|
+
if (next.value !== state.value) {
|
|
61
|
+
this.value = next.value;
|
|
62
|
+
this.changed(next.value);
|
|
63
|
+
} else this.update();
|
|
64
|
+
}
|
|
65
|
+
protected formValue() {
|
|
66
|
+
return { value: this.value == null ? null : String(this.value), missing: this.value == null };
|
|
67
|
+
}
|
|
68
|
+
protected render() {
|
|
69
|
+
const state = this.state, options = this.options;
|
|
70
|
+
const control = numberControlProps(state, options);
|
|
71
|
+
const buttons = numberButtons(state, options);
|
|
72
|
+
const i18n = this.i18n();
|
|
73
|
+
return h('span', { class: ['poad-number', numberRootClasses(state, options)] }, [
|
|
74
|
+
this.prefixText && h('span', { class: 'poad-number__affix' }, this.prefixText),
|
|
75
|
+
h('input', {
|
|
76
|
+
class: 'poad-number__input', type: control.type, inputmode: control.inputmode, role: control.role, value: numberDisplay(state, this.locale ?? i18n.locale, options),
|
|
77
|
+
placeholder: this.placeholder, disabled: control.disabled, readonly: control.readonly, 'aria-valuemin': control['aria-valuemin'],
|
|
78
|
+
'aria-valuemax': control['aria-valuemax'], 'aria-valuenow': control['aria-valuenow'], 'aria-invalid': control['aria-invalid'], 'aria-label': this.ariaLabel,
|
|
79
|
+
oninput: (e: Event) => { stop(e); this.send({ type: 'input', text: (e.target as HTMLInputElement).value }); },
|
|
80
|
+
onchange: stop,
|
|
81
|
+
onfocus: () => this.send({ type: 'focus' }),
|
|
82
|
+
onblur: () => this.send({ type: 'blur' }),
|
|
83
|
+
onkeydown: (e: KeyboardEvent) => { if (numberHandlesKey(e.key, options)) e.preventDefault(); this.send({ type: 'keydown', key: e.key, shiftKey: e.shiftKey }); },
|
|
84
|
+
}),
|
|
85
|
+
this.suffix && h('span', { class: 'poad-number__affix' }, this.suffix),
|
|
86
|
+
this.showButtons && h('span', { class: 'poad-number__btns' }, [
|
|
87
|
+
h('button', { type: 'button', tabindex: -1, 'aria-label': i18n.t('field.increment'), disabled: buttons.incrementDisabled, onclick: () => this.send({ type: 'step', direction: 1 }) },
|
|
88
|
+
icon(this.icons(), 'chevron-up', { size: 11 })),
|
|
89
|
+
h('button', { type: 'button', tabindex: -1, 'aria-label': i18n.t('field.decrement'), disabled: buttons.decrementDisabled, onclick: () => this.send({ type: 'step', direction: -1 }) },
|
|
90
|
+
icon(this.icons(), 'chevron-down', { size: 11 })),
|
|
91
|
+
]),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/password.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-password name="pwd" feedback autocomplete="new-password"></poad-password>
|
|
3
|
+
*
|
|
4
|
+
* Machine `password` de @poadio/ui-core (bouton œil : type du champ, nom du catalogue, `aria-pressed` ; jauge de
|
|
5
|
+
* robustesse) ; même DOM, mêmes classes, même ARIA que `poad-password` d'ui-angular. Propriétés `value`, `visible` ;
|
|
6
|
+
* évènements `input` (detail : le texte, à chaque frappe) et `change`. Formulaire : le `<input type="password">`
|
|
7
|
+
* intérieur porte `name` et participe lui-même (un vrai champ de mot de passe : gestionnaires de mots de passe,
|
|
8
|
+
* `required`, `autocomplete`). Style : `password.css`.
|
|
9
|
+
*/
|
|
10
|
+
import { passwordInputProps, passwordMeter, passwordRootClasses, passwordToggleProps, passwordTransition, type PasswordState } from '@poadio/ui-core';
|
|
11
|
+
import { h } from './dom.js';
|
|
12
|
+
import { PoadElement } from './element.js';
|
|
13
|
+
import { icon } from './icon.js';
|
|
14
|
+
|
|
15
|
+
export class PoadPasswordElement extends PoadElement {
|
|
16
|
+
static override props = {
|
|
17
|
+
value: 'string', visible: 'boolean', toggleMask: 'boolean', feedback: 'boolean', invalid: 'boolean', disabled: 'boolean', placeholder: 'string',
|
|
18
|
+
autocomplete: 'string', name: 'string', required: 'boolean', ariaLabel: 'string',
|
|
19
|
+
} as const;
|
|
20
|
+
declare value?: string;
|
|
21
|
+
declare visible?: boolean;
|
|
22
|
+
/** Bouton œil (défaut : oui ; `toggle-mask="false"`). */
|
|
23
|
+
declare toggleMask?: boolean;
|
|
24
|
+
declare feedback?: boolean;
|
|
25
|
+
declare invalid?: boolean;
|
|
26
|
+
declare disabled?: boolean;
|
|
27
|
+
declare placeholder?: string;
|
|
28
|
+
declare autocomplete?: string;
|
|
29
|
+
declare name?: string;
|
|
30
|
+
declare required?: boolean;
|
|
31
|
+
declare ariaLabel: string | null;
|
|
32
|
+
|
|
33
|
+
protected render() {
|
|
34
|
+
const { t } = this.i18n();
|
|
35
|
+
const state: PasswordState = { visible: !!this.visible, disabled: !!this.disabled };
|
|
36
|
+
const field = passwordInputProps(state, { invalid: this.invalid, autocomplete: this.autocomplete ?? 'current-password' });
|
|
37
|
+
const eye = passwordToggleProps(state);
|
|
38
|
+
const meter = passwordMeter(this.value, !!this.feedback);
|
|
39
|
+
const relay = (type: string) => (e: Event) => {
|
|
40
|
+
e.stopPropagation();
|
|
41
|
+
this.value = (e.target as HTMLInputElement).value;
|
|
42
|
+
this.emit(type, this.value);
|
|
43
|
+
};
|
|
44
|
+
return h('div', { class: ['poad-password', passwordRootClasses(state, { invalid: this.invalid })] }, [
|
|
45
|
+
h('div', { class: 'poad-password__box' }, [
|
|
46
|
+
h('input', {
|
|
47
|
+
type: field.type, name: this.name, required: this.required, value: this.value ?? '', placeholder: this.placeholder, disabled: field.disabled,
|
|
48
|
+
autocomplete: field.autocomplete, 'aria-invalid': field['aria-invalid'], 'aria-label': this.ariaLabel, spellcheck: 'false',
|
|
49
|
+
oninput: relay('input'), onchange: relay('change'),
|
|
50
|
+
}),
|
|
51
|
+
this.toggleMask !== false && h('button', {
|
|
52
|
+
type: 'button', 'aria-label': t(eye.labelKey), 'aria-pressed': eye['aria-pressed'], disabled: eye.disabled,
|
|
53
|
+
onclick: () => { const next = passwordTransition(state, { type: 'toggleVisible' }); if (next !== state) this.visible = next.visible; },
|
|
54
|
+
}, icon(this.icons(), eye.icon, { size: 15 })),
|
|
55
|
+
]),
|
|
56
|
+
meter && h('div', { class: 'poad-password__meter', 'data-level': meter.level, 'aria-live': 'polite' }, [h('i'), h('i'), h('i'), h('i'), h('span', t(meter.labelKey))]),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/popover.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-popover placement="bottom" align="start" focus-trap>
|
|
3
|
+
* <button slot="trigger">Filtres</button>
|
|
4
|
+
* …contenu…
|
|
5
|
+
* </poad-popover>
|
|
6
|
+
* pop.anchor = buttonEl; pop.open = true; ancré sur un élément de la page
|
|
7
|
+
*
|
|
8
|
+
* Panneau flottant ancré sur une cible : l'enfant `slot="trigger"` (il bascule le panneau et reçoit `aria-haspopup`,
|
|
9
|
+
* `aria-expanded`, `aria-controls`) ou l'élément `anchor` (propriété). Les autres enfants sont le contenu, posé dans le
|
|
10
|
+
* panneau à l'ouverture (fermé, il reste dans l'élément, caché : la page peut le chercher et le modifier). Propriété `open` ; évènement `openchange` (detail : ouvert ou non) aux ouvertures et
|
|
11
|
+
* fermetures de l'utilisateur. Fermé par un appui extérieur, Échap ; `focus-trap` : dialogue modal, focus piégé, rendu à
|
|
12
|
+
* la cible. `mobile="sheet"` : feuille basse sous 768 px. Décisions : `popover` d'ui-core ; couche flottante interne.
|
|
13
|
+
* Même DOM, mêmes classes, même ARIA que `poad-popover` d'ui-angular. Style : `popover.css`, `floating.css`, `sheet.css`.
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
POPOVER_ARROW, POPOVER_MARGIN, SHEET_MOBILE_QUERY, popoverCandidates, popoverDismiss, popoverProps, popoverRestoreFocus, popoverToggle, popoverTriggerProps,
|
|
17
|
+
popoverUseSheet, type FloatingAlign, type FloatingSide, type PopoverMobileMode,
|
|
18
|
+
} from '@poadio/ui-core';
|
|
19
|
+
import { h } from './dom.js';
|
|
20
|
+
import { PoadElement } from './element.js';
|
|
21
|
+
import { FloatingTracker, FocusTrap, Listening, Sheet, arrowStyle, controlOf, listenOutside, mediaMatches } from './floating.js';
|
|
22
|
+
|
|
23
|
+
const isTrigger = (n: Node): n is HTMLElement => n instanceof HTMLElement && n.getAttribute('slot') === 'trigger';
|
|
24
|
+
|
|
25
|
+
export class PoadPopoverElement extends PoadElement {
|
|
26
|
+
static override props = {
|
|
27
|
+
open: 'boolean', placement: 'string', align: 'string', offset: 'number', dismissOnClickOutside: 'boolean', closeOnEscape: 'boolean', focusTrap: 'boolean',
|
|
28
|
+
showArrow: 'boolean', hasBackdrop: 'boolean', width: 'number', minWidth: 'number', mobile: 'string', sheetTitle: 'string',
|
|
29
|
+
} as const;
|
|
30
|
+
declare open?: boolean;
|
|
31
|
+
declare placement?: FloatingSide;
|
|
32
|
+
declare align?: FloatingAlign;
|
|
33
|
+
declare offset?: number;
|
|
34
|
+
declare dismissOnClickOutside?: boolean;
|
|
35
|
+
declare closeOnEscape?: boolean;
|
|
36
|
+
declare focusTrap?: boolean;
|
|
37
|
+
declare showArrow?: boolean;
|
|
38
|
+
declare hasBackdrop?: boolean;
|
|
39
|
+
declare width?: number;
|
|
40
|
+
declare minWidth?: number;
|
|
41
|
+
declare mobile?: PopoverMobileMode;
|
|
42
|
+
declare sheetTitle?: string;
|
|
43
|
+
/** Élément d'ancrage tenu par la page (à la place d'un enfant `slot="trigger"`). */
|
|
44
|
+
anchor: HTMLElement | null = null;
|
|
45
|
+
private inSheet = false;
|
|
46
|
+
private wasOpen = false;
|
|
47
|
+
private wired: HTMLElement | null = null;
|
|
48
|
+
private readonly tracker = new FloatingTracker(() => this.update());
|
|
49
|
+
private readonly trap = new FocusTrap();
|
|
50
|
+
private readonly outside = new Listening(() => listenOutside(() => [this.target, this.querySelector('.poad-popover-pane')], () => this.setOpen(false), {
|
|
51
|
+
outsidePointer: this.dismissOnClickOutside !== false,
|
|
52
|
+
}));
|
|
53
|
+
private readonly sheet = new Sheet(() => this.update());
|
|
54
|
+
|
|
55
|
+
private get target(): HTMLElement | null {
|
|
56
|
+
return this.anchor ?? (this.content ?? []).find(isTrigger) ?? null;
|
|
57
|
+
}
|
|
58
|
+
private get options() {
|
|
59
|
+
return { dismissOnClickOutside: this.dismissOnClickOutside !== false, closeOnEscape: this.closeOnEscape !== false, focusTrap: !!this.focusTrap };
|
|
60
|
+
}
|
|
61
|
+
private setOpen(next: boolean) {
|
|
62
|
+
if (next === !!this.open) return;
|
|
63
|
+
this.open = next;
|
|
64
|
+
this.emit('openchange', next);
|
|
65
|
+
}
|
|
66
|
+
override disconnectedCallback(): void {
|
|
67
|
+
super.disconnectedCallback();
|
|
68
|
+
this.tracker.sync(null, null);
|
|
69
|
+
this.outside.toggle(false);
|
|
70
|
+
this.trap.sync(null, false);
|
|
71
|
+
this.sheet.dispose();
|
|
72
|
+
}
|
|
73
|
+
protected render() {
|
|
74
|
+
const open = !!this.open;
|
|
75
|
+
if (open && !this.wasOpen) this.inSheet = popoverUseSheet(this.mobile ?? 'popover', mediaMatches(SHEET_MOBILE_QUERY)); // décidé à chaque ouverture
|
|
76
|
+
this.wasOpen = open;
|
|
77
|
+
const id = `${this.uid}-pop`, arrow = this.showArrow !== false, floating = open && !this.inSheet;
|
|
78
|
+
const side = this.tracker.placement?.side ?? this.placement ?? 'bottom';
|
|
79
|
+
const attrs = popoverProps({ id, side, focusTrap: this.focusTrap, arrow });
|
|
80
|
+
const body = (sheet: boolean) => h('div', {
|
|
81
|
+
id: attrs.id, role: attrs.role, 'aria-modal': attrs['aria-modal'], 'data-placement': attrs['data-placement'], class: ['poad-popover', attrs.classes],
|
|
82
|
+
style: { width: this.width ? `${this.width}px` : undefined, minWidth: this.minWidth ? `${this.minWidth}px` : undefined },
|
|
83
|
+
onkeydown: (e: KeyboardEvent) => {
|
|
84
|
+
if (popoverDismiss({ type: 'keydown', key: e.key }, this.options).action === 'close') { e.stopPropagation(); this.setOpen(false); }
|
|
85
|
+
},
|
|
86
|
+
}, [arrow && h('span', { class: 'poad-popover__arrow', 'aria-hidden': 'true', style: sheet ? undefined : arrowStyle(this.tracker.placement) }), (this.content ?? []).filter((n) => !isTrigger(n))]);
|
|
87
|
+
return [
|
|
88
|
+
(this.content ?? []).filter(isTrigger),
|
|
89
|
+
// Fermé : le contenu reste dans l'élément, caché (la page le trouve, `querySelector`, et ses éléments gardent leur état).
|
|
90
|
+
!open && h('div', { class: 'poad-popover-stash', hidden: true }, (this.content ?? []).filter((n) => !isTrigger(n))),
|
|
91
|
+
floating && this.hasBackdrop && h('div', { class: 'poad-floating-backdrop poad-popover-backdrop', onclick: () => this.options.dismissOnClickOutside && this.setOpen(false) }),
|
|
92
|
+
floating && h('div', { class: 'poad-floating poad-popover-pane', style: this.tracker.style }, body(false)),
|
|
93
|
+
this.inSheet && this.sheet.render({
|
|
94
|
+
open, title: this.sheetTitle ?? '', titleId: `${id}-sheet-title`, dismissable: this.options.dismissOnClickOutside, closeOnEscape: this.options.closeOnEscape,
|
|
95
|
+
label: this.i18n().t('common.close'), icons: this.icons(), onClose: () => this.setOpen(false),
|
|
96
|
+
}, open ? body(true) : null),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
protected override updated(): void {
|
|
100
|
+
const target = this.target, open = !!this.open, floating = open && !this.inSheet;
|
|
101
|
+
if (target && target !== this.wired && !this.anchor) {
|
|
102
|
+
this.wired = target;
|
|
103
|
+
target.addEventListener('click', () => this.setOpen(popoverToggle(!!this.open, true) === 'open'));
|
|
104
|
+
}
|
|
105
|
+
if (target) for (const [name, value] of Object.entries(popoverTriggerProps(open, `${this.uid}-pop`))) {
|
|
106
|
+
const control = controlOf(target);
|
|
107
|
+
if (value == null) control.removeAttribute(name); else control.setAttribute(name, value);
|
|
108
|
+
}
|
|
109
|
+
const pane = this.querySelector<HTMLElement>(':scope > .poad-popover-pane');
|
|
110
|
+
this.tracker.sync(floating ? target : null, pane, {
|
|
111
|
+
candidates: popoverCandidates(this.placement ?? 'bottom', this.align ?? 'center'), offset: this.offset ?? 8, margin: POPOVER_MARGIN, shift: true,
|
|
112
|
+
arrow: this.showArrow !== false ? POPOVER_ARROW : undefined,
|
|
113
|
+
});
|
|
114
|
+
this.outside.toggle(floating && !this.hasBackdrop);
|
|
115
|
+
this.trap.sync(floating && this.focusTrap ? pane?.querySelector<HTMLElement>('.poad-popover') ?? null : null, popoverRestoreFocus(this.options));
|
|
116
|
+
this.sheet.sync(this);
|
|
117
|
+
}
|
|
118
|
+
}
|