@kenos-ui/react-select 0.2.1 → 0.2.3
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 +48 -0
- package/README.md +17 -17
- package/dist/index.cjs +24 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +24 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import React, { HTMLAttributes, ReactNode, RefObject, ButtonHTMLAttributes } from 'react';
|
|
3
2
|
|
|
4
3
|
interface SelectItemRecord {
|
|
@@ -151,10 +150,10 @@ interface SelectContentProps {
|
|
|
151
150
|
onOpenChangeComplete?: ((open: boolean) => void) | undefined;
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
declare function Root(props: SelectRootProps):
|
|
153
|
+
declare function Root(props: SelectRootProps): React.JSX.Element;
|
|
155
154
|
|
|
156
155
|
type LabelProps = React.LabelHTMLAttributes<HTMLLabelElement>;
|
|
157
|
-
declare function Label({ children, ...props }: LabelProps):
|
|
156
|
+
declare function Label({ children, ...props }: LabelProps): React.JSX.Element;
|
|
158
157
|
|
|
159
158
|
type TriggerProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "aria-haspopup" | "aria-expanded" | "aria-controls"> & {
|
|
160
159
|
/**
|
|
@@ -163,26 +162,26 @@ type TriggerProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "aria-ha
|
|
|
163
162
|
*/
|
|
164
163
|
openOnFocus?: boolean | undefined;
|
|
165
164
|
};
|
|
166
|
-
declare function Trigger({ children, onClick, onFocus, disabled, openOnFocus: openOnFocusProp, ...props }: TriggerProps):
|
|
165
|
+
declare function Trigger({ children, onClick, onFocus, disabled, openOnFocus: openOnFocusProp, ...props }: TriggerProps): React.JSX.Element;
|
|
167
166
|
|
|
168
167
|
interface ValueProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
169
168
|
placeholder?: string | undefined;
|
|
170
169
|
}
|
|
171
|
-
declare function Value({ placeholder, ...props }: ValueProps):
|
|
170
|
+
declare function Value({ placeholder, ...props }: ValueProps): React.JSX.Element;
|
|
172
171
|
|
|
173
172
|
type IconProps = React.HTMLAttributes<HTMLSpanElement>;
|
|
174
173
|
/** Chevron/arrow slot — render your own icon as children. */
|
|
175
|
-
declare function Icon({ children, ...props }: IconProps):
|
|
174
|
+
declare function Icon({ children, ...props }: IconProps): React.JSX.Element;
|
|
176
175
|
|
|
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>):
|
|
176
|
+
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.Element | null;
|
|
178
177
|
|
|
179
|
-
declare function Portal({ children, container }: SelectPortalProps):
|
|
178
|
+
declare function Portal({ children, container }: SelectPortalProps): React.JSX.Element | null;
|
|
180
179
|
|
|
181
|
-
declare function Positioner({ children, side, align, sideOffset, alignOffset, avoidCollisions, collisionPadding, sameWidth, alignItemWithTrigger, }: SelectPositionerProps):
|
|
180
|
+
declare function Positioner({ children, side, align, sideOffset, alignOffset, avoidCollisions, collisionPadding, sameWidth, alignItemWithTrigger, }: SelectPositionerProps): React.JSX.Element;
|
|
182
181
|
|
|
183
|
-
declare function Backdrop({ style, ...props }: SelectBackdropProps):
|
|
182
|
+
declare function Backdrop({ style, ...props }: SelectBackdropProps): React.JSX.Element | null;
|
|
184
183
|
|
|
185
|
-
declare function ClearTrigger({ onClick, ...props }: SelectClearTriggerProps):
|
|
184
|
+
declare function ClearTrigger({ onClick, ...props }: SelectClearTriggerProps): React.JSX.Element | null;
|
|
186
185
|
|
|
187
186
|
type ListProps = React.HTMLAttributes<HTMLUListElement> & {
|
|
188
187
|
/**
|
|
@@ -191,21 +190,21 @@ type ListProps = React.HTMLAttributes<HTMLUListElement> & {
|
|
|
191
190
|
*/
|
|
192
191
|
scrollToIndex?: number | undefined;
|
|
193
192
|
};
|
|
194
|
-
declare function List({ children, scrollToIndex, ...props }: ListProps):
|
|
193
|
+
declare function List({ children, scrollToIndex, ...props }: ListProps): React.JSX.Element;
|
|
195
194
|
|
|
196
195
|
interface ItemProps extends React.HTMLAttributes<HTMLLIElement> {
|
|
197
196
|
value: string;
|
|
198
197
|
disabled?: boolean | undefined;
|
|
199
198
|
textValue?: string | undefined;
|
|
200
199
|
}
|
|
201
|
-
declare function Item({ value, disabled, textValue, children, onClick, onPointerMove, ...props }: ItemProps):
|
|
200
|
+
declare function Item({ value, disabled, textValue, children, onClick, onPointerMove, ...props }: ItemProps): React.JSX.Element;
|
|
202
201
|
declare namespace Item {
|
|
203
202
|
var displayName: string;
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
type ItemTextProps = React.HTMLAttributes<HTMLSpanElement>;
|
|
207
206
|
/** Text label for a Select.Item — also used by Select.Value to display the selected label. */
|
|
208
|
-
declare function ItemText({ children, ...props }: ItemTextProps):
|
|
207
|
+
declare function ItemText({ children, ...props }: ItemTextProps): React.JSX.Element;
|
|
209
208
|
|
|
210
209
|
interface ItemIndicatorProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
211
210
|
/** The item value to check — reads from the nearest Item when not provided. */
|
|
@@ -215,21 +214,21 @@ interface ItemIndicatorProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
|
215
214
|
* Renders only when the parent item is selected.
|
|
216
215
|
* Wrap a checkmark or any indicator icon as children.
|
|
217
216
|
*/
|
|
218
|
-
declare function ItemIndicator({ value, children, style, ...props }: ItemIndicatorProps):
|
|
217
|
+
declare function ItemIndicator({ value, children, style, ...props }: ItemIndicatorProps): React.JSX.Element;
|
|
219
218
|
|
|
220
219
|
type GroupProps = React.HTMLAttributes<HTMLDivElement>;
|
|
221
|
-
declare function Group({ children, ...props }: GroupProps):
|
|
220
|
+
declare function Group({ children, ...props }: GroupProps): React.JSX.Element;
|
|
222
221
|
|
|
223
222
|
type GroupLabelProps = React.HTMLAttributes<HTMLDivElement>;
|
|
224
|
-
declare function GroupLabel({ children, ...props }: GroupLabelProps):
|
|
223
|
+
declare function GroupLabel({ children, ...props }: GroupLabelProps): React.JSX.Element;
|
|
225
224
|
|
|
226
|
-
declare function HiddenSelect():
|
|
225
|
+
declare function HiddenSelect(): React.JSX.Element | null;
|
|
227
226
|
|
|
228
227
|
type ScrollUpButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
229
|
-
declare function ScrollUpButton(props: ScrollUpButtonProps):
|
|
228
|
+
declare function ScrollUpButton(props: ScrollUpButtonProps): React.JSX.Element;
|
|
230
229
|
|
|
231
230
|
type ScrollDownButtonProps = Omit<SelectScrollButtonProps, "direction">;
|
|
232
|
-
declare function ScrollDownButton(props: ScrollDownButtonProps):
|
|
231
|
+
declare function ScrollDownButton(props: ScrollDownButtonProps): React.JSX.Element;
|
|
233
232
|
|
|
234
233
|
declare const index_parts_Backdrop: typeof Backdrop;
|
|
235
234
|
declare const index_parts_ClearTrigger: typeof ClearTrigger;
|
package/dist/index.js
CHANGED
|
@@ -163,17 +163,18 @@ function extractItemTextLabel(children) {
|
|
|
163
163
|
let label = null;
|
|
164
164
|
Children.forEach(children, (child) => {
|
|
165
165
|
if (label != null || !isValidElement(child)) return;
|
|
166
|
-
const
|
|
166
|
+
const element = child;
|
|
167
|
+
const type = element.type;
|
|
167
168
|
const isItemText = type?.displayName === "Select.ItemText" || type?.name === "ItemText";
|
|
168
169
|
if (isItemText) {
|
|
169
|
-
const content =
|
|
170
|
+
const content = element.props.children;
|
|
170
171
|
if (typeof content === "string" || typeof content === "number") {
|
|
171
172
|
label = String(content);
|
|
172
173
|
}
|
|
173
174
|
return;
|
|
174
175
|
}
|
|
175
|
-
if (
|
|
176
|
-
label = extractItemTextLabel(
|
|
176
|
+
if (element.props.children != null) {
|
|
177
|
+
label = extractItemTextLabel(element.props.children);
|
|
177
178
|
}
|
|
178
179
|
});
|
|
179
180
|
return label;
|
|
@@ -187,15 +188,16 @@ function extractItemsFromChildren(children) {
|
|
|
187
188
|
const walk = (node) => {
|
|
188
189
|
Children.forEach(node, (child) => {
|
|
189
190
|
if (!isValidElement(child)) return;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
191
|
+
const element = child;
|
|
192
|
+
if (isSelectItemElement(element)) {
|
|
193
|
+
const value = element.props.value;
|
|
194
|
+
const label = extractItemTextLabel(element.props.children) ?? value;
|
|
193
195
|
if (value != null && label != null) {
|
|
194
196
|
items[value] = label;
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
|
-
if (
|
|
198
|
-
walk(
|
|
199
|
+
if (element.props.children != null) {
|
|
200
|
+
walk(element.props.children);
|
|
199
201
|
}
|
|
200
202
|
});
|
|
201
203
|
};
|
|
@@ -364,10 +366,7 @@ function Root(props) {
|
|
|
364
366
|
[store]
|
|
365
367
|
);
|
|
366
368
|
const discoveredItems = useMemo(() => extractItemsFromChildren(children), [children]);
|
|
367
|
-
const mergedItems = useMemo(
|
|
368
|
-
() => ({ ...discoveredItems, ...items }),
|
|
369
|
-
[discoveredItems, items]
|
|
370
|
-
);
|
|
369
|
+
const mergedItems = useMemo(() => ({ ...discoveredItems, ...items }), [discoveredItems, items]);
|
|
371
370
|
const config = useMemo(
|
|
372
371
|
() => ({
|
|
373
372
|
disabled,
|
|
@@ -380,7 +379,17 @@ function Root(props) {
|
|
|
380
379
|
isItemEqualToValue,
|
|
381
380
|
openOnFocus
|
|
382
381
|
}),
|
|
383
|
-
[
|
|
382
|
+
[
|
|
383
|
+
disabled,
|
|
384
|
+
required,
|
|
385
|
+
readOnly,
|
|
386
|
+
modal,
|
|
387
|
+
name,
|
|
388
|
+
multiple,
|
|
389
|
+
mergedItems,
|
|
390
|
+
isItemEqualToValue,
|
|
391
|
+
openOnFocus
|
|
392
|
+
]
|
|
384
393
|
);
|
|
385
394
|
const ctx = useMemo(
|
|
386
395
|
() => ({
|
|
@@ -899,7 +908,7 @@ function Item({
|
|
|
899
908
|
const isDisabled = disabled || config.disabled || config.readOnly;
|
|
900
909
|
useLayoutEffect(() => {
|
|
901
910
|
const el = liRef.current;
|
|
902
|
-
const label = textValue ??
|
|
911
|
+
const label = textValue ?? el?.textContent ?? value;
|
|
903
912
|
store.registerItem({
|
|
904
913
|
value,
|
|
905
914
|
label,
|