@mirohq/design-system-combobox 0.3.5 → 0.3.7
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/dist/main.js +153 -208
- package/dist/main.js.map +1 -1
- package/dist/module.js +155 -210
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +7 -7
package/dist/main.js
CHANGED
|
@@ -15,12 +15,12 @@ var reactUseControllableState = require('@radix-ui/react-use-controllable-state'
|
|
|
15
15
|
var designSystemIcons = require('@mirohq/design-system-icons');
|
|
16
16
|
var designSystemScrollArea = require('@mirohq/design-system-scroll-area');
|
|
17
17
|
var designSystemBaseSelect = require('@mirohq/design-system-base-select');
|
|
18
|
-
var designSystemUseAriaDisabled = require('@mirohq/design-system-use-aria-disabled');
|
|
19
|
-
var designSystemUseLayoutEffect = require('@mirohq/design-system-use-layout-effect');
|
|
20
|
-
var reactDom = require('react-dom');
|
|
21
18
|
var designSystemPrimitive = require('@mirohq/design-system-primitive');
|
|
22
|
-
var
|
|
23
|
-
var
|
|
19
|
+
var reactDom = require('react-dom');
|
|
20
|
+
var designSystemUseLayoutEffect = require('@mirohq/design-system-use-layout-effect');
|
|
21
|
+
var designSystemUseAriaDisabled = require('@mirohq/design-system-use-aria-disabled');
|
|
22
|
+
var designSystemUseId = require('@mirohq/design-system-use-id');
|
|
23
|
+
var designSystemChip = require('@mirohq/design-system-chip');
|
|
24
24
|
|
|
25
25
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
26
|
|
|
@@ -79,6 +79,10 @@ const StyledBaseInput = designSystemStitches.styled(designSystemBaseInput.BaseIn
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
+
function searchQueryMatch(displayedText, searchValue) {
|
|
83
|
+
return displayedText.toLowerCase().includes(searchValue.toLowerCase());
|
|
84
|
+
}
|
|
85
|
+
|
|
82
86
|
const ComboboxContext = React.createContext({});
|
|
83
87
|
const ComboboxProvider = ({
|
|
84
88
|
children,
|
|
@@ -92,13 +96,12 @@ const ComboboxProvider = ({
|
|
|
92
96
|
onValueChange,
|
|
93
97
|
searchValue: searchValueProp,
|
|
94
98
|
onSearchValueChange,
|
|
95
|
-
autoFilter
|
|
99
|
+
autoFilter,
|
|
96
100
|
...restProps
|
|
97
101
|
}) => {
|
|
98
102
|
const triggerRef = React.useRef(null);
|
|
99
103
|
const inputRef = React.useRef(null);
|
|
100
104
|
const contentRef = React.useRef(null);
|
|
101
|
-
const [defaultValue, setDefaultValue] = React.useState(defaultValueProp);
|
|
102
105
|
const [openState = false, setOpenState] = reactUseControllableState.useControllableState({
|
|
103
106
|
prop: openProp,
|
|
104
107
|
defaultProp: defaultOpen,
|
|
@@ -115,16 +118,23 @@ const ComboboxProvider = ({
|
|
|
115
118
|
defaultProp: defaultValueProp,
|
|
116
119
|
onChange: onValueChange
|
|
117
120
|
});
|
|
118
|
-
const [
|
|
119
|
-
const [searchValue, setSearchValue] = reactUseControllableState.useControllableState({
|
|
121
|
+
const [searchValue = "", setSearchValue] = reactUseControllableState.useControllableState({
|
|
120
122
|
prop: searchValueProp,
|
|
121
123
|
defaultProp: "",
|
|
122
124
|
onChange: onSearchValueChange
|
|
123
125
|
});
|
|
124
126
|
const [size, setSize] = React.useState();
|
|
125
127
|
const [placeholder, setPlaceholder] = React.useState();
|
|
126
|
-
const [
|
|
128
|
+
const [itemsMap, setItemsMap] = React.useState(/* @__PURE__ */ new Map());
|
|
127
129
|
const { valid: formFieldValid } = designSystemBaseForm.useFormFieldContext();
|
|
130
|
+
const filteredItems = React.useMemo(() => {
|
|
131
|
+
if (searchValue.length > 0) {
|
|
132
|
+
return Array.from(itemsMap.values()).filter(
|
|
133
|
+
(item) => searchQueryMatch(item.displayedText, searchValue)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return [];
|
|
137
|
+
}, [itemsMap, searchValue]);
|
|
128
138
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
129
139
|
ComboboxContext.Provider,
|
|
130
140
|
{
|
|
@@ -135,18 +145,15 @@ const ComboboxProvider = ({
|
|
|
135
145
|
setOpenState,
|
|
136
146
|
value,
|
|
137
147
|
setValue,
|
|
138
|
-
setDefaultValue,
|
|
139
|
-
defaultValue,
|
|
140
148
|
triggerRef,
|
|
141
149
|
inputRef,
|
|
142
150
|
contentRef,
|
|
143
151
|
autoFilter,
|
|
144
152
|
searchValue,
|
|
145
153
|
setSearchValue,
|
|
154
|
+
itemsMap,
|
|
155
|
+
setItemsMap,
|
|
146
156
|
filteredItems,
|
|
147
|
-
setFilteredItems,
|
|
148
|
-
itemValueTextMap,
|
|
149
|
-
setItemValueTextMap,
|
|
150
157
|
placeholder,
|
|
151
158
|
setPlaceholder,
|
|
152
159
|
size,
|
|
@@ -233,7 +240,7 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
233
240
|
placeholder,
|
|
234
241
|
openActionLabel,
|
|
235
242
|
closeActionLabel,
|
|
236
|
-
clearable,
|
|
243
|
+
clearable = true,
|
|
237
244
|
clearActionLabel,
|
|
238
245
|
onChange,
|
|
239
246
|
onFocus,
|
|
@@ -351,6 +358,7 @@ const Trigger = React__default["default"].forwardRef(
|
|
|
351
358
|
}
|
|
352
359
|
);
|
|
353
360
|
|
|
361
|
+
const StyledItemsContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.div, designSystemBaseSelect.itemsContainerStyles);
|
|
354
362
|
const StyledContent = designSystemStitches.styled(RadixPopover__namespace.Content, {
|
|
355
363
|
...designSystemBaseSelect.contentStyles,
|
|
356
364
|
width: "var(--radix-popover-trigger-width)",
|
|
@@ -358,103 +366,6 @@ const StyledContent = designSystemStitches.styled(RadixPopover__namespace.Conten
|
|
|
358
366
|
boxSizing: "border-box"
|
|
359
367
|
});
|
|
360
368
|
|
|
361
|
-
const StyledItem = designSystemStitches.styled(react.ComboboxItem, designSystemBaseSelect.itemStyles);
|
|
362
|
-
|
|
363
|
-
const Item = React__default["default"].forwardRef(
|
|
364
|
-
({ disabled = false, value, textValue, children, ...restProps }, forwardRef) => {
|
|
365
|
-
const { "aria-disabled": ariaDisabled, ...restAriaDisabledProps } = designSystemUseAriaDisabled.useAriaDisabled(restProps, { allowArrows: true });
|
|
366
|
-
const {
|
|
367
|
-
autoFilter,
|
|
368
|
-
filteredItems,
|
|
369
|
-
setItemValueTextMap,
|
|
370
|
-
triggerRef,
|
|
371
|
-
inputRef,
|
|
372
|
-
value: comboboxValue = []
|
|
373
|
-
} = useComboboxContext();
|
|
374
|
-
designSystemUseLayoutEffect.useLayoutEffect(() => {
|
|
375
|
-
const textToSet = textValue !== void 0 ? textValue : typeof children === "string" ? children : "";
|
|
376
|
-
setItemValueTextMap((prevState) => new Map(prevState.set(value, textToSet)));
|
|
377
|
-
return () => {
|
|
378
|
-
setItemValueTextMap((prevState) => {
|
|
379
|
-
prevState.delete(value);
|
|
380
|
-
return new Map(prevState);
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
}, [setItemValueTextMap, value, textValue, children]);
|
|
384
|
-
if (autoFilter !== false && !filteredItems.has(value)) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
const scrollIntoView = (event) => {
|
|
388
|
-
var _a;
|
|
389
|
-
if (((_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.parentElement) != null && (triggerRef == null ? void 0 : triggerRef.current) != null) {
|
|
390
|
-
inputRef.current.parentElement.scrollTo({
|
|
391
|
-
top: triggerRef.current.scrollHeight
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
if (restProps.onClick !== void 0) {
|
|
395
|
-
restProps.onClick(event);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
const isSelected = comboboxValue.includes(value);
|
|
399
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
400
|
-
StyledItem,
|
|
401
|
-
{
|
|
402
|
-
...utils.mergeProps(restProps, restAriaDisabledProps),
|
|
403
|
-
focusable: true,
|
|
404
|
-
hideOnClick: false,
|
|
405
|
-
accessibleWhenDisabled: designSystemUtils.booleanify(ariaDisabled),
|
|
406
|
-
disabled: designSystemUtils.booleanify(ariaDisabled) || disabled,
|
|
407
|
-
ref: forwardRef,
|
|
408
|
-
value,
|
|
409
|
-
onClick: scrollIntoView,
|
|
410
|
-
"aria-selected": isSelected,
|
|
411
|
-
children: [
|
|
412
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
413
|
-
react.ComboboxItemCheck,
|
|
414
|
-
{
|
|
415
|
-
checked: isSelected,
|
|
416
|
-
render: ({ style, ...props }) => (
|
|
417
|
-
// AriakitComboboxItemCheck adds its owm inline styles which we want to omit here
|
|
418
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystemBaseSelect.StyledItemCheck, { ...props })
|
|
419
|
-
),
|
|
420
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
421
|
-
designSystemIcons.IconCheckMark,
|
|
422
|
-
{
|
|
423
|
-
size: "small",
|
|
424
|
-
"data-testid": process.env.NODE_ENV === "test" ? "combobox-item-check" : void 0
|
|
425
|
-
}
|
|
426
|
-
)
|
|
427
|
-
}
|
|
428
|
-
),
|
|
429
|
-
children
|
|
430
|
-
]
|
|
431
|
-
}
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
const itemType = React__default["default"].createElement(Item).type;
|
|
437
|
-
const getChildrenItemValues = (componentChildren) => {
|
|
438
|
-
const values = [];
|
|
439
|
-
const recurse = (children) => {
|
|
440
|
-
React__default["default"].Children.forEach(children, (child) => {
|
|
441
|
-
if (!React__default["default"].isValidElement(child)) {
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
if (child.type === itemType) {
|
|
445
|
-
const props = child.props;
|
|
446
|
-
values.push(props.value);
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
if (child.props.children) {
|
|
450
|
-
recurse(child.props.children);
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
recurse(componentChildren);
|
|
455
|
-
return values;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
369
|
const useDocumentFragment = () => {
|
|
459
370
|
const [fragment, setFragment] = React__default["default"].useState();
|
|
460
371
|
designSystemUseLayoutEffect.useLayoutEffect(() => {
|
|
@@ -472,6 +383,7 @@ const useInvisibleContent = () => {
|
|
|
472
383
|
};
|
|
473
384
|
|
|
474
385
|
const CONTENT_OFFSET = parseInt(designSystemStitches.theme.space[50]);
|
|
386
|
+
const RADIX_CONTENT_AVAILABLE_HEIGHT = "var(--radix-popover-content-available-height)";
|
|
475
387
|
const isInsideRef = (element, ref) => {
|
|
476
388
|
var _a, _b;
|
|
477
389
|
return (_b = element != null && ((_a = ref.current) == null ? void 0 : _a.contains(element))) != null ? _b : false;
|
|
@@ -491,31 +403,15 @@ const Content = React__default["default"].forwardRef(
|
|
|
491
403
|
children,
|
|
492
404
|
...restProps
|
|
493
405
|
}, forwardRef) => {
|
|
494
|
-
const {
|
|
495
|
-
triggerRef,
|
|
496
|
-
contentRef,
|
|
497
|
-
autoFilter,
|
|
498
|
-
setFilteredItems,
|
|
499
|
-
searchValue,
|
|
500
|
-
direction,
|
|
501
|
-
openState
|
|
502
|
-
} = useComboboxContext();
|
|
503
|
-
React.useEffect(() => {
|
|
504
|
-
const childrenItemValues = getChildrenItemValues(children);
|
|
505
|
-
const shouldFilter = autoFilter !== false && searchValue !== void 0 && searchValue.length > 0;
|
|
506
|
-
const items = shouldFilter ? childrenItemValues.filter(
|
|
507
|
-
(child) => child.toLowerCase().includes(searchValue.toLowerCase())
|
|
508
|
-
) : childrenItemValues;
|
|
509
|
-
setFilteredItems(new Set(items));
|
|
510
|
-
}, [children, autoFilter, setFilteredItems, searchValue]);
|
|
406
|
+
const { triggerRef, contentRef, direction, openState } = useComboboxContext();
|
|
511
407
|
const getInvisibleContent = useInvisibleContent();
|
|
512
408
|
if (!openState) {
|
|
513
409
|
return getInvisibleContent(children);
|
|
514
410
|
}
|
|
411
|
+
const content = /* @__PURE__ */ jsxRuntime.jsx(StyledItemsContainer, { children });
|
|
515
412
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
516
413
|
StyledContent,
|
|
517
414
|
{
|
|
518
|
-
asChild: true,
|
|
519
415
|
...restProps,
|
|
520
416
|
dir: direction,
|
|
521
417
|
side,
|
|
@@ -540,14 +436,112 @@ const Content = React__default["default"].forwardRef(
|
|
|
540
436
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
541
437
|
designSystemScrollArea.ScrollArea.Viewport,
|
|
542
438
|
{
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
children
|
|
439
|
+
css: {
|
|
440
|
+
maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
|
|
441
|
+
},
|
|
442
|
+
children: content
|
|
547
443
|
}
|
|
548
444
|
),
|
|
549
445
|
/* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsxRuntime.jsx(designSystemScrollArea.ScrollArea.Thumb, {}) })
|
|
550
|
-
] }) :
|
|
446
|
+
] }) : content })
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
const StyledItem = designSystemStitches.styled(react.ComboboxItem, designSystemBaseSelect.itemStyles);
|
|
453
|
+
|
|
454
|
+
const GroupContext = React.createContext({});
|
|
455
|
+
const GroupProvider = ({
|
|
456
|
+
children,
|
|
457
|
+
...restProps
|
|
458
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
459
|
+
GroupContext.Provider,
|
|
460
|
+
{
|
|
461
|
+
value: {
|
|
462
|
+
...restProps
|
|
463
|
+
},
|
|
464
|
+
children
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
const useGroupContext = () => React.useContext(GroupContext);
|
|
468
|
+
|
|
469
|
+
const Item = React__default["default"].forwardRef(
|
|
470
|
+
({ disabled = false, value, textValue, children, ...restProps }, forwardRef) => {
|
|
471
|
+
const { "aria-disabled": ariaDisabled, ...restAriaDisabledProps } = designSystemUseAriaDisabled.useAriaDisabled(restProps, { allowArrows: true });
|
|
472
|
+
const {
|
|
473
|
+
searchValue,
|
|
474
|
+
autoFilter,
|
|
475
|
+
setItemsMap,
|
|
476
|
+
triggerRef,
|
|
477
|
+
inputRef,
|
|
478
|
+
value: comboboxValue = []
|
|
479
|
+
} = useComboboxContext();
|
|
480
|
+
const { groupId } = useGroupContext();
|
|
481
|
+
const displayedText = React.useMemo(() => {
|
|
482
|
+
if (textValue !== void 0) {
|
|
483
|
+
return textValue;
|
|
484
|
+
}
|
|
485
|
+
return typeof children === "string" ? children : "";
|
|
486
|
+
}, [textValue, children]);
|
|
487
|
+
designSystemUseLayoutEffect.useLayoutEffect(() => {
|
|
488
|
+
setItemsMap(
|
|
489
|
+
(prevState) => new Map(prevState.set(value, { displayedText, groupId }))
|
|
490
|
+
);
|
|
491
|
+
return () => {
|
|
492
|
+
setItemsMap((prevState) => {
|
|
493
|
+
prevState.delete(value);
|
|
494
|
+
return new Map(prevState);
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
}, [setItemsMap, groupId, value, displayedText]);
|
|
498
|
+
if (autoFilter && searchValue.length > 0 && !searchQueryMatch(displayedText, searchValue)) {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
const scrollIntoView = (event) => {
|
|
502
|
+
var _a;
|
|
503
|
+
if (((_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.parentElement) != null && (triggerRef == null ? void 0 : triggerRef.current) != null) {
|
|
504
|
+
inputRef.current.parentElement.scrollTo({
|
|
505
|
+
top: triggerRef.current.scrollHeight
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
if (restProps.onClick !== void 0) {
|
|
509
|
+
restProps.onClick(event);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const isSelected = comboboxValue.includes(value);
|
|
513
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
514
|
+
StyledItem,
|
|
515
|
+
{
|
|
516
|
+
...utils.mergeProps(restProps, restAriaDisabledProps),
|
|
517
|
+
focusable: true,
|
|
518
|
+
hideOnClick: false,
|
|
519
|
+
accessibleWhenDisabled: designSystemUtils.booleanify(ariaDisabled),
|
|
520
|
+
disabled: designSystemUtils.booleanify(ariaDisabled) || disabled,
|
|
521
|
+
ref: forwardRef,
|
|
522
|
+
value,
|
|
523
|
+
onClick: scrollIntoView,
|
|
524
|
+
"aria-selected": isSelected,
|
|
525
|
+
children: [
|
|
526
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
527
|
+
react.ComboboxItemCheck,
|
|
528
|
+
{
|
|
529
|
+
checked: isSelected,
|
|
530
|
+
render: ({ style, ...props }) => (
|
|
531
|
+
// AriakitComboboxItemCheck adds its owm inline styles which we want to omit here
|
|
532
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystemBaseSelect.StyledItemCheck, { ...props })
|
|
533
|
+
),
|
|
534
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
535
|
+
designSystemIcons.IconCheckMark,
|
|
536
|
+
{
|
|
537
|
+
size: "small",
|
|
538
|
+
"data-testid": process.env.NODE_ENV === "test" ? "combobox-item-check" : void 0
|
|
539
|
+
}
|
|
540
|
+
)
|
|
541
|
+
}
|
|
542
|
+
),
|
|
543
|
+
children
|
|
544
|
+
]
|
|
551
545
|
}
|
|
552
546
|
);
|
|
553
547
|
}
|
|
@@ -558,79 +552,30 @@ const Portal = (props) => /* @__PURE__ */ jsxRuntime.jsx(RadixPopover.Portal, {
|
|
|
558
552
|
const StyledGroup = designSystemStitches.styled(react.Group, {});
|
|
559
553
|
|
|
560
554
|
const Group = React__default["default"].forwardRef(({ children, ...rest }, forwardRef) => {
|
|
561
|
-
const { autoFilter, filteredItems } = useComboboxContext();
|
|
562
|
-
const
|
|
563
|
-
// don't perform calculation if auto filter is disabled
|
|
564
|
-
() => autoFilter !== false ? getChildrenItemValues(children) : [],
|
|
565
|
-
[children, autoFilter]
|
|
566
|
-
);
|
|
567
|
-
const hasVisibleChildren = React.useMemo(
|
|
568
|
-
() => (
|
|
569
|
-
// don't perform calculation if auto filter is disabled
|
|
570
|
-
autoFilter !== false ? childValues.some((value) => filteredItems.has(value)) : true
|
|
571
|
-
),
|
|
572
|
-
[childValues, filteredItems, autoFilter]
|
|
573
|
-
);
|
|
555
|
+
const { autoFilter, searchValue, filteredItems } = useComboboxContext();
|
|
556
|
+
const id = designSystemUseId.useId();
|
|
574
557
|
const getInvisibleContent = useInvisibleContent();
|
|
575
|
-
|
|
576
|
-
|
|
558
|
+
let hasVisibleContent = true;
|
|
559
|
+
if (autoFilter && searchValue.length > 0) {
|
|
560
|
+
hasVisibleContent = filteredItems.some((item) => item.groupId === id);
|
|
577
561
|
}
|
|
578
|
-
return /* @__PURE__ */ jsxRuntime.jsx(StyledGroup, { ...rest, ref: forwardRef, children });
|
|
562
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GroupProvider, { groupId: id, children: hasVisibleContent ? /* @__PURE__ */ jsxRuntime.jsx(StyledGroup, { ...rest, ref: forwardRef, children }) : getInvisibleContent(children) });
|
|
579
563
|
});
|
|
580
564
|
|
|
581
565
|
const StyledGroupLabel = designSystemStitches.styled(react.GroupLabel, designSystemBaseSelect.groupLabelStyles);
|
|
582
566
|
|
|
583
567
|
const GroupLabel = React__default["default"].forwardRef((props, forwardRef) => /* @__PURE__ */ jsxRuntime.jsx(StyledGroupLabel, { ...props, ref: forwardRef }));
|
|
584
568
|
|
|
585
|
-
const StyledChip = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
586
|
-
fontSize: "$150",
|
|
587
|
-
padding: "$50 $100",
|
|
588
|
-
borderRadius: "$round",
|
|
589
|
-
display: "flex",
|
|
590
|
-
alignItems: "center",
|
|
591
|
-
gap: "$50",
|
|
592
|
-
whiteSpace: "nowrap",
|
|
593
|
-
maxWidth: "$35",
|
|
594
|
-
backgroundColor: "$background-neutrals-subtle",
|
|
595
|
-
color: "$text-neutrals"
|
|
596
|
-
});
|
|
597
|
-
const StyledChipButton = designSystemStitches.styled(designSystemBaseButton.BaseButton, {
|
|
598
|
-
color: "$icon-neutrals-inactive",
|
|
599
|
-
...designSystemStyles.focus.css({
|
|
600
|
-
boxShadow: "$focus-small-outline"
|
|
601
|
-
})
|
|
602
|
-
});
|
|
603
|
-
const StyledChipContent = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
604
|
-
textOverflow: "ellipsis",
|
|
605
|
-
whiteSpace: "nowrap",
|
|
606
|
-
overflow: "hidden",
|
|
607
|
-
lineHeight: 1.3
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
const StyledLeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
|
|
611
|
-
order: -1,
|
|
612
|
-
marginRight: "$50"
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
const LeftSlot = StyledLeftSlot;
|
|
616
|
-
|
|
617
|
-
const Chip = React__default["default"].forwardRef(
|
|
618
|
-
({ children, disabled = false, onRemove, removeAriaLabel, ...restProps }, forwardRef) => /* @__PURE__ */ jsxRuntime.jsxs(StyledChip, { ...restProps, ref: forwardRef, children: [
|
|
619
|
-
/* @__PURE__ */ jsxRuntime.jsx(StyledChipContent, { children }),
|
|
620
|
-
!designSystemUtils.booleanify(disabled) && /* @__PURE__ */ jsxRuntime.jsx(StyledChipButton, { onClick: onRemove, "aria-label": removeAriaLabel, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemIcons.IconCross, { size: "small", weight: "thin", "aria-hidden": true }) })
|
|
621
|
-
] })
|
|
622
|
-
);
|
|
623
|
-
Chip.LeftSlot = LeftSlot;
|
|
624
|
-
|
|
625
569
|
const Value = ({ unselectAriaLabel }) => {
|
|
626
570
|
const {
|
|
627
571
|
value = [],
|
|
628
572
|
setValue,
|
|
629
573
|
disabled,
|
|
574
|
+
readOnly,
|
|
630
575
|
"aria-disabled": ariaDisabled,
|
|
631
|
-
|
|
576
|
+
itemsMap
|
|
632
577
|
} = useComboboxContext();
|
|
633
|
-
const
|
|
578
|
+
const canRemoveItem = !designSystemUtils.booleanify(ariaDisabled) && !designSystemUtils.booleanify(disabled) && !designSystemUtils.booleanify(readOnly);
|
|
634
579
|
const onItemRemove = React.useCallback(
|
|
635
580
|
(item) => {
|
|
636
581
|
setValue((prevValue) => prevValue == null ? void 0 : prevValue.filter((value2) => value2 !== item));
|
|
@@ -639,26 +584,26 @@ const Value = ({ unselectAriaLabel }) => {
|
|
|
639
584
|
);
|
|
640
585
|
const getItemText = React.useCallback(
|
|
641
586
|
(itemValue) => {
|
|
642
|
-
const
|
|
643
|
-
if (
|
|
587
|
+
const itemData = itemsMap.get(itemValue);
|
|
588
|
+
if (itemData === void 0 || itemData.displayedText === "") {
|
|
644
589
|
return null;
|
|
645
590
|
}
|
|
646
591
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
647
|
-
Chip,
|
|
592
|
+
designSystemChip.Chip,
|
|
648
593
|
{
|
|
649
594
|
onRemove: (e) => {
|
|
650
595
|
onItemRemove(itemValue);
|
|
651
596
|
e.stopPropagation();
|
|
652
597
|
},
|
|
653
|
-
|
|
654
|
-
removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(
|
|
598
|
+
removable: canRemoveItem,
|
|
599
|
+
removeAriaLabel: "".concat(unselectAriaLabel, " ").concat(itemData.displayedText),
|
|
655
600
|
"data-testid": process.env.NODE_ENV === "test" ? "combobox-value-".concat(itemValue) : void 0,
|
|
656
|
-
children:
|
|
601
|
+
children: itemData.displayedText
|
|
657
602
|
},
|
|
658
603
|
itemValue
|
|
659
604
|
);
|
|
660
605
|
},
|
|
661
|
-
[
|
|
606
|
+
[canRemoveItem, itemsMap, onItemRemove, unselectAriaLabel]
|
|
662
607
|
);
|
|
663
608
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: value.map(getItemText) });
|
|
664
609
|
};
|
|
@@ -667,7 +612,7 @@ const StyledSeparator = designSystemStitches.styled(designSystemPrimitive.Primit
|
|
|
667
612
|
|
|
668
613
|
const Separator = React__default["default"].forwardRef((props, forwardRef) => {
|
|
669
614
|
const { autoFilter, searchValue } = useComboboxContext();
|
|
670
|
-
if (autoFilter
|
|
615
|
+
if (autoFilter && searchValue.length > 0) {
|
|
671
616
|
return null;
|
|
672
617
|
}
|
|
673
618
|
return /* @__PURE__ */ jsxRuntime.jsx(StyledSeparator, { ...props, ref: forwardRef, "aria-hidden": true });
|
|
@@ -687,11 +632,13 @@ const StyledNoResult = designSystemStitches.styled(designSystemPrimitive.Primiti
|
|
|
687
632
|
});
|
|
688
633
|
|
|
689
634
|
const NoResult = React__default["default"].forwardRef((props, forwardRef) => {
|
|
690
|
-
const { filteredItems } = useComboboxContext();
|
|
691
|
-
|
|
692
|
-
|
|
635
|
+
const { autoFilter, searchValue, filteredItems, itemsMap } = useComboboxContext();
|
|
636
|
+
const noActiveFiltering = !autoFilter || autoFilter && searchValue.length === 0;
|
|
637
|
+
const isVisible = noActiveFiltering ? itemsMap.size === 0 : filteredItems.length === 0;
|
|
638
|
+
if (isVisible) {
|
|
639
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StyledNoResult, { ...props, ref: forwardRef });
|
|
693
640
|
}
|
|
694
|
-
return
|
|
641
|
+
return null;
|
|
695
642
|
});
|
|
696
643
|
|
|
697
644
|
const Root = React__default["default"].forwardRef(
|
|
@@ -700,7 +647,6 @@ const Root = React__default["default"].forwardRef(
|
|
|
700
647
|
const {
|
|
701
648
|
openState,
|
|
702
649
|
setOpenState,
|
|
703
|
-
defaultValue,
|
|
704
650
|
value = [],
|
|
705
651
|
setValue,
|
|
706
652
|
required,
|
|
@@ -754,7 +700,6 @@ const Root = React__default["default"].forwardRef(
|
|
|
754
700
|
{
|
|
755
701
|
open: openState,
|
|
756
702
|
setOpen: onOpenChange,
|
|
757
|
-
defaultSelectedValue: defaultValue,
|
|
758
703
|
selectedValue: value,
|
|
759
704
|
setSelectedValue: onSetSelectedValue,
|
|
760
705
|
children: /* @__PURE__ */ jsxRuntime.jsxs(
|