@mirohq/design-system-combobox 1.6.2 → 1.7.0-filter-chip.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.
- package/dist/main.js +101 -44
- package/dist/main.js.map +1 -1
- package/dist/module.js +102 -45
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +78 -36
- package/package.json +8 -8
package/dist/module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import React, { createContext, useContext, useRef, useState, useMemo, useCallback, useEffect } from 'react';
|
|
3
|
-
import { Combobox as Combobox$1, useComboboxContext as useComboboxContext$1,
|
|
3
|
+
import { Combobox as Combobox$1, ComboboxList, useComboboxContext as useComboboxContext$1, ComboboxItem, ComboboxItemCheck, Group as Group$1, GroupLabel as GroupLabel$1, CompositeItem as CompositeItem$1, useCompositeContext, ComboboxProvider as ComboboxProvider$1 } from '@ariakit/react';
|
|
4
4
|
import { useFormFieldContext } from '@mirohq/design-system-base-form';
|
|
5
5
|
import { stringAttrValue, mergeRefs, booleanify } from '@mirohq/design-system-utils';
|
|
6
6
|
import * as RadixPopover from '@radix-ui/react-popover';
|
|
@@ -370,6 +370,12 @@ const StyledContent = styled(RadixPopover.Content, {
|
|
|
370
370
|
boxSizing: "border-box"
|
|
371
371
|
});
|
|
372
372
|
|
|
373
|
+
const List = ({ children }) => (
|
|
374
|
+
// Role must be set explicitly; Radix Content can overwrite Ariakit's default.
|
|
375
|
+
/* @__PURE__ */ jsx(ComboboxList, { role: "listbox", children: /* @__PURE__ */ jsx(StyledItemsContainer, { children }) })
|
|
376
|
+
);
|
|
377
|
+
List.displayName = "Combobox.List";
|
|
378
|
+
|
|
373
379
|
const useDocumentFragment = () => {
|
|
374
380
|
const [fragment, setFragment] = React.useState();
|
|
375
381
|
useLayoutEffect(() => {
|
|
@@ -392,6 +398,11 @@ const isInsideRef = (element, ref) => {
|
|
|
392
398
|
var _a, _b;
|
|
393
399
|
return (_b = element != null && ((_a = ref.current) == null ? void 0 : _a.contains(element))) != null ? _b : false;
|
|
394
400
|
};
|
|
401
|
+
const isComboboxList = (child) => {
|
|
402
|
+
var _a;
|
|
403
|
+
return React.isValidElement(child) && ((_a = child.type) == null ? void 0 : _a.displayName) === "Combobox.List";
|
|
404
|
+
};
|
|
405
|
+
const hasComboboxList = (children) => React.Children.toArray(children).some(isComboboxList);
|
|
395
406
|
const Content = React.forwardRef(
|
|
396
407
|
({
|
|
397
408
|
side = "bottom",
|
|
@@ -414,7 +425,22 @@ const Content = React.forwardRef(
|
|
|
414
425
|
if (!openState) {
|
|
415
426
|
return getInvisibleContent(children);
|
|
416
427
|
}
|
|
417
|
-
const
|
|
428
|
+
const listContent = hasComboboxList(children) ? children : /* @__PURE__ */ jsx(List, { children });
|
|
429
|
+
let content = listContent;
|
|
430
|
+
if (overflow === "auto") {
|
|
431
|
+
content = /* @__PURE__ */ jsxs(ScrollArea, { type: "always", dir: direction, children: [
|
|
432
|
+
/* @__PURE__ */ jsx(
|
|
433
|
+
ScrollArea.Viewport,
|
|
434
|
+
{
|
|
435
|
+
css: {
|
|
436
|
+
maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
|
|
437
|
+
},
|
|
438
|
+
children: listContent
|
|
439
|
+
}
|
|
440
|
+
),
|
|
441
|
+
/* @__PURE__ */ jsx(ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsx(ScrollArea.Thumb, {}) })
|
|
442
|
+
] });
|
|
443
|
+
}
|
|
418
444
|
return /* @__PURE__ */ jsx(
|
|
419
445
|
StyledContent,
|
|
420
446
|
{
|
|
@@ -429,6 +455,7 @@ const Content = React.forwardRef(
|
|
|
429
455
|
sticky,
|
|
430
456
|
hideWhenDetached,
|
|
431
457
|
onOpenAutoFocus: (event) => {
|
|
458
|
+
var _a;
|
|
432
459
|
if (onOpenAutoFocus != null) {
|
|
433
460
|
onOpenAutoFocus(event);
|
|
434
461
|
return;
|
|
@@ -436,6 +463,13 @@ const Content = React.forwardRef(
|
|
|
436
463
|
event == null ? void 0 : event.preventDefault();
|
|
437
464
|
if (externalOpenedRef.current !== true) return;
|
|
438
465
|
const baseElement = ariakitStore == null ? void 0 : ariakitStore.getState().baseElement;
|
|
466
|
+
if (!(baseElement instanceof HTMLInputElement)) {
|
|
467
|
+
const searchInput = (_a = contentRef.current) == null ? void 0 : _a.querySelector("input");
|
|
468
|
+
if (searchInput != null) {
|
|
469
|
+
searchInput.focus();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
439
473
|
baseElement == null ? void 0 : baseElement.focus();
|
|
440
474
|
},
|
|
441
475
|
ref: mergeRefs([forwardRef, contentRef]),
|
|
@@ -447,18 +481,7 @@ const Content = React.forwardRef(
|
|
|
447
481
|
event.preventDefault();
|
|
448
482
|
}
|
|
449
483
|
},
|
|
450
|
-
children:
|
|
451
|
-
/* @__PURE__ */ jsx(
|
|
452
|
-
ScrollArea.Viewport,
|
|
453
|
-
{
|
|
454
|
-
css: {
|
|
455
|
-
maxHeight: maxHeight !== void 0 ? "min(".concat(RADIX_CONTENT_AVAILABLE_HEIGHT, ", ").concat(typeof maxHeight === "number" ? "".concat(maxHeight, "px") : maxHeight, ")") : RADIX_CONTENT_AVAILABLE_HEIGHT
|
|
456
|
-
},
|
|
457
|
-
children: content
|
|
458
|
-
}
|
|
459
|
-
),
|
|
460
|
-
/* @__PURE__ */ jsx(ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsx(ScrollArea.Thumb, {}) })
|
|
461
|
-
] }) : content })
|
|
484
|
+
children: content
|
|
462
485
|
}
|
|
463
486
|
);
|
|
464
487
|
}
|
|
@@ -625,6 +648,7 @@ const Value = ({
|
|
|
625
648
|
return /* @__PURE__ */ jsx(
|
|
626
649
|
Chip,
|
|
627
650
|
{
|
|
651
|
+
size: "small",
|
|
628
652
|
disabled: isDisabled,
|
|
629
653
|
onRemove: (e) => {
|
|
630
654
|
onItemRemove(itemValue);
|
|
@@ -687,39 +711,71 @@ const StyledInputSearch = styled(InputSearch, {
|
|
|
687
711
|
"&&": {
|
|
688
712
|
border: "1px solid $border-neutrals",
|
|
689
713
|
backgroundColor: "$background-control"
|
|
714
|
+
},
|
|
715
|
+
variants: {
|
|
716
|
+
// Lay selected chips (passed as children, typically `<Combobox.Value />`)
|
|
717
|
+
// out inside the field alongside the text input, matching the multiselect
|
|
718
|
+
// trigger. The leading magnifier is pulled ahead of the chips so the field
|
|
719
|
+
// still reads as a search.
|
|
720
|
+
inlineChips: {
|
|
721
|
+
true: {
|
|
722
|
+
"&&": {
|
|
723
|
+
flexWrap: "wrap",
|
|
724
|
+
height: "auto",
|
|
725
|
+
minHeight: "$10",
|
|
726
|
+
paddingBlock: "$50",
|
|
727
|
+
gap: "$50"
|
|
728
|
+
},
|
|
729
|
+
// The magnifier icon slot (the only direct child that wraps a bare svg)
|
|
730
|
+
// leads the field, before the chips.
|
|
731
|
+
"& > div:has(> svg)": {
|
|
732
|
+
order: -1
|
|
733
|
+
},
|
|
734
|
+
"& input": {
|
|
735
|
+
width: "auto",
|
|
736
|
+
flexGrow: 1,
|
|
737
|
+
flexBasis: "$8",
|
|
738
|
+
minWidth: "$8"
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
690
742
|
}
|
|
691
743
|
});
|
|
692
|
-
const SearchInput = React.forwardRef(
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
744
|
+
const SearchInput = React.forwardRef(
|
|
745
|
+
({ children, onChange, onKeyDown, inlineChips = false, ...rest }, ref) => {
|
|
746
|
+
const { setSearchValue, contentRef } = useComboboxContext();
|
|
747
|
+
const handleSearchChange = useCallback(
|
|
748
|
+
(event) => {
|
|
749
|
+
setSearchValue(event.target.value);
|
|
750
|
+
onChange == null ? void 0 : onChange(event);
|
|
751
|
+
},
|
|
752
|
+
[onChange, setSearchValue]
|
|
753
|
+
);
|
|
754
|
+
const handleKeyDown = (event) => {
|
|
696
755
|
var _a;
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
);
|
|
722
|
-
});
|
|
756
|
+
if (event.key === "ArrowDown") {
|
|
757
|
+
event.preventDefault();
|
|
758
|
+
const firstItem = (_a = contentRef.current) == null ? void 0 : _a.querySelector(
|
|
759
|
+
'[role="option"]:not([aria-disabled="true"])'
|
|
760
|
+
);
|
|
761
|
+
firstItem == null ? void 0 : firstItem.focus();
|
|
762
|
+
}
|
|
763
|
+
onKeyDown == null ? void 0 : onKeyDown(event);
|
|
764
|
+
};
|
|
765
|
+
return /* @__PURE__ */ jsx(
|
|
766
|
+
StyledInputSearch,
|
|
767
|
+
{
|
|
768
|
+
...rest,
|
|
769
|
+
ref,
|
|
770
|
+
inlineChips,
|
|
771
|
+
onKeyDown: handleKeyDown,
|
|
772
|
+
onChange: handleSearchChange,
|
|
773
|
+
children
|
|
774
|
+
}
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
SearchInput.displayName = "Combobox.SearchInput";
|
|
723
779
|
|
|
724
780
|
const StyledCompositeItem = styled(CompositeItem$1, {
|
|
725
781
|
...itemStyles,
|
|
@@ -729,7 +785,7 @@ const StyledCompositeItem = styled(CompositeItem$1, {
|
|
|
729
785
|
|
|
730
786
|
const CompositeItem = ({
|
|
731
787
|
asChild = true,
|
|
732
|
-
role
|
|
788
|
+
role,
|
|
733
789
|
textValue,
|
|
734
790
|
disabled = false,
|
|
735
791
|
tabbable,
|
|
@@ -948,6 +1004,7 @@ Combobox.Portal = Portal;
|
|
|
948
1004
|
Combobox.Trigger = Trigger;
|
|
949
1005
|
Combobox.Input = Input;
|
|
950
1006
|
Combobox.Content = Content;
|
|
1007
|
+
Combobox.List = List;
|
|
951
1008
|
Combobox.Item = Item;
|
|
952
1009
|
Combobox.CompositeItem = CompositeItem;
|
|
953
1010
|
Combobox.Group = Group;
|