@mirohq/design-system-combobox 0.1.0-combobox.6 → 0.1.0-combobox.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 +127 -117
- package/dist/main.js.map +1 -1
- package/dist/module.js +129 -119
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -5
- package/package.json +3 -3
package/dist/module.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createContext, useRef, useState,
|
|
2
|
+
import React, { createContext, useContext, useRef, useState, useCallback, useEffect, useMemo } from 'react';
|
|
3
3
|
import { Combobox as Combobox$1, ComboboxItem, ComboboxItemCheck, Group as Group$1, GroupLabel as GroupLabel$1, ComboboxProvider as ComboboxProvider$1 } from '@ariakit/react';
|
|
4
4
|
import { useFormFieldContext, FloatingLabel } from '@mirohq/design-system-base-form';
|
|
5
|
-
import { stringAttrValue, booleanishAttrValue, mergeRefs, booleanify } from '@mirohq/design-system-utils';
|
|
6
5
|
import * as RadixPopover from '@radix-ui/react-popover';
|
|
7
|
-
import { Portal as Portal$1 } from '@radix-ui/react-popover';
|
|
6
|
+
import { Anchor, Portal as Portal$1 } from '@radix-ui/react-popover';
|
|
7
|
+
import { stringAttrValue, booleanishAttrValue, mergeRefs, booleanify } from '@mirohq/design-system-utils';
|
|
8
8
|
import { styled, theme } from '@mirohq/design-system-stitches';
|
|
9
9
|
import { Input } from '@mirohq/design-system-input';
|
|
10
10
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
@@ -16,6 +16,10 @@ import { focus } from '@mirohq/design-system-styles';
|
|
|
16
16
|
import { Primitive } from '@mirohq/design-system-primitive';
|
|
17
17
|
import { BaseButton } from '@mirohq/design-system-base-button';
|
|
18
18
|
|
|
19
|
+
const StyledAnchor = styled(Anchor, {
|
|
20
|
+
position: "relative",
|
|
21
|
+
width: "100%"
|
|
22
|
+
});
|
|
19
23
|
const StyledInput = styled(Input, {
|
|
20
24
|
flexWrap: "wrap",
|
|
21
25
|
flexGrow: 1,
|
|
@@ -169,6 +173,7 @@ const Trigger = React.forwardRef(
|
|
|
169
173
|
openActionLabel,
|
|
170
174
|
clearActionLabel,
|
|
171
175
|
onChange,
|
|
176
|
+
css,
|
|
172
177
|
...restProps
|
|
173
178
|
}, forwardRef) => {
|
|
174
179
|
const {
|
|
@@ -176,11 +181,13 @@ const Trigger = React.forwardRef(
|
|
|
176
181
|
valid: comboboxValid,
|
|
177
182
|
disabled,
|
|
178
183
|
value = [],
|
|
184
|
+
readOnly,
|
|
179
185
|
triggerRef,
|
|
180
186
|
inputRef,
|
|
181
187
|
onSearchValueChange,
|
|
182
188
|
searchValue,
|
|
183
|
-
setSearchValue
|
|
189
|
+
setSearchValue,
|
|
190
|
+
setOpenState
|
|
184
191
|
} = useComboboxContext();
|
|
185
192
|
const {
|
|
186
193
|
formElementId,
|
|
@@ -202,12 +209,13 @@ const Trigger = React.forwardRef(
|
|
|
202
209
|
),
|
|
203
210
|
valid,
|
|
204
211
|
disabled,
|
|
212
|
+
readOnly,
|
|
205
213
|
invalid: booleanishAttrValue(valid),
|
|
206
214
|
id: id != null ? id : formElementId,
|
|
207
215
|
placeholder: value.length === 0 ? placeholder : void 0
|
|
208
216
|
};
|
|
209
217
|
const shouldUseFloatingLabel = label !== null && isFloatingLabel;
|
|
210
|
-
const isFloating = placeholder !== void 0 || value.length !== 0 || focused;
|
|
218
|
+
const isFloating = placeholder !== void 0 || value.length !== 0 || focused || searchValue !== "";
|
|
211
219
|
const scrollIntoView = (event) => {
|
|
212
220
|
var _a;
|
|
213
221
|
const trigger = triggerRef == null ? void 0 : triggerRef.current;
|
|
@@ -227,36 +235,48 @@ const Trigger = React.forwardRef(
|
|
|
227
235
|
onSearchValueChange == null ? void 0 : onSearchValueChange(e.target.value);
|
|
228
236
|
onChange == null ? void 0 : onChange(e);
|
|
229
237
|
};
|
|
230
|
-
return /* @__PURE__ */ jsxs(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
return /* @__PURE__ */ jsxs(
|
|
239
|
+
StyledAnchor,
|
|
240
|
+
{
|
|
241
|
+
ref: mergeRefs([triggerRef, forwardRef]),
|
|
242
|
+
css,
|
|
243
|
+
onClick: () => {
|
|
244
|
+
if (!booleanify(disabled) && !booleanify(ariaDisabled) && !booleanify(readOnly)) {
|
|
245
|
+
setOpenState(true);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
children: [
|
|
249
|
+
shouldUseFloatingLabel && /* @__PURE__ */ jsx(FloatingLabel, { floating: isFloating, size, children: label }),
|
|
250
|
+
/* @__PURE__ */ jsx(
|
|
251
|
+
Combobox$1,
|
|
237
252
|
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
render: /* @__PURE__ */ jsxs(
|
|
254
|
+
StyledInput,
|
|
255
|
+
{
|
|
256
|
+
...inputProps,
|
|
257
|
+
value: searchValue,
|
|
258
|
+
size,
|
|
259
|
+
ref: inputRef,
|
|
260
|
+
onChange: onInputChange,
|
|
261
|
+
onFocus: scrollIntoView,
|
|
262
|
+
children: [
|
|
263
|
+
children,
|
|
264
|
+
/* @__PURE__ */ jsx(
|
|
265
|
+
TriggerActionButton,
|
|
266
|
+
{
|
|
267
|
+
openActionLabel,
|
|
268
|
+
clearActionLabel,
|
|
269
|
+
size
|
|
270
|
+
}
|
|
271
|
+
)
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
)
|
|
255
275
|
}
|
|
256
276
|
)
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
);
|
|
260
280
|
}
|
|
261
281
|
);
|
|
262
282
|
|
|
@@ -266,34 +286,30 @@ const StyledContent = styled(RadixPopover.Content, {
|
|
|
266
286
|
boxShadow: "$50",
|
|
267
287
|
fontSize: "$175",
|
|
268
288
|
fontWeight: "normal",
|
|
269
|
-
lineHeight: "
|
|
289
|
+
lineHeight: "20px",
|
|
270
290
|
width: "var(--radix-popover-trigger-width)",
|
|
271
291
|
zIndex: "$select",
|
|
272
292
|
overflowY: "auto",
|
|
273
|
-
padding: "$
|
|
293
|
+
padding: "$50",
|
|
274
294
|
boxSizing: "border-box",
|
|
275
295
|
outline: "1px solid transparent"
|
|
276
296
|
});
|
|
277
297
|
|
|
278
298
|
const StyledItemCheck = styled(Primitive.span, {
|
|
279
|
-
color: "$icon-primary"
|
|
280
|
-
paddingX: "$100"
|
|
299
|
+
color: "$icon-primary"
|
|
281
300
|
});
|
|
282
301
|
const StyledItem = styled(ComboboxItem, {
|
|
283
|
-
display: "
|
|
284
|
-
|
|
285
|
-
justifyContent: "space-between",
|
|
286
|
-
gap: "$200",
|
|
302
|
+
display: "grid",
|
|
303
|
+
gridTemplateColumns: "20px 1fr",
|
|
287
304
|
borderRadius: "$50",
|
|
288
305
|
boxSizing: "border-box",
|
|
289
306
|
color: "$text-neutrals",
|
|
290
307
|
cursor: "pointer",
|
|
291
308
|
fontSize: "$175",
|
|
292
|
-
lineHeight:
|
|
309
|
+
lineHeight: "20px",
|
|
293
310
|
position: "relative",
|
|
294
311
|
userSelect: "none",
|
|
295
|
-
|
|
296
|
-
paddingY: "10px",
|
|
312
|
+
padding: "6px $100 6px $150",
|
|
297
313
|
...focus.css({
|
|
298
314
|
boxShadow: "$focus-small"
|
|
299
315
|
}),
|
|
@@ -308,7 +324,13 @@ const StyledItem = styled(ComboboxItem, {
|
|
|
308
324
|
},
|
|
309
325
|
"&:disabled, &[aria-disabled=true], &[data-disabled]": {
|
|
310
326
|
cursor: "default",
|
|
311
|
-
color: "$text-neutrals-disabled"
|
|
327
|
+
color: "$text-neutrals-disabled",
|
|
328
|
+
["".concat(StyledItemCheck)]: {
|
|
329
|
+
color: "$icon-neutrals-disabled"
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
'&[aria-selected="true"]:not(:disabled,[aria-disabled=true],[data-disabled])': {
|
|
333
|
+
color: "$text-primary-selected"
|
|
312
334
|
}
|
|
313
335
|
});
|
|
314
336
|
|
|
@@ -335,13 +357,13 @@ const Item = React.forwardRef(
|
|
|
335
357
|
{
|
|
336
358
|
...mergeProps(restProps, restAriaDisabledProps),
|
|
337
359
|
focusable: true,
|
|
338
|
-
|
|
339
|
-
|
|
360
|
+
hideOnClick: false,
|
|
361
|
+
accessibleWhenDisabled: booleanify(ariaDisabled),
|
|
362
|
+
disabled: booleanify(ariaDisabled) || disabled,
|
|
340
363
|
ref: forwardRef,
|
|
341
364
|
value,
|
|
342
365
|
onClick: scrollIntoView,
|
|
343
366
|
children: [
|
|
344
|
-
children,
|
|
345
367
|
/* @__PURE__ */ jsx(
|
|
346
368
|
ComboboxItemCheck,
|
|
347
369
|
{
|
|
@@ -357,7 +379,8 @@ const Item = React.forwardRef(
|
|
|
357
379
|
}
|
|
358
380
|
)
|
|
359
381
|
}
|
|
360
|
-
)
|
|
382
|
+
),
|
|
383
|
+
children
|
|
361
384
|
]
|
|
362
385
|
}
|
|
363
386
|
);
|
|
@@ -434,7 +457,7 @@ const Content = React.forwardRef(
|
|
|
434
457
|
ScrollArea.Viewport,
|
|
435
458
|
{
|
|
436
459
|
availableHeight: "var(--radix-popover-content-available-height)",
|
|
437
|
-
verticalGap: "
|
|
460
|
+
verticalGap: "var(--space-50) * 2",
|
|
438
461
|
maxHeight,
|
|
439
462
|
children: content
|
|
440
463
|
}
|
|
@@ -469,11 +492,8 @@ const Group = React.forwardRef(({ children, ...rest }, forwardRef) => {
|
|
|
469
492
|
});
|
|
470
493
|
|
|
471
494
|
const StyledGroupLabel = styled(GroupLabel$1, {
|
|
472
|
-
padding: "$100",
|
|
473
|
-
color: "$text-neutrals-subtle"
|
|
474
|
-
fontSize: "$150",
|
|
475
|
-
textTransform: "uppercase",
|
|
476
|
-
fontWeight: 650
|
|
495
|
+
padding: "6px $100",
|
|
496
|
+
color: "$text-neutrals-subtle"
|
|
477
497
|
});
|
|
478
498
|
|
|
479
499
|
const GroupLabel = React.forwardRef((props, forwardRef) => /* @__PURE__ */ jsx(StyledGroupLabel, { ...props, ref: forwardRef }));
|
|
@@ -564,12 +584,11 @@ const Separator = React.forwardRef((props, forwardRef) => {
|
|
|
564
584
|
return /* @__PURE__ */ jsx(StyledSeparator, { ...props, ref: forwardRef, "aria-hidden": true });
|
|
565
585
|
});
|
|
566
586
|
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const Root = React.forwardRef(({ value: valueProp, onValueChange, children, ...restProps }, forwardRef) => {
|
|
587
|
+
const Root = ({
|
|
588
|
+
value: valueProp,
|
|
589
|
+
children,
|
|
590
|
+
...restProps
|
|
591
|
+
}) => {
|
|
573
592
|
const {
|
|
574
593
|
openState,
|
|
575
594
|
setOpenState,
|
|
@@ -579,8 +598,7 @@ const Root = React.forwardRef(({ value: valueProp, onValueChange, children, ...r
|
|
|
579
598
|
required,
|
|
580
599
|
readOnly,
|
|
581
600
|
"aria-disabled": ariaDisabled,
|
|
582
|
-
disabled
|
|
583
|
-
direction
|
|
601
|
+
disabled
|
|
584
602
|
} = useComboboxContext();
|
|
585
603
|
const { setRequired, setDisabled, setAriaDisabled, setReadOnly } = useFormFieldContext();
|
|
586
604
|
useEffect(() => {
|
|
@@ -601,78 +619,70 @@ const Root = React.forwardRef(({ value: valueProp, onValueChange, children, ...r
|
|
|
601
619
|
const onSetSelectedValue = (newValue) => {
|
|
602
620
|
setValue(typeof newValue === "string" ? [newValue] : newValue);
|
|
603
621
|
};
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (!booleanify(disabled)) {
|
|
608
|
-
setOpenState(true);
|
|
609
|
-
}
|
|
610
|
-
if (restProps.onClick !== void 0) {
|
|
611
|
-
restProps.onClick(event);
|
|
612
|
-
}
|
|
622
|
+
const onOpenChange = (value2) => {
|
|
623
|
+
if (!booleanify(readOnly)) {
|
|
624
|
+
setOpenState(value2);
|
|
613
625
|
}
|
|
614
626
|
};
|
|
615
|
-
return /* @__PURE__ */ jsx(
|
|
616
|
-
|
|
627
|
+
return /* @__PURE__ */ jsx(
|
|
628
|
+
RadixPopover.Root,
|
|
617
629
|
{
|
|
618
630
|
open: openState,
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
selectedValue: value,
|
|
622
|
-
setSelectedValue: onSetSelectedValue,
|
|
631
|
+
onOpenChange,
|
|
632
|
+
...restProps,
|
|
623
633
|
children: /* @__PURE__ */ jsx(
|
|
624
|
-
|
|
634
|
+
ComboboxProvider$1,
|
|
625
635
|
{
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
636
|
+
open: openState,
|
|
637
|
+
setOpen: onOpenChange,
|
|
638
|
+
defaultSelectedValue: defaultValue,
|
|
639
|
+
selectedValue: value,
|
|
640
|
+
setSelectedValue: onSetSelectedValue,
|
|
629
641
|
children
|
|
630
642
|
}
|
|
631
643
|
)
|
|
632
644
|
}
|
|
633
|
-
)
|
|
634
|
-
}
|
|
635
|
-
const Combobox =
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
645
|
+
);
|
|
646
|
+
};
|
|
647
|
+
const Combobox = ({
|
|
648
|
+
"aria-disabled": ariaDisabled,
|
|
649
|
+
defaultOpen = false,
|
|
650
|
+
open,
|
|
651
|
+
valid,
|
|
652
|
+
disabled,
|
|
653
|
+
readOnly,
|
|
654
|
+
required,
|
|
655
|
+
value,
|
|
656
|
+
defaultValue,
|
|
657
|
+
onOpen,
|
|
658
|
+
onClose,
|
|
659
|
+
onSearchValueChange,
|
|
660
|
+
onValueChange,
|
|
661
|
+
direction = "ltr",
|
|
662
|
+
autoFilter = true,
|
|
663
|
+
noResultsText,
|
|
664
|
+
...restProps
|
|
665
|
+
}) => /* @__PURE__ */ jsx(
|
|
666
|
+
ComboboxProvider,
|
|
667
|
+
{
|
|
668
|
+
defaultValue,
|
|
669
|
+
value,
|
|
670
|
+
onValueChange,
|
|
671
|
+
onSearchValueChange,
|
|
672
|
+
defaultOpen,
|
|
639
673
|
open,
|
|
674
|
+
onOpen,
|
|
675
|
+
onClose,
|
|
640
676
|
valid,
|
|
677
|
+
required,
|
|
641
678
|
disabled,
|
|
642
679
|
readOnly,
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
onOpen,
|
|
647
|
-
onClose,
|
|
648
|
-
onSearchValueChange,
|
|
649
|
-
onValueChange,
|
|
650
|
-
direction = "ltr",
|
|
651
|
-
autoFilter = true,
|
|
680
|
+
"aria-disabled": ariaDisabled,
|
|
681
|
+
direction,
|
|
682
|
+
autoFilter,
|
|
652
683
|
noResultsText,
|
|
653
|
-
...restProps
|
|
654
|
-
}
|
|
655
|
-
ComboboxProvider,
|
|
656
|
-
{
|
|
657
|
-
defaultValue,
|
|
658
|
-
value,
|
|
659
|
-
onValueChange,
|
|
660
|
-
onSearchValueChange,
|
|
661
|
-
defaultOpen,
|
|
662
|
-
open,
|
|
663
|
-
onOpen,
|
|
664
|
-
onClose,
|
|
665
|
-
valid,
|
|
666
|
-
required,
|
|
667
|
-
disabled,
|
|
668
|
-
readOnly,
|
|
669
|
-
"aria-disabled": ariaDisabled,
|
|
670
|
-
direction,
|
|
671
|
-
autoFilter,
|
|
672
|
-
noResultsText,
|
|
673
|
-
children: /* @__PURE__ */ jsx(Root, { ...restProps, value, ref: forwardRef })
|
|
674
|
-
}
|
|
675
|
-
)
|
|
684
|
+
children: /* @__PURE__ */ jsx(Root, { ...restProps, value })
|
|
685
|
+
}
|
|
676
686
|
);
|
|
677
687
|
Combobox.Portal = Portal;
|
|
678
688
|
Combobox.Trigger = Trigger;
|