@poadio/ui-elements 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/LICENSE +22 -0
- package/README.md +151 -2
- package/dist/accordion.d.ts +31 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +67 -0
- package/dist/accordion.js.map +1 -0
- package/dist/avatar.d.ts +56 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +49 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +19 -0
- package/dist/badge.js.map +1 -0
- package/dist/button-group.d.ts +43 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +63 -0
- package/dist/button-group.js.map +1 -0
- package/dist/button.d.ts +44 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +29 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.d.ts +32 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +46 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/chip.d.ts +37 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +46 -0
- package/dist/chip.js.map +1 -0
- package/dist/colorpicker.d.ts +63 -0
- package/dist/colorpicker.d.ts.map +1 -0
- package/dist/colorpicker.js +164 -0
- package/dist/colorpicker.js.map +1 -0
- package/dist/combo.d.ts +88 -0
- package/dist/combo.d.ts.map +1 -0
- package/dist/combo.js +238 -0
- package/dist/combo.js.map +1 -0
- package/dist/confirm.d.ts +35 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +94 -0
- package/dist/confirm.js.map +1 -0
- package/dist/datepicker.d.ts +146 -0
- package/dist/datepicker.d.ts.map +1 -0
- package/dist/datepicker.js +468 -0
- package/dist/datepicker.js.map +1 -0
- package/dist/declaration.d.ts +25 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +35 -0
- package/dist/declaration.js.map +1 -0
- package/dist/define.d.ts +2 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/dialog.d.ts +137 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +174 -0
- package/dist/dialog.js.map +1 -0
- package/dist/divider.d.ts +15 -0
- package/dist/divider.d.ts.map +1 -0
- package/dist/divider.js +17 -0
- package/dist/divider.js.map +1 -0
- package/dist/dom.d.ts +20 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +99 -0
- package/dist/dom.js.map +1 -0
- package/dist/element.d.ts +88 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +169 -0
- package/dist/element.js.map +1 -0
- package/dist/field.d.ts +50 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +90 -0
- package/dist/field.js.map +1 -0
- package/dist/floating.d.ts +134 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +311 -0
- package/dist/floating.js.map +1 -0
- package/dist/i18n.d.ts +32 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +49 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icon.d.ts +37 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +32 -0
- package/dist/icon.js.map +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/inplace.d.ts +25 -0
- package/dist/inplace.d.ts.map +1 -0
- package/dist/inplace.js +61 -0
- package/dist/inplace.js.map +1 -0
- package/dist/mask.d.ts +76 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +150 -0
- package/dist/mask.js.map +1 -0
- package/dist/menu.d.ts +121 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +245 -0
- package/dist/menu.js.map +1 -0
- package/dist/message.d.ts +31 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +28 -0
- package/dist/message.js.map +1 -0
- package/dist/meter.d.ts +43 -0
- package/dist/meter.d.ts.map +1 -0
- package/dist/meter.js +46 -0
- package/dist/meter.js.map +1 -0
- package/dist/multiselect.d.ts +133 -0
- package/dist/multiselect.d.ts.map +1 -0
- package/dist/multiselect.js +230 -0
- package/dist/multiselect.js.map +1 -0
- package/dist/number.d.ts +63 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/number.js +72 -0
- package/dist/number.js.map +1 -0
- package/dist/option-list.d.ts +28 -0
- package/dist/option-list.d.ts.map +1 -0
- package/dist/option-list.js +31 -0
- package/dist/option-list.js.map +1 -0
- package/dist/password.d.ts +30 -0
- package/dist/password.d.ts.map +1 -0
- package/dist/password.js +47 -0
- package/dist/password.js.map +1 -0
- package/dist/popover.d.ts +62 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +109 -0
- package/dist/popover.js.map +1 -0
- package/dist/progress.d.ts +48 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +42 -0
- package/dist/progress.js.map +1 -0
- package/dist/radio.d.ts +44 -0
- package/dist/radio.d.ts.map +1 -0
- package/dist/radio.js +70 -0
- package/dist/radio.js.map +1 -0
- package/dist/rating.d.ts +52 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +77 -0
- package/dist/rating.js.map +1 -0
- package/dist/segmented.d.ts +52 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +67 -0
- package/dist/segmented.js.map +1 -0
- package/dist/select.d.ts +119 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +185 -0
- package/dist/select.js.map +1 -0
- package/dist/services.d.ts +3 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +10 -0
- package/dist/services.js.map +1 -0
- package/dist/skeleton.d.ts +19 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +16 -0
- package/dist/skeleton.js.map +1 -0
- package/dist/slider.d.ts +77 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +136 -0
- package/dist/slider.js.map +1 -0
- package/dist/split-button.d.ts +47 -0
- package/dist/split-button.d.ts.map +1 -0
- package/dist/split-button.js +64 -0
- package/dist/split-button.js.map +1 -0
- package/dist/stepper.d.ts +56 -0
- package/dist/stepper.d.ts.map +1 -0
- package/dist/stepper.js +69 -0
- package/dist/stepper.js.map +1 -0
- package/dist/switch.d.ts +32 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +42 -0
- package/dist/switch.js.map +1 -0
- package/dist/tabs.d.ts +62 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +118 -0
- package/dist/tabs.js.map +1 -0
- package/dist/tag.d.ts +27 -0
- package/dist/tag.d.ts.map +1 -0
- package/dist/tag.js +21 -0
- package/dist/tag.js.map +1 -0
- package/dist/toast.d.ts +79 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +176 -0
- package/dist/toast.js.map +1 -0
- package/dist/toggle-button.d.ts +46 -0
- package/dist/toggle-button.d.ts.map +1 -0
- package/dist/toggle-button.js +39 -0
- package/dist/toggle-button.js.map +1 -0
- package/dist/tooltip.d.ts +48 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +105 -0
- package/dist/tooltip.js.map +1 -0
- package/package.json +66 -4
- package/src/accordion.ts +80 -0
- package/src/avatar.ts +78 -0
- package/src/badge.ts +26 -0
- package/src/button-group.ts +66 -0
- package/src/button.ts +44 -0
- package/src/checkbox.ts +57 -0
- package/src/chip.ts +54 -0
- package/src/colorpicker.ts +173 -0
- package/src/combo.ts +220 -0
- package/src/confirm.ts +106 -0
- package/src/datepicker.ts +413 -0
- package/src/declaration.ts +37 -0
- package/src/define.ts +4 -0
- package/src/dialog.ts +217 -0
- package/src/divider.ts +22 -0
- package/src/dom.ts +102 -0
- package/src/element.ts +187 -0
- package/src/field.ts +91 -0
- package/src/floating.ts +316 -0
- package/src/i18n.ts +61 -0
- package/src/icon.ts +42 -0
- package/src/index.ts +128 -0
- package/src/inplace.ts +69 -0
- package/src/mask.ts +170 -0
- package/src/menu.ts +281 -0
- package/src/message.ts +37 -0
- package/src/meter.ts +64 -0
- package/src/multiselect.ts +273 -0
- package/src/number.ts +94 -0
- package/src/option-list.ts +51 -0
- package/src/password.ts +59 -0
- package/src/popover.ts +118 -0
- package/src/progress.ts +62 -0
- package/src/radio.ts +84 -0
- package/src/rating.ts +91 -0
- package/src/segmented.ts +82 -0
- package/src/select.ts +226 -0
- package/src/services.ts +10 -0
- package/src/skeleton.ts +24 -0
- package/src/slider.ts +145 -0
- package/src/split-button.ts +76 -0
- package/src/stepper.ts +86 -0
- package/src/switch.ts +52 -0
- package/src/tabs.ts +129 -0
- package/src/tag.ts +29 -0
- package/src/toast.ts +203 -0
- package/src/toggle-button.ts +52 -0
- package/src/tooltip.ts +101 -0
package/src/progress.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-progress value="62" label="Build" show-value></poad-progress> <poad-progress indeterminate aria-label="Upload"></poad-progress>
|
|
3
|
+
* <poad-spinner size="24"></poad-spinner> (nom accessible : catalogue `display.loading`)
|
|
4
|
+
*
|
|
5
|
+
* Barre de progression et indicateur de chargement : classes, pourcentage et attributs de @poadio/ui-core
|
|
6
|
+
* (`progressClasses`, `progressTrackProps`, `spinnerClasses`) — même DOM que `poad-progress` / `poad-spinner`
|
|
7
|
+
* d'ui-angular. Style : `@poadio/ui-core/progress.css`.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
progressBarWidth, progressClasses, progressPercent, progressShowHead, progressShowValue, progressTrackProps, spinnerClasses,
|
|
11
|
+
type ProgressSeverity, type SpinnerSeverity,
|
|
12
|
+
} from '@poadio/ui-core';
|
|
13
|
+
import { h } from './dom.js';
|
|
14
|
+
import { PoadElement } from './element.js';
|
|
15
|
+
|
|
16
|
+
export class PoadProgressElement extends PoadElement {
|
|
17
|
+
static override props = {
|
|
18
|
+
value: 'number', max: 'number', indeterminate: 'boolean', severity: 'string', size: 'string', showValue: 'boolean', striped: 'boolean',
|
|
19
|
+
label: 'string', ariaLabel: 'string',
|
|
20
|
+
} as const;
|
|
21
|
+
declare value?: number;
|
|
22
|
+
declare max?: number;
|
|
23
|
+
declare indeterminate?: boolean;
|
|
24
|
+
declare severity?: ProgressSeverity;
|
|
25
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
26
|
+
declare showValue?: boolean;
|
|
27
|
+
declare striped?: boolean;
|
|
28
|
+
declare label?: string;
|
|
29
|
+
declare ariaLabel: string | null;
|
|
30
|
+
|
|
31
|
+
protected render() {
|
|
32
|
+
const track = progressTrackProps(this);
|
|
33
|
+
const width = progressBarWidth(this);
|
|
34
|
+
return h('div', { class: progressClasses(this) }, [
|
|
35
|
+
progressShowHead(this) && h('div', { class: 'poad-progress__head' }, [
|
|
36
|
+
h('span', { class: 'poad-progress__label' }, this.label),
|
|
37
|
+
progressShowValue(this) && h('span', { class: 'poad-progress__val' }, `${progressPercent(this.value, this.max)} %`),
|
|
38
|
+
]),
|
|
39
|
+
h('div', { class: 'poad-progress__track', ...track }, h('div', { class: 'poad-progress__bar', style: width ? { width } : undefined })),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class PoadSpinnerElement extends PoadElement {
|
|
45
|
+
static override props = { size: 'number', strokeWidth: 'number', severity: 'string', ariaLabel: 'string' } as const;
|
|
46
|
+
declare size?: number;
|
|
47
|
+
declare strokeWidth?: number;
|
|
48
|
+
declare severity?: SpinnerSeverity;
|
|
49
|
+
/** Nom accessible ; absent : message `display.loading` du catalogue. */
|
|
50
|
+
declare ariaLabel: string | null;
|
|
51
|
+
|
|
52
|
+
protected render() {
|
|
53
|
+
const size = this.size ?? 24, stroke = this.strokeWidth ?? 2.5;
|
|
54
|
+
return h('span', {
|
|
55
|
+
class: spinnerClasses(this.severity), role: 'status', 'aria-label': this.i18n().text(this.ariaLabel, 'display.loading'),
|
|
56
|
+
style: { width: `${size}px`, height: `${size}px` },
|
|
57
|
+
}, h('svg', { viewBox: '0 0 24 24', fill: 'none' }, [
|
|
58
|
+
h('circle', { cx: 12, cy: 12, r: 10, stroke: 'currentColor', 'stroke-width': stroke, 'stroke-opacity': '.2' }),
|
|
59
|
+
h('path', { d: 'M22 12a10 10 0 0 0-10-10', stroke: 'currentColor', 'stroke-width': stroke, 'stroke-linecap': 'round' }),
|
|
60
|
+
]));
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/radio.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-radio-group name="pooling" value="transaction" aria-label="Pooling">
|
|
3
|
+
* <poad-radio value="transaction" label="Transaction"></poad-radio>
|
|
4
|
+
* <poad-radio value="session" label="Session" hint="One connection per client" disabled></poad-radio>
|
|
5
|
+
* </poad-radio-group>
|
|
6
|
+
*
|
|
7
|
+
* Machine `radio` de @poadio/ui-core (choix au clic, flèches en boucle sur les radios actifs, « roving tabindex ») ;
|
|
8
|
+
* même DOM, mêmes classes, même ARIA que `poad-radio-group` / `poad-radio` d'ui-angular. Les `<poad-radio>` sont des
|
|
9
|
+
* DÉCLARATIONS lues par le groupe (attributs `value`, `label`, `hint`, `disabled`), qui dessine les radios directement
|
|
10
|
+
* sous sa racine `role="radiogroup"` ; propriété `options` pour les donner en données. Valeur : propriété `value` du
|
|
11
|
+
* groupe (chaîne), évènements `input` / `change`. Formulaire : `name`, `required`. Style : `radio.css`.
|
|
12
|
+
*/
|
|
13
|
+
import { radioControlProps, radioGroupClasses, radioKeydown, radioLabelProps, radioRootClasses, radioSelect, type RadioGroupState } from '@poadio/ui-core';
|
|
14
|
+
import { h } from './dom.js';
|
|
15
|
+
import { PoadElement, PoadFormElement, declared } from './element.js';
|
|
16
|
+
|
|
17
|
+
export interface RadioOption {
|
|
18
|
+
readonly value: string;
|
|
19
|
+
readonly label?: string;
|
|
20
|
+
readonly hint?: string;
|
|
21
|
+
readonly disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Déclaration d'un radio dans un `<poad-radio-group>` : rien à afficher par elle-même. */
|
|
25
|
+
export class PoadRadioElement extends PoadElement {
|
|
26
|
+
static override props = { value: 'string', label: 'string', hint: 'string', disabled: 'boolean' } as const;
|
|
27
|
+
protected render() {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class PoadRadioGroupElement extends PoadFormElement {
|
|
33
|
+
static override props = {
|
|
34
|
+
value: 'string', options: 'json', disabled: 'boolean', orientation: 'string', ariaLabel: 'string', name: 'string', required: 'boolean',
|
|
35
|
+
} as const;
|
|
36
|
+
declare value?: string | null;
|
|
37
|
+
/** Radios en données ; absent : les `<poad-radio>` écrits dans le groupe. */
|
|
38
|
+
declare options?: readonly RadioOption[];
|
|
39
|
+
declare disabled?: boolean;
|
|
40
|
+
declare orientation?: 'vertical' | 'horizontal';
|
|
41
|
+
declare ariaLabel: string | null;
|
|
42
|
+
declare name?: string;
|
|
43
|
+
declare required?: boolean;
|
|
44
|
+
protected readonly resetProps = ['value'];
|
|
45
|
+
|
|
46
|
+
private get items(): readonly RadioOption[] {
|
|
47
|
+
const tag = this.tag('radio');
|
|
48
|
+
return this.options ?? (this.content ?? []).filter((n): n is Element => n instanceof Element && n.localName === tag)
|
|
49
|
+
.map((el) => declared<RadioOption>(el, PoadRadioElement.props));
|
|
50
|
+
}
|
|
51
|
+
protected formValue() {
|
|
52
|
+
return { value: this.value ?? null, missing: this.value == null };
|
|
53
|
+
}
|
|
54
|
+
protected render() {
|
|
55
|
+
const items = this.items.map((o) => ({ ...o, disabled: !!o.disabled }));
|
|
56
|
+
const state: RadioGroupState<unknown> = { value: this.value ?? null, disabled: this.inactive };
|
|
57
|
+
const select = (value: string) => {
|
|
58
|
+
if (state.disabled || value === this.value) return;
|
|
59
|
+
this.value = value;
|
|
60
|
+
this.changed(value);
|
|
61
|
+
};
|
|
62
|
+
const onkeydown = (e: KeyboardEvent) => {
|
|
63
|
+
const next = radioKeydown(state, items, e.key);
|
|
64
|
+
if (!next) return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
this.querySelectorAll<HTMLElement>('[role="radio"]')[next.index]?.focus();
|
|
67
|
+
select(String(next.value));
|
|
68
|
+
};
|
|
69
|
+
return h('div', {
|
|
70
|
+
class: ['poad-radio-group', radioGroupClasses({ orientation: this.orientation, disabled: state.disabled })], role: 'radiogroup', 'aria-label': this.ariaLabel || undefined, onkeydown,
|
|
71
|
+
}, items.map((item, i) => {
|
|
72
|
+
const element = { id: `${this.uid}-${i}`, label: item.label };
|
|
73
|
+
const control = radioControlProps(state, items, i, element);
|
|
74
|
+
const label = radioLabelProps(element);
|
|
75
|
+
return h('span', { class: ['poad-radio', radioRootClasses(state, item)] }, [
|
|
76
|
+
h('button', {
|
|
77
|
+
type: 'button', role: control.role, id: control.id, 'aria-checked': control['aria-checked'], tabindex: control.tabindex, disabled: control.disabled,
|
|
78
|
+
'aria-labelledby': control['aria-labelledby'], onclick: () => { if (radioSelect(state, item)) select(item.value); },
|
|
79
|
+
}, h('span', { class: 'poad-radio__dot' })),
|
|
80
|
+
label && h('label', { id: label.id, for: label.for, class: 'poad-radio__label' }, [item.label ?? '', item.hint && h('small', item.hint)]),
|
|
81
|
+
]);
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/rating.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-rating name="note" value="3" max="5" allow-half show-value></poad-rating>
|
|
3
|
+
*
|
|
4
|
+
* Machine `rating` de @poadio/ui-core (← → ↑ ↓ ± 1 ou ½ avec miroir de droite à gauche, Home / End / Suppr, survol,
|
|
5
|
+
* demi-étoile, remise à zéro `clearable`, attributs `slider`) ; même DOM, mêmes classes, même ARIA que `poad-rating`
|
|
6
|
+
* d'ui-angular. Propriété `value` ; évènements `input` / `change` (detail : la note). Formulaire : `name`, `required`
|
|
7
|
+
* (une note de 0 manque). Nom par défaut : catalogue `field.rating`. Style : `rating.css`.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
RATING_KEYS, elementIsRtl, ratingColor, ratingControlProps, ratingFill, ratingFirstHalf, ratingIconSize, ratingInteractive, ratingRootClasses,
|
|
11
|
+
ratingShown, ratingStarClasses, ratingStars, ratingText, ratingTransition, type RatingEvent, type RatingSeverity, type RatingSize, type RatingState,
|
|
12
|
+
} from '@poadio/ui-core';
|
|
13
|
+
import { h } from './dom.js';
|
|
14
|
+
import { PoadFormElement } from './element.js';
|
|
15
|
+
import { icon } from './icon.js';
|
|
16
|
+
|
|
17
|
+
export class PoadRatingElement extends PoadFormElement {
|
|
18
|
+
static override props = {
|
|
19
|
+
value: 'number', max: 'number', allowHalf: 'boolean', readonly: 'boolean', disabled: 'boolean', clearable: 'boolean', icon: 'string', size: 'string',
|
|
20
|
+
severity: 'string', showValue: 'boolean', ariaLabel: 'string', name: 'string', required: 'boolean',
|
|
21
|
+
} as const;
|
|
22
|
+
declare value?: number | null;
|
|
23
|
+
declare max?: number;
|
|
24
|
+
declare allowHalf?: boolean;
|
|
25
|
+
declare readonly?: boolean;
|
|
26
|
+
declare disabled?: boolean;
|
|
27
|
+
/** Cliquer la note courante la remet à 0 (défaut : oui ; `clearable="false"`). */
|
|
28
|
+
declare clearable?: boolean;
|
|
29
|
+
declare icon?: string;
|
|
30
|
+
declare size?: RatingSize;
|
|
31
|
+
declare severity?: RatingSeverity;
|
|
32
|
+
declare showValue?: boolean;
|
|
33
|
+
declare ariaLabel: string | null;
|
|
34
|
+
declare name?: string;
|
|
35
|
+
declare required?: boolean;
|
|
36
|
+
protected readonly resetProps = ['value'];
|
|
37
|
+
private hover: number | null = null;
|
|
38
|
+
|
|
39
|
+
private get options() {
|
|
40
|
+
return { max: this.max ?? 5, allowHalf: this.allowHalf, clearable: this.clearable !== false };
|
|
41
|
+
}
|
|
42
|
+
private get state(): RatingState {
|
|
43
|
+
return { value: this.value ?? 0, hover: this.hover, disabled: this.inactive, readonly: !!this.readonly };
|
|
44
|
+
}
|
|
45
|
+
private send(event: RatingEvent) {
|
|
46
|
+
const state = this.state;
|
|
47
|
+
const next = ratingTransition(state, event, this.options);
|
|
48
|
+
if (next === state) return;
|
|
49
|
+
this.hover = next.hover;
|
|
50
|
+
if (next.value !== state.value) {
|
|
51
|
+
this.value = next.value;
|
|
52
|
+
this.changed(next.value);
|
|
53
|
+
} else this.update();
|
|
54
|
+
}
|
|
55
|
+
protected formValue() {
|
|
56
|
+
return { value: this.value ? String(this.value) : null, missing: !this.value };
|
|
57
|
+
}
|
|
58
|
+
protected render() {
|
|
59
|
+
const state = this.state, options = this.options;
|
|
60
|
+
const control = ratingControlProps(state, options);
|
|
61
|
+
const px = ratingIconSize(this.size ?? 'md'), name = this.icon ?? 'star';
|
|
62
|
+
const firstHalf = (e: MouseEvent) => {
|
|
63
|
+
const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
64
|
+
return ratingFirstHalf(e.clientX - r.left, r.width, elementIsRtl(this));
|
|
65
|
+
};
|
|
66
|
+
return h('span', { class: ['poad-rating', ratingRootClasses(state, { size: this.size ?? 'md' })], style: { '--_c': ratingColor(this.severity ?? 'warning') } }, [
|
|
67
|
+
h('div', {
|
|
68
|
+
class: 'poad-rating__stars', role: control.role, tabindex: control.tabindex, 'aria-valuemin': control['aria-valuemin'], 'aria-valuemax': control['aria-valuemax'],
|
|
69
|
+
'aria-valuenow': control['aria-valuenow'], 'aria-valuetext': control['aria-valuetext'], 'aria-label': this.ariaLabel || this.i18n().t('field.rating'),
|
|
70
|
+
'aria-disabled': control['aria-disabled'], 'aria-readonly': control['aria-readonly'],
|
|
71
|
+
onkeydown: (e: KeyboardEvent) => {
|
|
72
|
+
if (!ratingInteractive(state) || !RATING_KEYS.includes(e.key)) return;
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
this.send({ type: 'keydown', key: e.key, rtl: elementIsRtl(this) });
|
|
75
|
+
},
|
|
76
|
+
onmouseleave: () => this.send({ type: 'leave' }),
|
|
77
|
+
}, ratingStars(options).map((i) => {
|
|
78
|
+
const fill = ratingFill(state, i);
|
|
79
|
+
return h('span', {
|
|
80
|
+
class: ['poad-rating__star', ratingStarClasses(fill)],
|
|
81
|
+
onmousemove: (e: MouseEvent) => this.send({ type: 'hover', index: i, firstHalf: firstHalf(e) }),
|
|
82
|
+
onclick: (e: MouseEvent) => this.send({ type: 'select', index: i, firstHalf: firstHalf(e) }),
|
|
83
|
+
}, [
|
|
84
|
+
icon(this.icons(), name, { size: px, class: 'off' }),
|
|
85
|
+
h('span', { class: 'on', style: { width: `${fill * 100}%` } }, icon(this.icons(), name, { size: px, filled: true })),
|
|
86
|
+
]);
|
|
87
|
+
})),
|
|
88
|
+
this.showValue && h('span', { class: 'poad-rating__val' }, ratingText(ratingShown(state), options)),
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/segmented.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-segmented name="view" value="t" aria-label="View" options='[{"label":"Table","value":"t"},{"label":"SQL","value":"s","icon":"code"}]'></poad-segmented>
|
|
3
|
+
* seg.multiple = true; seg.value = ['mon']; seg.renderOption = (option) => …
|
|
4
|
+
*
|
|
5
|
+
* Choix segmenté : machine `segmented` de @poadio/ui-core (choix unique ou multiple, `allow-empty`, un seul arrêt de
|
|
6
|
+
* tabulation, flèches / Début / Fin qui déplacent le focus dans le sens de lecture, Espace / Entrée qui choisissent).
|
|
7
|
+
* Même DOM, mêmes classes, même ARIA que `poad-segmented` d'ui-angular. Propriété `value` (un tableau en multiple),
|
|
8
|
+
* évènements `input` / `change`. Formulaire : `name` (une entrée par valeur choisie), `required`. Style : `segmented.css`.
|
|
9
|
+
*/
|
|
10
|
+
import { segmentedKeydown, segmentedOptionProps, segmentedPick, segmentedRootClasses, type SegmentedItem } from '@poadio/ui-core';
|
|
11
|
+
import { h } from './dom.js';
|
|
12
|
+
import { PoadFormElement } from './element.js';
|
|
13
|
+
import { icon } from './icon.js';
|
|
14
|
+
|
|
15
|
+
/** Une option : `label`, `value`, `icon`, `disabled`, `title` — ou un objet lu par `option-label` / `option-value`. */
|
|
16
|
+
export type PoadSegmentOption = { readonly label?: string; readonly value?: unknown; readonly icon?: string; readonly disabled?: boolean; readonly title?: string } & Readonly<Record<string, unknown>>;
|
|
17
|
+
|
|
18
|
+
const resolve = (o: unknown, path: string): unknown => path.split('.').reduce<unknown>((acc, k) => (acc == null ? acc : (acc as Record<string, unknown>)[k]), o);
|
|
19
|
+
|
|
20
|
+
export class PoadSegmentedElement extends PoadFormElement {
|
|
21
|
+
static override props = {
|
|
22
|
+
value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', multiple: 'boolean', allowEmpty: 'boolean', block: 'boolean',
|
|
23
|
+
size: 'string', shape: 'string', disabled: 'boolean', ariaLabel: 'string', name: 'string', required: 'boolean',
|
|
24
|
+
} as const;
|
|
25
|
+
static override functions = ['renderOption'] as const;
|
|
26
|
+
declare value?: unknown;
|
|
27
|
+
declare options?: readonly PoadSegmentOption[];
|
|
28
|
+
declare optionLabel?: string;
|
|
29
|
+
declare optionValue?: string;
|
|
30
|
+
declare multiple?: boolean;
|
|
31
|
+
declare allowEmpty?: boolean;
|
|
32
|
+
declare block?: boolean;
|
|
33
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
34
|
+
declare shape?: 'rounded' | 'pill';
|
|
35
|
+
declare disabled?: boolean;
|
|
36
|
+
declare ariaLabel: string | null;
|
|
37
|
+
declare name?: string;
|
|
38
|
+
declare required?: boolean;
|
|
39
|
+
/** Contenu d'une option (gabarit d'option en Angular) ; absent : icône et libellé. */
|
|
40
|
+
declare renderOption?: (option: PoadSegmentOption) => string | Node;
|
|
41
|
+
protected readonly resetProps = ['value'];
|
|
42
|
+
|
|
43
|
+
protected formValue() {
|
|
44
|
+
const values = (Array.isArray(this.value) ? this.value : this.value == null ? [] : [this.value]) as unknown[];
|
|
45
|
+
if (!this.name || values.length < 2) return { value: values.length ? String(values[0]) : null, missing: !values.length };
|
|
46
|
+
const data = new FormData();
|
|
47
|
+
for (const v of values) data.append(this.name, String(v));
|
|
48
|
+
return { value: data, missing: false };
|
|
49
|
+
}
|
|
50
|
+
protected render() {
|
|
51
|
+
const mode = { multiple: this.multiple, allowEmpty: this.allowEmpty, disabled: this.inactive };
|
|
52
|
+
const options = this.options ?? [];
|
|
53
|
+
const items: SegmentedItem<unknown>[] = options.map((o) => ({ value: resolve(o, this.optionValue ?? 'value'), disabled: !!o.disabled }));
|
|
54
|
+
const current = this.value ?? null;
|
|
55
|
+
const pick = (index: number) => {
|
|
56
|
+
const next = segmentedPick(current, items[index]!.value, mode);
|
|
57
|
+
if (next === current) return;
|
|
58
|
+
this.value = next;
|
|
59
|
+
this.changed(next);
|
|
60
|
+
};
|
|
61
|
+
const onkeydown = (e: KeyboardEvent) => {
|
|
62
|
+
const buttons = [...this.querySelectorAll<HTMLButtonElement>(':scope > .poad-segmented > button')];
|
|
63
|
+
const from = buttons.indexOf(e.target as HTMLButtonElement);
|
|
64
|
+
if (from < 0) return;
|
|
65
|
+
const to = segmentedKeydown(items, from, e.key, { ...mode, rtl: getComputedStyle(this).direction === 'rtl' });
|
|
66
|
+
if (to === null) return;
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
buttons[to]?.focus();
|
|
69
|
+
};
|
|
70
|
+
return h('div', {
|
|
71
|
+
class: ['poad-segmented', segmentedRootClasses({ disabled: mode.disabled, size: this.size ?? 'md', block: this.block, shape: this.shape ?? 'rounded' })],
|
|
72
|
+
role: 'group', 'aria-label': this.ariaLabel || undefined, onkeydown,
|
|
73
|
+
}, options.map((o, i) => {
|
|
74
|
+
const attrs = segmentedOptionProps(current, items, i, mode);
|
|
75
|
+
const label = String(resolve(o, this.optionLabel ?? 'label') ?? '');
|
|
76
|
+
return h('button', {
|
|
77
|
+
type: 'button', class: attrs['aria-pressed'] === 'true' ? 'is-on' : undefined, disabled: attrs.disabled, 'aria-pressed': attrs['aria-pressed'],
|
|
78
|
+
tabindex: attrs.tabindex, title: o.title || undefined, onclick: () => pick(i),
|
|
79
|
+
}, this.renderOption ? this.renderOption(o) : [o.icon && icon(this.icons(), o.icon, { size: 14 }), label && h('span', label)]);
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/select.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-select name="runtime" aria-label="Runtime" placeholder="Choose" filter clearable
|
|
3
|
+
* options='[{"label":"Node","value":1},{"label":"Python","value":2}]'></poad-select>
|
|
4
|
+
* select.value = 2; select.addEventListener('change', (e) => e.detail); select.renderOption = (option, ctx) => …
|
|
5
|
+
*
|
|
6
|
+
* Liste déroulante (jamais de `<select>` natif) : machine `select` de @poadio/ui-core — options aplaties et groupes,
|
|
7
|
+
* filtre, ouverture, option active, clavier WAI-ARIA combobox, recherche au clavier, ARIA, classes d'état, placement.
|
|
8
|
+
* L'élément garde l'état de la machine, applique chaque transition et exécute ses effets. Même DOM, mêmes classes,
|
|
9
|
+
* même ARIA que `poad-select` d'ui-angular. Propriété `value` (attribut en JSON ou chaîne), évènements `input` /
|
|
10
|
+
* `change` (choix ou effacement de l'utilisateur), `openchange`, `filter`, `clear`. Formulaire : `name` (valeur en
|
|
11
|
+
* chaîne), `required`. Panneau : couche flottante interne (`floating.ts` : dans l'élément, `position: fixed`, placé par
|
|
12
|
+
* `floatingPlacement()` du socle, fermé par un appui extérieur) ; petit écran ou `mobile="sheet"` : feuille basse du
|
|
13
|
+
* socle (dialogue modal titré, focus piégé, glisser pour fermer, focus rendu au déclencheur). Style : `select.css`,
|
|
14
|
+
* `option-list.css`, `floating.css`, `sheet.css`, `icon.css`.
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
FOCUS_AUTOFOCUS_ATTR, SELECT_INITIAL, SELECT_PLACEMENTS, SHEET_MOBILE_QUERY, selectEmptyMessage, selectEquals, selectFallbackLabel, selectFilterProps,
|
|
18
|
+
selectFindOption, selectItems, selectRootClasses, selectScrollTop, selectSheetTitle, selectTransition,
|
|
19
|
+
selectTriggerProps, selectUseSheet, selectVisibleItems,
|
|
20
|
+
type SelectContext, type SelectEffect, type SelectEvent, type SelectMobileMode, type SelectState,
|
|
21
|
+
} from '@poadio/ui-core';
|
|
22
|
+
import { h } from './dom.js';
|
|
23
|
+
import { PoadFormElement } from './element.js';
|
|
24
|
+
import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
|
|
25
|
+
import { icon } from './icon.js';
|
|
26
|
+
import { optionList, type PoadSelectOptionContext } from './option-list.js';
|
|
27
|
+
|
|
28
|
+
/** Attribut « focus initial » du piège à focus de la feuille (ui-core). */
|
|
29
|
+
const autofocus = (on: boolean) => (on ? { [FOCUS_AUTOFOCUS_ATTR]: '' } : {});
|
|
30
|
+
|
|
31
|
+
export type { PoadSelectOptionContext };
|
|
32
|
+
|
|
33
|
+
export class PoadSelectElement extends PoadFormElement {
|
|
34
|
+
static override props = {
|
|
35
|
+
value: 'json', options: 'json', optionLabel: 'string', optionValue: 'string', optionDisabled: 'string', optionHint: 'string', optionIcon: 'string',
|
|
36
|
+
optionGroupLabel: 'string', optionGroupChildren: 'string', dataKey: 'string', placeholder: 'string', filter: 'boolean', filterPlaceholder: 'string',
|
|
37
|
+
filterBy: 'string', autofocusFilter: 'boolean', clearable: 'boolean', loading: 'boolean', emptyMessage: 'string', emptyFilterMessage: 'string',
|
|
38
|
+
size: 'string', invalid: 'boolean', disabled: 'boolean', readonly: 'boolean', panelMaxHeight: 'number', ariaLabel: 'string', mobile: 'string',
|
|
39
|
+
sheetTitle: 'string', name: 'string', required: 'boolean',
|
|
40
|
+
} as const;
|
|
41
|
+
static override functions = ['compareWith', 'renderOption', 'renderValue', 'renderEmpty'] as const;
|
|
42
|
+
declare value?: unknown;
|
|
43
|
+
declare options?: readonly unknown[];
|
|
44
|
+
declare optionLabel?: string;
|
|
45
|
+
declare optionValue?: string;
|
|
46
|
+
declare optionDisabled?: string;
|
|
47
|
+
declare optionHint?: string;
|
|
48
|
+
declare optionIcon?: string;
|
|
49
|
+
declare optionGroupLabel?: string;
|
|
50
|
+
declare optionGroupChildren?: string;
|
|
51
|
+
declare dataKey?: string;
|
|
52
|
+
declare placeholder?: string;
|
|
53
|
+
declare filter?: boolean;
|
|
54
|
+
declare filterPlaceholder?: string;
|
|
55
|
+
declare filterBy?: string;
|
|
56
|
+
declare autofocusFilter?: boolean;
|
|
57
|
+
declare clearable?: boolean;
|
|
58
|
+
declare loading?: boolean;
|
|
59
|
+
declare emptyMessage?: string;
|
|
60
|
+
declare emptyFilterMessage?: string;
|
|
61
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
62
|
+
declare invalid?: boolean;
|
|
63
|
+
declare disabled?: boolean;
|
|
64
|
+
declare readonly?: boolean;
|
|
65
|
+
declare panelMaxHeight?: number;
|
|
66
|
+
declare ariaLabel: string | null;
|
|
67
|
+
declare mobile?: SelectMobileMode;
|
|
68
|
+
declare sheetTitle?: string;
|
|
69
|
+
declare name?: string;
|
|
70
|
+
declare required?: boolean;
|
|
71
|
+
/** Comparaison de valeurs (objets). Défaut : `data-key`, puis `===`. */
|
|
72
|
+
declare compareWith?: (a: unknown, b: unknown) => boolean;
|
|
73
|
+
/** Contenu d'une option, de la valeur affichée, de la liste vide (gabarits `poadSelectItem` / `Selected` / `Empty`). */
|
|
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;
|
|
77
|
+
protected readonly resetProps = ['value'];
|
|
78
|
+
|
|
79
|
+
private state: SelectState = SELECT_INITIAL;
|
|
80
|
+
private focused = false;
|
|
81
|
+
private inSheet = false;
|
|
82
|
+
private triggerWidth = 0;
|
|
83
|
+
private readonly tracker = new FloatingTracker(() => this.update());
|
|
84
|
+
// déclencheur, panneau, feuille basse : chacun gère son clic ; dehors, la liste se ferme
|
|
85
|
+
private readonly outside = new Listening(() => listenOutside(() => [this], () => this.send({ type: 'close', refocus: false })));
|
|
86
|
+
private readonly sheet = new Sheet(() => this.update());
|
|
87
|
+
|
|
88
|
+
private find<E extends HTMLElement>(selector: string): E | null {
|
|
89
|
+
return this.querySelector<E>(`:scope > .poad-select ${selector}`);
|
|
90
|
+
}
|
|
91
|
+
private get listId() { return `${this.uid}-list`; }
|
|
92
|
+
private get items() {
|
|
93
|
+
const { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren } = this;
|
|
94
|
+
return selectItems(this.options, { optionLabel, optionValue, optionDisabled, optionHint, optionIcon, optionGroupLabel, optionGroupChildren }, this.listId);
|
|
95
|
+
}
|
|
96
|
+
private get compare() { return { compareWith: this.compareWith, dataKey: this.dataKey }; }
|
|
97
|
+
private get hasValue() { return this.value != null; }
|
|
98
|
+
private context(items = this.items): SelectContext<unknown> {
|
|
99
|
+
return {
|
|
100
|
+
items, filter: { enabled: !!this.filter, by: this.filterBy, grouped: !!this.optionGroupLabel }, interactive: !this.inactive && !this.readonly,
|
|
101
|
+
clearable: this.clearable, modal: this.inSheet, isSelected: (it) => this.hasValue && selectEquals(it.value, this.value, this.compare),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
protected formValue() {
|
|
106
|
+
return { value: this.hasValue ? (typeof this.value === 'object' ? JSON.stringify(this.value) : String(this.value)) : null, missing: !this.hasValue };
|
|
107
|
+
}
|
|
108
|
+
override disconnectedCallback(): void {
|
|
109
|
+
super.disconnectedCallback();
|
|
110
|
+
this.state = SELECT_INITIAL;
|
|
111
|
+
this.tracker.sync(null, null);
|
|
112
|
+
this.outside.toggle(false);
|
|
113
|
+
this.sheet.dispose();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private run(effect: SelectEffect<unknown>) {
|
|
117
|
+
switch (effect.type) {
|
|
118
|
+
case 'opened':
|
|
119
|
+
this.triggerWidth = this.find('.poad-select__trigger')?.getBoundingClientRect().width ?? 0;
|
|
120
|
+
this.inSheet = selectUseSheet(this.mobile ?? 'auto', mediaMatches(SHEET_MOBILE_QUERY));
|
|
121
|
+
return void this.emit('openchange', true);
|
|
122
|
+
case 'closed':
|
|
123
|
+
this.inSheet = false;
|
|
124
|
+
this.emit('openchange', false);
|
|
125
|
+
if (effect.refocus) this.find('.poad-select__trigger')?.focus();
|
|
126
|
+
return;
|
|
127
|
+
case 'pick':
|
|
128
|
+
if (selectEquals(effect.item.value, this.value, this.compare)) return;
|
|
129
|
+
this.value = effect.item.value;
|
|
130
|
+
return this.changed(effect.item.value);
|
|
131
|
+
case 'clear':
|
|
132
|
+
this.value = null;
|
|
133
|
+
this.changed(null);
|
|
134
|
+
return void this.emit('clear');
|
|
135
|
+
case 'filtered':
|
|
136
|
+
return void this.emit('filter', effect.query);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
private send(event: SelectEvent) {
|
|
140
|
+
const was = this.state.open;
|
|
141
|
+
const step = selectTransition(this.state, event, this.context());
|
|
142
|
+
this.state = step.state;
|
|
143
|
+
step.effects.forEach((e) => this.run(e));
|
|
144
|
+
this.update();
|
|
145
|
+
if (this.state.open && !was && this.filter && this.autofocusFilter !== false && !this.inSheet) this.find<HTMLInputElement>('.poad-select__search input')?.focus();
|
|
146
|
+
return step;
|
|
147
|
+
}
|
|
148
|
+
/** Après rendu : formulaire, panneau flottant placé, fermeture au dehors, feuille, option active visible. */
|
|
149
|
+
protected override updated(): void {
|
|
150
|
+
super.updated();
|
|
151
|
+
const floating = this.state.open && !this.inSheet;
|
|
152
|
+
this.tracker.sync(floating ? this.find('.poad-select__trigger') : null, floating ? this.find('.poad-floating') : null, {
|
|
153
|
+
candidates: SELECT_PLACEMENTS, offset: 4, shift: true,
|
|
154
|
+
});
|
|
155
|
+
this.outside.toggle(this.state.open);
|
|
156
|
+
this.sheet.sync(this);
|
|
157
|
+
const list = this.find('.poad-optlist');
|
|
158
|
+
const option = list?.querySelector<HTMLElement>(`[id="${this.listId}-opt-${this.state.activeIndex}"]`);
|
|
159
|
+
if (!list || !option) return;
|
|
160
|
+
const next = selectScrollTop({ top: option.offsetTop, height: option.offsetHeight }, { scrollTop: list.scrollTop, clientHeight: list.clientHeight });
|
|
161
|
+
if (next !== null) list.scrollTop = next;
|
|
162
|
+
}
|
|
163
|
+
private readonly onKeydown = (e: KeyboardEvent) => {
|
|
164
|
+
const step = this.send({
|
|
165
|
+
type: 'keydown', key: e.key, ctrlKey: e.ctrlKey, metaKey: e.metaKey, altKey: e.altKey, inTextField: e.target instanceof HTMLInputElement, time: Date.now(),
|
|
166
|
+
});
|
|
167
|
+
if (step.preventDefault) e.preventDefault();
|
|
168
|
+
if (step.stopPropagation) e.stopPropagation();
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
protected render() {
|
|
172
|
+
const { t, text } = this.i18n();
|
|
173
|
+
const registry = this.icons();
|
|
174
|
+
const s = this.state, items = this.items, c = this.context(items), listId = this.listId;
|
|
175
|
+
const trigger = selectTriggerProps(s, c, { id: this.uid, listId, ariaLabel: this.ariaLabel, invalid: this.invalid, disabled: this.inactive, readonly: this.readonly });
|
|
176
|
+
const selected = this.hasValue ? selectFindOption(items, this.value, this.compare) : undefined;
|
|
177
|
+
const visible = selectVisibleItems(s, c);
|
|
178
|
+
const filtered = !!s.query;
|
|
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' });
|
|
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
|
+
});
|
|
185
|
+
const f = selectFilterProps(s, c, { listId });
|
|
186
|
+
const panel = h('div', {
|
|
187
|
+
class: ['poad-select__panel', { 'is-sheet': this.inSheet }], style: this.inSheet ? undefined : { minWidth: `${this.triggerWidth}px` },
|
|
188
|
+
tabindex: this.inSheet ? -1 : undefined, ...autofocus(this.inSheet && !this.filter), onkeydown: this.onKeydown,
|
|
189
|
+
}, [
|
|
190
|
+
this.filter && h('div', { class: 'poad-select__search' }, [
|
|
191
|
+
icon(registry, 'search', { size: 13 }),
|
|
192
|
+
h('input', {
|
|
193
|
+
type: 'text', ...autofocus(this.inSheet), placeholder: text(this.filterPlaceholder, 'select.filterPlaceholder'), value: s.query, autocomplete: 'off', spellcheck: 'false',
|
|
194
|
+
role: f.role, 'aria-autocomplete': f['aria-autocomplete'], 'aria-controls': f['aria-controls'], 'aria-activedescendant': f['aria-activedescendant'],
|
|
195
|
+
oninput: (e: Event) => this.send({ type: 'filter', query: (e.target as HTMLInputElement).value }),
|
|
196
|
+
}),
|
|
197
|
+
]),
|
|
198
|
+
list,
|
|
199
|
+
]);
|
|
200
|
+
const titleId = `${this.uid}-sheet-title`;
|
|
201
|
+
return h('div', { class: ['poad-select', root] }, [
|
|
202
|
+
h('div', {
|
|
203
|
+
class: 'poad-select__trigger', role: trigger.role, tabindex: trigger.tabIndex, id: trigger.id, 'aria-haspopup': trigger['aria-haspopup'],
|
|
204
|
+
'aria-expanded': trigger['aria-expanded'], 'aria-controls': trigger['aria-controls'], 'aria-activedescendant': trigger['aria-activedescendant'],
|
|
205
|
+
'aria-label': trigger['aria-label'], 'aria-invalid': trigger['aria-invalid'], 'aria-disabled': trigger['aria-disabled'], 'aria-readonly': trigger['aria-readonly'],
|
|
206
|
+
onclick: () => this.send({ type: 'toggle' }), onkeydown: this.onKeydown,
|
|
207
|
+
onfocus: () => { this.focused = true; this.update(); }, onblur: () => { this.focused = false; this.update(); },
|
|
208
|
+
}, [
|
|
209
|
+
h('span', { class: ['poad-select__value', { 'is-placeholder': !this.hasValue }] }, selected
|
|
210
|
+
? this.renderValue ? this.renderValue(selected.option, { label: selected.label }) : [selected.icon && icon(registry, selected.icon, { size: 14, class: 'poad-select__icon' }), selected.label]
|
|
211
|
+
: this.hasValue ? selectFallbackLabel(this.value) : (this.placeholder ?? '')),
|
|
212
|
+
this.loading && icon(registry, 'loader', { size: 14, spin: true, class: 'poad-select__spin' }),
|
|
213
|
+
this.clearable && this.hasValue && c.interactive && h('button', {
|
|
214
|
+
type: 'button', class: 'poad-select__clear', tabindex: -1, 'aria-label': t('common.clear'),
|
|
215
|
+
onclick: (e: MouseEvent) => { e.stopPropagation(); this.send({ type: 'clear' }); },
|
|
216
|
+
}, icon(registry, 'x', { size: 12 })),
|
|
217
|
+
icon(registry, 'chevron-down', { size: 13, class: 'poad-select__chev' }),
|
|
218
|
+
]),
|
|
219
|
+
s.open && !this.inSheet && h('div', { class: 'poad-floating', style: this.tracker.style }, panel),
|
|
220
|
+
this.sheet.render({
|
|
221
|
+
open: s.open && this.inSheet, titleId, restoreFocus: false, label: t('common.close'), icons: registry, onClose: () => this.send({ type: 'close' }),
|
|
222
|
+
title: selectSheetTitle({ sheetTitle: this.sheetTitle, ariaLabel: this.ariaLabel, placeholder: this.placeholder }),
|
|
223
|
+
}, this.inSheet ? panel : null),
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
}
|
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/skeleton.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-skeleton width="70%"></poad-skeleton> <poad-skeleton lines="3"></poad-skeleton> <poad-skeleton shape="circle" width="32px" height="32px"></poad-skeleton>
|
|
3
|
+
*
|
|
4
|
+
* Squelette de chargement : barres et classes de @poadio/ui-core (`skeletonBars`, `skeletonRootClasses`) — même DOM
|
|
5
|
+
* que `poad-skeleton` d'ui-angular (caché aux technologies d'assistance). `animation="false"` l'arrête.
|
|
6
|
+
*/
|
|
7
|
+
import { skeletonBars, skeletonRootClasses } from '@poadio/ui-core';
|
|
8
|
+
import { h } from './dom.js';
|
|
9
|
+
import { PoadElement } from './element.js';
|
|
10
|
+
|
|
11
|
+
export class PoadSkeletonElement extends PoadElement {
|
|
12
|
+
static override props = { width: 'string', height: 'string', shape: 'string', lines: 'number', animation: 'boolean', lastWidth: 'string' } as const;
|
|
13
|
+
declare width?: string;
|
|
14
|
+
declare height?: string;
|
|
15
|
+
declare shape?: 'text' | 'rect' | 'circle';
|
|
16
|
+
declare lines?: number;
|
|
17
|
+
declare animation?: boolean;
|
|
18
|
+
declare lastWidth?: string;
|
|
19
|
+
|
|
20
|
+
protected render() {
|
|
21
|
+
return h('div', { class: ['poad-skeleton', skeletonRootClasses(this)], 'aria-hidden': 'true' },
|
|
22
|
+
skeletonBars(this).map((bar) => h('span', { class: bar.className, style: { width: bar.width, height: bar.height } })));
|
|
23
|
+
}
|
|
24
|
+
}
|