@poadio/ui-elements 0.1.0 → 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 +19 -0
- package/README.md +32 -0
- 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/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 +35 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -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/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/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/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 +29 -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/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/tabs.ts +129 -0
- package/src/toast.ts +203 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-multiselect name="envs" aria-label="Environments" filter show-toggle-all
|
|
3
|
+
* options='[{"label":"Dev","value":"dev"},{"label":"Prod","value":"prod"}]' value='["dev"]'></poad-multiselect>
|
|
4
|
+
*
|
|
5
|
+
* Liste à choix multiples : machine `select` de @poadio/ui-core en mode `multiple` (ouverture, option active, filtre,
|
|
6
|
+
* clavier, recherche au clavier, attributs, placement) et ses compléments `multiselect*` (bascule bornée par
|
|
7
|
+
* `selection-limit`, puces retirables, case « tout » tri-état sur les options visibles, ce que montre le déclencheur).
|
|
8
|
+
* Propriété `value` (tableau ; attribut en JSON) ; Espace / Entrée basculent l'option sans fermer. Évènements `input` /
|
|
9
|
+
* `change` (detail : le tableau) à chaque changement de l'utilisateur, `remove` (detail : la valeur d'une puce retirée),
|
|
10
|
+
* `clear`, `filter`, `openchange`. Formulaire : `name` (une entrée par valeur, en chaîne — JSON pour un objet),
|
|
11
|
+
* `required` (au moins une). Même DOM, mêmes classes, même ARIA que `poad-multiselect` d'ui-angular ; petit écran :
|
|
12
|
+
* feuille basse avec un pied « OK (n) ». Styles : `multiselect.css`, `option-list.css`, `icon.css`, `floating.css`,
|
|
13
|
+
* `sheet.css`.
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
FOCUS_AUTOFOCUS_ATTR, SELECT_INITIAL, SELECT_PLACEMENTS, SHEET_MOBILE_QUERY, multiselectAllProps, multiselectAllState, multiselectCountLabel, multiselectIncludes,
|
|
17
|
+
multiselectLimitReached, multiselectRemove, multiselectRootClasses, multiselectShows, multiselectToggle, multiselectToggleAll, selectEmptyMessage, selectFilterProps,
|
|
18
|
+
selectItems, selectOptionsOf, selectScrollTop, selectSheetTitle, selectTransition, selectTriggerProps, selectUseSheet, selectVisibleItems,
|
|
19
|
+
type MultiselectDisplay, type SelectContext, type SelectEffect, type SelectEvent, type SelectMobileMode, type SelectOptionItem, type SelectState,
|
|
20
|
+
} from '@poadio/ui-core';
|
|
21
|
+
import { h } from './dom.js';
|
|
22
|
+
import { PoadFormElement } from './element.js';
|
|
23
|
+
import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
|
|
24
|
+
import { icon } from './icon.js';
|
|
25
|
+
import { optionList, type PoadSelectOptionContext } from './option-list.js';
|
|
26
|
+
|
|
27
|
+
const autofocus = (on: boolean) => (on ? { [FOCUS_AUTOFOCUS_ATTR]: '' } : {});
|
|
28
|
+
|
|
29
|
+
export class PoadMultiselectElement extends PoadFormElement {
|
|
30
|
+
static override props = {
|
|
31
|
+
value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', optionDisabled: 'string', optionHint: 'string', optionIcon: 'string',
|
|
32
|
+
optionGroupLabel: 'string', optionGroupChildren: 'string', dataKey: 'string', placeholder: 'string', display: 'string', maxSelectedLabels: 'number',
|
|
33
|
+
selectedItemsLabel: 'string', showToggleAll: 'boolean', selectionLimit: 'number', filter: 'boolean', filterPlaceholder: 'string', filterBy: 'string',
|
|
34
|
+
autofocusFilter: 'boolean', clearable: 'boolean', loading: 'boolean', emptyMessage: 'string', emptyFilterMessage: 'string', size: 'string',
|
|
35
|
+
invalid: 'boolean', disabled: 'boolean', readonly: 'boolean', panelMaxHeight: 'number', ariaLabel: 'string', mobile: 'string', sheetTitle: 'string',
|
|
36
|
+
name: 'string', required: 'boolean',
|
|
37
|
+
} as const;
|
|
38
|
+
static override functions = ['compareWith', 'renderOption', 'renderValue', 'renderEmpty'] as const;
|
|
39
|
+
declare value?: readonly unknown[] | null;
|
|
40
|
+
declare options?: readonly unknown[];
|
|
41
|
+
declare optionLabel?: string;
|
|
42
|
+
declare optionValue?: string;
|
|
43
|
+
declare optionDisabled?: string;
|
|
44
|
+
declare optionHint?: string;
|
|
45
|
+
declare optionIcon?: string;
|
|
46
|
+
declare optionGroupLabel?: string;
|
|
47
|
+
declare optionGroupChildren?: string;
|
|
48
|
+
declare dataKey?: string;
|
|
49
|
+
declare placeholder?: string;
|
|
50
|
+
/** `chip` (défaut) : puces retirables ; `comma` : libellés joints. */
|
|
51
|
+
declare display?: MultiselectDisplay;
|
|
52
|
+
/** Au-delà de N valeurs, le déclencheur montre un compte (`selected-items-label`, `{0}` = nombre ; défaut : catalogue). */
|
|
53
|
+
declare maxSelectedLabels?: number | null;
|
|
54
|
+
declare selectedItemsLabel?: string;
|
|
55
|
+
declare showToggleAll?: boolean;
|
|
56
|
+
declare selectionLimit?: number | null;
|
|
57
|
+
declare filter?: boolean;
|
|
58
|
+
declare filterPlaceholder?: string;
|
|
59
|
+
declare filterBy?: string;
|
|
60
|
+
declare autofocusFilter?: boolean;
|
|
61
|
+
declare clearable?: boolean;
|
|
62
|
+
declare loading?: boolean;
|
|
63
|
+
declare emptyMessage?: string;
|
|
64
|
+
declare emptyFilterMessage?: string;
|
|
65
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
66
|
+
declare invalid?: boolean;
|
|
67
|
+
declare disabled?: boolean;
|
|
68
|
+
declare readonly?: boolean;
|
|
69
|
+
declare panelMaxHeight?: number;
|
|
70
|
+
declare ariaLabel: string | null;
|
|
71
|
+
declare mobile?: SelectMobileMode;
|
|
72
|
+
declare sheetTitle?: string;
|
|
73
|
+
declare name?: string;
|
|
74
|
+
declare required?: boolean;
|
|
75
|
+
declare compareWith?: (a: unknown, b: unknown) => boolean;
|
|
76
|
+
/** Contenu d'une option, d'une puce, de la liste vide. */
|
|
77
|
+
declare renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
|
|
78
|
+
declare renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
|
|
79
|
+
declare renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
|
|
80
|
+
protected readonly resetProps = ['value'];
|
|
81
|
+
|
|
82
|
+
private state: SelectState = SELECT_INITIAL;
|
|
83
|
+
private focused = false;
|
|
84
|
+
private inSheet = false;
|
|
85
|
+
private triggerWidth = 0;
|
|
86
|
+
private readonly tracker = new FloatingTracker(() => this.update());
|
|
87
|
+
private readonly outside = new Listening(() => listenOutside(() => [this], () => this.send({ type: 'close', refocus: false })));
|
|
88
|
+
private readonly sheet = new Sheet(() => this.update());
|
|
89
|
+
|
|
90
|
+
private find<E extends HTMLElement>(selector: string): E | null {
|
|
91
|
+
return this.querySelector<E>(`:scope > .poad-multiselect ${selector}`);
|
|
92
|
+
}
|
|
93
|
+
private get listId() { return `${this.uid}-list`; }
|
|
94
|
+
private get values(): readonly unknown[] { return this.value ?? []; }
|
|
95
|
+
private get items() {
|
|
96
|
+
const { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren } = this;
|
|
97
|
+
return selectItems(this.options, { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren }, this.listId);
|
|
98
|
+
}
|
|
99
|
+
private get compare() { return { compareWith: this.compareWith, dataKey: this.dataKey }; }
|
|
100
|
+
private get interactive() { return !this.inactive && !this.readonly; }
|
|
101
|
+
private readonly isSelected = (it: SelectOptionItem<unknown>) => multiselectIncludes(this.values, it.value, this.compare);
|
|
102
|
+
private context(items = this.items): SelectContext<unknown> {
|
|
103
|
+
return {
|
|
104
|
+
items, filter: { enabled: !!this.filter, by: this.filterBy, grouped: !!this.optionGroupLabel }, interactive: this.interactive, clearable: this.clearable,
|
|
105
|
+
modal: this.inSheet, multiple: true, isSelected: this.isSelected,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected formValue() {
|
|
110
|
+
const values = this.values;
|
|
111
|
+
if (!this.name || !values.length) return { value: null, missing: !values.length };
|
|
112
|
+
const data = new FormData();
|
|
113
|
+
for (const v of values) data.append(this.name, typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v));
|
|
114
|
+
return { value: data, missing: false };
|
|
115
|
+
}
|
|
116
|
+
override disconnectedCallback(): void {
|
|
117
|
+
super.disconnectedCallback();
|
|
118
|
+
this.state = SELECT_INITIAL;
|
|
119
|
+
this.tracker.sync(null, null);
|
|
120
|
+
this.outside.toggle(false);
|
|
121
|
+
this.sheet.dispose();
|
|
122
|
+
}
|
|
123
|
+
private commit(next: readonly unknown[]) {
|
|
124
|
+
this.value = next;
|
|
125
|
+
this.changed([...next]);
|
|
126
|
+
}
|
|
127
|
+
private run(effect: SelectEffect<unknown>) {
|
|
128
|
+
switch (effect.type) {
|
|
129
|
+
case 'opened':
|
|
130
|
+
this.triggerWidth = this.find('.poad-multiselect__trigger')?.getBoundingClientRect().width ?? 0;
|
|
131
|
+
this.inSheet = selectUseSheet(this.mobile ?? 'auto', mediaMatches(SHEET_MOBILE_QUERY));
|
|
132
|
+
return void this.emit('openchange', true);
|
|
133
|
+
case 'closed':
|
|
134
|
+
this.inSheet = false;
|
|
135
|
+
this.emit('openchange', false);
|
|
136
|
+
if (effect.refocus) this.find('.poad-multiselect__trigger')?.focus();
|
|
137
|
+
return;
|
|
138
|
+
case 'pick': {
|
|
139
|
+
const cur = this.values;
|
|
140
|
+
const next = multiselectToggle(cur, effect.item.value, this.compare, this.selectionLimit ?? null);
|
|
141
|
+
if (next === cur) return; // limite atteinte
|
|
142
|
+
this.state = { ...this.state, activeIndex: effect.item.index };
|
|
143
|
+
return this.commit(next);
|
|
144
|
+
}
|
|
145
|
+
case 'clear':
|
|
146
|
+
this.commit([]);
|
|
147
|
+
return void this.emit('clear');
|
|
148
|
+
case 'filtered':
|
|
149
|
+
return void this.emit('filter', effect.query);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
private send(event: SelectEvent) {
|
|
153
|
+
const was = this.state.open;
|
|
154
|
+
const step = selectTransition(this.state, event, this.context());
|
|
155
|
+
this.state = step.state;
|
|
156
|
+
step.effects.forEach((e) => this.run(e));
|
|
157
|
+
this.update();
|
|
158
|
+
if (this.state.open && !was && this.filter && this.autofocusFilter !== false && !this.inSheet) this.find<HTMLInputElement>('.poad-multiselect__head input')?.focus();
|
|
159
|
+
return step;
|
|
160
|
+
}
|
|
161
|
+
protected override updated(): void {
|
|
162
|
+
super.updated();
|
|
163
|
+
const floating = this.state.open && !this.inSheet;
|
|
164
|
+
this.tracker.sync(floating ? this.find('.poad-multiselect__trigger') : null, floating ? this.find('.poad-floating') : null, {
|
|
165
|
+
candidates: SELECT_PLACEMENTS, offset: 4, shift: true,
|
|
166
|
+
});
|
|
167
|
+
this.outside.toggle(this.state.open);
|
|
168
|
+
this.sheet.sync(this);
|
|
169
|
+
const list = this.find('.poad-optlist');
|
|
170
|
+
const option = list?.querySelector<HTMLElement>(`[id="${this.listId}-opt-${this.state.activeIndex}"]`);
|
|
171
|
+
if (!list || !option) return;
|
|
172
|
+
const next = selectScrollTop({ top: option.offsetTop, height: option.offsetHeight }, { scrollTop: list.scrollTop, clientHeight: list.clientHeight });
|
|
173
|
+
if (next !== null) list.scrollTop = next;
|
|
174
|
+
}
|
|
175
|
+
private readonly onKeydown = (e: KeyboardEvent) => {
|
|
176
|
+
const step = this.send({
|
|
177
|
+
type: 'keydown', key: e.key, ctrlKey: e.ctrlKey, metaKey: e.metaKey, altKey: e.altKey, inTextField: e.target instanceof HTMLInputElement, time: Date.now(),
|
|
178
|
+
});
|
|
179
|
+
if (step.preventDefault) e.preventDefault();
|
|
180
|
+
if (step.stopPropagation) e.stopPropagation();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
protected render() {
|
|
184
|
+
const { t, text } = this.i18n();
|
|
185
|
+
const registry = this.icons();
|
|
186
|
+
const s = this.state, items = this.items, c = this.context(items), listId = this.listId, values = this.values, compare = this.compare;
|
|
187
|
+
const hasValue = values.length > 0;
|
|
188
|
+
const trigger = selectTriggerProps(s, c, { id: this.uid, listId, ariaLabel: this.ariaLabel, invalid: this.invalid, disabled: this.inactive, readonly: this.readonly });
|
|
189
|
+
const selectedItems = selectOptionsOf(items).filter(this.isSelected);
|
|
190
|
+
const visible = selectVisibleItems(s, c);
|
|
191
|
+
const visibleOptions = selectOptionsOf(visible);
|
|
192
|
+
const filtered = !!s.query;
|
|
193
|
+
const limit = multiselectLimitReached(values, this.selectionLimit ?? null);
|
|
194
|
+
const display = this.display ?? 'chip';
|
|
195
|
+
const root = multiselectRootClasses({
|
|
196
|
+
open: s.open, disabled: this.inactive, readonly: this.readonly, invalid: this.invalid, focused: this.focused, hasValue, limit, size: this.size ?? 'md', display,
|
|
197
|
+
});
|
|
198
|
+
const shows = multiselectShows(values.length, display, this.maxSelectedLabels ?? null);
|
|
199
|
+
const all = multiselectAllProps(multiselectAllState(visibleOptions, values, compare), !visibleOptions.some((o) => !o.disabled));
|
|
200
|
+
const interactive = this.interactive;
|
|
201
|
+
const remove = (it: SelectOptionItem<unknown>, e: MouseEvent) => {
|
|
202
|
+
e.stopPropagation();
|
|
203
|
+
if (!interactive) return;
|
|
204
|
+
this.commit(multiselectRemove(values, it.value, compare));
|
|
205
|
+
this.emit('remove', it.value);
|
|
206
|
+
};
|
|
207
|
+
const toggleAll = () => { if (interactive) this.commit(multiselectToggleAll(visibleOptions, values, compare, this.selectionLimit ?? null)); };
|
|
208
|
+
const clear = (e: MouseEvent) => { e.stopPropagation(); this.send({ type: 'clear' }); };
|
|
209
|
+
const f = selectFilterProps(s, c, { listId });
|
|
210
|
+
const head = (this.filter || this.showToggleAll) && h('div', { class: 'poad-multiselect__head' }, [
|
|
211
|
+
this.showToggleAll && h('button', {
|
|
212
|
+
type: 'button', class: 'poad-multiselect__all', role: all.role, 'aria-checked': all['aria-checked'], 'aria-label': t('select.selectAll'), tabindex: -1,
|
|
213
|
+
disabled: all.disabled, onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: toggleAll,
|
|
214
|
+
}, h('span', { class: ['poad-multiselect__check', all.classes] },
|
|
215
|
+
all.classes['is-on'] ? icon(registry, 'check', { size: 10, strokeWidth: 3.2 }) : all.classes['is-mixed'] && h('i'))),
|
|
216
|
+
this.filter ? [
|
|
217
|
+
icon(registry, 'search', { size: 13 }),
|
|
218
|
+
h('input', {
|
|
219
|
+
type: 'text', ...autofocus(this.inSheet), placeholder: text(this.filterPlaceholder, 'select.filterPlaceholder'), value: s.query, autocomplete: 'off',
|
|
220
|
+
spellcheck: 'false', role: f.role, 'aria-autocomplete': f['aria-autocomplete'], 'aria-controls': f['aria-controls'], 'aria-activedescendant': f['aria-activedescendant'],
|
|
221
|
+
oninput: (e: Event) => this.send({ type: 'filter', query: (e.target as HTMLInputElement).value }),
|
|
222
|
+
}),
|
|
223
|
+
] : this.showToggleAll && h('span', { class: 'poad-multiselect__all-label', onclick: toggleAll }, t('common.all')),
|
|
224
|
+
]);
|
|
225
|
+
const panel = h('div', {
|
|
226
|
+
class: ['poad-multiselect__panel', { 'is-sheet': this.inSheet }], style: this.inSheet ? undefined : { minWidth: `${this.triggerWidth}px` },
|
|
227
|
+
tabindex: this.inSheet ? -1 : undefined, ...autofocus(this.inSheet && !this.filter), onkeydown: this.onKeydown,
|
|
228
|
+
}, [
|
|
229
|
+
head,
|
|
230
|
+
optionList({
|
|
231
|
+
listId, items: visible, activeIndex: s.activeIndex, isSelected: this.isSelected, multiple: true, maxHeight: this.panelMaxHeight ?? 260, icons: registry,
|
|
232
|
+
renderOption: this.renderOption, onPick: (item) => this.send({ type: 'pick', item }), onHover: (index) => this.send({ type: 'hover', index }),
|
|
233
|
+
empty: this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered)),
|
|
234
|
+
}),
|
|
235
|
+
this.inSheet && h('div', { class: 'poad-multiselect__sheet-foot' }, [
|
|
236
|
+
hasValue && this.clearable && h('button', { type: 'button', class: 'poad-multiselect__sheet-btn is-ghost', onclick: clear }, t('select.clearAll')),
|
|
237
|
+
h('button', { type: 'button', class: 'poad-multiselect__sheet-btn', onclick: () => this.send({ type: 'close' }) },
|
|
238
|
+
[t('common.ok'), values.length ? ` (${values.length})` : '']),
|
|
239
|
+
]),
|
|
240
|
+
]);
|
|
241
|
+
return h('div', { class: ['poad-multiselect', root] }, [
|
|
242
|
+
h('div', {
|
|
243
|
+
class: 'poad-multiselect__trigger', role: trigger.role, tabindex: trigger.tabIndex, id: trigger.id, 'aria-haspopup': trigger['aria-haspopup'],
|
|
244
|
+
'aria-expanded': trigger['aria-expanded'], 'aria-controls': trigger['aria-controls'], 'aria-activedescendant': trigger['aria-activedescendant'],
|
|
245
|
+
'aria-label': trigger['aria-label'], 'aria-invalid': trigger['aria-invalid'], 'aria-disabled': trigger['aria-disabled'], 'aria-readonly': trigger['aria-readonly'],
|
|
246
|
+
onclick: () => this.send({ type: 'toggle' }), onkeydown: this.onKeydown,
|
|
247
|
+
onfocus: () => { this.focused = true; this.update(); }, onblur: () => { this.focused = false; this.update(); },
|
|
248
|
+
}, [
|
|
249
|
+
h('span', { class: ['poad-multiselect__value', { 'is-placeholder': !hasValue }] },
|
|
250
|
+
shows === 'placeholder' ? (this.placeholder ?? '')
|
|
251
|
+
: shows === 'count' ? (multiselectCountLabel(this.selectedItemsLabel, values.length) ?? t('select.selectedCount', { n: values.length }))
|
|
252
|
+
: shows === 'comma' ? selectedItems.map((o) => o.label).join(', ')
|
|
253
|
+
: selectedItems.map((o) => h('span', { class: 'poad-multiselect__chip' }, [
|
|
254
|
+
this.renderValue ? this.renderValue(o.option, { label: o.label }) : o.label,
|
|
255
|
+
interactive && h('button', {
|
|
256
|
+
type: 'button', class: 'poad-multiselect__chip-x', tabindex: -1, 'aria-label': t('select.removeItem', { label: o.label }),
|
|
257
|
+
onclick: (e: MouseEvent) => remove(o, e),
|
|
258
|
+
}, icon(registry, 'x', { size: 10, strokeWidth: 2.6 })),
|
|
259
|
+
]))),
|
|
260
|
+
this.loading && icon(registry, 'loader', { size: 14, spin: true, class: 'poad-multiselect__spin' }),
|
|
261
|
+
this.clearable && hasValue && interactive && h('button', {
|
|
262
|
+
type: 'button', class: 'poad-multiselect__clear', tabindex: -1, 'aria-label': t('select.clearAll'), onclick: clear,
|
|
263
|
+
}, icon(registry, 'x', { size: 12 })),
|
|
264
|
+
icon(registry, 'chevron-down', { size: 13, class: 'poad-multiselect__chev' }),
|
|
265
|
+
]),
|
|
266
|
+
s.open && !this.inSheet && h('div', { class: 'poad-floating', style: this.tracker.style }, panel),
|
|
267
|
+
this.sheet.render({
|
|
268
|
+
open: s.open && this.inSheet, titleId: `${this.uid}-sheet-title`, restoreFocus: false, label: t('common.close'), icons: registry,
|
|
269
|
+
onClose: () => this.send({ type: 'close' }), title: selectSheetTitle({ sheetTitle: this.sheetTitle, ariaLabel: this.ariaLabel, placeholder: this.placeholder }),
|
|
270
|
+
}, this.inSheet ? panel : null),
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liste d'options d'un panneau — INTERNE, partagée par `<poad-select>` et `<poad-multiselect>` : même DOM que
|
|
3
|
+
* `poad-option-list` d'ui-angular (`role="listbox"`, options `role="option"`, coche ou case en choix multiple, icône,
|
|
4
|
+
* libellé, indice, groupes, message vide). Attributs : machine `select` d'ui-core. Style : `option-list.css`.
|
|
5
|
+
*/
|
|
6
|
+
import { selectListboxProps, selectOptionProps, type IconRegistry, type SelectListItem, type SelectOptionItem } from '@poadio/ui-core';
|
|
7
|
+
import { h, type Child, type VNode } from './dom.js';
|
|
8
|
+
import { icon } from './icon.js';
|
|
9
|
+
|
|
10
|
+
export interface PoadSelectOptionContext {
|
|
11
|
+
readonly selected: boolean;
|
|
12
|
+
readonly active: boolean;
|
|
13
|
+
readonly index: number;
|
|
14
|
+
readonly label: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface OptionListOptions<T> {
|
|
18
|
+
readonly listId: string;
|
|
19
|
+
readonly items: readonly SelectListItem<T>[];
|
|
20
|
+
readonly activeIndex: number;
|
|
21
|
+
readonly isSelected: (item: SelectOptionItem<T>) => boolean;
|
|
22
|
+
readonly multiple?: boolean;
|
|
23
|
+
readonly maxHeight: number;
|
|
24
|
+
readonly empty: Child;
|
|
25
|
+
readonly icons: IconRegistry;
|
|
26
|
+
readonly renderOption?: (option: T, context: PoadSelectOptionContext) => string | Node;
|
|
27
|
+
readonly onPick: (item: SelectOptionItem<T>) => void;
|
|
28
|
+
readonly onHover: (index: number) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function optionList<T>(o: OptionListOptions<T>): VNode {
|
|
32
|
+
const listbox = selectListboxProps(o.listId, o.multiple);
|
|
33
|
+
return h('div', {
|
|
34
|
+
class: 'poad-optlist', role: listbox.role, id: listbox.id, 'aria-multiselectable': listbox['aria-multiselectable'] ?? undefined, style: { maxHeight: `${o.maxHeight}px` },
|
|
35
|
+
}, o.items.length ? o.items.map((it): Child => {
|
|
36
|
+
if (it.kind === 'group') return h('div', { class: 'poad-optlist__group', role: 'presentation', id: it.id }, it.label);
|
|
37
|
+
const isSel = o.isSelected(it);
|
|
38
|
+
const p = selectOptionProps(it, { active: it.index === o.activeIndex, selected: isSel });
|
|
39
|
+
return h('div', {
|
|
40
|
+
id: p.id, role: p.role, class: ['poad-optlist__opt', p.classes], 'aria-selected': p['aria-selected'], 'aria-disabled': p['aria-disabled'],
|
|
41
|
+
onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: () => !it.disabled && o.onPick(it), onpointerenter: () => !it.disabled && o.onHover(it.index),
|
|
42
|
+
}, o.renderOption ? o.renderOption(it.option, { selected: isSel, active: p.classes['is-active'], index: it.index, label: it.label }) : [
|
|
43
|
+
o.multiple
|
|
44
|
+
? h('span', { class: ['poad-optlist__check', { 'is-on': isSel }] }, icon(o.icons, 'check', { size: 10, strokeWidth: 3.2 }))
|
|
45
|
+
: isSel && icon(o.icons, 'check', { size: 12, strokeWidth: 2.6, class: 'poad-optlist__tick' }),
|
|
46
|
+
it.icon && icon(o.icons, it.icon, { size: 14, class: 'poad-optlist__icon' }),
|
|
47
|
+
h('span', { class: 'poad-optlist__label' }, it.label),
|
|
48
|
+
it.hint && h('span', { class: 'poad-optlist__hint' }, it.hint),
|
|
49
|
+
]);
|
|
50
|
+
}) : h('div', { class: 'poad-optlist__empty', role: 'presentation' }, o.empty));
|
|
51
|
+
}
|
package/src/segmented.ts
CHANGED
|
@@ -22,6 +22,7 @@ export class PoadSegmentedElement extends PoadFormElement {
|
|
|
22
22
|
value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', multiple: 'boolean', allowEmpty: 'boolean', block: 'boolean',
|
|
23
23
|
size: 'string', shape: 'string', disabled: 'boolean', ariaLabel: 'string', name: 'string', required: 'boolean',
|
|
24
24
|
} as const;
|
|
25
|
+
static override functions = ['renderOption'] as const;
|
|
25
26
|
declare value?: unknown;
|
|
26
27
|
declare options?: readonly PoadSegmentOption[];
|
|
27
28
|
declare optionLabel?: string;
|
|
@@ -36,7 +37,7 @@ export class PoadSegmentedElement extends PoadFormElement {
|
|
|
36
37
|
declare name?: string;
|
|
37
38
|
declare required?: boolean;
|
|
38
39
|
/** Contenu d'une option (gabarit d'option en Angular) ; absent : icône et libellé. */
|
|
39
|
-
renderOption?: (option: PoadSegmentOption) => string | Node;
|
|
40
|
+
declare renderOption?: (option: PoadSegmentOption) => string | Node;
|
|
40
41
|
protected readonly resetProps = ['value'];
|
|
41
42
|
|
|
42
43
|
protected formValue() {
|
package/src/select.ts
CHANGED
|
@@ -15,24 +15,20 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {
|
|
17
17
|
FOCUS_AUTOFOCUS_ATTR, SELECT_INITIAL, SELECT_PLACEMENTS, SHEET_MOBILE_QUERY, selectEmptyMessage, selectEquals, selectFallbackLabel, selectFilterProps,
|
|
18
|
-
selectFindOption, selectItems,
|
|
18
|
+
selectFindOption, selectItems, selectRootClasses, selectScrollTop, selectSheetTitle, selectTransition,
|
|
19
19
|
selectTriggerProps, selectUseSheet, selectVisibleItems,
|
|
20
20
|
type SelectContext, type SelectEffect, type SelectEvent, type SelectMobileMode, type SelectState,
|
|
21
21
|
} from '@poadio/ui-core';
|
|
22
|
-
import { h
|
|
22
|
+
import { h } from './dom.js';
|
|
23
23
|
import { PoadFormElement } from './element.js';
|
|
24
24
|
import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
|
|
25
25
|
import { icon } from './icon.js';
|
|
26
|
+
import { optionList, type PoadSelectOptionContext } from './option-list.js';
|
|
26
27
|
|
|
27
28
|
/** Attribut « focus initial » du piège à focus de la feuille (ui-core). */
|
|
28
29
|
const autofocus = (on: boolean) => (on ? { [FOCUS_AUTOFOCUS_ATTR]: '' } : {});
|
|
29
30
|
|
|
30
|
-
export
|
|
31
|
-
readonly selected: boolean;
|
|
32
|
-
readonly active: boolean;
|
|
33
|
-
readonly index: number;
|
|
34
|
-
readonly label: string;
|
|
35
|
-
}
|
|
31
|
+
export type { PoadSelectOptionContext };
|
|
36
32
|
|
|
37
33
|
export class PoadSelectElement extends PoadFormElement {
|
|
38
34
|
static override props = {
|
|
@@ -42,6 +38,7 @@ export class PoadSelectElement extends PoadFormElement {
|
|
|
42
38
|
size: 'string', invalid: 'boolean', disabled: 'boolean', readonly: 'boolean', panelMaxHeight: 'number', ariaLabel: 'string', mobile: 'string',
|
|
43
39
|
sheetTitle: 'string', name: 'string', required: 'boolean',
|
|
44
40
|
} as const;
|
|
41
|
+
static override functions = ['compareWith', 'renderOption', 'renderValue', 'renderEmpty'] as const;
|
|
45
42
|
declare value?: unknown;
|
|
46
43
|
declare options?: readonly unknown[];
|
|
47
44
|
declare optionLabel?: string;
|
|
@@ -72,11 +69,11 @@ export class PoadSelectElement extends PoadFormElement {
|
|
|
72
69
|
declare name?: string;
|
|
73
70
|
declare required?: boolean;
|
|
74
71
|
/** Comparaison de valeurs (objets). Défaut : `data-key`, puis `===`. */
|
|
75
|
-
compareWith?: (a: unknown, b: unknown) => boolean;
|
|
72
|
+
declare compareWith?: (a: unknown, b: unknown) => boolean;
|
|
76
73
|
/** Contenu d'une option, de la valeur affichée, de la liste vide (gabarits `poadSelectItem` / `Selected` / `Empty`). */
|
|
77
|
-
renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
|
|
78
|
-
renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
|
|
79
|
-
renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
|
|
74
|
+
declare renderOption?: (option: unknown, context: PoadSelectOptionContext) => string | Node;
|
|
75
|
+
declare renderValue?: (option: unknown, context: { readonly label: string }) => string | Node;
|
|
76
|
+
declare renderEmpty?: (context: { readonly filtered: boolean; readonly query: string }) => string | Node;
|
|
80
77
|
protected readonly resetProps = ['value'];
|
|
81
78
|
|
|
82
79
|
private state: SelectState = SELECT_INITIAL;
|
|
@@ -180,24 +177,11 @@ export class PoadSelectElement extends PoadFormElement {
|
|
|
180
177
|
const visible = selectVisibleItems(s, c);
|
|
181
178
|
const filtered = !!s.query;
|
|
182
179
|
const root = selectRootClasses({ open: s.open, disabled: this.inactive, readonly: this.readonly, invalid: this.invalid, focused: this.focused, hasValue: this.hasValue, size: this.size ?? 'md' });
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const o = selectOptionProps(it, { active: it.index === s.activeIndex, selected: isSel });
|
|
189
|
-
return h('div', {
|
|
190
|
-
id: o.id, role: o.role, class: ['poad-optlist__opt', o.classes], 'aria-selected': o['aria-selected'], 'aria-disabled': o['aria-disabled'],
|
|
191
|
-
onpointerdown: (e: PointerEvent) => e.preventDefault(), onclick: () => !it.disabled && this.send({ type: 'pick', item: it }),
|
|
192
|
-
onpointerenter: () => !it.disabled && this.send({ type: 'hover', index: it.index }),
|
|
193
|
-
}, this.renderOption ? this.renderOption(it.option, { selected: isSel, active: o.classes['is-active'], index: it.index, label: it.label }) : [
|
|
194
|
-
isSel && icon(registry, 'check', { size: 12, strokeWidth: 2.6, class: 'poad-optlist__tick' }),
|
|
195
|
-
it.icon && icon(registry, it.icon, { size: 14, class: 'poad-optlist__icon' }),
|
|
196
|
-
h('span', { class: 'poad-optlist__label' }, it.label),
|
|
197
|
-
it.hint && h('span', { class: 'poad-optlist__hint' }, it.hint),
|
|
198
|
-
]);
|
|
199
|
-
}) : h('div', { class: 'poad-optlist__empty', role: 'presentation' },
|
|
200
|
-
this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered))));
|
|
180
|
+
const list = optionList({
|
|
181
|
+
listId, items: visible, activeIndex: s.activeIndex, isSelected: c.isSelected, maxHeight: this.panelMaxHeight ?? 260, icons: registry, renderOption: this.renderOption,
|
|
182
|
+
onPick: (item) => this.send({ type: 'pick', item }), onHover: (index) => this.send({ type: 'hover', index }),
|
|
183
|
+
empty: this.renderEmpty ? this.renderEmpty({ filtered, query: s.query }) : text(filtered ? this.emptyFilterMessage : this.emptyMessage, selectEmptyMessage(filtered)),
|
|
184
|
+
});
|
|
201
185
|
const f = selectFilterProps(s, c, { listId });
|
|
202
186
|
const panel = h('div', {
|
|
203
187
|
class: ['poad-select__panel', { 'is-sheet': this.inSheet }], style: this.inSheet ? undefined : { minWidth: `${this.triggerWidth}px` },
|
package/src/services.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Préfixe des éléments que créent les services (`poadConfirm`, `poadToast`) : celui du premier `defineElements()`,
|
|
3
|
+
* sinon `poad`. Interne.
|
|
4
|
+
*/
|
|
5
|
+
let prefix: string | null = null;
|
|
6
|
+
|
|
7
|
+
export function noteDefinedPrefix(p: string): void {
|
|
8
|
+
prefix ??= p;
|
|
9
|
+
}
|
|
10
|
+
export const servicePrefix = (): string => prefix ?? 'poad';
|
package/src/slider.ts
CHANGED
|
@@ -23,6 +23,7 @@ export class PoadSliderElement extends PoadFormElement {
|
|
|
23
23
|
marks: 'json', showTicks: 'boolean', disabled: 'boolean', readonly: 'boolean', invalid: 'boolean', size: 'string', severity: 'string', label: 'string',
|
|
24
24
|
ariaLabel: 'string', name: 'string',
|
|
25
25
|
} as const;
|
|
26
|
+
static override functions = ['formatValue'] as const;
|
|
26
27
|
declare value?: SliderValue | null;
|
|
27
28
|
declare min?: number;
|
|
28
29
|
declare max?: number;
|
|
@@ -42,7 +43,7 @@ export class PoadSliderElement extends PoadFormElement {
|
|
|
42
43
|
declare ariaLabel: string | null;
|
|
43
44
|
declare name?: string;
|
|
44
45
|
/** Texte d'une valeur (bulle, graduations, `aria-valuetext`). */
|
|
45
|
-
formatValue?: (v: number) => string;
|
|
46
|
+
declare formatValue?: (v: number) => string;
|
|
46
47
|
protected readonly resetProps = ['value'];
|
|
47
48
|
private draft: SliderValue | null = null;
|
|
48
49
|
private dragging: number | null = null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-split-button label="Save" icon="save" items='[{"label":"Save and close"}]'></poad-split-button>
|
|
3
|
+
*
|
|
4
|
+
* Bouton principal + bouton chevron accolé qui ouvre un menu flottant ancré sur lui (le même que `<poad-menu>`).
|
|
5
|
+
* Mêmes options d'apparence que `<poad-button>` (`severity`, `variant`, `size`, `loading`, `disabled`). Attributs du
|
|
6
|
+
* chevron (`aria-haspopup="menu"`, `aria-expanded`) et tailles d'icône : `menu` de @poadio/ui-core. Évènements :
|
|
7
|
+
* `press` (bouton principal), `itemclick` (detail `{ item, originalEvent }`), `openchange` (detail : ouvert ou non).
|
|
8
|
+
* Le contenu de l'élément suit le libellé dans le bouton principal. Même DOM que `poad-split-button` d'ui-angular.
|
|
9
|
+
* Styles : `menu.css`, `button.css` (et ceux du menu).
|
|
10
|
+
*/
|
|
11
|
+
import { buttonClasses, splitButtonIconSize, splitButtonToggleProps, type ButtonSeverity, type ButtonSize, type ButtonVariant } from '@poadio/ui-core';
|
|
12
|
+
import { button } from './button.js';
|
|
13
|
+
import { h } from './dom.js';
|
|
14
|
+
import { PoadElement } from './element.js';
|
|
15
|
+
import { icon } from './icon.js';
|
|
16
|
+
import { MenuController, type PoadMenuItem } from './menu.js';
|
|
17
|
+
|
|
18
|
+
export class PoadSplitButtonElement extends PoadElement {
|
|
19
|
+
static override props = {
|
|
20
|
+
label: 'string', icon: 'string', items: 'json', severity: 'string', variant: 'string', size: 'string', loading: 'boolean', disabled: 'boolean',
|
|
21
|
+
dropdownAriaLabel: 'string', menuMinWidth: 'number', mobile: 'string',
|
|
22
|
+
} as const;
|
|
23
|
+
declare label?: string;
|
|
24
|
+
declare icon?: string;
|
|
25
|
+
declare items?: readonly PoadMenuItem[];
|
|
26
|
+
declare severity?: ButtonSeverity;
|
|
27
|
+
declare variant?: ButtonVariant;
|
|
28
|
+
declare size?: ButtonSize;
|
|
29
|
+
declare loading?: boolean;
|
|
30
|
+
declare disabled?: boolean;
|
|
31
|
+
declare dropdownAriaLabel?: string;
|
|
32
|
+
declare menuMinWidth?: number;
|
|
33
|
+
declare mobile?: 'auto' | 'sheet' | 'popover';
|
|
34
|
+
private open = false;
|
|
35
|
+
private toggleEl: HTMLElement | null = null;
|
|
36
|
+
private readonly menu = new MenuController(this);
|
|
37
|
+
|
|
38
|
+
private setOpen(next: boolean) {
|
|
39
|
+
if (next === this.open) return;
|
|
40
|
+
this.open = next;
|
|
41
|
+
this.update();
|
|
42
|
+
this.emit('openchange', next);
|
|
43
|
+
}
|
|
44
|
+
override disconnectedCallback(): void {
|
|
45
|
+
super.disconnectedCallback();
|
|
46
|
+
this.open = false;
|
|
47
|
+
this.menu.dispose();
|
|
48
|
+
}
|
|
49
|
+
protected render() {
|
|
50
|
+
const { t, text } = this.i18n();
|
|
51
|
+
const registry = this.icons();
|
|
52
|
+
const size = this.size ?? 'md';
|
|
53
|
+
const iconSize = splitButtonIconSize(size);
|
|
54
|
+
const tg = splitButtonToggleProps(this.open, this.disabled, this.loading);
|
|
55
|
+
const look = { severity: this.severity ?? 'primary', variant: this.variant ?? 'solid', size } as const;
|
|
56
|
+
const main = { ...look, loading: this.loading, disabled: this.disabled };
|
|
57
|
+
const toggle = { ...look, disabled: tg.disabled, icon: true };
|
|
58
|
+
return h('div', { class: ['poad-split-button', { 'is-disabled': !!this.disabled }] }, [
|
|
59
|
+
button(main, { type: 'button', class: `${buttonClasses(main)} poad-split-button__main`, onclick: () => this.emit('press') },
|
|
60
|
+
[this.icon && icon(registry, this.icon, { size: iconSize }), this.label && h('span', {}, this.label), this.content]),
|
|
61
|
+
button(toggle, {
|
|
62
|
+
type: 'button', class: `${buttonClasses(toggle)} poad-split-button__toggle`, ref: (el: HTMLElement) => { this.toggleEl = el; },
|
|
63
|
+
'aria-label': text(this.dropdownAriaLabel, 'nav.moreActions'), 'aria-haspopup': tg['aria-haspopup'], 'aria-expanded': tg['aria-expanded'],
|
|
64
|
+
onclick: () => this.setOpen(!this.open),
|
|
65
|
+
}, icon(registry, 'chevron-down', { size: iconSize - 2 })),
|
|
66
|
+
this.menu.render({
|
|
67
|
+
id: `${this.uid}-menu`, items: this.items ?? [], open: this.open, popup: true, anchor: () => this.toggleEl, contextual: false, minWidth: this.menuMinWidth,
|
|
68
|
+
mobile: this.mobile, closeLabel: t('common.close'), icons: registry, setOpen: (open) => this.setOpen(open),
|
|
69
|
+
onItemClick: (item, originalEvent) => this.emit('itemclick', { item, originalEvent }),
|
|
70
|
+
}),
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
protected override updated(): void {
|
|
74
|
+
this.menu.sync();
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/stepper.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-stepper active-index="0" linear aria-label="Deployment">
|
|
3
|
+
* <poad-step label="Domain" description="DNS" completed>…contenu…</poad-step>
|
|
4
|
+
* <poad-step label="Certificate" optional>…</poad-step>
|
|
5
|
+
* <poad-step label="Go live"></poad-step>
|
|
6
|
+
* </poad-stepper>
|
|
7
|
+
*
|
|
8
|
+
* Étapes : machine `stepper` de @poadio/ui-core (état affiché de chaque étape, étapes atteignables en `linear`,
|
|
9
|
+
* `aria-current="step"`). Les `<poad-step>` sont des DÉCLARATIONS (leur contenu va dans le panneau de l'étape
|
|
10
|
+
* courante). Propriété `activeIndex` ; la page avance en la changeant (ses boutons « suivant » sont les siens).
|
|
11
|
+
* Évènements : `change` (detail : le rang de l'étape où l'utilisateur va par un clic), `stepclick` (detail : le rang
|
|
12
|
+
* cliqué, même non atteignable). Même DOM, mêmes classes, même ARIA que `poad-stepper` d'ui-angular. Style :
|
|
13
|
+
* `@poadio/ui-core/stepper.css` (et `icon.css`).
|
|
14
|
+
*/
|
|
15
|
+
import { stepperGoTo, stepperItemProps, stepperRootClasses, type StepItem, type StepState } 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
|
+
|
|
21
|
+
export interface StepData {
|
|
22
|
+
readonly label?: string;
|
|
23
|
+
readonly description?: string;
|
|
24
|
+
readonly icon?: string;
|
|
25
|
+
readonly optional?: boolean;
|
|
26
|
+
readonly disabled?: boolean;
|
|
27
|
+
readonly completed?: boolean;
|
|
28
|
+
readonly state?: StepState | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Déclaration d'une étape dans un `<poad-stepper>` ; ses enfants sont son contenu. */
|
|
32
|
+
export class PoadStepElement extends PoadDeclarationElement {
|
|
33
|
+
static override props = {
|
|
34
|
+
label: 'string', description: 'string', icon: 'string', optional: 'boolean', disabled: 'boolean', completed: 'boolean', state: 'string',
|
|
35
|
+
} as const;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class PoadStepperElement extends PoadElement {
|
|
39
|
+
static override props = {
|
|
40
|
+
activeIndex: 'number', linear: 'boolean', clickable: 'boolean', orientation: 'string', size: 'string', ariaLabel: 'string',
|
|
41
|
+
} as const;
|
|
42
|
+
declare activeIndex?: number;
|
|
43
|
+
declare linear?: boolean;
|
|
44
|
+
declare clickable?: boolean;
|
|
45
|
+
declare orientation?: 'horizontal' | 'vertical';
|
|
46
|
+
declare size?: 'sm' | 'md';
|
|
47
|
+
declare ariaLabel: string | null;
|
|
48
|
+
|
|
49
|
+
protected render() {
|
|
50
|
+
const { t } = this.i18n();
|
|
51
|
+
const registry = this.icons();
|
|
52
|
+
const steps = declarations<StepData>(this, this.content, this.tag('step'), PoadStepElement.props);
|
|
53
|
+
const items: StepItem[] = steps.map(({ data: s }) => ({ disabled: s.disabled, completed: s.completed, optional: s.optional, state: s.state }));
|
|
54
|
+
const active = this.activeIndex ?? 0;
|
|
55
|
+
const clickable = this.clickable !== false;
|
|
56
|
+
const vertical = this.orientation === 'vertical';
|
|
57
|
+
const click = (i: number) => {
|
|
58
|
+
this.emit('stepclick', i);
|
|
59
|
+
if (!clickable) return;
|
|
60
|
+
const to = stepperGoTo(items, active, i, this.linear);
|
|
61
|
+
if (to === null) return;
|
|
62
|
+
this.activeIndex = to;
|
|
63
|
+
this.emit('change', to);
|
|
64
|
+
};
|
|
65
|
+
return h('div', { class: ['poad-stepper', stepperRootClasses({ orientation: this.orientation, size: this.size })] }, [
|
|
66
|
+
h('ol', { class: 'poad-stepper__list', 'aria-label': this.ariaLabel || undefined }, steps.map(({ data: s, content }, i) => {
|
|
67
|
+
const a = stepperItemProps(items, i, active, { linear: this.linear, clickable });
|
|
68
|
+
return h('li', { class: ['poad-stepper__item', a.classes], 'data-state': a.state }, [
|
|
69
|
+
h('button', { type: 'button', class: 'poad-stepper__btn', disabled: a.disabled, 'aria-current': a['aria-current'], onclick: () => click(i) }, [
|
|
70
|
+
h('span', { class: 'poad-stepper__dot', 'aria-hidden': 'true' },
|
|
71
|
+
a.state === 'done' ? icon(registry, 'check', { size: 11, strokeWidth: 3 })
|
|
72
|
+
: a.state === 'error' ? icon(registry, 'x', { size: 11, strokeWidth: 3 })
|
|
73
|
+
: s.icon ? icon(registry, s.icon, { size: 12 }) : String(i + 1)),
|
|
74
|
+
h('span', { class: 'poad-stepper__txt' }, [
|
|
75
|
+
h('span', { class: 'poad-stepper__label' }, [s.label ?? '', s.optional && h('small', {}, ` ${t('nav.optional')}`)]),
|
|
76
|
+
s.description && h('span', { class: 'poad-stepper__desc' }, s.description),
|
|
77
|
+
]),
|
|
78
|
+
]),
|
|
79
|
+
i < steps.length - 1 && h('span', { class: 'poad-stepper__line', 'aria-hidden': 'true' }),
|
|
80
|
+
vertical && i === active && h('div', { class: 'poad-stepper__panel' }, content),
|
|
81
|
+
]);
|
|
82
|
+
})),
|
|
83
|
+
!vertical && steps[active] && h('div', { class: 'poad-stepper__panel' }, steps[active]!.content),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
}
|