@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.
Files changed (213) hide show
  1. package/README.md +496 -12
  2. package/dist/components/etic/action.d.ts +33 -0
  3. package/dist/components/etic/action.js +43 -0
  4. package/dist/components/etic/action.js.map +1 -0
  5. package/dist/components/etic/app-shell.d.ts +7 -4
  6. package/dist/components/etic/app-shell.js +119 -81
  7. package/dist/components/etic/app-shell.js.map +1 -1
  8. package/dist/components/etic/auth-image.d.ts +48 -0
  9. package/dist/components/etic/auth-image.js +44 -0
  10. package/dist/components/etic/auth-image.js.map +1 -0
  11. package/dist/components/etic/checkbox-list.d.ts +30 -0
  12. package/dist/components/etic/checkbox-list.js +56 -0
  13. package/dist/components/etic/checkbox-list.js.map +1 -0
  14. package/dist/components/etic/confirm-dialog.d.ts +63 -0
  15. package/dist/components/etic/confirm-dialog.js +84 -0
  16. package/dist/components/etic/confirm-dialog.js.map +1 -0
  17. package/dist/components/etic/copy-button.d.ts +24 -0
  18. package/dist/components/etic/copy-button.js +46 -0
  19. package/dist/components/etic/copy-button.js.map +1 -0
  20. package/dist/components/etic/data-table-bulk-actions.d.ts +29 -0
  21. package/dist/components/etic/data-table-bulk-actions.js +97 -0
  22. package/dist/components/etic/data-table-bulk-actions.js.map +1 -0
  23. package/dist/components/etic/data-table-format.d.ts +12 -0
  24. package/dist/components/etic/data-table-format.js +8 -0
  25. package/dist/components/etic/data-table-format.js.map +1 -0
  26. package/dist/components/etic/data-table-pagination.d.ts +22 -0
  27. package/dist/components/etic/data-table-pagination.js +104 -0
  28. package/dist/components/etic/data-table-pagination.js.map +1 -0
  29. package/dist/components/etic/data-table-toolbar.d.ts +69 -0
  30. package/dist/components/etic/data-table-toolbar.js +127 -0
  31. package/dist/components/etic/data-table-toolbar.js.map +1 -0
  32. package/dist/components/etic/data-table-view-options.d.ts +16 -0
  33. package/dist/components/etic/data-table-view-options.js +151 -0
  34. package/dist/components/etic/data-table-view-options.js.map +1 -0
  35. package/dist/components/etic/data-table.d.ts +263 -0
  36. package/dist/components/etic/data-table.js +403 -0
  37. package/dist/components/etic/data-table.js.map +1 -0
  38. package/dist/components/etic/date-picker.d.ts +32 -0
  39. package/dist/components/etic/date-picker.js +162 -0
  40. package/dist/components/etic/date-picker.js.map +1 -0
  41. package/dist/components/etic/delete-button.d.ts +57 -0
  42. package/dist/components/etic/delete-button.js +38 -0
  43. package/dist/components/etic/delete-button.js.map +1 -0
  44. package/dist/components/etic/detail-list.d.ts +14 -0
  45. package/dist/components/etic/detail-list.js +36 -0
  46. package/dist/components/etic/detail-list.js.map +1 -0
  47. package/dist/components/etic/empty-state.d.ts +20 -0
  48. package/dist/components/etic/empty-state.js +20 -0
  49. package/dist/components/etic/empty-state.js.map +1 -0
  50. package/dist/components/etic/error-banner.d.ts +50 -0
  51. package/dist/components/etic/error-banner.js +89 -0
  52. package/dist/components/etic/error-banner.js.map +1 -0
  53. package/dist/components/etic/error-boundary.d.ts +53 -0
  54. package/dist/components/etic/error-boundary.js +82 -0
  55. package/dist/components/etic/error-boundary.js.map +1 -0
  56. package/dist/components/etic/file-upload.d.ts +52 -0
  57. package/dist/components/etic/file-upload.js +142 -0
  58. package/dist/components/etic/file-upload.js.map +1 -0
  59. package/dist/components/etic/form-dialog.d.ts +45 -0
  60. package/dist/components/etic/form-dialog.js +136 -0
  61. package/dist/components/etic/form-dialog.js.map +1 -0
  62. package/dist/components/etic/form-field-context.d.ts +66 -0
  63. package/dist/components/etic/form-field-context.js +28 -0
  64. package/dist/components/etic/form-field-context.js.map +1 -0
  65. package/dist/components/etic/form-field.d.ts +53 -0
  66. package/dist/components/etic/form-field.js +105 -0
  67. package/dist/components/etic/form-field.js.map +1 -0
  68. package/dist/components/etic/icon-toggle.d.ts +33 -0
  69. package/dist/components/etic/icon-toggle.js +28 -0
  70. package/dist/components/etic/icon-toggle.js.map +1 -0
  71. package/dist/components/etic/loading.d.ts +45 -0
  72. package/dist/components/etic/loading.js +82 -0
  73. package/dist/components/etic/loading.js.map +1 -0
  74. package/dist/components/etic/page-container.d.ts +17 -0
  75. package/dist/components/etic/page-container.js +20 -0
  76. package/dist/components/etic/page-container.js.map +1 -0
  77. package/dist/components/etic/page-header.d.ts +58 -0
  78. package/dist/components/etic/page-header.js +104 -0
  79. package/dist/components/etic/page-header.js.map +1 -0
  80. package/dist/components/etic/phone-input.d.ts +31 -0
  81. package/dist/components/etic/phone-input.js +133 -0
  82. package/dist/components/etic/phone-input.js.map +1 -0
  83. package/dist/components/etic/query-boundary.d.ts +50 -0
  84. package/dist/components/etic/query-boundary.js +25 -0
  85. package/dist/components/etic/query-boundary.js.map +1 -0
  86. package/dist/components/etic/search-select.d.ts +41 -0
  87. package/dist/components/etic/search-select.js +126 -0
  88. package/dist/components/etic/search-select.js.map +1 -0
  89. package/dist/components/etic/section-card.d.ts +12 -0
  90. package/dist/components/etic/section-card.js +23 -0
  91. package/dist/components/etic/section-card.js.map +1 -0
  92. package/dist/components/etic/segmented-control.d.ts +29 -0
  93. package/dist/components/etic/segmented-control.js +44 -0
  94. package/dist/components/etic/segmented-control.js.map +1 -0
  95. package/dist/components/etic/stat-tile.d.ts +18 -0
  96. package/dist/components/etic/stat-tile.js +39 -0
  97. package/dist/components/etic/stat-tile.js.map +1 -0
  98. package/dist/components/etic/status-badge.d.ts +16 -0
  99. package/dist/components/etic/status-badge.js +30 -0
  100. package/dist/components/etic/status-badge.js.map +1 -0
  101. package/dist/components/etic/theme-menu.d.ts +5 -3
  102. package/dist/components/etic/theme-menu.js +38 -32
  103. package/dist/components/etic/theme-menu.js.map +1 -1
  104. package/dist/components/etic/tooltip-button.d.ts +29 -0
  105. package/dist/components/etic/tooltip-button.js +39 -0
  106. package/dist/components/etic/tooltip-button.js.map +1 -0
  107. package/dist/components/etic/use-draft-autosave.d.ts +68 -0
  108. package/dist/components/etic/use-draft-autosave.js +102 -0
  109. package/dist/components/etic/use-draft-autosave.js.map +1 -0
  110. package/dist/components/ui/alert-dialog.js +31 -31
  111. package/dist/components/ui/alert.d.ts +10 -0
  112. package/dist/components/ui/alert.js +47 -0
  113. package/dist/components/ui/alert.js.map +1 -0
  114. package/dist/components/ui/badge.d.ts +7 -0
  115. package/dist/components/ui/badge.js +32 -0
  116. package/dist/components/ui/badge.js.map +1 -0
  117. package/dist/components/ui/breadcrumb.d.ts +10 -0
  118. package/dist/components/ui/breadcrumb.js +73 -0
  119. package/dist/components/ui/breadcrumb.js.map +1 -0
  120. package/dist/components/ui/button-group.d.ts +10 -0
  121. package/dist/components/ui/button-group.js +42 -0
  122. package/dist/components/ui/button-group.js.map +1 -0
  123. package/dist/components/ui/button.d.ts +1 -1
  124. package/dist/components/ui/button.js +8 -8
  125. package/dist/components/ui/button.js.map +1 -1
  126. package/dist/components/ui/calendar.d.ts +10 -0
  127. package/dist/components/ui/calendar.js +96 -0
  128. package/dist/components/ui/calendar.js.map +1 -0
  129. package/dist/components/ui/card.d.ts +11 -0
  130. package/dist/components/ui/card.js +57 -0
  131. package/dist/components/ui/card.js.map +1 -0
  132. package/dist/components/ui/checkbox.d.ts +3 -0
  133. package/dist/components/ui/checkbox.js +20 -0
  134. package/dist/components/ui/checkbox.js.map +1 -0
  135. package/dist/components/ui/collapsible.d.ts +5 -0
  136. package/dist/components/ui/collapsible.js +25 -0
  137. package/dist/components/ui/collapsible.js.map +1 -0
  138. package/dist/components/ui/combobox.d.ts +24 -0
  139. package/dist/components/ui/combobox.js +165 -0
  140. package/dist/components/ui/combobox.js.map +1 -0
  141. package/dist/components/ui/dialog.d.ts +17 -0
  142. package/dist/components/ui/dialog.js +92 -0
  143. package/dist/components/ui/dialog.js.map +1 -0
  144. package/dist/components/ui/dropdown-menu.js +36 -36
  145. package/dist/components/ui/empty.d.ts +11 -0
  146. package/dist/components/ui/empty.js +60 -0
  147. package/dist/components/ui/empty.js.map +1 -0
  148. package/dist/components/ui/field.d.ts +24 -0
  149. package/dist/components/ui/field.js +108 -0
  150. package/dist/components/ui/field.js.map +1 -0
  151. package/dist/components/ui/input-group.d.ts +18 -0
  152. package/dist/components/ui/input-group.js +79 -0
  153. package/dist/components/ui/input-group.js.map +1 -0
  154. package/dist/components/ui/item.d.ts +22 -0
  155. package/dist/components/ui/item.js +122 -0
  156. package/dist/components/ui/item.js.map +1 -0
  157. package/dist/components/ui/kbd.d.ts +3 -0
  158. package/dist/components/ui/kbd.js +20 -0
  159. package/dist/components/ui/kbd.js.map +1 -0
  160. package/dist/components/ui/label.d.ts +3 -0
  161. package/dist/components/ui/label.js +14 -0
  162. package/dist/components/ui/label.js.map +1 -0
  163. package/dist/components/ui/native-select.d.ts +8 -0
  164. package/dist/components/ui/native-select.js +39 -0
  165. package/dist/components/ui/native-select.js.map +1 -0
  166. package/dist/components/ui/pagination.d.ts +17 -0
  167. package/dist/components/ui/pagination.js +81 -0
  168. package/dist/components/ui/pagination.js.map +1 -0
  169. package/dist/components/ui/popover.d.ts +9 -0
  170. package/dist/components/ui/popover.js +55 -0
  171. package/dist/components/ui/popover.js.map +1 -0
  172. package/dist/components/ui/progress.d.ts +7 -0
  173. package/dist/components/ui/progress.js +45 -0
  174. package/dist/components/ui/progress.js.map +1 -0
  175. package/dist/components/ui/radio-group.d.ts +5 -0
  176. package/dist/components/ui/radio-group.js +27 -0
  177. package/dist/components/ui/radio-group.js.map +1 -0
  178. package/dist/components/ui/scroll-area.d.ts +4 -0
  179. package/dist/components/ui/scroll-area.js +36 -0
  180. package/dist/components/ui/scroll-area.js.map +1 -0
  181. package/dist/components/ui/select.d.ts +15 -0
  182. package/dist/components/ui/select.js +99 -0
  183. package/dist/components/ui/select.js.map +1 -0
  184. package/dist/components/ui/sidebar.js +47 -47
  185. package/dist/components/ui/sidebar.js.map +1 -1
  186. package/dist/components/ui/slider.d.ts +3 -0
  187. package/dist/components/ui/slider.js +36 -0
  188. package/dist/components/ui/slider.js.map +1 -0
  189. package/dist/components/ui/spinner.d.ts +2 -0
  190. package/dist/components/ui/spinner.js +16 -0
  191. package/dist/components/ui/spinner.js.map +1 -0
  192. package/dist/components/ui/switch.d.ts +5 -0
  193. package/dist/components/ui/switch.js +20 -0
  194. package/dist/components/ui/switch.js.map +1 -0
  195. package/dist/components/ui/table.d.ts +10 -0
  196. package/dist/components/ui/table.js +67 -0
  197. package/dist/components/ui/table.js.map +1 -0
  198. package/dist/components/ui/tabs.d.ts +10 -0
  199. package/dist/components/ui/tabs.js +46 -0
  200. package/dist/components/ui/tabs.js.map +1 -0
  201. package/dist/components/ui/textarea.d.ts +3 -0
  202. package/dist/components/ui/textarea.js +14 -0
  203. package/dist/components/ui/textarea.js.map +1 -0
  204. package/dist/components/ui/toggle-group.d.ts +11 -0
  205. package/dist/components/ui/toggle-group.js +54 -0
  206. package/dist/components/ui/toggle-group.js.map +1 -0
  207. package/dist/components/ui/toggle.d.ts +8 -0
  208. package/dist/components/ui/toggle.js +36 -0
  209. package/dist/components/ui/toggle.js.map +1 -0
  210. package/dist/index.d.ts +66 -0
  211. package/dist/index.js +76 -13
  212. package/dist/styles.css +39 -4
  213. package/package.json +18 -7
