@kenos-ui/react-select 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/index.cjs +1162 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +320 -0
- package/dist/index.d.ts +320 -0
- package/dist/index.js +1158 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { HTMLAttributes, ReactNode, RefObject, ButtonHTMLAttributes } from 'react';
|
|
3
|
+
|
|
4
|
+
interface SelectItemRecord {
|
|
5
|
+
value: string;
|
|
6
|
+
/** Displayed label (from ItemText child). */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Used by typeahead. Defaults to label. */
|
|
9
|
+
textValue: string;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
/** The DOM element for the option — needed for aria-activedescendant. */
|
|
12
|
+
ref: HTMLElement | null;
|
|
13
|
+
groupId: string | null;
|
|
14
|
+
}
|
|
15
|
+
type SelectItemEqualFn = (a: string, b: string) => boolean;
|
|
16
|
+
interface SelectStoreState {
|
|
17
|
+
open: boolean;
|
|
18
|
+
openSource: "trigger" | null;
|
|
19
|
+
value: string | string[] | null;
|
|
20
|
+
highlightedValue: string | null;
|
|
21
|
+
/** Item registry: populated as Select.Item mounts. */
|
|
22
|
+
items: Map<string, SelectItemRecord>;
|
|
23
|
+
}
|
|
24
|
+
interface SelectRootPropsBase {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
/** Controlled open state. */
|
|
27
|
+
open?: boolean | undefined;
|
|
28
|
+
defaultOpen?: boolean | undefined;
|
|
29
|
+
onOpenChange?: ((open: boolean) => void) | undefined;
|
|
30
|
+
/** Fires when open transitions finish (including presence exit). */
|
|
31
|
+
onOpenChangeComplete?: ((open: boolean) => void) | undefined;
|
|
32
|
+
/** Native <select> name for form submission. */
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
disabled?: boolean | undefined;
|
|
35
|
+
required?: boolean | undefined;
|
|
36
|
+
readOnly?: boolean | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* When true, a focus trap + aria-modal is applied.
|
|
39
|
+
* **Default: false** (interop-first per popup-policy).
|
|
40
|
+
*/
|
|
41
|
+
modal?: boolean | undefined;
|
|
42
|
+
/** Unique id prefix (auto-generated when omitted). */
|
|
43
|
+
id?: string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Static value→label map for Value/HiddenSelect when items are not mounted.
|
|
46
|
+
* Registry labels take precedence when both exist.
|
|
47
|
+
*/
|
|
48
|
+
items?: Record<string, string> | undefined;
|
|
49
|
+
/** Custom equality for value matching. Default: strict `===`. */
|
|
50
|
+
isItemEqualToValue?: SelectItemEqualFn | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* When true, focusing the trigger opens the listbox.
|
|
53
|
+
* **Default: false**
|
|
54
|
+
*/
|
|
55
|
+
openOnFocus?: boolean | undefined;
|
|
56
|
+
}
|
|
57
|
+
interface SelectRootPropsSingle extends SelectRootPropsBase {
|
|
58
|
+
multiple?: false | undefined;
|
|
59
|
+
/** Controlled value. */
|
|
60
|
+
value?: string | null | undefined;
|
|
61
|
+
/** Uncontrolled default value. */
|
|
62
|
+
defaultValue?: string | null | undefined;
|
|
63
|
+
onValueChange?: ((value: string | null) => void) | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface SelectRootPropsMultiple extends SelectRootPropsBase {
|
|
66
|
+
multiple: true;
|
|
67
|
+
/** Controlled value. */
|
|
68
|
+
value?: string[] | undefined;
|
|
69
|
+
/** Uncontrolled default value. */
|
|
70
|
+
defaultValue?: string[] | undefined;
|
|
71
|
+
onValueChange?: ((value: string[]) => void) | undefined;
|
|
72
|
+
}
|
|
73
|
+
type SelectRootProps = SelectRootPropsSingle | SelectRootPropsMultiple;
|
|
74
|
+
type SelectPortalContainer = HTMLElement | RefObject<HTMLElement | null> | null;
|
|
75
|
+
interface SelectPortalProps {
|
|
76
|
+
children?: ReactNode;
|
|
77
|
+
/** Portal mount target. Defaults to `document.body`. */
|
|
78
|
+
container?: SelectPortalContainer | undefined;
|
|
79
|
+
}
|
|
80
|
+
interface SelectPositionerProps {
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
side?: "top" | "bottom" | "left" | "right" | undefined;
|
|
83
|
+
align?: "start" | "center" | "end" | undefined;
|
|
84
|
+
sideOffset?: number | undefined;
|
|
85
|
+
alignOffset?: number | undefined;
|
|
86
|
+
avoidCollisions?: boolean | undefined;
|
|
87
|
+
collisionPadding?: number | undefined;
|
|
88
|
+
/** Match the trigger's width. Default: false. */
|
|
89
|
+
sameWidth?: boolean | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* When true, positions content to cover the trigger.
|
|
92
|
+
* For `side="bottom"`, aligns the top of content with the top of the trigger.
|
|
93
|
+
* **Default: false**
|
|
94
|
+
*/
|
|
95
|
+
alignItemWithTrigger?: boolean | undefined;
|
|
96
|
+
}
|
|
97
|
+
interface SelectBackdropProps extends HTMLAttributes<HTMLDivElement> {
|
|
98
|
+
}
|
|
99
|
+
interface SelectClearTriggerProps extends HTMLAttributes<HTMLSpanElement> {
|
|
100
|
+
}
|
|
101
|
+
interface SelectScrollButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
102
|
+
direction: "up" | "down";
|
|
103
|
+
/**
|
|
104
|
+
* Keep the button in the DOM when the list is not scrollable in this direction.
|
|
105
|
+
* **Default: false**
|
|
106
|
+
*/
|
|
107
|
+
keepMounted?: boolean | undefined;
|
|
108
|
+
}
|
|
109
|
+
type SelectScrollUpButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
110
|
+
type SelectScrollDownButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
111
|
+
type ScrollToIndexAlign = "auto" | "start" | "end" | "center" | "nearest";
|
|
112
|
+
interface ScrollToIndexOptions {
|
|
113
|
+
align?: ScrollToIndexAlign | undefined;
|
|
114
|
+
}
|
|
115
|
+
interface SelectContentProps {
|
|
116
|
+
children?: ReactNode;
|
|
117
|
+
/** Force content to stay in the DOM even when closed. */
|
|
118
|
+
forceMount?: boolean | undefined;
|
|
119
|
+
side?: "top" | "bottom" | "left" | "right" | undefined;
|
|
120
|
+
align?: "start" | "center" | "end" | undefined;
|
|
121
|
+
sideOffset?: number | undefined;
|
|
122
|
+
alignOffset?: number | undefined;
|
|
123
|
+
avoidCollisions?: boolean | undefined;
|
|
124
|
+
collisionPadding?: number | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* When true, the content renders in a portal appended to document.body.
|
|
127
|
+
* **Default: false** (interop-first per popup-policy).
|
|
128
|
+
*/
|
|
129
|
+
portal?: boolean | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Portal mount target when `portal` is true.
|
|
132
|
+
* Defaults to `document.body`. Ignored when nested inside `<Select.Portal>`.
|
|
133
|
+
*/
|
|
134
|
+
container?: SelectPortalContainer | undefined;
|
|
135
|
+
/** Match the trigger's width. Default: false. */
|
|
136
|
+
sameWidth?: boolean | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* When true, positions content to cover the trigger.
|
|
139
|
+
* For `side="bottom"`, aligns the top of content with the top of the trigger.
|
|
140
|
+
* **Default: false**
|
|
141
|
+
*/
|
|
142
|
+
alignItemWithTrigger?: boolean | undefined;
|
|
143
|
+
/** Skip DOM until first open. Default: true. */
|
|
144
|
+
lazyMount?: boolean | undefined;
|
|
145
|
+
/** Remove from DOM when closed. Default: false. */
|
|
146
|
+
unmountOnExit?: boolean | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Fires when open transitions finish (including presence exit).
|
|
149
|
+
* Prefer `onOpenChangeComplete` on `<Select.Root>`; this prop overrides the root callback.
|
|
150
|
+
*/
|
|
151
|
+
onOpenChangeComplete?: ((open: boolean) => void) | undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare function Root(props: SelectRootProps): react_jsx_runtime.JSX.Element;
|
|
155
|
+
|
|
156
|
+
type LabelProps = React.LabelHTMLAttributes<HTMLLabelElement>;
|
|
157
|
+
declare function Label({ children, ...props }: LabelProps): react_jsx_runtime.JSX.Element;
|
|
158
|
+
|
|
159
|
+
type TriggerProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "aria-haspopup" | "aria-expanded" | "aria-controls"> & {
|
|
160
|
+
/**
|
|
161
|
+
* When true, focusing the trigger opens the listbox.
|
|
162
|
+
* Overrides `openOnFocus` on `<Select.Root>` when set.
|
|
163
|
+
*/
|
|
164
|
+
openOnFocus?: boolean | undefined;
|
|
165
|
+
};
|
|
166
|
+
declare function Trigger({ children, onClick, onFocus, disabled, openOnFocus: openOnFocusProp, ...props }: TriggerProps): react_jsx_runtime.JSX.Element;
|
|
167
|
+
|
|
168
|
+
interface ValueProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
169
|
+
placeholder?: string | undefined;
|
|
170
|
+
}
|
|
171
|
+
declare function Value({ placeholder, ...props }: ValueProps): react_jsx_runtime.JSX.Element;
|
|
172
|
+
|
|
173
|
+
type IconProps = React.HTMLAttributes<HTMLSpanElement>;
|
|
174
|
+
/** Chevron/arrow slot — render your own icon as children. */
|
|
175
|
+
declare function Icon({ children, ...props }: IconProps): react_jsx_runtime.JSX.Element;
|
|
176
|
+
|
|
177
|
+
declare function Content({ children, forceMount, side, align, sideOffset, alignOffset, avoidCollisions, collisionPadding, portal, container, sameWidth, alignItemWithTrigger, lazyMount, unmountOnExit, onOpenChangeComplete: onOpenChangeCompleteProp, style, onKeyDown, ...props }: SelectContentProps & React.HTMLAttributes<HTMLDivElement>): react_jsx_runtime.JSX.Element | null;
|
|
178
|
+
|
|
179
|
+
declare function Portal({ children, container }: SelectPortalProps): react_jsx_runtime.JSX.Element | null;
|
|
180
|
+
|
|
181
|
+
declare function Positioner({ children, side, align, sideOffset, alignOffset, avoidCollisions, collisionPadding, sameWidth, alignItemWithTrigger, }: SelectPositionerProps): react_jsx_runtime.JSX.Element;
|
|
182
|
+
|
|
183
|
+
declare function Backdrop({ style, ...props }: SelectBackdropProps): react_jsx_runtime.JSX.Element | null;
|
|
184
|
+
|
|
185
|
+
declare function ClearTrigger({ onClick, ...props }: SelectClearTriggerProps): react_jsx_runtime.JSX.Element | null;
|
|
186
|
+
|
|
187
|
+
type ListProps = React.HTMLAttributes<HTMLUListElement> & {
|
|
188
|
+
/**
|
|
189
|
+
* When set, scrolls the list to the item at this index.
|
|
190
|
+
* Useful with virtualization or controlled scroll sync.
|
|
191
|
+
*/
|
|
192
|
+
scrollToIndex?: number | undefined;
|
|
193
|
+
};
|
|
194
|
+
declare function List({ children, scrollToIndex, ...props }: ListProps): react_jsx_runtime.JSX.Element;
|
|
195
|
+
|
|
196
|
+
interface ItemProps extends React.HTMLAttributes<HTMLLIElement> {
|
|
197
|
+
value: string;
|
|
198
|
+
disabled?: boolean | undefined;
|
|
199
|
+
textValue?: string | undefined;
|
|
200
|
+
}
|
|
201
|
+
declare function Item({ value, disabled, textValue, children, onClick, onPointerMove, ...props }: ItemProps): react_jsx_runtime.JSX.Element;
|
|
202
|
+
declare namespace Item {
|
|
203
|
+
var displayName: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
type ItemTextProps = React.HTMLAttributes<HTMLSpanElement>;
|
|
207
|
+
/** Text label for a Select.Item — also used by Select.Value to display the selected label. */
|
|
208
|
+
declare function ItemText({ children, ...props }: ItemTextProps): react_jsx_runtime.JSX.Element;
|
|
209
|
+
|
|
210
|
+
interface ItemIndicatorProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
211
|
+
/** The item value to check — reads from the nearest Item when not provided. */
|
|
212
|
+
value?: string | undefined;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Renders only when the parent item is selected.
|
|
216
|
+
* Wrap a checkmark or any indicator icon as children.
|
|
217
|
+
*/
|
|
218
|
+
declare function ItemIndicator({ value, children, style, ...props }: ItemIndicatorProps): react_jsx_runtime.JSX.Element;
|
|
219
|
+
|
|
220
|
+
type GroupProps = React.HTMLAttributes<HTMLDivElement>;
|
|
221
|
+
declare function Group({ children, ...props }: GroupProps): react_jsx_runtime.JSX.Element;
|
|
222
|
+
|
|
223
|
+
type GroupLabelProps = React.HTMLAttributes<HTMLDivElement>;
|
|
224
|
+
declare function GroupLabel({ children, ...props }: GroupLabelProps): react_jsx_runtime.JSX.Element;
|
|
225
|
+
|
|
226
|
+
declare function HiddenSelect(): react_jsx_runtime.JSX.Element | null;
|
|
227
|
+
|
|
228
|
+
type ScrollUpButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
229
|
+
declare function ScrollUpButton(props: ScrollUpButtonProps): react_jsx_runtime.JSX.Element;
|
|
230
|
+
|
|
231
|
+
type ScrollDownButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
232
|
+
declare function ScrollDownButton(props: ScrollDownButtonProps): react_jsx_runtime.JSX.Element;
|
|
233
|
+
|
|
234
|
+
declare const index_parts_Backdrop: typeof Backdrop;
|
|
235
|
+
declare const index_parts_ClearTrigger: typeof ClearTrigger;
|
|
236
|
+
declare const index_parts_Content: typeof Content;
|
|
237
|
+
declare const index_parts_Group: typeof Group;
|
|
238
|
+
declare const index_parts_GroupLabel: typeof GroupLabel;
|
|
239
|
+
declare const index_parts_HiddenSelect: typeof HiddenSelect;
|
|
240
|
+
declare const index_parts_Icon: typeof Icon;
|
|
241
|
+
declare const index_parts_Item: typeof Item;
|
|
242
|
+
declare const index_parts_ItemIndicator: typeof ItemIndicator;
|
|
243
|
+
declare const index_parts_ItemText: typeof ItemText;
|
|
244
|
+
declare const index_parts_Label: typeof Label;
|
|
245
|
+
declare const index_parts_List: typeof List;
|
|
246
|
+
declare const index_parts_Portal: typeof Portal;
|
|
247
|
+
declare const index_parts_Positioner: typeof Positioner;
|
|
248
|
+
declare const index_parts_Root: typeof Root;
|
|
249
|
+
declare const index_parts_ScrollDownButton: typeof ScrollDownButton;
|
|
250
|
+
declare const index_parts_ScrollUpButton: typeof ScrollUpButton;
|
|
251
|
+
declare const index_parts_Trigger: typeof Trigger;
|
|
252
|
+
declare const index_parts_Value: typeof Value;
|
|
253
|
+
declare namespace index_parts {
|
|
254
|
+
export { index_parts_Backdrop as Backdrop, index_parts_ClearTrigger as ClearTrigger, index_parts_Content as Content, index_parts_Group as Group, index_parts_GroupLabel as GroupLabel, index_parts_HiddenSelect as HiddenSelect, index_parts_Icon as Icon, index_parts_Item as Item, index_parts_ItemIndicator as ItemIndicator, index_parts_ItemText as ItemText, index_parts_Label as Label, index_parts_List as List, index_parts_Portal as Portal, index_parts_Positioner as Positioner, index_parts_Root as Root, index_parts_ScrollDownButton as ScrollDownButton, index_parts_ScrollUpButton as ScrollUpButton, index_parts_Trigger as Trigger, index_parts_Value as Value };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare function scrollToIndexInState(state: SelectStoreState, index: number, options?: ScrollToIndexOptions): void;
|
|
258
|
+
|
|
259
|
+
type Listener = () => void;
|
|
260
|
+
declare class SelectStore {
|
|
261
|
+
private state;
|
|
262
|
+
private listeners;
|
|
263
|
+
constructor(initial?: Partial<SelectStoreState>);
|
|
264
|
+
getState(): SelectStoreState;
|
|
265
|
+
subscribe(listener: Listener): () => void;
|
|
266
|
+
private notify;
|
|
267
|
+
setOpen(open: boolean, source?: "trigger" | null): void;
|
|
268
|
+
setValue(value: string | null): void;
|
|
269
|
+
setValues(values: string[]): void;
|
|
270
|
+
toggleValue(value: string, comparator: SelectItemEqualFn): void;
|
|
271
|
+
clearValue(multiple: boolean): void;
|
|
272
|
+
isSelected(value: string, multiple: boolean, comparator: SelectItemEqualFn): boolean;
|
|
273
|
+
setHighlightedValue(value: string | null): void;
|
|
274
|
+
registerItem(record: SelectItemRecord): void;
|
|
275
|
+
unregisterItem(value: string): void;
|
|
276
|
+
updateItemRef(value: string, ref: HTMLElement | null): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface SelectRefs {
|
|
280
|
+
triggerRef: RefObject<HTMLButtonElement | null>;
|
|
281
|
+
contentRef: RefObject<HTMLDivElement | null>;
|
|
282
|
+
listRef: RefObject<HTMLUListElement | null>;
|
|
283
|
+
}
|
|
284
|
+
interface SelectContextValue {
|
|
285
|
+
store: SelectStore;
|
|
286
|
+
ids: {
|
|
287
|
+
root: string;
|
|
288
|
+
label: string;
|
|
289
|
+
trigger: string;
|
|
290
|
+
content: string;
|
|
291
|
+
};
|
|
292
|
+
refs: SelectRefs;
|
|
293
|
+
config: {
|
|
294
|
+
disabled: boolean;
|
|
295
|
+
required: boolean;
|
|
296
|
+
readOnly: boolean;
|
|
297
|
+
modal: boolean;
|
|
298
|
+
name: string | undefined;
|
|
299
|
+
multiple: boolean;
|
|
300
|
+
items: Record<string, string>;
|
|
301
|
+
isItemEqualToValue: SelectItemEqualFn;
|
|
302
|
+
openOnFocus: boolean;
|
|
303
|
+
};
|
|
304
|
+
isControlledOpen: boolean;
|
|
305
|
+
isControlledValue: boolean;
|
|
306
|
+
onOpenChangeComplete: ((open: boolean) => void) | undefined;
|
|
307
|
+
/** Close the listbox and restore focus to the trigger. */
|
|
308
|
+
close: () => void;
|
|
309
|
+
/** Select a value (toggle in multiple mode, set + close in single mode). */
|
|
310
|
+
selectValue: (value: string) => void;
|
|
311
|
+
/** Alias for selectValue — kept for backward compatibility. */
|
|
312
|
+
selectAndClose: (value: string) => void;
|
|
313
|
+
/** Clear the current selection. */
|
|
314
|
+
clearValue: () => void;
|
|
315
|
+
/** Scroll the list to the item at the given index. */
|
|
316
|
+
scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void;
|
|
317
|
+
}
|
|
318
|
+
declare function useSelectContext(): SelectContextValue;
|
|
319
|
+
|
|
320
|
+
export { type ScrollToIndexAlign, type ScrollToIndexOptions, index_parts as Select, type SelectContentProps, type SelectContextValue, type SelectItemRecord, type SelectRootProps, type SelectScrollDownButtonProps, type SelectScrollUpButtonProps, type SelectStoreState, scrollToIndexInState, useSelectContext };
|