@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.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +331 -0
- package/dist/accordion.js +25 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +8 -0
- package/dist/alert-dialog.d.ts +56 -0
- package/dist/alert-dialog.js +45 -0
- package/dist/async-options.d.ts +22 -0
- package/dist/async-options.js +56 -0
- package/dist/autocomplete.d.ts +102 -0
- package/dist/autocomplete.js +195 -0
- package/dist/avatar.d.ts +301 -0
- package/dist/avatar.js +17 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.js +45 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +9 -0
- package/dist/calendar.d.ts +80 -0
- package/dist/calendar.js +257 -0
- package/dist/carousel.d.ts +52 -0
- package/dist/carousel.js +151 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.js +98 -0
- package/dist/children.d.ts +38 -0
- package/dist/children.js +63 -0
- package/dist/collapsible.d.ts +302 -0
- package/dist/collapsible.js +19 -0
- package/dist/color-picker.d.ts +72 -0
- package/dist/color-picker.js +133 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +22 -0
- package/dist/combobox.d.ts +152 -0
- package/dist/combobox.js +338 -0
- package/dist/command.d.ts +88 -0
- package/dist/command.js +233 -0
- package/dist/controller-target.d.ts +3 -0
- package/dist/controller-target.js +59 -0
- package/dist/date-input.d.ts +19 -0
- package/dist/date-input.js +58 -0
- package/dist/date-picker.d.ts +47 -0
- package/dist/date-picker.js +310 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +60 -0
- package/dist/dialog-parts.d.ts +23 -0
- package/dist/dialog-parts.js +142 -0
- package/dist/dialog.d.ts +57 -0
- package/dist/dialog.js +32 -0
- package/dist/drawer.d.ts +70 -0
- package/dist/drawer.js +158 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +9 -0
- package/dist/field-context.d.ts +47 -0
- package/dist/field-context.js +87 -0
- package/dist/field.d.ts +49 -0
- package/dist/field.js +169 -0
- package/dist/file-input.d.ts +46 -0
- package/dist/file-input.js +170 -0
- package/dist/form-inputs.d.ts +5 -0
- package/dist/form-inputs.js +22 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +16 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +12 -0
- package/dist/hover-card.d.ts +33 -0
- package/dist/hover-card.js +84 -0
- package/dist/image-cropper.d.ts +333 -0
- package/dist/image-cropper.js +37 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +6 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +51 -0
- package/dist/label.d.ts +294 -0
- package/dist/label.js +9 -0
- package/dist/list-items.d.ts +15 -0
- package/dist/list-items.js +39 -0
- package/dist/list-text.d.ts +4 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +56 -0
- package/dist/listbox.js +122 -0
- package/dist/menu.d.ts +116 -0
- package/dist/menu.js +426 -0
- package/dist/menubar-context.d.ts +4 -0
- package/dist/menubar-context.js +7 -0
- package/dist/menubar.d.ts +11 -0
- package/dist/menubar.js +32 -0
- package/dist/meter.d.ts +312 -0
- package/dist/meter.js +30 -0
- package/dist/navigation-menu.d.ts +61 -0
- package/dist/navigation-menu.js +169 -0
- package/dist/number-input.d.ts +44 -0
- package/dist/number-input.js +185 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +40 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +8 -0
- package/dist/otp-input.d.ts +29 -0
- package/dist/otp-input.js +94 -0
- package/dist/overlays.d.ts +26 -0
- package/dist/overlays.js +82 -0
- package/dist/pagination.d.ts +336 -0
- package/dist/pagination.js +71 -0
- package/dist/password-input.d.ts +23 -0
- package/dist/password-input.js +65 -0
- package/dist/popover.d.ts +54 -0
- package/dist/popover.js +151 -0
- package/dist/popup.d.ts +41 -0
- package/dist/popup.js +180 -0
- package/dist/preferences.d.ts +35 -0
- package/dist/preferences.js +93 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +14 -0
- package/dist/progress.d.ts +312 -0
- package/dist/progress.js +30 -0
- package/dist/radio.d.ts +22 -0
- package/dist/radio.js +86 -0
- package/dist/rating.d.ts +20 -0
- package/dist/rating.js +94 -0
- package/dist/render-element.d.ts +35 -0
- package/dist/render-element.js +103 -0
- package/dist/resizable.d.ts +302 -0
- package/dist/resizable.js +23 -0
- package/dist/scroll-area.d.ts +324 -0
- package/dist/scroll-area.js +49 -0
- package/dist/segmented-control.d.ts +24 -0
- package/dist/segmented-control.js +78 -0
- package/dist/segmented-input.d.ts +15 -0
- package/dist/segmented-input.js +48 -0
- package/dist/select.d.ts +125 -0
- package/dist/select.js +330 -0
- package/dist/separator.d.ts +290 -0
- package/dist/separator.js +9 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +61 -0
- package/dist/slider.d.ts +38 -0
- package/dist/slider.js +163 -0
- package/dist/switch.d.ts +15 -0
- package/dist/switch.js +39 -0
- package/dist/tabs.d.ts +331 -0
- package/dist/tabs.js +28 -0
- package/dist/text-control.d.ts +22 -0
- package/dist/text-control.js +24 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +8 -0
- package/dist/textarea.d.ts +10 -0
- package/dist/textarea.js +48 -0
- package/dist/time-input.d.ts +19 -0
- package/dist/time-input.js +63 -0
- package/dist/timeline.d.ts +327 -0
- package/dist/timeline.js +31 -0
- package/dist/toast-parts.d.ts +63 -0
- package/dist/toast-parts.js +144 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +22 -0
- package/dist/toggle.d.ts +23 -0
- package/dist/toggle.js +76 -0
- package/dist/token-input.d.ts +35 -0
- package/dist/token-input.js +100 -0
- package/dist/toolbar-context.d.ts +6 -0
- package/dist/toolbar-context.js +16 -0
- package/dist/toolbar.d.ts +38 -0
- package/dist/toolbar.js +63 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +108 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +150 -0
- package/dist/trigger-menu.d.ts +83 -0
- package/dist/trigger-menu.js +167 -0
- package/dist/use-primitive.d.ts +178 -0
- package/dist/use-primitive.js +674 -0
- package/dist/waterfall.d.ts +80 -0
- package/dist/waterfall.js +108 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1391 -0
- package/docs/components/alert-dialog.md +850 -0
- package/docs/components/autocomplete.md +1963 -0
- package/docs/components/avatar.md +252 -0
- package/docs/components/button.md +444 -0
- package/docs/components/calendar.md +1687 -0
- package/docs/components/carousel.md +1244 -0
- package/docs/components/checkbox.md +1069 -0
- package/docs/components/collapsible.md +567 -0
- package/docs/components/color-picker.md +736 -0
- package/docs/components/combobox.md +3647 -0
- package/docs/components/command.md +1573 -0
- package/docs/components/date-input.md +608 -0
- package/docs/components/date-picker.md +1266 -0
- package/docs/components/dialog.md +1469 -0
- package/docs/components/drawer.md +1197 -0
- package/docs/components/field.md +549 -0
- package/docs/components/file-input.md +609 -0
- package/docs/components/hover-card.md +514 -0
- package/docs/components/image-cropper.md +579 -0
- package/docs/components/input.md +301 -0
- package/docs/components/label.md +217 -0
- package/docs/components/listbox.md +1130 -0
- package/docs/components/menu.md +1286 -0
- package/docs/components/menubar.md +455 -0
- package/docs/components/meter.md +304 -0
- package/docs/components/navigation-menu.md +1581 -0
- package/docs/components/number-input.md +1086 -0
- package/docs/components/otp-input.md +565 -0
- package/docs/components/pagination.md +648 -0
- package/docs/components/password-input.md +737 -0
- package/docs/components/popover.md +1552 -0
- package/docs/components/preferences.md +220 -0
- package/docs/components/progress.md +443 -0
- package/docs/components/radio.md +846 -0
- package/docs/components/rating.md +458 -0
- package/docs/components/resizable.md +982 -0
- package/docs/components/scroll-area.md +980 -0
- package/docs/components/segmented-control.md +465 -0
- package/docs/components/select.md +2133 -0
- package/docs/components/separator.md +243 -0
- package/docs/components/slider.md +1169 -0
- package/docs/components/switch.md +613 -0
- package/docs/components/tabs.md +1014 -0
- package/docs/components/textarea.md +318 -0
- package/docs/components/time-input.md +231 -0
- package/docs/components/timeline.md +677 -0
- package/docs/components/toast.md +1395 -0
- package/docs/components/toggle.md +541 -0
- package/docs/components/token-input.md +1007 -0
- package/docs/components/toolbar.md +787 -0
- package/docs/components/tooltip.md +884 -0
- package/docs/components/tree.md +1346 -0
- package/docs/components/trigger-menu.md +1257 -0
- package/docs/components/waterfall.md +754 -0
- package/docs/controllers.md +89 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +120 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +148 -0
- package/docs/hooks/async-options.md +366 -0
- package/docs/hooks/shortcuts.md +221 -0
- package/docs/installation.md +45 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +170 -0
- package/docs/llms.txt +1844 -0
- package/docs/parts-and-composition.md +93 -0
- package/docs/popups.md +117 -0
- package/docs/rendering.md +121 -0
- package/docs/server-rendering.md +253 -0
- package/docs/state-and-events.md +105 -0
- package/docs/styling-and-animation.md +176 -0
- package/package.json +333 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Lists and Menus
|
|
2
|
+
|
|
3
|
+
Supply options as data, load them from a server, and define menu actions.
|
|
4
|
+
|
|
5
|
+
Select, Combobox, Autocomplete, Listbox, and Trigger Menu accept items as data. Use this when your choices already come from an array. You can also compose their item parts yourself.
|
|
6
|
+
|
|
7
|
+
## Start with Strings
|
|
8
|
+
|
|
9
|
+
Give a Select an array and render its trigger and content:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import {
|
|
13
|
+
Select,
|
|
14
|
+
SelectContent,
|
|
15
|
+
SelectTrigger,
|
|
16
|
+
SelectValue,
|
|
17
|
+
} from "@ui-sdk/react/select"
|
|
18
|
+
|
|
19
|
+
function Example() {
|
|
20
|
+
return (
|
|
21
|
+
<Select items={["Apple", "Banana", "Pear"]}>
|
|
22
|
+
<SelectTrigger aria-label="Fruit">
|
|
23
|
+
<SelectValue placeholder="Choose a fruit" />
|
|
24
|
+
</SelectTrigger>
|
|
25
|
+
<SelectContent />
|
|
26
|
+
</Select>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Example }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each string is both the value and its label. Use objects when those need to differ:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
<Select
|
|
37
|
+
items={[
|
|
38
|
+
{ value: "apple", label: "Apple" },
|
|
39
|
+
{ value: "banana", label: "Banana", disabled: true },
|
|
40
|
+
]}
|
|
41
|
+
>
|
|
42
|
+
{/* Trigger and content. */}
|
|
43
|
+
</Select>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Items can also have `keywords` for searching. Group them with `{ type: "group", label, items }`, or separate them with `{ type: "separator" }`. Type the array with `ListData`, so each entry is checked where you write it:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import type { ListData } from "@ui-sdk/react/select"
|
|
50
|
+
|
|
51
|
+
const fruits: ListData = [
|
|
52
|
+
{ value: "apple", label: "Apple", keywords: ["red"] },
|
|
53
|
+
{ type: "separator" },
|
|
54
|
+
{ type: "group", label: "Citrus", items: ["Lemon", "Lime"] },
|
|
55
|
+
]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Command, Menu and Trigger Menu take the same entries, plus fields of their own like a command's `shortcut`. Type them with `CommandData`, `MenuData` and `TriggerMenuData`. Tree takes `TreeItemData[]`.
|
|
59
|
+
|
|
60
|
+
If the value itself is an object, provide `itemToValue` for its submitted string and `itemToLabel` for its displayed text. [Select](./components/select.md) and [Combobox](./components/combobox.md) show complete examples.
|
|
61
|
+
|
|
62
|
+
## Style the Items
|
|
63
|
+
|
|
64
|
+
Items from data render as bare parts, with no classes, check marks or arrows. To style them, render the parts yourself. For an array you have, map it into items, with your classes inline:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import {
|
|
68
|
+
Select,
|
|
69
|
+
SelectContent,
|
|
70
|
+
SelectItem,
|
|
71
|
+
SelectItemIndicator,
|
|
72
|
+
SelectTrigger,
|
|
73
|
+
SelectValue,
|
|
74
|
+
} from "@ui-sdk/react/select"
|
|
75
|
+
|
|
76
|
+
const fruits = [
|
|
77
|
+
{ value: "apple", label: "Apple" },
|
|
78
|
+
{ value: "banana", label: "Banana" },
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
function Example() {
|
|
82
|
+
return (
|
|
83
|
+
<Select items={fruits}>
|
|
84
|
+
<SelectTrigger aria-label="Fruit">
|
|
85
|
+
<SelectValue placeholder="Choose a fruit" />
|
|
86
|
+
</SelectTrigger>
|
|
87
|
+
<SelectContent className="rounded-2xl bg-white p-1">
|
|
88
|
+
{fruits.map((fruit) => (
|
|
89
|
+
<SelectItem
|
|
90
|
+
key={fruit.value}
|
|
91
|
+
value={fruit.value}
|
|
92
|
+
className="flex rounded-xl px-2 py-1.5 data-highlighted:bg-neutral-100"
|
|
93
|
+
>
|
|
94
|
+
{fruit.label}
|
|
95
|
+
<SelectItemIndicator className="ms-auto">✓</SelectItemIndicator>
|
|
96
|
+
</SelectItem>
|
|
97
|
+
))}
|
|
98
|
+
</SelectContent>
|
|
99
|
+
</Select>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { Example }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Keeping `items` on the select lets it show the chosen label before the list first renders. Searchable components still filter the items you render: the ones that don't match are hidden.
|
|
107
|
+
|
|
108
|
+
Items that only exist in state, like results from a server, render from the list's children function, with `state.items`:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<ComboboxList>
|
|
112
|
+
{(state) =>
|
|
113
|
+
(state.items as { value: string; label: string }[]).map((item) => (
|
|
114
|
+
<ComboboxItem
|
|
115
|
+
key={item.value}
|
|
116
|
+
value={item.value}
|
|
117
|
+
className="rounded-xl px-2 py-1.5 data-highlighted:bg-neutral-100"
|
|
118
|
+
>
|
|
119
|
+
{item.label}
|
|
120
|
+
</ComboboxItem>
|
|
121
|
+
))
|
|
122
|
+
}
|
|
123
|
+
</ComboboxList>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Search and Load Items
|
|
127
|
+
|
|
128
|
+
Searchable components accept a `filter` to change how typing narrows their items. For data from a server, [Async Options](./hooks/async-options.md) handles loading, debouncing, and aborting stale requests.
|
|
129
|
+
|
|
130
|
+
Data lists can virtualize large collections. You don't need to render every item yourself.
|
|
131
|
+
|
|
132
|
+
## Define a Menu
|
|
133
|
+
|
|
134
|
+
A `MenuData` array describes actions, separators, groups, and submenus. A plain string is an action whose value and label are the string:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
"use client"
|
|
138
|
+
|
|
139
|
+
import { Menu, MenuTrigger, type MenuData } from "@ui-sdk/react/menu"
|
|
140
|
+
|
|
141
|
+
const actions: MenuData = [
|
|
142
|
+
{ value: "open", label: "Open", shortcut: "mod+o" },
|
|
143
|
+
{ type: "separator" },
|
|
144
|
+
{
|
|
145
|
+
type: "submenu",
|
|
146
|
+
label: "Share",
|
|
147
|
+
items: [{ value: "email", label: "Email" }],
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
function Example() {
|
|
152
|
+
return (
|
|
153
|
+
<Menu items={actions} onAction={(value) => console.log(value)}>
|
|
154
|
+
<MenuTrigger>File</MenuTrigger>
|
|
155
|
+
</Menu>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { Example }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
To style it, put your own `MenuContent` in the menu and render its items from the same array, as [Menu](./components/menu.md#menus-as-data) shows. That page also covers checkbox items, radio groups, and nested menus.
|
|
163
|
+
|
|
164
|
+
## Keys and Shortcuts
|
|
165
|
+
|
|
166
|
+
`loop` controls whether arrow keys wrap around a list. Components that support `orientation` use it to choose the navigation axis.
|
|
167
|
+
|
|
168
|
+
A trigger's `shortcut="mod+k"` opens it from elsewhere on the page. `mod` means Command on Apple platforms and Control elsewhere. A data menu runs item shortcuts while closed; a manually rendered MenuItem's shortcut only displays the keys.
|
|
169
|
+
|
|
170
|
+
[Shortcuts](./hooks/shortcuts.md) covers registering your own. Page shortcuts pause while a modal is open, and ordinary typing in text fields stays typing.
|