@spark-ui/components 11.1.0 → 11.1.2

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 (146) hide show
  1. package/dist/DialogTrigger-woU7vsJi.d.ts +142 -0
  2. package/dist/Input-N8AWWSmt.d.ts +41 -0
  3. package/dist/InputTrailingIcon-ZZx8PoJy.d.ts +20 -0
  4. package/dist/LabelRequiredIndicator-DRnCzHMU.d.ts +19 -0
  5. package/dist/accordion/index.d.ts +73 -0
  6. package/dist/accordion/index.js +325 -0
  7. package/dist/accordion/index.js.map +1 -0
  8. package/dist/alert-dialog/index.d.ts +119 -0
  9. package/dist/alert-dialog/index.js +1554 -0
  10. package/dist/alert-dialog/index.js.map +1 -0
  11. package/dist/avatar/index.d.ts +66 -0
  12. package/dist/avatar/index.js +1303 -0
  13. package/dist/avatar/index.js.map +1 -0
  14. package/dist/badge/index.d.ts +47 -0
  15. package/dist/badge/index.js +122 -0
  16. package/dist/badge/index.js.map +1 -0
  17. package/dist/breadcrumb/index.d.ts +64 -0
  18. package/dist/breadcrumb/index.js +327 -0
  19. package/dist/breadcrumb/index.js.map +1 -0
  20. package/dist/button/index.d.ts +41 -0
  21. package/dist/button/index.js +935 -0
  22. package/dist/button/index.js.map +1 -0
  23. package/dist/card/index.d.ts +61 -0
  24. package/dist/card/index.js +502 -0
  25. package/dist/card/index.js.map +1 -0
  26. package/dist/carousel/index.d.ts +261 -0
  27. package/dist/carousel/index.js +1801 -0
  28. package/dist/carousel/index.js.map +1 -0
  29. package/dist/checkbox/index.d.ts +120 -0
  30. package/dist/checkbox/index.js +511 -0
  31. package/dist/checkbox/index.js.map +1 -0
  32. package/dist/chip/index.d.ts +97 -0
  33. package/dist/chip/index.js +908 -0
  34. package/dist/chip/index.js.map +1 -0
  35. package/dist/collapsible/index.d.ts +43 -0
  36. package/dist/collapsible/index.js +109 -0
  37. package/dist/collapsible/index.js.map +1 -0
  38. package/dist/combobox/index.d.ts +287 -0
  39. package/dist/combobox/index.js +2588 -0
  40. package/dist/combobox/index.js.map +1 -0
  41. package/dist/dialog/index.d.ts +33 -0
  42. package/dist/dialog/index.js +1389 -0
  43. package/dist/dialog/index.js.map +1 -0
  44. package/dist/divider/index.d.ts +61 -0
  45. package/dist/divider/index.js +224 -0
  46. package/dist/divider/index.js.map +1 -0
  47. package/dist/drawer/index.d.ts +152 -0
  48. package/dist/drawer/index.js +1400 -0
  49. package/dist/drawer/index.js.map +1 -0
  50. package/dist/dropdown/index.d.ts +233 -0
  51. package/dist/dropdown/index.js +2051 -0
  52. package/dist/dropdown/index.js.map +1 -0
  53. package/dist/form-field/index.d.ts +186 -0
  54. package/dist/form-field/index.js +553 -0
  55. package/dist/form-field/index.js.map +1 -0
  56. package/dist/icon/index.d.ts +28 -0
  57. package/dist/icon/index.js +127 -0
  58. package/dist/icon/index.js.map +1 -0
  59. package/dist/icon-button/index.d.ts +16 -0
  60. package/dist/icon-button/index.js +980 -0
  61. package/dist/icon-button/index.js.map +1 -0
  62. package/dist/input/index.d.ts +78 -0
  63. package/dist/input/index.js +724 -0
  64. package/dist/input/index.js.map +1 -0
  65. package/dist/kbd/index.d.ts +9 -0
  66. package/dist/kbd/index.js +47 -0
  67. package/dist/kbd/index.js.map +1 -0
  68. package/dist/label/index.d.ts +11 -0
  69. package/dist/label/index.js +78 -0
  70. package/dist/label/index.js.map +1 -0
  71. package/dist/link-box/index.d.ts +34 -0
  72. package/dist/link-box/index.js +92 -0
  73. package/dist/link-box/index.js.map +1 -0
  74. package/dist/pagination/index.d.ts +143 -0
  75. package/dist/pagination/index.js +1353 -0
  76. package/dist/pagination/index.js.map +1 -0
  77. package/dist/popover/index.d.ts +93 -0
  78. package/dist/popover/index.js +1339 -0
  79. package/dist/popover/index.js.map +1 -0
  80. package/dist/portal/index.d.ts +13 -0
  81. package/dist/portal/index.js +37 -0
  82. package/dist/portal/index.js.map +1 -0
  83. package/dist/progress/index.d.ts +48 -0
  84. package/dist/progress/index.js +223 -0
  85. package/dist/progress/index.js.map +1 -0
  86. package/dist/progress-tracker/index.d.ts +80 -0
  87. package/dist/progress-tracker/index.js +571 -0
  88. package/dist/progress-tracker/index.js.map +1 -0
  89. package/dist/radio-group/index.d.ts +100 -0
  90. package/dist/radio-group/index.js +318 -0
  91. package/dist/radio-group/index.js.map +1 -0
  92. package/dist/rating/index.d.ts +78 -0
  93. package/dist/rating/index.js +363 -0
  94. package/dist/rating/index.js.map +1 -0
  95. package/dist/scrolling-list/index.d.ts +118 -0
  96. package/dist/scrolling-list/index.js +1426 -0
  97. package/dist/scrolling-list/index.js.map +1 -0
  98. package/dist/segmented-gauge/index.d.ts +100 -0
  99. package/dist/segmented-gauge/index.js +277 -0
  100. package/dist/segmented-gauge/index.js.map +1 -0
  101. package/dist/select/index.d.ts +167 -0
  102. package/dist/select/index.js +581 -0
  103. package/dist/select/index.js.map +1 -0
  104. package/dist/skeleton/index.d.ts +67 -0
  105. package/dist/skeleton/index.js +206 -0
  106. package/dist/skeleton/index.js.map +1 -0
  107. package/dist/slider/index.d.ts +97 -0
  108. package/dist/slider/index.js +220 -0
  109. package/dist/slider/index.js.map +1 -0
  110. package/dist/slot/index.d.ts +16 -0
  111. package/dist/slot/index.js +51 -0
  112. package/dist/slot/index.js.map +1 -0
  113. package/dist/snackbar/index.d.ts +158 -0
  114. package/dist/snackbar/index.js +1756 -0
  115. package/dist/snackbar/index.js.map +1 -0
  116. package/dist/spinner/index.d.mts +1 -1
  117. package/dist/spinner/index.d.ts +21 -0
  118. package/dist/spinner/index.js +139 -0
  119. package/dist/spinner/index.js.map +1 -0
  120. package/dist/stepper/index.d.ts +81 -0
  121. package/dist/stepper/index.js +1847 -0
  122. package/dist/stepper/index.js.map +1 -0
  123. package/dist/switch/index.d.ts +64 -0
  124. package/dist/switch/index.js +327 -0
  125. package/dist/switch/index.js.map +1 -0
  126. package/dist/tabs/index.d.ts +103 -0
  127. package/dist/tabs/index.js +1376 -0
  128. package/dist/tabs/index.js.map +1 -0
  129. package/dist/tag/index.d.ts +29 -0
  130. package/dist/tag/index.js +283 -0
  131. package/dist/tag/index.js.map +1 -0
  132. package/dist/text-link/index.d.ts +20 -0
  133. package/dist/text-link/index.js +100 -0
  134. package/dist/text-link/index.js.map +1 -0
  135. package/dist/textarea/index.d.ts +57 -0
  136. package/dist/textarea/index.js +797 -0
  137. package/dist/textarea/index.js.map +1 -0
  138. package/dist/toast/index.d.ts +56 -0
  139. package/dist/toast/index.js +1412 -0
  140. package/dist/toast/index.js.map +1 -0
  141. package/dist/toast/index.mjs +1 -1
  142. package/dist/toast/index.mjs.map +1 -1
  143. package/dist/visually-hidden/index.d.ts +16 -0
  144. package/dist/visually-hidden/index.js +67 -0
  145. package/dist/visually-hidden/index.js.map +1 -0
  146. package/package.json +5 -5
