@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1

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 (247) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +331 -0
  4. package/dist/accordion.js +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +8 -0
  7. package/dist/alert-dialog.d.ts +56 -0
  8. package/dist/alert-dialog.js +45 -0
  9. package/dist/async-options.d.ts +22 -0
  10. package/dist/async-options.js +56 -0
  11. package/dist/autocomplete.d.ts +102 -0
  12. package/dist/autocomplete.js +195 -0
  13. package/dist/avatar.d.ts +301 -0
  14. package/dist/avatar.js +17 -0
  15. package/dist/button.d.ts +21 -0
  16. package/dist/button.js +45 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +9 -0
  19. package/dist/calendar.d.ts +80 -0
  20. package/dist/calendar.js +257 -0
  21. package/dist/carousel.d.ts +52 -0
  22. package/dist/carousel.js +151 -0
  23. package/dist/checkbox.d.ts +24 -0
  24. package/dist/checkbox.js +98 -0
  25. package/dist/children.d.ts +38 -0
  26. package/dist/children.js +63 -0
  27. package/dist/collapsible.d.ts +302 -0
  28. package/dist/collapsible.js +19 -0
  29. package/dist/color-picker.d.ts +72 -0
  30. package/dist/color-picker.js +133 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +22 -0
  33. package/dist/combobox.d.ts +152 -0
  34. package/dist/combobox.js +338 -0
  35. package/dist/command.d.ts +88 -0
  36. package/dist/command.js +233 -0
  37. package/dist/controller-target.d.ts +3 -0
  38. package/dist/controller-target.js +59 -0
  39. package/dist/date-input.d.ts +19 -0
  40. package/dist/date-input.js +58 -0
  41. package/dist/date-picker.d.ts +47 -0
  42. package/dist/date-picker.js +310 -0
  43. package/dist/date.d.ts +2 -0
  44. package/dist/date.js +60 -0
  45. package/dist/dialog-parts.d.ts +23 -0
  46. package/dist/dialog-parts.js +142 -0
  47. package/dist/dialog.d.ts +57 -0
  48. package/dist/dialog.js +32 -0
  49. package/dist/drawer.d.ts +70 -0
  50. package/dist/drawer.js +158 -0
  51. package/dist/editor-context.d.ts +4 -0
  52. package/dist/editor-context.js +9 -0
  53. package/dist/field-context.d.ts +47 -0
  54. package/dist/field-context.js +87 -0
  55. package/dist/field.d.ts +49 -0
  56. package/dist/field.js +169 -0
  57. package/dist/file-input.d.ts +46 -0
  58. package/dist/file-input.js +170 -0
  59. package/dist/form-inputs.d.ts +5 -0
  60. package/dist/form-inputs.js +22 -0
  61. package/dist/gesture.d.ts +1 -0
  62. package/dist/gesture.js +16 -0
  63. package/dist/history.d.ts +2 -0
  64. package/dist/history.js +12 -0
  65. package/dist/hover-card.d.ts +33 -0
  66. package/dist/hover-card.js +84 -0
  67. package/dist/image-cropper.d.ts +333 -0
  68. package/dist/image-cropper.js +37 -0
  69. package/dist/image.d.ts +2 -0
  70. package/dist/image.js +6 -0
  71. package/dist/input.d.ts +22 -0
  72. package/dist/input.js +51 -0
  73. package/dist/label.d.ts +294 -0
  74. package/dist/label.js +9 -0
  75. package/dist/list-items.d.ts +15 -0
  76. package/dist/list-items.js +39 -0
  77. package/dist/list-text.d.ts +4 -0
  78. package/dist/list-text.js +15 -0
  79. package/dist/listbox.d.ts +56 -0
  80. package/dist/listbox.js +122 -0
  81. package/dist/menu.d.ts +116 -0
  82. package/dist/menu.js +426 -0
  83. package/dist/menubar-context.d.ts +4 -0
  84. package/dist/menubar-context.js +7 -0
  85. package/dist/menubar.d.ts +11 -0
  86. package/dist/menubar.js +32 -0
  87. package/dist/meter.d.ts +312 -0
  88. package/dist/meter.js +30 -0
  89. package/dist/navigation-menu.d.ts +61 -0
  90. package/dist/navigation-menu.js +169 -0
  91. package/dist/number-input.d.ts +44 -0
  92. package/dist/number-input.js +185 -0
  93. package/dist/number.d.ts +2 -0
  94. package/dist/number.js +40 -0
  95. package/dist/observe.d.ts +2 -0
  96. package/dist/observe.js +8 -0
  97. package/dist/otp-input.d.ts +29 -0
  98. package/dist/otp-input.js +94 -0
  99. package/dist/overlays.d.ts +26 -0
  100. package/dist/overlays.js +82 -0
  101. package/dist/pagination.d.ts +336 -0
  102. package/dist/pagination.js +71 -0
  103. package/dist/password-input.d.ts +23 -0
  104. package/dist/password-input.js +65 -0
  105. package/dist/popover.d.ts +54 -0
  106. package/dist/popover.js +151 -0
  107. package/dist/popup.d.ts +41 -0
  108. package/dist/popup.js +180 -0
  109. package/dist/preferences.d.ts +35 -0
  110. package/dist/preferences.js +93 -0
  111. package/dist/primitive.d.ts +2 -0
  112. package/dist/primitive.js +14 -0
  113. package/dist/progress.d.ts +312 -0
  114. package/dist/progress.js +30 -0
  115. package/dist/radio.d.ts +22 -0
  116. package/dist/radio.js +86 -0
  117. package/dist/rating.d.ts +20 -0
  118. package/dist/rating.js +94 -0
  119. package/dist/render-element.d.ts +35 -0
  120. package/dist/render-element.js +103 -0
  121. package/dist/resizable.d.ts +302 -0
  122. package/dist/resizable.js +23 -0
  123. package/dist/scroll-area.d.ts +324 -0
  124. package/dist/scroll-area.js +49 -0
  125. package/dist/segmented-control.d.ts +24 -0
  126. package/dist/segmented-control.js +78 -0
  127. package/dist/segmented-input.d.ts +15 -0
  128. package/dist/segmented-input.js +48 -0
  129. package/dist/select.d.ts +125 -0
  130. package/dist/select.js +330 -0
  131. package/dist/separator.d.ts +290 -0
  132. package/dist/separator.js +9 -0
  133. package/dist/shortcuts.d.ts +32 -0
  134. package/dist/shortcuts.js +61 -0
  135. package/dist/slider.d.ts +38 -0
  136. package/dist/slider.js +163 -0
  137. package/dist/switch.d.ts +15 -0
  138. package/dist/switch.js +39 -0
  139. package/dist/tabs.d.ts +331 -0
  140. package/dist/tabs.js +28 -0
  141. package/dist/text-control.d.ts +22 -0
  142. package/dist/text-control.js +24 -0
  143. package/dist/text-match.d.ts +2 -0
  144. package/dist/text-match.js +8 -0
  145. package/dist/textarea.d.ts +10 -0
  146. package/dist/textarea.js +48 -0
  147. package/dist/time-input.d.ts +19 -0
  148. package/dist/time-input.js +63 -0
  149. package/dist/timeline.d.ts +327 -0
  150. package/dist/timeline.js +31 -0
  151. package/dist/toast-parts.d.ts +63 -0
  152. package/dist/toast-parts.js +144 -0
  153. package/dist/toast.d.ts +2 -0
  154. package/dist/toast.js +22 -0
  155. package/dist/toggle.d.ts +23 -0
  156. package/dist/toggle.js +76 -0
  157. package/dist/token-input.d.ts +35 -0
  158. package/dist/token-input.js +100 -0
  159. package/dist/toolbar-context.d.ts +6 -0
  160. package/dist/toolbar-context.js +16 -0
  161. package/dist/toolbar.d.ts +38 -0
  162. package/dist/toolbar.js +63 -0
  163. package/dist/tooltip.d.ts +39 -0
  164. package/dist/tooltip.js +108 -0
  165. package/dist/tree.d.ts +51 -0
  166. package/dist/tree.js +150 -0
  167. package/dist/trigger-menu.d.ts +83 -0
  168. package/dist/trigger-menu.js +167 -0
  169. package/dist/use-primitive.d.ts +178 -0
  170. package/dist/use-primitive.js +674 -0
  171. package/dist/waterfall.d.ts +80 -0
  172. package/dist/waterfall.js +108 -0
  173. package/docs/README.md +89 -0
  174. package/docs/agents.md +1523 -0
  175. package/docs/components/accordion.md +1391 -0
  176. package/docs/components/alert-dialog.md +850 -0
  177. package/docs/components/autocomplete.md +1963 -0
  178. package/docs/components/avatar.md +252 -0
  179. package/docs/components/button.md +444 -0
  180. package/docs/components/calendar.md +1687 -0
  181. package/docs/components/carousel.md +1244 -0
  182. package/docs/components/checkbox.md +1069 -0
  183. package/docs/components/collapsible.md +567 -0
  184. package/docs/components/color-picker.md +736 -0
  185. package/docs/components/combobox.md +3647 -0
  186. package/docs/components/command.md +1573 -0
  187. package/docs/components/date-input.md +608 -0
  188. package/docs/components/date-picker.md +1266 -0
  189. package/docs/components/dialog.md +1469 -0
  190. package/docs/components/drawer.md +1197 -0
  191. package/docs/components/field.md +549 -0
  192. package/docs/components/file-input.md +609 -0
  193. package/docs/components/hover-card.md +514 -0
  194. package/docs/components/image-cropper.md +579 -0
  195. package/docs/components/input.md +301 -0
  196. package/docs/components/label.md +217 -0
  197. package/docs/components/listbox.md +1130 -0
  198. package/docs/components/menu.md +1286 -0
  199. package/docs/components/menubar.md +455 -0
  200. package/docs/components/meter.md +304 -0
  201. package/docs/components/navigation-menu.md +1581 -0
  202. package/docs/components/number-input.md +1086 -0
  203. package/docs/components/otp-input.md +565 -0
  204. package/docs/components/pagination.md +648 -0
  205. package/docs/components/password-input.md +737 -0
  206. package/docs/components/popover.md +1552 -0
  207. package/docs/components/preferences.md +220 -0
  208. package/docs/components/progress.md +443 -0
  209. package/docs/components/radio.md +846 -0
  210. package/docs/components/rating.md +458 -0
  211. package/docs/components/resizable.md +982 -0
  212. package/docs/components/scroll-area.md +980 -0
  213. package/docs/components/segmented-control.md +465 -0
  214. package/docs/components/select.md +2133 -0
  215. package/docs/components/separator.md +243 -0
  216. package/docs/components/slider.md +1169 -0
  217. package/docs/components/switch.md +613 -0
  218. package/docs/components/tabs.md +1014 -0
  219. package/docs/components/textarea.md +318 -0
  220. package/docs/components/time-input.md +231 -0
  221. package/docs/components/timeline.md +677 -0
  222. package/docs/components/toast.md +1395 -0
  223. package/docs/components/toggle.md +541 -0
  224. package/docs/components/token-input.md +1007 -0
  225. package/docs/components/toolbar.md +787 -0
  226. package/docs/components/tooltip.md +884 -0
  227. package/docs/components/tree.md +1346 -0
  228. package/docs/components/trigger-menu.md +1257 -0
  229. package/docs/components/waterfall.md +754 -0
  230. package/docs/controllers.md +89 -0
  231. package/docs/core.md +8027 -0
  232. package/docs/custom-parts.md +120 -0
  233. package/docs/first-component.md +83 -0
  234. package/docs/forms.md +148 -0
  235. package/docs/hooks/async-options.md +366 -0
  236. package/docs/hooks/shortcuts.md +221 -0
  237. package/docs/installation.md +45 -0
  238. package/docs/introduction.md +32 -0
  239. package/docs/lists-and-menus.md +170 -0
  240. package/docs/llms.txt +1844 -0
  241. package/docs/parts-and-composition.md +93 -0
  242. package/docs/popups.md +117 -0
  243. package/docs/rendering.md +121 -0
  244. package/docs/server-rendering.md +253 -0
  245. package/docs/state-and-events.md +105 -0
  246. package/docs/styling-and-animation.md +176 -0
  247. package/package.json +333 -3
