@mirohq/design-system-dropdown-menu 3.3.3 → 3.3.4-use-press.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/module.js CHANGED
@@ -1,14 +1,16 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
1
2
  import React, { createContext, useState, useRef, useCallback, useContext, useMemo } from 'react';
2
3
  import * as RadixDropdownMenu from '@radix-ui/react-dropdown-menu';
3
4
  import { Portal as Portal$1 } from '@radix-ui/react-dropdown-menu';
4
5
  import { IconProhibit, IconCheckMark, IconChevronRight } from '@mirohq/design-system-icons';
5
- import { addPropsToChildren, booleanify } from '@mirohq/design-system-utils';
6
+ import { addPropsToChildren, booleanify, mergeRefs } from '@mirohq/design-system-utils';
6
7
  import { Primitive } from '@mirohq/design-system-primitive';
7
8
  import { styled, theme } from '@mirohq/design-system-stitches';
8
9
  import { focus, animations } from '@mirohq/design-system-styles';
9
10
  import { useLayoutEffect } from '@mirohq/design-system-use-layout-effect';
10
11
  import { ScrollArea } from '@mirohq/design-system-scroll-area';
11
12
  import { styles, Thumb } from '@mirohq/design-system-base-switch';
13
+ import { isVirtualClick } from '@react-aria/utils';
12
14
  import { styles as styles$1, isIconComponent } from '@mirohq/design-system-base-icon';
13
15
 
14
16
  const ItemDescription = styled(Primitive.div, {
@@ -81,13 +83,17 @@ const ContentProvider = ({
81
83
  "--right-slot-max-width": `${Math.ceil(maxWidth)}px`
82
84
  }
83
85
  });
84
- return /* @__PURE__ */ React.createElement(Context$1.Provider, {
85
- value: {
86
- rightSlotMount,
87
- rightSlotDestroy,
88
- containerSpacing
86
+ return /* @__PURE__ */ jsx(
87
+ Context$1.Provider,
88
+ {
89
+ value: {
90
+ rightSlotMount,
91
+ rightSlotDestroy,
92
+ containerSpacing
93
+ },
94
+ children: formattedChildren
89
95
  }
90
- }, formattedChildren);
96
+ );
91
97
  };
92
98
  const useContent = () => useContext(Context$1);
93
99
 
@@ -119,10 +125,7 @@ const RightSlot = (props) => {
119
125
  return () => {
120
126
  };
121
127
  }, [rightSlotMount, rightSlotDestroy, ref]);
122
- return /* @__PURE__ */ React.createElement(StyledRightSlot, {
123
- ref,
124
- ...props
125
- });
128
+ return /* @__PURE__ */ jsx(StyledRightSlot, { ref, ...props });
126
129
  };
127
130
 
