@etic-insa/ui 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +496 -12
- 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 +7 -4
- package/dist/components/etic/app-shell.js +119 -81
- package/dist/components/etic/app-shell.js.map +1 -1
- 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 +5 -3
- package/dist/components/etic/theme-menu.js +38 -32
- package/dist/components/etic/theme-menu.js.map +1 -1
- 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.js +31 -31
- 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/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.js +36 -36
- 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/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/sidebar.js +47 -47
- package/dist/components/ui/sidebar.js.map +1 -1
- 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/index.d.ts +66 -0
- package/dist/index.js +76 -13
- package/dist/styles.css +39 -4
- package/package.json +18 -7
|
@@ -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,KAA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A;KAAc,CAAA,GAChD,kBAACmC,GAAD,EAAkB,aAAU,aAAc,CAAA,CACpC;IACM,CAAA,EAAA,CAAA;GACC,EAAA,CAAA,GAGnB,kBAAC,KAAD;IAAG,WAAU;IAAU,aAAU;IAAS,eAAY;IACnD,UAAA,QAAQnC,EAAK,OAAOI;GACpB,CAAA,CACO;EACV,CAAA,IAAA,IACD;;AAET"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { DataTableUnite } from './data-table-format';
|
|
3
|
+
export interface DataTableCountProps {
|
|
4
|
+
/** Nombre total d'éléments, toutes pages comprises. */
|
|
5
|
+
total: number;
|
|
6
|
+
/** Rang (à partir de 0) du premier élément affiché. 0 par défaut. */
|
|
7
|
+
decalage?: number;
|
|
8
|
+
/** Nombre d'éléments affichés. */
|
|
9
|
+
nombre: number;
|
|
10
|
+
/** Nom des éléments. « élément », « éléments » par défaut. */
|
|
11
|
+
unite?: DataTableUnite;
|
|
12
|
+
/** Accorde « affichées » au féminin. */
|
|
13
|
+
feminin?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compteur d'une liste : « 128 éléments · 26–50 affichés ». C'est une zone
|
|
18
|
+
* de statut : après une recherche, un filtre ou un changement de page, le
|
|
19
|
+
* nouveau compte est annoncé sans déplacer le focus.
|
|
20
|
+
*/
|
|
21
|
+
export declare function DataTableCount({ total, decalage, nombre, unite, feminin, className, }: DataTableCountProps): import("react").JSX.Element;
|
|
22
|
+
export interface DataTableSelectFilterOption {
|
|
23
|
+
valeur: string;
|
|
24
|
+
libelle: string;
|
|
25
|
+
}
|
|
26
|
+
export interface DataTableSelectFilterProps {
|
|
27
|
+
/** Nom du filtre pour les lecteurs d'écran : « Filtrer par statut ». */
|
|
28
|
+
libelle: string;
|
|
29
|
+
/** Valeur choisie ; `null` = pas de filtre. */
|
|
30
|
+
valeur: string | null;
|
|
31
|
+
onValeurChange: (valeur: string | null) => void;
|
|
32
|
+
options: DataTableSelectFilterOption[];
|
|
33
|
+
/** Entrée sans filtre : « Tous les statuts ». */
|
|
34
|
+
libelleTous: string;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Filtre d'une liste : un Select de shadcn dont la première entrée retire
|
|
38
|
+
* le filtre. */
|
|
39
|
+
export declare function DataTableSelectFilter({ libelle, valeur, onValeurChange, options, libelleTous, className, }: DataTableSelectFilterProps): import("react").JSX.Element;
|
|
40
|
+
export interface DataTableToolbarProps {
|
|
41
|
+
/** Champ de recherche, contrôlé (l'application temporise sa requête). */
|
|
42
|
+
recherche?: {
|
|
43
|
+
valeur: string;
|
|
44
|
+
onValeurChange: (valeur: string) => void;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
/** Nom du champ. « Rechercher » par défaut. */
|
|
47
|
+
libelle?: string;
|
|
48
|
+
};
|
|
49
|
+
/** Filtres : `DataTableSelectFilter`… */
|
|
50
|
+
filtres?: ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Nombre de filtres actifs. Fourni, il replie les filtres derrière un
|
|
53
|
+
* bouton « Filtres (n) » sur mobile, où ils s'empileraient sinon au-dessus
|
|
54
|
+
* des résultats, et affiche « Réinitialiser » s'il y en a.
|
|
55
|
+
*/
|
|
56
|
+
filtresActifs?: number;
|
|
57
|
+
/** Retire tous les filtres (bouton « Réinitialiser »). */
|
|
58
|
+
onReinitialiser?: () => void;
|
|
59
|
+
/** Compteur « N éléments · a–b affichés ». */
|
|
60
|
+
compteur?: DataTableCountProps;
|
|
61
|
+
/** À droite : `DataTableViewOptions`, bouton d'ajout… */
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
className?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Barre d'outils au-dessus d'un tableau, sur le modèle de celle de shadcn :
|
|
67
|
+
* recherche et filtres à gauche, compteur et commandes (colonnes…) à droite.
|
|
68
|
+
*/
|
|
69
|
+
export declare function DataTableToolbar({ recherche, filtres, filtresActifs, onReinitialiser, compteur, children, className, }: DataTableToolbarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Button as e } from "../ui/button.js";
|
|
2
|
+
import { InputGroup as t, InputGroupAddon as n, InputGroupButton as r, InputGroupInput as i } from "../ui/input-group.js";
|
|
3
|
+
import { Tooltip as a, TooltipContent as o, TooltipTrigger as s } from "../ui/tooltip.js";
|
|
4
|
+
import { Popover as c, PopoverContent as l, PopoverTrigger as u } from "../ui/popover.js";
|
|
5
|
+
import { Select as d, SelectContent as f, SelectItem as p, SelectTrigger as m, SelectValue as h } from "../ui/select.js";
|
|
6
|
+
import { useIsMobile as g } from "../../hooks/use-mobile.js";
|
|
7
|
+
import { UNITE_PAR_DEFAUT as _, nombreFr as v, participe as y, uniteAccordee as b } from "./data-table-format.js";
|
|
8
|
+
import { cn as x } from "cn";
|
|
9
|
+
import { useRef as S } from "react";
|
|
10
|
+
import { jsx as C, jsxs as w } from "react/jsx-runtime";
|
|
11
|
+
import { ListFilterIcon as T, SearchIcon as E, XIcon as D } from "lucide-react";
|
|
12
|
+
// src/components/etic/data-table-toolbar.tsx
|
|
13
|
+
function O({ total: e, decalage: t = 0, nombre: n, unite: r = _, feminin: i = !1, className: a }) {
|
|
14
|
+
let o = t + 1, s = t + n;
|
|
15
|
+
return /* @__PURE__ */ w("p", {
|
|
16
|
+
"data-slot": "data-table-count",
|
|
17
|
+
role: "status",
|
|
18
|
+
"aria-atomic": "true",
|
|
19
|
+
className: x("text-sm whitespace-nowrap text-muted-foreground", a),
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ C("strong", {
|
|
22
|
+
className: "font-medium text-foreground tabular-nums",
|
|
23
|
+
children: v(e)
|
|
24
|
+
}),
|
|
25
|
+
" ",
|
|
26
|
+
b(e, r),
|
|
27
|
+
n > 0 ? /* @__PURE__ */ w("span", {
|
|
28
|
+
className: "tabular-nums",
|
|
29
|
+
children: [
|
|
30
|
+
" ",
|
|
31
|
+
"·",
|
|
32
|
+
" ",
|
|
33
|
+
s > o ? `${v(o)}–${v(s)}` : v(o),
|
|
34
|
+
" ",
|
|
35
|
+
y("affiché", n, i)
|
|
36
|
+
]
|
|
37
|
+
}) : null
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function k({ libelle: e, valeur: t, onValeurChange: n, options: r, libelleTous: i, className: a }) {
|
|
42
|
+
let o = [{
|
|
43
|
+
value: null,
|
|
44
|
+
label: i
|
|
45
|
+
}, ...r.map((e) => ({
|
|
46
|
+
value: e.valeur,
|
|
47
|
+
label: e.libelle
|
|
48
|
+
}))];
|
|
49
|
+
return /* @__PURE__ */ w(d, {
|
|
50
|
+
items: o,
|
|
51
|
+
value: t,
|
|
52
|
+
onValueChange: n,
|
|
53
|
+
children: [/* @__PURE__ */ C(m, {
|
|
54
|
+
"aria-label": e,
|
|
55
|
+
className: a,
|
|
56
|
+
children: /* @__PURE__ */ C(h, {})
|
|
57
|
+
}), /* @__PURE__ */ C(f, { children: o.map((e) => /* @__PURE__ */ C(p, {
|
|
58
|
+
value: e.value,
|
|
59
|
+
children: e.label
|
|
60
|
+
}, e.value ?? "")) })]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function A({ recherche: d, filtres: f, filtresActifs: p, onReinitialiser: m, compteur: h, children: _, className: v }) {
|
|
64
|
+
let y = g() && f != null && p !== void 0, b = S(null), k = S(null);
|
|
65
|
+
return /* @__PURE__ */ w("div", {
|
|
66
|
+
ref: b,
|
|
67
|
+
"data-slot": "data-table-toolbar",
|
|
68
|
+
className: x("flex flex-wrap items-center gap-2", v),
|
|
69
|
+
children: [
|
|
70
|
+
d ? /* @__PURE__ */ w(t, {
|
|
71
|
+
className: "w-full sm:w-64",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ C(n, { children: /* @__PURE__ */ C(E, {}) }),
|
|
74
|
+
/* @__PURE__ */ C(i, {
|
|
75
|
+
ref: k,
|
|
76
|
+
type: "search",
|
|
77
|
+
"aria-label": d.libelle ?? "Rechercher",
|
|
78
|
+
placeholder: d.placeholder ?? "Rechercher…",
|
|
79
|
+
value: d.valeur,
|
|
80
|
+
onChange: (e) => d.onValeurChange(e.target.value),
|
|
81
|
+
autoComplete: "off",
|
|
82
|
+
className: "[&::-webkit-search-cancel-button]:appearance-none"
|
|
83
|
+
}),
|
|
84
|
+
d.valeur ? /* @__PURE__ */ C(n, {
|
|
85
|
+
align: "inline-end",
|
|
86
|
+
children: /* @__PURE__ */ w(a, { children: [/* @__PURE__ */ C(s, {
|
|
87
|
+
render: /* @__PURE__ */ C(r, {
|
|
88
|
+
size: "icon-xs",
|
|
89
|
+
"aria-label": "Effacer la recherche",
|
|
90
|
+
onClick: () => {
|
|
91
|
+
k.current?.focus(), d.onValeurChange("");
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
children: /* @__PURE__ */ C(D, {})
|
|
95
|
+
}), /* @__PURE__ */ C(o, { children: "Effacer la recherche" })] })
|
|
96
|
+
}) : null
|
|
97
|
+
]
|
|
98
|
+
}) : null,
|
|
99
|
+
y ? /* @__PURE__ */ w(c, { children: [/* @__PURE__ */ w(u, {
|
|
100
|
+
render: /* @__PURE__ */ C(e, { variant: "outline" }),
|
|
101
|
+
children: [
|
|
102
|
+
/* @__PURE__ */ C(T, { "data-icon": "inline-start" }),
|
|
103
|
+
"Filtres",
|
|
104
|
+
p ? ` (${p})` : ""
|
|
105
|
+
]
|
|
106
|
+
}), /* @__PURE__ */ C(l, {
|
|
107
|
+
align: "start",
|
|
108
|
+
className: "w-64 *:data-[slot=select-trigger]:w-full",
|
|
109
|
+
children: f
|
|
110
|
+
})] }) : f,
|
|
111
|
+
p && m ? /* @__PURE__ */ w(e, {
|
|
112
|
+
variant: "ghost",
|
|
113
|
+
onClick: () => {
|
|
114
|
+
b.current?.querySelector("input[type=\"search\"], [data-slot=\"popover-trigger\"], [data-slot=\"select-trigger\"]")?.focus(), m?.();
|
|
115
|
+
},
|
|
116
|
+
children: ["Réinitialiser", /* @__PURE__ */ C(D, { "data-icon": "inline-end" })]
|
|
117
|
+
}) : null,
|
|
118
|
+
h || _ ? /* @__PURE__ */ w("div", {
|
|
119
|
+
className: "ml-auto flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
120
|
+
children: [h ? /* @__PURE__ */ C(O, { ...h }) : null, _]
|
|
121
|
+
}) : null
|
|
122
|
+
]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
export { O as DataTableCount, k as DataTableSelectFilter, A as DataTableToolbar };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=data-table-toolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-toolbar.js","names":["DataTableCount","UNITE_PAR_DEFAUT","debut","decalage","fin","nombre","cn","className","nombreFr","total","uniteAccordee","unite","participe","feminin","DataTableSelectFilter","items","libelleTous","options","option","Select","valeur","onValeurChange","SelectTrigger","libelle","SelectValue","SelectContent","SelectItem","item","DataTableToolbar","replier","useIsMobile","filtres","filtresActifs","racineRef","useRef","rechercheRef","recherche","InputGroup","InputGroupAddon","SearchIcon","InputGroupInput","event","Tooltip","TooltipTrigger","InputGroupButton","XIcon","TooltipContent","Popover","PopoverTrigger","Button","ListFilterIcon","PopoverContent","onReinitialiser","compteur","children"],"sources":["../../../src/components/etic/data-table-toolbar.tsx"],"sourcesContent":["import { useRef, type ReactNode } from \"react\"\nimport { cn } from \"cn\"\nimport { ListFilterIcon, SearchIcon, XIcon } from \"lucide-react\"\n\nimport { Button } from \"@etic-ui/components/ui/button\"\nimport {\n InputGroup,\n InputGroupAddon,\n InputGroupButton,\n InputGroupInput,\n} from \"@etic-ui/components/ui/input-group\"\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@etic-ui/components/ui/tooltip\"\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"@etic-ui/components/ui/popover\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@etic-ui/components/ui/select\"\nimport { useIsMobile } from \"@etic-ui/hooks/use-mobile\"\nimport {\n UNITE_PAR_DEFAUT,\n nombreFr,\n participe,\n uniteAccordee,\n type DataTableUnite,\n} from \"@etic-ui/components/etic/data-table-format\"\n\nexport interface DataTableCountProps {\n /** Nombre total d'éléments, toutes pages comprises. */\n total: number\n /** Rang (à partir de 0) du premier élément affiché. 0 par défaut. */\n decalage?: number\n /** Nombre d'éléments affichés. */\n nombre: number\n /** Nom des éléments. « élément », « éléments » par défaut. */\n unite?: DataTableUnite\n /** Accorde « affichées » au féminin. */\n feminin?: boolean\n className?: string\n}\n\n/**\n * Compteur d'une liste : « 128 éléments · 26–50 affichés ». C'est une zone\n * de statut : après une recherche, un filtre ou un changement de page, le\n * nouveau compte est annoncé sans déplacer le focus.\n */\nexport function DataTableCount({\n total,\n decalage = 0,\n nombre,\n unite = UNITE_PAR_DEFAUT,\n feminin = false,\n className,\n}: DataTableCountProps) {\n const debut = decalage + 1\n const fin = decalage + nombre\n return (\n <p\n data-slot=\"data-table-count\"\n role=\"status\"\n aria-atomic=\"true\"\n className={cn(\n \"text-sm whitespace-nowrap text-muted-foreground\",\n className\n )}\n >\n <strong className=\"font-medium text-foreground tabular-nums\">\n {nombreFr(total)}\n </strong>{\" \"}\n {uniteAccordee(total, unite)}\n {nombre > 0 ? (\n <span className=\"tabular-nums\">\n {\" \"}\n ·{\" \"}\n {fin > debut\n ? `${nombreFr(debut)}–${nombreFr(fin)}`\n : nombreFr(debut)}{\" \"}\n {participe(\"affiché\", nombre, feminin)}\n </span>\n ) : null}\n </p>\n )\n}\n\nexport interface DataTableSelectFilterOption {\n valeur: string\n libelle: string\n}\n\nexport interface DataTableSelectFilterProps {\n /** Nom du filtre pour les lecteurs d'écran : « Filtrer par statut ». */\n libelle: string\n /** Valeur choisie ; `null` = pas de filtre. */\n valeur: string | null\n onValeurChange: (valeur: string | null) => void\n options: DataTableSelectFilterOption[]\n /** Entrée sans filtre : « Tous les statuts ». */\n libelleTous: string\n className?: string\n}\n\n/** Filtre d'une liste : un Select de shadcn dont la première entrée retire\n * le filtre. */\nexport function DataTableSelectFilter({\n libelle,\n valeur,\n onValeurChange,\n options,\n libelleTous,\n className,\n}: DataTableSelectFilterProps) {\n const items = [\n { value: null, label: libelleTous },\n ...options.map((option) => ({\n value: option.valeur,\n label: option.libelle,\n })),\n ]\n return (\n <Select items={items} value={valeur} onValueChange={onValeurChange}>\n <SelectTrigger aria-label={libelle} className={className}>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {items.map((item) => (\n <SelectItem key={item.value ?? \"\"} value={item.value}>\n {item.label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n )\n}\n\nexport interface DataTableToolbarProps {\n /** Champ de recherche, contrôlé (l'application temporise sa requête). */\n recherche?: {\n valeur: string\n onValeurChange: (valeur: string) => void\n placeholder?: string\n /** Nom du champ. « Rechercher » par défaut. */\n libelle?: string\n }\n /** Filtres : `DataTableSelectFilter`… */\n filtres?: ReactNode\n /**\n * Nombre de filtres actifs. Fourni, il replie les filtres derrière un\n * bouton « Filtres (n) » sur mobile, où ils s'empileraient sinon au-dessus\n * des résultats, et affiche « Réinitialiser » s'il y en a.\n */\n filtresActifs?: number\n /** Retire tous les filtres (bouton « Réinitialiser »). */\n onReinitialiser?: () => void\n /** Compteur « N éléments · a–b affichés ». */\n compteur?: DataTableCountProps\n /** À droite : `DataTableViewOptions`, bouton d'ajout… */\n children?: ReactNode\n className?: string\n}\n\n/**\n * Barre d'outils au-dessus d'un tableau, sur le modèle de celle de shadcn :\n * recherche et filtres à gauche, compteur et commandes (colonnes…) à droite.\n */\nexport function DataTableToolbar({\n recherche,\n filtres,\n filtresActifs,\n onReinitialiser,\n compteur,\n children,\n className,\n}: DataTableToolbarProps) {\n const mobile = useIsMobile()\n const replier = mobile && filtres != null && filtresActifs !== undefined\n const racineRef = useRef<HTMLDivElement>(null)\n const rechercheRef = useRef<HTMLInputElement>(null)\n\n // « Réinitialiser » disparaît avec les filtres : le focus passe d'abord au\n // champ de recherche, sinon au premier filtre (ou au bouton « Filtres »),\n // au lieu de tomber sur <body>.\n const reinitialiser = () => {\n racineRef.current\n ?.querySelector<HTMLElement>(\n 'input[type=\"search\"], [data-slot=\"popover-trigger\"], [data-slot=\"select-trigger\"]'\n )\n ?.focus()\n onReinitialiser?.()\n }\n\n return (\n <div\n ref={racineRef}\n data-slot=\"data-table-toolbar\"\n className={cn(\"flex flex-wrap items-center gap-2\", className)}\n >\n {recherche ? (\n <InputGroup className=\"w-full sm:w-64\">\n <InputGroupAddon>\n <SearchIcon />\n </InputGroupAddon>\n <InputGroupInput\n ref={rechercheRef}\n type=\"search\"\n aria-label={recherche.libelle ?? \"Rechercher\"}\n placeholder={recherche.placeholder ?? \"Rechercher…\"}\n value={recherche.valeur}\n onChange={(event) => recherche.onValeurChange(event.target.value)}\n autoComplete=\"off\"\n // La croix native de Chrome (bleue, 14 px, absente de Firefox)\n // cède la place au bouton ci-dessous.\n className=\"[&::-webkit-search-cancel-button]:appearance-none\"\n />\n {recherche.valeur ? (\n <InputGroupAddon align=\"inline-end\">\n <Tooltip>\n <TooltipTrigger\n render={\n <InputGroupButton\n size=\"icon-xs\"\n aria-label=\"Effacer la recherche\"\n onClick={() => {\n // Le bouton disparaît : le focus revient au champ.\n rechercheRef.current?.focus()\n recherche.onValeurChange(\"\")\n }}\n />\n }\n >\n <XIcon />\n </TooltipTrigger>\n <TooltipContent>Effacer la recherche</TooltipContent>\n </Tooltip>\n </InputGroupAddon>\n ) : null}\n </InputGroup>\n ) : null}\n {replier ? (\n <Popover>\n <PopoverTrigger render={<Button variant=\"outline\" />}>\n <ListFilterIcon data-icon=\"inline-start\" />\n Filtres{filtresActifs ? ` (${filtresActifs})` : \"\"}\n </PopoverTrigger>\n <PopoverContent\n align=\"start\"\n className=\"w-64 *:data-[slot=select-trigger]:w-full\"\n >\n {filtres}\n </PopoverContent>\n </Popover>\n ) : (\n filtres\n )}\n {filtresActifs && onReinitialiser ? (\n <Button variant=\"ghost\" onClick={reinitialiser}>\n Réinitialiser\n <XIcon data-icon=\"inline-end\" />\n </Button>\n ) : null}\n {compteur || children ? (\n <div className=\"ml-auto flex flex-wrap items-center gap-x-4 gap-y-2\">\n {compteur ? <DataTableCount {...compteur} /> : null}\n {children}\n </div>\n ) : null}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAwDA,SAAgBA,EAAe,EAC7B,UACA,cAAW,GACX,WACA,WAAQC,GACR,aAAU,IACV,gBACsB;CACtB,IAAMC,IAAQC,IAAW,GACnBC,IAAMD,IAAWE;CACvB,OACE,kBAAC,KAAD;EACE,aAAU;EACV,MAAK;EACL,eAAY;EACZ,WAAWC,EACT,mDACAC,CACF;EAPF,UAAA;GASE,kBAAC,UAAD;IAAQ,WAAU;IACf,UAAAC,EAASC,CAAK;GACT,CAAA;GAAE;GACTC,EAAcD,GAAOE,CAAK;GAC1BN,IAAS,IACR,kBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA;KACG;KAAI;KACH;KACDD,IAAMF,IACH,GAAGM,EAASN,CAAK,EAAE,GAAGM,EAASJ,CAAG,MAClCI,EAASN,CAAK;KAAG;KACpBU,EAAU,WAAWP,GAAQQ,CAAO;IACjC;GACJ,CAAA,IAAA;EACH;;AAEP;AAqBA,SAAgBC,EAAsB,EACpC,YACA,WACA,mBACA,YACA,gBACA,gBAC6B;CAC7B,IAAMC,IAAQ,CACZ;EAAE,OAAO;EAAM,OAAOC;CAAY,GAClC,GAAGC,EAAQ,KAAK,OAAY;EAC1B,OAAOC,EAAO;EACd,OAAOA,EAAO;CAChB,EAAE,CACJ;CACA,OACE,kBAACC,GAAD;EAAe;EAAO,OAAOC;EAAQ,eAAeC;EAApD,UAAA,CACE,kBAACC,GAAD;GAAe,cAAYC;GAAoB;GAC7C,UAAA,kBAACC,GAAD,CAAc,CAAA;EACD,CAAA,GACf,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CAAA;IAAnD,UAAA;KACE,kBAACC,GAAD,EAAgB,aAAU,eAAgB,CAAA;KAAC;KACnClB,IAAgB,KAAKA,EAAc,KAAK;IAClC;GAChB,CAAA,GAAA,kBAACmB,GAAD;IACE,OAAM;IACN,WAAU;IAET,UAAApB;GACa,CAAA,CACT,EAAA,CAAA,IAETA;GAEDC,KAAiBoB,IAChB,kBAACH,GAAD;IAAQ,SAAQ;IAAQ,eAzEF;KAM1B,AALAhB,EAAU,SACN,cACA,yFACF,CAAC,EACC,MAAM,GACVmB,IAAkB;IACpB;IAkEM,UAAA,CAAgD,iBAE9C,kBAACP,GAAD,EAAO,aAAU,aAAc,CAAA,CACzB;GACN,CAAA,IAAA;GACHQ,KAAYC,IACX,kBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACGD,IAAW,kBAACrD,GAAD,EAAgB,GAAIqD,EAAW,CAAA,IAAI,MAC9CC,CACE;GACH,CAAA,IAAA;EACD;;AAET"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RowData } from '@tanstack/react-table';
|
|
2
|
+
import { DataTableInstance } from './data-table';
|
|
3
|
+
export interface DataTableViewOptionsProps<TData extends RowData> {
|
|
4
|
+
table: DataTableInstance<TData>;
|
|
5
|
+
/** Texte du bouton. « Colonnes » par défaut. */
|
|
6
|
+
libelle?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Sélecteur de colonnes : le bouton « Colonnes » de shadcn, dont le panneau
|
|
11
|
+
* coche les colonnes affichées et les réordonne par glisser-déposer (dnd-kit),
|
|
12
|
+
* à la souris, au toucher ou au clavier (poignée : Espace, flèches, Espace).
|
|
13
|
+
* Les colonnes qui ne se masquent pas (`enableHiding: false`) n'y figurent
|
|
14
|
+
* pas et gardent leur place. Le panneau reste ouvert pendant les réglages.
|
|
15
|
+
*/
|
|
16
|
+
export declare function DataTableViewOptions<TData extends RowData>({ table, libelle, className, }: DataTableViewOptionsProps<TData>): import("react").JSX.Element;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Button as e, buttonVariants as t } from "../ui/button.js";
|
|
2
|
+
import { Checkbox as n } from "../ui/checkbox.js";
|
|
3
|
+
import { Popover as r, PopoverContent as i, PopoverDescription as a, PopoverHeader as o, PopoverTitle as s, PopoverTrigger as c } from "../ui/popover.js";
|
|
4
|
+
import { cn as l } from "cn";
|
|
5
|
+
import { useId as u, useRef as d, useState as f } from "react";
|
|
6
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
7
|
+
import { Columns3Icon as h, GripVerticalIcon as g } from "lucide-react";
|
|
8
|
+
import { DndContext as _, KeyboardSensor as v, PointerSensor as y, closestCenter as b, useSensor as x, useSensors as S } from "@dnd-kit/core";
|
|
9
|
+
import { SortableContext as C, arrayMove as w, sortableKeyboardCoordinates as T, useSortable as E, verticalListSortingStrategy as D } from "@dnd-kit/sortable";
|
|
10
|
+
import { CSS as O } from "@dnd-kit/utilities";
|
|
11
|
+
// src/components/etic/data-table-view-options.tsx
|
|
12
|
+
function k(e) {
|
|
13
|
+
let { meta: t, header: n } = e.columnDef;
|
|
14
|
+
return t?.libelle ? t.libelle : typeof n == "string" ? n : e.id;
|
|
15
|
+
}
|
|
16
|
+
function A(e, t, n) {
|
|
17
|
+
let r = n[Symbol.iterator]();
|
|
18
|
+
return e.map((e) => t.has(e) ? r.next().value : e);
|
|
19
|
+
}
|
|
20
|
+
var j = /* @__PURE__ */ new Set([
|
|
21
|
+
"select",
|
|
22
|
+
"expand",
|
|
23
|
+
"actions"
|
|
24
|
+
]), M = ({ transform: e }) => ({
|
|
25
|
+
...e,
|
|
26
|
+
x: 0
|
|
27
|
+
}), N = { draggable: "Pour déplacer une colonne, appuyez sur Espace ou Entrée, déplacez-la avec les flèches haut et bas, puis appuyez de nouveau sur Espace ou Entrée pour la déposer, ou sur Échap pour annuler." };
|
|
28
|
+
function P({ table: t, libelle: n = "Colonnes", className: g }) {
|
|
29
|
+
let [E, O] = f(!1), P = d(!1), I = d(null), L = S(x(y, { activationConstraint: { distance: 4 } }), x(v, { coordinateGetter: T })), R = t.getAllLeafColumns(), z = R.filter((e) => e.getCanHide()), B = z.map((e) => e.id), V = R.filter((e) => e.getIsVisible() && !j.has(e.id) && (e.accessorFn || e.getCanHide())), H = V.length === 1 && V[0].getCanHide() ? V[0].id : void 0, U = u(), W = (e) => {
|
|
30
|
+
let t = z.find((t) => t.id === e);
|
|
31
|
+
return t ? k(t) : String(e);
|
|
32
|
+
}, G = (e) => `${B.indexOf(String(e)) + 1} sur ${B.length}`, K = {
|
|
33
|
+
onDragStart: ({ active: e }) => `Colonne ${W(e.id)} saisie, position ${G(e.id)}.`,
|
|
34
|
+
onDragOver: ({ active: e, over: t }) => t ? `Colonne ${W(e.id)} déplacée en position ${G(t.id)}.` : void 0,
|
|
35
|
+
onDragEnd: ({ active: e, over: t }) => t ? `Colonne ${W(e.id)} déposée en position ${G(t.id)}.` : `Colonne ${W(e.id)} déposée.`,
|
|
36
|
+
onDragCancel: ({ active: e }) => `Déplacement annulé : la colonne ${W(e.id)} reprend sa place.`
|
|
37
|
+
};
|
|
38
|
+
function q() {
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
P.current = !1;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function J({ active: e, over: n }) {
|
|
44
|
+
if (q(), !n || e.id === n.id) return;
|
|
45
|
+
let r = w(B, B.indexOf(String(e.id)), B.indexOf(String(n.id)));
|
|
46
|
+
t.setColumnOrder(A(R.map((e) => e.id), new Set(B), r));
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ m(r, {
|
|
49
|
+
open: E,
|
|
50
|
+
onOpenChange: (e, t) => {
|
|
51
|
+
!e && P.current ? t.allowPropagation() : O(e);
|
|
52
|
+
},
|
|
53
|
+
children: [/* @__PURE__ */ m(c, {
|
|
54
|
+
render: /* @__PURE__ */ p(e, {
|
|
55
|
+
variant: "outline",
|
|
56
|
+
className: l("h-8", g)
|
|
57
|
+
}),
|
|
58
|
+
children: [/* @__PURE__ */ p(h, { "data-icon": "inline-start" }), n]
|
|
59
|
+
}), /* @__PURE__ */ m(i, {
|
|
60
|
+
align: "end",
|
|
61
|
+
className: "w-64 gap-1 p-1",
|
|
62
|
+
initialFocus: () => I.current?.querySelector("[role=\"checkbox\"]") ?? !0,
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ m(o, {
|
|
65
|
+
className: "px-2 pt-1.5 pb-1",
|
|
66
|
+
children: [/* @__PURE__ */ p(s, {
|
|
67
|
+
className: "text-sm font-medium",
|
|
68
|
+
children: "Colonnes affichées"
|
|
69
|
+
}), /* @__PURE__ */ p(a, {
|
|
70
|
+
className: "text-xs",
|
|
71
|
+
children: "Cochez pour afficher, glissez pour réordonner."
|
|
72
|
+
})]
|
|
73
|
+
}),
|
|
74
|
+
/* @__PURE__ */ p(_, {
|
|
75
|
+
sensors: L,
|
|
76
|
+
collisionDetection: b,
|
|
77
|
+
modifiers: [M],
|
|
78
|
+
accessibility: {
|
|
79
|
+
announcements: K,
|
|
80
|
+
screenReaderInstructions: N
|
|
81
|
+
},
|
|
82
|
+
onDragStart: () => {
|
|
83
|
+
P.current = !0;
|
|
84
|
+
},
|
|
85
|
+
onDragEnd: J,
|
|
86
|
+
onDragCancel: q,
|
|
87
|
+
children: /* @__PURE__ */ p(C, {
|
|
88
|
+
items: B,
|
|
89
|
+
strategy: D,
|
|
90
|
+
children: /* @__PURE__ */ p("ul", {
|
|
91
|
+
ref: I,
|
|
92
|
+
className: "flex max-h-80 flex-col overflow-y-auto",
|
|
93
|
+
children: z.map((e) => /* @__PURE__ */ p(F, {
|
|
94
|
+
id: e.id,
|
|
95
|
+
libelle: k(e),
|
|
96
|
+
visible: e.getIsVisible(),
|
|
97
|
+
onVisibleChange: (t) => e.toggleVisibility(t),
|
|
98
|
+
verrou: e.id === H ? U : void 0
|
|
99
|
+
}, e.id))
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
}),
|
|
103
|
+
H ? /* @__PURE__ */ p("p", {
|
|
104
|
+
id: U,
|
|
105
|
+
className: "px-2 pb-1 text-xs text-muted-foreground",
|
|
106
|
+
children: "Au moins une colonne reste affichée."
|
|
107
|
+
}) : null
|
|
108
|
+
]
|
|
109
|
+
})]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function F({ id: e, libelle: r, visible: i, onVisibleChange: a, verrou: o }) {
|
|
113
|
+
let { attributes: s, listeners: c, setNodeRef: u, setActivatorNodeRef: d, transform: f, transition: h, isDragging: _ } = E({
|
|
114
|
+
id: e,
|
|
115
|
+
attributes: { roleDescription: "colonne déplaçable" }
|
|
116
|
+
});
|
|
117
|
+
return /* @__PURE__ */ m("li", {
|
|
118
|
+
ref: u,
|
|
119
|
+
style: {
|
|
120
|
+
transform: O.Translate.toString(f),
|
|
121
|
+
transition: h
|
|
122
|
+
},
|
|
123
|
+
"data-dragging": _ || void 0,
|
|
124
|
+
className: "flex items-center gap-1 rounded-md bg-popover pr-2 hover:bg-muted data-dragging:relative data-dragging:z-10 data-dragging:shadow-md",
|
|
125
|
+
children: [/* @__PURE__ */ p("button", {
|
|
126
|
+
type: "button",
|
|
127
|
+
ref: d,
|
|
128
|
+
className: l(t({
|
|
129
|
+
variant: "ghost",
|
|
130
|
+
size: "icon-xs"
|
|
131
|
+
}), "cursor-grab touch-none text-muted-foreground active:cursor-grabbing"),
|
|
132
|
+
"aria-label": `Déplacer la colonne ${r}`,
|
|
133
|
+
...s,
|
|
134
|
+
...c,
|
|
135
|
+
children: /* @__PURE__ */ p(g, {})
|
|
136
|
+
}), /* @__PURE__ */ m("label", {
|
|
137
|
+
className: "flex flex-1 cursor-pointer items-center gap-2 py-1.5 text-sm has-aria-disabled:cursor-not-allowed",
|
|
138
|
+
children: [/* @__PURE__ */ p(n, {
|
|
139
|
+
checked: i,
|
|
140
|
+
onCheckedChange: a,
|
|
141
|
+
readOnly: o !== void 0,
|
|
142
|
+
"aria-disabled": o !== void 0 || void 0,
|
|
143
|
+
"aria-describedby": o,
|
|
144
|
+
className: "aria-disabled:opacity-50"
|
|
145
|
+
}), r]
|
|
146
|
+
})]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export { P as DataTableViewOptions };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=data-table-view-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table-view-options.js","names":["libelleDe","colonne","meta","header","fusionnerOrdre","suivantes","nouvelOrdre","toutes","deplacables","id","COLONNES_DE_STRUCTURE","verticalSeulement","transform","INSTRUCTIONS","DataTableViewOptions","ouvert","setOuvert","useState","glisseRef","useRef","listeRef","capteurs","useSensors","useSensor","PointerSensor","KeyboardSensor","sortableKeyboardCoordinates","table","colonnes","ids","donneesVisibles","derniere","idVerrou","useId","nom","c","position","annonces","active","over","finirGlisser","deposer","arrayMove","Popover","suivant","details","PopoverTrigger","Button","cn","className","Columns3Icon","libelle","PopoverContent","PopoverHeader","PopoverTitle","PopoverDescription","DndContext","closestCenter","SortableContext","verticalListSortingStrategy","ElementColonne","visible","useSortable","setNodeRef","CSS","isDragging","setActivatorNodeRef","buttonVariants","attributes","listeners","GripVerticalIcon","Checkbox","onVisibleChange","verrou"],"sources":["../../../src/components/etic/data-table-view-options.tsx"],"sourcesContent":["import { useId, useRef, useState } from \"react\"\nimport {\n DndContext,\n KeyboardSensor,\n PointerSensor,\n closestCenter,\n useSensor,\n useSensors,\n type Announcements,\n type DragEndEvent,\n type Modifier,\n type UniqueIdentifier,\n} from \"@dnd-kit/core\"\nimport {\n SortableContext,\n arrayMove,\n sortableKeyboardCoordinates,\n useSortable,\n verticalListSortingStrategy,\n} from \"@dnd-kit/sortable\"\nimport { CSS } from \"@dnd-kit/utilities\"\nimport type { Column, RowData } from \"@tanstack/react-table\"\nimport { cn } from \"cn\"\nimport { Columns3Icon, GripVerticalIcon } from \"lucide-react\"\n\nimport { Button, buttonVariants } from \"@etic-ui/components/ui/button\"\nimport { Checkbox } from \"@etic-ui/components/ui/checkbox\"\nimport {\n Popover,\n PopoverContent,\n PopoverDescription,\n PopoverHeader,\n PopoverTitle,\n PopoverTrigger,\n} from \"@etic-ui/components/ui/popover\"\nimport type {\n DataTableFeatures,\n DataTableInstance,\n} from \"@etic-ui/components/etic/data-table\"\n\ntype Colonne<TData extends RowData> = Column<DataTableFeatures, TData, unknown>\n\n/** Nom d'une colonne : `meta.libelle`, sinon son en-tête s'il est un texte,\n * sinon son identifiant. */\nfunction libelleDe<TData extends RowData>(colonne: Colonne<TData>): string {\n const { meta, header } = colonne.columnDef\n if (meta?.libelle) return meta.libelle\n return typeof header === \"string\" ? header : colonne.id\n}\n\n/** Ordre complet des colonnes quand celles du sélecteur prennent l'ordre\n * `deplacables` : les colonnes fixes (sélection, actions…) gardent leur\n * place. */\nfunction fusionnerOrdre(\n toutes: string[],\n deplacables: Set<string>,\n nouvelOrdre: string[]\n): string[] {\n const suivantes = nouvelOrdre[Symbol.iterator]()\n return toutes.map((id) =>\n deplacables.has(id) ? (suivantes.next().value as string) : id\n )\n}\n\n/** Colonnes qui ne portent pas de données : cases de sélection\n * (`dataTableSelectionColumn`), dépliage (`dataTableExpandColumn`) et menu\n * des actions de ligne (`id: \"actions\"`, comme dans shadcn). */\nconst COLONNES_DE_STRUCTURE = new Set([\"select\", \"expand\", \"actions\"])\n\nconst verticalSeulement: Modifier = ({ transform }) => ({ ...transform, x: 0 })\n\nconst INSTRUCTIONS = {\n draggable:\n \"Pour déplacer une colonne, appuyez sur Espace ou Entrée, déplacez-la avec les flèches haut et bas, puis appuyez de nouveau sur Espace ou Entrée pour la déposer, ou sur Échap pour annuler.\",\n}\n\nexport interface DataTableViewOptionsProps<TData extends RowData> {\n table: DataTableInstance<TData>\n /** Texte du bouton. « Colonnes » par défaut. */\n libelle?: string\n className?: string\n}\n\n/**\n * Sélecteur de colonnes : le bouton « Colonnes » de shadcn, dont le panneau\n * coche les colonnes affichées et les réordonne par glisser-déposer (dnd-kit),\n * à la souris, au toucher ou au clavier (poignée : Espace, flèches, Espace).\n * Les colonnes qui ne se masquent pas (`enableHiding: false`) n'y figurent\n * pas et gardent leur place. Le panneau reste ouvert pendant les réglages.\n */\nexport function DataTableViewOptions<TData extends RowData>({\n table,\n libelle = \"Colonnes\",\n className,\n}: DataTableViewOptionsProps<TData>) {\n const [ouvert, setOuvert] = useState(false)\n // Échap annule un glisser au clavier : il ne doit pas aussi fermer le panneau.\n const glisseRef = useRef(false)\n const listeRef = useRef<HTMLUListElement>(null)\n const capteurs = useSensors(\n useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n })\n )\n\n const toutes = table.getAllLeafColumns()\n const colonnes = toutes.filter((colonne) => colonne.getCanHide())\n const ids = colonnes.map((colonne) => colonne.id)\n // La dernière colonne de données affichée ne se masque pas : il ne\n // resterait que les cases et les menus, un tableau vide en apparence.\n // Colonne de données : à accesseur, ou de rendu (`display`) masquable ;\n // jamais la sélection, le dépliage ni les actions de ligne.\n const donneesVisibles = toutes.filter(\n (colonne) =>\n colonne.getIsVisible() &&\n !COLONNES_DE_STRUCTURE.has(colonne.id) &&\n (colonne.accessorFn || colonne.getCanHide())\n )\n const derniere =\n donneesVisibles.length === 1 && donneesVisibles[0].getCanHide()\n ? donneesVisibles[0].id\n : undefined\n const idVerrou = useId()\n const nom = (id: UniqueIdentifier) => {\n const colonne = colonnes.find((c) => c.id === id)\n return colonne ? libelleDe(colonne) : String(id)\n }\n const position = (id: UniqueIdentifier) =>\n `${ids.indexOf(String(id)) + 1} sur ${ids.length}`\n\n const annonces: Announcements = {\n onDragStart: ({ active }) =>\n `Colonne ${nom(active.id)} saisie, position ${position(active.id)}.`,\n onDragOver: ({ active, over }) =>\n over\n ? `Colonne ${nom(active.id)} déplacée en position ${position(over.id)}.`\n : undefined,\n onDragEnd: ({ active, over }) =>\n over\n ? `Colonne ${nom(active.id)} déposée en position ${position(over.id)}.`\n : `Colonne ${nom(active.id)} déposée.`,\n onDragCancel: ({ active }) =>\n `Déplacement annulé : la colonne ${nom(active.id)} reprend sa place.`,\n }\n\n function finirGlisser() {\n // Laisse passer l'Échap en cours avant de rendre la main au panneau.\n setTimeout(() => {\n glisseRef.current = false\n })\n }\n\n function deposer({ active, over }: DragEndEvent) {\n finirGlisser()\n if (!over || active.id === over.id) return\n const nouvelOrdre = arrayMove(\n ids,\n ids.indexOf(String(active.id)),\n ids.indexOf(String(over.id))\n )\n table.setColumnOrder(\n fusionnerOrdre(\n toutes.map((colonne) => colonne.id),\n new Set(ids),\n nouvelOrdre\n )\n )\n }\n\n return (\n <Popover\n open={ouvert}\n onOpenChange={(suivant, details) => {\n if (!suivant && glisseRef.current) {\n // Échap revient à dnd-kit (qui l'écoute sur window) pour annuler\n // le glisser ; le panneau reste ouvert.\n details.allowPropagation()\n return\n }\n setOuvert(suivant)\n }}\n >\n <PopoverTrigger\n render={<Button variant=\"outline\" className={cn(\"h-8\", className)} />}\n >\n <Columns3Icon data-icon=\"inline-start\" />\n {libelle}\n </PopoverTrigger>\n <PopoverContent\n align=\"end\"\n className=\"w-64 gap-1 p-1\"\n // La première case plutôt que la première poignée : cocher est le\n // geste courant, et une poignée n'est utile qu'au glisser.\n initialFocus={() =>\n listeRef.current?.querySelector<HTMLElement>('[role=\"checkbox\"]') ??\n true\n }\n >\n <PopoverHeader className=\"px-2 pt-1.5 pb-1\">\n <PopoverTitle className=\"text-sm font-medium\">\n Colonnes affichées\n </PopoverTitle>\n <PopoverDescription className=\"text-xs\">\n Cochez pour afficher, glissez pour réordonner.\n </PopoverDescription>\n </PopoverHeader>\n <DndContext\n sensors={capteurs}\n collisionDetection={closestCenter}\n modifiers={[verticalSeulement]}\n accessibility={{\n announcements: annonces,\n screenReaderInstructions: INSTRUCTIONS,\n }}\n onDragStart={() => {\n glisseRef.current = true\n }}\n onDragEnd={deposer}\n onDragCancel={finirGlisser}\n >\n <SortableContext items={ids} strategy={verticalListSortingStrategy}>\n <ul\n ref={listeRef}\n className=\"flex max-h-80 flex-col overflow-y-auto\"\n >\n {colonnes.map((colonne) => (\n <ElementColonne\n key={colonne.id}\n id={colonne.id}\n libelle={libelleDe(colonne)}\n visible={colonne.getIsVisible()}\n onVisibleChange={(visible) =>\n colonne.toggleVisibility(visible)\n }\n verrou={colonne.id === derniere ? idVerrou : undefined}\n />\n ))}\n </ul>\n </SortableContext>\n </DndContext>\n {derniere ? (\n <p id={idVerrou} className=\"px-2 pb-1 text-xs text-muted-foreground\">\n Au moins une colonne reste affichée.\n </p>\n ) : null}\n </PopoverContent>\n </Popover>\n )\n}\n\nfunction ElementColonne({\n id,\n libelle,\n visible,\n onVisibleChange,\n verrou,\n}: {\n id: string\n libelle: string\n visible: boolean\n onVisibleChange: (visible: boolean) => void\n /** Id du texte qui dit pourquoi la case ne se décoche pas. */\n verrou?: string\n}) {\n const {\n attributes,\n listeners,\n setNodeRef,\n setActivatorNodeRef,\n transform,\n transition,\n isDragging,\n } = useSortable({\n id,\n attributes: { roleDescription: \"colonne déplaçable\" },\n })\n\n return (\n <li\n ref={setNodeRef}\n style={{ transform: CSS.Translate.toString(transform), transition }}\n data-dragging={isDragging || undefined}\n className=\"flex items-center gap-1 rounded-md bg-popover pr-2 hover:bg-muted data-dragging:relative data-dragging:z-10 data-dragging:shadow-md\"\n >\n {/* Sans infobulle : ouverte au focus, elle prenait pour elle le premier\n Échap, qui ne fermait plus le panneau. L'en-tête du panneau dit\n déjà « glissez pour réordonner ». */}\n <button\n type=\"button\"\n ref={setActivatorNodeRef}\n className={cn(\n buttonVariants({ variant: \"ghost\", size: \"icon-xs\" }),\n \"cursor-grab touch-none text-muted-foreground active:cursor-grabbing\"\n )}\n aria-label={`Déplacer la colonne ${libelle}`}\n {...attributes}\n {...listeners}\n >\n <GripVerticalIcon />\n </button>\n <label className=\"flex flex-1 cursor-pointer items-center gap-2 py-1.5 text-sm has-aria-disabled:cursor-not-allowed\">\n <Checkbox\n checked={visible}\n onCheckedChange={onVisibleChange}\n readOnly={verrou !== undefined}\n aria-disabled={verrou !== undefined || undefined}\n aria-describedby={verrou}\n className=\"aria-disabled:opacity-50\"\n />\n {libelle}\n </label>\n </li>\n )\n}\n"],"mappings":";;;;;;;;;;;AA4CA,SAASA,EAAiC,GAAiC;CACzE,IAAM,EAAE,SAAM,cAAWC,EAAQ;CAEjC,OADIC,GAAM,UAAgBA,EAAK,UACxB,OAAOC,KAAW,WAAWA,IAASF,EAAQ;AACvD;AAKA,SAASG,EACP,GACA,GACA,GACU;CACV,IAAMC,IAAYC,EAAY,OAAO,SAAS,CAAC;CAC/C,OAAOC,EAAO,KAAK,MACjBC,EAAY,IAAIC,CAAE,IAAKJ,EAAU,KAAK,CAAC,CAAC,QAAmBI,CAC7D;AACF;AAKA,IAAMC,oBAAwB,IAAI,IAAI;CAAC;CAAU;CAAU;AAAS,CAAC,GAE/DC,KAA+B,EAAE,oBAAiB;CAAE,GAAGC;CAAW,GAAG;AAAE,IAEvEC,IAAe,EACnB,WACE,8LACJ;AAgBA,SAAgBC,EAA4C,EAC1D,UACA,aAAU,YACV,gBACmC;CACnC,IAAM,CAACC,GAAQC,KAAaC,EAAS,EAAK,GAEpCC,IAAYC,EAAO,EAAK,GACxBC,IAAWD,EAAyB,IAAI,GACxCE,IAAWC,EACfC,EAAUC,GAAe,EAAE,sBAAsB,EAAE,UAAU,EAAE,EAAE,CAAC,GAClED,EAAUE,GAAgB,EACxB,kBAAkBC,EACpB,CAAC,CACH,GAEMnB,IAASoB,EAAM,kBAAkB,GACjCC,IAAWrB,EAAO,QAAQ,MAAYN,EAAQ,WAAW,CAAC,GAC1D4B,IAAMD,EAAS,KAAK,MAAY3B,EAAQ,EAAE,GAK1C6B,IAAkBvB,EAAO,QAC5B,MACCN,EAAQ,aAAa,KACrB,CAACS,EAAsB,IAAIT,EAAQ,EAAE,MACpCA,EAAQ,cAAcA,EAAQ,WAAW,EAC9C,GACM8B,IACJD,EAA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