@@ -0,0 +1,136 @@
1
+ import { Button as e } from "../ui/button.js";
2
+ import { Dialog as t, DialogContent as n, DialogDescription as r, DialogFooter as i, DialogHeader as a, DialogTitle as o, DialogTrigger as s } from "../ui/dialog.js";
3
+ import { SpinnerBouton as c, useAction as l, useOuvertureDialogue as u } from "./action.js";
4
+ import { ErrorBanner as d } from "./error-banner.js";
5
+ import { TooltipButton as f } from "./tooltip-button.js";
6
+ import { cn as p } from "cn";
7
+ import { useRef as m, useState as h } from "react";
8
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
9
+ import { XIcon as v } from "lucide-react";
10
+ // src/components/etic/form-dialog.tsx
11
+ var y = ["input:not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"file\"]):not([type=\"hidden\"]):not([type=\"submit\"]):not([type=\"button\"])", "textarea"].map((e) => `${e}:not([disabled]):not([readonly]):not([tabindex="-1"]):not([aria-hidden="true"])`).join(", "), b = {
12
+ sm: "sm:max-w-sm",
13
+ md: "sm:max-w-lg",
14
+ lg: "sm:max-w-2xl",
15
+ xl: "sm:max-w-4xl"
16
+ };
17
+ function x({ validity: e, validationMessage: t }) {
18
+ return e.valueMissing ? "obligatoire" : e.typeMismatch || e.patternMismatch ? "format invalide" : e.tooShort ? "trop court" : e.tooLong ? "trop long" : e.rangeUnderflow ? "valeur trop petite" : e.rangeOverflow ? "valeur trop grande" : e.stepMismatch ? "valeur non permise" : e.badInput ? "valeur illisible" : t || "valeur invalide";
19
+ }
20
+ function S(e) {
21
+ return e?.textContent?.replace(/\s*\*\s*$/, "").trim() || void 0;
22
+ }
23
+ function C(e) {
24
+ return e.getAttribute("aria-hidden") === "true" || e.getAttribute("type") === "hidden" || e.tabIndex < 0;
25
+ }
26
+ function w(e) {
27
+ return e.closest("[data-slot=\"field\"]")?.querySelector("[data-slot=\"field-label\"]");
28
+ }
29
+ function T(e) {
30
+ if (!C(e)) return e;
31
+ let t = w(e)?.htmlFor;
32
+ return t && document.getElementById(t) || e;
33
+ }
34
+ function E(e) {
35
+ let t = T(e);
36
+ return S((t.labels ?? e.labels)?.[0]) || t.getAttribute("aria-label")?.trim() || S(document.getElementById(t.getAttribute("aria-labelledby")?.split(/\s+/)[0] ?? "")) || S(w(e)) || e.name || "Champ";
37
+ }
38
+ function D({ titre: S, description: C, children: w, onEnvoyer: D, libelleEnvoyer: O = "Enregistrer", envoiDesactive: k = !1, verrouEnvoi: A, taille: j = "md", ouvert: M, onOuvertChange: N, declencheur: P, finalFocus: F, className: I }) {
39
+ let L = l(), R = u(M, N, L.enCours), [z, B] = h([]), V = m(null), H = m(null), U = m(null), W = m(/* @__PURE__ */ new Map()), G = (e = !1) => {
40
+ for (let [t, n] of W.current) (e || n.validity.valid) && (t.removeAttribute("aria-invalid"), W.current.delete(t));
41
+ };
42
+ return /* @__PURE__ */ _(t, {
43
+ open: R.ouvert,
44
+ onOpenChange: R.changer,
45
+ onOpenChangeComplete: (e) => {
46
+ e || (L.reinitialiser(), B([]), G(!0));
47
+ },
48
+ children: [P ? /* @__PURE__ */ g(s, { render: P }) : null, /* @__PURE__ */ _(n, {
49
+ showCloseButton: !1,
50
+ className: p("max-h-[calc(100dvh-2rem)] overflow-y-auto", b[j], I),
51
+ initialFocus: () => V.current?.querySelector(y) ?? !0,
52
+ finalFocus: F,
53
+ children: [
54
+ /* @__PURE__ */ _(a, { children: [/* @__PURE__ */ g(o, { children: S }), C ? /* @__PURE__ */ g(r, { children: C }) : null] }),
55
+ /* @__PURE__ */ _("form", {
56
+ ref: V,
57
+ onSubmit: (e) => {
58
+ if (e.preventDefault(), L.enCours || k || A) return;
59
+ let t = e.currentTarget, n = Array.from(t.elements).filter((e) => "willValidate" in e && e.willValidate === !0 && !e.validity.valid);
60
+ B(n.map((e) => ({
61
+ nom: E(e),
62
+ raison: x(e)
63
+ }))), G(!0);
64
+ for (let e of n) {
65
+ let t = T(e);
66
+ [
67
+ "true",
68
+ "grammar",
69
+ "spelling"
70
+ ].includes(t.getAttribute("aria-invalid") ?? "") || (t.setAttribute("aria-invalid", "true"), W.current.set(t, e));
71
+ }
72
+ n.length > 0 ? T(n[0]).focus() : (H.current?.contains(document.activeElement) && U.current?.focus(), L.lancer(() => D(e), () => R.definir(!1)));
73
+ },
74
+ onInput: () => G(),
75
+ onChange: () => G(),
76
+ onBlur: () => G(),
77
+ noValidate: !0,
78
+ "aria-busy": L.enCours || void 0,
79
+ className: "flex flex-col gap-4",
80
+ children: [
81
+ /* @__PURE__ */ g(d, { erreur: L.erreur }),
82
+ /* @__PURE__ */ g(d, {
83
+ erreur: z.length > 0,
84
+ titre: "Le formulaire est incomplet.",
85
+ description: /* @__PURE__ */ g("ul", {
86
+ className: "list-disc pl-4",
87
+ children: z.map(({ nom: e, raison: t }, n) => /* @__PURE__ */ _("li", { children: [
88
+ e,
89
+ "\xA0: ",
90
+ t
91
+ ] }, n))
92
+ })
93
+ }),
94
+ /* @__PURE__ */ g("fieldset", {
95
+ ref: H,
96
+ disabled: L.enCours,
97
+ className: "contents",
98
+ children: w
99
+ }),
100
+ /* @__PURE__ */ _(i, { children: [/* @__PURE__ */ g(e, {
101
+ variant: "outline",
102
+ disabled: L.enCours,
103
+ focusableWhenDisabled: !0,
104
+ onClick: () => R.changer(!1),
105
+ children: "Annuler"
106
+ }), /* @__PURE__ */ _(f, {
107
+ ref: U,
108
+ type: "submit",
109
+ disabled: L.enCours || k,
110
+ focusableWhenDisabled: !0,
111
+ verrou: A,
112
+ "aria-busy": L.enCours || void 0,
113
+ children: [L.enCours ? /* @__PURE__ */ g(c, {}) : null, O]
114
+ })] })
115
+ ]
116
+ }),
117
+ /* @__PURE__ */ _(e, {
118
+ variant: "ghost",
119
+ size: "icon-sm",
120
+ "data-slot": "dialog-close",
121
+ className: "absolute top-2 right-2",
122
+ disabled: L.enCours,
123
+ focusableWhenDisabled: !0,
124
+ onClick: () => R.changer(!1),
125
+ children: [/* @__PURE__ */ g(v, {}), /* @__PURE__ */ g("span", {
126
+ className: "sr-only",
127
+ children: "Fermer"
128
+ })]
129
+ })
130
+ ]
131
+ })]
132
+ });
133
+ }
134
+ export { D as FormDialog };
135
+
136
+ //# sourceMappingURL=form-dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-dialog.js","names":["PREMIER_CHAMP","selecteur","LARGEURS","raisonInvalide","validity","validationMessage","texteDuLibelle","element","estCache","champ","libelleDuField","controleVisible","cible","nomDuChamp","visible","FormDialog","action","useAction","ouverture","useOuvertureDialogue","ouvert","onOuvertChange","invalides","setInvalides","useState","formulaire","useRef","champs","boutonEnvoi","marques","demarquer","tout","Dialog","suivant","declencheur","DialogTrigger","DialogContent","cn","taille","className","DialogHeader","DialogTitle","titre","description","DialogDescription","event","envoiDesactive","verrouEnvoi","form","fautifs","onEnvoyer","ErrorBanner","nom","raison","index","DialogFooter","Button","TooltipButton","SpinnerBouton","libelleEnvoyer","XIcon"],"sources":["../../../src/components/etic/form-dialog.tsx"],"sourcesContent":["import {\n useRef,\n useState,\n type FormEvent,\n type ReactElement,\n type ReactNode,\n} from \"react\"\nimport { cn } from \"cn\"\nimport { XIcon } from \"lucide-react\"\n\nimport { Button } from \"@etic-ui/components/ui/button\"\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from \"@etic-ui/components/ui/dialog\"\nimport {\n SpinnerBouton,\n useAction,\n useOuvertureDialogue,\n} from \"@etic-ui/components/etic/action\"\nimport type { DialogFinalFocus } from \"@etic-ui/components/etic/confirm-dialog\"\nimport { ErrorBanner } from \"@etic-ui/components/etic/error-banner\"\nimport { TooltipButton } from \"@etic-ui/components/etic/tooltip-button\"\n\n/**\n * Premier champ où l'on tape : ni case, ni bouton radio, ni fichier, ni\n * liste déroulante (elle a déjà une valeur valable), ni champ désactivé ou\n * en lecture seule, ni l'entrée cachée d'un `Select` ou d'un `Combobox` de\n * Base UI (`aria-hidden`, hors tabulation).\n */\nconst PREMIER_CHAMP = [\n 'input:not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"file\"]):not([type=\"hidden\"]):not([type=\"submit\"]):not([type=\"button\"])',\n \"textarea\",\n]\n .map(\n (selecteur) =>\n `${selecteur}:not([disabled]):not([readonly]):not([tabindex=\"-1\"]):not([aria-hidden=\"true\"])`\n )\n .join(\", \")\n\n/** Largeur du dialogue, selon la densité du formulaire. */\nexport type FormDialogTaille = \"sm\" | \"md\" | \"lg\" | \"xl\"\n\nconst LARGEURS: Record<FormDialogTaille, string> = {\n sm: \"sm:max-w-sm\",\n md: \"sm:max-w-lg\",\n lg: \"sm:max-w-2xl\",\n xl: \"sm:max-w-4xl\",\n}\n\ntype ChampValidable = HTMLElement & {\n willValidate: boolean\n validity: ValidityState\n validationMessage: string\n labels?: NodeListOf<HTMLLabelElement> | null\n name?: string\n}\n\n/** Ce qui ne va pas dans un champ, en français (la bulle native du\n * navigateur parle sa langue, et l'erreur n'est pas reliée au champ). */\nfunction raisonInvalide({ validity, validationMessage }: ChampValidable) {\n if (validity.valueMissing) return \"obligatoire\"\n if (validity.typeMismatch || validity.patternMismatch)\n return \"format invalide\"\n if (validity.tooShort) return \"trop court\"\n if (validity.tooLong) return \"trop long\"\n if (validity.rangeUnderflow) return \"valeur trop petite\"\n if (validity.rangeOverflow) return \"valeur trop grande\"\n if (validity.stepMismatch) return \"valeur non permise\"\n if (validity.badInput) return \"valeur illisible\"\n // Message posé par l'application (setCustomValidity), déjà dans sa langue.\n return validationMessage || \"valeur invalide\"\n}\n\n/** Texte d'un libellé, sans l'astérisque de RequiredMark. */\nfunction texteDuLibelle(element: Element | null | undefined) {\n return element?.textContent?.replace(/\\s*\\*\\s*$/, \"\").trim() || undefined\n}\n\n/**\n * Entrée cachée qui porte la valeur d'un composite (Select, Combobox de Base\n * UI, SearchSelect…) : ni libellé ni focus. Le champ visible est alors celui\n * que vise le libellé de son `FormField` (`[data-slot=field]` parent).\n */\nfunction estCache(champ: ChampValidable) {\n return (\n champ.getAttribute(\"aria-hidden\") === \"true\" ||\n champ.getAttribute(\"type\") === \"hidden\" ||\n champ.tabIndex < 0\n )\n}\n\nfunction libelleDuField(champ: ChampValidable) {\n return champ\n .closest('[data-slot=\"field\"]')\n ?.querySelector<HTMLLabelElement>('[data-slot=\"field-label\"]')\n}\n\n/** Contrôle que voit l'utilisateur : le champ lui-même, ou pour une entrée\n * cachée, le contrôle que vise le libellé de son `FormField`. */\nfunction controleVisible(champ: ChampValidable): HTMLElement {\n if (!estCache(champ)) return champ\n const cible = libelleDuField(champ)?.htmlFor\n return (cible && document.getElementById(cible)) || champ\n}\n\nfunction nomDuChamp(champ: ChampValidable) {\n const visible = controleVisible(champ)\n const etiquettes = (visible as ChampValidable).labels ?? champ.labels\n const nomme =\n texteDuLibelle(etiquettes?.[0]) ||\n visible.getAttribute(\"aria-label\")?.trim() ||\n texteDuLibelle(\n document.getElementById(\n visible.getAttribute(\"aria-labelledby\")?.split(/\\s+/)[0] ?? \"\"\n )\n ) ||\n texteDuLibelle(libelleDuField(champ))\n return nomme || champ.name || \"Champ\"\n}\n\nexport interface FormDialogProps {\n titre: string\n description?: ReactNode\n /** Les champs du formulaire. */\n children: ReactNode\n /**\n * Envoi du formulaire (l'évènement a déjà son `preventDefault`), appelé\n * seulement si les contraintes des champs (`required`, `type`, `pattern`…)\n * sont tenues : sinon le dialogue liste en français les champs à corriger\n * et met le focus sur le premier. Si l'envoi renvoie une promesse, le\n * dialogue l'attend (champs et pied occupés, impossible à fermer), se ferme\n * quand elle aboutit et affiche l'erreur en tête du formulaire si elle\n * échoue. Sinon, il se ferme aussitôt. Renvoyer `false` (ou une promesse\n * résolue à `false`) le garde ouvert, sans erreur.\n */\n onEnvoyer: (event: FormEvent<HTMLFormElement>) => unknown\n /** « Enregistrer » par défaut. */\n libelleEnvoyer?: string\n /** Bouton d'envoi désactivé : formulaire incomplet, rien de modifié… */\n envoiDesactive?: boolean\n /** Envoi impossible, et pourquoi : le bouton reste focalisable et son\n * infobulle donne la raison (voir `TooltipButton`). */\n verrouEnvoi?: string\n /** « md » par défaut ; « sm » pour un seul champ, « lg » ou « xl » pour\n * un formulaire dense. */\n taille?: FormDialogTaille\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 /** Où mettre le focus à la fermeture (voir `ConfirmDialog`). */\n finalFocus?: DialogFinalFocus\n className?: string\n}\n\n/**\n * Dialogue de création ou de modification, sur le `Dialog` de shadcn : un\n * formulaire, le pied « Annuler / Enregistrer », l'état d'envoi et l'erreur\n * d'envoi en tête. Il s'ouvre le curseur dans le premier champ à remplir.\n */\nexport function FormDialog({\n titre,\n description,\n children,\n onEnvoyer,\n libelleEnvoyer = \"Enregistrer\",\n envoiDesactive = false,\n verrouEnvoi,\n taille = \"md\",\n ouvert,\n onOuvertChange,\n declencheur,\n finalFocus,\n className,\n}: FormDialogProps) {\n const action = useAction()\n const ouverture = useOuvertureDialogue(ouvert, onOuvertChange, action.enCours)\n const [invalides, setInvalides] = useState<{ nom: string; raison: string }[]>(\n []\n )\n const formulaire = useRef<HTMLFormElement>(null)\n const champs = useRef<HTMLFieldSetElement>(null)\n const boutonEnvoi = useRef<HTMLButtonElement>(null)\n // Contrôles visibles marqués `aria-invalid` par le dialogue (et non par\n // l'application), avec le champ dont ils portent la contrainte.\n const marques = useRef(new Map<HTMLElement, ChampValidable>())\n\n /** Retire la marque des champs redevenus valides (tous si `tout`). */\n const demarquer = (tout = false) => {\n for (const [visible, champ] of marques.current) {\n if (!tout && !champ.validity.valid) continue\n visible.removeAttribute(\"aria-invalid\")\n marques.current.delete(visible)\n }\n }\n\n const envoyer = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault()\n if (action.enCours || envoiDesactive || verrouEnvoi) return\n const form = event.currentTarget\n // `willValidate` écarte les boutons, les champs désactivés et les\n // `fieldset`, qui ne sont pas soumis aux contraintes.\n const fautifs = Array.from(form.elements).filter(\n (element): element is ChampValidable =>\n \"willValidate\" in element &&\n element.willValidate === true &&\n !(element as ChampValidable).validity.valid\n )\n setInvalides(\n fautifs.map((champ) => ({\n nom: nomDuChamp(champ),\n raison: raisonInvalide(champ),\n }))\n )\n demarquer(true)\n for (const champ of fautifs) {\n const visible = controleVisible(champ)\n // Un `aria-invalid` posé par l'application (FormField en erreur) reste\n // le sien : le dialogue ne le retirera pas.\n const dejaInvalide = [\"true\", \"grammar\", \"spelling\"].includes(\n visible.getAttribute(\"aria-invalid\") ?? \"\"\n )\n if (dejaInvalide) continue\n visible.setAttribute(\"aria-invalid\", \"true\")\n marques.current.set(visible, champ)\n }\n if (fautifs.length > 0) {\n controleVisible(fautifs[0]).focus()\n return\n }\n // Les champs sont désactivés pendant l'envoi : celui qui a le focus (Entrée\n // y envoie) le perdrait au profit de <body>. Il passe au bouton d'envoi,\n // occupé mais focalisable.\n if (champs.current?.contains(document.activeElement)) {\n boutonEnvoi.current?.focus()\n }\n void action.lancer(\n () => onEnvoyer(event),\n () => ouverture.definir(false)\n )\n }\n\n return (\n <Dialog\n open={ouverture.ouvert}\n onOpenChange={ouverture.changer}\n onOpenChangeComplete={(suivant) => {\n if (suivant) return\n action.reinitialiser()\n setInvalides([])\n demarquer(true)\n }}\n >\n {declencheur ? <DialogTrigger render={declencheur} /> : null}\n <DialogContent\n showCloseButton={false}\n className={cn(\n \"max-h-[calc(100dvh-2rem)] overflow-y-auto\",\n LARGEURS[taille],\n className\n )}\n initialFocus={() =>\n formulaire.current?.querySelector<HTMLElement>(PREMIER_CHAMP) ?? true\n }\n finalFocus={finalFocus}\n >\n <DialogHeader>\n <DialogTitle>{titre}</DialogTitle>\n {description ? (\n <DialogDescription>{description}</DialogDescription>\n ) : null}\n </DialogHeader>\n <form\n ref={formulaire}\n onSubmit={envoyer}\n // Un champ corrigé perd sa marque dès la saisie (ou en sortant\n // d'un composite, dont l'entrée cachée n'émet rien).\n onInput={() => demarquer()}\n onChange={() => demarquer()}\n onBlur={() => demarquer()}\n noValidate\n aria-busy={action.enCours || undefined}\n className=\"flex flex-col gap-4\"\n >\n <ErrorBanner erreur={action.erreur} />\n <ErrorBanner\n erreur={invalides.length > 0}\n titre=\"Le formulaire est incomplet.\"\n description={\n <ul className=\"list-disc pl-4\">\n {invalides.map(({ nom, raison }, index) => (\n <li key={index}>\n {nom}&nbsp;: {raison}\n </li>\n ))}\n </ul>\n }\n />\n {/* Champs figés pendant l'envoi : une modification faite pendant\n l'attente serait perdue sans le savoir. */}\n <fieldset ref={champs} disabled={action.enCours} className=\"contents\">\n {children}\n </fieldset>\n <DialogFooter>\n <Button\n variant=\"outline\"\n disabled={action.enCours}\n focusableWhenDisabled\n onClick={() => ouverture.changer(false)}\n >\n Annuler\n </Button>\n <TooltipButton\n ref={boutonEnvoi}\n type=\"submit\"\n disabled={action.enCours || envoiDesactive}\n focusableWhenDisabled\n verrou={verrouEnvoi}\n aria-busy={action.enCours || undefined}\n >\n {action.enCours ? <SpinnerBouton /> : null}\n {libelleEnvoyer}\n </TooltipButton>\n </DialogFooter>\n </form>\n {/* La croix de shadcn, occupée comme « Annuler » pendant l'envoi. */}\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n data-slot=\"dialog-close\"\n className=\"absolute top-2 right-2\"\n disabled={action.enCours}\n focusableWhenDisabled\n onClick={() => ouverture.changer(false)}\n >\n <XIcon />\n <span className=\"sr-only\">Fermer</span>\n </Button>\n </DialogContent>\n </Dialog>\n )\n}\n"],"mappings":";;;;;;;;;;AAmCA,IAAMA,IAAgB,CACpB,kJACA,UACF,CAAC,CACE,KACE,MACC,GAAGC,EAAU,gFACjB,CAAC,CACA,KAAK,IAAI,GAKNC,IAA6C;CACjD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAYA,SAASC,EAAe,EAAE,aAAU,wBAAqC;CAWvE,OAVIC,EAAS,eAAqB,gBAC9BA,EAAS,gBAAgBA,EAAS,kBAC7B,oBACLA,EAAS,WAAiB,eAC1BA,EAAS,UAAgB,cACzBA,EAAS,iBAAuB,uBAChCA,EAAS,gBAAsB,uBAC/BA,EAAS,eAAqB,uBAC9BA,EAAS,WAAiB,qBAEvBC,KAAqB;AAC9B;AAGA,SAASC,EAAe,GAAqC;CAC3D,OAAOC,GAAS,aAAa,QAAQ,aAAa,EAAE,CAAC,CAAC,KAAK,KAAK,KAAA;AAClE;AAOA,SAASC,EAAS,GAAuB;CACvC,OACEC,EAAM,aAAa,aAAa,MAAM,UACtCA,EAAM,aAAa,MAAM,MAAM,YAC/BA,EAAM,WAAW;AAErB;AAEA,SAASC,EAAe,GAAuB;CAC7C,OAAOD,EACJ,QAAQ,uBAAqB,CAAC,EAC7B,cAAgC,6BAA2B;AACjE;AAIA,SAASE,EAAgB,GAAoC;CAC3D,IAAI,CAACH,EAASC,CAAK,GAAG,OAAOA;CAC7B,IAAMG,IAAQF,EAAeD,CAAK,CAAC,EAAE;CACrC,OAAQG,KAAS,SAAS,eAAeA,CAAK,KAAMH;AACtD;AAEA,SAASI,EAAW,GAAuB;CACzC,IAAMC,IAAUH,EAAgBF,CAAK;CAWrC,OAREH,GAFkBQ,EAA2B,UAAUL,EAAM,OAAA,GAEjC,EAAE,KAC9BK,EAAQ,aAAa,YAAY,CAAC,EAAE,KAAK,KACzCR,EACE,SAAS,eACPQ,EAAQ,aAAa,iBAAiB,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,EAC9D,CACF,KACAR,EAAeI,EAAeD,CAAK,CAAC,KACtBA,EAAM,QAAQ;AAChC;AA2CA,SAAgBM,EAAW,EACzB,UACA,gBACA,aACA,cACA,oBAAiB,eACjB,oBAAiB,IACjB,gBACA,YAAS,MACT,WACA,mBACA,gBACA,eACA,gBACkB;CAClB,IAAMC,IAASC,EAAU,GACnBC,IAAYC,EAAqBC,GAAQC,GAAgBL,EAAO,OAAO,GACvE,CAACM,GAAWC,KAAgBC,EAChC,CAAC,CACH,GACMC,IAAaC,EAAwB,IAAI,GACzCC,IAASD,EAA4B,IAAI,GACzCE,IAAcF,EAA0B,IAAI,GAG5CG,IAAUH,kBAAO,IAAI,IAAiC,CAAC,GAGvDI,KAAa,IAAO,OAAU;EAClC,KAAK,IAAM,CAAChB,GAASL,MAAUoB,EAAQ,SACrC,CAAKE,KAAStB,EAAM,SAAS,WAC7BK,EAAQ,gBAAgB,cAAc,GACtCe,EAAQ,QAAQ,OAAOf,CAAO;CAElC;CAgDA,OACE,kBAACkB,GAAD;EACE,MAAMd,EAAU;EAChB,cAAcA,EAAU;EACxB,uBAAuB,MAAY;GACjC,AAAIe,MACJjB,EAAO,cAAc,GACrBO,EAAa,CAAC,CAAC,GACfO,EAAU,EAAI;EAChB;EARF,UAAA,CAUGI,IAAc,kBAACC,GAAD,EAAe,QAAQD,EAAc,CAAA,IAAI,MACxD,kBAACE,GAAD;GACE,iBAAiB;GACjB,WAAWC,EACT,6CACAnC,EAASoC,IACTC,CACF;GACA,oBACEd,EAAW,SAAS,cAA2BzB,CAAa,KAAK;GAEvD;GAVd,UAAA;IAYE,kBAACwC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD,EAAA,UAAcC,EAAmB,CAAA,GAChCC,IACC,kBAACC,GAAD,EAAA,UAAoBD,EAA+B,CAAA,IACjD,IACQ,EAAA,CAAA;IACd,kBAAC,QAAD;KACE,KAAKlB;KACL,WA9ES,MAAsC;MAErD,IADAoB,EAAM,eAAe,GACjB7B,EAAO,WAAW8B,KAAkBC,GAAa;MACrD,IAAMC,IAAOH,EAAM,eAGbI,IAAU,MAAM,KAAKD,EAAK,QAAQ,CAAC,CAAC,QACvC,MACC,kBAAkBzC,KAClBA,EAAQ,iBAAiB,MACzB,CAAEA,EAA2B,SAAS,KAC1C;MAOA,AANAgB,EACE0B,EAAQ,KAAK,OAAW;OACtB,KAAKpC,EAAWJ,CAAK;OACrB,QAAQN,EAAeM,CAAK;MAC9B,EAAE,CACJ,GACAqB,EAAU,EAAI;MACd,KAAK,IAAMrB,KAASwC,GAAS;OAC3B,IAAMnC,IAAUH,EAAgBF,CAAK;OAMrC,AAHqB;QAAC;QAAQ;QAAW;OAAU,CAAC,CAAC,SACnDK,EAAQ,aAAa,cAAc,KAAK,EAEtC,MACJA,EAAQ,aAAa,gBAAgB,MAAM,GAC3Ce,EAAQ,QAAQ,IAAIf,GAASL,CAAK;MACpC;MACA,AAAIwC,EAAQ,SAAS,IACnBtC,EAAgBsC,EAAQ,EAAE,CAAC,CAAC,MAAM,KAMhCtB,EAAO,SAAS,SAAS,SAAS,aAAa,KACjDC,EAAY,SAAS,MAAM,GAE7BZ,EAAY,aACJkC,EAAUL,CAAK,SACf3B,EAAU,QAAQ,EAAK,CAC/B;KACF;KAqCQ,eAAeY,EAAU;KACzB,gBAAgBA,EAAU;KAC1B,cAAcA,EAAU;KACxB,YAAA;KACA,aAAWd,EAAO,WAAW,KAAA;KAC7B,WAAU;KAVZ,UAAA;MAYE,kBAACmC,GAAD,EAAa,QAAQnC,EAAO,OAAS,CAAA;MACrC,kBAACmC,GAAD;OACE,QAAQ7B,EAAU,SAAS;OAC3B,OAAM;OACN,aACE,kBAAC,MAAD;QAAI,WAAU;QACX,UAAAA,EAAU,KAAK,EAAE,QAAK,aAAU,MAC/B,kBAAC,MAAD,EAAA,UAAA;SACG8B;SAAI;SAASC;QACZ,EAAA,GAFKC,CAEL,CACL;OACC,CAAA;MAEP,CAAA;MAGD,kBAAC,YAAD;OAAU,KAAK3B;OAAQ,UAAUX,EAAO;OAAS,WAAU;OACxD;MACO,CAAA;MACV,kBAACuC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;OACE,SAAQ;OACR,UAAUxC,EAAO;OACjB,uBAAA;OACA,eAAeE,EAAU,QAAQ,EAAK;OACvC,UAAA;MAEO,CAAA,GACR,kBAACuC,GAAD;OACE,KAAK7B;OACL,MAAK;OACL,UAAUZ,EAAO,WAAW8B;OAC5B,uBAAA;OACA,QAAQC;OACR,aAAW/B,EAAO,WAAW,KAAA;OAN/B,UAAA,CAQGA,EAAO,UAAU,kBAAC0C,GAAD,CAAgB,CAAA,IAAI,MACrCC,CACY;MACH,CAAA,CAAA,EAAA,CAAA;KACV;;IAEN,kBAACH,GAAD;KACE,SAAQ;KACR,MAAK;KACL,aAAU;KACV,WAAU;KACV,UAAUxC,EAAO;KACjB,uBAAA;KACA,eAAeE,EAAU,QAAQ,EAAK;KAPxC,UAAA,CASE,kBAAC0C,GAAD,CAAQ,CAAA,GACR,kBAAC,QAAD;MAAM,WAAU;MAAU,UAAA;KAAY,CAAA,CAChC;;GACK;EACT,CAAA,CAAA;;AAEZ"}
@@ -0,0 +1,66 @@
1
+ /** Ce que `FormField` sait de son champ, pour le contrôle qu'il contient. */
2
+ export interface FormFieldContexte {
3
+ /** Identifiant du contrôle (cible du libellé). */
4
+ id: string;
5
+ /** Identifiant du libellé : un groupe (cases, boutons joints), qu'un
6
+ * `<label for>` ne nomme pas, le cite dans `aria-labelledby`. */
7
+ libelleId: string;
8
+ /** Identifiant de l'aide, si le champ en a une. */
9
+ descriptionId?: string;
10
+ /** Identifiant du message d'erreur, s'il est affiché. */
11
+ erreurId?: string;
12
+ /** Valeur d'`aria-describedby` : aide et erreur. */
13
+ describedBy?: string;
14
+ obligatoire: boolean;
15
+ invalide: boolean;
16
+ }
17
+ export declare const FormFieldContext: import('react').Context<FormFieldContexte | null>;
18
+ /**
19
+ * Le champ (`FormField`) qui entoure le composant, ou `null` hors d'un champ.
20
+ * Un contrôle composite y lit de quoi poser `id`, `aria-describedby`,
21
+ * `aria-invalid` et `required` sur son vrai élément de saisie, comme le
22
+ * `useFormField()` du Form de shadcn.
23
+ */
24
+ export declare function useFormField(): FormFieldContexte | null;
25
+ /** Attributs explicites d'un groupe, prioritaires sur ceux du champ. */
26
+ interface AttributsDeGroupe {
27
+ required?: boolean;
28
+ "aria-labelledby"?: string;
29
+ "aria-describedby"?: string;
30
+ "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling";
31
+ }
32
+ /**
33
+ * Attributs d'un groupe de contrôles (cases, boutons joints) : `role="group"`
34
+ * n'admet pas `aria-required`, et un `<label for>` ne le nomme pas. Le
35
+ * groupe cite donc le libellé du champ (`aria-labelledby`), et un groupe
36
+ * obligatoire cite aussi `idMention`, un élément masqué « obligatoire » que
37
+ * le composant rend : son nom devient « Groupes obligatoire ». Sans libellé à
38
+ * citer (`aria-label`), la mention passe dans la description.
39
+ */
40
+ export declare function attributsDuGroupe(champ: FormFieldContexte | null, props: AttributsDeGroupe, idMention: string): {
41
+ obligatoire: boolean;
42
+ attributs: {
43
+ "aria-labelledby": string | undefined;
44
+ "aria-describedby": string | undefined;
45
+ "aria-invalid": boolean | "true" | "false" | "grammar" | "spelling" | undefined;
46
+ };
47
+ };
48
+ /** Attributs explicites d'un contrôle, prioritaires sur ceux du champ. */
49
+ interface AttributsExplicites {
50
+ id?: string;
51
+ "aria-describedby"?: string;
52
+ "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling";
53
+ required?: boolean;
54
+ }
55
+ /**
56
+ * Attributs du vrai élément de saisie d'un composite : ceux qu'il reçoit,
57
+ * sinon ceux du champ. Le `aria-required` posé par `FormField` sur le
58
+ * composite est ignoré : son élément de saisie porte un vrai `required`.
59
+ */
60
+ export declare function attributsDuChamp(champ: FormFieldContexte | null, props: AttributsExplicites): {
61
+ id: string | undefined;
62
+ "aria-describedby": string | undefined;
63
+ "aria-invalid": boolean | "true" | "false" | "grammar" | "spelling" | undefined;
64
+ required: boolean | undefined;
65
+ };
66
+ export {};
@@ -0,0 +1,28 @@
1
+ import { createContext as e, useContext as t } from "react";
2
+ // src/components/etic/form-field-context.ts
3
+ var n = e(null);
4
+ function r() {
5
+ return t(n);
6
+ }
7
+ function i(e, t, n) {
8
+ let r = t.required ?? e?.obligatoire ?? !1, i = t["aria-labelledby"] ?? e?.libelleId, a = r ? n : void 0;
9
+ return {
10
+ obligatoire: r,
11
+ attributs: {
12
+ "aria-labelledby": i ? [i, a].filter(Boolean).join(" ") : void 0,
13
+ "aria-describedby": [t["aria-describedby"] ?? e?.describedBy, i ? null : a].filter(Boolean).join(" ") || void 0,
14
+ "aria-invalid": t["aria-invalid"] ?? (e?.invalide || void 0)
15
+ }
16
+ };
17
+ }
18
+ function a(e, t) {
19
+ return {
20
+ id: t.id ?? e?.id,
21
+ "aria-describedby": t["aria-describedby"] ?? e?.describedBy,
22
+ "aria-invalid": t["aria-invalid"] ?? (e?.invalide || void 0),
23
+ required: t.required ?? (e?.obligatoire || void 0)
24
+ };
25
+ }
26
+ export { n as FormFieldContext, a as attributsDuChamp, i as attributsDuGroupe, r as useFormField };
27
+
28
+ //# sourceMappingURL=form-field-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-field-context.js","names":["FormFieldContext","createContext","useFormField","useContext","attributsDuGroupe","obligatoire","props","champ","nom","mention","idMention","attributsDuChamp"],"sources":["../../../src/components/etic/form-field-context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\"\n\n/** Ce que `FormField` sait de son champ, pour le contrôle qu'il contient. */\nexport interface FormFieldContexte {\n /** Identifiant du contrôle (cible du libellé). */\n id: string\n /** Identifiant du libellé : un groupe (cases, boutons joints), qu'un\n * `<label for>` ne nomme pas, le cite dans `aria-labelledby`. */\n libelleId: string\n /** Identifiant de l'aide, si le champ en a une. */\n descriptionId?: string\n /** Identifiant du message d'erreur, s'il est affiché. */\n erreurId?: string\n /** Valeur d'`aria-describedby` : aide et erreur. */\n describedBy?: string\n obligatoire: boolean\n invalide: boolean\n}\n\nexport const FormFieldContext = createContext<FormFieldContexte | null>(null)\n\n/**\n * Le champ (`FormField`) qui entoure le composant, ou `null` hors d'un champ.\n * Un contrôle composite y lit de quoi poser `id`, `aria-describedby`,\n * `aria-invalid` et `required` sur son vrai élément de saisie, comme le\n * `useFormField()` du Form de shadcn.\n */\nexport function useFormField(): FormFieldContexte | null {\n return useContext(FormFieldContext)\n}\n\n/** Attributs explicites d'un groupe, prioritaires sur ceux du champ. */\ninterface AttributsDeGroupe {\n required?: boolean\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean | \"true\" | \"false\" | \"grammar\" | \"spelling\"\n}\n\n/**\n * Attributs d'un groupe de contrôles (cases, boutons joints) : `role=\"group\"`\n * n'admet pas `aria-required`, et un `<label for>` ne le nomme pas. Le\n * groupe cite donc le libellé du champ (`aria-labelledby`), et un groupe\n * obligatoire cite aussi `idMention`, un élément masqué « obligatoire » que\n * le composant rend : son nom devient « Groupes obligatoire ». Sans libellé à\n * citer (`aria-label`), la mention passe dans la description.\n */\nexport function attributsDuGroupe(\n champ: FormFieldContexte | null,\n props: AttributsDeGroupe,\n idMention: string\n) {\n const obligatoire = props.required ?? champ?.obligatoire ?? false\n const nom = props[\"aria-labelledby\"] ?? champ?.libelleId\n const mention = obligatoire ? idMention : undefined\n return {\n obligatoire,\n attributs: {\n \"aria-labelledby\": nom\n ? [nom, mention].filter(Boolean).join(\" \")\n : undefined,\n \"aria-describedby\":\n [props[\"aria-describedby\"] ?? champ?.describedBy, nom ? null : mention]\n .filter(Boolean)\n .join(\" \") || undefined,\n \"aria-invalid\": props[\"aria-invalid\"] ?? (champ?.invalide || undefined),\n },\n }\n}\n\n/** Attributs explicites d'un contrôle, prioritaires sur ceux du champ. */\ninterface AttributsExplicites {\n id?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean | \"true\" | \"false\" | \"grammar\" | \"spelling\"\n required?: boolean\n}\n\n/**\n * Attributs du vrai élément de saisie d'un composite : ceux qu'il reçoit,\n * sinon ceux du champ. Le `aria-required` posé par `FormField` sur le\n * composite est ignoré : son élément de saisie porte un vrai `required`.\n */\nexport function attributsDuChamp(\n champ: FormFieldContexte | null,\n props: AttributsExplicites\n) {\n return {\n id: props.id ?? champ?.id,\n \"aria-describedby\": props[\"aria-describedby\"] ?? champ?.describedBy,\n \"aria-invalid\": props[\"aria-invalid\"] ?? (champ?.invalide || undefined),\n required: props.required ?? (champ?.obligatoire || undefined),\n }\n}\n"],"mappings":";;AAmBA,IAAaA,IAAmBC,EAAwC,IAAI;AAQ5E,SAAgBC,IAAyC;CACvD,OAAOC,EAAWH,CAAgB;AACpC;AAkBA,SAAgBI,EACd,GACA,GACA,GACA;CACA,IAAMC,IAAcC,EAAM,YAAYC,GAAO,eAAe,IACtDC,IAAMF,EAAM,sBAAsBC,GAAO,WACzCE,IAAUJ,IAAcK,IAAY,KAAA;CAC1C,OAAO;EACL;EACA,WAAW;GACT,mBAAmBF,IACf,CAACA,GAAKC,CAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,IACvC,KAAA;GACJ,oBACE,CAACH,EAAM,uBAAuBC,GAAO,aAAaC,IAAM,OAAOC,CAAO,CAAC,CACpE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;GAClB,gBAAgBH,EAAM,oBAAoBC,GAAO,YAAY,KAAA;EAC/D;CACF;AACF;AAeA,SAAgBI,EACd,GACA,GACA;CACA,OAAO;EACL,IAAIL,EAAM,MAAMC,GAAO;EACvB,oBAAoBD,EAAM,uBAAuBC,GAAO;EACxD,gBAAgBD,EAAM,oBAAoBC,GAAO,YAAY,KAAA;EAC7D,UAAUD,EAAM,aAAaC,GAAO,eAAe,KAAA;CACrD;AACF"}
@@ -0,0 +1,53 @@
1
+ import { ComponentProps, ReactElement, ReactNode } from 'react';
2
+ import { Field, FieldSet } from '../ui/field';
3
+ /** Astérisque d'un champ obligatoire, masqué aux lecteurs d'écran : ils
4
+ * annoncent le `required` (ou `aria-required`) du contrôle, que `FormField`
5
+ * pose quand il est `obligatoire`. */
6
+ export declare function RequiredMark({ className, ...props }: ComponentProps<"span">): import("react").JSX.Element;
7
+ /** Attributs posés sur l'enfant direct par `FormField`. */
8
+ export interface FormFieldControleProps {
9
+ id?: string;
10
+ "aria-describedby"?: string;
11
+ "aria-invalid"?: boolean;
12
+ required?: boolean;
13
+ "aria-required"?: boolean;
14
+ }
15
+ export interface FormFieldProps extends Omit<ComponentProps<typeof Field>, "children"> {
16
+ libelle: ReactNode;
17
+ /** Affiche l'astérisque et rend le contrôle requis (voir `FormField`). */
18
+ obligatoire?: boolean;
19
+ /** Ligne d'aide sous le contrôle. */
20
+ description?: ReactNode;
21
+ /** Message d'erreur, ou plusieurs (un par ligne). Rend le champ invalide. */
22
+ erreur?: ReactNode | string[];
23
+ /** Identifiant du contrôle ; généré s'il manque. */
24
+ id?: string;
25
+ /** Le contrôle (Input, Select…, ou tout composant qui transmet `id` et les
26
+ * attributs `aria-*` à son élément de saisie). */
27
+ children: ReactElement<FormFieldControleProps>;
28
+ }
29
+ /**
30
+ * Un champ de formulaire complet : le `Field` de shadcn, avec libellé (et
31
+ * astérisque si obligatoire), contrôle, aide et erreur, reliés par `htmlFor`,
32
+ * `aria-describedby` et `aria-invalid` posés sur le contrôle.
33
+ *
34
+ * Un champ obligatoire rend le contrôle requis. Règle : un champ natif ou une
35
+ * primitive shadcn de saisie (Input, Textarea, NativeSelect, champ
36
+ * d'InputGroup) reçoit `required` ; tout autre enfant reçoit `aria-required`.
37
+ * Un composite (DatePicker, PhoneInput, SearchSelect, ou un composant de
38
+ * l'application) lit `useFormField()` et pose lui-même un vrai `required` sur
39
+ * son élément de saisie, en ignorant ce `aria-required` ; un groupe
40
+ * (CheckboxList, SegmentedControl) l'ignore aussi et se dit « obligatoire »
41
+ * dans son nom. Autour d'un `InputGroup`, les attributs vont à son champ.
42
+ */
43
+ export declare function FormField({ libelle, obligatoire, description, erreur, id, children, ...props }: FormFieldProps): import("react").JSX.Element;
44
+ export interface FormSectionProps extends Omit<ComponentProps<typeof FieldSet>, "title"> {
45
+ titre?: ReactNode;
46
+ description?: ReactNode;
47
+ }
48
+ /**
49
+ * Regroupe des champs sous un titre : `FieldSet` et `FieldLegend` de shadcn
50
+ * (un `<fieldset>`, que les lecteurs d'écran annoncent avec son titre), les
51
+ * champs espacés par `FieldGroup`.
52
+ */
53
+ export declare function FormSection({ titre, description, children, ...props }: FormSectionProps): import("react").JSX.Element;
@@ -0,0 +1,105 @@
1
+ import { Field as e, FieldDescription as t, FieldError as n, FieldGroup as r, FieldLabel as i, FieldLegend as a, FieldSet as o } from "../ui/field.js";
2
+ import { Input as s } from "../ui/input.js";
3
+ import { InputGroup as c, InputGroupInput as l, InputGroupTextarea as u } from "../ui/input-group.js";
4
+ import { NativeSelect as d } from "../ui/native-select.js";
5
+ import { Textarea as f } from "../ui/textarea.js";
6
+ import { FormFieldContext as p } from "./form-field-context.js";
7
+ import { cn as m } from "cn";
8
+ import { Children as h, cloneElement as g, isValidElement as _, useId as v } from "react";
9
+ import { jsx as y, jsxs as b } from "react/jsx-runtime";
10
+ // src/components/etic/form-field.tsx
11
+ function x({ className: e, ...t }) {
12
+ return /* @__PURE__ */ y("span", {
13
+ "data-slot": "required-mark",
14
+ "aria-hidden": "true",
15
+ title: "Champ obligatoire",
16
+ className: m("text-destructive", e),
17
+ ...t,
18
+ children: "*"
19
+ });
20
+ }
21
+ var S = /* @__PURE__ */ new Set([
22
+ "input",
23
+ "textarea",
24
+ "select",
25
+ s,
26
+ f,
27
+ d,
28
+ l,
29
+ u
30
+ ]), C = /* @__PURE__ */ new Set([
31
+ "input",
32
+ "textarea",
33
+ l,
34
+ u
35
+ ]);
36
+ function w(e) {
37
+ let { children: t } = e.props;
38
+ return h.toArray(t).find((e) => _(e) && C.has(e.type));
39
+ }
40
+ function T(e, t, n) {
41
+ if (!t) return g(e, n);
42
+ let r = !1, { children: i } = e.props;
43
+ return g(e, {}, h.map(i, (e) => r || !_(e) || !C.has(e.type) ? e : (r = !0, g(e, n))));
44
+ }
45
+ function E({ libelle: r, obligatoire: a = !1, description: o, erreur: s, id: l, children: u, ...d }) {
46
+ let f = v(), m = u.type === c ? w(u) : void 0, h = m ?? u, g = l ?? h.props.id ?? f, _ = `${g}-libelle`, C = `${g}-description`, E = `${g}-erreur`, D = Array.isArray(s) ? s.filter(Boolean).map((e) => ({ message: e })) : void 0, O = D ? D.length > 0 : !!s, k = [
47
+ h.props["aria-describedby"],
48
+ o ? C : null,
49
+ O ? E : null
50
+ ].filter(Boolean).join(" ") || void 0, A = {
51
+ id: g,
52
+ libelleId: _,
53
+ descriptionId: o ? C : void 0,
54
+ erreurId: O ? E : void 0,
55
+ describedBy: k,
56
+ obligatoire: a,
57
+ invalide: O
58
+ };
59
+ return /* @__PURE__ */ b(e, {
60
+ "data-invalid": O || void 0,
61
+ ...d,
62
+ children: [
63
+ /* @__PURE__ */ b(i, {
64
+ id: _,
65
+ htmlFor: g,
66
+ children: [r, a ? /* @__PURE__ */ y(x, {}) : null]
67
+ }),
68
+ /* @__PURE__ */ y(p.Provider, {
69
+ value: A,
70
+ children: T(u, !!m, {
71
+ id: g,
72
+ "aria-describedby": k,
73
+ "aria-invalid": O || h.props["aria-invalid"] || void 0,
74
+ ...a ? S.has(h.type) ? { required: !0 } : { "aria-required": !0 } : {}
75
+ })
76
+ }),
77
+ o ? /* @__PURE__ */ y(t, {
78
+ id: C,
79
+ children: o
80
+ }) : null,
81
+ O ? D ? /* @__PURE__ */ y(n, {
82
+ id: E,
83
+ role: void 0,
84
+ errors: D
85
+ }) : /* @__PURE__ */ y(n, {
86
+ id: E,
87
+ role: void 0,
88
+ children: s
89
+ }) : null
90
+ ]
91
+ });
92
+ }
93
+ function D({ titre: e, description: n, children: i, ...s }) {
94
+ return /* @__PURE__ */ b(o, {
95
+ ...s,
96
+ children: [
97
+ e ? /* @__PURE__ */ y(a, { children: e }) : null,
98
+ n ? /* @__PURE__ */ y(t, { children: n }) : null,
99
+ /* @__PURE__ */ y(r, { children: i })
100
+ ]
101
+ });
102
+ }
103
+ export { E as FormField, D as FormSection, x as RequiredMark };
104
+
105
+ //# sourceMappingURL=form-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-field.js","names":["RequiredMark","props","cn","className","CHAMPS_NATIFS","Input","Textarea","NativeSelect","InputGroupInput","InputGroupTextarea","CHAMPS_DE_GROUPE","champDuGroupe","groupe","Children","children","isValidElement","enfant","relier","dansGroupe","cloneElement","controle","attributs","fait","FormField","genere","useId","champGroupe","InputGroup","cible","idControle","id","idLibelle","idDescription","idErreur","erreurs","erreur","invalide","decrit","description","contexte","Field","FieldLabel","libelle","obligatoire","FormFieldContext","FieldDescription","FieldError","FormSection","FieldSet","titre","FieldLegend","FieldGroup"],"sources":["../../../src/components/etic/form-field.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n isValidElement,\n useId,\n type ComponentProps,\n type ReactElement,\n type ReactNode,\n} from \"react\"\nimport { cn } from \"cn\"\n\nimport {\n Field,\n FieldDescription,\n FieldError,\n FieldGroup,\n FieldLabel,\n FieldLegend,\n FieldSet,\n} from \"@etic-ui/components/ui/field\"\nimport { Input } from \"@etic-ui/components/ui/input\"\nimport {\n InputGroup,\n InputGroupInput,\n InputGroupTextarea,\n} from \"@etic-ui/components/ui/input-group\"\nimport { NativeSelect } from \"@etic-ui/components/ui/native-select\"\nimport { Textarea } from \"@etic-ui/components/ui/textarea\"\nimport {\n FormFieldContext,\n type FormFieldContexte,\n} from \"@etic-ui/components/etic/form-field-context\"\n\n/** Astérisque d'un champ obligatoire, masqué aux lecteurs d'écran : ils\n * annoncent le `required` (ou `aria-required`) du contrôle, que `FormField`\n * pose quand il est `obligatoire`. */\nexport function RequiredMark({ className, ...props }: ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"required-mark\"\n aria-hidden=\"true\"\n title=\"Champ obligatoire\"\n className={cn(\"text-destructive\", className)}\n {...props}\n >\n *\n </span>\n )\n}\n\n/** Attributs posés sur l'enfant direct par `FormField`. */\nexport interface FormFieldControleProps {\n id?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n required?: boolean\n \"aria-required\"?: boolean\n}\n\n/** Champs de saisie natifs, ou primitives shadcn qui en rendent un : seuls à\n * recevoir un vrai `required` de `FormField`. */\nconst CHAMPS_NATIFS = new Set<unknown>([\n \"input\",\n \"textarea\",\n \"select\",\n Input,\n Textarea,\n NativeSelect,\n InputGroupInput,\n InputGroupTextarea,\n])\n\n/** Champ de saisie d'un `InputGroup` (suffixe, bouton…) : c'est lui, et non\n * l'enveloppe, que vise le libellé. */\nconst CHAMPS_DE_GROUPE = new Set<unknown>([\n \"input\",\n \"textarea\",\n InputGroupInput,\n InputGroupTextarea,\n])\n\ntype Controle = ReactElement<FormFieldControleProps>\n\nfunction champDuGroupe(groupe: ReactElement): Controle | undefined {\n const { children } = groupe.props as { children?: ReactNode }\n return Children.toArray(children).find(\n (enfant): enfant is Controle =>\n isValidElement(enfant) && CHAMPS_DE_GROUPE.has(enfant.type)\n )\n}\n\n/** Pose `attributs` sur le contrôle ; dans un `InputGroup`, sur son champ. */\nfunction relier(\n controle: Controle,\n dansGroupe: boolean,\n attributs: FormFieldControleProps\n) {\n if (!dansGroupe) return cloneElement(controle, attributs)\n let fait = false\n const { children } = controle.props as { children?: ReactNode }\n return cloneElement(\n controle as ReactElement<{ children?: ReactNode }>,\n {},\n Children.map(children, (enfant) => {\n if (fait || !isValidElement(enfant) || !CHAMPS_DE_GROUPE.has(enfant.type))\n return enfant\n fait = true\n return cloneElement(enfant as Controle, attributs)\n })\n )\n}\n\nexport interface FormFieldProps extends Omit<\n ComponentProps<typeof Field>,\n \"children\"\n> {\n libelle: ReactNode\n /** Affiche l'astérisque et rend le contrôle requis (voir `FormField`). */\n obligatoire?: boolean\n /** Ligne d'aide sous le contrôle. */\n description?: ReactNode\n /** Message d'erreur, ou plusieurs (un par ligne). Rend le champ invalide. */\n erreur?: ReactNode | string[]\n /** Identifiant du contrôle ; généré s'il manque. */\n id?: string\n /** Le contrôle (Input, Select…, ou tout composant qui transmet `id` et les\n * attributs `aria-*` à son élément de saisie). */\n children: ReactElement<FormFieldControleProps>\n}\n\n/**\n * Un champ de formulaire complet : le `Field` de shadcn, avec libellé (et\n * astérisque si obligatoire), contrôle, aide et erreur, reliés par `htmlFor`,\n * `aria-describedby` et `aria-invalid` posés sur le contrôle.\n *\n * Un champ obligatoire rend le contrôle requis. Règle : un champ natif ou une\n * primitive shadcn de saisie (Input, Textarea, NativeSelect, champ\n * d'InputGroup) reçoit `required` ; tout autre enfant reçoit `aria-required`.\n * Un composite (DatePicker, PhoneInput, SearchSelect, ou un composant de\n * l'application) lit `useFormField()` et pose lui-même un vrai `required` sur\n * son élément de saisie, en ignorant ce `aria-required` ; un groupe\n * (CheckboxList, SegmentedControl) l'ignore aussi et se dit « obligatoire »\n * dans son nom. Autour d'un `InputGroup`, les attributs vont à son champ.\n */\nexport function FormField({\n libelle,\n obligatoire = false,\n description,\n erreur,\n id,\n children,\n ...props\n}: FormFieldProps) {\n const genere = useId()\n // Autour d'un InputGroup, le libellé vise son champ de saisie.\n const champGroupe =\n children.type === InputGroup ? champDuGroupe(children) : undefined\n const cible = champGroupe ?? children\n const idControle = id ?? cible.props.id ?? genere\n const idLibelle = `${idControle}-libelle`\n const idDescription = `${idControle}-description`\n const idErreur = `${idControle}-erreur`\n const erreurs = Array.isArray(erreur)\n ? erreur.filter(Boolean).map((message) => ({ message }))\n : undefined\n const invalide = erreurs ? erreurs.length > 0 : Boolean(erreur)\n\n const decrit =\n [\n cible.props[\"aria-describedby\"],\n description ? idDescription : null,\n invalide ? idErreur : null,\n ]\n .filter(Boolean)\n .join(\" \") || undefined\n\n const contexte: FormFieldContexte = {\n id: idControle,\n libelleId: idLibelle,\n descriptionId: description ? idDescription : undefined,\n erreurId: invalide ? idErreur : undefined,\n describedBy: decrit,\n obligatoire,\n invalide,\n }\n\n return (\n <Field data-invalid={invalide || undefined} {...props}>\n <FieldLabel id={idLibelle} htmlFor={idControle}>\n {libelle}\n {obligatoire ? <RequiredMark /> : null}\n </FieldLabel>\n <FormFieldContext.Provider value={contexte}>\n {relier(children, Boolean(champGroupe), {\n id: idControle,\n \"aria-describedby\": decrit,\n \"aria-invalid\": invalide || cible.props[\"aria-invalid\"] || undefined,\n ...(obligatoire\n ? CHAMPS_NATIFS.has(cible.type)\n ? { required: true }\n : { \"aria-required\": true }\n : {}),\n })}\n </FormFieldContext.Provider>\n {description ? (\n <FieldDescription id={idDescription}>{description}</FieldDescription>\n ) : null}\n {/* Pas de `role=\"alert\"` (shadcn) : cinq champs fautifs feraient cinq\n alertes, et une erreur affichée pendant la frappe la couperait.\n L'erreur est dans la description du contrôle. */}\n {invalide ? (\n erreurs ? (\n <FieldError id={idErreur} role={undefined} errors={erreurs} />\n ) : (\n <FieldError id={idErreur} role={undefined}>\n {erreur as ReactNode}\n </FieldError>\n )\n ) : null}\n </Field>\n )\n}\n\nexport interface FormSectionProps extends Omit<\n ComponentProps<typeof FieldSet>,\n \"title\"\n> {\n titre?: ReactNode\n description?: ReactNode\n}\n\n/**\n * Regroupe des champs sous un titre : `FieldSet` et `FieldLegend` de shadcn\n * (un `<fieldset>`, que les lecteurs d'écran annoncent avec son titre), les\n * champs espacés par `FieldGroup`.\n */\nexport function FormSection({\n titre,\n description,\n children,\n ...props\n}: FormSectionProps) {\n return (\n <FieldSet {...props}>\n {titre ? <FieldLegend>{titre}</FieldLegend> : null}\n {description ? <FieldDescription>{description}</FieldDescription> : null}\n <FieldGroup>{children}</FieldGroup>\n </FieldSet>\n )\n}\n"],"mappings":"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"}
@@ -0,0 +1,33 @@
1
+ import { ComponentProps } from 'react';
2
+ import { LucideIcon } from 'lucide-react';
3
+ import { Toggle } from '../ui/toggle';
4
+ export interface IconToggleProps extends Omit<ComponentProps<typeof Toggle>, "children" | "pressed" | "defaultPressed" | "onPressedChange" | "disabled"> {
5
+ /** État actuel : le marqueur est-il posé ? */
6
+ actif: boolean;
7
+ /** Appelé avec l'état voulu. */
8
+ onActifChange: (actif: boolean) => void;
9
+ icone: LucideIcon;
10
+ /** Nom accessible, constant (l'état est porté par `aria-pressed`) :
11
+ * « Groupe critique ». */
12
+ libelle: string;
13
+ /** Infobulle selon l'état : ce que ferait un clic (« Marquer ce groupe
14
+ * comme critique », « Retirer le marqueur critique »). Le libellé par
15
+ * défaut. */
16
+ infobulles?: {
17
+ activer: string;
18
+ desactiver: string;
19
+ };
20
+ /** Bascule en cours d'enregistrement : le bouton est occupé
21
+ * (`aria-busy`) et ne réagit plus, mais garde le focus. */
22
+ enCours?: boolean;
23
+ /** Bascule impossible : le bouton reste focalisable, et son infobulle dit
24
+ * pourquoi. */
25
+ verrou?: string;
26
+ }
27
+ /**
28
+ * Bouton à icône qui pose ou retire un marqueur sensible (élément critique,
29
+ * protégé…), sur le `Toggle` de shadcn : sans libellé visible, il porte son
30
+ * état (`aria-pressed`, fond marqué quand il est actif), et son infobulle
31
+ * dit ce que ferait un clic.
32
+ */
33
+ export declare function IconToggle({ actif, onActifChange, icone: Icone, libelle, infobulles, enCours, verrou, size, className, ...props }: IconToggleProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { Toggle as e } from "../ui/toggle.js";
2
+ import { Tooltip as t, TooltipContent as n, TooltipTrigger as r } from "../ui/tooltip.js";
3
+ import { useRaisonVerrou as i } from "./tooltip-button.js";
4
+ import { cn as a } from "cn";
5
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
6
+ // src/components/etic/icon-toggle.tsx
7
+ function l({ actif: l, onActifChange: u, icone: d, libelle: f, infobulles: p, enCours: m = !1, verrou: h, size: g = "sm", className: _, ...v }) {
8
+ let { describedBy: y, raison: b } = i(h), x = p ? l ? p.desactiver : p.activer : f, S = !!h || m;
9
+ return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ c(t, { children: [/* @__PURE__ */ s(r, {
10
+ render: /* @__PURE__ */ s(e, {
11
+ ...v,
12
+ size: g,
13
+ pressed: l,
14
+ onPressedChange: (e) => {
15
+ S || u(e);
16
+ },
17
+ "aria-disabled": S || void 0,
18
+ "aria-busy": m || void 0,
19
+ "aria-label": f,
20
+ "aria-describedby": y,
21
+ className: a("aria-pressed:text-foreground", h && "cursor-not-allowed opacity-50", m && "cursor-progress opacity-50", _)
22
+ }),
23
+ children: /* @__PURE__ */ s(d, {})
24
+ }), /* @__PURE__ */ s(n, { children: h ?? x })] }), b] });
25
+ }
26
+ export { l as IconToggle };
27
+
28
+ //# sourceMappingURL=icon-toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-toggle.js","names":["_Fragment","IconToggle","Icone","props","useRaisonVerrou","verrou","action","infobulles","actif","libelle","inerte","enCours","Fragment","Tooltip","TooltipTrigger","Toggle","onActifChange","suivant","describedBy","cn","className","TooltipContent","raison"],"sources":["../../../src/components/etic/icon-toggle.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\"\nimport { cn } from \"cn\"\nimport type { LucideIcon } from \"lucide-react\"\n\nimport { Toggle } from \"@etic-ui/components/ui/toggle\"\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@etic-ui/components/ui/tooltip\"\nimport { useRaisonVerrou } from \"@etic-ui/components/etic/tooltip-button\"\n\nexport interface IconToggleProps extends Omit<\n ComponentProps<typeof Toggle>,\n \"children\" | \"pressed\" | \"defaultPressed\" | \"onPressedChange\" | \"disabled\"\n> {\n /** État actuel : le marqueur est-il posé ? */\n actif: boolean\n /** Appelé avec l'état voulu. */\n onActifChange: (actif: boolean) => void\n icone: LucideIcon\n /** Nom accessible, constant (l'état est porté par `aria-pressed`) :\n * « Groupe critique ». */\n libelle: string\n /** Infobulle selon l'état : ce que ferait un clic (« Marquer ce groupe\n * comme critique », « Retirer le marqueur critique »). Le libellé par\n * défaut. */\n infobulles?: { activer: string; desactiver: string }\n /** Bascule en cours d'enregistrement : le bouton est occupé\n * (`aria-busy`) et ne réagit plus, mais garde le focus. */\n enCours?: boolean\n /** Bascule impossible : le bouton reste focalisable, et son infobulle dit\n * pourquoi. */\n verrou?: string\n}\n\n/**\n * Bouton à icône qui pose ou retire un marqueur sensible (élément critique,\n * protégé…), sur le `Toggle` de shadcn : sans libellé visible, il porte son\n * état (`aria-pressed`, fond marqué quand il est actif), et son infobulle\n * dit ce que ferait un clic.\n */\nexport function IconToggle({\n actif,\n onActifChange,\n icone: Icone,\n libelle,\n infobulles,\n enCours = false,\n verrou,\n size = \"sm\",\n className,\n ...props\n}: IconToggleProps) {\n const { describedBy, raison } = useRaisonVerrou(verrou)\n const action = infobulles\n ? actif\n ? infobulles.desactiver\n : infobulles.activer\n : libelle\n // Ni le verrou ni l'enregistrement ne désactivent nativement le bouton :\n // il perdrait le focus (et le survol qui montre la raison). Il est dit\n // indisponible et ignore les clics.\n const inerte = !!verrou || enCours\n return (\n <>\n <Tooltip>\n <TooltipTrigger\n render={\n <Toggle\n {...props}\n size={size}\n pressed={actif}\n onPressedChange={(suivant) => {\n if (!inerte) onActifChange(suivant)\n }}\n aria-disabled={inerte || undefined}\n aria-busy={enCours || undefined}\n aria-label={libelle}\n aria-describedby={describedBy}\n className={cn(\n \"aria-pressed:text-foreground\",\n verrou && \"cursor-not-allowed opacity-50\",\n enCours && \"cursor-progress opacity-50\",\n className\n )}\n />\n }\n >\n <Icone />\n </TooltipTrigger>\n <TooltipContent>{verrou ?? action}</TooltipContent>\n </Tooltip>\n {raison}\n </>\n )\n}\n"],"mappings":";;;;;;AA0CA,SAAgBC,EAAW,EACzB,UACA,kBACA,OAAOC,GACP,YACA,eACA,aAAU,IACV,WACA,UAAO,MACP,cACA,GAAGC,KACe;CAClB,IAAM,EAAE,gBAAa,cAAWC,EAAgBC,CAAM,GAChDC,IAASC,IACXC,IACED,EAAW,aACXA,EAAW,UACbE,GAIEC,IAAS,CAAC,CAACL,KAAUM;CAC3B,OACE,kBAAAX,GAAA,EAAA,UAAA,CACE,kBAACa,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;EACE,QACE,kBAACC,GAAD;GACE,GAAIZ;GACE;GACN,SAASK;GACT,kBAAkB,MAAY;IAC5B,AAAKE,KAAQM,EAAcC,CAAO;GACpC;GACA,iBAAeP,KAAU,KAAA;GACzB,aAAWC,KAAW,KAAA;GACtB,cAAYF;GACZ,oBAAkBS;GAClB,WAAWC,EACT,gCACAd,KAAU,iCACVM,KAAW,8BACXS,CACF;EACD,CAAA;EAGH,UAAA,kBAAClB,GAAD,CAAQ,CAAA;CACM,CAAA,GAChB,kBAACmB,GAAD,EAAA,UAAiBhB,KAAUC,EAAuB,CAAA,CAC3C,EAAA,CAAA,GACRgB,CACD,EAAA,CAAA;AAEN"}
@@ -0,0 +1,45 @@
1
+ import { ComponentProps } from 'react';
2
+ import { Spinner } from '../ui/spinner';
3
+ /**
4
+ * Roue muette, à côté d'un texte qui dit déjà qu'on attend (bouton occupé,
5
+ * statut « Chargement… ») : sans rôle ni nom, cachée aux lecteurs d'écran.
6
+ * Usage interne.
7
+ */
8
+ export declare function SpinnerDecoratif(props: ComponentProps<typeof Spinner>): import("react").JSX.Element;
9
+ export interface LoadingProps {
10
+ /** Annoncé aux lecteurs d'écran à chaque changement ; « Chargement… »
11
+ * par défaut. */
12
+ libelle?: string;
13
+ className?: string;
14
+ }
15
+ /** Attente sans forme connue : roue et libellé, annoncés poliment
16
+ * (`role="status"`). */
17
+ export declare function Loading({ libelle, className }: LoadingProps): import("react").JSX.Element;
18
+ export interface SkeletonTableProps {
19
+ /** 5 par défaut. */
20
+ lignes?: number;
21
+ /** 4 par défaut. */
22
+ colonnes?: number;
23
+ className?: string;
24
+ }
25
+ /** Lignes de barres, à la place d'un tableau qui charge. */
26
+ export declare function SkeletonTable({ lignes, colonnes, className, }: SkeletonTableProps): import("react").JSX.Element;
27
+ export interface SkeletonCardProps {
28
+ /** 3 par défaut. */
29
+ lignes?: number;
30
+ /**
31
+ * Porte le statut « Chargement… » ; vrai par défaut. Faux quand la carte
32
+ * fait partie d'un squelette qui l'annonce déjà (une seule annonce par
33
+ * zone qui charge).
34
+ */
35
+ annoncer?: boolean;
36
+ className?: string;
37
+ }
38
+ /** Une carte de lignes de texte, pour une fiche ou un résumé. */
39
+ export declare function SkeletonCard({ lignes, annoncer, className, }: SkeletonCardProps): import("react").JSX.Element;
40
+ export interface SkeletonPageProps {
41
+ className?: string;
42
+ }
43
+ /** Une fiche qui charge : la ligne du titre, puis deux cartes ; un seul
44
+ * statut « Chargement… ». */
45
+ export declare function SkeletonPage({ className }: SkeletonPageProps): import("react").JSX.Element;