@@ -0,0 +1,2588 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/combobox/index.ts
21
+ var combobox_exports = {};
22
+ __export(combobox_exports, {
23
+ Combobox: () => Combobox2,
24
+ ComboboxProvider: () => ComboboxProvider,
25
+ useComboboxContext: () => useComboboxContext
26
+ });
27
+ module.exports = __toCommonJS(combobox_exports);
28
+
29
+ // src/combobox/ComboboxContext.tsx
30
+ var import_form_field = require("@spark-ui/components/form-field");
31
+ var import_use_combined_state = require("@spark-ui/hooks/use-combined-state");
32
+ var import_downshift3 = require("downshift");
33
+ var import_react7 = require("react");
34
+
35
+ // src/popover/Popover.tsx
36
+ var import_radix_ui = require("radix-ui");
37
+
38
+ // src/popover/PopoverContext.tsx
39
+ var import_react = require("react");
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ var PopoverContext = (0, import_react.createContext)(null);
42
+ var ID_PREFIX = ":popover";
43
+ var PopoverProvider = ({
44
+ children,
45
+ intent
46
+ }) => {
47
+ const [headerId, setHeaderId] = (0, import_react.useState)(null);
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
+ PopoverContext.Provider,
50
+ {
51
+ value: {
52
+ headerId,
53
+ setHeaderId,
54
+ intent
55
+ },
56
+ children
57
+ }
58
+ );
59
+ };
60
+ var usePopover = () => {
61
+ const context = (0, import_react.useContext)(PopoverContext);
62
+ if (!context) {
63
+ throw Error("usePopover must be used within a Popover provider");
64
+ }
65
+ return context;
66
+ };
67
+
68
+ // src/popover/Popover.tsx
69
+ var import_jsx_runtime2 = require("react/jsx-runtime");
70
+ var Popover = ({ children, intent = "surface", modal = false, ...rest }) => {
71
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PopoverProvider, { intent, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_radix_ui.Popover.Root, { "data-spark-component": "popover", modal, ...rest, children }) });
72
+ };
73
+ Popover.displayName = "Popover";
74
+
75
+ // src/popover/PopoverAnchor.tsx
76
+ var import_radix_ui2 = require("radix-ui");
77
+ var import_jsx_runtime3 = require("react/jsx-runtime");
78
+ var Anchor = ({ asChild = false, children, ref, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_radix_ui2.Popover.Anchor, { "data-spark-component": "popover-anchor", ref, asChild, ...rest, children });
79
+ Anchor.displayName = "Popover.Anchor";
80
+
81
+ // src/popover/PopoverArrow.tsx
82
+ var import_class_variance_authority = require("class-variance-authority");
83
+ var import_radix_ui3 = require("radix-ui");
84
+ var import_jsx_runtime4 = require("react/jsx-runtime");
85
+ var Arrow = ({
86
+ asChild = false,
87
+ width = 16,
88
+ height = 8,
89
+ className,
90
+ ref,
91
+ ...rest
92
+ }) => {
93
+ const { intent } = usePopover();
94
+ const styles4 = (0, import_class_variance_authority.cva)("visible", {
95
+ variants: {
96
+ intent: {
97
+ surface: "fill-surface",
98
+ main: "fill-main-container",
99
+ support: "fill-support-container",
100
+ accent: "fill-accent-container",
101
+ basic: "fill-basic-container",
102
+ success: "fill-success-container",
103
+ alert: "fill-alert-container",
104
+ danger: "fill-error-container",
105
+ info: "fill-info-container",
106
+ neutral: "fill-neutral-container"
107
+ }
108
+ },
109
+ defaultVariants: {
110
+ intent: "surface"
111
+ }
112
+ });
113
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
114
+ import_radix_ui3.Popover.Arrow,
115
+ {
116
+ "data-spark-component": "popover-arrow",
117
+ ref,
118
+ className: styles4({ intent, className }),
119
+ asChild,
120
+ width,
121
+ height,
122
+ ...rest
123
+ }
124
+ );
125
+ };
126
+ Arrow.displayName = "Popover.Arrow";
127
+
128
+ // src/popover/PopoverCloseButton.tsx
129
+ var import_Close = require("@spark-ui/icons/Close");
130
+ var import_class_variance_authority7 = require("class-variance-authority");
131
+ var import_radix_ui5 = require("radix-ui");
132
+
133
+ // src/icon/Icon.tsx
134
+ var import_react3 = require("react");
135
+
136
+ // src/slot/Slot.tsx
137
+ var import_radix_ui4 = require("radix-ui");
138
+ var import_react2 = require("react");
139
+ var import_jsx_runtime5 = require("react/jsx-runtime");
140
+ var Slottable = import_radix_ui4.Slot.Slottable;
141
+ var Slot = ({ ref, ...props }) => {
142
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_radix_ui4.Slot.Root, { ref, ...props });
143
+ };
144
+ var wrapPolymorphicSlot = (asChild, children, callback) => {
145
+ if (!asChild) return callback(children);
146
+ return (0, import_react2.isValidElement)(children) ? (0, import_react2.cloneElement)(
147
+ children,
148
+ void 0,
149
+ callback(children.props.children)
150
+ ) : null;
151
+ };
152
+
153
+ // src/visually-hidden/VisuallyHidden.tsx
154
+ var import_jsx_runtime6 = require("react/jsx-runtime");
155
+ var VisuallyHidden = ({ asChild = false, ref, ...props }) => {
156
+ const Component = asChild ? Slot : "span";
157
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
158
+ Component,
159
+ {
160
+ ...props,
161
+ ref,
162
+ style: {
163
+ // See: https://github.com/twbs/bootstrap/blob/main/scss/mixins/_visually-hidden.scss
164
+ position: "absolute",
165
+ border: 0,
166
+ width: 1,
167
+ height: 1,
168
+ padding: 0,
169
+ margin: -1,
170
+ overflow: "hidden",
171
+ clip: "rect(0, 0, 0, 0)",
172
+ whiteSpace: "nowrap",
173
+ wordWrap: "normal",
174
+ ...props.style
175
+ }
176
+ }
177
+ );
178
+ };
179
+ VisuallyHidden.displayName = "VisuallyHidden";
180
+
181
+ // src/icon/Icon.styles.tsx
182
+ var import_internal_utils = require("@spark-ui/internal-utils");
183
+ var import_class_variance_authority2 = require("class-variance-authority");
184
+ var iconStyles = (0, import_class_variance_authority2.cva)(["fill-current shrink-0"], {
185
+ variants: {
186
+ /**
187
+ * Color scheme of the icon.
188
+ */
189
+ intent: (0, import_internal_utils.makeVariants)({
190
+ current: ["text-current"],
191
+ main: ["text-main"],
192
+ support: ["text-support"],
193
+ accent: ["text-accent"],
194
+ basic: ["text-basic"],
195
+ success: ["text-success"],
196
+ alert: ["text-alert"],
197
+ error: ["text-error"],
198
+ info: ["text-info"],
199
+ neutral: ["text-neutral"]
200
+ }),
201
+ /**
202
+ * Sets the size of the icon.
203
+ */
204
+ size: (0, import_internal_utils.makeVariants)({
205
+ current: ["u-current-font-size"],
206
+ sm: ["w-sz-16", "h-sz-16"],
207
+ md: ["w-sz-24", "h-sz-24"],
208
+ lg: ["w-sz-32", "h-sz-32"],
209
+ xl: ["w-sz-40", "h-sz-40"]
210
+ })
211
+ }
212
+ });
213
+
214
+ // src/icon/Icon.tsx
215
+ var import_jsx_runtime7 = require("react/jsx-runtime");
216
+ var Icon = ({
217
+ label,
218
+ className,
219
+ size = "current",
220
+ intent = "current",
221
+ children,
222
+ ...others
223
+ }) => {
224
+ const child = import_react3.Children.only(children);
225
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
226
+ (0, import_react3.cloneElement)(child, {
227
+ className: iconStyles({ className, size, intent }),
228
+ "data-spark-component": "icon",
229
+ "aria-hidden": "true",
230
+ focusable: "false",
231
+ ...others
232
+ }),
233
+ label && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(VisuallyHidden, { children: label })
234
+ ] });
235
+ };
236
+ Icon.displayName = "Icon";
237
+
238
+ // src/button/Button.tsx
239
+ var import_class_variance_authority5 = require("class-variance-authority");
240
+ var import_react4 = require("react");
241
+
242
+ // src/spinner/Spinner.styles.tsx
243
+ var import_internal_utils2 = require("@spark-ui/internal-utils");
244
+ var import_class_variance_authority3 = require("class-variance-authority");
245
+ var defaultVariants = {
246
+ intent: "current",
247
+ size: "current",
248
+ isBackgroundVisible: false
249
+ };
250
+ var spinnerStyles = (0, import_class_variance_authority3.cva)(
251
+ ["inline-block", "border-solid", "rounded-full", "border-md", "animate-spin"],
252
+ {
253
+ variants: {
254
+ /**
255
+ * Use `size` prop to set the size of the spinner. If you want to set the full size for the spinner, don't forget to add a wrapping container with its own size.
256
+ */
257
+ size: {
258
+ current: ["u-current-font-size"],
259
+ sm: ["w-sz-20", "h-sz-20"],
260
+ md: ["w-sz-28", "h-sz-28"],
261
+ full: ["w-full", "h-full"]
262
+ },
263
+ /**
264
+ * Color scheme of the spinner.
265
+ */
266
+ intent: (0, import_internal_utils2.makeVariants)({
267
+ current: ["border-current"],
268
+ main: ["border-main"],
269
+ support: ["border-support"],
270
+ accent: ["border-accent"],
271
+ basic: ["border-basic"],
272
+ success: ["border-success"],
273
+ alert: ["border-alert"],
274
+ error: ["border-error"],
275
+ info: ["border-info"],
276
+ neutral: ["border-neutral"]
277
+ }),
278
+ /**
279
+ * Size of the button.
280
+ */
281
+ isBackgroundVisible: {
282
+ true: ["border-b-neutral-container", "border-l-neutral-container"],
283
+ false: ["border-b-transparent", "border-l-transparent"]
284
+ }
285
+ },
286
+ defaultVariants
287
+ }
288
+ );
289
+
290
+ // src/spinner/Spinner.tsx
291
+ var import_jsx_runtime8 = require("react/jsx-runtime");
292
+ var Spinner = ({
293
+ className,
294
+ size = "current",
295
+ intent = "current",
296
+ label,
297
+ isBackgroundVisible,
298
+ ref,
299
+ ...others
300
+ }) => {
301
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
302
+ "span",
303
+ {
304
+ role: "status",
305
+ "data-spark-component": "spinner",
306
+ ref,
307
+ className: spinnerStyles({ className, size, intent, isBackgroundVisible }),
308
+ ...others,
309
+ children: label && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(VisuallyHidden, { children: label })
310
+ }
311
+ );
312
+ };
313
+
314
+ // src/button/Button.styles.tsx
315
+ var import_internal_utils8 = require("@spark-ui/internal-utils");
316
+ var import_class_variance_authority4 = require("class-variance-authority");
317
+
318
+ // src/button/variants/filled.ts
319
+ var import_internal_utils3 = require("@spark-ui/internal-utils");
320
+ var filledVariants = [
321
+ // Main
322
+ {
323
+ intent: "main",
324
+ design: "filled",
325
+ class: (0, import_internal_utils3.tw)([
326
+ "bg-main",
327
+ "text-on-main",
328
+ "hover:bg-main-hovered",
329
+ "enabled:active:bg-main-hovered",
330
+ "focus-visible:bg-main-hovered"
331
+ ])
332
+ },
333
+ // Support
334
+ {
335
+ intent: "support",
336
+ design: "filled",
337
+ class: (0, import_internal_utils3.tw)([
338
+ "bg-support",
339
+ "text-on-support",
340
+ "hover:bg-support-hovered",
341
+ "enabled:active:bg-support-hovered",
342
+ "focus-visible:bg-support-hovered"
343
+ ])
344
+ },
345
+ // Accent
346
+ {
347
+ intent: "accent",
348
+ design: "filled",
349
+ class: (0, import_internal_utils3.tw)([
350
+ "bg-accent",
351
+ "text-on-accent",
352
+ "hover:bg-accent-hovered",
353
+ "enabled:active:bg-accent-hovered",
354
+ "focus-visible:bg-accent-hovered"
355
+ ])
356
+ },
357
+ // Basic
358
+ {
359
+ intent: "basic",
360
+ design: "filled",
361
+ class: (0, import_internal_utils3.tw)([
362
+ "bg-basic",
363
+ "text-on-basic",
364
+ "hover:bg-basic-hovered",
365
+ "enabled:active:bg-basic-hovered",
366
+ "focus-visible:bg-basic-hovered"
367
+ ])
368
+ },
369
+ // Success
370
+ {
371
+ intent: "success",
372
+ design: "filled",
373
+ class: (0, import_internal_utils3.tw)([
374
+ "bg-success",
375
+ "text-on-success",
376
+ "hover:bg-success-hovered",
377
+ "enabled:active:bg-success-hovered",
378
+ "focus-visible:bg-success-hovered"
379
+ ])
380
+ },
381
+ // Alert
382
+ {
383
+ intent: "alert",
384
+ design: "filled",
385
+ class: (0, import_internal_utils3.tw)([
386
+ "bg-alert",
387
+ "text-on-alert",
388
+ "hover:bg-alert-hovered",
389
+ "enabled:active:bg-alert-hovered",
390
+ "focus-visible:bg-alert-hovered"
391
+ ])
392
+ },
393
+ // Danger
394
+ {
395
+ intent: "danger",
396
+ design: "filled",
397
+ class: (0, import_internal_utils3.tw)([
398
+ "text-on-error bg-error",
399
+ "hover:bg-error-hovered enabled:active:bg-error-hovered",
400
+ "focus-visible:bg-error-hovered"
401
+ ])
402
+ },
403
+ // Info
404
+ {
405
+ intent: "info",
406
+ design: "filled",
407
+ class: (0, import_internal_utils3.tw)([
408
+ "text-on-error bg-info",
409
+ "hover:bg-info-hovered enabled:active:bg-info-hovered",
410
+ "focus-visible:bg-info-hovered"
411
+ ])
412
+ },
413
+ // Neutral
414
+ {
415
+ intent: "neutral",
416
+ design: "filled",
417
+ class: (0, import_internal_utils3.tw)([
418
+ "bg-neutral",
419
+ "text-on-neutral",
420
+ "hover:bg-neutral-hovered",
421
+ "enabled:active:bg-neutral-hovered",
422
+ "focus-visible:bg-neutral-hovered"
423
+ ])
424
+ },
425
+ // Surface
426
+ {
427
+ intent: "surface",
428
+ design: "filled",
429
+ class: (0, import_internal_utils3.tw)([
430
+ "bg-surface",
431
+ "text-on-surface",
432
+ "hover:bg-surface-hovered",
433
+ "enabled:active:bg-surface-hovered",
434
+ "focus-visible:bg-surface-hovered"
435
+ ])
436
+ },
437
+ {
438
+ intent: "surfaceInverse",
439
+ design: "filled",
440
+ class: (0, import_internal_utils3.tw)([
441
+ "bg-surface-inverse",
442
+ "text-on-surface-inverse",
443
+ "hover:bg-surface-inverse-hovered",
444
+ "enabled:active:bg-surface-inverse-hovered",
445
+ "focus-visible:bg-surface-inverse-hovered"
446
+ ])
447
+ }
448
+ ];
449
+
450
+ // src/button/variants/ghost.ts
451
+ var import_internal_utils4 = require("@spark-ui/internal-utils");
452
+ var ghostVariants = [
453
+ {
454
+ intent: "main",
455
+ design: "ghost",
456
+ class: (0, import_internal_utils4.tw)([
457
+ "text-on-main-container",
458
+ "hover:bg-main/dim-5",
459
+ "enabled:active:bg-main/dim-5",
460
+ "focus-visible:bg-main/dim-5"
461
+ ])
462
+ },
463
+ {
464
+ intent: "support",
465
+ design: "ghost",
466
+ class: (0, import_internal_utils4.tw)([
467
+ "text-on-support-container",
468
+ "hover:bg-support/dim-5",
469
+ "enabled:active:bg-support/dim-5",
470
+ "focus-visible:bg-support/dim-5"
471
+ ])
472
+ },
473
+ {
474
+ intent: "accent",
475
+ design: "ghost",
476
+ class: (0, import_internal_utils4.tw)([
477
+ "text-on-accent-container",
478
+ "hover:bg-accent/dim-5",
479
+ "enabled:active:bg-accent/dim-5",
480
+ "focus-visible:bg-accent/dim-5"
481
+ ])
482
+ },
483
+ {
484
+ intent: "basic",
485
+ design: "ghost",
486
+ class: (0, import_internal_utils4.tw)([
487
+ "text-on-basic-container",
488
+ "hover:bg-basic/dim-5",
489
+ "enabled:active:bg-basic/dim-5",
490
+ "focus-visible:bg-basic/dim-5"
491
+ ])
492
+ },
493
+ {
494
+ intent: "success",
495
+ design: "ghost",
496
+ class: (0, import_internal_utils4.tw)([
497
+ "text-on-success-container",
498
+ "hover:bg-success/dim-5",
499
+ "enabled:active:bg-success/dim-5",
500
+ "focus-visible:bg-success/dim-5"
501
+ ])
502
+ },
503
+ {
504
+ intent: "alert",
505
+ design: "ghost",
506
+ class: (0, import_internal_utils4.tw)([
507
+ "text-on-alert-container",
508
+ "hover:bg-alert/dim-5",
509
+ "enabled:active:bg-alert/dim-5",
510
+ "focus-visible:bg-alert/dim-5"
511
+ ])
512
+ },
513
+ {
514
+ intent: "danger",
515
+ design: "ghost",
516
+ class: (0, import_internal_utils4.tw)([
517
+ "text-on-error-container",
518
+ "hover:bg-error/dim-5",
519
+ "enabled:active:bg-error/dim-5",
520
+ "focus-visible:bg-error/dim-5"
521
+ ])
522
+ },
523
+ {
524
+ intent: "info",
525
+ design: "ghost",
526
+ class: (0, import_internal_utils4.tw)([
527
+ "text-on-info-container",
528
+ "hover:bg-info/dim-5",
529
+ "enabled:active:bg-info/dim-5",
530
+ "focus-visible:bg-info/dim-5"
531
+ ])
532
+ },
533
+ {
534
+ intent: "neutral",
535
+ design: "ghost",
536
+ class: (0, import_internal_utils4.tw)([
537
+ "text-on-neutral-container",
538
+ "hover:bg-neutral/dim-5",
539
+ "enabled:active:bg-neutral/dim-5",
540
+ "focus-visible:bg-neutral/dim-5"
541
+ ])
542
+ },
543
+ {
544
+ intent: "surface",
545
+ design: "ghost",
546
+ class: (0, import_internal_utils4.tw)([
547
+ "text-surface",
548
+ "hover:bg-surface/dim-5",
549
+ "enabled:active:bg-surface/dim-5",
550
+ "focus-visible:bg-surface/dim-5"
551
+ ])
552
+ },
553
+ {
554
+ intent: "surfaceInverse",
555
+ design: "ghost",
556
+ class: (0, import_internal_utils4.tw)([
557
+ "text-surface-inverse",
558
+ "hover:bg-surface-inverse/dim-5",
559
+ "enabled:active:bg-surface-inverse/dim-5",
560
+ "focus-visible:bg-surface-inverse/dim-5"
561
+ ])
562
+ }
563
+ ];
564
+
565
+ // src/button/variants/outlined.ts
566
+ var import_internal_utils5 = require("@spark-ui/internal-utils");
567
+ var outlinedVariants = [
568
+ {
569
+ intent: "main",
570
+ design: "outlined",
571
+ class: (0, import_internal_utils5.tw)([
572
+ "hover:bg-main/dim-5",
573
+ "enabled:active:bg-main/dim-5",
574
+ "focus-visible:bg-main/dim-5",
575
+ "text-main"
576
+ ])
577
+ },
578
+ {
579
+ intent: "support",
580
+ design: "outlined",
581
+ class: (0, import_internal_utils5.tw)([
582
+ "hover:bg-support/dim-5",
583
+ "enabled:active:bg-support/dim-5",
584
+ "focus-visible:bg-support/dim-5",
585
+ "text-support"
586
+ ])
587
+ },
588
+ {
589
+ intent: "accent",
590
+ design: "outlined",
591
+ class: (0, import_internal_utils5.tw)([
592
+ "hover:bg-accent/dim-5",
593
+ "enabled:active:bg-accent/dim-5",
594
+ "focus-visible:bg-accent/dim-5",
595
+ "text-accent"
596
+ ])
597
+ },
598
+ {
599
+ intent: "basic",
600
+ design: "outlined",
601
+ class: (0, import_internal_utils5.tw)([
602
+ "hover:bg-basic/dim-5",
603
+ "enabled:active:bg-basic/dim-5",
604
+ "focus-visible:bg-basic/dim-5",
605
+ "text-basic"
606
+ ])
607
+ },
608
+ {
609
+ intent: "success",
610
+ design: "outlined",
611
+ class: (0, import_internal_utils5.tw)([
612
+ "hover:bg-success/dim-5",
613
+ "enabled:active:bg-success/dim-5",
614
+ "focus-visible:bg-success/dim-5",
615
+ "text-success"
616
+ ])
617
+ },
618
+ {
619
+ intent: "alert",
620
+ design: "outlined",
621
+ class: (0, import_internal_utils5.tw)([
622
+ "hover:bg-alert/dim-5",
623
+ "enabled:active:bg-alert/dim-5",
624
+ "focus-visible:bg-alert/dim-5",
625
+ "text-alert"
626
+ ])
627
+ },
628
+ {
629
+ intent: "danger",
630
+ design: "outlined",
631
+ class: (0, import_internal_utils5.tw)([
632
+ "hover:bg-error/dim-5",
633
+ "enabled:active:bg-error/dim-5",
634
+ "focus-visible:bg-error/dim-5",
635
+ "text-error"
636
+ ])
637
+ },
638
+ {
639
+ intent: "info",
640
+ design: "outlined",
641
+ class: (0, import_internal_utils5.tw)([
642
+ "hover:bg-info/dim-5",
643
+ "enabled:active:bg-info/dim-5",
644
+ "focus-visible:bg-info/dim-5",
645
+ "text-info"
646
+ ])
647
+ },
648
+ {
649
+ intent: "neutral",
650
+ design: "outlined",
651
+ class: (0, import_internal_utils5.tw)([
652
+ "hover:bg-neutral/dim-5",
653
+ "enabled:active:bg-neutral/dim-5",
654
+ "focus-visible:bg-neutral/dim-5",
655
+ "text-neutral"
656
+ ])
657
+ },
658
+ {
659
+ intent: "surface",
660
+ design: "outlined",
661
+ class: (0, import_internal_utils5.tw)([
662
+ "hover:bg-surface/dim-5",
663
+ "enabled:active:bg-surface/dim-5",
664
+ "focus-visible:bg-surface/dim-5",
665
+ "text-surface"
666
+ ])
667
+ },
668
+ {
669
+ intent: "surfaceInverse",
670
+ design: "outlined",
671
+ class: (0, import_internal_utils5.tw)([
672
+ "hover:bg-surface-inverse/dim-5",
673
+ "enabled:active:bg-surface-inverse/dim-5",
674
+ "focus-visible:bg-surface-inverse/dim-5",
675
+ "text-surface-inverse"
676
+ ])
677
+ }
678
+ ];
679
+
680
+ // src/button/variants/tinted.ts
681
+ var import_internal_utils6 = require("@spark-ui/internal-utils");
682
+ var tintedVariants = [
683
+ {
684
+ intent: "main",
685
+ design: "tinted",
686
+ class: (0, import_internal_utils6.tw)([
687
+ "bg-main-container",
688
+ "text-on-main-container",
689
+ "hover:bg-main-container-hovered",
690
+ "enabled:active:bg-main-container-hovered",
691
+ "focus-visible:bg-main-container-hovered"
692
+ ])
693
+ },
694
+ {
695
+ intent: "support",
696
+ design: "tinted",
697
+ class: (0, import_internal_utils6.tw)([
698
+ "bg-support-container",
699
+ "text-on-support-container",
700
+ "hover:bg-support-container-hovered",
701
+ "enabled:active:bg-support-container-hovered",
702
+ "focus-visible:bg-support-container-hovered"
703
+ ])
704
+ },
705
+ {
706
+ intent: "accent",
707
+ design: "tinted",
708
+ class: (0, import_internal_utils6.tw)([
709
+ "bg-accent-container",
710
+ "text-on-accent-container",
711
+ "hover:bg-accent-container-hovered",
712
+ "enabled:active:bg-accent-container-hovered",
713
+ "focus-visible:bg-accent-container-hovered"
714
+ ])
715
+ },
716
+ {
717
+ intent: "basic",
718
+ design: "tinted",
719
+ class: (0, import_internal_utils6.tw)([
720
+ "bg-basic-container",
721
+ "text-on-basic-container",
722
+ "hover:bg-basic-container-hovered",
723
+ "enabled:active:bg-basic-container-hovered",
724
+ "focus-visible:bg-basic-container-hovered"
725
+ ])
726
+ },
727
+ {
728
+ intent: "success",
729
+ design: "tinted",
730
+ class: (0, import_internal_utils6.tw)([
731
+ "bg-success-container",
732
+ "text-on-success-container",
733
+ "hover:bg-success-container-hovered",
734
+ "enabled:active:bg-success-container-hovered",
735
+ "focus-visible:bg-success-container-hovered"
736
+ ])
737
+ },
738
+ {
739
+ intent: "alert",
740
+ design: "tinted",
741
+ class: (0, import_internal_utils6.tw)([
742
+ "bg-alert-container",
743
+ "text-on-alert-container",
744
+ "hover:bg-alert-container-hovered",
745
+ "enabled:active:bg-alert-container-hovered",
746
+ "focus-visible:bg-alert-container-hovered"
747
+ ])
748
+ },
749
+ {
750
+ intent: "danger",
751
+ design: "tinted",
752
+ class: (0, import_internal_utils6.tw)([
753
+ "bg-error-container",
754
+ "text-on-error-container",
755
+ "hover:bg-error-container-hovered",
756
+ "enabled:active:bg-error-container-hovered",
757
+ "focus-visible:bg-error-container-hovered"
758
+ ])
759
+ },
760
+ {
761
+ intent: "info",
762
+ design: "tinted",
763
+ class: (0, import_internal_utils6.tw)([
764
+ "bg-info-container",
765
+ "text-on-info-container",
766
+ "hover:bg-info-container-hovered",
767
+ "enabled:active:bg-info-container-hovered",
768
+ "focus-visible:bg-info-container-hovered"
769
+ ])
770
+ },
771
+ {
772
+ intent: "neutral",
773
+ design: "tinted",
774
+ class: (0, import_internal_utils6.tw)([
775
+ "bg-neutral-container",
776
+ "text-on-neutral-container",
777
+ "hover:bg-neutral-container-hovered",
778
+ "enabled:active:bg-neutral-container-hovered",
779
+ "focus-visible:bg-neutral-container-hovered"
780
+ ])
781
+ },
782
+ {
783
+ intent: "surface",
784
+ design: "tinted",
785
+ class: (0, import_internal_utils6.tw)([
786
+ "bg-surface",
787
+ "text-on-surface",
788
+ "hover:bg-surface-hovered",
789
+ "enabled:active:bg-surface-hovered",
790
+ "focus-visible:bg-surface-hovered"
791
+ ])
792
+ },
793
+ {
794
+ intent: "surfaceInverse",
795
+ design: "tinted",
796
+ class: (0, import_internal_utils6.tw)([
797
+ "bg-surface-inverse",
798
+ "text-on-surface-inverse",
799
+ "hover:bg-surface-inverse-hovered",
800
+ "enabled:active:bg-surface-inverse-hovered",
801
+ "focus-visible:bg-surface-inverse-hovered"
802
+ ])
803
+ }
804
+ ];
805
+
806
+ // src/button/variants/contrast.ts
807
+ var import_internal_utils7 = require("@spark-ui/internal-utils");
808
+ var contrastVariants = [
809
+ {
810
+ intent: "main",
811
+ design: "contrast",
812
+ class: (0, import_internal_utils7.tw)([
813
+ "text-on-main-contaier bg-surface",
814
+ "hover:bg-main-container-hovered",
815
+ "enabled:active:bg-main-container-hovered",
816
+ "focus-visible:bg-main-container-hovered"
817
+ ])
818
+ },
819
+ {
820
+ intent: "support",
821
+ design: "contrast",
822
+ class: (0, import_internal_utils7.tw)([
823
+ "text-on-support-container bg-surface",
824
+ "hover:bg-support-container-hovered",
825
+ "enabled:active:bg-support-container-hovered",
826
+ "focus-visible:bg-support-container-hovered"
827
+ ])
828
+ },
829
+ {
830
+ intent: "accent",
831
+ design: "contrast",
832
+ class: (0, import_internal_utils7.tw)([
833
+ "text-on-accent-container bg-surface",
834
+ "hover:bg-accent-container-hovered",
835
+ "enabled:active:bg-accent-container-hovered",
836
+ "focus-visible:bg-accent-container-hovered"
837
+ ])
838
+ },
839
+ {
840
+ intent: "basic",
841
+ design: "contrast",
842
+ class: (0, import_internal_utils7.tw)([
843
+ "text-on-basic-container bg-surface",
844
+ "hover:bg-basic-container-hovered",
845
+ "enabled:active:bg-basic-container-hovered",
846
+ "focus-visible:bg-basic-container-hovered"
847
+ ])
848
+ },
849
+ {
850
+ intent: "success",
851
+ design: "contrast",
852
+ class: (0, import_internal_utils7.tw)([
853
+ "text-on-success-container bg-surface",
854
+ "hover:bg-success-container-hovered",
855
+ "enabled:active:bg-success-container-hovered",
856
+ "focus-visible:bg-success-container-hovered"
857
+ ])
858
+ },
859
+ {
860
+ intent: "alert",
861
+ design: "contrast",
862
+ class: (0, import_internal_utils7.tw)([
863
+ "text-on-alert-container bg-surface",
864
+ "hover:bg-alert-container-hovered",
865
+ "enabled:active:bg-alert-container-hovered",
866
+ "focus-visible:bg-alert-container-hovered"
867
+ ])
868
+ },
869
+ {
870
+ intent: "danger",
871
+ design: "contrast",
872
+ class: (0, import_internal_utils7.tw)([
873
+ "text-on-error-container bg-surface",
874
+ "hover:bg-error-container-hovered",
875
+ "enabled:active:bg-error-container-hovered",
876
+ "focus-visible:bg-error-container-hovered"
877
+ ])
878
+ },
879
+ {
880
+ intent: "info",
881
+ design: "contrast",
882
+ class: (0, import_internal_utils7.tw)([
883
+ "text-on-info-container bg-surface",
884
+ "hover:bg-info-container-hovered",
885
+ "enabled:active:bg-info-container-hovered",
886
+ "focus-visible:bg-info-container-hovered"
887
+ ])
888
+ },
889
+ {
890
+ intent: "neutral",
891
+ design: "contrast",
892
+ class: (0, import_internal_utils7.tw)([
893
+ "text-on-neutral-container bg-surface",
894
+ "hover:bg-neutral-container-hovered",
895
+ "enabled:active:bg-neutral-container-hovered",
896
+ "focus-visible:bg-neutral-container-hovered"
897
+ ])
898
+ },
899
+ {
900
+ intent: "surface",
901
+ design: "contrast",
902
+ class: (0, import_internal_utils7.tw)([
903
+ "text-on-surface bg-surface",
904
+ "hover:bg-surface-hovered",
905
+ "enabled:active:bg-surface-hovered",
906
+ "focus-visible:bg-surface-hovered"
907
+ ])
908
+ },
909
+ {
910
+ intent: "surfaceInverse",
911
+ design: "contrast",
912
+ class: (0, import_internal_utils7.tw)([
913
+ "text-on-surface-inverse bg-surface-inverse",
914
+ "hover:bg-surface-inverse-hovered",
915
+ "enabled:active:bg-surface-inverse-hovered",
916
+ "focus-visible:bg-surface-inverse-hovered"
917
+ ])
918
+ }
919
+ ];
920
+
921
+ // src/button/Button.styles.tsx
922
+ var buttonStyles = (0, import_class_variance_authority4.cva)(
923
+ [
924
+ "u-shadow-border-transition",
925
+ "box-border inline-flex items-center justify-center gap-md whitespace-nowrap",
926
+ "default:px-lg",
927
+ "text-body-1 font-bold",
928
+ "focus-visible:u-outline"
929
+ ],
930
+ {
931
+ variants: {
932
+ /**
933
+ * Main style of the button.
934
+ *
935
+ * - `filled`: Button will be plain.
936
+ *
937
+ * - `outlined`: Button will be transparent with an outline.
938
+ *
939
+ * - `tinted`: Button will be filled but using a lighter color scheme.
940
+ *
941
+ * - `ghost`: Button will look like a link. No borders, plain text.
942
+ *
943
+ * - `contrast`: Button will be surface filled. No borders, plain text.
944
+ *
945
+ */
946
+ design: (0, import_internal_utils8.makeVariants)({
947
+ filled: [],
948
+ outlined: ["bg-transparent", "border-sm", "border-current"],
949
+ tinted: [],
950
+ ghost: ["default:-mx-md px-md hover:bg-main/dim-5"],
951
+ contrast: []
952
+ }),
953
+ underline: {
954
+ true: ["underline"]
955
+ },
956
+ /**
957
+ * Color scheme of the button.
958
+ */
959
+ intent: (0, import_internal_utils8.makeVariants)({
960
+ main: [],
961
+ support: [],
962
+ accent: [],
963
+ basic: [],
964
+ success: [],
965
+ alert: [],
966
+ danger: [],
967
+ info: [],
968
+ neutral: [],
969
+ surface: [],
970
+ surfaceInverse: []
971
+ }),
972
+ /**
973
+ * Size of the button.
974
+ */
975
+ size: (0, import_internal_utils8.makeVariants)({
976
+ sm: ["min-w-sz-32", "h-sz-32"],
977
+ md: ["min-w-sz-44", "h-sz-44"],
978
+ lg: ["min-w-sz-56", "h-sz-56"]
979
+ }),
980
+ /**
981
+ * Shape of the button.
982
+ */
983
+ shape: (0, import_internal_utils8.makeVariants)({
984
+ rounded: ["rounded-lg"],
985
+ square: ["rounded-0"],
986
+ pill: ["rounded-full"]
987
+ }),
988
+ /**
989
+ * Disable the button, preventing user interaction and adding opacity.
990
+ */
991
+ disabled: {
992
+ true: ["cursor-not-allowed", "opacity-dim-3"],
993
+ false: ["cursor-pointer"]
994
+ }
995
+ },
996
+ compoundVariants: [
997
+ ...filledVariants,
998
+ ...outlinedVariants,
999
+ ...tintedVariants,
1000
+ ...ghostVariants,
1001
+ ...contrastVariants
1002
+ ],
1003
+ defaultVariants: {
1004
+ design: "filled",
1005
+ intent: "main",
1006
+ size: "md",
1007
+ shape: "rounded"
1008
+ }
1009
+ }
1010
+ );
1011
+
1012
+ // src/button/Button.tsx
1013
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1014
+ var blockedEventHandlers = [
1015
+ "onClick",
1016
+ "onMouseDown",
1017
+ "onMouseUp",
1018
+ "onMouseEnter",
1019
+ "onMouseLeave",
1020
+ "onMouseOver",
1021
+ "onMouseOut",
1022
+ "onKeyDown",
1023
+ "onKeyPress",
1024
+ "onKeyUp",
1025
+ "onSubmit"
1026
+ ];
1027
+ var Button = ({
1028
+ children,
1029
+ design = "filled",
1030
+ disabled = false,
1031
+ intent = "main",
1032
+ isLoading = false,
1033
+ loadingLabel,
1034
+ loadingText,
1035
+ shape = "rounded",
1036
+ size = "md",
1037
+ asChild,
1038
+ className,
1039
+ underline = false,
1040
+ ref,
1041
+ ...others
1042
+ }) => {
1043
+ const Component = asChild ? Slot : "button";
1044
+ const shouldNotInteract = !!disabled || isLoading;
1045
+ const disabledEventHandlers = (0, import_react4.useMemo)(() => {
1046
+ const result = {};
1047
+ if (shouldNotInteract) {
1048
+ blockedEventHandlers.forEach((eventHandler) => result[eventHandler] = void 0);
1049
+ }
1050
+ return result;
1051
+ }, [shouldNotInteract]);
1052
+ const spinnerProps = {
1053
+ size: "current",
1054
+ className: loadingText ? "inline-block" : "absolute",
1055
+ ...loadingLabel && { "aria-label": loadingLabel }
1056
+ };
1057
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1058
+ Component,
1059
+ {
1060
+ "data-spark-component": "button",
1061
+ ...Component === "button" && { type: "button" },
1062
+ ref,
1063
+ className: buttonStyles({
1064
+ className,
1065
+ design,
1066
+ disabled: shouldNotInteract,
1067
+ intent,
1068
+ shape,
1069
+ size,
1070
+ underline
1071
+ }),
1072
+ disabled: !!disabled,
1073
+ "aria-busy": isLoading,
1074
+ "aria-live": isLoading ? "assertive" : "off",
1075
+ ...others,
1076
+ ...disabledEventHandlers,
1077
+ children: wrapPolymorphicSlot(
1078
+ asChild,
1079
+ children,
1080
+ (slotted) => isLoading ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1081
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Spinner, { ...spinnerProps }),
1082
+ loadingText && loadingText,
1083
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1084
+ "div",
1085
+ {
1086
+ "aria-hidden": true,
1087
+ className: (0, import_class_variance_authority5.cx)("gap-md", loadingText ? "hidden" : "inline-flex opacity-0"),
1088
+ children: slotted
1089
+ }
1090
+ )
1091
+ ] }) : slotted
1092
+ )
1093
+ }
1094
+ );
1095
+ };
1096
+ Button.displayName = "Button";
1097
+
1098
+ // src/icon-button/IconButton.styles.tsx
1099
+ var import_internal_utils9 = require("@spark-ui/internal-utils");
1100
+ var import_class_variance_authority6 = require("class-variance-authority");
1101
+ var iconButtonStyles = (0, import_class_variance_authority6.cva)(["pl-0 pr-0"], {
1102
+ variants: {
1103
+ /**
1104
+ * Sets the size of the icon.
1105
+ */
1106
+ size: (0, import_internal_utils9.makeVariants)({
1107
+ sm: ["text-body-1"],
1108
+ md: ["text-body-1"],
1109
+ lg: ["text-display-3"]
1110
+ })
1111
+ }
1112
+ });
1113
+
1114
+ // src/icon-button/IconButton.tsx
1115
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1116
+ var IconButton = ({
1117
+ design = "filled",
1118
+ disabled = false,
1119
+ intent = "main",
1120
+ shape = "rounded",
1121
+ size = "md",
1122
+ className,
1123
+ ref,
1124
+ ...others
1125
+ }) => {
1126
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1127
+ Button,
1128
+ {
1129
+ "data-spark-component": "icon-button",
1130
+ ref,
1131
+ className: iconButtonStyles({ size, className }),
1132
+ design,
1133
+ disabled,
1134
+ intent,
1135
+ shape,
1136
+ size,
1137
+ ...others
1138
+ }
1139
+ );
1140
+ };
1141
+ IconButton.displayName = "IconButton";
1142
+
1143
+ // src/popover/PopoverCloseButton.tsx
1144
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1145
+ var CloseButton = ({
1146
+ "aria-label": ariaLabel,
1147
+ className,
1148
+ ref,
1149
+ ...rest
1150
+ }) => {
1151
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1152
+ import_radix_ui5.Popover.Close,
1153
+ {
1154
+ "data-spark-component": "popover-close-button",
1155
+ ref,
1156
+ className: (0, import_class_variance_authority7.cx)("right-lg top-md absolute", className),
1157
+ asChild: true,
1158
+ ...rest,
1159
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconButton, { size: "sm", intent: "neutral", design: "ghost", "aria-label": ariaLabel, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Icon, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_Close.Close, {}) }) })
1160
+ }
1161
+ );
1162
+ };
1163
+ CloseButton.displayName = "Popover.CloseButton";
1164
+
1165
+ // src/popover/PopoverContent.tsx
1166
+ var import_radix_ui6 = require("radix-ui");
1167
+
1168
+ // src/popover/PopoverContent.styles.ts
1169
+ var import_class_variance_authority8 = require("class-variance-authority");
1170
+ var styles = (0, import_class_variance_authority8.cva)(
1171
+ [
1172
+ "rounded-md",
1173
+ "shadow-sm",
1174
+ "focus-visible:outline-hidden focus-visible:u-outline",
1175
+ "max-h-(--radix-popper-available-height) overflow-y-auto"
1176
+ ],
1177
+ {
1178
+ variants: {
1179
+ intent: {
1180
+ surface: "bg-surface text-on-surface",
1181
+ main: "bg-main-container text-on-main-container",
1182
+ support: "bg-support-container text-on-support-container",
1183
+ accent: "bg-accent-container text-on-accent-container",
1184
+ basic: "bg-basic-container text-on-basic-container",
1185
+ success: "bg-success-container text-on-success-container",
1186
+ alert: "bg-alert-container text-on-alert-container",
1187
+ danger: "bg-error-container text-on-error-container",
1188
+ info: "bg-info-container text-on-info-container",
1189
+ neutral: "bg-neutral-container text-on-neutral-container"
1190
+ },
1191
+ matchTriggerWidth: {
1192
+ true: "w-(--radix-popper-anchor-width)"
1193
+ },
1194
+ enforceBoundaries: {
1195
+ true: ["max-w-(--radix-popper-available-width)"]
1196
+ },
1197
+ inset: {
1198
+ true: "overflow-hidden",
1199
+ false: "p-lg"
1200
+ },
1201
+ elevation: {
1202
+ dropdown: "z-dropdown",
1203
+ popover: "z-popover"
1204
+ }
1205
+ },
1206
+ compoundVariants: [
1207
+ {
1208
+ inset: false,
1209
+ /**
1210
+ * When there is a close button, padding to the right side must be adjusted to avoid content overlapping with it.
1211
+ */
1212
+ class: "has-data-[spark-component=popover-close-button]:pr-3xl"
1213
+ },
1214
+ {
1215
+ enforceBoundaries: false,
1216
+ matchTriggerWidth: false,
1217
+ class: "max-w-[min(var(--spacing-sz-384),100vw)]"
1218
+ }
1219
+ ],
1220
+ defaultVariants: {
1221
+ matchTriggerWidth: false,
1222
+ enforceBoundaries: false,
1223
+ inset: false,
1224
+ intent: "surface",
1225
+ elevation: "popover"
1226
+ }
1227
+ }
1228
+ );
1229
+
1230
+ // src/popover/PopoverContent.tsx
1231
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1232
+ var Content = ({
1233
+ // Spark props
1234
+ className,
1235
+ children,
1236
+ matchTriggerWidth = false,
1237
+ // Radix props
1238
+ align = "center",
1239
+ arrowPadding = 16,
1240
+ // In order not to overlap the arrow on the rounded corners of the popover.
1241
+ asChild = false,
1242
+ avoidCollisions = true,
1243
+ "aria-labelledby": ariaLabelledBy,
1244
+ collisionBoundary,
1245
+ collisionPadding = 0,
1246
+ hideWhenDetached = false,
1247
+ side = "bottom",
1248
+ sideOffset = 8,
1249
+ sticky = "partial",
1250
+ inset = false,
1251
+ elevation = "popover",
1252
+ ref,
1253
+ ...rest
1254
+ }) => {
1255
+ const { headerId, intent } = usePopover();
1256
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1257
+ import_radix_ui6.Popover.Content,
1258
+ {
1259
+ "aria-labelledby": headerId || ariaLabelledBy,
1260
+ className: styles({
1261
+ enforceBoundaries: !!collisionBoundary,
1262
+ matchTriggerWidth,
1263
+ inset,
1264
+ elevation,
1265
+ intent,
1266
+ className
1267
+ }),
1268
+ "data-spark-component": "popover-content",
1269
+ ref,
1270
+ ...{
1271
+ align,
1272
+ arrowPadding,
1273
+ asChild,
1274
+ avoidCollisions,
1275
+ collisionBoundary,
1276
+ collisionPadding,
1277
+ hideWhenDetached,
1278
+ side,
1279
+ sideOffset,
1280
+ sticky
1281
+ },
1282
+ ...rest,
1283
+ children
1284
+ }
1285
+ );
1286
+ };
1287
+ Content.displayName = "Popover.Content";
1288
+
1289
+ // src/popover/PopoverHeader.tsx
1290
+ var import_class_variance_authority9 = require("class-variance-authority");
1291
+ var import_react5 = require("react");
1292
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1293
+ var Header = ({ children, className, ref, ...rest }) => {
1294
+ const id = `${ID_PREFIX}-header-${(0, import_react5.useId)()}`;
1295
+ const { setHeaderId } = usePopover();
1296
+ (0, import_react5.useLayoutEffect)(() => {
1297
+ setHeaderId(id);
1298
+ return () => setHeaderId(null);
1299
+ }, [id, setHeaderId]);
1300
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("header", { id, ref, className: (0, import_class_variance_authority9.cx)("mb-md text-headline-2", className), ...rest, children });
1301
+ };
1302
+ Header.displayName = "Popover.Header";
1303
+
1304
+ // src/popover/PopoverPortal.tsx
1305
+ var import_radix_ui7 = require("radix-ui");
1306
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1307
+ var Portal = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_radix_ui7.Popover.Portal, { ...rest, children });
1308
+ Portal.displayName = "Popover.Portal";
1309
+
1310
+ // src/popover/PopoverTrigger.tsx
1311
+ var import_radix_ui8 = require("radix-ui");
1312
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1313
+ var Trigger = ({ asChild = false, children, ref, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1314
+ import_radix_ui8.Popover.Trigger,
1315
+ {
1316
+ "data-spark-component": "popover-trigger",
1317
+ ref,
1318
+ asChild,
1319
+ ...rest,
1320
+ children
1321
+ }
1322
+ );
1323
+ Trigger.displayName = "Popover.Trigger";
1324
+
1325
+ // src/popover/index.ts
1326
+ var Popover2 = Object.assign(Popover, {
1327
+ Anchor,
1328
+ Arrow,
1329
+ CloseButton,
1330
+ Content,
1331
+ Header,
1332
+ Portal,
1333
+ Trigger
1334
+ });
1335
+ Popover2.displayName = "Popover";
1336
+ Anchor.displayName = "Popover.Anchor";
1337
+ Arrow.displayName = "Popover.Arrow";
1338
+ CloseButton.displayName = "Popover.CloseButton";
1339
+ Content.displayName = "Popover.Content";
1340
+ Header.displayName = "Popover.Header";
1341
+ Portal.displayName = "Popover.Portal";
1342
+ Trigger.displayName = "Popover.Trigger";
1343
+
1344
+ // src/combobox/useCombobox/multipleSelectionReducer.ts
1345
+ var import_downshift = require("downshift");
1346
+
1347
+ // src/combobox/utils/index.ts
1348
+ var import_react6 = require("react");
1349
+ function getIndexByKey(map, targetKey) {
1350
+ let index = 0;
1351
+ for (const [key] of map.entries()) {
1352
+ if (key === targetKey) {
1353
+ return index;
1354
+ }
1355
+ index++;
1356
+ }
1357
+ return -1;
1358
+ }
1359
+ var getKeyAtIndex = (map, index) => {
1360
+ let i = 0;
1361
+ for (const key of map.keys()) {
1362
+ if (i === index) return key;
1363
+ i++;
1364
+ }
1365
+ return void 0;
1366
+ };
1367
+ var getElementByIndex = (map, index) => {
1368
+ const key = getKeyAtIndex(map, index);
1369
+ return key !== void 0 ? map.get(key) : void 0;
1370
+ };
1371
+ var getElementDisplayName = (element) => {
1372
+ return element ? element.type.displayName : "";
1373
+ };
1374
+ var getOrderedItems = (children, result = []) => {
1375
+ import_react6.Children.forEach(children, (child) => {
1376
+ if (!(0, import_react6.isValidElement)(child)) return;
1377
+ if (getElementDisplayName(child) === "Combobox.Item") {
1378
+ const childProps = child.props;
1379
+ result.push({
1380
+ value: childProps.value,
1381
+ disabled: !!childProps.disabled,
1382
+ text: getItemText(childProps.children)
1383
+ });
1384
+ }
1385
+ if (child.props.children) {
1386
+ getOrderedItems(child.props.children, result);
1387
+ }
1388
+ });
1389
+ return result;
1390
+ };
1391
+ var findNestedItemText = (children) => {
1392
+ if (!children) return "";
1393
+ for (const child of import_react6.Children.toArray(children)) {
1394
+ if ((0, import_react6.isValidElement)(child)) {
1395
+ const childElement = child;
1396
+ if (getElementDisplayName(childElement) === "Combobox.ItemText") {
1397
+ return childElement.props.children;
1398
+ }
1399
+ const foundText = findNestedItemText(childElement.props.children);
1400
+ if (foundText) return foundText;
1401
+ }
1402
+ }
1403
+ return "";
1404
+ };
1405
+ var getItemText = (children) => {
1406
+ return typeof children === "string" ? children : findNestedItemText(children);
1407
+ };
1408
+ var getItemsFromChildren = (children) => {
1409
+ const newMap = /* @__PURE__ */ new Map();
1410
+ getOrderedItems(children).forEach((itemData) => {
1411
+ newMap.set(itemData.value, itemData);
1412
+ });
1413
+ return newMap;
1414
+ };
1415
+ var hasChildComponent = (children, displayName) => {
1416
+ return import_react6.Children.toArray(children).some((child) => {
1417
+ if (!(0, import_react6.isValidElement)(child)) return false;
1418
+ if (getElementDisplayName(child) === displayName) {
1419
+ return true;
1420
+ } else if (child.props.children) {
1421
+ return hasChildComponent(child.props.children, displayName);
1422
+ }
1423
+ return false;
1424
+ });
1425
+ };
1426
+ var findElement = (children, value) => {
1427
+ return import_react6.Children.toArray(children).filter(import_react6.isValidElement).find((child) => value === getElementDisplayName(child) || "");
1428
+ };
1429
+
1430
+ // src/combobox/useCombobox/multipleSelectionReducer.ts
1431
+ var multipleSelectionReducer = ({
1432
+ multiselect,
1433
+ selectedItems,
1434
+ allowCustomValue = false,
1435
+ setSelectedItems,
1436
+ triggerAreaRef,
1437
+ items
1438
+ }) => {
1439
+ const reducer = (_, { changes, type }) => {
1440
+ const isFocusInsideTriggerArea = triggerAreaRef.current?.contains?.(document.activeElement);
1441
+ switch (type) {
1442
+ case import_downshift.useCombobox.stateChangeTypes.InputClick:
1443
+ return {
1444
+ ...changes,
1445
+ isOpen: true
1446
+ // keep menu opened
1447
+ };
1448
+ case import_downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
1449
+ case import_downshift.useCombobox.stateChangeTypes.ItemClick: {
1450
+ const newState = { ...changes };
1451
+ if (changes.selectedItem != null) {
1452
+ newState.inputValue = "";
1453
+ newState.isOpen = true;
1454
+ const highlightedIndex = getIndexByKey(items, changes.selectedItem.value);
1455
+ newState.highlightedIndex = highlightedIndex;
1456
+ const isAlreadySelected = multiselect.selectedItems.some(
1457
+ (selectedItem) => selectedItem.value === changes.selectedItem?.value
1458
+ );
1459
+ const updatedItems = isAlreadySelected ? selectedItems.filter((item) => item.value !== changes.selectedItem?.value) : [...selectedItems, changes.selectedItem];
1460
+ setSelectedItems(updatedItems);
1461
+ }
1462
+ return newState;
1463
+ }
1464
+ case import_downshift.useCombobox.stateChangeTypes.ToggleButtonClick:
1465
+ return {
1466
+ ...changes,
1467
+ inputValue: allowCustomValue ? changes.inputValue : ""
1468
+ };
1469
+ case import_downshift.useCombobox.stateChangeTypes.InputChange:
1470
+ return {
1471
+ ...changes,
1472
+ selectedItem: changes.highlightedIndex === -1 ? null : changes.selectedItem
1473
+ };
1474
+ case import_downshift.useCombobox.stateChangeTypes.InputBlur:
1475
+ return {
1476
+ ...changes,
1477
+ inputValue: allowCustomValue ? changes.inputValue : "",
1478
+ isOpen: isFocusInsideTriggerArea
1479
+ };
1480
+ default:
1481
+ return changes;
1482
+ }
1483
+ };
1484
+ return reducer;
1485
+ };
1486
+
1487
+ // src/combobox/useCombobox/singleSelectionReducer.ts
1488
+ var import_downshift2 = require("downshift");
1489
+ var singleSelectionReducer = ({
1490
+ filteredItems,
1491
+ allowCustomValue = false,
1492
+ setSelectedItem
1493
+ }) => {
1494
+ const reducer = (state, { changes, type }) => {
1495
+ const exactMatch = filteredItems.find(
1496
+ (item) => item.text.toLowerCase() === state.inputValue.toLowerCase()
1497
+ );
1498
+ switch (type) {
1499
+ case import_downshift2.useCombobox.stateChangeTypes.InputKeyDownEscape:
1500
+ if (!changes.selectedItem) {
1501
+ setSelectedItem(null);
1502
+ }
1503
+ return changes;
1504
+ case import_downshift2.useCombobox.stateChangeTypes.ItemClick:
1505
+ case import_downshift2.useCombobox.stateChangeTypes.InputKeyDownEnter:
1506
+ if (changes.selectedItem) {
1507
+ setSelectedItem(changes.selectedItem);
1508
+ }
1509
+ return changes;
1510
+ case import_downshift2.useCombobox.stateChangeTypes.InputClick:
1511
+ return { ...changes, isOpen: true };
1512
+ case import_downshift2.useCombobox.stateChangeTypes.ToggleButtonClick:
1513
+ case import_downshift2.useCombobox.stateChangeTypes.InputBlur:
1514
+ if (allowCustomValue) return changes;
1515
+ if (state.inputValue === "") {
1516
+ setSelectedItem(null);
1517
+ return { ...changes, selectedItem: null };
1518
+ }
1519
+ if (exactMatch) {
1520
+ setSelectedItem(exactMatch);
1521
+ return { ...changes, selectedItem: exactMatch, inputValue: exactMatch.text };
1522
+ }
1523
+ if (state.selectedItem) {
1524
+ return { ...changes, inputValue: state.selectedItem.text };
1525
+ }
1526
+ return { ...changes, inputValue: "" };
1527
+ default:
1528
+ return changes;
1529
+ }
1530
+ };
1531
+ return reducer;
1532
+ };
1533
+
1534
+ // src/combobox/ComboboxContext.tsx
1535
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1536
+ var ComboboxContext = (0, import_react7.createContext)(null);
1537
+ var getFilteredItemsMap = (map, inputValue) => {
1538
+ if (!inputValue) return map;
1539
+ return new Map(
1540
+ Array.from(map).filter(([_, { text }]) => text.toLowerCase().includes(inputValue.toLowerCase()))
1541
+ );
1542
+ };
1543
+ var ID_PREFIX2 = ":combobox";
1544
+ var ComboboxProvider = ({
1545
+ children,
1546
+ state: stateProp,
1547
+ allowCustomValue = false,
1548
+ filtering = "auto",
1549
+ disabled: disabledProp = false,
1550
+ multiple = false,
1551
+ readOnly: readOnlyProp = false,
1552
+ wrap = true,
1553
+ // Value
1554
+ value: controlledValue,
1555
+ defaultValue,
1556
+ onValueChange,
1557
+ // Open
1558
+ open: controlledOpen,
1559
+ defaultOpen,
1560
+ onOpenChange,
1561
+ isLoading
1562
+ }) => {
1563
+ const isMounted = (0, import_react7.useRef)(false);
1564
+ const [inputValue, setInputValue] = (0, import_react7.useState)("");
1565
+ const [isTyping, setIsTyping] = (0, import_react7.useState)(filtering === "strict");
1566
+ const triggerAreaRef = (0, import_react7.useRef)(null);
1567
+ const innerInputRef = (0, import_react7.useRef)(null);
1568
+ const [onInputValueChange, setOnInputValueChange] = (0, import_react7.useState)(null);
1569
+ const [comboboxValue] = (0, import_use_combined_state.useCombinedState)(controlledValue, defaultValue);
1570
+ const shouldFilterItems = filtering === "strict" || filtering === "auto" && isTyping;
1571
+ const [itemsMap, setItemsMap] = (0, import_react7.useState)(getItemsFromChildren(children));
1572
+ const [filteredItemsMap, setFilteredItems] = (0, import_react7.useState)(
1573
+ shouldFilterItems ? getFilteredItemsMap(itemsMap, inputValue) : itemsMap
1574
+ );
1575
+ const [selectedItem, setSelectedItem] = (0, import_react7.useState)(
1576
+ itemsMap.get(comboboxValue) || null
1577
+ );
1578
+ const [selectedItems, setSelectedItems] = (0, import_react7.useState)(
1579
+ comboboxValue ? [...itemsMap.values()].filter((item) => comboboxValue.includes(item.value)) : []
1580
+ );
1581
+ const onInternalSelectedItemChange = (item) => {
1582
+ setIsTyping(false);
1583
+ if (item?.value !== selectedItem?.value) {
1584
+ setSelectedItem(item);
1585
+ setTimeout(() => {
1586
+ onValueChange?.(item?.value);
1587
+ }, 0);
1588
+ }
1589
+ };
1590
+ const onInternalSelectedItemsChange = (items) => {
1591
+ setSelectedItems(items);
1592
+ setTimeout(() => {
1593
+ onValueChange?.(items.map((i) => i.value));
1594
+ }, 0);
1595
+ };
1596
+ (0, import_react7.useEffect)(() => {
1597
+ if (!isMounted.current) {
1598
+ isMounted.current = true;
1599
+ return;
1600
+ }
1601
+ if (multiple) {
1602
+ const newSelectedItems = comboboxValue.reduce(
1603
+ (accum, value) => {
1604
+ const match = itemsMap.get(value);
1605
+ return match ? [...accum, match] : accum;
1606
+ },
1607
+ []
1608
+ );
1609
+ setSelectedItems(comboboxValue ? newSelectedItems : []);
1610
+ } else {
1611
+ setSelectedItem(itemsMap.get(comboboxValue) || null);
1612
+ }
1613
+ }, [multiple ? JSON.stringify(comboboxValue) : comboboxValue]);
1614
+ const field = (0, import_form_field.useFormFieldControl)();
1615
+ const internalFieldLabelID = `${ID_PREFIX2}-label-${(0, import_react7.useId)()}`;
1616
+ const internalFieldID = `${ID_PREFIX2}-field-${(0, import_react7.useId)()}`;
1617
+ const id = field.id || internalFieldID;
1618
+ const labelId = field.labelId || internalFieldLabelID;
1619
+ const state = field.state || stateProp;
1620
+ const disabled = field.disabled ?? disabledProp;
1621
+ const readOnly = field.readOnly ?? readOnlyProp;
1622
+ const [hasPopover, setHasPopover] = (0, import_react7.useState)(
1623
+ hasChildComponent(children, "Combobox.Popover")
1624
+ );
1625
+ const [areSelectedItemsInTrigger, setAreSelectedItemsInTrigger] = (0, import_react7.useState)(false);
1626
+ const [lastInteractionType, setLastInteractionType] = (0, import_react7.useState)("mouse");
1627
+ (0, import_react7.useEffect)(() => {
1628
+ setFilteredItems(shouldFilterItems ? getFilteredItemsMap(itemsMap, inputValue) : itemsMap);
1629
+ }, [inputValue, itemsMap]);
1630
+ const multiselect = (0, import_downshift3.useMultipleSelection)({
1631
+ selectedItems,
1632
+ stateReducer: (state2, { type, changes }) => {
1633
+ const types = import_downshift3.useMultipleSelection.stateChangeTypes;
1634
+ switch (type) {
1635
+ case types.SelectedItemKeyDownBackspace:
1636
+ case types.SelectedItemKeyDownDelete: {
1637
+ onInternalSelectedItemsChange(changes.selectedItems || []);
1638
+ let activeIndex;
1639
+ if (type === types.SelectedItemKeyDownDelete) {
1640
+ const isLastItem = state2?.activeIndex === changes.selectedItems?.length;
1641
+ activeIndex = isLastItem ? -1 : state2.activeIndex;
1642
+ } else {
1643
+ const hasItemBefore = (changes?.activeIndex || 0) - 1 >= 0;
1644
+ activeIndex = hasItemBefore ? state2.activeIndex - 1 : changes?.activeIndex;
1645
+ }
1646
+ return {
1647
+ ...changes,
1648
+ activeIndex
1649
+ };
1650
+ }
1651
+ case types.SelectedItemClick:
1652
+ if (innerInputRef.current) {
1653
+ innerInputRef.current.focus();
1654
+ }
1655
+ return {
1656
+ ...changes,
1657
+ activeIndex: -1
1658
+ // the focus will remain on the input
1659
+ };
1660
+ case types.FunctionRemoveSelectedItem:
1661
+ return {
1662
+ ...changes,
1663
+ activeIndex: -1
1664
+ // the focus will remain on the input
1665
+ };
1666
+ case types.DropdownKeyDownNavigationPrevious:
1667
+ downshift.closeMenu();
1668
+ return changes;
1669
+ default:
1670
+ return changes;
1671
+ }
1672
+ }
1673
+ });
1674
+ const filteredItems = Array.from(filteredItemsMap.values());
1675
+ (0, import_react7.useEffect)(() => {
1676
+ onInputValueChange?.(inputValue || "");
1677
+ }, [inputValue]);
1678
+ const downshift = (0, import_downshift3.useCombobox)({
1679
+ inputId: id,
1680
+ items: filteredItems,
1681
+ selectedItem: multiple ? void 0 : selectedItem,
1682
+ id,
1683
+ labelId,
1684
+ // Input
1685
+ inputValue,
1686
+ onInputValueChange: ({ inputValue: newInputValue }) => {
1687
+ setInputValue(newInputValue);
1688
+ if (shouldFilterItems) {
1689
+ const filtered = getFilteredItemsMap(itemsMap, newInputValue || "");
1690
+ setFilteredItems(filtered);
1691
+ }
1692
+ },
1693
+ // Open
1694
+ initialIsOpen: defaultOpen,
1695
+ ...controlledOpen != null && { isOpen: controlledOpen },
1696
+ onIsOpenChange: (changes) => {
1697
+ if (changes.isOpen != null) {
1698
+ onOpenChange?.(changes.isOpen);
1699
+ }
1700
+ },
1701
+ // Custom Spark item object parsing
1702
+ itemToString: (item) => {
1703
+ return item?.text;
1704
+ },
1705
+ isItemDisabled: (item) => {
1706
+ const isFilteredOut = !!inputValue && !filteredItems.some((filteredItem) => {
1707
+ return item.value === filteredItem.value;
1708
+ });
1709
+ return item.disabled || isFilteredOut;
1710
+ },
1711
+ // Main reducer
1712
+ stateReducer: multiple ? multipleSelectionReducer({
1713
+ multiselect,
1714
+ selectedItems,
1715
+ allowCustomValue,
1716
+ setSelectedItems: onInternalSelectedItemsChange,
1717
+ triggerAreaRef,
1718
+ items: itemsMap
1719
+ }) : singleSelectionReducer({
1720
+ allowCustomValue,
1721
+ setSelectedItem: onInternalSelectedItemChange,
1722
+ filteredItems: [...filteredItemsMap.values()]
1723
+ }),
1724
+ /**
1725
+ * Downshift default behaviour is to scroll into view the highlighted item when the dropdown opens. This behaviour is not stable and scrolls the dropdown to the bottom of the screen.
1726
+ */
1727
+ scrollIntoView: (node) => {
1728
+ if (node) {
1729
+ node.scrollIntoView({ block: "nearest" });
1730
+ }
1731
+ return void 0;
1732
+ }
1733
+ });
1734
+ (0, import_react7.useEffect)(() => {
1735
+ const newMap = getItemsFromChildren(children);
1736
+ const previousItems = [...itemsMap.values()];
1737
+ const newItems = [...newMap.values()];
1738
+ const hasItemsChanges = previousItems.length !== newItems.length || previousItems.some((item, index) => {
1739
+ const hasUpdatedValue = item.value !== newItems[index]?.value;
1740
+ const hasUpdatedText = item.text !== newItems[index]?.text;
1741
+ return hasUpdatedValue || hasUpdatedText;
1742
+ });
1743
+ if (hasItemsChanges) {
1744
+ setItemsMap(newMap);
1745
+ }
1746
+ }, [children]);
1747
+ const [WrapperComponent, wrapperProps] = hasPopover ? [Popover2, { open: true }] : [import_react7.Fragment, {}];
1748
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1749
+ ComboboxContext.Provider,
1750
+ {
1751
+ value: {
1752
+ // Data
1753
+ itemsMap,
1754
+ filteredItemsMap,
1755
+ highlightedItem: getElementByIndex(filteredItemsMap, downshift.highlightedIndex),
1756
+ // State
1757
+ multiple,
1758
+ disabled,
1759
+ readOnly,
1760
+ areSelectedItemsInTrigger,
1761
+ setAreSelectedItemsInTrigger,
1762
+ hasPopover,
1763
+ setHasPopover,
1764
+ state,
1765
+ lastInteractionType,
1766
+ setLastInteractionType,
1767
+ wrap,
1768
+ // Refs
1769
+ innerInputRef,
1770
+ triggerAreaRef,
1771
+ // Downshift state
1772
+ ...downshift,
1773
+ ...multiselect,
1774
+ setInputValue,
1775
+ selectItem: onInternalSelectedItemChange,
1776
+ setSelectedItems: onInternalSelectedItemsChange,
1777
+ isLoading,
1778
+ setOnInputValueChange,
1779
+ isTyping,
1780
+ setIsTyping
1781
+ },
1782
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(WrapperComponent, { ...wrapperProps, children })
1783
+ }
1784
+ );
1785
+ };
1786
+ var useComboboxContext = () => {
1787
+ const context = (0, import_react7.useContext)(ComboboxContext);
1788
+ if (!context) {
1789
+ throw Error("useComboboxContext must be used within a Combobox provider");
1790
+ }
1791
+ return context;
1792
+ };
1793
+
1794
+ // src/combobox/Combobox.tsx
1795
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1796
+ var Combobox = ({ children, ...props }) => {
1797
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ComboboxProvider, { ...props, children });
1798
+ };
1799
+ Combobox.displayName = "Combobox";
1800
+
1801
+ // src/combobox/ComboboxClearButton.tsx
1802
+ var import_DeleteOutline = require("@spark-ui/icons/DeleteOutline");
1803
+ var import_class_variance_authority10 = require("class-variance-authority");
1804
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1805
+ var ClearButton = ({
1806
+ className,
1807
+ tabIndex = -1,
1808
+ onClick,
1809
+ ref,
1810
+ ...others
1811
+ }) => {
1812
+ const ctx = useComboboxContext();
1813
+ const handleClick = (event) => {
1814
+ event.stopPropagation();
1815
+ if (ctx.multiple) {
1816
+ ctx.setSelectedItems([]);
1817
+ } else {
1818
+ ctx.selectItem(null);
1819
+ }
1820
+ ctx.setInputValue("");
1821
+ if (ctx.innerInputRef.current) {
1822
+ ctx.innerInputRef.current.focus();
1823
+ }
1824
+ if (onClick) {
1825
+ onClick(event);
1826
+ }
1827
+ };
1828
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1829
+ "button",
1830
+ {
1831
+ ref,
1832
+ className: (0, import_class_variance_authority10.cx)(className, "h-sz-44 text-neutral hover:text-neutral-hovered"),
1833
+ tabIndex,
1834
+ onClick: handleClick,
1835
+ type: "button",
1836
+ ...others,
1837
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Icon, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_DeleteOutline.DeleteOutline, {}) })
1838
+ }
1839
+ );
1840
+ };
1841
+ ClearButton.displayName = "Combobox.ClearButton";
1842
+
1843
+ // src/combobox/ComboboxDisclosure.tsx
1844
+ var import_use_merge_refs = require("@spark-ui/hooks/use-merge-refs");
1845
+ var import_ArrowHorizontalDown = require("@spark-ui/icons/ArrowHorizontalDown");
1846
+ var import_class_variance_authority11 = require("class-variance-authority");
1847
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1848
+ var Disclosure = ({
1849
+ className,
1850
+ closedLabel,
1851
+ openedLabel,
1852
+ intent = "neutral",
1853
+ design = "ghost",
1854
+ size = "sm",
1855
+ ref: forwardedRef,
1856
+ ...props
1857
+ }) => {
1858
+ const ctx = useComboboxContext();
1859
+ const { ref: downshiftRef, ...downshiftDisclosureProps } = ctx.getToggleButtonProps({
1860
+ disabled: ctx.disabled || ctx.readOnly,
1861
+ onClick: (event) => {
1862
+ event.stopPropagation();
1863
+ }
1864
+ });
1865
+ const isExpanded = downshiftDisclosureProps["aria-expanded"];
1866
+ const ref = (0, import_use_merge_refs.useMergeRefs)(forwardedRef, downshiftRef);
1867
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1868
+ IconButton,
1869
+ {
1870
+ ref,
1871
+ className: (0, import_class_variance_authority11.cx)(className, "ml-sm mt-[calc((44px-32px)/2)]"),
1872
+ intent,
1873
+ design,
1874
+ size,
1875
+ ...downshiftDisclosureProps,
1876
+ ...props,
1877
+ "aria-label": isExpanded ? openedLabel : closedLabel,
1878
+ disabled: ctx.disabled,
1879
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1880
+ Icon,
1881
+ {
1882
+ className: (0, import_class_variance_authority11.cx)("shrink-0", "rotate-0 transition duration-100 ease-in", {
1883
+ "rotate-180": isExpanded
1884
+ }),
1885
+ size: "sm",
1886
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_ArrowHorizontalDown.ArrowHorizontalDown, {})
1887
+ }
1888
+ )
1889
+ }
1890
+ );
1891
+ };
1892
+ Disclosure.displayName = "Combobox.Disclosure";
1893
+
1894
+ // src/combobox/ComboboxEmpty.tsx
1895
+ var import_class_variance_authority12 = require("class-variance-authority");
1896
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1897
+ var Empty = ({ className, children, ref: forwardedRef }) => {
1898
+ const ctx = useComboboxContext();
1899
+ const hasNoItemVisible = ctx.filteredItemsMap.size === 0;
1900
+ return hasNoItemVisible ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1901
+ "div",
1902
+ {
1903
+ ref: forwardedRef,
1904
+ className: (0, import_class_variance_authority12.cx)("px-lg py-md text-body-1 text-on-surface/dim-1", className),
1905
+ children
1906
+ }
1907
+ ) : null;
1908
+ };
1909
+ Empty.displayName = "Combobox.Empty";
1910
+
1911
+ // src/combobox/ComboboxGroup.tsx
1912
+ var import_class_variance_authority13 = require("class-variance-authority");
1913
+ var import_react9 = require("react");
1914
+
1915
+ // src/combobox/ComboboxItemsGroupContext.tsx
1916
+ var import_react8 = require("react");
1917
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1918
+ var ComboboxGroupContext = (0, import_react8.createContext)(null);
1919
+ var ComboboxGroupProvider = ({ children }) => {
1920
+ const groupLabelId = `${ID_PREFIX2}-group-label-${(0, import_react8.useId)()}`;
1921
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ComboboxGroupContext.Provider, { value: { groupLabelId }, children });
1922
+ };
1923
+ var useComboboxGroupContext = () => {
1924
+ const context = (0, import_react8.useContext)(ComboboxGroupContext);
1925
+ if (!context) {
1926
+ throw Error("useComboboxGroupContext must be used within a ComboboxGroup provider");
1927
+ }
1928
+ return context;
1929
+ };
1930
+
1931
+ // src/combobox/ComboboxGroup.tsx
1932
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1933
+ var Group = ({ children, ref: forwardedRef, ...props }) => {
1934
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ComboboxGroupProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(GroupContent, { ref: forwardedRef, ...props, children }) });
1935
+ };
1936
+ var GroupContent = ({ children, className, ref: forwardedRef }) => {
1937
+ const ctx = useComboboxContext();
1938
+ const groupCtx = useComboboxGroupContext();
1939
+ const hasVisibleOptions = import_react9.Children.toArray(children).some((child) => {
1940
+ return (0, import_react9.isValidElement)(child) && ctx.filteredItemsMap.get(child.props.value);
1941
+ });
1942
+ return hasVisibleOptions ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1943
+ "div",
1944
+ {
1945
+ ref: forwardedRef,
1946
+ role: "group",
1947
+ "aria-labelledby": groupCtx.groupLabelId,
1948
+ className: (0, import_class_variance_authority13.cx)(className),
1949
+ children
1950
+ }
1951
+ ) : null;
1952
+ };
1953
+ Group.displayName = "Combobox.Group";
1954
+
1955
+ // src/combobox/ComboboxInput.tsx
1956
+ var import_form_field2 = require("@spark-ui/components/form-field");
1957
+ var import_use_combined_state2 = require("@spark-ui/hooks/use-combined-state");
1958
+ var import_use_merge_refs2 = require("@spark-ui/hooks/use-merge-refs");
1959
+ var import_class_variance_authority14 = require("class-variance-authority");
1960
+ var import_react10 = require("react");
1961
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1962
+ var Input = ({
1963
+ "aria-label": ariaLabel,
1964
+ className,
1965
+ placeholder,
1966
+ value,
1967
+ defaultValue,
1968
+ onValueChange,
1969
+ ref: forwardedRef,
1970
+ ...props
1971
+ }) => {
1972
+ const ctx = useComboboxContext();
1973
+ const field = (0, import_form_field2.useFormFieldControl)();
1974
+ const [inputValue] = (0, import_use_combined_state2.useCombinedState)(value, defaultValue);
1975
+ const { isInvalid, description } = field;
1976
+ (0, import_react10.useEffect)(() => {
1977
+ if (inputValue != null) {
1978
+ ctx.setInputValue(inputValue);
1979
+ }
1980
+ }, [inputValue]);
1981
+ (0, import_react10.useEffect)(() => {
1982
+ if (onValueChange) {
1983
+ ctx.setOnInputValueChange(() => onValueChange);
1984
+ }
1985
+ if (!ctx.multiple && ctx.selectedItem) {
1986
+ ctx.setInputValue(ctx.selectedItem.text);
1987
+ }
1988
+ }, []);
1989
+ const PopoverTrigger = ctx.hasPopover ? Popover2.Trigger : import_react10.Fragment;
1990
+ const popoverTriggerProps = ctx.hasPopover ? {
1991
+ asChild: true,
1992
+ type: void 0
1993
+ } : {};
1994
+ const multiselectInputProps = ctx.getDropdownProps();
1995
+ const inputRef = (0, import_use_merge_refs2.useMergeRefs)(forwardedRef, ctx.innerInputRef, multiselectInputProps.ref);
1996
+ const downshiftInputProps = ctx.getInputProps({
1997
+ disabled: ctx.disabled || ctx.readOnly,
1998
+ ...multiselectInputProps,
1999
+ onKeyDown: (event) => {
2000
+ multiselectInputProps.onKeyDown?.(event);
2001
+ ctx.setLastInteractionType("keyboard");
2002
+ ctx.setIsTyping(true);
2003
+ },
2004
+ /**
2005
+ *
2006
+ * Important:
2007
+ * - without this, the input cursor is moved to the end after every change.
2008
+ * @see https://github.com/downshift-js/downshift/issues/1108#issuecomment-674180157
2009
+ */
2010
+ onChange: (e) => {
2011
+ ctx.setInputValue(e.target.value);
2012
+ },
2013
+ ref: inputRef
2014
+ });
2015
+ const hasPlaceholder = ctx.multiple ? !ctx.areSelectedItemsInTrigger || ctx.selectedItems.length === 0 : ctx.selectedItem === null;
2016
+ function mergeHandlers(handlerA, handlerB) {
2017
+ return (event) => {
2018
+ handlerA?.(event);
2019
+ handlerB?.(event);
2020
+ };
2021
+ }
2022
+ const mergedEventProps = {
2023
+ onBlur: mergeHandlers(props.onBlur, downshiftInputProps.onBlur),
2024
+ onChange: mergeHandlers(props.onChange, downshiftInputProps.onChange),
2025
+ onClick: mergeHandlers(props.onClick, downshiftInputProps.onClick),
2026
+ onKeyDown: mergeHandlers(props.onKeyDown, downshiftInputProps.onKeyDown)
2027
+ };
2028
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2029
+ ariaLabel && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("label", { ...ctx.getLabelProps(), children: ariaLabel }) }),
2030
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(PopoverTrigger, { ...popoverTriggerProps, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2031
+ "input",
2032
+ {
2033
+ "data-spark-component": "combobox-input",
2034
+ type: "text",
2035
+ ...hasPlaceholder && { placeholder },
2036
+ className: (0, import_class_variance_authority14.cx)(
2037
+ "max-w-full shrink-0 grow basis-[80px]",
2038
+ "h-sz-28 bg-surface px-sm text-body-1 text-ellipsis outline-hidden",
2039
+ "disabled:text-on-surface/dim-3 disabled:cursor-not-allowed disabled:bg-transparent",
2040
+ "read-only:text-on-surface read-only:cursor-default read-only:bg-transparent",
2041
+ className
2042
+ ),
2043
+ ...props,
2044
+ ...downshiftInputProps,
2045
+ ...mergedEventProps,
2046
+ value: ctx.inputValue,
2047
+ "aria-label": ariaLabel,
2048
+ disabled: ctx.disabled,
2049
+ readOnly: ctx.readOnly,
2050
+ "aria-invalid": isInvalid,
2051
+ "aria-describedby": description
2052
+ }
2053
+ ) })
2054
+ ] });
2055
+ };
2056
+ Input.displayName = "Combobox.Input";
2057
+
2058
+ // src/combobox/ComboboxItem.tsx
2059
+ var import_use_merge_refs3 = require("@spark-ui/hooks/use-merge-refs");
2060
+ var import_class_variance_authority15 = require("class-variance-authority");
2061
+
2062
+ // src/combobox/ComboboxItemContext.tsx
2063
+ var import_react11 = require("react");
2064
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2065
+ var ComboboxItemContext = (0, import_react11.createContext)(null);
2066
+ var ComboboxItemProvider = ({
2067
+ value,
2068
+ disabled = false,
2069
+ children
2070
+ }) => {
2071
+ const ctx = useComboboxContext();
2072
+ const [textId, setTextId] = (0, import_react11.useState)(void 0);
2073
+ const index = getIndexByKey(ctx.filteredItemsMap, value);
2074
+ const itemData = { disabled, value, text: getItemText(children) };
2075
+ const isSelected = ctx.multiple ? ctx.selectedItems.some((selectedItem) => selectedItem.value === value) : ctx.selectedItem?.value === value;
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2077
+ ComboboxItemContext.Provider,
2078
+ {
2079
+ value: { textId, setTextId, isSelected, itemData, index, disabled },
2080
+ children
2081
+ }
2082
+ );
2083
+ };
2084
+ var useComboboxItemContext = () => {
2085
+ const context = (0, import_react11.useContext)(ComboboxItemContext);
2086
+ if (!context) {
2087
+ throw Error("useComboboxItemContext must be used within a ComboboxItem provider");
2088
+ }
2089
+ return context;
2090
+ };
2091
+
2092
+ // src/combobox/ComboboxItem.tsx
2093
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2094
+ var Item = ({ children, ref: forwardedRef, ...props }) => {
2095
+ const { value, disabled } = props;
2096
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ComboboxItemProvider, { value, disabled, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ItemContent, { ref: forwardedRef, ...props, children }) });
2097
+ };
2098
+ var styles2 = (0, import_class_variance_authority15.cva)("px-lg py-md text-body-1", {
2099
+ variants: {
2100
+ selected: {
2101
+ true: "font-bold"
2102
+ },
2103
+ disabled: {
2104
+ true: "opacity-dim-3 cursor-not-allowed",
2105
+ false: "cursor-pointer"
2106
+ },
2107
+ highlighted: {
2108
+ true: ""
2109
+ },
2110
+ interactionType: {
2111
+ mouse: "",
2112
+ keyboard: ""
2113
+ }
2114
+ },
2115
+ compoundVariants: [
2116
+ {
2117
+ highlighted: true,
2118
+ interactionType: "mouse",
2119
+ class: "bg-surface-hovered"
2120
+ },
2121
+ {
2122
+ highlighted: true,
2123
+ interactionType: "keyboard",
2124
+ class: "u-outline"
2125
+ }
2126
+ ]
2127
+ });
2128
+ var ItemContent = ({
2129
+ className,
2130
+ disabled = false,
2131
+ value,
2132
+ children,
2133
+ ref: forwardedRef,
2134
+ ...rest
2135
+ }) => {
2136
+ const ctx = useComboboxContext();
2137
+ const itemCtx = useComboboxItemContext();
2138
+ const isVisible = !!ctx.filteredItemsMap.get(value);
2139
+ const { ref: downshiftRef, ...downshiftItemProps } = ctx.getItemProps({
2140
+ item: itemCtx.itemData,
2141
+ index: itemCtx.index
2142
+ });
2143
+ const ref = (0, import_use_merge_refs3.useMergeRefs)(forwardedRef, downshiftRef);
2144
+ if (!isVisible) return null;
2145
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2146
+ "li",
2147
+ {
2148
+ ref,
2149
+ className: (0, import_class_variance_authority15.cx)(
2150
+ styles2({
2151
+ selected: itemCtx.isSelected,
2152
+ disabled,
2153
+ highlighted: ctx.highlightedItem?.value === value,
2154
+ interactionType: ctx.lastInteractionType,
2155
+ className
2156
+ })
2157
+ ),
2158
+ ...downshiftItemProps,
2159
+ ...rest,
2160
+ "aria-selected": itemCtx.isSelected,
2161
+ "aria-labelledby": itemCtx.textId,
2162
+ children
2163
+ },
2164
+ value
2165
+ );
2166
+ };
2167
+ Item.displayName = "Combobox.Item";
2168
+
2169
+ // src/combobox/ComboboxItemIndicator.tsx
2170
+ var import_Check = require("@spark-ui/icons/Check");
2171
+ var import_class_variance_authority16 = require("class-variance-authority");
2172
+ var import_jsx_runtime26 = require("react/jsx-runtime");
2173
+ var ItemIndicator = ({
2174
+ className,
2175
+ children,
2176
+ label,
2177
+ ref: forwardedRef
2178
+ }) => {
2179
+ const { disabled, isSelected } = useComboboxItemContext();
2180
+ const childElement = children || /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Icon, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_Check.Check, { "aria-label": label }) });
2181
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
2182
+ "span",
2183
+ {
2184
+ ref: forwardedRef,
2185
+ className: (0, import_class_variance_authority16.cx)("min-h-sz-16 min-w-sz-16 flex", disabled && "opacity-dim-3", className),
2186
+ children: isSelected && childElement
2187
+ }
2188
+ );
2189
+ };
2190
+ ItemIndicator.displayName = "Combobox.ItemIndicator";
2191
+
2192
+ // src/combobox/ComboboxItems.tsx
2193
+ var import_use_merge_refs4 = require("@spark-ui/hooks/use-merge-refs");
2194
+ var import_class_variance_authority17 = require("class-variance-authority");
2195
+ var import_react12 = require("react");
2196
+ var import_jsx_runtime27 = require("react/jsx-runtime");
2197
+ var Items = ({ children, className, ref: forwardedRef, ...props }) => {
2198
+ const ctx = useComboboxContext();
2199
+ const { ref: downshiftRef, ...downshiftMenuProps } = ctx.getMenuProps({
2200
+ onMouseMove: () => {
2201
+ ctx.setLastInteractionType("mouse");
2202
+ }
2203
+ });
2204
+ const innerRef = (0, import_react12.useRef)(null);
2205
+ const ref = (0, import_use_merge_refs4.useMergeRefs)(forwardedRef, downshiftRef, innerRef);
2206
+ const isOpen = ctx.hasPopover ? ctx.isOpen : true;
2207
+ const isPointerEventsDisabled = ctx.hasPopover && !isOpen;
2208
+ (0, import_react12.useLayoutEffect)(() => {
2209
+ if (innerRef.current?.parentElement) {
2210
+ innerRef.current.parentElement.style.pointerEvents = isPointerEventsDisabled ? "none" : "";
2211
+ innerRef.current.style.pointerEvents = isPointerEventsDisabled ? "none" : "";
2212
+ }
2213
+ }, [isPointerEventsDisabled]);
2214
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
2215
+ "ul",
2216
+ {
2217
+ ref,
2218
+ className: (0, import_class_variance_authority17.cx)(
2219
+ className,
2220
+ "flex flex-col",
2221
+ isOpen ? "block" : "pointer-events-none invisible opacity-0",
2222
+ ctx.hasPopover && "p-lg",
2223
+ ctx.isLoading && "items-center overflow-y-auto"
2224
+ ),
2225
+ ...props,
2226
+ ...downshiftMenuProps,
2227
+ "aria-busy": ctx.isLoading,
2228
+ "data-spark-component": "combobox-items",
2229
+ children: ctx.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Spinner, { size: "sm" }) : children
2230
+ }
2231
+ );
2232
+ };
2233
+ Items.displayName = "Combobox.Items";
2234
+
2235
+ // src/combobox/ComboboxItemText.tsx
2236
+ var import_class_variance_authority18 = require("class-variance-authority");
2237
+ var import_react13 = require("react");
2238
+ var import_jsx_runtime28 = require("react/jsx-runtime");
2239
+ var ItemText = ({ children, className, ref: forwardedRef }) => {
2240
+ const id = `${ID_PREFIX2}-item-text-${(0, import_react13.useId)()}`;
2241
+ const { setTextId } = useComboboxItemContext();
2242
+ (0, import_react13.useEffect)(() => {
2243
+ setTextId(id);
2244
+ return () => setTextId(void 0);
2245
+ });
2246
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { id, className: (0, import_class_variance_authority18.cx)("inline", className), ref: forwardedRef, children });
2247
+ };
2248
+ ItemText.displayName = "Combobox.ItemText";
2249
+
2250
+ // src/combobox/ComboboxLabel.tsx
2251
+ var import_class_variance_authority19 = require("class-variance-authority");
2252
+ var import_jsx_runtime29 = require("react/jsx-runtime");
2253
+ var Label = ({ children, className, ref: forwardedRef }) => {
2254
+ const groupCtx = useComboboxGroupContext();
2255
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2256
+ "div",
2257
+ {
2258
+ ref: forwardedRef,
2259
+ id: groupCtx.groupLabelId,
2260
+ className: (0, import_class_variance_authority19.cx)("px-md py-sm text-body-2 text-neutral italic", className),
2261
+ children
2262
+ }
2263
+ );
2264
+ };
2265
+ Label.displayName = "Combobox.Label";
2266
+
2267
+ // src/combobox/ComboboxLeadingIcon.tsx
2268
+ var import_jsx_runtime30 = require("react/jsx-runtime");
2269
+ var LeadingIcon = ({ children }) => {
2270
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Icon, { size: "sm", className: "h-sz-44 shrink-0", children });
2271
+ };
2272
+ LeadingIcon.displayName = "Combobox.LeadingIcon";
2273
+
2274
+ // src/combobox/ComboboxPopover.tsx
2275
+ var import_class_variance_authority20 = require("class-variance-authority");
2276
+ var import_react14 = require("react");
2277
+ var import_jsx_runtime31 = require("react/jsx-runtime");
2278
+ var Popover3 = ({
2279
+ children,
2280
+ matchTriggerWidth = true,
2281
+ sideOffset = 4,
2282
+ className,
2283
+ ref: forwardedRef,
2284
+ ...props
2285
+ }) => {
2286
+ const ctx = useComboboxContext();
2287
+ (0, import_react14.useEffect)(() => {
2288
+ ctx.setHasPopover(true);
2289
+ return () => ctx.setHasPopover(false);
2290
+ }, []);
2291
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2292
+ Popover2.Content,
2293
+ {
2294
+ ref: forwardedRef,
2295
+ inset: true,
2296
+ asChild: true,
2297
+ matchTriggerWidth,
2298
+ className: (0, import_class_variance_authority20.cx)("z-dropdown! relative", className),
2299
+ sideOffset,
2300
+ onOpenAutoFocus: (e) => {
2301
+ e.preventDefault();
2302
+ },
2303
+ ...props,
2304
+ "data-spark-component": "combobox-popover",
2305
+ children
2306
+ }
2307
+ );
2308
+ };
2309
+ Popover3.displayName = "Combobox.Popover";
2310
+
2311
+ // src/combobox/ComboboxPortal.tsx
2312
+ var import_jsx_runtime32 = require("react/jsx-runtime");
2313
+ var Portal2 = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Popover2.Portal, { ...rest, children });
2314
+ Portal2.displayName = "Combobox.Portal";
2315
+
2316
+ // src/combobox/ComboboxSelectedItems.tsx
2317
+ var import_DeleteOutline2 = require("@spark-ui/icons/DeleteOutline");
2318
+ var import_class_variance_authority21 = require("class-variance-authority");
2319
+ var import_jsx_runtime33 = require("react/jsx-runtime");
2320
+ var SelectedItem = ({ item: selectedItem, index }) => {
2321
+ const ctx = useComboboxContext();
2322
+ const isCleanable = !ctx.disabled && !ctx.readOnly;
2323
+ const handleFocus = (e) => {
2324
+ const element = e.target;
2325
+ if (ctx.lastInteractionType === "keyboard") {
2326
+ element.scrollIntoView({
2327
+ behavior: "smooth",
2328
+ block: "nearest",
2329
+ inline: "nearest"
2330
+ });
2331
+ }
2332
+ };
2333
+ const { disabled, ...selectedItemProps } = ctx.getSelectedItemProps({
2334
+ disabled: ctx.disabled || ctx.readOnly,
2335
+ selectedItem,
2336
+ index
2337
+ });
2338
+ const Element = disabled ? "button" : "span";
2339
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
2340
+ Element,
2341
+ {
2342
+ role: "presentation",
2343
+ "data-spark-component": "combobox-selected-item",
2344
+ className: (0, import_class_variance_authority21.cx)(
2345
+ "h-sz-28 bg-neutral-container flex items-center rounded-md align-middle",
2346
+ "text-body-2 text-on-neutral-container",
2347
+ "disabled:opacity-dim-3 disabled:cursor-not-allowed",
2348
+ "focus-visible:u-outline-inset outline-hidden",
2349
+ { "px-md": !isCleanable, "pl-md": isCleanable }
2350
+ ),
2351
+ ...selectedItemProps,
2352
+ tabIndex: -1,
2353
+ ...disabled && { disabled: true },
2354
+ onFocus: handleFocus,
2355
+ children: [
2356
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2357
+ "span",
2358
+ {
2359
+ className: (0, import_class_variance_authority21.cx)("line-clamp-1 overflow-x-hidden leading-normal break-all text-ellipsis", {
2360
+ "w-max": !ctx.wrap
2361
+ }),
2362
+ children: selectedItem.text
2363
+ }
2364
+ ),
2365
+ ctx.disabled,
2366
+ isCleanable && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2367
+ "button",
2368
+ {
2369
+ type: "button",
2370
+ tabIndex: -1,
2371
+ "aria-hidden": true,
2372
+ className: "px-md h-full cursor-pointer",
2373
+ onClick: (e) => {
2374
+ e.stopPropagation();
2375
+ const updatedSelectedItems = ctx.selectedItems.filter(
2376
+ (item) => item.value !== selectedItem.value
2377
+ );
2378
+ ctx.setSelectedItems(updatedSelectedItems);
2379
+ if (ctx.innerInputRef.current) {
2380
+ ctx.innerInputRef.current.focus({ preventScroll: true });
2381
+ }
2382
+ },
2383
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Icon, { size: "sm", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_DeleteOutline2.DeleteOutline, {}) })
2384
+ }
2385
+ )
2386
+ ]
2387
+ },
2388
+ `selected-item-${index}`
2389
+ );
2390
+ };
2391
+ var SelectedItems = () => {
2392
+ const ctx = useComboboxContext();
2393
+ return ctx.multiple && ctx.selectedItems.length ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_jsx_runtime33.Fragment, { children: ctx.selectedItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(SelectedItem, { item, index }, item.value)) }) : null;
2394
+ };
2395
+ SelectedItems.displayName = "Combobox.SelectedItems";
2396
+
2397
+ // src/combobox/ComboboxTrigger.tsx
2398
+ var import_form_field3 = require("@spark-ui/components/form-field");
2399
+ var import_use_merge_refs5 = require("@spark-ui/hooks/use-merge-refs");
2400
+ var import_class_variance_authority23 = require("class-variance-authority");
2401
+ var import_react16 = require("react");
2402
+
2403
+ // src/combobox/ComboboxTrigger.styles.tsx
2404
+ var import_class_variance_authority22 = require("class-variance-authority");
2405
+ var styles3 = (0, import_class_variance_authority22.cva)(
2406
+ [
2407
+ "flex items-start gap-md min-h-sz-44 text-body-1",
2408
+ "h-fit rounded-lg px-lg",
2409
+ // outline styles
2410
+ "ring-1 outline-hidden ring-inset focus-within:ring-2 focus-within:ring-focus"
2411
+ ],
2412
+ {
2413
+ variants: {
2414
+ allowWrap: {
2415
+ true: "",
2416
+ false: "h-sz-44"
2417
+ },
2418
+ state: {
2419
+ undefined: "ring-outline",
2420
+ error: "ring-error",
2421
+ alert: "ring-alert",
2422
+ success: "ring-success"
2423
+ },
2424
+ disabled: {
2425
+ true: "cursor-not-allowed border-outline bg-on-surface/dim-5 text-on-surface/dim-3"
2426
+ },
2427
+ readOnly: {
2428
+ true: "cursor-default bg-on-surface/dim-5 text-on-surface"
2429
+ }
2430
+ },
2431
+ compoundVariants: [
2432
+ {
2433
+ disabled: false,
2434
+ state: void 0,
2435
+ class: "default:hover:ring-outline-high"
2436
+ },
2437
+ {
2438
+ disabled: false,
2439
+ readOnly: false,
2440
+ class: "bg-surface text-on-surface cursor-text"
2441
+ }
2442
+ ],
2443
+ defaultVariants: {
2444
+ state: void 0,
2445
+ disabled: false,
2446
+ readOnly: false
2447
+ }
2448
+ }
2449
+ );
2450
+
2451
+ // src/combobox/utils/useWidthIncreaseCallback.ts
2452
+ var import_react15 = require("react");
2453
+ var useWidthIncreaseCallback = (elementRef, callback) => {
2454
+ const prevWidthRef = (0, import_react15.useRef)(null);
2455
+ (0, import_react15.useEffect)(() => {
2456
+ const checkWidthIncrease = () => {
2457
+ const currentWidth = elementRef.current?.scrollWidth || null;
2458
+ if (prevWidthRef.current && currentWidth && currentWidth > prevWidthRef.current) {
2459
+ callback();
2460
+ }
2461
+ prevWidthRef.current = currentWidth;
2462
+ requestAnimationFrame(checkWidthIncrease);
2463
+ };
2464
+ const interval = requestAnimationFrame(checkWidthIncrease);
2465
+ return () => cancelAnimationFrame(interval);
2466
+ }, [elementRef]);
2467
+ };
2468
+
2469
+ // src/combobox/ComboboxTrigger.tsx
2470
+ var import_jsx_runtime34 = require("react/jsx-runtime");
2471
+ var Trigger2 = ({ className, children, ref: forwardedRef }) => {
2472
+ const ctx = useComboboxContext();
2473
+ const field = (0, import_form_field3.useFormFieldControl)();
2474
+ const leadingIcon = findElement(children, "Combobox.LeadingIcon");
2475
+ const selectedItems = findElement(children, "Combobox.SelectedItems");
2476
+ const input = findElement(children, "Combobox.Input");
2477
+ const clearButton = findElement(children, "Combobox.ClearButton");
2478
+ const disclosure = findElement(children, "Combobox.Disclosure");
2479
+ const [PopoverAnchor, popoverAnchorProps] = ctx.hasPopover ? [Popover2.Anchor, { asChild: true, type: void 0 }] : [import_react16.Fragment, {}];
2480
+ const ref = (0, import_use_merge_refs5.useMergeRefs)(forwardedRef, ctx.triggerAreaRef);
2481
+ const scrollableAreaRef = (0, import_react16.useRef)(null);
2482
+ const disabled = field.disabled || ctx.disabled;
2483
+ const readOnly = field.readOnly || ctx.readOnly;
2484
+ const hasClearButton = !!clearButton && !disabled && !readOnly;
2485
+ const scrollToRight = () => {
2486
+ if (scrollableAreaRef.current && !ctx.wrap) {
2487
+ const { scrollWidth, clientWidth } = scrollableAreaRef.current;
2488
+ scrollableAreaRef.current.scrollLeft = scrollWidth - clientWidth;
2489
+ }
2490
+ };
2491
+ useWidthIncreaseCallback(scrollableAreaRef, scrollToRight);
2492
+ const hasSelectedItems = !!selectedItems;
2493
+ (0, import_react16.useEffect)(() => {
2494
+ ctx.setAreSelectedItemsInTrigger(hasSelectedItems);
2495
+ }, [hasSelectedItems]);
2496
+ (0, import_react16.useEffect)(() => {
2497
+ const resizeObserver = new ResizeObserver(scrollToRight);
2498
+ if (scrollableAreaRef.current) {
2499
+ resizeObserver.observe(scrollableAreaRef.current);
2500
+ }
2501
+ return () => {
2502
+ resizeObserver.disconnect();
2503
+ };
2504
+ }, []);
2505
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_jsx_runtime34.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(PopoverAnchor, { ...popoverAnchorProps, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2506
+ "div",
2507
+ {
2508
+ ref,
2509
+ className: styles3({
2510
+ className,
2511
+ state: ctx.state,
2512
+ disabled,
2513
+ readOnly,
2514
+ allowWrap: ctx.wrap
2515
+ }),
2516
+ onClick: () => {
2517
+ if (!ctx.isOpen && !disabled && !readOnly) {
2518
+ ctx.openMenu();
2519
+ if (ctx.innerInputRef.current) {
2520
+ ctx.innerInputRef.current.focus();
2521
+ }
2522
+ }
2523
+ },
2524
+ children: [
2525
+ leadingIcon,
2526
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2527
+ "div",
2528
+ {
2529
+ ref: scrollableAreaRef,
2530
+ className: (0, import_class_variance_authority23.cx)(
2531
+ "min-w-none gap-sm py-md inline-flex grow items-start",
2532
+ ctx.wrap ? "flex-wrap" : "u-no-scrollbar overflow-x-auto p-[2px]"
2533
+ ),
2534
+ children: [
2535
+ selectedItems,
2536
+ input
2537
+ ]
2538
+ }
2539
+ ),
2540
+ hasClearButton && clearButton,
2541
+ disclosure
2542
+ ]
2543
+ }
2544
+ ) }) });
2545
+ };
2546
+ Trigger2.displayName = "Combobox.Trigger";
2547
+
2548
+ // src/combobox/index.ts
2549
+ var Combobox2 = Object.assign(Combobox, {
2550
+ Group,
2551
+ Item,
2552
+ Items,
2553
+ ItemText,
2554
+ ItemIndicator,
2555
+ Label,
2556
+ Popover: Popover3,
2557
+ Trigger: Trigger2,
2558
+ LeadingIcon,
2559
+ Empty,
2560
+ Input,
2561
+ Disclosure,
2562
+ SelectedItems,
2563
+ ClearButton,
2564
+ Portal: Portal2
2565
+ });
2566
+ Combobox2.displayName = "Combobox";
2567
+ Group.displayName = "Combobox.Group";
2568
+ Items.displayName = "Combobox.Items";
2569
+ Item.displayName = "Combobox.Item";
2570
+ ItemText.displayName = "Combobox.ItemText";
2571
+ ItemIndicator.displayName = "Combobox.ItemIndicator";
2572
+ Label.displayName = "Combobox.Label";
2573
+ Popover3.displayName = "Combobox.Popover";
2574
+ Trigger2.displayName = "Combobox.Trigger";
2575
+ LeadingIcon.displayName = "Combobox.LeadingIcon";
2576
+ Empty.displayName = "Combobox.Empty";
2577
+ Input.displayName = "Combobox.Input";
2578
+ Disclosure.displayName = "Combobox.Disclosure";
2579
+ SelectedItems.displayName = "Combobox.SelectedItems";
2580
+ ClearButton.displayName = "Combobox.ClearButton";
2581
+ Portal2.displayName = "Combobox.Portal";
2582
+ // Annotate the CommonJS export names for ESM import in node:
2583
+ 0 && (module.exports = {
2584
+ Combobox,
2585
+ ComboboxProvider,
2586
+ useComboboxContext
2587
+ });
2588
+ //# sourceMappingURL=index.js.map