@etic-insa/ui 0.0.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/README.md +549 -9
- package/dist/components/etic/action.d.ts +33 -0
- package/dist/components/etic/action.js +43 -0
- package/dist/components/etic/action.js.map +1 -0
- package/dist/components/etic/app-shell.d.ts +72 -0
- package/dist/components/etic/app-shell.js +218 -0
- package/dist/components/etic/app-shell.js.map +1 -0
- package/dist/components/etic/auth-image.d.ts +48 -0
- package/dist/components/etic/auth-image.js +44 -0
- package/dist/components/etic/auth-image.js.map +1 -0
- package/dist/components/etic/checkbox-list.d.ts +30 -0
- package/dist/components/etic/checkbox-list.js +56 -0
- package/dist/components/etic/checkbox-list.js.map +1 -0
- package/dist/components/etic/confirm-dialog.d.ts +63 -0
- package/dist/components/etic/confirm-dialog.js +84 -0
- package/dist/components/etic/confirm-dialog.js.map +1 -0
- package/dist/components/etic/copy-button.d.ts +24 -0
- package/dist/components/etic/copy-button.js +46 -0
- package/dist/components/etic/copy-button.js.map +1 -0
- package/dist/components/etic/data-table-bulk-actions.d.ts +29 -0
- package/dist/components/etic/data-table-bulk-actions.js +97 -0
- package/dist/components/etic/data-table-bulk-actions.js.map +1 -0
- package/dist/components/etic/data-table-format.d.ts +12 -0
- package/dist/components/etic/data-table-format.js +8 -0
- package/dist/components/etic/data-table-format.js.map +1 -0
- package/dist/components/etic/data-table-pagination.d.ts +22 -0
- package/dist/components/etic/data-table-pagination.js +104 -0
- package/dist/components/etic/data-table-pagination.js.map +1 -0
- package/dist/components/etic/data-table-toolbar.d.ts +69 -0
- package/dist/components/etic/data-table-toolbar.js +127 -0
- package/dist/components/etic/data-table-toolbar.js.map +1 -0
- package/dist/components/etic/data-table-view-options.d.ts +16 -0
- package/dist/components/etic/data-table-view-options.js +151 -0
- package/dist/components/etic/data-table-view-options.js.map +1 -0
- package/dist/components/etic/data-table.d.ts +263 -0
- package/dist/components/etic/data-table.js +403 -0
- package/dist/components/etic/data-table.js.map +1 -0
- package/dist/components/etic/date-picker.d.ts +32 -0
- package/dist/components/etic/date-picker.js +162 -0
- package/dist/components/etic/date-picker.js.map +1 -0
- package/dist/components/etic/delete-button.d.ts +57 -0
- package/dist/components/etic/delete-button.js +38 -0
- package/dist/components/etic/delete-button.js.map +1 -0
- package/dist/components/etic/detail-list.d.ts +14 -0
- package/dist/components/etic/detail-list.js +36 -0
- package/dist/components/etic/detail-list.js.map +1 -0
- package/dist/components/etic/empty-state.d.ts +20 -0
- package/dist/components/etic/empty-state.js +20 -0
- package/dist/components/etic/empty-state.js.map +1 -0
- package/dist/components/etic/error-banner.d.ts +50 -0
- package/dist/components/etic/error-banner.js +89 -0
- package/dist/components/etic/error-banner.js.map +1 -0
- package/dist/components/etic/error-boundary.d.ts +53 -0
- package/dist/components/etic/error-boundary.js +82 -0
- package/dist/components/etic/error-boundary.js.map +1 -0
- package/dist/components/etic/file-upload.d.ts +52 -0
- package/dist/components/etic/file-upload.js +142 -0
- package/dist/components/etic/file-upload.js.map +1 -0
- package/dist/components/etic/form-dialog.d.ts +45 -0
- package/dist/components/etic/form-dialog.js +136 -0
- package/dist/components/etic/form-dialog.js.map +1 -0
- package/dist/components/etic/form-field-context.d.ts +66 -0
- package/dist/components/etic/form-field-context.js +28 -0
- package/dist/components/etic/form-field-context.js.map +1 -0
- package/dist/components/etic/form-field.d.ts +53 -0
- package/dist/components/etic/form-field.js +105 -0
- package/dist/components/etic/form-field.js.map +1 -0
- package/dist/components/etic/icon-toggle.d.ts +33 -0
- package/dist/components/etic/icon-toggle.js +28 -0
- package/dist/components/etic/icon-toggle.js.map +1 -0
- package/dist/components/etic/loading.d.ts +45 -0
- package/dist/components/etic/loading.js +82 -0
- package/dist/components/etic/loading.js.map +1 -0
- package/dist/components/etic/page-container.d.ts +17 -0
- package/dist/components/etic/page-container.js +20 -0
- package/dist/components/etic/page-container.js.map +1 -0
- package/dist/components/etic/page-header.d.ts +58 -0
- package/dist/components/etic/page-header.js +104 -0
- package/dist/components/etic/page-header.js.map +1 -0
- package/dist/components/etic/phone-input.d.ts +31 -0
- package/dist/components/etic/phone-input.js +133 -0
- package/dist/components/etic/phone-input.js.map +1 -0
- package/dist/components/etic/query-boundary.d.ts +50 -0
- package/dist/components/etic/query-boundary.js +25 -0
- package/dist/components/etic/query-boundary.js.map +1 -0
- package/dist/components/etic/search-select.d.ts +41 -0
- package/dist/components/etic/search-select.js +126 -0
- package/dist/components/etic/search-select.js.map +1 -0
- package/dist/components/etic/section-card.d.ts +12 -0
- package/dist/components/etic/section-card.js +23 -0
- package/dist/components/etic/section-card.js.map +1 -0
- package/dist/components/etic/segmented-control.d.ts +29 -0
- package/dist/components/etic/segmented-control.js +44 -0
- package/dist/components/etic/segmented-control.js.map +1 -0
- package/dist/components/etic/stat-tile.d.ts +18 -0
- package/dist/components/etic/stat-tile.js +39 -0
- package/dist/components/etic/stat-tile.js.map +1 -0
- package/dist/components/etic/status-badge.d.ts +16 -0
- package/dist/components/etic/status-badge.js +30 -0
- package/dist/components/etic/status-badge.js.map +1 -0
- package/dist/components/etic/theme-menu.d.ts +21 -0
- package/dist/components/etic/theme-menu.js +72 -0
- package/dist/components/etic/theme-menu.js.map +1 -0
- package/dist/components/etic/tooltip-button.d.ts +29 -0
- package/dist/components/etic/tooltip-button.js +39 -0
- package/dist/components/etic/tooltip-button.js.map +1 -0
- package/dist/components/etic/use-draft-autosave.d.ts +68 -0
- package/dist/components/etic/use-draft-autosave.js +102 -0
- package/dist/components/etic/use-draft-autosave.js.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/alert-dialog.js +95 -0
- package/dist/components/ui/alert-dialog.js.map +1 -0
- package/dist/components/ui/alert.d.ts +10 -0
- package/dist/components/ui/alert.js +47 -0
- package/dist/components/ui/alert.js.map +1 -0
- package/dist/components/ui/avatar.d.ts +11 -0
- package/dist/components/ui/avatar.js +52 -0
- package/dist/components/ui/avatar.js.map +1 -0
- package/dist/components/ui/badge.d.ts +7 -0
- package/dist/components/ui/badge.js +32 -0
- package/dist/components/ui/badge.js.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +10 -0
- package/dist/components/ui/breadcrumb.js +73 -0
- package/dist/components/ui/breadcrumb.js.map +1 -0
- package/dist/components/ui/button-group.d.ts +10 -0
- package/dist/components/ui/button-group.js +42 -0
- package/dist/components/ui/button-group.js.map +1 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/button.js +8 -8
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.d.ts +10 -0
- package/dist/components/ui/calendar.js +96 -0
- package/dist/components/ui/calendar.js.map +1 -0
- package/dist/components/ui/card.d.ts +11 -0
- package/dist/components/ui/card.js +57 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +3 -0
- package/dist/components/ui/checkbox.js +20 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/collapsible.js +25 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/combobox.d.ts +24 -0
- package/dist/components/ui/combobox.js +165 -0
- package/dist/components/ui/combobox.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.js +92 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +29 -0
- package/dist/components/ui/dropdown-menu.js +137 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/empty.d.ts +11 -0
- package/dist/components/ui/empty.js +60 -0
- package/dist/components/ui/empty.js.map +1 -0
- package/dist/components/ui/field.d.ts +24 -0
- package/dist/components/ui/field.js +108 -0
- package/dist/components/ui/field.js.map +1 -0
- package/dist/components/ui/input-group.d.ts +18 -0
- package/dist/components/ui/input-group.js +79 -0
- package/dist/components/ui/input-group.js.map +1 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +16 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/item.d.ts +22 -0
- package/dist/components/ui/item.js +122 -0
- package/dist/components/ui/item.js.map +1 -0
- package/dist/components/ui/kbd.d.ts +3 -0
- package/dist/components/ui/kbd.js +20 -0
- package/dist/components/ui/kbd.js.map +1 -0
- package/dist/components/ui/label.d.ts +3 -0
- package/dist/components/ui/label.js +14 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/native-select.d.ts +8 -0
- package/dist/components/ui/native-select.js +39 -0
- package/dist/components/ui/native-select.js.map +1 -0
- package/dist/components/ui/pagination.d.ts +17 -0
- package/dist/components/ui/pagination.js +81 -0
- package/dist/components/ui/pagination.js.map +1 -0
- package/dist/components/ui/popover.d.ts +9 -0
- package/dist/components/ui/popover.js +55 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/progress.d.ts +7 -0
- package/dist/components/ui/progress.js +45 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +27 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +4 -0
- package/dist/components/ui/scroll-area.js +36 -0
- package/dist/components/ui/scroll-area.js.map +1 -0
- package/dist/components/ui/select.d.ts +15 -0
- package/dist/components/ui/select.js +99 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/separator.d.ts +3 -0
- package/dist/components/ui/separator.js +15 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/sheet.d.ts +14 -0
- package/dist/components/ui/sheet.js +90 -0
- package/dist/components/ui/sheet.js.map +1 -0
- package/dist/components/ui/sidebar.d.ts +63 -0
- package/dist/components/ui/sidebar.js +358 -0
- package/dist/components/ui/sidebar.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/skeleton.js +13 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/slider.d.ts +3 -0
- package/dist/components/ui/slider.js +36 -0
- package/dist/components/ui/slider.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/spinner.js +16 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.js +20 -0
- package/dist/components/ui/switch.js.map +1 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/table.js +67 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/tabs.d.ts +10 -0
- package/dist/components/ui/tabs.js +46 -0
- package/dist/components/ui/tabs.js.map +1 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.js +14 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/components/ui/toggle-group.d.ts +11 -0
- package/dist/components/ui/toggle-group.js +54 -0
- package/dist/components/ui/toggle-group.js.map +1 -0
- package/dist/components/ui/toggle.d.ts +8 -0
- package/dist/components/ui/toggle.js +36 -0
- package/dist/components/ui/toggle.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/components/ui/tooltip.js +42 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/hooks/use-mobile.d.ts +18 -0
- package/dist/hooks/use-mobile.js +16 -0
- package/dist/hooks/use-mobile.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +77 -2
- package/dist/styles.css +39 -4
- package/package.json +19 -7
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ComponentProps, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { AlertDialogContent } from '../ui/alert-dialog';
|
|
3
|
+
import { ActionDialogue } from './action';
|
|
4
|
+
/**
|
|
5
|
+
* Garde renforcée des actions les plus graves : le bouton de confirmation
|
|
6
|
+
* reste désactivé tant que la personne n'a pas saisi `attendu`, que le
|
|
7
|
+
* dialogue n'affiche pas (le nombre d'éléments sélectionnés, lu ailleurs à
|
|
8
|
+
* l'écran, ou le nom de ce qui sera détruit).
|
|
9
|
+
*/
|
|
10
|
+
export interface ConfirmDialogSaisie {
|
|
11
|
+
attendu: string;
|
|
12
|
+
/** Consigne au-dessus du champ : « Saisissez le nombre de… ». */
|
|
13
|
+
libelle: string;
|
|
14
|
+
/** Affiché quand la saisie, aussi longue que la réponse, est fausse. */
|
|
15
|
+
messageErreur: string;
|
|
16
|
+
/** Clavier numérique sur téléphone. */
|
|
17
|
+
numerique?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Où va le focus à la fermeture : celui du `Popup` de Base UI. */
|
|
20
|
+
export type DialogFinalFocus = ComponentProps<typeof AlertDialogContent>["finalFocus"];
|
|
21
|
+
export interface ConfirmDialogProps {
|
|
22
|
+
/** Le titre nomme l'action : « Supprimer le groupe ». */
|
|
23
|
+
titre: string;
|
|
24
|
+
/** La phrase qui nomme ce qui va changer ou être détruit. */
|
|
25
|
+
description: ReactNode;
|
|
26
|
+
/** Sous la description : liste des éléments touchés, conséquences… */
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
/** « Confirmer » par défaut. */
|
|
29
|
+
libelleConfirmer?: string;
|
|
30
|
+
/** Bouton de confirmation rouge ; vrai par défaut. */
|
|
31
|
+
destructif?: boolean;
|
|
32
|
+
saisie?: ConfirmDialogSaisie;
|
|
33
|
+
/**
|
|
34
|
+
* L'action confirmée. Si elle renvoie une promesse, le dialogue l'attend
|
|
35
|
+
* (boutons occupés, impossible à fermer, le focus reste sur le bouton), se
|
|
36
|
+
* ferme quand elle aboutit et affiche l'erreur si elle échoue. Sinon, il se
|
|
37
|
+
* ferme aussitôt. Si elle renvoie `false` (ou une promesse résolue à
|
|
38
|
+
* `false`), il reste ouvert sans erreur : suppression en deux temps, où la
|
|
39
|
+
* page change sa question (« Supprimer quand même »).
|
|
40
|
+
*/
|
|
41
|
+
onConfirmer: ActionDialogue;
|
|
42
|
+
/** Ouverture contrôlée par l'application… */
|
|
43
|
+
ouvert?: boolean;
|
|
44
|
+
onOuvertChange?: (ouvert: boolean) => void;
|
|
45
|
+
/** …ou bouton qui ouvre le dialogue, rendu à sa place. */
|
|
46
|
+
declencheur?: ReactElement;
|
|
47
|
+
/**
|
|
48
|
+
* Où mettre le focus à la fermeture (`finalFocus` de Base UI : un ref, ou
|
|
49
|
+
* une fonction). Par défaut, le déclencheur ; à fournir quand l'action le
|
|
50
|
+
* fait disparaître (ligne supprimée) : la ligne suivante, le titre de la
|
|
51
|
+
* liste…
|
|
52
|
+
*/
|
|
53
|
+
finalFocus?: DialogFinalFocus;
|
|
54
|
+
className?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Confirmation d'une action, sur l'`AlertDialog` de shadcn : le titre nomme
|
|
58
|
+
* l'action, la description ce qu'elle touche, et l'erreur de l'action
|
|
59
|
+
* s'affiche dans le dialogue, resté ouvert (un bandeau dans la page, derrière
|
|
60
|
+
* le voile, passerait inaperçu). `saisie` exige en plus de taper une valeur
|
|
61
|
+
* pour les actions critiques.
|
|
62
|
+
*/
|
|
63
|
+
export declare function ConfirmDialog({ titre, description, children, libelleConfirmer, destructif, saisie, onConfirmer, ouvert, onOuvertChange, declencheur, finalFocus, className, }: ConfirmDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AlertDialog as e, AlertDialogAction as t, AlertDialogContent as n, AlertDialogDescription as r, AlertDialogFooter as i, AlertDialogHeader as a, AlertDialogTitle as o, AlertDialogTrigger as s } from "../ui/alert-dialog.js";
|
|
2
|
+
import { Button as c } from "../ui/button.js";
|
|
3
|
+
import { Field as l, FieldLabel as u } from "../ui/field.js";
|
|
4
|
+
import { Input as d } from "../ui/input.js";
|
|
5
|
+
import { SpinnerBouton as f, useAction as p, useOuvertureDialogue as m } from "./action.js";
|
|
6
|
+
import { ErrorBanner as h } from "./error-banner.js";
|
|
7
|
+
import { useId as g, useRef as _, useState as v } from "react";
|
|
8
|
+
import { jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
9
|
+
// src/components/etic/confirm-dialog.tsx
|
|
10
|
+
function x({ titre: x, description: S, children: C, libelleConfirmer: w = "Confirmer", destructif: T = !0, saisie: E, onConfirmer: D, ouvert: O, onOuvertChange: k, declencheur: A, finalFocus: j, className: M }) {
|
|
11
|
+
let [N, P] = v(""), F = p(), I = m(O, k, F.enCours), L = _(null), R = g(), z = g(), B = N.trim(), V = !E || B === E.attendu, H = !!E && !V && B.length >= E.attendu.length, U = V && !F.enCours, W = () => {
|
|
12
|
+
U && F.lancer(D, () => I.definir(!1));
|
|
13
|
+
};
|
|
14
|
+
return /* @__PURE__ */ b(e, {
|
|
15
|
+
open: I.ouvert,
|
|
16
|
+
onOpenChange: I.changer,
|
|
17
|
+
onOpenChangeComplete: (e) => {
|
|
18
|
+
e || (P(""), F.reinitialiser());
|
|
19
|
+
},
|
|
20
|
+
children: [A ? /* @__PURE__ */ y(s, { render: A }) : null, /* @__PURE__ */ b(n, {
|
|
21
|
+
initialFocus: E ? L : void 0,
|
|
22
|
+
finalFocus: j,
|
|
23
|
+
className: M,
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ b(a, { children: [/* @__PURE__ */ y(o, { children: x }), /* @__PURE__ */ y(r, {
|
|
26
|
+
"aria-live": "polite",
|
|
27
|
+
children: S
|
|
28
|
+
})] }),
|
|
29
|
+
/* @__PURE__ */ y(h, { erreur: F.erreur }),
|
|
30
|
+
C,
|
|
31
|
+
E ? /* @__PURE__ */ b(l, {
|
|
32
|
+
"data-invalid": H || void 0,
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ y(u, {
|
|
35
|
+
htmlFor: R,
|
|
36
|
+
children: E.libelle
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ y(d, {
|
|
39
|
+
ref: L,
|
|
40
|
+
id: R,
|
|
41
|
+
name: "confirmation",
|
|
42
|
+
type: "text",
|
|
43
|
+
inputMode: E.numerique ? "numeric" : void 0,
|
|
44
|
+
autoComplete: "off",
|
|
45
|
+
spellCheck: !1,
|
|
46
|
+
value: N,
|
|
47
|
+
readOnly: F.enCours,
|
|
48
|
+
"aria-invalid": H || void 0,
|
|
49
|
+
"aria-describedby": H ? z : void 0,
|
|
50
|
+
onChange: (e) => P(e.target.value),
|
|
51
|
+
onKeyDown: (e) => {
|
|
52
|
+
e.key === "Enter" && (e.preventDefault(), W());
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ y("div", {
|
|
56
|
+
id: z,
|
|
57
|
+
"data-slot": "field-error",
|
|
58
|
+
"aria-live": "polite",
|
|
59
|
+
className: "text-sm font-normal text-destructive empty:hidden",
|
|
60
|
+
children: H ? E.messageErreur : null
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
}) : null,
|
|
64
|
+
/* @__PURE__ */ b(i, { children: [/* @__PURE__ */ y(c, {
|
|
65
|
+
variant: "outline",
|
|
66
|
+
disabled: F.enCours,
|
|
67
|
+
focusableWhenDisabled: !0,
|
|
68
|
+
onClick: () => I.changer(!1),
|
|
69
|
+
children: "Annuler"
|
|
70
|
+
}), /* @__PURE__ */ b(t, {
|
|
71
|
+
variant: T ? "destructive" : "default",
|
|
72
|
+
disabled: !U,
|
|
73
|
+
focusableWhenDisabled: !0,
|
|
74
|
+
"aria-busy": F.enCours || void 0,
|
|
75
|
+
onClick: W,
|
|
76
|
+
children: [F.enCours ? /* @__PURE__ */ y(f, {}) : null, w]
|
|
77
|
+
})] })
|
|
78
|
+
]
|
|
79
|
+
})]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export { x as ConfirmDialog };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=confirm-dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-dialog.js","names":["ConfirmDialog","saisi","setSaisi","useState","action","useAction","ouverture","useOuvertureDialogue","ouvert","onOuvertChange","champ","useRef","idChamp","useId","idErreur","valeur","correct","saisie","faux","peutConfirmer","confirmer","onConfirmer","AlertDialog","suivant","declencheur","AlertDialogTrigger","AlertDialogContent","AlertDialogHeader","AlertDialogTitle","titre","AlertDialogDescription","description","ErrorBanner","children","Field","FieldLabel","Input","event","AlertDialogFooter","Button","AlertDialogAction","destructif","SpinnerBouton","libelleConfirmer"],"sources":["../../../src/components/etic/confirm-dialog.tsx"],"sourcesContent":["import {\n useId,\n useRef,\n useState,\n type ComponentProps,\n type ReactElement,\n type ReactNode,\n} from \"react\"\n\nimport {\n AlertDialog,\n AlertDialogAction,\n AlertDialogContent,\n AlertDialogDescription,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogTitle,\n AlertDialogTrigger,\n} from \"@etic-ui/components/ui/alert-dialog\"\nimport { Button } from \"@etic-ui/components/ui/button\"\nimport { Field, FieldLabel } from \"@etic-ui/components/ui/field\"\nimport { Input } from \"@etic-ui/components/ui/input\"\nimport {\n SpinnerBouton,\n useAction,\n useOuvertureDialogue,\n type ActionDialogue,\n} from \"@etic-ui/components/etic/action\"\nimport { ErrorBanner } from \"@etic-ui/components/etic/error-banner\"\n\n/**\n * Garde renforcée des actions les plus graves : le bouton de confirmation\n * reste désactivé tant que la personne n'a pas saisi `attendu`, que le\n * dialogue n'affiche pas (le nombre d'éléments sélectionnés, lu ailleurs à\n * l'écran, ou le nom de ce qui sera détruit).\n */\nexport interface ConfirmDialogSaisie {\n attendu: string\n /** Consigne au-dessus du champ : « Saisissez le nombre de… ». */\n libelle: string\n /** Affiché quand la saisie, aussi longue que la réponse, est fausse. */\n messageErreur: string\n /** Clavier numérique sur téléphone. */\n numerique?: boolean\n}\n\n/** Où va le focus à la fermeture : celui du `Popup` de Base UI. */\nexport type DialogFinalFocus = ComponentProps<\n typeof AlertDialogContent\n>[\"finalFocus\"]\n\nexport interface ConfirmDialogProps {\n /** Le titre nomme l'action : « Supprimer le groupe ». */\n titre: string\n /** La phrase qui nomme ce qui va changer ou être détruit. */\n description: ReactNode\n /** Sous la description : liste des éléments touchés, conséquences… */\n children?: ReactNode\n /** « Confirmer » par défaut. */\n libelleConfirmer?: string\n /** Bouton de confirmation rouge ; vrai par défaut. */\n destructif?: boolean\n saisie?: ConfirmDialogSaisie\n /**\n * L'action confirmée. Si elle renvoie une promesse, le dialogue l'attend\n * (boutons occupés, impossible à fermer, le focus reste sur le bouton), se\n * ferme quand elle aboutit et affiche l'erreur si elle échoue. Sinon, il se\n * ferme aussitôt. Si elle renvoie `false` (ou une promesse résolue à\n * `false`), il reste ouvert sans erreur : suppression en deux temps, où la\n * page change sa question (« Supprimer quand même »).\n */\n onConfirmer: ActionDialogue\n /** Ouverture contrôlée par l'application… */\n ouvert?: boolean\n onOuvertChange?: (ouvert: boolean) => void\n /** …ou bouton qui ouvre le dialogue, rendu à sa place. */\n declencheur?: ReactElement\n /**\n * Où mettre le focus à la fermeture (`finalFocus` de Base UI : un ref, ou\n * une fonction). Par défaut, le déclencheur ; à fournir quand l'action le\n * fait disparaître (ligne supprimée) : la ligne suivante, le titre de la\n * liste…\n */\n finalFocus?: DialogFinalFocus\n className?: string\n}\n\n/**\n * Confirmation d'une action, sur l'`AlertDialog` de shadcn : le titre nomme\n * l'action, la description ce qu'elle touche, et l'erreur de l'action\n * s'affiche dans le dialogue, resté ouvert (un bandeau dans la page, derrière\n * le voile, passerait inaperçu). `saisie` exige en plus de taper une valeur\n * pour les actions critiques.\n */\nexport function ConfirmDialog({\n titre,\n description,\n children,\n libelleConfirmer = \"Confirmer\",\n destructif = true,\n saisie,\n onConfirmer,\n ouvert,\n onOuvertChange,\n declencheur,\n finalFocus,\n className,\n}: ConfirmDialogProps) {\n const [saisi, setSaisi] = useState(\"\")\n const action = useAction()\n const ouverture = useOuvertureDialogue(ouvert, onOuvertChange, action.enCours)\n const champ = useRef<HTMLInputElement>(null)\n const idChamp = useId()\n const idErreur = useId()\n\n const valeur = saisi.trim()\n const correct = !saisie || valeur === saisie.attendu\n // Pas de rouge tant que la saisie est plus courte que la réponse : le\n // premier de deux chiffres n'est pas une erreur.\n const faux = !!saisie && !correct && valeur.length >= saisie.attendu.length\n const peutConfirmer = correct && !action.enCours\n\n const confirmer = () => {\n if (!peutConfirmer) return\n void action.lancer(onConfirmer, () => ouverture.definir(false))\n }\n\n return (\n <AlertDialog\n open={ouverture.ouvert}\n onOpenChange={ouverture.changer}\n onOpenChangeComplete={(suivant) => {\n if (suivant) return\n setSaisi(\"\")\n action.reinitialiser()\n }}\n >\n {declencheur ? <AlertDialogTrigger render={declencheur} /> : null}\n <AlertDialogContent\n initialFocus={saisie ? champ : undefined}\n finalFocus={finalFocus}\n className={className}\n >\n <AlertDialogHeader>\n <AlertDialogTitle>{titre}</AlertDialogTitle>\n {/* Région polie : une description changée pendant l'ouverture\n (suppression en deux temps) est lue ; celle de l'ouverture est\n lue avec le dialogue, qu'elle décrit. */}\n <AlertDialogDescription aria-live=\"polite\">\n {description}\n </AlertDialogDescription>\n </AlertDialogHeader>\n <ErrorBanner erreur={action.erreur} />\n {children}\n {saisie ? (\n <Field data-invalid={faux || undefined}>\n <FieldLabel htmlFor={idChamp}>{saisie.libelle}</FieldLabel>\n <Input\n ref={champ}\n id={idChamp}\n name=\"confirmation\"\n type=\"text\"\n inputMode={saisie.numerique ? \"numeric\" : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n value={saisi}\n // En lecture seule plutôt que désactivé pendant l'action : un\n // champ désactivé perdrait le focus (Entrée confirme d'ici).\n readOnly={action.enCours}\n aria-invalid={faux || undefined}\n aria-describedby={faux ? idErreur : undefined}\n onChange={(event) => setSaisi(event.target.value)}\n onKeyDown={(event) => {\n if (event.key !== \"Enter\") return\n event.preventDefault()\n confirmer()\n }}\n />\n {/* Zone montée en permanence, polie : l'erreur apparaît pendant\n la frappe, une alerte la couperait. */}\n <div\n id={idErreur}\n data-slot=\"field-error\"\n aria-live=\"polite\"\n className=\"text-sm font-normal text-destructive empty:hidden\"\n >\n {faux ? saisie.messageErreur : null}\n </div>\n </Field>\n ) : null}\n <AlertDialogFooter>\n {/* Boutons occupés mais focalisables pendant l'action : un bouton\n désactivé nativement perdrait le focus au profit de <body>. */}\n <Button\n variant=\"outline\"\n disabled={action.enCours}\n focusableWhenDisabled\n onClick={() => ouverture.changer(false)}\n >\n Annuler\n </Button>\n <AlertDialogAction\n variant={destructif ? \"destructive\" : \"default\"}\n disabled={!peutConfirmer}\n focusableWhenDisabled\n aria-busy={action.enCours || undefined}\n onClick={confirmer}\n >\n {action.enCours ? <SpinnerBouton /> : null}\n {libelleConfirmer}\n </AlertDialogAction>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialog>\n )\n}\n"],"mappings":";;;;;;;;;AA8FA,SAAgBA,EAAc,EAC5B,UACA,gBACA,aACA,sBAAmB,aACnB,gBAAa,IACb,WACA,gBACA,WACA,mBACA,gBACA,eACA,gBACqB;CACrB,IAAM,CAACC,GAAOC,KAAYC,EAAS,EAAE,GAC/BC,IAASC,EAAU,GACnBC,IAAYC,EAAqBC,GAAQC,GAAgBL,EAAO,OAAO,GACvEM,IAAQC,EAAyB,IAAI,GACrCC,IAAUC,EAAM,GAChBC,IAAWD,EAAM,GAEjBE,IAASd,EAAM,KAAK,GACpBe,IAAU,CAACC,KAAUF,MAAWE,EAAO,SAGvCC,IAAO,CAAC,CAACD,KAAU,CAACD,KAAWD,EAAO,UAAUE,EAAO,QAAQ,QAC/DE,IAAgBH,KAAW,CAACZ,EAAO,SAEnCgB,UAAkB;EACtB,AAAKD,KACLf,EAAY,OAAOiB,SAAmBf,EAAU,QAAQ,EAAK,CAAC;CAChE;CAEA,OACE,kBAACgB,GAAD;EACE,MAAMhB,EAAU;EAChB,cAAcA,EAAU;EACxB,uBAAuB,MAAY;GACjC,AAAIiB,MACJrB,EAAS,EAAE,GACXE,EAAO,cAAc;EACvB;EAPF,UAAA,CASGoB,IAAc,kBAACC,GAAD,EAAoB,QAAQD,EAAc,CAAA,IAAI,MAC7D,kBAACE,GAAD;GACE,cAAcT,IAASP,IAAQ,KAAA;GACnB;GACD;GAHb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AAA;GACD;EACT,CAAA,CAAA;;AAEjB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TooltipButtonProps } from './tooltip-button';
|
|
2
|
+
export interface CopyButtonProps extends Omit<TooltipButtonProps, "value" | "onClick" | "children" | "infobulle"> {
|
|
3
|
+
/** Texte copié. */
|
|
4
|
+
valeur: string;
|
|
5
|
+
/** Infobulle et nom accessible : ce qui est copié. « Copier » par défaut. */
|
|
6
|
+
libelle?: string;
|
|
7
|
+
/** Après la copie, deux secondes. « Copié ! » par défaut. */
|
|
8
|
+
libelleCopie?: string;
|
|
9
|
+
/** Quand le navigateur refuse la copie, quatre secondes. « Copie
|
|
10
|
+
* impossible : copiez le texte à la main » par défaut. */
|
|
11
|
+
libelleEchec?: string;
|
|
12
|
+
/** Appelé après une copie réussie (un secret montré une seule fois…). */
|
|
13
|
+
onCopie?: () => void;
|
|
14
|
+
/** Appelé quand la copie est refusée (permission, contexte non sûr). */
|
|
15
|
+
onEchec?: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Bouton de copie : une icône seule, son libellé dans l'infobulle et le nom
|
|
19
|
+
* accessible. Après la copie, une coche et « Copié ! » pendant deux
|
|
20
|
+
* secondes ; si le navigateur la refuse, une croix et « Copie impossible ».
|
|
21
|
+
* Les deux sont annoncés aux lecteurs d'écran. `verrou` comme pour
|
|
22
|
+
* `TooltipButton`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function CopyButton({ valeur, libelle, libelleCopie, libelleEchec, onCopie, onEchec, variant, size, className, ...props }: CopyButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TooltipButton as e } from "./tooltip-button.js";
|
|
2
|
+
import { cn as t } from "cn";
|
|
3
|
+
import { useEffect as n, useRef as r, useState as i } from "react";
|
|
4
|
+
import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
5
|
+
import { CheckIcon as c, CopyIcon as l, XIcon as u } from "lucide-react";
|
|
6
|
+
// src/components/etic/copy-button.tsx
|
|
7
|
+
async function d(e) {
|
|
8
|
+
if (navigator.clipboard?.writeText) try {
|
|
9
|
+
return await navigator.clipboard.writeText(e), !0;
|
|
10
|
+
} catch {}
|
|
11
|
+
let t = document.createElement("textarea");
|
|
12
|
+
try {
|
|
13
|
+
return t.value = e, t.setAttribute("readonly", ""), t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select(), document.execCommand("copy");
|
|
14
|
+
} catch {
|
|
15
|
+
return !1;
|
|
16
|
+
} finally {
|
|
17
|
+
t.remove();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function f({ valeur: f, libelle: p = "Copier", libelleCopie: m = "Copié !", libelleEchec: h = "Copie impossible\xA0: copiez le texte à la main", onCopie: g, onEchec: _, variant: v = "outline", size: y = "icon-sm", className: b, ...x }) {
|
|
21
|
+
let [S, C] = i(null), w = r(void 0);
|
|
22
|
+
n(() => () => clearTimeout(w.current), []);
|
|
23
|
+
let T = async () => {
|
|
24
|
+
let e = await d(f);
|
|
25
|
+
C(e ? "copie" : "echec"), e ? g?.() : _?.(), clearTimeout(w.current), w.current = setTimeout(() => C(null), e ? 2e3 : 4e3);
|
|
26
|
+
}, E = S === "copie" ? m : S === "echec" ? h : "";
|
|
27
|
+
return /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ o(e, {
|
|
28
|
+
variant: v,
|
|
29
|
+
size: y,
|
|
30
|
+
"aria-label": p,
|
|
31
|
+
infobulle: E || p,
|
|
32
|
+
"data-copie": S === "copie" || void 0,
|
|
33
|
+
"data-echec": S === "echec" || void 0,
|
|
34
|
+
className: t(S === "copie" && "text-success", S === "echec" && "text-destructive", b),
|
|
35
|
+
onClick: T,
|
|
36
|
+
...x,
|
|
37
|
+
children: o(S === "copie" ? c : S === "echec" ? u : l, {})
|
|
38
|
+
}), /* @__PURE__ */ o("span", {
|
|
39
|
+
className: "sr-only",
|
|
40
|
+
role: "status",
|
|
41
|
+
children: E
|
|
42
|
+
})] });
|
|
43
|
+
}
|
|
44
|
+
export { f as CopyButton };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=copy-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-button.js","names":["_Fragment","Fragment$1","copier","texte","champ","CopyButton","props","etat","setEtat","useState","minuterie","useRef","surClic","reussi","valeur","onCopie","onEchec","annonce","libelleCopie","libelleEchec","TooltipButton","libelle","cn","className","jsx","CheckIcon","XIcon","CopyIcon"],"sources":["../../../src/components/etic/copy-button.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\"\nimport { cn } from \"cn\"\nimport { CheckIcon, CopyIcon, XIcon } from \"lucide-react\"\n\nimport {\n TooltipButton,\n type TooltipButtonProps,\n} from \"@etic-ui/components/etic/tooltip-button\"\n\n/** Écrit dans le presse-papiers : l'API asynchrone si elle est là, sinon un\n * champ caché et `execCommand` (contexte non sécurisé, vieux navigateur). */\nasync function copier(texte: string): Promise<boolean> {\n if (navigator.clipboard?.writeText) {\n try {\n await navigator.clipboard.writeText(texte)\n return true\n } catch {\n // On tente l'ancienne méthode.\n }\n }\n const champ = document.createElement(\"textarea\")\n try {\n champ.value = texte\n champ.setAttribute(\"readonly\", \"\")\n champ.style.position = \"fixed\"\n champ.style.opacity = \"0\"\n document.body.appendChild(champ)\n champ.select()\n return document.execCommand(\"copy\")\n } catch {\n return false\n } finally {\n // Retiré même si execCommand lève (absent ou refusé).\n champ.remove()\n }\n}\n\nexport interface CopyButtonProps extends Omit<\n TooltipButtonProps,\n \"value\" | \"onClick\" | \"children\" | \"infobulle\"\n> {\n /** Texte copié. */\n valeur: string\n /** Infobulle et nom accessible : ce qui est copié. « Copier » par défaut. */\n libelle?: string\n /** Après la copie, deux secondes. « Copié ! » par défaut. */\n libelleCopie?: string\n /** Quand le navigateur refuse la copie, quatre secondes. « Copie\n * impossible : copiez le texte à la main » par défaut. */\n libelleEchec?: string\n /** Appelé après une copie réussie (un secret montré une seule fois…). */\n onCopie?: () => void\n /** Appelé quand la copie est refusée (permission, contexte non sûr). */\n onEchec?: () => void\n}\n\n/**\n * Bouton de copie : une icône seule, son libellé dans l'infobulle et le nom\n * accessible. Après la copie, une coche et « Copié ! » pendant deux\n * secondes ; si le navigateur la refuse, une croix et « Copie impossible ».\n * Les deux sont annoncés aux lecteurs d'écran. `verrou` comme pour\n * `TooltipButton`.\n */\nexport function CopyButton({\n valeur,\n libelle = \"Copier\",\n libelleCopie = \"Copié !\",\n libelleEchec = \"Copie impossible : copiez le texte à la main\",\n onCopie,\n onEchec,\n variant = \"outline\",\n size = \"icon-sm\",\n className,\n ...props\n}: CopyButtonProps) {\n const [etat, setEtat] = useState<\"copie\" | \"echec\" | null>(null)\n const minuterie = useRef<ReturnType<typeof setTimeout>>(undefined)\n\n useEffect(() => () => clearTimeout(minuterie.current), [])\n\n const surClic = async () => {\n const reussi = await copier(valeur)\n setEtat(reussi ? \"copie\" : \"echec\")\n if (reussi) onCopie?.()\n else onEchec?.()\n clearTimeout(minuterie.current)\n minuterie.current = setTimeout(() => setEtat(null), reussi ? 2000 : 4000)\n }\n\n const annonce =\n etat === \"copie\" ? libelleCopie : etat === \"echec\" ? libelleEchec : \"\"\n return (\n <>\n <TooltipButton\n variant={variant}\n size={size}\n // Nom constant : le résultat est annoncé par la zone ci-dessous.\n aria-label={libelle}\n infobulle={annonce || libelle}\n data-copie={etat === \"copie\" || undefined}\n data-echec={etat === \"echec\" || undefined}\n className={cn(\n etat === \"copie\" && \"text-success\",\n etat === \"echec\" && \"text-destructive\",\n className\n )}\n onClick={surClic}\n {...props}\n >\n {etat === \"copie\" ? (\n <CheckIcon />\n ) : etat === \"echec\" ? (\n <XIcon />\n ) : (\n <CopyIcon />\n )}\n </TooltipButton>\n {/* Hors du bouton (ses enfants ne sont pas exposés) et montée en\n permanence : une zone insérée avec son texte n'est pas toujours lue. */}\n <span className=\"sr-only\" role=\"status\">\n {annonce}\n </span>\n </>\n )\n}\n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,UACCkB,EADDjB,MAAS,UACPkB,IACClB,MAAS,UACVmB,IAEAC,GAJD,CAAY,CAID;CAEA,CAAA,GAGf,kBAAC,QAAD;EAAM,WAAU;EAAU,MAAK;EAC5B,UAAAV;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { RowData } from '@tanstack/react-table';
|
|
3
|
+
import { DataTableInstance } from './data-table';
|
|
4
|
+
import { DataTableUnite } from './data-table-format';
|
|
5
|
+
export interface DataTableBulkActionsProps<TData extends RowData> {
|
|
6
|
+
table: DataTableInstance<TData>;
|
|
7
|
+
/** Nom des éléments : « 3 personnes sélectionnées ». « élément »,
|
|
8
|
+
* « éléments » par défaut. */
|
|
9
|
+
unite?: DataTableUnite;
|
|
10
|
+
/** Accorde « sélectionnées » au féminin. */
|
|
11
|
+
feminin?: boolean;
|
|
12
|
+
/** Les actions : boutons `size="sm"`. Les lignes visées viennent de
|
|
13
|
+
* `table.getSelectedRowModel()` (ou `getSelectedRowIds()`) ; quand
|
|
14
|
+
* `toutSelectionne` est vrai, l'action porte sur tous les éléments. */
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Barre d'actions groupées : apparaît avec la sélection, dit combien
|
|
20
|
+
* d'éléments sont sélectionnés, porte les actions et « Tout désélectionner »
|
|
21
|
+
* (aussi Échap, quand le focus est dans le tableau ou dans la barre). À
|
|
22
|
+
* placer une fois, après le tableau : collante en bas de l'écran, elle reste
|
|
23
|
+
* à portée au-dessus d'un long tableau sans le décaler.
|
|
24
|
+
*
|
|
25
|
+
* Quand elle disparaît avec le focus dedans (« Tout désélectionner », Échap,
|
|
26
|
+
* action qui vide la sélection), le focus passe à la case d'en-tête du
|
|
27
|
+
* tableau plutôt que de tomber sur `<body>`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function DataTableBulkActions<TData extends RowData>({ table, unite, feminin, children, className, }: DataTableBulkActionsProps<TData>): import("react").JSX.Element;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Button as e } from "../ui/button.js";
|
|
2
|
+
import { Kbd as t } from "../ui/kbd.js";
|
|
3
|
+
import { Separator as n } from "../ui/separator.js";
|
|
4
|
+
import { focaliserTableau as r } from "./data-table.js";
|
|
5
|
+
import { UNITE_PAR_DEFAUT as i, nombreFr as a, participe as o, uniteAccordee as s } from "./data-table-format.js";
|
|
6
|
+
import { cn as c } from "cn";
|
|
7
|
+
import { useEffect as l, useEffectEvent as u, useId as d, useLayoutEffect as f, useRef as p, useState as m } from "react";
|
|
8
|
+
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
9
|
+
import { XIcon as v } from "lucide-react";
|
|
10
|
+
// src/components/etic/data-table-bulk-actions.tsx
|
|
11
|
+
function y(e) {
|
|
12
|
+
if (e.defaultPrevented) return !0;
|
|
13
|
+
let t = e.target;
|
|
14
|
+
return t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)) && !(t instanceof HTMLInputElement && t.type === "checkbox");
|
|
15
|
+
}
|
|
16
|
+
function b({ table: b, unite: x = i, feminin: S = !1, children: C, className: w }) {
|
|
17
|
+
let T = d(), E = b.options.meta, D = p(null), O = E?.toutSelectionne && E.total !== void 0 ? E.total : b.getSelectedRowIds().length, k = O > 0, A = `${s(O, x)} ${o("sélectionné", O, S)}`, j = p(null), M = () => E?.racine.current ?? null, N = () => {
|
|
18
|
+
D.current?.contains(document.activeElement) && r(M()), E ? E.toutDeselectionner() : b.resetRowSelection(!0);
|
|
19
|
+
};
|
|
20
|
+
f(() => {
|
|
21
|
+
if (k) return;
|
|
22
|
+
let e = j.current;
|
|
23
|
+
j.current = null, !e || e.isConnected || document.activeElement && document.activeElement !== document.body || r(M());
|
|
24
|
+
});
|
|
25
|
+
let [P, F] = m(k), [I, L] = m(!1);
|
|
26
|
+
k !== P && (F(k), L(!k));
|
|
27
|
+
let R = u((e) => {
|
|
28
|
+
if (e.key !== "Escape" || y(e)) return;
|
|
29
|
+
let t = e.target;
|
|
30
|
+
((M()?.contains(t) ?? !1) || D.current?.contains(t)) && N();
|
|
31
|
+
});
|
|
32
|
+
return l(() => {
|
|
33
|
+
if (k) return document.addEventListener("keydown", R), () => document.removeEventListener("keydown", R);
|
|
34
|
+
}, [k]), /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("div", {
|
|
35
|
+
"data-slot": "data-table-bulk-actions-status",
|
|
36
|
+
className: "sr-only",
|
|
37
|
+
"aria-live": "polite",
|
|
38
|
+
"aria-atomic": "true",
|
|
39
|
+
children: k ? `${a(O)} ${A}` : I ? "Sélection effacée" : null
|
|
40
|
+
}), k ? /* @__PURE__ */ _("div", {
|
|
41
|
+
ref: D,
|
|
42
|
+
"data-slot": "data-table-bulk-actions",
|
|
43
|
+
role: "toolbar",
|
|
44
|
+
"aria-labelledby": T,
|
|
45
|
+
onFocus: (e) => {
|
|
46
|
+
j.current = e.target;
|
|
47
|
+
},
|
|
48
|
+
onBlur: (e) => {
|
|
49
|
+
let t = e.relatedTarget;
|
|
50
|
+
t && !e.currentTarget.contains(t) && (j.current = null);
|
|
51
|
+
},
|
|
52
|
+
className: c("sticky bottom-4 z-20 mx-auto flex w-fit max-w-full flex-wrap items-center gap-2 rounded-xl border bg-popover p-1.5 pl-3 text-sm text-popover-foreground shadow-lg", w),
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ _("span", {
|
|
55
|
+
id: T,
|
|
56
|
+
className: "whitespace-nowrap",
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ g("strong", {
|
|
59
|
+
className: "font-medium tabular-nums",
|
|
60
|
+
children: a(O)
|
|
61
|
+
}),
|
|
62
|
+
" ",
|
|
63
|
+
A
|
|
64
|
+
]
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ g(n, {
|
|
67
|
+
orientation: "vertical",
|
|
68
|
+
className: "h-5 self-center!"
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ g("div", {
|
|
71
|
+
className: "flex flex-wrap items-center gap-1.5",
|
|
72
|
+
children: C
|
|
73
|
+
}),
|
|
74
|
+
/* @__PURE__ */ _(e, {
|
|
75
|
+
variant: "ghost",
|
|
76
|
+
size: "sm",
|
|
77
|
+
onClick: N,
|
|
78
|
+
"aria-keyshortcuts": "Escape",
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ g(v, { "data-icon": "inline-start" }),
|
|
81
|
+
/* @__PURE__ */ g("span", {
|
|
82
|
+
className: "max-sm:sr-only",
|
|
83
|
+
children: "Tout désélectionner"
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ g(t, {
|
|
86
|
+
"aria-hidden": !0,
|
|
87
|
+
className: "ml-1 max-sm:hidden",
|
|
88
|
+
children: "Échap"
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}) : null] });
|
|
94
|
+
}
|
|
95
|
+
export { b as DataTableBulkActions };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=data-table-bulk-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-bulk-actions.js","names":["_Fragment","Fragment$1","echapPourUnChamp","event","cible","DataTableBulkActions","UNITE_PAR_DEFAUT","idResume","useId","meta","table","barreRef","useRef","nombre","visible","resume","uniteAccordee","unite","participe","feminin","focusDansBarre","racine","toutDeselectionner","focaliserTableau","perdu","etaitVisible","setEtaitVisible","useState","effacee","setEffacee","surTouche","useEffectEvent","useEffect","nombreFr","vers","cn","className","Separator","Button","XIcon","Kbd"],"sources":["../../../src/components/etic/data-table-bulk-actions.tsx"],"sourcesContent":["import {\n useEffect,\n useEffectEvent,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\"\nimport type { RowData } from \"@tanstack/react-table\"\nimport { cn } from \"cn\"\nimport { XIcon } from \"lucide-react\"\n\nimport { Button } from \"@etic-ui/components/ui/button\"\nimport { Kbd } from \"@etic-ui/components/ui/kbd\"\nimport { Separator } from \"@etic-ui/components/ui/separator\"\nimport {\n focaliserTableau,\n type DataTableInstance,\n} from \"@etic-ui/components/etic/data-table\"\nimport {\n UNITE_PAR_DEFAUT,\n nombreFr,\n participe,\n uniteAccordee,\n type DataTableUnite,\n} from \"@etic-ui/components/etic/data-table-format\"\n\n/** Un Échap tapé dans un champ (recherche dans une cellule…) lui revient. */\nfunction echapPourUnChamp(event: KeyboardEvent): boolean {\n if (event.defaultPrevented) return true\n const cible = event.target\n return (\n cible instanceof HTMLElement &&\n (cible.isContentEditable ||\n /^(INPUT|TEXTAREA|SELECT)$/.test(cible.tagName)) &&\n !(cible instanceof HTMLInputElement && cible.type === \"checkbox\")\n )\n}\n\nexport interface DataTableBulkActionsProps<TData extends RowData> {\n table: DataTableInstance<TData>\n /** Nom des éléments : « 3 personnes sélectionnées ». « élément »,\n * « éléments » par défaut. */\n unite?: DataTableUnite\n /** Accorde « sélectionnées » au féminin. */\n feminin?: boolean\n /** Les actions : boutons `size=\"sm\"`. Les lignes visées viennent de\n * `table.getSelectedRowModel()` (ou `getSelectedRowIds()`) ; quand\n * `toutSelectionne` est vrai, l'action porte sur tous les éléments. */\n children: ReactNode\n className?: string\n}\n\n/**\n * Barre d'actions groupées : apparaît avec la sélection, dit combien\n * d'éléments sont sélectionnés, porte les actions et « Tout désélectionner »\n * (aussi Échap, quand le focus est dans le tableau ou dans la barre). À\n * placer une fois, après le tableau : collante en bas de l'écran, elle reste\n * à portée au-dessus d'un long tableau sans le décaler.\n *\n * Quand elle disparaît avec le focus dedans (« Tout désélectionner », Échap,\n * action qui vide la sélection), le focus passe à la case d'en-tête du\n * tableau plutôt que de tomber sur `<body>`.\n */\nexport function DataTableBulkActions<TData extends RowData>({\n table,\n unite = UNITE_PAR_DEFAUT,\n feminin = false,\n children,\n className,\n}: DataTableBulkActionsProps<TData>) {\n const idResume = useId()\n const meta = table.options.meta\n const barreRef = useRef<HTMLDivElement>(null)\n // « Tous sélectionnés » : le total, pas seulement les lignes de la page.\n const nombre =\n meta?.toutSelectionne && meta.total !== undefined\n ? meta.total\n : table.getSelectedRowIds().length\n const visible = nombre > 0\n const resume = `${uniteAccordee(nombre, unite)} ${participe(\"sélectionné\", nombre, feminin)}`\n\n // Dernier élément de la barre qui a eu le focus, tant que le focus n'est\n // pas parti ailleurs : s'il disparaît avec la barre, on rattrape le focus.\n const focusDansBarre = useRef<HTMLElement | null>(null)\n const racine = () => meta?.racine.current ?? null\n const toutDeselectionner = () => {\n if (barreRef.current?.contains(document.activeElement))\n focaliserTableau(racine())\n if (meta) meta.toutDeselectionner()\n else table.resetRowSelection(true)\n }\n useLayoutEffect(() => {\n if (visible) return\n const perdu = focusDansBarre.current\n focusDansBarre.current = null\n if (\n perdu &&\n !perdu.isConnected &&\n (!document.activeElement || document.activeElement === document.body)\n )\n focaliserTableau(racine())\n })\n\n // Une sélection effacée est dite, une seule fois : la zone garde sinon le\n // dernier compte, ou rien avant la première sélection.\n const [etaitVisible, setEtaitVisible] = useState(visible)\n const [effacee, setEffacee] = useState(false)\n if (visible !== etaitVisible) {\n setEtaitVisible(visible)\n setEffacee(!visible)\n }\n\n const surTouche = useEffectEvent((event: KeyboardEvent) => {\n if (event.key !== \"Escape\" || echapPourUnChamp(event)) return\n // Échap ne s'adresse à la barre que depuis le tableau ou la barre : pas\n // depuis la navigation, ni depuis un dialogue ou un menu (rendus hors du\n // tableau, dans un portail).\n const cible = event.target as Node\n const dansTableau = racine()?.contains(cible) ?? false\n if (!dansTableau && !barreRef.current?.contains(cible)) return\n toutDeselectionner()\n })\n useEffect(() => {\n if (!visible) return\n document.addEventListener(\"keydown\", surTouche)\n return () => document.removeEventListener(\"keydown\", surTouche)\n }, [visible])\n\n return (\n <>\n {/* Toujours montée : une zone annoncée insérée avec son texte n'est\n pas lue de façon fiable, la première case cochée passerait sous\n silence. */}\n <div\n data-slot=\"data-table-bulk-actions-status\"\n className=\"sr-only\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {visible\n ? `${nombreFr(nombre)} ${resume}`\n : effacee\n ? \"Sélection effacée\"\n : null}\n </div>\n {visible ? (\n <div\n ref={barreRef}\n data-slot=\"data-table-bulk-actions\"\n role=\"toolbar\"\n aria-labelledby={idResume}\n onFocus={(event) => {\n focusDansBarre.current = event.target\n }}\n onBlur={(event) => {\n const vers = event.relatedTarget\n if (vers && !event.currentTarget.contains(vers))\n focusDansBarre.current = null\n }}\n className={cn(\n \"sticky bottom-4 z-20 mx-auto flex w-fit max-w-full flex-wrap items-center gap-2 rounded-xl border bg-popover p-1.5 pl-3 text-sm text-popover-foreground shadow-lg\",\n className\n )}\n >\n <span id={idResume} className=\"whitespace-nowrap\">\n <strong className=\"font-medium tabular-nums\">\n {nombreFr(nombre)}\n </strong>{\" \"}\n {resume}\n </span>\n <Separator orientation=\"vertical\" className=\"h-5 self-center!\" />\n <div className=\"flex flex-wrap items-center gap-1.5\">{children}</div>\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={toutDeselectionner}\n aria-keyshortcuts=\"Escape\"\n >\n <XIcon data-icon=\"inline-start\" />\n {/* Sur mobile, l'icône seule garde la barre sur une ligne. */}\n <span className=\"max-sm:sr-only\">Tout désélectionner</span>\n <Kbd aria-hidden className=\"ml-1 max-sm:hidden\">\n Échap\n </Kbd>\n </Button>\n </div>\n ) : null}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;AA6BA,SAASE,EAAiB,GAA+B;CACvD,IAAIC,EAAM,kBAAkB,OAAO;CACnC,IAAMC,IAAQD,EAAM;CACpB,OACEC,aAAiB,gBAChBA,EAAM,qBACL,4BAA4B,KAAKA,EAAM,OAAO,MAChD,EAAEA,aAAiB,oBAAoBA,EAAM,SAAS;AAE1D;AA2BA,SAAgBC,EAA4C,EAC1D,UACA,WAAQC,GACR,aAAU,IACV,aACA,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AA,CAIE,kBAAC,OAAD;EACE,aAAU;EACV,WAAU;EACV,aAAU;EACV,eAAY;EAEX,UAAAc,IACG,GAAGmB,EAASpB,CAAM,EAAE,GAAGE,MACvBa,IACE,sBACA;CACH,CAAA,GACJd,IACC,kBAAC,OAAD;EACE,KAAKH;EACL,aAAU;EACV,MAAK;EACL,mBAAiBJ;EACjB,UAAU,MAAU;GAClB,EAAe,UAAUJ,EAAM;EACjC;EACA,SAAS,MAAU;GACjB,IAAM+B,IAAO/B,EAAM;GACnB,AAAI+B,KAAQ,CAAC/B,EAAM,cAAc,SAAS+B,CAAI,MAC5C,EAAe,UAAU;EAC7B;EACA,WAAWC,EACT,qKACAC,CACF;EAhBF,UAAA;GAkBE,kBAAC,QAAD;IAAM,IAAI7B;IAAU,WAAU;IAA9B,UAAA;KACE,kBAAC,UAAD;MAAQ,WAAU;MACf,UAAA0B,EAASpB,CAAM;KACV,CAAA;KAAE;KACTE;IACG;;GACN,kBAACsB,GAAD;IAAW,aAAY;IAAW,WAAU;GAAoB,CAAA;GAChE,kBAAC,OAAD;IAAK,WAAU;IAAuC;GAAc,CAAA;GACpE,kBAACC,GAAD;IACE,SAAQ;IACR,MAAK;IACL,SAAShB;IACT,qBAAkB;IAJpB,UAAA;KAME,kBAACiB,GAAD,EAAO,aAAU,eAAgB,CAAA;KAEjC,kBAAC,QAAD;MAAM,WAAU;MAAiB,UAAA;KAAyB,CAAA;KAC1D,kBAACC,GAAD;MAAK,eAAA;MAAY,WAAU;MAAqB,UAAA;KAE3C,CAAA;IACC;;EACL;CACH,CAAA,IAAA,IACJ,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Nom des éléments d'une liste, au singulier et au pluriel. */
|
|
2
|
+
export interface DataTableUnite {
|
|
3
|
+
singulier: string;
|
|
4
|
+
pluriel: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const UNITE_PAR_DEFAUT: DataTableUnite;
|
|
7
|
+
/** 1234 → « 1 234 » (espace fine insécable, comme `Intl`). */
|
|
8
|
+
export declare const nombreFr: (n: number) => string;
|
|
9
|
+
/** Nom accordé au nombre : 0 et 1 au singulier, comme en français. */
|
|
10
|
+
export declare const uniteAccordee: (n: number, unite: DataTableUnite) => string;
|
|
11
|
+
/** Participe accordé : `participe("sélectionné", 3, true)` → « sélectionnées ». */
|
|
12
|
+
export declare const participe: (base: string, n: number, feminin: boolean) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/components/etic/data-table-format.ts
|
|
2
|
+
var e = {
|
|
3
|
+
singulier: "élément",
|
|
4
|
+
pluriel: "éléments"
|
|
5
|
+
}, t = (e) => e.toLocaleString("fr-FR"), n = (e, t) => e > 1 ? t.pluriel : t.singulier, r = (e, t, n) => `${e}${n ? "e" : ""}${t > 1 ? "s" : ""}`;
|
|
6
|
+
export { e as UNITE_PAR_DEFAUT, t as nombreFr, r as participe, n as uniteAccordee };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=data-table-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-format.js","names":["UNITE_PAR_DEFAUT","nombreFr","n","uniteAccordee","unite","participe","base","feminin"],"sources":["../../../src/components/etic/data-table-format.ts"],"sourcesContent":["// Textes chiffrés de la famille DataTable (compteur, proposition « tout\n// sélectionner », barre d'actions groupées) : un seul endroit pour le\n// format français et les accords.\n\n/** Nom des éléments d'une liste, au singulier et au pluriel. */\nexport interface DataTableUnite {\n singulier: string\n pluriel: string\n}\n\nexport const UNITE_PAR_DEFAUT: DataTableUnite = {\n singulier: \"élément\",\n pluriel: \"éléments\",\n}\n\n/** 1234 → « 1 234 » (espace fine insécable, comme `Intl`). */\nexport const nombreFr = (n: number) => n.toLocaleString(\"fr-FR\")\n\n/** Nom accordé au nombre : 0 et 1 au singulier, comme en français. */\nexport const uniteAccordee = (n: number, unite: DataTableUnite) =>\n n > 1 ? unite.pluriel : unite.singulier\n\n/** Participe accordé : `participe(\"sélectionné\", 3, true)` → « sélectionnées ». */\nexport const participe = (base: string, n: number, feminin: boolean) =>\n `${base}${feminin ? \"e\" : \"\"}${n > 1 ? \"s\" : \"\"}`\n"],"mappings":";AAUA,IAAaA,IAAmC;CAC9C,WAAW;CACX,SAAS;AACX,GAGaC,KAAY,MAAcC,EAAE,eAAe,OAAO,GAGlDC,KAAiB,GAAW,MACvCD,IAAI,IAAIE,EAAM,UAAUA,EAAM,WAGnBC,KAAa,GAAc,GAAW,MACjD,GAAGC,IAAOC,IAAU,MAAM,KAAKL,IAAI,IAAI,MAAM"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface DataTablePaginationProps {
|
|
2
|
+
/** Nombre total d'éléments, toutes pages comprises. */
|
|
3
|
+
total: number;
|
|
4
|
+
/** Rang (à partir de 0) du premier élément de la page. */
|
|
5
|
+
decalage: number;
|
|
6
|
+
/** Nombre d'éléments par page. */
|
|
7
|
+
limite: number;
|
|
8
|
+
onDecalageChange: (decalage: number) => void;
|
|
9
|
+
/** Sans lui, pas de choix du nombre par page. Changer de taille ramène à
|
|
10
|
+
* la première page (`onDecalageChange(0)`). */
|
|
11
|
+
onLimiteChange?: (limite: number) => void;
|
|
12
|
+
/** Nombres d'éléments par page proposés. 10, 25, 50 et 100 par défaut. */
|
|
13
|
+
limites?: readonly number[];
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Pagination par décalage (offset/limit, total connu) sur la Pagination de
|
|
18
|
+
* shadcn : précédente, fenêtre de pages, suivante, et le nombre de lignes par
|
|
19
|
+
* page (Select). Rien ne s'affiche quand tout tient sur une page de la plus
|
|
20
|
+
* petite taille.
|
|
21
|
+
*/
|
|
22
|
+
export declare function DataTablePagination({ total, decalage, limite, onDecalageChange, onLimiteChange, limites, className, }: DataTablePaginationProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Button as e } from "../ui/button.js";
|
|
2
|
+
import { Pagination as t, PaginationContent as n, PaginationEllipsis as r, PaginationItem as i } from "../ui/pagination.js";
|
|
3
|
+
import { Select as a, SelectContent as o, SelectItem as s, SelectTrigger as c, SelectValue as l } from "../ui/select.js";
|
|
4
|
+
import { cn as u } from "cn";
|
|
5
|
+
import { useEffect as d, useEffectEvent as f, useId as p } from "react";
|
|
6
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
7
|
+
import { ChevronLeftIcon as g, ChevronRightIcon as _ } from "lucide-react";
|
|
8
|
+
// src/components/etic/data-table-pagination.tsx
|
|
9
|
+
function v(e, t) {
|
|
10
|
+
let n = [.../* @__PURE__ */ new Set([
|
|
11
|
+
1,
|
|
12
|
+
t,
|
|
13
|
+
e,
|
|
14
|
+
e - 1,
|
|
15
|
+
e + 1
|
|
16
|
+
])].filter((e) => e >= 1 && e <= t).sort((e, t) => e - t), r = [], i = 0;
|
|
17
|
+
for (let e of n) e - i > 1 && r.push("…"), r.push(e), i = e;
|
|
18
|
+
return r;
|
|
19
|
+
}
|
|
20
|
+
function y({ total: y, decalage: b, limite: x, onDecalageChange: S, onLimiteChange: C, limites: w = [
|
|
21
|
+
10,
|
|
22
|
+
25,
|
|
23
|
+
50,
|
|
24
|
+
100
|
|
25
|
+
], className: T }) {
|
|
26
|
+
let E = p(), D = Math.max(1, Math.ceil(y / x)), O = Math.min(Math.floor(b / x) + 1, D), k = [.../* @__PURE__ */ new Set([...w, x])].sort((e, t) => e - t), A = C !== void 0 && y > k[0], j = (D - 1) * x, M = f(() => S(j));
|
|
27
|
+
if (d(() => {
|
|
28
|
+
y > 0 && b >= y && M();
|
|
29
|
+
}, [b, y]), D <= 1 && !A) return null;
|
|
30
|
+
let N = (e) => S((Math.min(Math.max(1, e), D) - 1) * x);
|
|
31
|
+
return /* @__PURE__ */ h("div", {
|
|
32
|
+
"data-slot": "data-table-pagination",
|
|
33
|
+
className: u("flex flex-wrap items-center justify-between gap-x-6 gap-y-2", T),
|
|
34
|
+
children: [A ? /* @__PURE__ */ h("div", {
|
|
35
|
+
className: "flex items-center gap-2",
|
|
36
|
+
children: [/* @__PURE__ */ m("span", {
|
|
37
|
+
id: E,
|
|
38
|
+
className: "text-sm font-medium",
|
|
39
|
+
children: "Lignes par page"
|
|
40
|
+
}), /* @__PURE__ */ h(a, {
|
|
41
|
+
value: String(x),
|
|
42
|
+
onValueChange: (e) => {
|
|
43
|
+
e !== null && (C(Number(e)), S(0));
|
|
44
|
+
},
|
|
45
|
+
children: [/* @__PURE__ */ m(c, {
|
|
46
|
+
className: "w-[4.5rem]",
|
|
47
|
+
"aria-labelledby": E,
|
|
48
|
+
children: /* @__PURE__ */ m(l, {})
|
|
49
|
+
}), /* @__PURE__ */ m(o, {
|
|
50
|
+
side: "top",
|
|
51
|
+
alignItemWithTrigger: !1,
|
|
52
|
+
children: k.map((e) => /* @__PURE__ */ m(s, {
|
|
53
|
+
value: String(e),
|
|
54
|
+
children: e
|
|
55
|
+
}, e))
|
|
56
|
+
})]
|
|
57
|
+
})]
|
|
58
|
+
}) : null, D > 1 ? /* @__PURE__ */ h(t, {
|
|
59
|
+
className: "mx-0 ml-auto w-auto",
|
|
60
|
+
children: [/* @__PURE__ */ h(n, { children: [
|
|
61
|
+
/* @__PURE__ */ m(i, { children: /* @__PURE__ */ h(e, {
|
|
62
|
+
variant: "ghost",
|
|
63
|
+
className: "pl-1.5!",
|
|
64
|
+
"aria-label": "Page précédente",
|
|
65
|
+
disabled: O === 1,
|
|
66
|
+
focusableWhenDisabled: !0,
|
|
67
|
+
onClick: () => N(O - 1),
|
|
68
|
+
children: [/* @__PURE__ */ m(g, { "data-icon": "inline-start" }), /* @__PURE__ */ m("span", {
|
|
69
|
+
className: "hidden sm:block",
|
|
70
|
+
children: "Précédente"
|
|
71
|
+
})]
|
|
72
|
+
}) }),
|
|
73
|
+
v(O, D).map((t, n) => /* @__PURE__ */ m(i, { children: t === "…" ? /* @__PURE__ */ m(r, {}) : /* @__PURE__ */ m(e, {
|
|
74
|
+
variant: t === O ? "outline" : "ghost",
|
|
75
|
+
size: "icon",
|
|
76
|
+
"aria-current": t === O ? "page" : void 0,
|
|
77
|
+
"aria-label": `Page ${t}`,
|
|
78
|
+
onClick: () => N(t),
|
|
79
|
+
children: t
|
|
80
|
+
}) }, t === "…" ? `…${n}` : t)),
|
|
81
|
+
/* @__PURE__ */ m(i, { children: /* @__PURE__ */ h(e, {
|
|
82
|
+
variant: "ghost",
|
|
83
|
+
className: "pr-1.5!",
|
|
84
|
+
"aria-label": "Page suivante",
|
|
85
|
+
disabled: O === D,
|
|
86
|
+
focusableWhenDisabled: !0,
|
|
87
|
+
onClick: () => N(O + 1),
|
|
88
|
+
children: [/* @__PURE__ */ m("span", {
|
|
89
|
+
className: "hidden sm:block",
|
|
90
|
+
children: "Suivante"
|
|
91
|
+
}), /* @__PURE__ */ m(_, { "data-icon": "inline-end" })]
|
|
92
|
+
}) })
|
|
93
|
+
] }), /* @__PURE__ */ m("p", {
|
|
94
|
+
className: "sr-only",
|
|
95
|
+
"aria-live": "polite",
|
|
96
|
+
"aria-atomic": "true",
|
|
97
|
+
children: `Page ${O} sur ${D}`
|
|
98
|
+
})]
|
|
99
|
+
}) : null]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
export { y as DataTablePagination };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=data-table-pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-pagination.js","names":["fenetre","pages","nombre","courante","p","a","b","sortie","precedente","page","DataTablePagination","idTaille","useId","nombrePages","total","limite","decalage","tailles","limites","choixTaille","onLimiteChange","decalageMax","ramener","useEffectEvent","onDecalageChange","useEffect","allerA","cible","cn","className","Select","valeur","SelectTrigger","SelectValue","SelectContent","SelectItem","taille","Pagination","PaginationContent","PaginationItem","Button","ChevronLeftIcon","PaginationEllipsis","i","ChevronRightIcon"],"sources":["../../../src/components/etic/data-table-pagination.tsx"],"sourcesContent":["import { useEffect, useEffectEvent, useId } from \"react\"\nimport { cn } from \"cn\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\"\n\nimport { Button } from \"@etic-ui/components/ui/button\"\nimport {\n Pagination,\n PaginationContent,\n PaginationEllipsis,\n PaginationItem,\n} from \"@etic-ui/components/ui/pagination\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@etic-ui/components/ui/select\"\n\n/** Fenêtre de pages : la première, la dernière, la courante et ses voisines,\n * « … » pour les pages sautées. Page 6 sur 20 : 1 … 5 6 7 … 20. */\nfunction fenetre(courante: number, nombre: number): (number | \"…\")[] {\n const pages = [...new Set([1, nombre, courante, courante - 1, courante + 1])]\n .filter((p) => p >= 1 && p <= nombre)\n .sort((a, b) => a - b)\n const sortie: (number | \"…\")[] = []\n let precedente = 0\n for (const page of pages) {\n if (page - precedente > 1) sortie.push(\"…\")\n sortie.push(page)\n precedente = page\n }\n return sortie\n}\n\nexport interface DataTablePaginationProps {\n /** Nombre total d'éléments, toutes pages comprises. */\n total: number\n /** Rang (à partir de 0) du premier élément de la page. */\n decalage: number\n /** Nombre d'éléments par page. */\n limite: number\n onDecalageChange: (decalage: number) => void\n /** Sans lui, pas de choix du nombre par page. Changer de taille ramène à\n * la première page (`onDecalageChange(0)`). */\n onLimiteChange?: (limite: number) => void\n /** Nombres d'éléments par page proposés. 10, 25, 50 et 100 par défaut. */\n limites?: readonly number[]\n className?: string\n}\n\n/**\n * Pagination par décalage (offset/limit, total connu) sur la Pagination de\n * shadcn : précédente, fenêtre de pages, suivante, et le nombre de lignes par\n * page (Select). Rien ne s'affiche quand tout tient sur une page de la plus\n * petite taille.\n */\nexport function DataTablePagination({\n total,\n decalage,\n limite,\n onDecalageChange,\n onLimiteChange,\n limites = [10, 25, 50, 100],\n className,\n}: DataTablePaginationProps) {\n const idTaille = useId()\n const nombrePages = Math.max(1, Math.ceil(total / limite))\n const page = Math.min(Math.floor(decalage / limite) + 1, nombrePages)\n const tailles = [...new Set([...limites, limite])].sort((a, b) => a - b)\n const choixTaille = onLimiteChange !== undefined && total > tailles[0]\n\n // Décalage au-delà de la fin (dernière ligne de la dernière page\n // supprimée) : on ramène l'application sur la dernière page, sans quoi\n // elle afficherait une page vide sous un numéro de page surligné. Pas\n // tant que `total` vaut 0 : c'est souvent un total pas encore connu\n // (requête de la page suivante en cours, décalage lu dans l'URL), et le\n // ramener renverrait à la première page.\n const decalageMax = (nombrePages - 1) * limite\n const ramener = useEffectEvent(() => onDecalageChange(decalageMax))\n useEffect(() => {\n if (total > 0 && decalage >= total) ramener()\n }, [decalage, total])\n\n if (nombrePages <= 1 && !choixTaille) return null\n\n const allerA = (cible: number) =>\n onDecalageChange((Math.min(Math.max(1, cible), nombrePages) - 1) * limite)\n\n return (\n <div\n data-slot=\"data-table-pagination\"\n className={cn(\n \"flex flex-wrap items-center justify-between gap-x-6 gap-y-2\",\n className\n )}\n >\n {choixTaille ? (\n <div className=\"flex items-center gap-2\">\n <span id={idTaille} className=\"text-sm font-medium\">\n Lignes par page\n </span>\n <Select\n value={String(limite)}\n onValueChange={(valeur) => {\n if (valeur === null) return\n onLimiteChange(Number(valeur))\n onDecalageChange(0)\n }}\n >\n <SelectTrigger className=\"w-[4.5rem]\" aria-labelledby={idTaille}>\n <SelectValue />\n </SelectTrigger>\n <SelectContent side=\"top\" alignItemWithTrigger={false}>\n {tailles.map((taille) => (\n <SelectItem key={taille} value={String(taille)}>\n {taille}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n ) : null}\n {nombrePages > 1 ? (\n <Pagination className=\"mx-0 ml-auto w-auto\">\n <PaginationContent>\n <PaginationItem>\n {/* Focalisable désactivé : arrivé en bout de liste au clavier,\n le focus reste sur le bouton au lieu de partir sur <body>. */}\n <Button\n variant=\"ghost\"\n className=\"pl-1.5!\"\n aria-label=\"Page précédente\"\n disabled={page === 1}\n focusableWhenDisabled\n onClick={() => allerA(page - 1)}\n >\n <ChevronLeftIcon data-icon=\"inline-start\" />\n <span className=\"hidden sm:block\">Précédente</span>\n </Button>\n </PaginationItem>\n {fenetre(page, nombrePages).map((p, i) => (\n <PaginationItem key={p === \"…\" ? `…${i}` : p}>\n {p === \"…\" ? (\n <PaginationEllipsis />\n ) : (\n <Button\n variant={p === page ? \"outline\" : \"ghost\"}\n size=\"icon\"\n aria-current={p === page ? \"page\" : undefined}\n aria-label={`Page ${p}`}\n onClick={() => allerA(p)}\n >\n {p}\n </Button>\n )}\n </PaginationItem>\n ))}\n <PaginationItem>\n <Button\n variant=\"ghost\"\n className=\"pr-1.5!\"\n aria-label=\"Page suivante\"\n disabled={page === nombrePages}\n focusableWhenDisabled\n onClick={() => allerA(page + 1)}\n >\n <span className=\"hidden sm:block\">Suivante</span>\n <ChevronRightIcon data-icon=\"inline-end\" />\n </Button>\n </PaginationItem>\n </PaginationContent>\n {/* Le focus reste sur la pagination, sous le tableau : la page\n atteinte est annoncée. */}\n <p className=\"sr-only\" aria-live=\"polite\" aria-atomic=\"true\">\n {`Page ${page} sur ${nombrePages}`}\n </p>\n </Pagination>\n ) : null}\n </div>\n )\n}\n"],"mappings":";;;;;;;;AAqBA,SAASA,EAAQ,GAAkB,GAAkC;CACnE,IAAMC,IAAQ,CAAC,mBAAG,IAAI,IAAI;EAAC;EAAGC;EAAQC;EAAUA,IAAW;EAAGA,IAAW;CAAC,CAAC,CAAC,CAAC,CAC1E,QAAQ,MAAMC,KAAK,KAAKA,KAAKF,CAAM,CAAC,CACpC,MAAM,GAAG,MAAMG,IAAIC,CAAC,GACjBC,IAA2B,CAAC,GAC9BC,IAAa;CACjB,KAAK,IAAMC,KAAQR,GAGjB,AAFIQ,IAAOD,IAAa,KAAGD,EAAO,KAAK,GAAG,GAC1CA,EAAO,KAAKE,CAAI,GAChB,IAAaA;CAEf,OAAOF;AACT;AAwBA,SAAgBG,EAAoB,EAClC,UACA,aACA,WACA,qBACA,mBACA,aAAU;CAAC;CAAI;CAAI;CAAI;AAAG,GAC1B,gBAC2B;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