@mirohq/design-system-dropdown-menu 3.3.0-dropdown.3 → 3.3.0-dropdown.5

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 CHANGED
@@ -10,6 +10,7 @@ var designSystemPrimitive = require('@mirohq/design-system-primitive');
10
10
  var designSystemStitches = require('@mirohq/design-system-stitches');
11
11
  var designSystemStyles = require('@mirohq/design-system-styles');
12
12
  var designSystemBaseSwitch = require('@mirohq/design-system-base-switch');
13
+ var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -51,18 +52,20 @@ const LeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div
51
52
  marginRight: "$100",
52
53
  gridArea: "left-slot"
53
54
  });
54
- const IconSlot = designSystemStitches.styled(LeftSlot, {
55
- width: "$6"
56
- });
57
55
  const IllustrationSlot = designSystemStitches.styled(LeftSlot, {
58
56
  width: "$13"
59
57
  });
60
- const RightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
58
+ const StyledRightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
61
59
  display: "flex",
62
60
  alignItems: "center",
63
61
  marginLeft: "auto",
64
62
  paddingLeft: "$200",
65
- gridArea: "right-slot"
63
+ gridArea: "right-slot",
64
+ minWidth: "max-content",
65
+ textAlign: "right",
66
+ "&:empty": {
67
+ paddingLeft: "$none"
68
+ }
66
69
  });
67
70
 
68
71
  const itemDefaults = {
@@ -75,16 +78,26 @@ const itemDefaults = {
75
78
  display: "grid",
76
79
  gridTemplateColumns: "auto 1fr auto",
77
80
  gridTemplateRows: "1fr auto",
78
- gridTemplateAreas: `
79
- 'left-slot item-text right-slot'
80
- 'left-slot item-description right-slot'
81
- `,
82
- alignItems: "center",
83
- minHeight: "$11",
84
- padding: "$100 $150",
81
+ gridTemplateAreas: `'left-slot item-text right-slot'
82
+ 'left-slot item-description right-slot'`,
83
+ alignItems: "start",
84
+ minHeight: "$10",
85
+ padding: "$100 $100",
85
86
  position: "relative",
86
87
  userSelect: "none",
87
88
  cursor: "pointer",
89
+ "&[data-no-left-slot]": {
90
+ gridTemplateColumns: "1fr auto",
91
+ gridTemplateRows: "auto",
92
+ gridTemplateAreas: `'item-text right-slot'
93
+ 'item-description right-slot'`
94
+ },
95
+ "&:not(:last-child)": {
96
+ marginBottom: "$50"
97
+ },
98
+ "&:not(:first-child)": {
99
+ marginTop: "$50"
100
+ },
88
101
  ...designSystemStyles.focus.defaults,
89
102
  '&:disabled, &[aria-disabled="true"], &[data-disabled]': {
90
103
  pointerEvents: "none",
@@ -112,7 +125,9 @@ const itemDefaults = {
112
125
  }
113
126
  };
114
127
 
115
- const StyledIndicator = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {});
128
+ const StyledIndicator = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
129
+ padding: "4px 6px"
130
+ });
116
131
  const StyledCheckboxItem = designSystemStitches.styled(RadixDropdownMenu__namespace.CheckboxItem, {
117
132
  ...itemDefaults,
118
133
  [`&[data-state="checked"] ${StyledIndicator}`]: {
@@ -129,6 +144,53 @@ const StyledCheckboxItem = designSystemStitches.styled(RadixDropdownMenu__namesp
129
144
  }
130
145
  });
131
146
 
147
+ const Context = React.createContext({
148
+ counter: {
149
+ right: 0,
150
+ left: 0
151
+ },
152
+ increaseCounter: () => {
153
+ },
154
+ decreaseCounter: () => {
155
+ }
156
+ });
157
+ const SlotsProvider = ({
158
+ children
159
+ }) => {
160
+ const [counter, setCounter] = React.useState({
161
+ right: 0,
162
+ left: 0
163
+ });
164
+ return /* @__PURE__ */ React__default["default"].createElement(Context.Provider, {
165
+ value: {
166
+ counter,
167
+ increaseCounter: (side) => {
168
+ setCounter((counter2) => ({
169
+ ...counter2,
170
+ [side]: counter2[side] + 1
171
+ }));
172
+ },
173
+ decreaseCounter: (side) => setCounter((counter2) => ({
174
+ ...counter2,
175
+ [side]: counter2[side] - 1
176
+ }))
177
+ }
178
+ }, children);
179
+ };
180
+ const useSlots = () => React.useContext(Context);
181
+
182
+ const RightSlot = (props) => {
183
+ const { increaseCounter, decreaseCounter } = useSlots();
184
+ React.useEffect(() => {
185
+ increaseCounter("right");
186
+ return () => decreaseCounter("right");
187
+ }, []);
188
+ return /* @__PURE__ */ React__default["default"].createElement(StyledRightSlot, {
189
+ ...props
190
+ });
191
+ };
192
+ const HotkeySlot = RightSlot;
193
+
132
194
  const useAriaDisabled = ({ "aria-disabled": ariaDisabled, onKeyDown, onSelect }, preventDefault = false) => React.useMemo(
133
195
  () => ({
134
196
  "aria-disabled": designSystemUtils.booleanify(ariaDisabled) ? ariaDisabled : void 0,
@@ -166,26 +228,17 @@ const CheckboxItem = React__default["default"].forwardRef(({ children, checked,
166
228
  }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledIndicator, null, (disabled === true || designSystemUtils.booleanify(ariaDisabled)) && !checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconProhibit, {
167
229
  size: "small"
168
230
  }), checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconCheckMark, {
169
- size: "small"
231
+ css: { width: "12px", display: "block" }
170
232
  }))));
171
233
  });