@@ -0,0 +1,152 @@
1
+ import { type ComboboxChipProps, type ComboboxChipState, type ComboboxChipsOverflowState, type ComboboxClearState, type ComboboxContentProps, type ComboboxContentState, type ComboboxCreateProps, type ComboboxCreateState, type ComboboxEmptyState, type ComboboxInputState, type ComboboxItemIconProps, type ComboboxItemIconState, type ComboboxItemProps, type ComboboxItemState, type ComboboxItemTextState, type ComboboxOptions, type ComboboxSelectAllState, type ComboboxValueProps, type ComboboxValueState, type ListData } from "@ui-sdk/core/combobox";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ type Clashing = "value" | "defaultValue" | "onChange" | "onSelect";
5
+ /**
6
+ * The props of `Combobox`.
7
+ * @stable
8
+ */
9
+ type ComboboxProps<T = string, Multiple extends boolean | undefined = false> = ComboboxOptions<T, Multiple> & {
10
+ children?: React.ReactNode;
11
+ };
12
+ /**
13
+ * A text input that filters a list as you type.
14
+ * `T` is inferred from `value`, `defaultValue`, `items` or `onValueChange`, and
15
+ * `multiple` makes the value a list.
16
+ * @stable
17
+ */
18
+ declare function Combobox<T = string, Multiple extends boolean | undefined = false>({ children, container, ...options }: ComboboxProps<T, Multiple>): React.JSX.Element;
19
+ /**
20
+ * A visible label for the input.
21
+ * @stable
22
+ */
23
+ declare const ComboboxLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "label", "label">;
24
+ /**
25
+ * The text input that filters the list and holds the chosen item's label.
26
+ * @stable
27
+ */
28
+ declare function ComboboxInput({ render, ...props }: Omit<PartProps<"input", ComboboxInputState>, "value" | "defaultValue" | "children" | "readOnly">): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
29
+ /**
30
+ * A button that opens and closes the list, out of the tab order.
31
+ * @stable
32
+ */
33
+ declare const ComboboxTrigger: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "trigger", "button">;
34
+ /**
35
+ * The popup that holds the list, positioned against the input.
36
+ * @stable
37
+ */
38
+ declare function ComboboxContent({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, keepMounted, container, render, children, ...props }: PartProps<"div", ComboboxContentState> & ComboboxContentProps): React.JSX.Element | null;
39
+ /**
40
+ * The listbox. Without children, it renders the combobox's `items`, filtered.
41
+ * @stable
42
+ */
43
+ declare function ComboboxList({ children, ...props }: PartProps<"div", ComboboxContentState>): React.JSX.Element | null;
44
+ /**
45
+ * An option. Pressing it selects it, or toggles it with `multiple`.
46
+ * @stable
47
+ */
48
+ declare const ComboboxItem: <T = string>(props: Omit<PartProps<"div", ComboboxItemState>, Clashing> & ComboboxItemProps<T>) => React.ReactNode;
49
+ /**
50
+ * The item's text, with the part the input's text matched in `<mark>`. Without string content, it shows the item's label.
51
+ * @stable
52
+ */
53
+ declare function ComboboxItemText({ children, ...props }: PartProps<"span", ComboboxItemTextState>): React.JSX.Element | null;
54
+ /**
55
+ * An option that selects every item that matches, with `multiple`: in its group inside a `ComboboxGroup`, or in the whole list.
56
+ * @stable
57
+ */
58
+ declare function ComboboxSelectAll({ render, ...props }: PartProps<"div", ComboboxSelectAllState>): React.JSX.Element | null;
59
+ /**
60
+ * The check inside a selected item. Rendered while it's selected, or always with `keepMounted`.
61
+ * @stable
62
+ */
63
+ declare const ComboboxItemIndicator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "item-indicator", "span">;
64
+ /**
65
+ * An icon inside an item. `ComboboxValueIcon` shows the selected item's next to the input. Screen
66
+ * readers, typeahead and filtering skip it, and `mirror` flips it in right-to-left text.
67
+ * @stable
68
+ */
69
+ declare const ComboboxItemIcon: ({ mirror, render, ...props }: PartProps<"span", ComboboxItemIconState> & ComboboxItemIconProps) => React.JSX.Element | null;
70
+ /**
71
+ * The selected item's icon, copied from its `ComboboxItemIcon`, like next to the input. Rendered
72
+ * while one item is selected and it has an icon.
73
+ * @stable
74
+ */
75
+ declare function ComboboxValueIcon(props: Omit<PartProps<"span">, "children">): React.JSX.Element | null;
76
+ /**
77
+ * A group of items, named by its `ComboboxGroupLabel`, and hidden while none of its items shows.
78
+ * @stable
79
+ */
80
+ declare const ComboboxGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "group", "div">;
81
+ /**
82
+ * The group's heading, which names the group.
83
+ * @stable
84
+ */
85
+ declare const ComboboxGroupLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "group-label", "div">;
86
+ /**
87
+ * A line between items or groups, hidden from screen readers.
88
+ * @stable
89
+ */
90
+ declare const ComboboxSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "separator", "div">;
91
+ /**
92
+ * An option that creates an item from the input's text. Shown while the text matches no item's label exactly.
93
+ * @stable
94
+ */
95
+ declare function ComboboxCreate({ onCreate, minLength, children, ...props }: Omit<PartProps<"div", ComboboxCreateState>, Clashing> & ComboboxCreateProps): React.JSX.Element | null;
96
+ /**
97
+ * Shown while no item matches. Its message is announced when it appears.
98
+ * @stable
99
+ */
100
+ declare function ComboboxEmpty({ children, ...props }: PartProps<"div", ComboboxEmptyState>): React.JSX.Element | null;
101
+ /**
102
+ * A polite live region for loading and result counts. Its content is yours, usually a function of its state.
103
+ * @stable
104
+ */
105
+ declare const ComboboxStatus: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "status", "div">;
106
+ /**
107
+ * A button that empties the input and selects nothing. Shown while there's something to clear.
108
+ * @stable
109
+ */
110
+ declare const ComboboxClear: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "clear", "button">;
111
+ /**
112
+ * The selected value, as a function of its state, like one chip per value. Without children, the labels joined with commas, or "France, Chile and 2 more" with `maxLabels`. Renders no element of its own.
113
+ * @stable
114
+ */
115
+ declare function ComboboxValue({ maxLabels, getMoreLabel, children, }: ComboboxValueProps & {
116
+ children?: React.ReactNode | ((state: ComboboxValueState) => React.ReactNode);
117
+ }): React.JSX.Element | null;
118
+ /**
119
+ * How many chips don't fit on the chips' line, once some collapse. Rendering it inside `ComboboxChips` turns collapsing on. Without children, "+2 more".
120
+ * @stable
121
+ */
122
+ declare function ComboboxChipsOverflow({ children, ...props }: PartProps<"span", ComboboxChipsOverflowState>): React.JSX.Element | null;
123
+ /**
124
+ * The selected values as chips, around the input.
125
+ * @stable
126
+ */
127
+ declare function ComboboxChips({ render, ...props }: PartProps<"div">): React.JSX.Element | null;
128
+ /**
129
+ * One selected value. Without children, it shows the value's label.
130
+ * @stable
131
+ */
132
+ declare function ComboboxChip<T = string>({ value, children, ...props }: Omit<PartProps<"div", ComboboxChipState>, Clashing> & ComboboxChipProps<T>): React.JSX.Element;
133
+ /**
134
+ * A button inside a chip that removes its value. Name it with `aria-label`.
135
+ * @stable
136
+ */
137
+ declare function ComboboxChipRemove({ render, ...props }: PartProps<"button", ComboboxClearState>): React.JSX.Element | null;
138
+ /**
139
+ * An arrow on the popup's edge that points at the input.
140
+ * @stable
141
+ */
142
+ declare const ComboboxArrow: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/combobox").ComboboxPrimitive, "arrow", "div">;
143
+ /**
144
+ * Renders data items. Used by data comboboxes, and available for custom layouts.
145
+ * @stable
146
+ */
147
+ declare function ComboboxItems({ items }: {
148
+ items: ListData<unknown>;
149
+ }): React.JSX.Element;
150
+ export { createComboboxController } from "@ui-sdk/core/combobox";
151
+ export type { ComboboxApi, ComboboxArrowState, ComboboxChangeOptions, ComboboxChipProps, ComboboxChipState, ComboboxChipsOverflowState, ComboboxClearProps, ComboboxClearState, ComboboxContentProps, ComboboxContentState, ComboboxController, ComboboxCreateProps, ComboboxCreateState, ComboboxDismissReason, ComboboxEmptyState, ComboboxInputState, ComboboxItemIconProps, ComboboxItemIconState, ComboboxItemIndicatorProps, ComboboxItemIndicatorState, ComboboxItemProps, ComboboxItemState, ComboboxItemTextState, ComboboxOpenChangeReason, ComboboxOptions, ComboboxPrimitive, ComboboxQueryChangeReason, ComboboxSelectAllState, ComboboxStatusState, ComboboxTriggerState, ComboboxValue as ComboboxValueData, ComboboxValueChangeReason, ComboboxValueProps, ComboboxValueState, ListAnnouncement, ListData, ListFilter, ListGroup, ListHighlightDetails, ListItem, ListSeparator, MatchSegment, } from "@ui-sdk/core/combobox";
152
+ export { Combobox, ComboboxArrow, ComboboxChip, ComboboxChipRemove, ComboboxChips, ComboboxChipsOverflow, ComboboxClear, ComboboxContent, ComboboxCreate, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxItemIcon, ComboboxItemIndicator, ComboboxItems, ComboboxItemText, ComboboxLabel, ComboboxList, type ComboboxProps, ComboboxSelectAll, ComboboxSeparator, ComboboxStatus, ComboboxTrigger, ComboboxValue, ComboboxValueIcon, };
@@ -0,0 +1,338 @@
1
+ "use client";
2
+ // src/combobox.tsx
3
+ import {
4
+ combobox as comboboxPrimitive
5
+ } from "@ui-sdk/core/combobox";
6
+ import {
7
+ comboboxChips,
8
+ comboboxCreate,
9
+ comboboxItemIcons,
10
+ comboboxSelectAll,
11
+ selectAllKey
12
+ } from "@ui-sdk/core/renderer";
13
+ import * as React from "react";
14
+ import {
15
+ hasChild,
16
+ learnLabels,
17
+ notLabel,
18
+ Placed,
19
+ usePlaceContent,
20
+ usePlacedContent
21
+ } from "./children.js";
22
+ import { controlRender, useFieldControl } from "./field-context.js";
23
+ import { markSegments, textToMark } from "./list-text.js";
24
+ import {
25
+ renderPopup,
26
+ SheetHeaderContext,
27
+ inSheetHeader,
28
+ sheetHeader,
29
+ sheetViewport,
30
+ useControllerEntry,
31
+ useOwnContainer,
32
+ usePopupContainer
33
+ } from "./popup.js";
34
+ import {
35
+ createParts,
36
+ HandleScope,
37
+ useAround,
38
+ useHandle,
39
+ useNearest,
40
+ usePart,
41
+ usePrimitive
42
+ } from "./use-primitive.js";
43
+ import { FormInputs } from "./form-inputs.js";
44
+ import { ListItems } from "./list-items.js";
45
+ import { createComboboxController } from "@ui-sdk/core/combobox";
46
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
47
+ var parts = createParts(comboboxPrimitive, {
48
+ label: "label",
49
+ trigger: "button",
50
+ item: "div",
51
+ "item-indicator": "span",
52
+ group: "div",
53
+ "group-label": "div",
54
+ separator: "div",
55
+ status: "div",
56
+ clear: "button",
57
+ arrow: "div"
58
+ });
59
+ var ContainerContext = React.createContext(void 0);
60
+ var ChipContext = React.createContext(null);
61
+ function useCombobox() {
62
+ return useHandle(comboboxPrimitive);
63
+ }
64
+ function Combobox({
65
+ children,
66
+ container,
67
+ ...options
68
+ }) {
69
+ const field = useFieldControl();
70
+ const combobox = usePrimitive(comboboxPrimitive, {
71
+ ...options,
72
+ name: options.name ?? field?.name,
73
+ disabled: options.disabled || field?.disabled
74
+ });
75
+ useControllerEntry(options.controller, combobox);
76
+ learnLabels(combobox.api.internal, children, itemDecorations);
77
+ const header = React.useState(null);
78
+ const found = hasChild(children, ComboboxContent);
79
+ const [placed, place] = usePlacedContent(!!options.items && !found);
80
+ const own = placed || found;
81
+ return /* @__PURE__ */ jsx(HandleScope, { handle: combobox, children: /* @__PURE__ */ jsx(ContainerContext.Provider, { value: container, children: /* @__PURE__ */ jsxs(SheetHeaderContext.Provider, { value: header, children: [
82
+ /* @__PURE__ */ jsx(Placed, { value: place, children }),
83
+ /* @__PURE__ */ jsx(Placed, { value: null, children: options.items && !own && /* @__PURE__ */ jsx(ComboboxContent, {}) }),
84
+ /* @__PURE__ */ jsx(FormInputs, { handle: combobox })
85
+ ] }) }) });
86
+ }
87
+ var ComboboxLabel = parts.Label;
88
+ function ComboboxInput({
89
+ render,
90
+ ...props
91
+ }) {
92
+ const [header] = React.useContext(SheetHeaderContext);
93
+ const element = {
94
+ ...props,
95
+ render: controlRender(useFieldControl(props), "input", render)
96
+ };
97
+ const input = usePart(comboboxPrimitive, "input", {}, element, "input");
98
+ return input && inSheetHeader(input, header);
99
+ }
100
+ var ComboboxTrigger = parts.Trigger;
101
+ function ComboboxContent({
102
+ side,
103
+ align,
104
+ sideOffset,
105
+ alignOffset,
106
+ collisionPadding,
107
+ arrowPadding,
108
+ anchor,
109
+ keepMounted,
110
+ container,
111
+ render,
112
+ children,
113
+ ...props
114
+ }) {
115
+ usePlaceContent();
116
+ const combobox = useCombobox();
117
+ const target = usePopupContainer(useOwnContainer(container, ContainerContext));
118
+ const content = {
119
+ side,
120
+ align,
121
+ sideOffset,
122
+ alignOffset,
123
+ collisionPadding,
124
+ arrowPadding,
125
+ anchor,
126
+ keepMounted
127
+ };
128
+ const [, setHeader] = React.useContext(SheetHeaderContext);
129
+ const body = (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
130
+ sheetHeader(combobox, setHeader),
131
+ typeof children === "function" ? children(state) : children ?? (state.items && combobox.state.items && /* @__PURE__ */ jsx(ComboboxList, {}))
132
+ ] });
133
+ const element = usePart(combobox, "content", content, {
134
+ ...props,
135
+ children: body,
136
+ render: sheetViewport(combobox, render)
137
+ });
138
+ return element && renderPopup(element, target);
139
+ }
140
+ function ComboboxList({
141
+ children = listItems,
142
+ ...props
143
+ }) {
144
+ return usePart(comboboxPrimitive, "list", {}, { ...props, children });
145
+ }
146
+ var listItems = (state) => /* @__PURE__ */ jsx(ComboboxItems, { items: state.items });
147
+ var ComboboxItem = parts.Item;
148
+ function ComboboxItemText({
149
+ children,
150
+ ...props
151
+ }) {
152
+ const item = useAround(comboboxPrimitive, "item");
153
+ if (!item) {
154
+ throw new Error("<ComboboxItemText> must be used inside <ComboboxItem>.");
155
+ }
156
+ const label2 = item.label ?? item.value;
157
+ const part = { id: item.value, text: textToMark(children, label2) };
158
+ const content = typeof children === "function" ? children : (state) => markSegments(state.segments);
159
+ return usePart(
160
+ comboboxPrimitive,
161
+ "item-text",
162
+ part,
163
+ { ...props, children: content },
164
+ "span"
165
+ );
166
+ }
167
+ function ComboboxSelectAll({
168
+ render,
169
+ ...props
170
+ }) {
171
+ const combobox = useCombobox();
172
+ combobox.instance.use(comboboxSelectAll);
173
+ const part = {
174
+ id: selectAllKey(
175
+ useAround(comboboxPrimitive, "group")?.id
176
+ )
177
+ };
178
+ return usePart(combobox, "select-all", part, { ...props, render }, "div");
179
+ }
180
+ var ComboboxItemIndicator = parts.ItemIndicator;
181
+ var itemDecorations = /* @__PURE__ */ new Set([ComboboxItemIndicator]);
182
+ var ComboboxItemIcon = /* @__PURE__ */ notLabel(function ComboboxItemIcon2({
183
+ mirror,
184
+ render,
185
+ ...props
186
+ }) {
187
+ const combobox = useCombobox();
188
+ combobox.instance.use(comboboxItemIcons);
189
+ const part = {
190
+ id: React.useId(),
191
+ mirror,
192
+ item: useAround(comboboxPrimitive, "item")?.value
193
+ };
194
+ return usePart(combobox, "item-icon", part, { ...props, render }, "span");
195
+ });
196
+ function ComboboxValueIcon(props) {
197
+ return useNearest(comboboxPrimitive) ? /* @__PURE__ */ jsx(ComboboxValueIconPart, { ...props }) : null;
198
+ }
199
+ function ComboboxValueIconPart(props) {
200
+ const combobox = useCombobox();
201
+ combobox.instance.use(comboboxItemIcons);
202
+ return usePart(combobox, "value-icon", {}, props, "span");
203
+ }
204
+ var ComboboxGroup = parts.Group;
205
+ var ComboboxGroupLabel = parts.GroupLabel;
206
+ var ComboboxSeparator = parts.Separator;
207
+ function ComboboxCreate({
208
+ onCreate,
209
+ minLength,
210
+ children = create,
211
+ ...props
212
+ }) {
213
+ const combobox = useCombobox();
214
+ combobox.instance.use(comboboxCreate);
215
+ return usePart(
216
+ combobox,
217
+ "create",
218
+ { onCreate, minLength },
219
+ { ...props, children }
220
+ );
221
+ }
222
+ var create = (state) => `Create \u201C${state.query}\u201D`;
223
+ function ComboboxEmpty({
224
+ children,
225
+ ...props
226
+ }) {
227
+ const content = (state) => typeof children === "function" ? children(state) : state.empty ? children : null;
228
+ return usePart(
229
+ comboboxPrimitive,
230
+ "empty",
231
+ {},
232
+ { ...props, children: content }
233
+ );
234
+ }
235
+ var ComboboxStatus = parts.Status;
236
+ var ComboboxClear = parts.Clear;
237
+ function ComboboxValue({
238
+ maxLabels,
239
+ getMoreLabel,
240
+ children
241
+ }) {
242
+ const value = (_props, state) => /* @__PURE__ */ jsx(Fragment, { children: typeof children === "function" ? children(state) : children ?? state.label });
243
+ return usePart(
244
+ comboboxPrimitive,
245
+ "value",
246
+ { maxLabels, getMoreLabel },
247
+ { render: value }
248
+ );
249
+ }
250
+ function ComboboxChipsOverflow({
251
+ children = more,
252
+ ...props
253
+ }) {
254
+ const combobox = useCombobox();
255
+ combobox.instance.use(comboboxChips);
256
+ return usePart(combobox, "chips-overflow", {}, { ...props, children }, "span");
257
+ }
258
+ var more = (state) => `+${state.count} more`;
259
+ function ComboboxChips({ render, ...props }) {
260
+ const combobox = useCombobox();
261
+ combobox.instance.use(comboboxChips);
262
+ return usePart(combobox, "chips", {}, { ...props, render }, "div");
263
+ }
264
+ function ComboboxChip({
265
+ value,
266
+ children = label,
267
+ ...props
268
+ }) {
269
+ const combobox = useCombobox();
270
+ combobox.instance.use(comboboxChips);
271
+ const part = { id: combobox.api.internal.keyOf(value), value };
272
+ const chip = React.useMemo(() => ({ value }), [value]);
273
+ return /* @__PURE__ */ jsx(ChipContext.Provider, { value: chip, children: usePart(combobox, "chip", part, { ...props, children }) });
274
+ }
275
+ var label = (state) => state.label;
276
+ function ComboboxChipRemove({
277
+ render,
278
+ ...props
279
+ }) {
280
+ const combobox = useCombobox();
281
+ combobox.instance.use(comboboxChips);
282
+ const chip = React.useContext(ChipContext);
283
+ if (!chip) {
284
+ throw new Error("<ComboboxChipRemove> must be used inside <ComboboxChip>.");
285
+ }
286
+ const part = {
287
+ id: combobox.api.internal.keyOf(chip.value),
288
+ value: chip.value
289
+ };
290
+ return usePart(combobox, "chip-remove", part, { ...props, render }, "button");
291
+ }
292
+ var ComboboxArrow = parts.Arrow;
293
+ function ComboboxItems({ items }) {
294
+ const combobox = useCombobox();
295
+ return /* @__PURE__ */ jsx(
296
+ ListItems,
297
+ {
298
+ items,
299
+ parts: listParts,
300
+ keyOf: combobox.api.internal.keyOf
301
+ }
302
+ );
303
+ }
304
+ var listParts = {
305
+ Item: ComboboxItem,
306
+ Group: ComboboxGroup,
307
+ GroupLabel: ComboboxGroupLabel,
308
+ Separator: ComboboxSeparator
309
+ };
310
+ export {
311
+ Combobox,
312
+ ComboboxArrow,
313
+ ComboboxChip,
314
+ ComboboxChipRemove,
315
+ ComboboxChips,
316
+ ComboboxChipsOverflow,
317
+ ComboboxClear,
318
+ ComboboxContent,
319
+ ComboboxCreate,
320
+ ComboboxEmpty,
321
+ ComboboxGroup,
322
+ ComboboxGroupLabel,
323
+ ComboboxInput,
324
+ ComboboxItem,
325
+ ComboboxItemIcon,
326
+ ComboboxItemIndicator,
327
+ ComboboxItemText,
328
+ ComboboxItems,
329
+ ComboboxLabel,
330
+ ComboboxList,
331
+ ComboboxSelectAll,
332
+ ComboboxSeparator,
333
+ ComboboxStatus,
334
+ ComboboxTrigger,
335
+ ComboboxValue,
336
+ ComboboxValueIcon,
337
+ createComboboxController
338
+ };
@@ -0,0 +1,88 @@
1
+ import { type CommandData, type CommandEmptyState, type CommandItemProps, type CommandItemState, type CommandItemTextState, type CommandListState, type CommandOptions, type CommandPageProps, type CommandState, type CommandShortcutProps, type CommandShortcutState } from "@ui-sdk/core/command";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ type Clashing = "value" | "defaultValue" | "onChange" | "onSelect";
5
+ /**
6
+ * The props of `Command`.
7
+ * @stable
8
+ */
9
+ type CommandProps = CommandOptions & Omit<PartProps<"div", CommandState>, Clashing>;
10
+ /**
11
+ * A search field over an always-open list of commands. Renders a `div` around them.
12
+ * @stable
13
+ */
14
+ declare function Command({ value, defaultValue, onValueChange, query, defaultQuery, onQueryChange, pages, defaultPages, onPagesChange, onAction, pendingAnnouncement, items, emptyItems, filter, autoHighlight, loop, status, onLoadMore, announcement, controller, debug, children, ...props }: CommandProps): React.JSX.Element | null;
15
+ /**
16
+ * The search field. It keeps focus while arrow keys move the highlight. Name it with `aria-label`.
17
+ * @stable
18
+ */
19
+ declare const CommandInput: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "input", "input">;
20
+ /**
21
+ * The listbox. Without children, it renders the command's `items`, ranked as the user types.
22
+ * @stable
23
+ */
24
+ declare function CommandList({ children, ...props }: PartProps<"div", CommandListState>): React.JSX.Element | null;
25
+ /**
26
+ * A command. Pressing it, or Enter while it's highlighted, runs it, with its `value` passed to the command's
27
+ * `onAction`.
28
+ * @stable
29
+ */
30
+ declare function CommandItem({ value, label, keywords, disabled, shortcut, page, index, onSelect, render, ...props }: Omit<PartProps<"div", CommandItemState>, Clashing> & CommandItemProps): React.JSX.Element | null;
31
+ /**
32
+ * The command's text, with the part the search matched in `<mark>`. Without string content, it shows the command's label.
33
+ * @stable
34
+ */
35
+ declare function CommandItemText({ children, ...props }: PartProps<"span", CommandItemTextState>): React.JSX.Element | null;
36
+ /**
37
+ * An icon inside a command. Screen readers, typeahead and filtering skip it, and `mirror` flips it
38
+ * in right-to-left text.
39
+ * @stable
40
+ */
41
+ declare const CommandItemIcon: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "item-icon", "span">;
42
+ /**
43
+ * The keys of a command's shortcut, formatted for the platform. Inside a command, its `shortcut`.
44
+ * @stable
45
+ */
46
+ declare function CommandShortcut({ shortcut, children, ...props }: PartProps<"span", CommandShortcutState> & CommandShortcutProps): React.JSX.Element | null;
47
+ /**
48
+ * Commands shown while this page is on top. Without `value`, it's the first page. Renders no element.
49
+ * @stable
50
+ */
51
+ declare function CommandPage({ value, children, }: CommandPageProps & {
52
+ children?: React.ReactNode;
53
+ }): React.JSX.Element | null;
54
+ /**
55
+ * A group of commands. It hides while none of its commands matches the search.
56
+ * @stable
57
+ */
58
+ declare const CommandGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "group", "div">;
59
+ /**
60
+ * A group's heading, which names it.
61
+ * @stable
62
+ */
63
+ declare const CommandGroupLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "group-label", "div">;
64
+ /**
65
+ * A line between groups. Composed separators hide while the list is filtered.
66
+ * @stable
67
+ */
68
+ declare const CommandSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "separator", "div">;
69
+ /**
70
+ * Shown while no command matches. Its message is announced when it appears. Place it outside the list.
71
+ * @stable
72
+ */
73
+ declare function CommandEmpty({ children, ...props }: PartProps<"div", CommandEmptyState>): React.JSX.Element | null;
74
+ /**
75
+ * A polite live region for loading and result counts. Its content is yours, usually a function of its state.
76
+ * @stable
77
+ */
78
+ declare const CommandStatus: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/command").CommandPrimitive, "status", "div">;
79
+ /**
80
+ * Renders data commands. Used by data command lists, and available for custom layouts.
81
+ * @stable
82
+ */
83
+ declare function CommandItems({ items }: {
84
+ items: CommandData;
85
+ }): React.JSX.Element;
86
+ export { createCommandController } from "@ui-sdk/core/command";
87
+ export type { CommandActionDetails, CommandApi, CommandChangeOptions, CommandController, CommandData, CommandDataGroup, CommandDataItem, CommandEmptyState, CommandInputState, CommandItemIconProps, CommandItemIconState, CommandItemProps, CommandItemState, CommandItemTextState, CommandListState, CommandOptions, CommandPageProps, CommandPagesChangeReason, CommandPrimitive, CommandQueryChangeReason, CommandState, CommandShortcutProps, CommandShortcutState, CommandStatusState, CommandValueChangeDetails, CommandValueChangeReason, ListAnnouncement, ListFilter, ListSeparator, MatchSegment, SearchFilter, } from "@ui-sdk/core/command";
88
+ export { Command, CommandEmpty, CommandGroup, CommandGroupLabel, CommandInput, CommandItem, CommandItemIcon, CommandItems, CommandItemText, CommandList, CommandPage, type CommandProps, CommandSeparator, CommandShortcut, CommandStatus, };