@poadio/ui-react 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 +58 -0
- package/LICENSE +22 -0
- package/README.md +161 -2
- package/dist/avatar.d.ts +26 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +35 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +14 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +7 -0
- package/dist/badge.js.map +1 -0
- package/dist/button-group.d.ts +24 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +38 -0
- package/dist/button-group.js.map +1 -0
- package/dist/button.d.ts +20 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +8 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.d.ts +34 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +41 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/chip.d.ts +26 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +25 -0
- package/dist/chip.js.map +1 -0
- package/dist/colorpicker.d.ts +37 -0
- package/dist/colorpicker.d.ts.map +1 -0
- package/dist/colorpicker.js +107 -0
- package/dist/colorpicker.js.map +1 -0
- package/dist/controllable.d.ts +2 -0
- package/dist/controllable.d.ts.map +1 -0
- package/dist/controllable.js +12 -0
- package/dist/controllable.js.map +1 -0
- package/dist/divider.d.ts +13 -0
- package/dist/divider.d.ts.map +1 -0
- package/dist/divider.js +8 -0
- package/dist/divider.js.map +1 -0
- package/dist/field.d.ts +43 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +57 -0
- package/dist/field.js.map +1 -0
- package/dist/floating.d.ts +86 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +235 -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 +34 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icon.d.ts +31 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +40 -0
- package/dist/icon.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/inplace.d.ts +36 -0
- package/dist/inplace.d.ts.map +1 -0
- package/dist/inplace.js +58 -0
- package/dist/inplace.js.map +1 -0
- package/dist/mask.d.ts +65 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +104 -0
- package/dist/mask.js.map +1 -0
- package/dist/message.d.ts +21 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +14 -0
- package/dist/message.js.map +1 -0
- package/dist/meter.d.ts +26 -0
- package/dist/meter.d.ts.map +1 -0
- package/dist/meter.js +26 -0
- package/dist/meter.js.map +1 -0
- package/dist/number.d.ts +37 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/number.js +41 -0
- package/dist/number.js.map +1 -0
- package/dist/password.d.ts +38 -0
- package/dist/password.d.ts.map +1 -0
- package/dist/password.js +24 -0
- package/dist/password.js.map +1 -0
- package/dist/popover.d.ts +44 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +76 -0
- package/dist/popover.js.map +1 -0
- package/dist/progress.d.ts +25 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +15 -0
- package/dist/progress.js.map +1 -0
- package/dist/radio.d.ts +35 -0
- package/dist/radio.d.ts.map +1 -0
- package/dist/radio.js +74 -0
- package/dist/radio.js.map +1 -0
- package/dist/rating.d.ts +35 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +52 -0
- package/dist/rating.js.map +1 -0
- package/dist/segmented.d.ts +39 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +51 -0
- package/dist/segmented.js.map +1 -0
- package/dist/select.d.ts +96 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +156 -0
- package/dist/select.js.map +1 -0
- package/dist/skeleton.d.ts +13 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +7 -0
- package/dist/skeleton.js.map +1 -0
- package/dist/slider.d.ts +46 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +105 -0
- package/dist/slider.js.map +1 -0
- package/dist/switch.d.ts +37 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +36 -0
- package/dist/switch.js.map +1 -0
- package/dist/tag.d.ts +17 -0
- package/dist/tag.d.ts.map +1 -0
- package/dist/tag.js +8 -0
- package/dist/tag.js.map +1 -0
- package/dist/toggle-button.d.ts +31 -0
- package/dist/toggle-button.d.ts.map +1 -0
- package/dist/toggle-button.js +20 -0
- package/dist/toggle-button.js.map +1 -0
- package/dist/tooltip.d.ts +32 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +79 -0
- package/dist/tooltip.js.map +1 -0
- package/package.json +71 -4
- package/src/avatar.tsx +65 -0
- package/src/badge.tsx +22 -0
- package/src/button-group.tsx +51 -0
- package/src/button.tsx +39 -0
- package/src/checkbox.tsx +77 -0
- package/src/chip.tsx +63 -0
- package/src/colorpicker.tsx +213 -0
- package/src/controllable.ts +11 -0
- package/src/divider.tsx +21 -0
- package/src/field.tsx +123 -0
- package/src/floating.tsx +308 -0
- package/src/i18n.tsx +54 -0
- package/src/icon.tsx +77 -0
- package/src/index.ts +49 -0
- package/src/inplace.tsx +101 -0
- package/src/mask.ts +142 -0
- package/src/message.tsx +42 -0
- package/src/meter.tsx +71 -0
- package/src/number.tsx +90 -0
- package/src/password.tsx +83 -0
- package/src/popover.tsx +131 -0
- package/src/progress.tsx +66 -0
- package/src/radio.tsx +123 -0
- package/src/rating.tsx +100 -0
- package/src/segmented.tsx +89 -0
- package/src/select.tsx +314 -0
- package/src/skeleton.tsx +20 -0
- package/src/slider.tsx +166 -0
- package/src/switch.tsx +79 -0
- package/src/tag.tsx +28 -0
- package/src/toggle-button.tsx +60 -0
- package/src/tooltip.tsx +118 -0
package/src/mask.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* Masque de saisie et filtre de touches pour React, en crochets (hooks) à poser sur un `<input>` — `PoadInput` ou
|
|
4
|
+
* natif. La logique est `mask` de @poadio/ui-core, la même que `input[poadMask]` / `input[poadKeyFilter]` d'ui-angular.
|
|
5
|
+
*
|
|
6
|
+
* const tel = usePoadMask({ preset: 'phone', value: phone, onValueChange: setPhone });
|
|
7
|
+
* <PoadInput {...tel.inputProps} aria-invalid={!tel.complete || undefined} />
|
|
8
|
+
*
|
|
9
|
+
* const digits = usePoadKeyFilter('int');
|
|
10
|
+
* <PoadInput {...digits.inputProps} />
|
|
11
|
+
*
|
|
12
|
+
* MASQUE : `9` chiffre, `a` lettre, `*` lettre ou chiffre, le reste littéral ; `preset` : `MASK_PRESETS` du socle
|
|
13
|
+
* (`phone`, `siret`, `siren`, `postal`, `date`, `time`, `iban`, `plate`). Le texte du champ est réécrit à chaque
|
|
14
|
+
* frappe (le champ n'est donc pas « contrôlé » au sens de React : le crochet tient son texte et son curseur). La
|
|
15
|
+
* valeur rendue est le texte masqué, ou les seuls caractères utiles (`unmask`) ; `null` quand le champ est vide.
|
|
16
|
+
* `value` (contrôlé) ou `defaultValue` ; `complete` dit si toutes les places sont remplies (ou le champ vide) ;
|
|
17
|
+
* `autoClear` vide un champ incomplet à la sortie.
|
|
18
|
+
*
|
|
19
|
+
* FILTRE : `int`, `num`, `alpha`, `alphanum`, `hex`, `email` ou une expression testée sur chaque caractère ; une
|
|
20
|
+
* frappe refusée est empêchée, un collage est nettoyé. `validateOnly` : rien n'est bloqué ; `valid(valeur)` dit si
|
|
21
|
+
* la valeur entière convient.
|
|
22
|
+
*/
|
|
23
|
+
import { useCallback, useEffect, useRef, useState, type ClipboardEvent, type FocusEvent, type FormEvent, type KeyboardEvent, type Ref, type RefCallback } from 'react';
|
|
24
|
+
import {
|
|
25
|
+
MASK_SLOT, keyFilterBlocks, keyFilterPaste, keyFilterValid, maskFirstSlot, maskInput, maskInputMode, maskPlaceholder, maskResolve, maskWrite,
|
|
26
|
+
type KeyFilter,
|
|
27
|
+
} from '@poadio/ui-core';
|
|
28
|
+
|
|
29
|
+
export interface UsePoadMaskOptions {
|
|
30
|
+
/** Masque (`99 99 99 99 99`) ; prime sur `preset`. */
|
|
31
|
+
readonly mask?: string;
|
|
32
|
+
readonly preset?: string;
|
|
33
|
+
/** Caractère des places libres. Défaut : `_`. */
|
|
34
|
+
readonly slotChar?: string;
|
|
35
|
+
/** Valeur = caractères utiles seulement. */
|
|
36
|
+
readonly unmask?: boolean;
|
|
37
|
+
/** Vide le champ à la sortie s'il est incomplet. */
|
|
38
|
+
readonly autoClear?: boolean;
|
|
39
|
+
/** Valeur imposée (mode contrôlé) ; `null` = vide. */
|
|
40
|
+
readonly value?: string | null;
|
|
41
|
+
readonly defaultValue?: string | null;
|
|
42
|
+
/** Appelé quand l'UTILISATEUR change la valeur. */
|
|
43
|
+
readonly onValueChange?: (value: string | null) => void;
|
|
44
|
+
/** `ref` de l'application sur l'`<input>`, réuni à celle du crochet. */
|
|
45
|
+
readonly ref?: Ref<HTMLInputElement>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PoadMaskInputProps {
|
|
49
|
+
readonly ref: RefCallback<HTMLInputElement>;
|
|
50
|
+
readonly defaultValue: string;
|
|
51
|
+
readonly placeholder: string;
|
|
52
|
+
readonly inputMode: 'numeric' | undefined;
|
|
53
|
+
readonly onInput: (e: FormEvent<HTMLInputElement>) => void;
|
|
54
|
+
readonly onFocus: (e: FocusEvent<HTMLInputElement>) => void;
|
|
55
|
+
readonly onBlur: (e: FocusEvent<HTMLInputElement>) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const assignRef = <T,>(ref: Ref<T> | undefined, value: T | null): void => {
|
|
59
|
+
if (typeof ref === 'function') ref(value);
|
|
60
|
+
else if (ref) (ref as { current: T | null }).current = value;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function usePoadMask(options: UsePoadMaskOptions): { readonly inputProps: PoadMaskInputProps; readonly complete: boolean } {
|
|
64
|
+
const { slotChar = MASK_SLOT, unmask, autoClear, value, defaultValue = null, onValueChange, ref } = options;
|
|
65
|
+
const mask = maskResolve(options.mask, options.preset);
|
|
66
|
+
const controlled = value !== undefined;
|
|
67
|
+
const element = useRef<HTMLInputElement | null>(null);
|
|
68
|
+
/** Dernière valeur rendue à l'application : une `value` égale ne réécrit pas le champ (curseur gardé). */
|
|
69
|
+
const emitted = useRef<string | null>(controlled ? (value ?? null) : defaultValue);
|
|
70
|
+
const [complete, setComplete] = useState(() => maskWrite(mask, controlled ? value : defaultValue, slotChar).complete);
|
|
71
|
+
const initial = useRef(maskWrite(mask, controlled ? value : defaultValue, slotChar).display);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!controlled || (value ?? null) === emitted.current || !element.current) return;
|
|
75
|
+
const r = maskWrite(mask, value, slotChar);
|
|
76
|
+
element.current.value = r.display;
|
|
77
|
+
emitted.current = value ?? null;
|
|
78
|
+
setComplete(r.complete);
|
|
79
|
+
}, [controlled, value, mask, slotChar]);
|
|
80
|
+
|
|
81
|
+
const emit = (next: string | null) => {
|
|
82
|
+
emitted.current = next;
|
|
83
|
+
onValueChange?.(next);
|
|
84
|
+
};
|
|
85
|
+
const setRef = useCallback((el: HTMLInputElement | null) => { element.current = el; assignRef(ref, el); }, [ref]);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
complete,
|
|
89
|
+
inputProps: {
|
|
90
|
+
ref: setRef,
|
|
91
|
+
defaultValue: initial.current,
|
|
92
|
+
placeholder: maskPlaceholder(mask, slotChar),
|
|
93
|
+
inputMode: maskInputMode(mask) ?? undefined,
|
|
94
|
+
onInput: (e) => {
|
|
95
|
+
const el = e.currentTarget;
|
|
96
|
+
const deleting = !!(e.nativeEvent as InputEvent).inputType?.startsWith('delete');
|
|
97
|
+
const r = maskInput(mask, el.value, el.selectionStart ?? el.value.length, { slot: slotChar, unmask, deleting });
|
|
98
|
+
el.value = r.display;
|
|
99
|
+
el.setSelectionRange(r.caret, r.caret);
|
|
100
|
+
setComplete(r.complete);
|
|
101
|
+
emit(r.value);
|
|
102
|
+
},
|
|
103
|
+
onFocus: (e) => {
|
|
104
|
+
const el = e.currentTarget;
|
|
105
|
+
setTimeout(() => { const p = maskFirstSlot(el.value, slotChar); if (el.value) el.setSelectionRange(p, p); });
|
|
106
|
+
},
|
|
107
|
+
onBlur: (e) => {
|
|
108
|
+
if (!autoClear || complete) return;
|
|
109
|
+
e.currentTarget.value = '';
|
|
110
|
+
setComplete(true);
|
|
111
|
+
emit(null);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface PoadKeyFilterInputProps {
|
|
118
|
+
readonly onKeyDown: (e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
119
|
+
readonly onPaste: (e: ClipboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function usePoadKeyFilter(filter: KeyFilter = 'alphanum', options: { readonly validateOnly?: boolean } = {}): {
|
|
123
|
+
readonly inputProps: PoadKeyFilterInputProps;
|
|
124
|
+
readonly valid: (value: unknown) => boolean;
|
|
125
|
+
} {
|
|
126
|
+
const validateOnly = !!options.validateOnly;
|
|
127
|
+
return {
|
|
128
|
+
valid: (v) => keyFilterValid(filter, v),
|
|
129
|
+
inputProps: {
|
|
130
|
+
onKeyDown: (e) => { if (keyFilterBlocks(filter, e, validateOnly)) e.preventDefault(); },
|
|
131
|
+
onPaste: (e) => {
|
|
132
|
+
const clean = keyFilterPaste(filter, e.clipboardData?.getData('text') ?? '', validateOnly);
|
|
133
|
+
if (clean == null) return;
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
const el = e.currentTarget;
|
|
136
|
+
const s = el.selectionStart ?? el.value.length, end = el.selectionEnd ?? s;
|
|
137
|
+
el.setRangeText(clean, s, end, 'end');
|
|
138
|
+
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
package/src/message.tsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadMessage severity="warning" closable>The certificate expires in 6 days.</PoadMessage>
|
|
4
|
+
* <PoadMessage text="Saved" severity="success" variant="outline" size="sm" icon="" /> sans icône
|
|
5
|
+
* <PoadMessage open={shown} onClose={() => setShown(false)} closable>…</PoadMessage> contrôlé
|
|
6
|
+
*
|
|
7
|
+
* Message en ligne : classes et icône de @poadio/ui-core (`messageClasses`, `messageIcon`) — même DOM que
|
|
8
|
+
* `poad-message` d'ui-angular (`role="status"`). Fermé, il reste dans le DOM avec `is-hidden`, comme en Angular.
|
|
9
|
+
* Le bouton de fermeture est nommé par le catalogue (`common.close`). Style : `@poadio/ui-core/message.css`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ComponentPropsWithRef } from 'react';
|
|
12
|
+
import { messageClasses, messageIcon, messageIconSize, type MessageOptions } from '@poadio/ui-core';
|
|
13
|
+
import { useControllable } from './controllable.js';
|
|
14
|
+
import { PoadIcon } from './icon.js';
|
|
15
|
+
import { useUiI18n } from './i18n.js';
|
|
16
|
+
|
|
17
|
+
export interface PoadMessageProps extends ComponentPropsWithRef<'div'>, Omit<MessageOptions, 'hidden'> {
|
|
18
|
+
readonly text?: string;
|
|
19
|
+
readonly closable?: boolean;
|
|
20
|
+
/** Visible (mode contrôlé). Absent : visible jusqu'à la fermeture par l'utilisateur. */
|
|
21
|
+
readonly open?: boolean;
|
|
22
|
+
/** L'utilisateur ferme le message. */
|
|
23
|
+
readonly onClose?: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function PoadMessage({ severity, text, icon, closable, variant, size, open, onClose, className, children, ...rest }: PoadMessageProps) {
|
|
27
|
+
const { t } = useUiI18n();
|
|
28
|
+
const [shown, setShown] = useControllable(open, true);
|
|
29
|
+
const options = { severity, variant, size, icon, hidden: !shown };
|
|
30
|
+
const iconName = messageIcon(options);
|
|
31
|
+
return (
|
|
32
|
+
<div {...rest} className={className ? `${messageClasses(options)} ${className}` : messageClasses(options)} role="status">
|
|
33
|
+
{iconName && <PoadIcon className="poad-message__icon" name={iconName} size={messageIconSize(options)} />}
|
|
34
|
+
<div className="poad-message__body">{text}{children}</div>
|
|
35
|
+
{closable && (
|
|
36
|
+
<button type="button" className="poad-message__close" aria-label={t('common.close')} onClick={() => { setShown(false); onClose?.(); }}>
|
|
37
|
+
<PoadIcon name="x" size={13} />
|
|
38
|
+
</button>
|
|
39
|
+
)}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
package/src/meter.tsx
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadMeter values={[{ label: 'Used', value: 62, severity: 'primary' }, { label: 'Reserved', value: 18, severity: 'warning' }]} unit="Gi" />
|
|
4
|
+
* <PoadMeter values={v} showRemaining renderLabel={(s, percent) => <b>{s.label}</b>} orientation="vertical" />
|
|
5
|
+
*
|
|
6
|
+
* Jauge segmentée : segments, couleurs, total, reste, attributs (`role="meter"`) et textes de @poadio/ui-core
|
|
7
|
+
* (`meterSegments`, `meterBarProps`, `meterValueText`, `meterPercentText`) — même DOM que `poad-meter` d'ui-angular.
|
|
8
|
+
* Nombres mis en forme dans la langue courante (`Intl.NumberFormat`, `UiI18nProvider`) ; titres et « reste » viennent
|
|
9
|
+
* du catalogue (`display.meterSegment`, `display.remaining`). Style : `@poadio/ui-core/meter.css`.
|
|
10
|
+
*/
|
|
11
|
+
import { type ComponentPropsWithRef, type ReactNode } from 'react';
|
|
12
|
+
import {
|
|
13
|
+
classNames, meterBarProps, meterPercentText, meterRemaining, meterRootClasses, meterSegments, meterValueText,
|
|
14
|
+
type MeterNumberFormat, type MeterOptions, type MeterSegment, type MeterValue,
|
|
15
|
+
} from '@poadio/ui-core';
|
|
16
|
+
import { useUiI18n } from './i18n.js';
|
|
17
|
+
|
|
18
|
+
export interface PoadMeterProps<V extends MeterValue = MeterValue> extends Omit<ComponentPropsWithRef<'div'>, 'children'>, Omit<MeterOptions, 'values' | 'ariaLabel'> {
|
|
19
|
+
readonly values?: readonly V[];
|
|
20
|
+
readonly unit?: string;
|
|
21
|
+
/** Légende. Défaut : oui. */
|
|
22
|
+
readonly showLabels?: boolean;
|
|
23
|
+
/** Ligne « reste » dans la légende. */
|
|
24
|
+
readonly showRemaining?: boolean;
|
|
25
|
+
/** Libellé du reste ; absent : message `display.remaining` du catalogue. */
|
|
26
|
+
readonly remainingLabel?: string;
|
|
27
|
+
readonly 'aria-label'?: string;
|
|
28
|
+
/** Rendu d'une entrée de la légende — `poadMeterLabel` en Angular. */
|
|
29
|
+
readonly renderLabel?: (segment: MeterSegment<V>, percent: number) => ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function PoadMeter<V extends MeterValue = MeterValue>({
|
|
33
|
+
values = [], min = 0, max = 100, unit = '', orientation, showLabels = true, labelPosition = 'end', size, showRemaining, remainingLabel,
|
|
34
|
+
'aria-label': ariaLabel, renderLabel, className, ...rest
|
|
35
|
+
}: PoadMeterProps<V>) {
|
|
36
|
+
const { locale, t, text } = useUiI18n();
|
|
37
|
+
const format: MeterNumberFormat = (v, o) => new Intl.NumberFormat(locale, o).format(v);
|
|
38
|
+
const segments = meterSegments(values, min, max);
|
|
39
|
+
const remaining = meterRemaining(values, min, max);
|
|
40
|
+
const bar = meterBarProps({ values, min, max, ariaLabel });
|
|
41
|
+
const val = (v: number) => meterValueText(format, v, unit);
|
|
42
|
+
const pct = (p: number) => meterPercentText(format, p);
|
|
43
|
+
const legend = showLabels && (
|
|
44
|
+
<div className="mt__legend">
|
|
45
|
+
{segments.map((s, i) => (
|
|
46
|
+
<div key={i} className="mt__li">
|
|
47
|
+
{renderLabel ? renderLabel(s, s.percent) : (
|
|
48
|
+
<><i style={{ background: s.color }} /><span className="lb">{s.label}</span><span className="v">{val(s.value)} <small>({pct(s.percent)})</small></span></>
|
|
49
|
+
)}
|
|
50
|
+
</div>
|
|
51
|
+
))}
|
|
52
|
+
{showRemaining && remaining > 0 && (
|
|
53
|
+
<div className="mt__li is-rest"><i /><span className="lb">{text(remainingLabel, 'display.remaining')}</span><span className="v">{val(remaining)}</span></div>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
return (
|
|
58
|
+
<div {...rest} className={classNames('poad-meter', meterRootClasses({ orientation, size, labelPosition }), className)}>
|
|
59
|
+
{labelPosition === 'start' && legend}
|
|
60
|
+
<div
|
|
61
|
+
className="mt__bar" role={bar.role} aria-valuemin={Number(bar['aria-valuemin'])} aria-valuemax={Number(bar['aria-valuemax'])}
|
|
62
|
+
aria-valuenow={Number(bar['aria-valuenow'])} aria-label={bar['aria-label'] ?? undefined}
|
|
63
|
+
>
|
|
64
|
+
{segments.map((s, i) => (
|
|
65
|
+
<div key={i} className="mt__seg" style={{ flexBasis: `${s.percent}%`, background: s.color }} title={t('display.meterSegment', { label: s.label, value: val(s.value), percent: pct(s.percent) })} />
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
{labelPosition === 'end' && legend}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
package/src/number.tsx
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadNumber value={port} onValueChange={setPort} min={1} max={65535} suffix=" ms" showButtons /> contrôlé
|
|
4
|
+
* <PoadNumber defaultValue={12.5} decimals={2} /> non contrôlé
|
|
5
|
+
*
|
|
6
|
+
* La logique (texte en cours de frappe, lecture `,` ou `.`, bornes, arrondi, mise en forme `Intl` dans la langue de
|
|
7
|
+
* `UiI18nProvider` ou de `locale`, ↑ / ↓ ± pas, Maj × 10, Home / End, Entrée, boutons, attributs `spinbutton`) est la
|
|
8
|
+
* machine `number` de @poadio/ui-core. Même DOM, mêmes classes, même ARIA que `poad-number` d'ui-angular. Style :
|
|
9
|
+
* `@poadio/ui-core/number.css` (+ `icon.css`).
|
|
10
|
+
*
|
|
11
|
+
* `onValueChange` : changements validés par l'utilisateur (sortie du champ, touches, boutons). `ref` désigne
|
|
12
|
+
* l'`<input>` ; `className` et les autres props vont sur la racine `<span class="poad-number">`.
|
|
13
|
+
*/
|
|
14
|
+
import { useState, type ComponentPropsWithoutRef, type Ref } from 'react';
|
|
15
|
+
import {
|
|
16
|
+
classNames, numberButtons, numberControlProps, numberDisplay, numberHandlesKey, numberRootClasses, numberTransition,
|
|
17
|
+
type NumberElementOptions, type NumberEvent, type NumberState,
|
|
18
|
+
} from '@poadio/ui-core';
|
|
19
|
+
import { useControllable } from './controllable.js';
|
|
20
|
+
import { useUiI18n } from './i18n.js';
|
|
21
|
+
import { PoadIcon } from './icon.js';
|
|
22
|
+
|
|
23
|
+
export interface PoadNumberProps extends Omit<ComponentPropsWithoutRef<'span'>, 'onChange' | 'defaultValue' | 'onFocus' | 'onBlur'>, NumberElementOptions {
|
|
24
|
+
/** Valeur imposée (mode contrôlé) ; `null` = vide. */
|
|
25
|
+
readonly value?: number | null;
|
|
26
|
+
readonly defaultValue?: number | null;
|
|
27
|
+
/** Appelé quand l'UTILISATEUR change la valeur. */
|
|
28
|
+
readonly onValueChange?: (value: number | null) => void;
|
|
29
|
+
/** Focus pris (`true`) ou perdu (`false`) par le champ. */
|
|
30
|
+
readonly onFocusChange?: (focused: boolean) => void;
|
|
31
|
+
/** Langue de mise en forme ; défaut : celle de `UiI18nProvider`. */
|
|
32
|
+
readonly locale?: string;
|
|
33
|
+
readonly prefix?: string;
|
|
34
|
+
readonly suffix?: string;
|
|
35
|
+
readonly placeholder?: string;
|
|
36
|
+
readonly showButtons?: boolean;
|
|
37
|
+
readonly disabled?: boolean;
|
|
38
|
+
readonly readOnly?: boolean;
|
|
39
|
+
readonly id?: string;
|
|
40
|
+
readonly 'aria-label'?: string;
|
|
41
|
+
readonly 'aria-describedby'?: string;
|
|
42
|
+
readonly ref?: Ref<HTMLInputElement>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function PoadNumber({
|
|
46
|
+
value, defaultValue = null, onValueChange, onFocusChange, locale, prefix, suffix, placeholder, showButtons, disabled, readOnly, min, max, step, decimals,
|
|
47
|
+
invalid, size, id, 'aria-label': ariaLabel, 'aria-describedby': describedBy, ref, className, ...rest
|
|
48
|
+
}: PoadNumberProps) {
|
|
49
|
+
const i18n = useUiI18n();
|
|
50
|
+
const [current, setCurrent] = useControllable(value, defaultValue);
|
|
51
|
+
const [editing, setEditing] = useState<string | null>(null);
|
|
52
|
+
const options: NumberElementOptions = { min, max, step, decimals, invalid, size };
|
|
53
|
+
const state: NumberState = { value: current ?? null, editing, disabled: !!disabled, readonly: !!readOnly };
|
|
54
|
+
const control = numberControlProps(state, options);
|
|
55
|
+
const buttons = numberButtons(state, options);
|
|
56
|
+
|
|
57
|
+
const send = (event: NumberEvent) => {
|
|
58
|
+
const next = numberTransition(state, event, options);
|
|
59
|
+
if (next === state) return;
|
|
60
|
+
setEditing(next.editing);
|
|
61
|
+
if (next.value !== state.value) { setCurrent(next.value); onValueChange?.(next.value); }
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<span {...rest} className={classNames('poad-number', numberRootClasses(state, options), className)}>
|
|
66
|
+
{prefix && <span className="poad-number__affix">{prefix}</span>}
|
|
67
|
+
<input
|
|
68
|
+
ref={ref} id={id} className="poad-number__input" type={control.type} inputMode={control.inputmode} role={control.role}
|
|
69
|
+
value={numberDisplay(state, locale ?? i18n.locale, options)} placeholder={placeholder} disabled={control.disabled} readOnly={control.readonly}
|
|
70
|
+
aria-valuemin={control['aria-valuemin'] ?? undefined} aria-valuemax={control['aria-valuemax'] ?? undefined} aria-valuenow={control['aria-valuenow'] ?? undefined}
|
|
71
|
+
aria-invalid={control['aria-invalid'] ?? undefined} aria-label={ariaLabel} aria-describedby={describedBy}
|
|
72
|
+
onChange={(e) => send({ type: 'input', text: e.target.value })}
|
|
73
|
+
onFocus={() => { send({ type: 'focus' }); onFocusChange?.(true); }}
|
|
74
|
+
onBlur={() => { send({ type: 'blur' }); onFocusChange?.(false); }}
|
|
75
|
+
onKeyDown={(e) => { if (numberHandlesKey(e.key, options)) e.preventDefault(); send({ type: 'keydown', key: e.key, shiftKey: e.shiftKey }); }}
|
|
76
|
+
/>
|
|
77
|
+
{suffix && <span className="poad-number__affix">{suffix}</span>}
|
|
78
|
+
{showButtons && (
|
|
79
|
+
<span className="poad-number__btns">
|
|
80
|
+
<button type="button" tabIndex={-1} aria-label={i18n.t('field.increment')} disabled={buttons.incrementDisabled} onClick={() => send({ type: 'step', direction: 1 })}>
|
|
81
|
+
<PoadIcon name="chevron-up" size={11} />
|
|
82
|
+
</button>
|
|
83
|
+
<button type="button" tabIndex={-1} aria-label={i18n.t('field.decrement')} disabled={buttons.decrementDisabled} onClick={() => send({ type: 'step', direction: -1 })}>
|
|
84
|
+
<PoadIcon name="chevron-down" size={11} />
|
|
85
|
+
</button>
|
|
86
|
+
</span>
|
|
87
|
+
)}
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
}
|
package/src/password.tsx
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadPassword value={pwd} onValueChange={setPwd} feedback autoComplete="new-password" /> contrôlé
|
|
4
|
+
* <PoadPassword defaultValue="" placeholder="…" /> non contrôlé
|
|
5
|
+
*
|
|
6
|
+
* La logique (bouton œil : type du champ, nom du catalogue `field.showPassword` / `field.hidePassword`,
|
|
7
|
+
* `aria-pressed` ; jauge de robustesse et son libellé) est la machine `password` de @poadio/ui-core. Même DOM, mêmes
|
|
8
|
+
* classes, même ARIA que `poad-password` d'ui-angular. Style : `@poadio/ui-core/password.css` (+ `icon.css`).
|
|
9
|
+
*
|
|
10
|
+
* `visible` contrôlé ou non (`defaultVisible`, `onVisibleChange`). `ref` désigne l'`<input>` ; `className` et les
|
|
11
|
+
* autres props vont sur la racine `<div class="poad-password">`.
|
|
12
|
+
*/
|
|
13
|
+
import type { ComponentPropsWithoutRef, Ref } from 'react';
|
|
14
|
+
import { classNames, passwordInputProps, passwordMeter, passwordRootClasses, passwordToggleProps, passwordTransition, type PasswordState } from '@poadio/ui-core';
|
|
15
|
+
import { useControllable } from './controllable.js';
|
|
16
|
+
import { useUiI18n } from './i18n.js';
|
|
17
|
+
import { PoadIcon } from './icon.js';
|
|
18
|
+
|
|
19
|
+
export interface PoadPasswordProps extends Omit<ComponentPropsWithoutRef<'div'>, 'onChange' | 'defaultValue'> {
|
|
20
|
+
readonly value?: string;
|
|
21
|
+
readonly defaultValue?: string;
|
|
22
|
+
/** Appelé à chaque frappe de l'UTILISATEUR. */
|
|
23
|
+
readonly onValueChange?: (value: string) => void;
|
|
24
|
+
/** Mot de passe en clair ? */
|
|
25
|
+
readonly visible?: boolean;
|
|
26
|
+
readonly defaultVisible?: boolean;
|
|
27
|
+
readonly onVisibleChange?: (visible: boolean) => void;
|
|
28
|
+
/** Bouton œil (défaut : oui). */
|
|
29
|
+
readonly toggleMask?: boolean;
|
|
30
|
+
/** Jauge de robustesse. */
|
|
31
|
+
readonly feedback?: boolean;
|
|
32
|
+
readonly invalid?: boolean;
|
|
33
|
+
readonly disabled?: boolean;
|
|
34
|
+
readonly placeholder?: string;
|
|
35
|
+
/** Défaut : `current-password`. */
|
|
36
|
+
readonly autoComplete?: string;
|
|
37
|
+
readonly id?: string;
|
|
38
|
+
readonly name?: string;
|
|
39
|
+
readonly 'aria-label'?: string;
|
|
40
|
+
readonly 'aria-describedby'?: string;
|
|
41
|
+
readonly ref?: Ref<HTMLInputElement>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function PoadPassword({
|
|
45
|
+
value, defaultValue = '', onValueChange, visible, defaultVisible = false, onVisibleChange, toggleMask = true, feedback, invalid, disabled, placeholder,
|
|
46
|
+
autoComplete = 'current-password', id, name, 'aria-label': ariaLabel, 'aria-describedby': describedBy, ref, className, ...rest
|
|
47
|
+
}: PoadPasswordProps) {
|
|
48
|
+
const { t } = useUiI18n();
|
|
49
|
+
const [text, setText] = useControllable(value, defaultValue);
|
|
50
|
+
const [shown, setShown] = useControllable(visible, defaultVisible);
|
|
51
|
+
const state: PasswordState = { visible: !!shown, disabled: !!disabled };
|
|
52
|
+
const field = passwordInputProps(state, { invalid, autocomplete: autoComplete });
|
|
53
|
+
const eye = passwordToggleProps(state);
|
|
54
|
+
const meter = passwordMeter(text, !!feedback);
|
|
55
|
+
const toggle = () => {
|
|
56
|
+
const next = passwordTransition(state, { type: 'toggleVisible' });
|
|
57
|
+
if (next === state) return;
|
|
58
|
+
setShown(next.visible);
|
|
59
|
+
onVisibleChange?.(next.visible);
|
|
60
|
+
};
|
|
61
|
+
return (
|
|
62
|
+
<div {...rest} className={classNames('poad-password', passwordRootClasses(state, { invalid }), className)}>
|
|
63
|
+
<div className="poad-password__box">
|
|
64
|
+
<input
|
|
65
|
+
ref={ref} id={id} name={name} type={field.type} value={text ?? ''} placeholder={placeholder} disabled={field.disabled}
|
|
66
|
+
autoComplete={field.autocomplete ?? undefined} aria-invalid={field['aria-invalid'] ?? undefined} spellCheck={false}
|
|
67
|
+
aria-label={ariaLabel} aria-describedby={describedBy}
|
|
68
|
+
onChange={(e) => { setText(e.target.value); onValueChange?.(e.target.value); }}
|
|
69
|
+
/>
|
|
70
|
+
{toggleMask && (
|
|
71
|
+
<button type="button" aria-label={t(eye.labelKey)} aria-pressed={eye['aria-pressed']} disabled={eye.disabled} onClick={toggle}>
|
|
72
|
+
<PoadIcon name={eye.icon} size={15} />
|
|
73
|
+
</button>
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
{meter && (
|
|
77
|
+
<div className="poad-password__meter" data-level={meter.level} aria-live="polite">
|
|
78
|
+
<i /><i /><i /><i /><span>{t(meter.labelKey)}</span>
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
package/src/popover.tsx
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadPopover trigger={<button>Filtres</button>} placement="bottom" align="start" focusTrap>…contenu…</PoadPopover>
|
|
4
|
+
* <PoadPopover anchor={ref} open={open} onOpenChange={setOpen}>…</PoadPopover> ancré sur un élément de l'application
|
|
5
|
+
*
|
|
6
|
+
* Panneau flottant ancré sur une cible : le `trigger` (cloné : il bascule le panneau et reçoit `aria-haspopup`,
|
|
7
|
+
* `aria-expanded`, `aria-controls`) ou l'élément `anchor`. Ouvert contrôlé (`open` / `onOpenChange`) ou non
|
|
8
|
+
* (`defaultOpen`). Fermé par un appui extérieur, Échap ; `focusTrap` : dialogue modal, focus piégé, rendu à la cible à
|
|
9
|
+
* la fermeture. `mobile="sheet"` : feuille basse sous 768 px. Décisions : `popover` d'ui-core ; couche flottante
|
|
10
|
+
* interne. Même DOM, mêmes classes, même ARIA que `poad-popover`. Style : `@poadio/ui-core/popover.css`,
|
|
11
|
+
* `floating.css`, `sheet.css`.
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
cloneElement, isValidElement, useEffect, useId, useRef,
|
|
15
|
+
type KeyboardEvent, type MouseEvent, type ReactElement, type ReactNode, type Ref, type RefObject,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import {
|
|
18
|
+
POPOVER_ARROW, POPOVER_MARGIN, SHEET_MOBILE_QUERY, classNames, popoverCandidates, popoverDismiss, popoverProps, popoverRestoreFocus, popoverToggle,
|
|
19
|
+
popoverTriggerProps, popoverUseSheet, type FloatingAlign, type FloatingSide, type PopoverMobileMode,
|
|
20
|
+
} from '@poadio/ui-core';
|
|
21
|
+
import { useControllable } from './controllable.js';
|
|
22
|
+
import { PoadSheet, arrowStyle, useDismiss, useFloating, useFocusTrap, useMediaQuery } from './floating.js';
|
|
23
|
+
|
|
24
|
+
export interface PoadPopoverProps {
|
|
25
|
+
/** Élément qui ouvre et ferme le panneau (cloné). */
|
|
26
|
+
readonly trigger?: ReactElement;
|
|
27
|
+
/** Ou : élément d'ancrage tenu par l'application (ouverture contrôlée). */
|
|
28
|
+
readonly anchor?: RefObject<HTMLElement | null>;
|
|
29
|
+
readonly open?: boolean;
|
|
30
|
+
readonly defaultOpen?: boolean;
|
|
31
|
+
readonly onOpenChange?: (open: boolean) => void;
|
|
32
|
+
/** Côté voulu (défaut `bottom`), retourné s'il ne tient pas. */
|
|
33
|
+
readonly placement?: FloatingSide;
|
|
34
|
+
/** Alignement sur la cible (défaut `center`). */
|
|
35
|
+
readonly align?: FloatingAlign;
|
|
36
|
+
/** Distance à la cible (px, défaut 8). */
|
|
37
|
+
readonly offset?: number;
|
|
38
|
+
readonly dismissOnClickOutside?: boolean;
|
|
39
|
+
readonly closeOnEscape?: boolean;
|
|
40
|
+
readonly focusTrap?: boolean;
|
|
41
|
+
readonly showArrow?: boolean;
|
|
42
|
+
readonly hasBackdrop?: boolean;
|
|
43
|
+
readonly width?: number;
|
|
44
|
+
readonly minWidth?: number;
|
|
45
|
+
/** `sheet` : feuille basse sous le seuil mobile ; `popover` (défaut) : ancré partout. */
|
|
46
|
+
readonly mobile?: PopoverMobileMode;
|
|
47
|
+
readonly sheetTitle?: string;
|
|
48
|
+
/** Classe en plus sur `.poad-popover`. */
|
|
49
|
+
readonly className?: string;
|
|
50
|
+
readonly id?: string;
|
|
51
|
+
readonly children?: ReactNode;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type TriggerProps = { ref?: Ref<HTMLElement>; onClick?: (e: MouseEvent<HTMLElement>) => void };
|
|
55
|
+
|
|
56
|
+
export function PoadPopover({
|
|
57
|
+
trigger, anchor: anchorProp, open: openProp, defaultOpen = false, onOpenChange, placement = 'bottom', align = 'center', offset = 8,
|
|
58
|
+
dismissOnClickOutside = true, closeOnEscape = true, focusTrap = false, showArrow = true, hasBackdrop = false, width, minWidth, mobile = 'popover',
|
|
59
|
+
sheetTitle = '', className, id: idProp, children,
|
|
60
|
+
}: PoadPopoverProps) {
|
|
61
|
+
const generated = useId();
|
|
62
|
+
const id = idProp ?? `poad-popover-${generated}`;
|
|
63
|
+
const [open, setOpenInner] = useControllable(openProp, defaultOpen);
|
|
64
|
+
const triggerEl = useRef<HTMLElement | null>(null);
|
|
65
|
+
const anchor = anchorProp ?? triggerEl;
|
|
66
|
+
const floatEl = useRef<HTMLDivElement | null>(null);
|
|
67
|
+
const panelEl = useRef<HTMLDivElement | null>(null);
|
|
68
|
+
const options = { dismissOnClickOutside, closeOnEscape, focusTrap };
|
|
69
|
+
const inSheet = popoverUseSheet(mobile, useMediaQuery(SHEET_MOBILE_QUERY));
|
|
70
|
+
const setOpen = (next: boolean) => { if (next === open) return; setOpenInner(next); onOpenChange?.(next); };
|
|
71
|
+
|
|
72
|
+
const floating = open && !inSheet;
|
|
73
|
+
const { style, placement: placed } = useFloating({
|
|
74
|
+
open: floating, anchor, floating: floatEl, candidates: popoverCandidates(placement, align), offset, margin: POPOVER_MARGIN, shift: true,
|
|
75
|
+
arrow: showArrow ? POPOVER_ARROW : undefined,
|
|
76
|
+
});
|
|
77
|
+
useDismiss(floating && !hasBackdrop, [anchor, floatEl], () => setOpen(false), { outsidePointer: dismissOnClickOutside });
|
|
78
|
+
useFocusTrap(panelEl, floating && focusTrap, popoverRestoreFocus(options));
|
|
79
|
+
// la cible tenue par l'application reçoit les mêmes attributs que le déclencheur cloné
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const el = anchorProp?.current;
|
|
82
|
+
if (!el) return;
|
|
83
|
+
for (const [name, value] of Object.entries(popoverTriggerProps(open, id))) {
|
|
84
|
+
if (value == null) el.removeAttribute(name); else el.setAttribute(name, value);
|
|
85
|
+
}
|
|
86
|
+
}, [anchorProp, open, id]);
|
|
87
|
+
|
|
88
|
+
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
89
|
+
if (popoverDismiss({ type: 'keydown', key: e.key }, options).action === 'close') { e.stopPropagation(); setOpen(false); }
|
|
90
|
+
};
|
|
91
|
+
const side = placed?.side ?? placement;
|
|
92
|
+
const attrs = popoverProps({ id, side, focusTrap, arrow: showArrow });
|
|
93
|
+
const body = (sheet: boolean) => (
|
|
94
|
+
<div
|
|
95
|
+
ref={sheet ? undefined : panelEl} id={attrs.id} role={attrs.role} aria-modal={attrs['aria-modal'] ?? undefined} data-placement={attrs['data-placement']}
|
|
96
|
+
className={classNames('poad-popover', attrs.classes, className)} style={{ width, minWidth }} onKeyDown={onKeyDown}
|
|
97
|
+
>
|
|
98
|
+
{showArrow && <span className="poad-popover__arrow" aria-hidden="true" style={sheet ? undefined : arrowStyle(placed)} />}
|
|
99
|
+
{children}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
let cloned: ReactNode = null;
|
|
104
|
+
if (trigger && isValidElement<TriggerProps>(trigger)) {
|
|
105
|
+
const own = trigger.props;
|
|
106
|
+
const t = popoverTriggerProps(open, id);
|
|
107
|
+
cloned = cloneElement(trigger, {
|
|
108
|
+
ref: (el: HTMLElement | null) => {
|
|
109
|
+
triggerEl.current = el;
|
|
110
|
+
if (typeof own.ref === 'function') own.ref(el);
|
|
111
|
+
else if (own.ref) (own.ref as { current: HTMLElement | null }).current = el;
|
|
112
|
+
},
|
|
113
|
+
'aria-haspopup': t['aria-haspopup'], 'aria-expanded': t['aria-expanded'], 'aria-controls': t['aria-controls'] ?? undefined,
|
|
114
|
+
onClick: (e: MouseEvent<HTMLElement>) => { own.onClick?.(e); setOpen(popoverToggle(open, true) === 'open'); },
|
|
115
|
+
} as TriggerProps);
|
|
116
|
+
}
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
{cloned}
|
|
120
|
+
{floating && hasBackdrop && <div className="poad-floating-backdrop poad-popover-backdrop" onClick={() => dismissOnClickOutside && setOpen(false)} />}
|
|
121
|
+
{floating && <div ref={floatEl} className="poad-floating poad-popover-pane" style={style}>{body(false)}</div>}
|
|
122
|
+
{inSheet && (
|
|
123
|
+
<PoadSheet
|
|
124
|
+
open={open} onClose={() => setOpen(false)} title={sheetTitle} titleId={`${id}-sheet-title`} dismissable={dismissOnClickOutside} closeOnEscape={closeOnEscape}
|
|
125
|
+
>
|
|
126
|
+
{body(true)}
|
|
127
|
+
</PoadSheet>
|
|
128
|
+
)}
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
}
|
package/src/progress.tsx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* <PoadProgress value={62} label="Build" showValue /> <PoadProgress indeterminate aria-label="Upload" />
|
|
4
|
+
* <PoadSpinner size={24} /> (nom accessible : catalogue `display.loading`)
|
|
5
|
+
*
|
|
6
|
+
* Barre de progression et indicateur de chargement : classes, pourcentage et attributs de @poadio/ui-core
|
|
7
|
+
* (`progressClasses`, `progressTrackProps`, `spinnerClasses`) — même DOM que `poad-progress` / `poad-spinner`
|
|
8
|
+
* d'ui-angular. Style : `@poadio/ui-core/progress.css`. 'use client' : l'indicateur lit la langue (`useUiI18n`).
|
|
9
|
+
*/
|
|
10
|
+
import type { ComponentPropsWithRef } from 'react';
|
|
11
|
+
import {
|
|
12
|
+
progressBarWidth, progressClasses, progressPercent, progressShowHead, progressShowValue, progressTrackProps, spinnerClasses,
|
|
13
|
+
type ProgressOptions, type SpinnerSeverity,
|
|
14
|
+
} from '@poadio/ui-core';
|
|
15
|
+
import { useUiI18n } from './i18n.js';
|
|
16
|
+
|
|
17
|
+
export interface PoadProgressProps extends Omit<ComponentPropsWithRef<'div'>, 'children'>, Omit<ProgressOptions, 'ariaLabel'> {
|
|
18
|
+
/** Nom accessible quand il n'y a pas de libellé visible. */
|
|
19
|
+
readonly 'aria-label'?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function PoadProgress({ value = 0, max = 100, indeterminate, severity, size, showValue, striped, label, 'aria-label': ariaLabel, className, ...rest }: PoadProgressProps) {
|
|
23
|
+
const options = { value, max, indeterminate, severity, size, showValue, striped, label, ariaLabel };
|
|
24
|
+
const track = progressTrackProps(options);
|
|
25
|
+
const width = progressBarWidth(options);
|
|
26
|
+
return (
|
|
27
|
+
<div {...rest} className={className ? `${progressClasses(options)} ${className}` : progressClasses(options)}>
|
|
28
|
+
{progressShowHead(options) && (
|
|
29
|
+
<div className="poad-progress__head">
|
|
30
|
+
<span className="poad-progress__label">{label}</span>
|
|
31
|
+
{progressShowValue(options) && <span className="poad-progress__val">{`${progressPercent(value, max)} %`}</span>}
|
|
32
|
+
</div>
|
|
33
|
+
)}
|
|
34
|
+
<div
|
|
35
|
+
className="poad-progress__track" role={track.role} aria-valuemin={Number(track['aria-valuemin'])} aria-valuemax={Number(track['aria-valuemax'])}
|
|
36
|
+
aria-valuenow={track['aria-valuenow'] === null ? undefined : Number(track['aria-valuenow'])} aria-label={track['aria-label'] ?? undefined}
|
|
37
|
+
>
|
|
38
|
+
<div className="poad-progress__bar" style={width ? { width } : undefined} />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PoadSpinnerProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {
|
|
45
|
+
/** Côté en px. Défaut 24. */
|
|
46
|
+
readonly size?: number;
|
|
47
|
+
readonly strokeWidth?: number;
|
|
48
|
+
readonly severity?: SpinnerSeverity;
|
|
49
|
+
/** Nom accessible ; absent : message `display.loading` du catalogue. */
|
|
50
|
+
readonly 'aria-label'?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function PoadSpinner({ size = 24, strokeWidth = 2.5, severity, 'aria-label': ariaLabel, className, style, ...rest }: PoadSpinnerProps) {
|
|
54
|
+
const { text } = useUiI18n();
|
|
55
|
+
return (
|
|
56
|
+
<span
|
|
57
|
+
{...rest} className={className ? `${spinnerClasses(severity)} ${className}` : spinnerClasses(severity)} role="status"
|
|
58
|
+
aria-label={text(ariaLabel, 'display.loading')} style={{ ...style, width: size, height: size }}
|
|
59
|
+
>
|
|
60
|
+
<svg viewBox="0 0 24 24" fill="none">
|
|
61
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth={strokeWidth} strokeOpacity=".2" />
|
|
62
|
+
<path d="M22 12a10 10 0 0 0-10-10" stroke="currentColor" strokeWidth={strokeWidth} strokeLinecap="round" />
|
|
63
|
+
</svg>
|
|
64
|
+
</span>
|
|
65
|
+
);
|
|
66
|
+
}
|