172
234
 
173
- const GUTTER_TOKEN = 150;
174
- const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[GUTTER_TOKEN]);
235
+ const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[150]);
175
236
  const CONTENT_OFFSET = parseInt(designSystemStitches.theme.space[50]);
176
- const ITEM_WITHOUT_RIGHT_SLOT = `[role="menuitem"]:not(:has(${RightSlot}))`;
177
237
  const contentDefaults = {
178
238
  maxWidth: "$125",
179
239
  backgroundColor: "$white",
180
240
  borderRadius: "$50",
181
- padding: `$${GUTTER_TOKEN}`,
182
241
  boxShadow: "$50",
183
- [`&:has(${RightSlot}) > ${ITEM_WITHOUT_RIGHT_SLOT}`]: {
184
- paddingRight: "44px"
185
- },
186
- [`&:has([role="switch"]) > ${ITEM_WITHOUT_RIGHT_SLOT}`]: {
187
- paddingRight: "56px"
188
- },
189
242
  "@media (prefers-reduced-motion: no-preference)": {
190
243
  animationDuration: "150ms",
191
244
  animationTimingFunction: "cubic-bezier(0.25, 0.5, 0.5, 0.9)",
@@ -217,7 +270,28 @@ const contentDefaults = {
217
270
  zIndex: "$dropdownMenu"
218
271
  };
219
272
 
220
- const StyledContent = designSystemStitches.styled(RadixDropdownMenu__namespace.Content, contentDefaults);
273
+ const StyledContent = designSystemStitches.styled(RadixDropdownMenu__namespace.Content, {
274
+ ...contentDefaults,
275
+ variants: {
276
+ containerSpacing: {
277
+ small: {
278
+ '&, [role="menu"]': {
279
+ padding: "$50 $150"
280
+ }
281
+ },
282
+ medium: {
283
+ '&, [role="menu"]': {
284
+ padding: "$150"
285
+ }
286
+ },
287
+ large: {
288
+ '&, [role="menu"]': {
289
+ padding: "$150 $300"
290
+ }
291
+ }
292
+ }
293
+ }
294
+ });
221
295
 
222
296
  const Content = React__default["default"].forwardRef(
223
297
  ({
@@ -230,8 +304,9 @@ const Content = React__default["default"].forwardRef(
230
304
  avoidCollisions = true,
231
305
  sticky = "partial",
232
306
  hideWhenDetached = false,
307
+ containerSpacing = "medium",
233
308
  ...restProps
234
- }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledContent, {
309
+ }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(SlotsProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledContent, {
235
310
  ...restProps,
236
311
  ref: forwardRef,
237
312
  loop,
@@ -242,20 +317,32 @@ const Content = React__default["default"].forwardRef(
242
317
  avoidCollisions,
243
318
  collisionPadding,
244
319
  sticky,
245
- hideWhenDetached
246
- })
320
+ hideWhenDetached,
321
+ containerSpacing
322
+ }))
247
323
  );
248
324
 
249
- const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item, itemDefaults);
325
+ const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item, {
326
+ ...itemDefaults,
327
+ variants: {
328
+ hasRightSlot: {
329
+ true: {
330
+ paddingRight: "$600"
331
+ }
332
+ }
333
+ }
334
+ });
250
335
 
