@sia-ui/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/dist/diff.mjs +91 -0
  4. package/dist/index.js +325 -0
  5. package/dist/lifecycle.mjs +242 -0
  6. package/dist/lock.mjs +92 -0
  7. package/dist/registry/package/components/Accordion/index.tsx +172 -0
  8. package/dist/registry/package/components/Accordion/styles.css +97 -0
  9. package/dist/registry/package/components/Alert/index.tsx +31 -0
  10. package/dist/registry/package/components/Alert/styles.css +12 -0
  11. package/dist/registry/package/components/AmountDisplay/index.tsx +11 -0
  12. package/dist/registry/package/components/AmountDisplay/styles.css +9 -0
  13. package/dist/registry/package/components/AppShell/index.tsx +6 -0
  14. package/dist/registry/package/components/AppShell/styles.css +7 -0
  15. package/dist/registry/package/components/AspectRatio/index.tsx +29 -0
  16. package/dist/registry/package/components/AspectRatio/styles.css +15 -0
  17. package/dist/registry/package/components/AsyncState/index.tsx +22 -0
  18. package/dist/registry/package/components/AsyncState/styles.css +1 -0
  19. package/dist/registry/package/components/AuditMeta/index.tsx +44 -0
  20. package/dist/registry/package/components/AuditMeta/styles.css +12 -0
  21. package/dist/registry/package/components/AuthLayout/index.tsx +39 -0
  22. package/dist/registry/package/components/AuthLayout/styles.css +6 -0
  23. package/dist/registry/package/components/Autocomplete/index.tsx +8 -0
  24. package/dist/registry/package/components/Avatar/index.tsx +23 -0
  25. package/dist/registry/package/components/Avatar/styles.css +5 -0
  26. package/dist/registry/package/components/Badge/index.tsx +62 -0
  27. package/dist/registry/package/components/Badge/styles.css +26 -0
  28. package/dist/registry/package/components/Breadcrumb/index.tsx +131 -0
  29. package/dist/registry/package/components/Breadcrumb/styles.css +76 -0
  30. package/dist/registry/package/components/Button/index.tsx +91 -0
  31. package/dist/registry/package/components/Button/styles.css +111 -0
  32. package/dist/registry/package/components/Calendar/index.tsx +192 -0
  33. package/dist/registry/package/components/Card/index.tsx +8 -0
  34. package/dist/registry/package/components/Card/styles.css +4 -0
  35. package/dist/registry/package/components/Chart/index.tsx +437 -0
  36. package/dist/registry/package/components/Chart/styles.css +182 -0
  37. package/dist/registry/package/components/Checkbox/index.tsx +193 -0
  38. package/dist/registry/package/components/Checkbox/styles.css +39 -0
  39. package/dist/registry/package/components/ColorPicker/index.tsx +6 -0
  40. package/dist/registry/package/components/ColorPicker/styles.css +2 -0
  41. package/dist/registry/package/components/CommandPalette/index.tsx +7 -0
  42. package/dist/registry/package/components/CommandPalette/styles.css +8 -0
  43. package/dist/registry/package/components/ConfirmDialog/index.tsx +24 -0
  44. package/dist/registry/package/components/Container/index.tsx +11 -0
  45. package/dist/registry/package/components/Container/styles.css +1 -0
  46. package/dist/registry/package/components/Countdown/index.tsx +3 -0
  47. package/dist/registry/package/components/CrudPage/index.tsx +9 -0
  48. package/dist/registry/package/components/CrudPage/styles.css +1 -0
  49. package/dist/registry/package/components/CurrencyInput/index.tsx +15 -0
  50. package/dist/registry/package/components/CurrencyInput/styles.css +1 -0
  51. package/dist/registry/package/components/DataTable/index.tsx +240 -0
  52. package/dist/registry/package/components/DataTable/styles.css +98 -0
  53. package/dist/registry/package/components/DatePicker/index.tsx +102 -0
  54. package/dist/registry/package/components/DateRangeFilter/index.tsx +8 -0
  55. package/dist/registry/package/components/DateRangeFilter/styles.css +4 -0
  56. package/dist/registry/package/components/DateRangePicker/index.tsx +36 -0
  57. package/dist/registry/package/components/DateTimePicker/index.tsx +32 -0
  58. package/dist/registry/package/components/Descriptions/index.tsx +7 -0
  59. package/dist/registry/package/components/Descriptions/styles.css +8 -0
  60. package/dist/registry/package/components/Divider/index.tsx +12 -0
  61. package/dist/registry/package/components/Divider/styles.css +3 -0
  62. package/dist/registry/package/components/Drawer/context.ts +14 -0
  63. package/dist/registry/package/components/Drawer/index.tsx +209 -0
  64. package/dist/registry/package/components/Drawer/styles.css +151 -0
  65. package/dist/registry/package/components/DropdownMenu/index.tsx +350 -0
  66. package/dist/registry/package/components/DropdownMenu/styles.css +100 -0
  67. package/dist/registry/package/components/DurationDisplay/index.tsx +3 -0
  68. package/dist/registry/package/components/EmptyState/index.tsx +23 -0
  69. package/dist/registry/package/components/EmptyState/styles.css +6 -0
  70. package/dist/registry/package/components/EntityMeta/index.tsx +65 -0
  71. package/dist/registry/package/components/EntityMeta/styles.css +9 -0
  72. package/dist/registry/package/components/ErrorState/index.tsx +30 -0
  73. package/dist/registry/package/components/ErrorState/styles.css +6 -0
  74. package/dist/registry/package/components/EventCalendar/index.tsx +8 -0
  75. package/dist/registry/package/components/EventCalendar/styles.css +8 -0
  76. package/dist/registry/package/components/Field/index.tsx +664 -0
  77. package/dist/registry/package/components/Field/styles.css +14 -0
  78. package/dist/registry/package/components/FileUpload/index.tsx +68 -0
  79. package/dist/registry/package/components/FileUpload/styles.css +4 -0
  80. package/dist/registry/package/components/FiltersBar/index.tsx +20 -0
  81. package/dist/registry/package/components/FiltersBar/styles.css +6 -0
  82. package/dist/registry/package/components/Form/index.tsx +211 -0
  83. package/dist/registry/package/components/Form/styles.css +80 -0
  84. package/dist/registry/package/components/FormField/index.tsx +2 -0
  85. package/dist/registry/package/components/HoverCard/index.tsx +121 -0
  86. package/dist/registry/package/components/HoverCard/styles.css +26 -0
  87. package/dist/registry/package/components/IconButton/index.tsx +27 -0
  88. package/dist/registry/package/components/IconButton/styles.css +7 -0
  89. package/dist/registry/package/components/Icons/index.tsx +185 -0
  90. package/dist/registry/package/components/ImageUpload/index.tsx +6 -0
  91. package/dist/registry/package/components/ImageUpload/styles.css +4 -0
  92. package/dist/registry/package/components/Input/index.tsx +103 -0
  93. package/dist/registry/package/components/Input/styles.css +8 -0
  94. package/dist/registry/package/components/InputNumber/index.tsx +196 -0
  95. package/dist/registry/package/components/InputNumber/styles.css +54 -0
  96. package/dist/registry/package/components/JsonEditor/index.tsx +6 -0
  97. package/dist/registry/package/components/JsonEditor/styles.css +2 -0
  98. package/dist/registry/package/components/KpiGrid/index.tsx +11 -0
  99. package/dist/registry/package/components/KpiGrid/styles.css +5 -0
  100. package/dist/registry/package/components/Label/index.tsx +43 -0
  101. package/dist/registry/package/components/Label/styles.css +25 -0
  102. package/dist/registry/package/components/MarkdownEditor/index.tsx +5 -0
  103. package/dist/registry/package/components/MiniCalendar/index.tsx +3 -0
  104. package/dist/registry/package/components/Modal/index.tsx +104 -0
  105. package/dist/registry/package/components/Modal/styles.css +20 -0
  106. package/dist/registry/package/components/MonthPicker/index.tsx +5 -0
  107. package/dist/registry/package/components/MultiSelect/index.tsx +133 -0
  108. package/dist/registry/package/components/MultiSelect/styles.css +3 -0
  109. package/dist/registry/package/components/OtpInput/index.tsx +5 -0
  110. package/dist/registry/package/components/OtpInput/styles.css +2 -0
  111. package/dist/registry/package/components/Overlay/index.tsx +140 -0
  112. package/dist/registry/package/components/Overlay/styles.css +1 -0
  113. package/dist/registry/package/components/PageHeader/index.tsx +24 -0
  114. package/dist/registry/package/components/PageHeader/styles.css +5 -0
  115. package/dist/registry/package/components/Pagination/index.tsx +155 -0
  116. package/dist/registry/package/components/Pagination/styles.css +103 -0
  117. package/dist/registry/package/components/PasswordInput/index.tsx +125 -0
  118. package/dist/registry/package/components/PasswordInput/styles.css +58 -0
  119. package/dist/registry/package/components/PermissionGate/index.tsx +3 -0
  120. package/dist/registry/package/components/PhoneInput/index.tsx +189 -0
  121. package/dist/registry/package/components/PhoneInput/styles.css +35 -0
  122. package/dist/registry/package/components/Popover/index.tsx +12 -0
  123. package/dist/registry/package/components/Popover/styles.css +12 -0
  124. package/dist/registry/package/components/Progress/index.tsx +149 -0
  125. package/dist/registry/package/components/Progress/styles.css +101 -0
  126. package/dist/registry/package/components/QrCode/index.tsx +6 -0
  127. package/dist/registry/package/components/QrCode/styles.css +5 -0
  128. package/dist/registry/package/components/RadioGroup/index.tsx +29 -0
  129. package/dist/registry/package/components/RadioGroup/styles.css +20 -0
  130. package/dist/registry/package/components/Rating/index.tsx +82 -0
  131. package/dist/registry/package/components/Rating/styles.css +41 -0
  132. package/dist/registry/package/components/ReferenceSelect/index.tsx +7 -0
  133. package/dist/registry/package/components/ReferenceSelect/styles.css +2 -0
  134. package/dist/registry/package/components/RelativeTime/index.tsx +22 -0
  135. package/dist/registry/package/components/RelativeTime/styles.css +1 -0
  136. package/dist/registry/package/components/RequireSession/index.tsx +127 -0
  137. package/dist/registry/package/components/RequireSession/styles.css +13 -0
  138. package/dist/registry/package/components/ResizablePanel/index.tsx +6 -0
  139. package/dist/registry/package/components/ResizablePanel/styles.css +5 -0
  140. package/dist/registry/package/components/RichTextEditor/index.tsx +5 -0
  141. package/dist/registry/package/components/RichTextEditor/styles.css +2 -0
  142. package/dist/registry/package/components/ScrollArea/index.tsx +114 -0
  143. package/dist/registry/package/components/ScrollArea/styles.css +74 -0
  144. package/dist/registry/package/components/SearchInput/index.tsx +121 -0
  145. package/dist/registry/package/components/SearchInput/styles.css +6 -0
  146. package/dist/registry/package/components/Select/index.tsx +324 -0
  147. package/dist/registry/package/components/Select/styles.css +58 -0
  148. package/dist/registry/package/components/Sidebar/index.tsx +232 -0
  149. package/dist/registry/package/components/Sidebar/styles.css +140 -0
  150. package/dist/registry/package/components/Skeleton/index.tsx +21 -0
  151. package/dist/registry/package/components/Skeleton/styles.css +2 -0
  152. package/dist/registry/package/components/Slider/index.tsx +193 -0
  153. package/dist/registry/package/components/Slider/styles.css +53 -0
  154. package/dist/registry/package/components/Spinner/index.tsx +28 -0
  155. package/dist/registry/package/components/Spinner/styles.css +8 -0
  156. package/dist/registry/package/components/StatCard/index.tsx +15 -0
  157. package/dist/registry/package/components/StatCard/styles.css +3 -0
  158. package/dist/registry/package/components/Statistic/index.tsx +23 -0
  159. package/dist/registry/package/components/Statistic/styles.css +6 -0
  160. package/dist/registry/package/components/Steps/index.tsx +108 -0
  161. package/dist/registry/package/components/Steps/styles.css +138 -0
  162. package/dist/registry/package/components/Switch/index.tsx +46 -0
  163. package/dist/registry/package/components/Switch/styles.css +26 -0
  164. package/dist/registry/package/components/Tabs/index.tsx +44 -0
  165. package/dist/registry/package/components/Tabs/styles.css +41 -0
  166. package/dist/registry/package/components/TagsInput/index.tsx +6 -0
  167. package/dist/registry/package/components/TagsInput/styles.css +2 -0
  168. package/dist/registry/package/components/Textarea/index.tsx +21 -0
  169. package/dist/registry/package/components/Textarea/styles.css +7 -0
  170. package/dist/registry/package/components/TimePicker/index.tsx +76 -0
  171. package/dist/registry/package/components/TimePicker/styles.css +13 -0
  172. package/dist/registry/package/components/TimeRangePicker/index.tsx +32 -0
  173. package/dist/registry/package/components/TimeRangePicker/styles.css +1 -0
  174. package/dist/registry/package/components/Timeline/index.tsx +8 -0
  175. package/dist/registry/package/components/Timeline/styles.css +12 -0
  176. package/dist/registry/package/components/Timer/index.tsx +9 -0
  177. package/dist/registry/package/components/Toast/index.tsx +426 -0
  178. package/dist/registry/package/components/Toast/styles.css +175 -0
  179. package/dist/registry/package/components/Toggle/index.tsx +181 -0
  180. package/dist/registry/package/components/Toggle/styles.css +124 -0
  181. package/dist/registry/package/components/Tooltip/index.tsx +163 -0
  182. package/dist/registry/package/components/Tooltip/styles.css +57 -0
  183. package/dist/registry/package/components/Tour/index.tsx +8 -0
  184. package/dist/registry/package/components/Tour/styles.css +6 -0
  185. package/dist/registry/package/components/Transfer/index.tsx +7 -0
  186. package/dist/registry/package/components/Transfer/styles.css +6 -0
  187. package/dist/registry/package/components/Tree/index.tsx +8 -0
  188. package/dist/registry/package/components/Tree/styles.css +6 -0
  189. package/dist/registry/package/components/TreeSelect/index.tsx +10 -0
  190. package/dist/registry/package/components/TreeSelect/styles.css +3 -0
  191. package/dist/registry/package/components/Typography/index.tsx +27 -0
  192. package/dist/registry/package/components/Typography/styles.css +16 -0
  193. package/dist/registry/package/components/UnsavedChangesGuard/index.tsx +4 -0
  194. package/dist/registry/package/components/WeekPicker/index.tsx +5 -0
  195. package/dist/registry/package/components/YearPicker/index.tsx +3 -0
  196. package/dist/registry/package/lib/form-adapter-rhf.tsx +141 -0
  197. package/dist/registry/registry.json +1780 -0
  198. package/dist/registry/styles/sia-ui.css +361 -0
  199. package/dist/source.mjs +93 -0
  200. package/package.json +55 -0
