@bento/listbox 0.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.
@@ -0,0 +1,264 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { Slots } from '@bento/slots';
3
+ import { LinkDOMProps, HoverEvents, Key } from '@react-types/shared';
4
+ import { SelectionBehavior, ListState, Orientation } from 'react-stately';
5
+ import { AriaListBoxProps } from '@react-types/listbox';
6
+ export { Collection } from '@react-aria/collections';
7
+
8
+ /**
9
+ * Props for the Header component.
10
+ * @interface HeaderProps
11
+ */
12
+ interface HeaderProps extends Slots, React.ComponentProps<'header'> {
13
+ /**
14
+ * The children of the header.
15
+ */
16
+ readonly children?: React.ReactNode;
17
+ }
18
+ /**
19
+ * Context value structure for Header components.
20
+ * Extends HTML attributes to support all standard header element properties.
21
+ * @interface HeaderContextValue
22
+ */
23
+ interface HeaderContextValue extends React.HTMLAttributes<HTMLElement> {
24
+ /**
25
+ * Reference to the header element for forwarding.
26
+ */
27
+ readonly ref?: React.RefObject<HTMLDivElement>;
28
+ }
29
+ /**
30
+ * React context for providing header-related attributes and refs to Header components.
31
+ * Used internally by ListBoxSection to pass heading props to Header elements.
32
+ * @public
33
+ */
34
+ declare const HeaderContext: React.Context<HeaderContextValue>;
35
+ /**
36
+ * A Header component for section headings within a ListBox.
37
+ * Provides semantic header structure with proper accessibility attributes
38
+ * and integrates with React Aria's collection system for automatic handling.
39
+ *
40
+ * This is the main public interface for creating headers in ListBox sections.
41
+ * It automatically receives heading props from the parent ListBoxSection via HeaderContext.
42
+ *
43
+ * @component
44
+ * @example
45
+ * ```tsx
46
+ * <ListBoxSection>
47
+ * <Header>Fruits</Header>
48
+ * <ListBoxItem>Apple</ListBoxItem>
49
+ * <ListBoxItem>Banana</ListBoxItem>
50
+ * </ListBoxSection>
51
+ * ```
52
+ * @public
53
+ */
54
+ declare const Header: React.ForwardRefExoticComponent<HeaderProps & React.RefAttributes<HTMLElement>>;
55
+
56
+ /**
57
+ * Render props provided to ListBoxItem render functions.
58
+ * @interface ListBoxItemRenderProps
59
+ */
60
+ interface ListBoxItemRenderProps {
61
+ /**
62
+ * Whether the item is currently hovered.
63
+ * @selector [data-hovered]
64
+ */
65
+ readonly isHovered: boolean;
66
+ /**
67
+ * Whether the item is currently pressed.
68
+ * @selector [data-pressed]
69
+ */
70
+ readonly isPressed: boolean;
71
+ /**
72
+ * Whether the item is currently selected.
73
+ * @selector [data-selected]
74
+ */
75
+ readonly isSelected: boolean;
76
+ /**
77
+ * Whether the item is currently focused.
78
+ * @selector [data-focused]
79
+ */
80
+ readonly isFocused: boolean;
81
+ /**
82
+ * Whether the item is currently keyboard focused.
83
+ * @selector [data-focus-visible]
84
+ */
85
+ readonly isFocusVisible: boolean;
86
+ /**
87
+ * Whether the item is disabled.
88
+ * @selector [data-disabled]
89
+ */
90
+ readonly isDisabled: boolean;
91
+ /**
92
+ * The type of selection that is allowed in the collection.
93
+ * @selector [data-selection-mode="none | single | multiple"]
94
+ */
95
+ readonly selectionMode: 'none' | 'single' | 'multiple';
96
+ /**
97
+ * The selection behavior for the collection.
98
+ * @selector [data-selection-behavior="toggle | replace"]
99
+ */
100
+ readonly selectionBehavior: 'toggle' | 'replace';
101
+ }
102
+ /**
103
+ * Props for the ListBoxItem component.
104
+ * @interface ListBoxItemProps
105
+ * @template T The type of the item value
106
+ */
107
+ interface ListBoxItemProps<T = object> extends LinkDOMProps, HoverEvents, Omit<React.HTMLAttributes<HTMLElement>, keyof LinkDOMProps | keyof HoverEvents | 'id' | 'children'> {
108
+ /** The unique id of the item. If not provided, React Aria will auto-generate one. */
109
+ readonly id?: Key;
110
+ /** The object value that this item represents. When using dynamic collections, this is set automatically. */
111
+ readonly value?: T;
112
+ /** A string representation of the item's contents, used for features like typeahead. If not provided, React Aria will derive it from children automatically. */
113
+ readonly textValue?: string;
114
+ /**
115
+ * Handler that is called when a user performs an action on the item. The exact user event depends on the
116
+ * collection's `selectionBehavior` prop and the interaction modality.
117
+ */
118
+ readonly onAction?: () => void;
119
+ /** The contents of the item. Can be a render function that receives render props. */
120
+ readonly children?: ReactNode | ((values: ListBoxItemRenderProps) => ReactNode);
121
+ /**
122
+ * A slot name for the component. Used by Bento's slot system.
123
+ */
124
+ readonly slot?: string;
125
+ /** Whether the item is disabled. */
126
+ readonly isDisabled?: boolean;
127
+ }
128
+ /**
129
+ * A single item within a ListBox component.
130
+ * Handles user interactions, accessibility, and state management for individual options.
131
+ *
132
+ * @component
133
+ * @template T The type of the item value
134
+ * @example
135
+ * ```tsx
136
+ * <ListBoxItem>Simple option</ListBoxItem>
137
+ * ```
138
+ * @public
139
+ */
140
+ declare const ListBoxItem: <T extends object>(props: ListBoxItemProps<T> & React.RefAttributes<T>) => React.ReactElement | null;
141
+
142
+ /**
143
+ * Render props provided to ListBox render functions and empty state renderers.
144
+ * @interface ListBoxRenderProps
145
+ */
146
+ interface ListBoxRenderProps {
147
+ /**
148
+ * Whether the listbox has no items and should display its empty state.
149
+ * @selector [data-empty]
150
+ */
151
+ readonly isEmpty: boolean;
152
+ /**
153
+ * Whether the listbox is currently focused.
154
+ * @selector [data-focused]
155
+ */
156
+ readonly isFocused: boolean;
157
+ /**
158
+ * Whether the listbox is currently keyboard focused.
159
+ * @selector [data-focus-visible]
160
+ */
161
+ readonly isFocusVisible: boolean;
162
+ /**
163
+ * Whether the listbox is currently the active drop target.
164
+ * @selector [data-drop-target]
165
+ */
166
+ readonly isDropTarget: boolean;
167
+ /**
168
+ * Whether the items are arranged in a stack or grid.
169
+ * @selector [data-layout="stack | grid"]
170
+ */
171
+ readonly layout?: 'stack' | 'grid';
172
+ /**
173
+ * State of the listbox.
174
+ */
175
+ readonly state: ListState<unknown>;
176
+ /**
177
+ * The items array when using dynamic collections.
178
+ */
179
+ readonly items?: Iterable<unknown>;
180
+ }
181
+ /**
182
+ * Props for the ListBox component.
183
+ * @interface ListBoxProps
184
+ * @template T The type of items in the collection
185
+ */
186
+ interface ListBoxProps<T> extends Omit<AriaListBoxProps<T>, 'label' | 'children'>, Omit<React.ComponentProps<'div'>, keyof AriaListBoxProps<T> | 'children'>, Slots {
187
+ /**
188
+ * How multiple selection should behave in the collection.
189
+ */
190
+ readonly selectionBehavior?: SelectionBehavior;
191
+ /**
192
+ * Provides content to display when there are no items in the list.
193
+ */
194
+ readonly renderEmptyState?: (props: ListBoxRenderProps) => React.ReactNode;
195
+ /**
196
+ * Whether the items are arranged in a stack layout.
197
+ * @default 'stack'
198
+ */
199
+ readonly layout?: 'stack';
200
+ /**
201
+ * The primary orientation of the items. Usually this is the direction that the collection scrolls.
202
+ * @default 'vertical'
203
+ */
204
+ readonly orientation?: Orientation;
205
+ /**
206
+ * Static children or render function for the ListBox.
207
+ * When items prop is provided, children receives individual items for React Aria compatibility.
208
+ * When no items prop is provided, children receives Bento render props { isEmpty, isFocused, state, etc. }.
209
+ */
210
+ readonly children?: React.ReactNode | ((item: T) => React.ReactNode) | ((props: ListBoxRenderProps) => React.ReactNode);
211
+ }
212
+ /**
213
+ * A complete ListBox component providing accessible selection lists with keyboard navigation.
214
+ * Supports both static children and dynamic collections, with single/multiple selection modes.
215
+ * Built on React Aria with full ARIA compliance and keyboard accessibility.
216
+ *
217
+ * @component
218
+ * @example
219
+ * ```tsx
220
+ * <ListBox aria-label="Fruits" selectionMode="single">
221
+ * <ListBoxItem id="apple" textValue="Apple">Apple</ListBoxItem>
222
+ * <ListBoxItem id="banana" textValue="Banana">Banana</ListBoxItem>
223
+ * </ListBox>
224
+ * ```
225
+ * @public
226
+ */
227
+ declare const ListBox: React.NamedExoticComponent<ListBoxProps<unknown> & Slots>;
228
+
229
+ /**
230
+ * Props for the ListBoxSection component.
231
+ * @interface ListBoxSectionProps
232
+ */
233
+ interface ListBoxSectionProps extends Omit<React.ComponentProps<'section'>, 'title'> {
234
+ /**
235
+ * A slot name for the component. Used by Bento's slot system.
236
+ */
237
+ readonly slot?: string;
238
+ /**
239
+ * The title of the section.
240
+ */
241
+ readonly title?: React.ReactNode;
242
+ /**
243
+ * The children of the section.
244
+ */
245
+ readonly children?: React.ReactNode;
246
+ }
247
+ /**
248
+ * A section component for organizing related items within a ListBox.
249
+ *
250
+ * @component
251
+ * @example
252
+ * ```tsx
253
+ * <ListBoxSection title="Fruits">
254
+ * <ListBoxItem>Apple</ListBoxItem>
255
+ * <ListBoxItem>Banana</ListBoxItem>
256
+ * </ListBoxSection>
257
+ * ```
258
+ * @public
259
+ */
260
+ declare const ListBoxSection: <_T extends object>(props: ListBoxSectionProps & {
261
+ children?: React.ReactNode;
262
+ }) => React.ReactElement;
263
+
264
+ export { Header, HeaderContext, type HeaderProps, ListBox, ListBoxItem, type ListBoxItemProps, type ListBoxItemRenderProps, type ListBoxProps, type ListBoxRenderProps, ListBoxSection, type ListBoxSectionProps };
@@ -0,0 +1,264 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { Slots } from '@bento/slots';
3
+ import { LinkDOMProps, HoverEvents, Key } from '@react-types/shared';
4
+ import { SelectionBehavior, ListState, Orientation } from 'react-stately';
5
+ import { AriaListBoxProps } from '@react-types/listbox';
6
+ export { Collection } from '@react-aria/collections';
7
+
8
+ /**
9
+ * Props for the Header component.
10
+ * @interface HeaderProps
11
+ */
12
+ interface HeaderProps extends Slots, React.ComponentProps<'header'> {
13
+ /**
14
+ * The children of the header.
15
+ */
16
+ readonly children?: React.ReactNode;
17
+ }
18
+ /**
19
+ * Context value structure for Header components.
20
+ * Extends HTML attributes to support all standard header element properties.
21
+ * @interface HeaderContextValue
22
+ */
23
+ interface HeaderContextValue extends React.HTMLAttributes<HTMLElement> {
24
+ /**
25
+ * Reference to the header element for forwarding.
26
+ */
27
+ readonly ref?: React.RefObject<HTMLDivElement>;
28
+ }
29
+ /**
30
+ * React context for providing header-related attributes and refs to Header components.
31
+ * Used internally by ListBoxSection to pass heading props to Header elements.
32
+ * @public
33
+ */
34
+ declare const HeaderContext: React.Context<HeaderContextValue>;
35
+ /**
36
+ * A Header component for section headings within a ListBox.
37
+ * Provides semantic header structure with proper accessibility attributes
38
+ * and integrates with React Aria's collection system for automatic handling.
39
+ *
40
+ * This is the main public interface for creating headers in ListBox sections.
41
+ * It automatically receives heading props from the parent ListBoxSection via HeaderContext.
42
+ *
43
+ * @component
44
+ * @example
45
+ * ```tsx
46
+ * <ListBoxSection>
47
+ * <Header>Fruits</Header>
48
+ * <ListBoxItem>Apple</ListBoxItem>
49
+ * <ListBoxItem>Banana</ListBoxItem>
50
+ * </ListBoxSection>
51
+ * ```
52
+ * @public
53
+ */
54
+ declare const Header: React.ForwardRefExoticComponent<HeaderProps & React.RefAttributes<HTMLElement>>;
55
+
56
+ /**
57
+ * Render props provided to ListBoxItem render functions.
58
+ * @interface ListBoxItemRenderProps
59
+ */
60
+ interface ListBoxItemRenderProps {
61
+ /**
62
+ * Whether the item is currently hovered.
63
+ * @selector [data-hovered]
64
+ */
65
+ readonly isHovered: boolean;
66
+ /**
67
+ * Whether the item is currently pressed.
68
+ * @selector [data-pressed]
69
+ */
70
+ readonly isPressed: boolean;
71
+ /**
72
+ * Whether the item is currently selected.
73
+ * @selector [data-selected]
74
+ */
75
+ readonly isSelected: boolean;
76
+ /**
77
+ * Whether the item is currently focused.
78
+ * @selector [data-focused]
79
+ */
80
+ readonly isFocused: boolean;
81
+ /**
82
+ * Whether the item is currently keyboard focused.
83
+ * @selector [data-focus-visible]
84
+ */
85
+ readonly isFocusVisible: boolean;
86
+ /**
87
+ * Whether the item is disabled.
88
+ * @selector [data-disabled]
89
+ */
90
+ readonly isDisabled: boolean;
91
+ /**
92
+ * The type of selection that is allowed in the collection.
93
+ * @selector [data-selection-mode="none | single | multiple"]
94
+ */
95
+ readonly selectionMode: 'none' | 'single' | 'multiple';
96
+ /**
97
+ * The selection behavior for the collection.
98
+ * @selector [data-selection-behavior="toggle | replace"]
99
+ */
100
+ readonly selectionBehavior: 'toggle' | 'replace';
101
+ }
102
+ /**
103
+ * Props for the ListBoxItem component.
104
+ * @interface ListBoxItemProps
105
+ * @template T The type of the item value
106
+ */
107
+ interface ListBoxItemProps<T = object> extends LinkDOMProps, HoverEvents, Omit<React.HTMLAttributes<HTMLElement>, keyof LinkDOMProps | keyof HoverEvents | 'id' | 'children'> {
108
+ /** The unique id of the item. If not provided, React Aria will auto-generate one. */
109
+ readonly id?: Key;
110
+ /** The object value that this item represents. When using dynamic collections, this is set automatically. */
111
+ readonly value?: T;
112
+ /** A string representation of the item's contents, used for features like typeahead. If not provided, React Aria will derive it from children automatically. */
113
+ readonly textValue?: string;
114
+ /**
115
+ * Handler that is called when a user performs an action on the item. The exact user event depends on the
116
+ * collection's `selectionBehavior` prop and the interaction modality.
117
+ */
118
+ readonly onAction?: () => void;
119
+ /** The contents of the item. Can be a render function that receives render props. */
120
+ readonly children?: ReactNode | ((values: ListBoxItemRenderProps) => ReactNode);
121
+ /**
122
+ * A slot name for the component. Used by Bento's slot system.
123
+ */
124
+ readonly slot?: string;
125
+ /** Whether the item is disabled. */
126
+ readonly isDisabled?: boolean;
127
+ }
128
+ /**
129
+ * A single item within a ListBox component.
130
+ * Handles user interactions, accessibility, and state management for individual options.
131
+ *
132
+ * @component
133
+ * @template T The type of the item value
134
+ * @example
135
+ * ```tsx
136
+ * <ListBoxItem>Simple option</ListBoxItem>
137
+ * ```
138
+ * @public
139
+ */
140
+ declare const ListBoxItem: <T extends object>(props: ListBoxItemProps<T> & React.RefAttributes<T>) => React.ReactElement | null;
141
+
142
+ /**
143
+ * Render props provided to ListBox render functions and empty state renderers.
144
+ * @interface ListBoxRenderProps
145
+ */
146
+ interface ListBoxRenderProps {
147
+ /**
148
+ * Whether the listbox has no items and should display its empty state.
149
+ * @selector [data-empty]
150
+ */
151
+ readonly isEmpty: boolean;
152
+ /**
153
+ * Whether the listbox is currently focused.
154
+ * @selector [data-focused]
155
+ */
156
+ readonly isFocused: boolean;
157
+ /**
158
+ * Whether the listbox is currently keyboard focused.
159
+ * @selector [data-focus-visible]
160
+ */
161
+ readonly isFocusVisible: boolean;
162
+ /**
163
+ * Whether the listbox is currently the active drop target.
164
+ * @selector [data-drop-target]
165
+ */
166
+ readonly isDropTarget: boolean;
167
+ /**
168
+ * Whether the items are arranged in a stack or grid.
169
+ * @selector [data-layout="stack | grid"]
170
+ */
171
+ readonly layout?: 'stack' | 'grid';
172
+ /**
173
+ * State of the listbox.
174
+ */
175
+ readonly state: ListState<unknown>;
176
+ /**
177
+ * The items array when using dynamic collections.
178
+ */
179
+ readonly items?: Iterable<unknown>;
180
+ }
181
+ /**
182
+ * Props for the ListBox component.
183
+ * @interface ListBoxProps
184
+ * @template T The type of items in the collection
185
+ */
186
+ interface ListBoxProps<T> extends Omit<AriaListBoxProps<T>, 'label' | 'children'>, Omit<React.ComponentProps<'div'>, keyof AriaListBoxProps<T> | 'children'>, Slots {
187
+ /**
188
+ * How multiple selection should behave in the collection.
189
+ */
190
+ readonly selectionBehavior?: SelectionBehavior;
191
+ /**
192
+ * Provides content to display when there are no items in the list.
193
+ */
194
+ readonly renderEmptyState?: (props: ListBoxRenderProps) => React.ReactNode;
195
+ /**
196
+ * Whether the items are arranged in a stack layout.
197
+ * @default 'stack'
198
+ */
199
+ readonly layout?: 'stack';
200
+ /**
201
+ * The primary orientation of the items. Usually this is the direction that the collection scrolls.
202
+ * @default 'vertical'
203
+ */
204
+ readonly orientation?: Orientation;
205
+ /**
206
+ * Static children or render function for the ListBox.
207
+ * When items prop is provided, children receives individual items for React Aria compatibility.
208
+ * When no items prop is provided, children receives Bento render props { isEmpty, isFocused, state, etc. }.
209
+ */
210
+ readonly children?: React.ReactNode | ((item: T) => React.ReactNode) | ((props: ListBoxRenderProps) => React.ReactNode);
211
+ }
212
+ /**
213
+ * A complete ListBox component providing accessible selection lists with keyboard navigation.
214
+ * Supports both static children and dynamic collections, with single/multiple selection modes.
215
+ * Built on React Aria with full ARIA compliance and keyboard accessibility.
216
+ *
217
+ * @component
218
+ * @example
219
+ * ```tsx
220
+ * <ListBox aria-label="Fruits" selectionMode="single">
221
+ * <ListBoxItem id="apple" textValue="Apple">Apple</ListBoxItem>
222
+ * <ListBoxItem id="banana" textValue="Banana">Banana</ListBoxItem>
223
+ * </ListBox>
224
+ * ```
225
+ * @public
226
+ */
227
+ declare const ListBox: React.NamedExoticComponent<ListBoxProps<unknown> & Slots>;
228
+
229
+ /**
230
+ * Props for the ListBoxSection component.
231
+ * @interface ListBoxSectionProps
232
+ */
233
+ interface ListBoxSectionProps extends Omit<React.ComponentProps<'section'>, 'title'> {
234
+ /**
235
+ * A slot name for the component. Used by Bento's slot system.
236
+ */
237
+ readonly slot?: string;
238
+ /**
239
+ * The title of the section.
240
+ */
241
+ readonly title?: React.ReactNode;
242
+ /**
243
+ * The children of the section.
244
+ */
245
+ readonly children?: React.ReactNode;
246
+ }
247
+ /**
248
+ * A section component for organizing related items within a ListBox.
249
+ *
250
+ * @component
251
+ * @example
252
+ * ```tsx
253
+ * <ListBoxSection title="Fruits">
254
+ * <ListBoxItem>Apple</ListBoxItem>
255
+ * <ListBoxItem>Banana</ListBoxItem>
256
+ * </ListBoxSection>
257
+ * ```
258
+ * @public
259
+ */
260
+ declare const ListBoxSection: <_T extends object>(props: ListBoxSectionProps & {
261
+ children?: React.ReactNode;
262
+ }) => React.ReactElement;
263
+
264
+ export { Header, HeaderContext, type HeaderProps, ListBox, ListBoxItem, type ListBoxItemProps, type ListBoxItemRenderProps, type ListBoxProps, type ListBoxRenderProps, ListBoxSection, type ListBoxSectionProps };