251
336
  const Item = React__default["default"].forwardRef(
252
337
  ({ disabled = false, ...restProps }, forwardRef) => {
338
+ const { counter } = useSlots();
253
339
  const ariaDisabledProps = useAriaDisabled(restProps);
254
340
  return /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
255
341
  ...restProps,
256
342
  ...ariaDisabledProps,
257
343
  disabled,
258
- ref: forwardRef
344
+ ref: forwardRef,
345
+ hasRightSlot: counter.right > 0
259
346
  });
260
347
  }
261
348
  );
@@ -272,7 +359,9 @@ const LinkItem = React__default["default"].forwardRef(({ children, href, ...rest
272
359
  }, children));
273
360
  });
274
361
 
275
- const StyledRadioGroup = designSystemStitches.styled(RadixDropdownMenu__namespace.RadioGroup);
362
+ const StyledRadioGroup = designSystemStitches.styled(RadixDropdownMenu__namespace.RadioGroup, {
363
+ marginY: "$50"
364
+ });
276
365
 
277
366
  const RadioGroup = React__default["default"].forwardRef((props, forwardRef) => {
278
367
  const { onChange, ...restProps } = props;
@@ -291,7 +380,8 @@ const StyledRadioContainer = designSystemStitches.styled(designSystemPrimitive.P
291
380
  height: "$4",
292
381
  boxSizing: "border-box",
293
382
  border: "1px solid $border-neutrals",
294
- borderRadius: "$half"
383
+ borderRadius: "$half",
384
+ marginTop: "2px"
295
385
  });
296
386
  const StyledPill = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
297
387
  display: "none",
@@ -350,8 +440,7 @@ const RadioItem = React__default["default"].forwardRef(({ disabled = false, chil
350
440
  });
351
441
 
352
442
  const StyledSeparator = designSystemStitches.styled(RadixDropdownMenu__namespace.Separator, {
353
- borderTop: "1px solid $border-neutrals-subtle",
354
- marginY: "$100"
443
+ borderTop: "1px solid $border-neutrals-subtle"
355
444
  });
356
445
 
357
446
  const Separator = React__default["default"].forwardRef((props, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSeparator, {
@@ -362,7 +451,8 @@ const Separator = React__default["default"].forwardRef((props, forwardRef) => /*
362
451
  const StyledSwitch = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
363
452
  ...designSystemBaseSwitch.styles.default,
364
453
  width: "$7",
365
- height: "$4"
454
+ height: "$4",
455
+ marginTop: "2px"
366
456
  });
367
457
  const StyledSwitchItem = designSystemStitches.styled(RadixDropdownMenu__namespace.CheckboxItem, {
368
458
  ...itemDefaults,
@@ -389,19 +479,18 @@ const SwitchItem = React__default["default"].forwardRef(
389
479
  }
390
480
  );
391
481
 
392
- const defaultStyles = {
393
- boxSizing: "border-box",
394
- cursor: "pointer",
395
- ...designSystemStyles.focus.defaults
396
- };
397
482
  const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.Trigger, {
398
483
  variants: {
399
484
  unstyled: {
400
485
  true: {
401
486
  all: "unset",
402
- ...defaultStyles
487
+ boxSizing: "border-box",
488
+ cursor: "pointer",
489
+ ...designSystemStyles.focus.defaults
403
490
  },
404
- false: defaultStyles
491
+ false: {
492
+ cursor: "pointer"
493
+ }
405
494
  }
406
495
  }
407
496
  });
@@ -414,21 +503,18 @@ const Trigger = React__default["default"].forwardRef(({ asChild = false, onPress
414
503
  asChild
415
504
  }));
416
505
 
506
+ const StyledIconContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
507
+ color: "$icon-neutrals-with-text",
508
+ marginRight: "-4px"
509
+ });
417
510
  const StyledSubTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.SubTrigger, {
418
511
  ...itemDefaults,
419
- '&[data-state="open"]': itemDefaults["&:hover"]
512
+ '&[data-state="open"]': itemDefaults["&:hover"],
513
+ [`&[data-state="open"] ${StyledIconContainer}, &:hover ${StyledIconContainer}`]: {
514
+ color: "$icon-primary-hover"
515
+ }
420
516
  });
421
517
 
422
- const ArrowIcon = () => /* @__PURE__ */ React__default["default"].createElement("svg", {
423
- width: "16",
424
- height: "16",
425
- viewBox: "0 0 16 16",
426
- fill: "currentColor",
427
- xmlns: "http://www.w3.org/2000/svg",
428
- "data-testid": "submenu-arrow-icon"
429
- }, /* @__PURE__ */ React__default["default"].createElement("path", {
430
- d: "M5.29289 3.29289C5.68342 2.90237 6.31658 2.90237 6.70711 3.29289L11.4142 8L6.70711 12.7071C6.31658 13.0976 5.68342 13.0976 5.29289 12.7071C4.90237 12.3166 4.90237 11.6834 5.29289 11.2929L8.58579 8L5.29289 4.70711C4.90237 4.31658 4.90237 3.68342 5.29289 3.29289Z"
431
- }));
432
518
  const SubTrigger = React__default["default"].forwardRef(({ children, disabled = false, ...restProps }, forwardRef) => {
433
519
  const { onSelect, ...ariaDisabledProps } = useAriaDisabled({
434
520
  onKeyDown: restProps.onKeyDown,
@@ -439,7 +525,12 @@ const SubTrigger = React__default["default"].forwardRef(({ children, disabled =
439
525
  ...ariaDisabledProps,
440
526
  disabled,
441
527
  ref: forwardRef
442
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(ArrowIcon, null)));
528
+ }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledIconContainer, {
529
+ "data-testid": process.env.NODE_ENV === "test" ? "submenu-arrow-icon" : void 0
530
+ }, /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconChevronRight, {
531
+ size: "small",
532
+ weight: "thin"
533
+ }))));
443
534
  });
444
535
 
445
536
  const StyledSubContent = designSystemStitches.styled(
@@ -457,7 +548,7 @@ const SubContent = React__default["default"].forwardRef(
457
548
  hideWhenDetached = false,
458
549
  sticky = "partial",
459
550
  ...restProps
460
- }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSubContent, {
551
+ }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(SlotsProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledSubContent, {
461
552
  ...restProps,
462
553
  ref: forwardRef,
463
554
  sideOffset,
@@ -466,7 +557,7 @@ const SubContent = React__default["default"].forwardRef(
466
557
  loop,
467
558
  hideWhenDetached,
468
559
  sticky
469
- })
560
+ }))
470
561
  );
471
562
 
472
563
  const StyledSub = designSystemStitches.styled(RadixDropdownMenu__namespace.Sub, {});
@@ -492,6 +583,32 @@ const Portal = (props) => /* @__PURE__ */ React__default["default"].createElemen
492
583
  ...props
493
584
  });