128
131
  const HotkeySlot = styled(RightSlot, {
@@ -275,31 +278,46 @@ const ItemProvider = ({
275
278
  const formattedChildren = hasSlot ? children : addPropsToChildren(children, () => true, {
276
279
  "data-no-left-slot": ""
277
280
  });
278
- return /* @__PURE__ */ React.createElement(Context.Provider, {
279
- value: {
280
- leftSlotMount,
281
- leftSlotDestroy
281
+ return /* @__PURE__ */ jsx(
282
+ Context.Provider,
283
+ {
284
+ value: {
285
+ leftSlotMount,
286
+ leftSlotDestroy
287
+ },
288
+ children: formattedChildren
282
289
  }
283
- }, formattedChildren);
290
+ );
284
291
  };
285
292
  const useItem = () => useContext(Context);
286
293
 
287
294
  const CheckboxItem = React.forwardRef(({ children, checked, onChange, disabled, ...restProps }, forwardRef) => {
288
295
  const ariaDisabledProps = useAriaDisabled(restProps, true);
289
296
  const { "aria-disabled": ariaDisabled } = ariaDisabledProps;
290
- return /* @__PURE__ */ React.createElement(ItemProvider, null, /* @__PURE__ */ React.createElement(StyledCheckboxItem, {
291
- ...restProps,
292
- ...ariaDisabledProps,
293
- ref: forwardRef,
294
- checked,
295
- disabled,
296
- onCheckedChange: onChange
297
- }, children, /* @__PURE__ */ React.createElement(RightSlot, null, /* @__PURE__ */ React.createElement(StyledIndicator, null, (disabled === true || booleanify(ariaDisabled)) && !checked && /* @__PURE__ */ React.createElement(IconProhibit, {
298
- weight: "thin",
299
- css: { square: "$3", display: "block" }
300
- }), checked && /* @__PURE__ */ React.createElement(IconCheckMark, {
301
- css: { square: "$3", display: "block" }
302
- })))));
297
+ return /* @__PURE__ */ jsx(ItemProvider, { children: /* @__PURE__ */ jsxs(
298
+ StyledCheckboxItem,
299
+ {
300
+ ...restProps,
301
+ ...ariaDisabledProps,
302
+ ref: forwardRef,
303
+ checked,
304
+ disabled,
305
+ onCheckedChange: onChange,
306
+ children: [
307
+ children,
308
+ /* @__PURE__ */ jsx(RightSlot, { children: /* @__PURE__ */ jsxs(StyledIndicator, { children: [
309
+ (disabled === true || booleanify(ariaDisabled)) && !checked && /* @__PURE__ */ jsx(
310
+ IconProhibit,
311
+ {
312
+ weight: "thin",
313
+ css: { square: "$3", display: "block" }
314
+ }
315
+ ),
316
+ checked && /* @__PURE__ */ jsx(IconCheckMark, { css: { square: "$3", display: "block" } })
317
+ ] }) })
318
+ ]
319
+ }
320
+ ) });
303
321
  });
304
322
 
305
323
  const CONTENT_GUTTER = parseInt(theme.space[150]);
@@ -389,16 +407,19 @@ const ScrollableContent = ({
389
407
  };
390
408
  }, [maxHeight, overflow, containerSpacing]);
391
409
  if (overflow === "auto") {
392
- return /* @__PURE__ */ React.createElement(ScrollArea, {
393
- css: { margin: `-${CONTENT_BORDER_FOCUS_ITEM}` },
394
- type: "always"
395
- }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
396
- css: { ...getOverflowMaxHeight() }
397
- }, children), /* @__PURE__ */ React.createElement(ScrollArea.Scrollbar, {
398
- orientation: "vertical"
399
- }, /* @__PURE__ */ React.createElement(ScrollArea.Thumb, null)));
410
+ return /* @__PURE__ */ jsxs(
411
+ ScrollArea,
412
+ {
413
+ css: { margin: `-${CONTENT_BORDER_FOCUS_ITEM}` },
414
+ type: "always",
415
+ children: [
416
+ /* @__PURE__ */ jsx(ScrollArea.Viewport, { css: { ...getOverflowMaxHeight() }, children }),
417
+ /* @__PURE__ */ jsx(ScrollArea.Scrollbar, { orientation: "vertical", children: /* @__PURE__ */ jsx(ScrollArea.Thumb, {}) })
418
+ ]
419
+ }
420
+ );
400
421
  }
401
- return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
422
+ return /* @__PURE__ */ jsx(Fragment, { children });
402
423
  };
403
424
 
404
425
  const Content = React.forwardRef(
@@ -417,29 +438,31 @@ const Content = React.forwardRef(
417
438
  maxHeight,
418
439
  children,
419
440
  ...restProps
420
- }, forwardRef) => /* @__PURE__ */ React.createElement(ContentProvider, {
421
- containerSpacing
422
- }, /* @__PURE__ */ React.createElement(StyledContent, {
423
- ...restProps,
424
- ref: forwardRef,
425
- loop,
426
- side,
427
- sideOffset,
428
- align,
429
- alignOffset,
430
- avoidCollisions,
431
- collisionPadding,
432
- sticky,
433
- hideWhenDetached,
434
- containerSpacing
435
- }, /* @__PURE__ */ React.createElement(ScrollableContent, {
436
- ...{ containerSpacing, maxHeight, overflow }
437
- }, children)))
441
+ }, forwardRef) => /* @__PURE__ */ jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsx(
442
+ StyledContent,
443
+ {
444
+ ...restProps,
445
+ ref: forwardRef,
446
+ loop,
447
+ side,
448
+ sideOffset,
449
+ align,
450
+ alignOffset,
451
+ avoidCollisions,
452
+ collisionPadding,
453
+ sticky,
454
+ hideWhenDetached,
455
+ containerSpacing,
456
+ children: /* @__PURE__ */ jsx(ScrollableContent, { ...{ containerSpacing, maxHeight, overflow }, children })
457
+ }
458
+ ) })
438
459
  );