@@ -0,0 +1,114 @@
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useRef,
5
+ useState,
6
+ type CSSProperties,
7
+ type ReactNode,
8
+ } from "react";
9
+ import { cn } from "@sia-ui/utils";
10
+ import "./styles.css";
11
+
12
+ export interface ScrollAreaProps {
13
+ children: ReactNode;
14
+ /** Hauteur maximale. Au-delà, la zone défile. */
15
+ maxHeight?: number | string;
16
+ height?: number | string;
17
+ orientation?: "vertical" | "horizontal" | "both";
18
+ /**
19
+ * Estompe le contenu aux bords tant qu'il reste quelque chose à faire
20
+ * défiler. C'est le seul indice fiable quand la barre est fine ou masquée.
21
+ */
22
+ fade?: boolean;
23
+ className?: string;
24
+ }
25
+
26
+ /**
27
+ * Une zone défilante sobre.
28
+ *
29
+ * La barre reste celle du navigateur, seulement affinée : une barre
30
+ * réimplémentée en JavaScript coûte un écouteur de défilement, deux mesures
31
+ * par image et perd le défilement inertiel des pavés tactiles. Le seul ajout
32
+ * est l'estompe des bords, qui ne demande qu'un booléen par côté.
33
+ */
34
+ export function ScrollArea({
35
+ children,
36
+ maxHeight,
37
+ height,
38
+ orientation = "vertical",
39
+ fade = true,
40
+ className,
41
+ }: ScrollAreaProps) {
42
+ const ref = useRef<HTMLDivElement>(null);
43
+ const [edges, setEdges] = useState({
44
+ top: false,
45
+ bottom: false,
46
+ left: false,
47
+ right: false,
48
+ });
49
+
50
+ const measure = useCallback(() => {
51
+ const node = ref.current;
52
+ if (!node || !fade) return;
53
+ const {
54
+ scrollTop,
55
+ scrollLeft,
56
+ scrollHeight,
57
+ scrollWidth,
58
+ clientHeight,
59
+ clientWidth,
60
+ } = node;
61
+ setEdges({
62
+ top: scrollTop > 1,
63
+ // Une tolérance d'un pixel : un zoom navigateur produit des hauteurs
64
+ // fractionnaires et l'estompe du bas resterait sinon allumée en bout
65
+ // de course.
66
+ bottom: scrollTop + clientHeight < scrollHeight - 1,
67
+ left: scrollLeft > 1,
68
+ right: scrollLeft + clientWidth < scrollWidth - 1,
69
+ });
70
+ }, [fade]);
71
+
72
+ // Le contenu peut changer sans qu'on défile — une liste qui se charge.
73
+ useEffect(() => {
74
+ measure();
75
+ const node = ref.current;
76
+ if (!node || typeof ResizeObserver === "undefined") return undefined;
77
+ const observer = new ResizeObserver(measure);
78
+ observer.observe(node);
79
+ for (const child of Array.from(node.children)) observer.observe(child);
80
+ return () => observer.disconnect();
81
+ }, [children, measure]);
82
+
83
+ const style: CSSProperties = {
84
+ ...(height !== undefined ? { height } : {}),
85
+ ...(maxHeight !== undefined ? { maxHeight } : {}),
86
+ };
87
+
88
+ return (
89
+ <div
90
+ className={cn(
91
+ "sia-scroll-area",
92
+ `sia-scroll-area--${orientation}`,
93
+ fade && "sia-scroll-area--fade",
94
+ className,
95
+ )}
96
+ data-top={edges.top || undefined}
97
+ data-bottom={edges.bottom || undefined}
98
+ data-left={edges.left || undefined}
99
+ data-right={edges.right || undefined}
100
+ >
101
+ <div
102
+ ref={ref}
103
+ className="sia-scroll-area__viewport"
104
+ style={style}
105
+ {...(fade ? { onScroll: measure } : {})}
106
+ // Focalisable : sans cela les flèches du clavier ne font défiler la
107
+ // zone qu'une fois un élément intérieur atteint par tabulation.
108
+ tabIndex={0}
109
+ >
110
+ {children}
111
+ </div>
112
+ </div>
113
+ );
114
+ }
@@ -0,0 +1,74 @@
1
+ .sia-scroll-area { position: relative; min-height: 0; min-width: 0; }
2
+
3
+ .sia-scroll-area__viewport {
4
+ overflow: auto;
5
+ /* La barre fine standardisée. Firefox comprend ces deux propriétés, les
6
+ navigateurs WebKit passent par le sélecteur ci-dessous. */
7
+ scrollbar-width: thin;
8
+ scrollbar-color: var(--sia-border-strong) transparent;
9
+ overscroll-behavior: contain;
10
+ scroll-behavior: smooth;
11
+ }
12
+ .sia-scroll-area--vertical .sia-scroll-area__viewport { overflow-x: hidden; }
13
+ .sia-scroll-area--horizontal .sia-scroll-area__viewport { overflow-y: hidden; }
14
+
15
+ .sia-scroll-area__viewport::-webkit-scrollbar { width: 8px; height: 8px; }
16
+ .sia-scroll-area__viewport::-webkit-scrollbar-track { background: transparent; }
17
+ .sia-scroll-area__viewport::-webkit-scrollbar-thumb {
18
+ border: 2px solid transparent;
19
+ border-radius: 999px;
20
+ background-clip: content-box;
21
+ background-color: transparent;
22
+ transition: background-color var(--sia-duration-base) var(--sia-easing-standard);
23
+ }
24
+ /* Le curseur n'apparaît qu'à l'approche : une barre permanente sur une liste
25
+ courte attire l'œil pour rien. */
26
+ .sia-scroll-area:hover .sia-scroll-area__viewport::-webkit-scrollbar-thumb,
27
+ .sia-scroll-area__viewport:focus-within::-webkit-scrollbar-thumb {
28
+ background-color: var(--sia-border-strong);
29
+ }
30
+ .sia-scroll-area__viewport::-webkit-scrollbar-thumb:hover {
31
+ background-color: var(--sia-muted);
32
+ }
33
+
34
+ /* ── Estompe des bords ─────────────────────────────────────────────────── */
35
+
36
+ .sia-scroll-area--fade::before,
37
+ .sia-scroll-area--fade::after {
38
+ content: "";
39
+ position: absolute;
40
+ z-index: 1;
41
+ opacity: 0;
42
+ pointer-events: none;
43
+ transition: opacity var(--sia-duration-base) var(--sia-easing-standard);
44
+ }
45
+
46
+ .sia-scroll-area--fade.sia-scroll-area--vertical::before,
47
+ .sia-scroll-area--fade.sia-scroll-area--both::before {
48
+ inset: 0 0 auto 0;
49
+ height: 2rem;
50
+ background: linear-gradient(to bottom, var(--sia-background), transparent);
51
+ }
52
+ .sia-scroll-area--fade.sia-scroll-area--vertical::after,
53
+ .sia-scroll-area--fade.sia-scroll-area--both::after {
54
+ inset: auto 0 0 0;
55
+ height: 2rem;
56
+ background: linear-gradient(to top, var(--sia-background), transparent);
57
+ }
58
+ .sia-scroll-area--fade.sia-scroll-area--horizontal::before {
59
+ inset: 0 auto 0 0;
60
+ width: 2rem;
61
+ background: linear-gradient(to right, var(--sia-background), transparent);
62
+ }
63
+ .sia-scroll-area--fade.sia-scroll-area--horizontal::after {
64
+ inset: 0 0 0 auto;
65
+ width: 2rem;
66
+ background: linear-gradient(to left, var(--sia-background), transparent);
67
+ }
68
+
69
+ .sia-scroll-area--vertical[data-top]::before,
70
+ .sia-scroll-area--both[data-top]::before,
71
+ .sia-scroll-area--horizontal[data-left]::before { opacity: 1; }
72
+ .sia-scroll-area--vertical[data-bottom]::after,
73
+ .sia-scroll-area--both[data-bottom]::after,
74
+ .sia-scroll-area--horizontal[data-right]::after { opacity: 1; }
@@ -0,0 +1,121 @@
1
+ import {
2
+ forwardRef,
3
+ useEffect,
4
+ useRef,
5
+ useState,
6
+ type InputHTMLAttributes,
7
+ } from "react";
8
+ import { cn } from "@sia-ui/utils";
9
+ import { useSiaLocale } from "@sia-ui/headless";
10
+ import { SearchIcon, XIcon } from "../Icons";
11
+ import "./styles.css";
12
+
13
+ export interface SearchInputProps
14
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "onChange"> {
15
+ value?: string;
16
+ defaultValue?: string;
17
+ onValueChange?: (value: string) => void;
18
+ /** Appelé à la validation, et après le délai si `searchDelay` est posé. */
19
+ onSearch?: (value: string) => void;
20
+ /**
21
+ * Millisecondes d'inactivité avant de déclencher `onSearch`.
22
+ *
23
+ * `0` — le défaut — ne déclenche qu'à la validation. Au-delà, la recherche
24
+ * part quand la frappe s'arrête : c'est ce que chaque projet réécrivait
25
+ * autour de ce champ.
26
+ */
27
+ searchDelay?: number;
28
+ clearable?: boolean;
29
+ searchLabel?: string;
30
+ clearLabel?: string;
31
+ }
32
+
33
+ export const SearchInput = forwardRef<HTMLInputElement, SearchInputProps>(
34
+ (
35
+ {
36
+ value,
37
+ defaultValue = "",
38
+ onValueChange,
39
+ onSearch,
40
+ searchDelay = 0,
41
+ clearable = true,
42
+ searchLabel: searchLabelProp,
43
+ clearLabel = "Effacer la recherche",
44
+ className,
45
+ placeholder: placeholderProp,
46
+ ...props
47
+ },
48
+ ref,
49
+ ) => {
50
+ const locale = useSiaLocale();
51
+ const placeholder = placeholderProp ?? locale.searchPlaceholder;
52
+ const searchLabel = searchLabelProp ?? locale.search;
53
+
54
+ const [internal, setInternal] = useState(defaultValue);
55
+ const current = value ?? internal;
56
+
57
+ // Le champ reste immédiat : seul le déclenchement est retardé. Retarder
58
+ // la valeur affichée donnerait un champ qui paraît figé à la frappe.
59
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
60
+ const latest = useRef({ onSearch, searchDelay });
61
+ latest.current = { onSearch, searchDelay };
62
+
63
+ useEffect(() => () => clearTimeout(timer.current), []);
64
+
65
+ const update = (next: string) => {
66
+ if (value === undefined) setInternal(next);
67
+ onValueChange?.(next);
68
+
69
+ const { searchDelay: wait, onSearch: search } = latest.current;
70
+ if (!wait || !search) return;
71
+
72
+ clearTimeout(timer.current);
73
+ timer.current = setTimeout(() => search(next), wait);
74
+ };
75
+
76
+ return (
77
+ <form
78
+ className={cn("sia-search-input", className)}
79
+ role="search"
80
+ onSubmit={(event) => {
81
+ event.preventDefault();
82
+ // La validation l'emporte sur le délai en cours : on n'attend pas
83
+ // 300 ms de plus après avoir appuyé sur Entrée.
84
+ clearTimeout(timer.current);
85
+ onSearch?.(current);
86
+ }}
87
+ >
88
+ <span className="sia-search-input__icon" aria-hidden="true">
89
+ <SearchIcon />
90
+ </span>
91
+ <input
92
+ ref={ref}
93
+ type="search"
94
+ value={current}
95
+ placeholder={placeholder}
96
+ aria-label={searchLabel}
97
+ onChange={(event) => update(event.target.value)}
98
+ {...props}
99
+ />
100
+ {clearable && current && (
101
+ <button
102
+ type="button"
103
+ aria-label={clearLabel}
104
+ className="sia-search-input__clear"
105
+ onClick={() => {
106
+ update("");
107
+ // Effacer relance la recherche tout de suite : attendre le
108
+ // délai pour afficher la liste complète n'a aucun sens.
109
+ clearTimeout(timer.current);
110
+ onSearch?.("");
111
+ }}
112
+ >
113
+ <XIcon />
114
+ </button>
115
+ )}
116
+ </form>
117
+ );
118
+ },
119
+ );
120
+
121
+ SearchInput.displayName = "SearchInput";
@@ -0,0 +1,6 @@
1
+ .sia-search-input { display:flex; align-items:center; min-height:2.5rem; overflow:hidden; border:1px solid var(--sia-border); border-radius:var(--sia-radius); color:var(--sia-muted); background:var(--sia-background); }
2
+ .sia-search-input:focus-within { outline:3px solid color-mix(in srgb,var(--sia-primary) 30%,transparent); outline-offset:2px; }
3
+ .sia-search-input__icon { padding-left:.75rem; }
4
+ .sia-search-input input { flex:1; min-width:0; min-height:2.4rem; padding:0 .65rem; border:0; outline:0; color:var(--sia-foreground); background:transparent; font:inherit; }
5
+ .sia-search-input__clear { padding:.4rem .75rem; border:0; color:var(--sia-muted); background:transparent; font-size:1.1rem; cursor:pointer; }
6
+ .sia-search-input input { line-height:1.25; }
@@ -0,0 +1,324 @@
1
+ import {
2
+ Children,
3
+ forwardRef,
4
+ isValidElement,
5
+ useEffect,
6
+ useId,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ type KeyboardEvent,
11
+ type ReactNode,
12
+ } from "react";
13
+ import { cn } from "@sia-ui/utils";
14
+ import { Overlay, type OverlayPlacement } from "../Overlay";
15
+ import { Spinner } from "../Spinner";
16
+ import { ChevronDownIcon, SearchIcon, CheckIcon, XIcon } from "../Icons";
17
+ import "./styles.css";
18
+
19
+ export interface SelectOption {
20
+ value: string;
21
+ label: ReactNode;
22
+ description?: ReactNode;
23
+ disabled?: boolean;
24
+ keywords?: string[];
25
+ }
26
+
27
+ export interface SelectProps {
28
+ id?: string;
29
+ name?: string;
30
+ options?: SelectOption[];
31
+ /** Compatibility path. Prefer the options prop. */
32
+ children?: ReactNode;
33
+ value?: string;
34
+ defaultValue?: string;
35
+ onValueChange?: (value: string, option?: SelectOption) => void;
36
+ placeholder?: string;
37
+ searchable?: boolean;
38
+ searchPlaceholder?: string;
39
+ fetcher?: (query: string, signal?: AbortSignal) => Promise<SelectOption[]>;
40
+ debounce?: number;
41
+ loadingText?: ReactNode;
42
+ emptyText?: ReactNode;
43
+ errorText?: ReactNode;
44
+ clearable?: boolean;
45
+ disabled?: boolean;
46
+ invalid?: boolean;
47
+ required?: boolean;
48
+ placement?: OverlayPlacement;
49
+ className?: string;
50
+ "aria-label"?: string;
51
+ "aria-describedby"?: string;
52
+ "aria-labelledby"?: string;
53
+ "aria-invalid"?: boolean;
54
+ "aria-required"?: boolean;
55
+ }
56
+
57
+ function optionsFromChildren(children: ReactNode): SelectOption[] {
58
+ return Children.toArray(children).flatMap((child) => {
59
+ if (!isValidElement<{ value?: string; disabled?: boolean; children?: ReactNode }>(child))
60
+ return [];
61
+ const value = child.props.value;
62
+ if (value === undefined) return [];
63
+ return [{
64
+ value: String(value),
65
+ label: child.props.children,
66
+ ...(child.props.disabled !== undefined ? { disabled: child.props.disabled } : {}),
67
+ }];
68
+ });
69
+ }
70
+
71
+ function optionText(option: SelectOption) {
72
+ return [option.label, option.description, ...(option.keywords ?? [])]
73
+ .map((value) => (typeof value === "string" || typeof value === "number" ? String(value) : ""))
74
+ .join(" ")
75
+ .toLocaleLowerCase();
76
+ }
77
+
78
+ export const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(
79
+ {
80
+ id,
81
+ name,
82
+ options,
83
+ children,
84
+ value,
85
+ defaultValue = "",
86
+ onValueChange,
87
+ placeholder = "Sélectionner",
88
+ searchable = false,
89
+ searchPlaceholder = "Rechercher...",
90
+ fetcher,
91
+ debounce = 250,
92
+ loadingText = "Chargement des options...",
93
+ emptyText = "Aucun résultat",
94
+ errorText = "Impossible de charger les options",
95
+ clearable = false,
96
+ disabled = false,
97
+ invalid = false,
98
+ required = false,
99
+ placement = "bottom-start",
100
+ className,
101
+ "aria-invalid": ariaInvalid,
102
+ "aria-required": ariaRequired,
103
+ ...ariaProps
104
+ },
105
+ forwardedRef,
106
+ ) {
107
+ const generatedId = useId();
108
+ const controlId = id ?? `sia-select-${generatedId.replace(/:/g, "")}`;
109
+ const listboxId = `${controlId}-listbox`;
110
+ const triggerRef = useRef<HTMLButtonElement>(null);
111
+ const searchRef = useRef<HTMLInputElement>(null);
112
+ const staticOptions = useMemo(
113
+ () => options ?? optionsFromChildren(children),
114
+ [children, options],
115
+ );
116
+ const [internalValue, setInternalValue] = useState(defaultValue);
117
+ const [open, setOpen] = useState(false);
118
+ const [query, setQuery] = useState("");
119
+ const [remoteOptions, setRemoteOptions] = useState<SelectOption[]>([]);
120
+ const [selectedRemoteOption, setSelectedRemoteOption] = useState<SelectOption>();
121
+ const [loading, setLoading] = useState(false);
122
+ const [loadError, setLoadError] = useState(false);
123
+ const [activeIndex, setActiveIndex] = useState(-1);
124
+ const currentValue = value ?? internalValue;
125
+ const sourceOptions = fetcher ? remoteOptions : staticOptions;
126
+ const visibleOptions = useMemo(() => {
127
+ if (fetcher) return sourceOptions;
128
+ const needle = query.trim().toLocaleLowerCase();
129
+ return needle
130
+ ? sourceOptions.filter((option) => optionText(option).includes(needle))
131
+ : sourceOptions;
132
+ }, [fetcher, query, sourceOptions]);
133
+ const selectedOption = [...staticOptions, ...remoteOptions].find(
134
+ (option) => option.value === currentValue,
135
+ ) ?? (selectedRemoteOption?.value === currentValue ? selectedRemoteOption : undefined);
136
+
137
+ useEffect(() => {
138
+ if (!open || !fetcher) return;
139
+ const controller = new AbortController();
140
+ const timeout = window.setTimeout(async () => {
141
+ setLoading(true);
142
+ setLoadError(false);
143
+ try {
144
+ const nextOptions = await fetcher(query, controller.signal);
145
+ if (!controller.signal.aborted) setRemoteOptions(nextOptions);
146
+ } catch {
147
+ if (!controller.signal.aborted) setLoadError(true);
148
+ } finally {
149
+ if (!controller.signal.aborted) setLoading(false);
150
+ }
151
+ }, debounce);
152
+ return () => {
153
+ window.clearTimeout(timeout);
154
+ controller.abort();
155
+ };
156
+ }, [debounce, fetcher, open, query]);
157
+
158
+ useEffect(() => {
159
+ if (!open) return;
160
+ setActiveIndex(visibleOptions.findIndex((option) => option.value === currentValue));
161
+ if (searchable || fetcher) window.setTimeout(() => searchRef.current?.focus(), 0);
162
+ }, [currentValue, fetcher, open, searchable, visibleOptions]);
163
+
164
+ const setTriggerRef = (node: HTMLButtonElement | null) => {
165
+ triggerRef.current = node;
166
+ if (typeof forwardedRef === "function") forwardedRef(node);
167
+ else if (forwardedRef) forwardedRef.current = node;
168
+ };
169
+ const changeValue = (nextValue: string, option?: SelectOption) => {
170
+ if (value === undefined) setInternalValue(nextValue);
171
+ onValueChange?.(nextValue, option);
172
+ };
173
+ const choose = (option: SelectOption) => {
174
+ if (option.disabled) return;
175
+ if (fetcher) setSelectedRemoteOption(option);
176
+ changeValue(option.value, option);
177
+ setOpen(false);
178
+ setQuery("");
179
+ window.setTimeout(() => triggerRef.current?.focus(), 0);
180
+ };
181
+ const moveActive = (direction: 1 | -1) => {
182
+ if (!visibleOptions.length) return;
183
+ let next = activeIndex;
184
+ for (let count = 0; count < visibleOptions.length; count += 1) {
185
+ next = (next + direction + visibleOptions.length) % visibleOptions.length;
186
+ if (!visibleOptions[next]?.disabled) break;
187
+ }
188
+ setActiveIndex(next);
189
+ };
190
+ const handleKeyDown = (event: KeyboardEvent<HTMLElement>) => {
191
+ if (["ArrowDown", "ArrowUp"].includes(event.key)) {
192
+ event.preventDefault();
193
+ if (!open) setOpen(true);
194
+ else moveActive(event.key === "ArrowDown" ? 1 : -1);
195
+ return;
196
+ }
197
+ if (event.key === "Home" && open) {
198
+ event.preventDefault();
199
+ setActiveIndex(visibleOptions.findIndex((option) => !option.disabled));
200
+ } else if (event.key === "End" && open) {
201
+ event.preventDefault();
202
+ for (let index = visibleOptions.length - 1; index >= 0; index -= 1) {
203
+ if (!visibleOptions[index]?.disabled) {
204
+ setActiveIndex(index);
205
+ break;
206
+ }
207
+ }
208
+ } else if (event.key === "Enter" && open && activeIndex >= 0) {
209
+ event.preventDefault();
210
+ const active = visibleOptions[activeIndex];
211
+ if (active) choose(active);
212
+ } else if (event.key === "Escape" && open) {
213
+ event.preventDefault();
214
+ setOpen(false);
215
+ triggerRef.current?.focus();
216
+ } else if (!open && clearable && currentValue && ["Backspace", "Delete"].includes(event.key)) {
217
+ event.preventDefault();
218
+ changeValue("");
219
+ }
220
+ };
221
+
222
+ const showSearch = searchable || Boolean(fetcher);
223
+ const activeOption = activeIndex >= 0 ? visibleOptions[activeIndex] : undefined;
224
+
225
+ return (
226
+ <div className={cn("sia-select", disabled && "sia-select--disabled", className)}>
227
+ {name && <input type="hidden" name={name} value={currentValue} />}
228
+ <button
229
+ ref={setTriggerRef}
230
+ id={controlId}
231
+ type="button"
232
+ className={cn("sia-select__trigger", invalid && "sia-select__trigger--invalid")}
233
+ role="combobox"
234
+ aria-haspopup="listbox"
235
+ aria-expanded={open}
236
+ aria-controls={listboxId}
237
+ aria-activedescendant={open && activeOption ? `${listboxId}-${activeIndex}` : undefined}
238
+ aria-invalid={ariaInvalid ?? (invalid || undefined)}
239
+ aria-required={ariaRequired ?? (required || undefined)}
240
+ disabled={disabled}
241
+ onClick={() => setOpen((current) => !current)}
242
+ onKeyDown={handleKeyDown}
243
+ {...ariaProps}
244
+ >
245
+ <span className={cn("sia-select__value", !selectedOption && "sia-select__placeholder")}>{selectedOption?.label ?? placeholder}</span>
246
+ <span className="sia-select__actions">
247
+ {clearable && currentValue && !disabled && (
248
+ <span
249
+ className="sia-select__clear"
250
+ aria-hidden="true"
251
+ title="Effacer la sélection"
252
+ onClick={(event) => {
253
+ event.stopPropagation();
254
+ changeValue("");
255
+ }}
256
+ >
257
+ <XIcon />
258
+ </span>
259
+ )}
260
+ <ChevronDownIcon className="sia-select__chevron" aria-hidden="true" />
261
+ </span>
262
+ </button>
263
+ <Overlay
264
+ open={open}
265
+ anchorRef={triggerRef}
266
+ onOpenChange={setOpen}
267
+ placement={placement}
268
+ matchAnchorWidth
269
+ className="sia-select__overlay"
270
+ >
271
+ <div className="sia-select__panel" onKeyDown={handleKeyDown}>
272
+ {showSearch && (
273
+ <div className="sia-select__search-wrap">
274
+ <SearchIcon aria-hidden="true" />
275
+ <input
276
+ ref={searchRef}
277
+ className="sia-select__search"
278
+ value={query}
279
+ placeholder={searchPlaceholder}
280
+ aria-label={searchPlaceholder}
281
+ onChange={(event) => setQuery(event.target.value)}
282
+ />
283
+ {loading && <Spinner size="xs" label="Chargement" />}
284
+ </div>
285
+ )}
286
+ <div id={listboxId} role="listbox" aria-busy={loading || undefined} className="sia-select__options">
287
+ {loading && !visibleOptions.length ? (
288
+ <div className="sia-select__status">{loadingText}</div>
289
+ ) : loadError ? (
290
+ <div className="sia-select__status sia-select__status--error">{errorText}</div>
291
+ ) : !visibleOptions.length ? (
292
+ <div className="sia-select__status">{emptyText}</div>
293
+ ) : (
294
+ visibleOptions.map((option, index) => (
295
+ <button
296
+ id={`${listboxId}-${index}`}
297
+ key={option.value}
298
+ type="button"
299
+ role="option"
300
+ aria-selected={currentValue === option.value}
301
+ disabled={option.disabled}
302
+ className={cn(
303
+ "sia-select__option",
304
+ index === activeIndex && "sia-select__option--active",
305
+ )}
306
+ onMouseEnter={() => setActiveIndex(index)}
307
+ onClick={() => choose(option)}
308
+ >
309
+ <span className="sia-select__option-content">
310
+ <span>{option.label}</span>
311
+ {option.description && <small>{option.description}</small>}
312
+ </span>
313
+ {currentValue === option.value && <CheckIcon aria-hidden="true" />}
314
+ </button>
315
+ ))
316
+ )}
317
+ </div>
318
+ </div>
319
+ </Overlay>
320
+ </div>
321
+ );
322
+ });
323
+
324
+ Select.displayName = "Select";