494
585
 
586
+ const StyledIconSlot = designSystemStitches.styled(LeftSlot, {
587
+ paddingTop: "2px",
588
+ variants: {
589
+ customIcon: {
590
+ true: {
591
+ square: "$icon-200"
592
+ }
593
+ }
594
+ }
595
+ });
596
+
597
+ const IconSlot = React__default["default"].forwardRef(({ children, ...restProps }, forwardRef) => {
598
+ const child = React__default["default"].Children.only(children);
599
+ const isIcon = designSystemBaseIcon.isIconComponent(child);
600
+ const formattedChild = isIcon ? React__default["default"].cloneElement(child, {
601
+ ...child.props,
602
+ size: "small",
603
+ weight: "thin"
604
+ }) : child;
605
+ return /* @__PURE__ */ React__default["default"].createElement(StyledIconSlot, {
606
+ ref: forwardRef,
607
+ ...restProps,
608
+ customIcon: !isIcon
609
+ }, formattedChild);
610
+ });
611
+
495
612
  const DropdownMenu = ({
496
613
  defaultOpen = false,
497
614
  direction = "ltr",
@@ -517,6 +634,7 @@ const DropdownMenu = ({
517
634
  };
518
635
  DropdownMenu.CheckboxItem = CheckboxItem;
519
636
  DropdownMenu.Content = Content;
637
+ DropdownMenu.HotkeySlot = HotkeySlot;
520
638
  DropdownMenu.IconSlot = IconSlot;
521
639
  DropdownMenu.IllustrationSlot = IllustrationSlot;
522
640
  DropdownMenu.Item = Item;