439
460
 
440
461
  const StyledItem = styled(RadixDropdownMenu.Item, {
441
462
  ...itemDefaults,
442
463
  variants: {
464
+ // This is a hack for the :has() selector
465
+ // Remove it after Firefox implements it
443
466
  hasRightSlot: {
444
467
  true: {
445
468
  paddingRight: "$600"
@@ -451,25 +474,21 @@ const StyledItem = styled(RadixDropdownMenu.Item, {
451
474
  const Item = React.forwardRef(
452
475
  ({ disabled = false, ...restProps }, forwardRef) => {
453
476
  const ariaDisabledProps = useAriaDisabled(restProps);
454
- return /* @__PURE__ */ React.createElement(ItemProvider, null, /* @__PURE__ */ React.createElement(StyledItem, {
455
- ...restProps,
456
- ...ariaDisabledProps,
457
- disabled,
458
- ref: forwardRef
459
- }));
477
+ return /* @__PURE__ */ jsx(ItemProvider, { children: /* @__PURE__ */ jsx(
478
+ StyledItem,
479
+ {
480
+ ...restProps,
481
+ ...ariaDisabledProps,
482
+ disabled,
483
+ ref: forwardRef
484
+ }
485
+ ) });
460
486
  }
461
487
  );
462
488
 
463
489
  const LinkItem = React.forwardRef(({ children, href, ...restProps }, forwardRef) => {
464
490
  const ariaDisabledProps = useAriaDisabled(restProps);
465
- return /* @__PURE__ */ React.createElement(Item, {
466
- asChild: true,
467
- ref: forwardRef,
468
- ...restProps,
469
- ...ariaDisabledProps
470
- }, /* @__PURE__ */ React.createElement("a", {
471
- href
472
- }, children));
491
+ return /* @__PURE__ */ jsx(Item, { asChild: true, ref: forwardRef, ...restProps, ...ariaDisabledProps, children: /* @__PURE__ */ jsx("a", { href, children }) });
473
492
  });
474
493
 
475
494
  const StyledRadioGroup = styled(RadixDropdownMenu.RadioGroup, {
@@ -478,11 +497,14 @@ const StyledRadioGroup = styled(RadixDropdownMenu.RadioGroup, {
478
497
 
479
498
  const RadioGroup = React.forwardRef((props, forwardRef) => {
480
499
  const { onChange, ...restProps } = props;
481
- return /* @__PURE__ */ React.createElement(StyledRadioGroup, {
482
- ...restProps,
483
- ref: forwardRef,
484
- onValueChange: onChange
485
- });
500
+ return /* @__PURE__ */ jsx(
501
+ StyledRadioGroup,
502
+ {
503
+ ...restProps,
504
+ ref: forwardRef,
505
+ onValueChange: onChange
506
+ }
507
+ );
486
508
  });
487
509
 
488
510
  const StyledRadioContainer = styled(Primitive.div, {
@@ -543,24 +565,29 @@ const StyledRadioItem = styled(RadixDropdownMenu.RadioItem, {
543
565
 
544
566
  const RadioItem = React.forwardRef(({ disabled = false, children, ...restProps }, forwardRef) => {
545
567
  const ariaDisabledProps = useAriaDisabled(restProps, true);
546
- return /* @__PURE__ */ React.createElement(ItemProvider, null, /* @__PURE__ */ React.createElement(StyledRadioItem, {
547
- ...restProps,
548
- ...ariaDisabledProps,
549
- disabled,
550
- ref: forwardRef
551
- }, children, /* @__PURE__ */ React.createElement(RightSlot, null, /* @__PURE__ */ React.createElement(StyledRadioContainer, null, /* @__PURE__ */ React.createElement(StyledPill, null), /* @__PURE__ */ React.createElement(StyledProhibited, {
552
- weight: "thin"
553
- })))));
568
+ return /* @__PURE__ */ jsx(ItemProvider, { children: /* @__PURE__ */ jsxs(
569
+ StyledRadioItem,
570
+ {
571
+ ...restProps,
572
+ ...ariaDisabledProps,
573
+ disabled,
574
+ ref: forwardRef,
575
+ children: [
576
+ children,
577
+ /* @__PURE__ */ jsx(RightSlot, { children: /* @__PURE__ */ jsxs(StyledRadioContainer, { children: [
578
+ /* @__PURE__ */ jsx(StyledPill, {}),
579
+ /* @__PURE__ */ jsx(StyledProhibited, { weight: "thin" })
580
+ ] }) })
581
+ ]
582
+ }
583
+ ) });
554
584
  });
555
585
 
556
586
  const StyledSeparator = styled(RadixDropdownMenu.Separator, {
557
587
  borderTop: "1px solid $border-neutrals-subtle"
558
588
  });
559
589
 
560
- const Separator = React.forwardRef((props, forwardRef) => /* @__PURE__ */ React.createElement(StyledSeparator, {
561
- ...props,
562
- ref: forwardRef
563
- }));
590
+ const Separator = React.forwardRef((props, forwardRef) => /* @__PURE__ */ jsx(StyledSeparator, { ...props, ref: forwardRef }));
564
591
 
565
592
  const StyledSwitch = styled(Primitive.span, {
566
593
  ...styles.default,
@@ -581,14 +608,21 @@ const StyledSwitchItem = styled(RadixDropdownMenu.CheckboxItem, {
581
608
  const SwitchItem = React.forwardRef(
582
609
  ({ disabled = false, checked, onChange, children, ...restProps }, forwardRef) => {
583
610
  const ariaDisabledProps = useAriaDisabled(restProps, true);
584
- return /* @__PURE__ */ React.createElement(ItemProvider, null, /* @__PURE__ */ React.createElement(StyledSwitchItem, {
585
- ...restProps,
586
- ...ariaDisabledProps,
587
- disabled,
588
- checked,
589
- onCheckedChange: onChange,
590
- ref: forwardRef
591
- }, children, /* @__PURE__ */ React.createElement(RightSlot, null, /* @__PURE__ */ React.createElement(StyledSwitch, null, /* @__PURE__ */ React.createElement(Thumb, null)))));
611
+ return /* @__PURE__ */ jsx(ItemProvider, { children: /* @__PURE__ */ jsxs(
612
+ StyledSwitchItem,
613
+ {
614
+ ...restProps,
615
+ ...ariaDisabledProps,
616
+ disabled,
617
+ checked,
618
+ onCheckedChange: onChange,
619
+ ref: forwardRef,
620
+ children: [
621
+ children,
622
+ /* @__PURE__ */ jsx(RightSlot, { children: /* @__PURE__ */ jsx(StyledSwitch, { children: /* @__PURE__ */ jsx(Thumb, {}) }) })
623
+ ]
624
+ }
625
+ ) });
592
626
  }
593
627
  );
594
628
 
@@ -611,13 +645,32 @@ const StyledTrigger = styled(RadixDropdownMenu.Trigger, {
611
645
  }
612
646
  });
613
647
 
614
- const Trigger = React.forwardRef(({ asChild = false, onPress, onClick, ...restProps }, forwardRef) => /* @__PURE__ */ React.createElement(StyledTrigger, {
615
- ...restProps,
616
- onClick: onPress != null ? onPress : onClick,
617
- ref: forwardRef,
618
- unstyled: !asChild,
619
- asChild
620
- }));
648
+ const Trigger = React.forwardRef(({ asChild = false, onPress, onClick, ...restProps }, forwardRef) => {
649
+ const ref = useRef(null);
650
+ const handleVirtualClick = (e) => {
651
+ var _a;
652
+ if (isVirtualClick(e.nativeEvent) && ref.current !== null) {
653
+ const pointerDownEvent = new MouseEvent("pointerdown", {
654
+ bubbles: true,
655
+ cancelable: true
656
+ });
657
+ (_a = ref.current) == null ? void 0 : _a.dispatchEvent(pointerDownEvent);
658
+ }
659
+ };
660
+ return /* @__PURE__ */ jsx(
661
+ StyledTrigger,
662
+ {
663
+ ...restProps,
664
+ onClick: (e) => {
665
+ handleVirtualClick(e);
666
+ onClick == null ? void 0 : onClick(e);
667
+ },
668
+ ref: mergeRefs([ref, forwardRef]),
669
+ unstyled: !asChild,
670
+ asChild
671
+ }
672
+ );
673
+ });
621
674
 
622
675
  const StyledIconContainer = styled(Primitive.span, {
623
676
  color: "$icon-neutrals-with-text",
@@ -637,17 +690,25 @@ const SubTrigger = React.forwardRef(({ children, disabled = false, ...restProps
637
690
  onKeyDown: restProps.onKeyDown,
638
691
  "aria-disabled": restProps["aria-disabled"]
639
692
  });
640
- return /* @__PURE__ */ React.createElement(StyledSubTrigger, {
641
- ...restProps,
642
- ...ariaDisabledProps,
643
- disabled,
644
- ref: forwardRef
645
- }, children, /* @__PURE__ */ React.createElement(RightSlot, null, /* @__PURE__ */ React.createElement(StyledIconContainer, {
646
- "data-testid": process.env.NODE_ENV === "test" ? "submenu-arrow-icon" : void 0
647
- }, /* @__PURE__ */ React.createElement(IconChevronRight, {
648
- size: "small",
649
- weight: "thin"
650
- }))));
693
+ return /* @__PURE__ */ jsxs(
694
+ StyledSubTrigger,
695
+ {
696
+ ...restProps,
697
+ ...ariaDisabledProps,
698
+ disabled,
699
+ ref: forwardRef,
700
+ children: [
701
+ children,
702
+ /* @__PURE__ */ jsx(RightSlot, { children: /* @__PURE__ */ jsx(
703
+ StyledIconContainer,
704
+ {
705
+ "data-testid": process.env.NODE_ENV === "test" ? "submenu-arrow-icon" : void 0,
706
+ children: /* @__PURE__ */ jsx(IconChevronRight, { size: "small", weight: "thin" })
707
+ }
708
+ ) })
709
+ ]
710
+ }
711
+ );
651
712
  });
652
713
 
653
714
  const StyledSubContent = styled(
@@ -670,20 +731,20 @@ const SubContent = React.forwardRef(
670
731
  ...restProps
671
732
  }, forwardRef) => {
672
733
  const { containerSpacing } = useContent();
673
- return /* @__PURE__ */ React.createElement(ContentProvider, {
674
- containerSpacing
675
- }, /* @__PURE__ */ React.createElement(StyledSubContent, {
676
- ...restProps,
677
- ref: forwardRef,
678
- sideOffset,
679
- alignOffset,
680
- collisionPadding,
681
- loop,
682
- hideWhenDetached,
683
- sticky
684
- }, /* @__PURE__ */ React.createElement(ScrollableContent, {
685
- ...{ containerSpacing, maxHeight, overflow }
686
- }, children)));
734
+ return /* @__PURE__ */ jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsx(
735
+ StyledSubContent,
736
+ {
737
+ ...restProps,
738
+ ref: forwardRef,
739
+ sideOffset,
740
+ alignOffset,
741
+ collisionPadding,
742
+ loop,
743
+ hideWhenDetached,
744
+ sticky,
745
+ children: /* @__PURE__ */ jsx(ScrollableContent, { ...{ containerSpacing, maxHeight, overflow }, children })
746
+ }
747
+ ) });
687
748
  }
688
749
  );
689
750
 
@@ -692,23 +753,24 @@ const StyledSub = styled(RadixDropdownMenu.Sub, {});
692
753
  const Sub = React.forwardRef(
693
754
  ({ defaultOpen, onOpen, onClose, open, ...restProps }, forwardRef) => {
694
755
  const [openState, setOpenState] = useState(defaultOpen);
695
- return /* @__PURE__ */ React.createElement(StyledSub, {
696
- ...restProps,
697
- open: open != null ? open : openState,
698
- onOpenChange: (newOpen) => {
699
- if (open == null) {
700
- setOpenState(newOpen);
701
- }
702
- newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
703
- },
704
- ref: forwardRef
705
- });
756
+ return /* @__PURE__ */ jsx(
757
+ StyledSub,
758
+ {
759
+ ...restProps,
760
+ open: open != null ? open : openState,
761
+ onOpenChange: (newOpen) => {
762
+ if (open == null) {
763
+ setOpenState(newOpen);
764
+ }
765
+ newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
766
+ },
767
+ ref: forwardRef
768
+ }
769
+ );
706
770
  }
707
771
  );
708
772
 
709
- const Portal = (props) => /* @__PURE__ */ React.createElement(Portal$1, {
710
- ...props
711
- });
773
+ const Portal = (props) => /* @__PURE__ */ jsx(Portal$1, { ...props });
712
774
 
713
775
  const StyledIconSlot = styled(LeftSlot, {
714
776
  square: "$5",
@@ -733,13 +795,7 @@ const IconSlot = React.forwardRef(({ children, ...restProps }, forwardRef) => {
733
795
  leftSlotMount();
734
796
  return () => leftSlotDestroy();
735
797
  }, [leftSlotMount, leftSlotDestroy]);
736
- return /* @__PURE__ */ React.createElement(StyledIconSlot, {
737
- ref: forwardRef,
738
- ...restProps
739
- }, /* @__PURE__ */ React.createElement(Primitive.svg, {
740
- asChild: true,
741
- "aria-hidden": true
742
- }, formattedChildren));
798
+ return /* @__PURE__ */ jsx(StyledIconSlot, { ref: forwardRef, ...restProps, children: /* @__PURE__ */ jsx(Primitive.svg, { asChild: true, "aria-hidden": true, children: formattedChildren }) });
743
799
  });
744
800
 
745
801
  const IllustrationSlot = React.forwardRef((props, forwardRef) => {
@@ -748,10 +804,7 @@ const IllustrationSlot = React.forwardRef((props, forwardRef) => {
748
804
  leftSlotMount();
749
805
  return () => leftSlotDestroy();
750
806
  }, [leftSlotMount, leftSlotDestroy]);
751
- return /* @__PURE__ */ React.createElement(StyledIllustrationSlot, {
752
- ref: forwardRef,
753
- ...props
754
- });
807
+ return /* @__PURE__ */ jsx(StyledIllustrationSlot, { ref: forwardRef, ...props });
755
808
  });
756
809
 
757
810
  const DropdownMenu = ({
@@ -764,18 +817,21 @@ const DropdownMenu = ({
764
817
  ...restProps
765
818
  }) => {
766
819
  const [openState, setOpenState] = useState(defaultOpen);
767
- return /* @__PURE__ */ React.createElement(RadixDropdownMenu.Root, {
768
- ...restProps,
769
- dir: direction,
770
- modal: interactOutside,
771
- open: open != null ? open : openState,
772
- onOpenChange: (newOpen) => {
773
- if (open == null) {
774
- setOpenState(newOpen);
820
+ return /* @__PURE__ */ jsx(
821
+ RadixDropdownMenu.Root,
822
+ {
823
+ ...restProps,
824
+ dir: direction,
825
+ modal: interactOutside,
826
+ open: open != null ? open : openState,
827
+ onOpenChange: (newOpen) => {
828
+ if (open == null) {
829
+ setOpenState(newOpen);
830
+ }
831
+ newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
775
832
  }
776
- newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
777
833
  }
778
- });
834
+ );
779
835
  };
780
836
  DropdownMenu.CheckboxItem = CheckboxItem;
781
837
  DropdownMenu.Content = Content;