@mirohq/design-system-dropdown-menu 3.3.0-dropdown.4 → 3.3.0-dropdown.6

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
 
@@ -45,23 +46,140 @@ const ItemDescription = designSystemStitches.styled(designSystemPrimitive.Primit
45
46
  color: "$text-neutrals-subtle"
46
47
  });
47
48
 
49
+ const Context$1 = React.createContext({
50
+ rightSlotMount: () => 0,
51
+ rightSlotDestroy: () => {
52
+ }
53
+ });
54
+ const ContentProvider = ({
55
+ children
56
+ }) => {
57
+ const [maxWidth, setMaxWidth] = React.useState(0);
58
+ const maxRef = React.useRef(0);
59
+ const indexRef = React.useRef(0);
60
+ const widthMapRef = React.useRef(/* @__PURE__ */ new Map());
61
+ const updateMaxWith = React.useCallback((value) => {
62
+ maxRef.current = value;
63
+ setMaxWidth(value);
64
+ }, []);
65
+ const rightSlotMount = React.useCallback(
66
+ (width) => {
67
+ indexRef.current++;
68
+ widthMapRef.current.set(indexRef.current, width);
69
+ if (width > maxRef.current) {
70
+ updateMaxWith(width);
71
+ }
72
+ return indexRef.current;
73
+ },
74
+ [updateMaxWith]
75
+ );
76
+ const rightSlotDestroy = React.useCallback(
77
+ (index) => {
78
+ widthMapRef.current.delete(index);
79
+ if (widthMapRef.current.size === 0) {
80
+ updateMaxWith(0);
81
+ } else {
82
+ const maximum = Math.max(...Array.from(widthMapRef.current.values()));
83
+ updateMaxWith(maximum);
84
+ }
85
+ },
86
+ [updateMaxWith]
87
+ );
88
+ const formattedChildren = designSystemUtils.addPropsToChildren(children, () => true, {
89
+ UNSAFE_style: {
90
+ "--right-slot-max-width": `${Math.ceil(maxWidth)}px`
91
+ }
92
+ });
93
+ return /* @__PURE__ */ React__default["default"].createElement(Context$1.Provider, {
94
+ value: {
95
+ rightSlotMount,
96
+ rightSlotDestroy
97
+ }
98
+ }, formattedChildren);
99
+ };
100
+ const useContent = () => React.useContext(Context$1);
101
+
48
102
  const LeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
49
103
  display: "flex",
50
104
  placeContent: "center",
51
105
  marginRight: "$100",
52
106
  gridArea: "left-slot"
53
107
  });
54
- const IllustrationSlot = designSystemStitches.styled(LeftSlot, {
108
+ const StyledIllustrationSlot = designSystemStitches.styled(LeftSlot, {
55
109
  width: "$13"
56
110
  });
57
- const RightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
111
+ const StyledRightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
58
112
  display: "flex",
59
113
  alignItems: "center",
60
114
  marginLeft: "auto",
61
115
  paddingLeft: "$200",
62
- gridArea: "right-slot"
116
+ gridArea: "right-slot",
117
+ minWidth: "max-content",
118
+ textAlign: "right",
119
+ "&:empty": {
120
+ paddingLeft: "$none"
121
+ }
122
+ });
123
+
124
+ const Context = React.createContext({
125
+ leftSlotMount: () => {
126
+ },
127
+ leftSlotDestroy: () => {
128
+ }
129
+ });
130
+ const ItemProvider = ({
131
+ children
132
+ }) => {
133
+ const [hasSlot, setHasSlot] = React.useState(false);
134
+ const leftSlotMount = React.useCallback(() => {
135
+ setHasSlot(true);
136
+ }, []);
137
+ const leftSlotDestroy = React.useCallback(() => {
138
+ setHasSlot(false);
139
+ }, []);
140
+ const formattedChildren = hasSlot ? children : designSystemUtils.addPropsToChildren(children, () => true, {
141
+ "data-no-left-slot": ""
142
+ });
143
+ return /* @__PURE__ */ React__default["default"].createElement(Context.Provider, {
144
+ value: {
145
+ leftSlotMount,
146
+ leftSlotDestroy
147
+ }
148
+ }, formattedChildren);
149
+ };
150
+ const useItem = () => React.useContext(Context);
151
+
152
+ const RightSlot = (props) => {
153
+ const { rightSlotMount, rightSlotDestroy } = useContent();
154
+ const ref = React.useRef(null);
155
+ React.useEffect(() => {
156
+ if (ref.current !== null) {
157
+ const width = ref.current.getBoundingClientRect().width;
158
+ const index = rightSlotMount(width);
159
+ return () => rightSlotDestroy(index);
160
+ }
161
+ return () => {
162
+ };
163
+ }, [rightSlotMount, rightSlotDestroy, ref]);
164
+ return /* @__PURE__ */ React__default["default"].createElement(StyledRightSlot, {
165
+ ref,
166
+ ...props
167
+ });
168
+ };
169
+ const HotkeySlot = designSystemStitches.styled(RightSlot, {
170
+ color: "$text-neutrals-subtle"
171
+ });
172
+ const IllustrationSlot = React__default["default"].forwardRef((props, forwardRef) => {
173
+ const { leftSlotMount, leftSlotDestroy } = useItem();
174
+ React.useEffect(() => {
175
+ leftSlotMount();
176
+ return () => leftSlotDestroy();
177
+ }, [leftSlotMount, leftSlotDestroy]);
178
+ return /* @__PURE__ */ React__default["default"].createElement(StyledIllustrationSlot, {
179
+ ref: forwardRef,
180
+ ...props
181
+ });
63
182
  });
64
- const HotkeySlot = RightSlot;
65
183
 
66
184
  const itemDefaults = {
67
185
  all: "unset",
@@ -71,18 +189,28 @@ const itemDefaults = {
71
189
  color: "$text-neutrals",
72
190
  borderRadius: "$50",
73
191
  display: "grid",
74
- gridTemplateColumns: "auto 1fr auto",
192
+ gridTemplateColumns: "auto 1fr minmax(auto, var(--right-slot-max-width))",
75
193
  gridTemplateRows: "1fr auto",
76
- gridTemplateAreas: `
77
- 'left-slot item-text right-slot'
78
- 'left-slot item-description right-slot'
79
- `,
80
- alignItems: "center",
81
- minHeight: "$11",
82
- padding: "$100 $150",
194
+ gridTemplateAreas: `'left-slot item-text right-slot'
195
+ 'left-slot item-description right-slot'`,
196
+ alignItems: "start",
197
+ minHeight: "$10",
198
+ padding: "$100 $100",
83
199
  position: "relative",
84
200
  userSelect: "none",
85
201
  cursor: "pointer",
202
+ "&[data-no-left-slot]": {
203
+ gridTemplateColumns: "1fr minmax(auto, var(--right-slot-max-width))",
204
+ gridTemplateRows: "auto",
205
+ gridTemplateAreas: `'item-text right-slot'
206
+ 'item-description right-slot'`
207
+ },
208
+ "&:not(:last-child)": {
209
+ marginBottom: "$50"
210
+ },
211
+ "&:not(:first-child)": {
212
+ marginTop: "$50"
213
+ },
86
214
  ...designSystemStyles.focus.defaults,
87
215
  '&:disabled, &[aria-disabled="true"], &[data-disabled]': {
88
216
  pointerEvents: "none",
@@ -110,7 +238,9 @@ const itemDefaults = {
110
238
  }
111
239
  };
112
240
 
113
- const StyledIndicator = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {});
241
+ const StyledIndicator = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
242
+ padding: "4px 6px"
243
+ });
114
244
  const StyledCheckboxItem = designSystemStitches.styled(RadixDropdownMenu__namespace.CheckboxItem, {
115
245
  ...itemDefaults,
116
246
  [`&[data-state="checked"] ${StyledIndicator}`]: {
@@ -154,7 +284,7 @@ const useAriaDisabled = ({ "aria-disabled": ariaDisabled, onKeyDown, onSelect },
154
284
  const CheckboxItem = React__default["default"].forwardRef(({ children, checked, onChange, disabled, ...restProps }, forwardRef) => {
155
285
  const ariaDisabledProps = useAriaDisabled(restProps, true);
156
286
  const { "aria-disabled": ariaDisabled } = ariaDisabledProps;
157
- return /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
287
+ return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
158
288
  ...restProps,
159
289
  ...ariaDisabledProps,
160
290
  ref: forwardRef,
@@ -164,26 +294,17 @@ const CheckboxItem = React__default["default"].forwardRef(({ children, checked,
164
294
  }, 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, {
165
295
  size: "small"
166
296
  }), checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconCheckMark, {
167
- size: "small"
168
- }))));
297
+ css: { width: "12px", display: "block" }
298
+ })))));
169
299
  });
170
300
 
171
- const GUTTER_TOKEN = 150;
172
- const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[GUTTER_TOKEN]);
301
+ const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[150]);
173
302
  const CONTENT_OFFSET = parseInt(designSystemStitches.theme.space[50]);
174
- const ITEM_WITHOUT_RIGHT_SLOT = `[role="menuitem"]:not(:has(${RightSlot}))`;
175
303
  const contentDefaults = {
176
304
  maxWidth: "$125",
177
305
  backgroundColor: "$white",
178
306
  borderRadius: "$50",
179
- padding: `$${GUTTER_TOKEN}`,
180
307
  boxShadow: "$50",
181
- [`&:has(${RightSlot}) > ${ITEM_WITHOUT_RIGHT_SLOT}`]: {
182
- paddingRight: "44px"
183
- },
184
- [`&:has([role="switch"]) > ${ITEM_WITHOUT_RIGHT_SLOT}`]: {
185
- paddingRight: "56px"
186
- },
187
308
  "@media (prefers-reduced-motion: no-preference)": {
188
309
  animationDuration: "150ms",
189
310
  animationTimingFunction: "cubic-bezier(0.25, 0.5, 0.5, 0.9)",
@@ -215,7 +336,28 @@ const contentDefaults = {
215
336
  zIndex: "$dropdownMenu"
216
337
  };
217
338
 
218
- const StyledContent = designSystemStitches.styled(RadixDropdownMenu__namespace.Content, contentDefaults);
339
+ const StyledContent = designSystemStitches.styled(RadixDropdownMenu__namespace.Content, {
340
+ ...contentDefaults,
341
+ variants: {
342
+ containerSpacing: {
343
+ small: {
344
+ '&, [role="menu"]': {
345
+ padding: "$50 $150"
346
+ }
347
+ },
348
+ medium: {
349
+ '&, [role="menu"]': {
350
+ padding: "$150"
351
+ }
352
+ },
353
+ large: {
354
+ '&, [role="menu"]': {
355
+ padding: "$150 $300"
356
+ }
357
+ }
358
+ }
359
+ }
360
+ });
219
361
 
220
362
  const Content = React__default["default"].forwardRef(
221
363
  ({
@@ -228,8 +370,9 @@ const Content = React__default["default"].forwardRef(
228
370
  avoidCollisions = true,
229
371
  sticky = "partial",
230
372
  hideWhenDetached = false,
373
+ containerSpacing = "medium",
231
374
  ...restProps
232
- }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledContent, {
375
+ }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(ContentProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledContent, {
233
376
  ...restProps,
234
377
  ref: forwardRef,
235
378
  loop,
@@ -240,21 +383,31 @@ const Content = React__default["default"].forwardRef(
240
383
  avoidCollisions,
241
384
  collisionPadding,
242
385
  sticky,
243
- hideWhenDetached
244
- })
386
+ hideWhenDetached,
387
+ containerSpacing
388
+ }))
245
389
  );
246
390
 
247
- const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item, itemDefaults);
391
+ const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item, {
392
+ ...itemDefaults,
393
+ variants: {
394
+ hasRightSlot: {
395
+ true: {
396
+ paddingRight: "$600"
397
+ }
398
+ }
399
+ }
400
+ });
248
401
 
249
402
  const Item = React__default["default"].forwardRef(
250
403
  ({ disabled = false, ...restProps }, forwardRef) => {
251
404
  const ariaDisabledProps = useAriaDisabled(restProps);
252
- return /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
405
+ return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
253
406
  ...restProps,
254
407
  ...ariaDisabledProps,
255
408
  disabled,
256
409
  ref: forwardRef
257
- });
410
+ }));
258
411
  }
259
412
  );
260
413
 
@@ -270,7 +423,9 @@ const LinkItem = React__default["default"].forwardRef(({ children, href, ...rest
270
423
  }, children));
271
424
  });
272
425
 
273
- const StyledRadioGroup = designSystemStitches.styled(RadixDropdownMenu__namespace.RadioGroup);
426
+ const StyledRadioGroup = designSystemStitches.styled(RadixDropdownMenu__namespace.RadioGroup, {
427
+ marginY: "$50"
428
+ });
274
429
 
275
430
  const RadioGroup = React__default["default"].forwardRef((props, forwardRef) => {
276
431
  const { onChange, ...restProps } = props;
@@ -289,7 +444,8 @@ const StyledRadioContainer = designSystemStitches.styled(designSystemPrimitive.P
289
444
  height: "$4",
290
445
  boxSizing: "border-box",
291
446
  border: "1px solid $border-neutrals",
292
- borderRadius: "$half"
447
+ borderRadius: "$half",
448
+ marginTop: "2px"
293
449
  });
294
450
  const StyledPill = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
295
451
  display: "none",
@@ -339,17 +495,16 @@ const StyledRadioItem = designSystemStitches.styled(RadixDropdownMenu__namespace
339
495
 
340
496
  const RadioItem = React__default["default"].forwardRef(({ disabled = false, children, ...restProps }, forwardRef) => {
341
497
  const ariaDisabledProps = useAriaDisabled(restProps, true);
342
- return /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
498
+ return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
343
499
  ...restProps,
344
500
  ...ariaDisabledProps,
345
501
  disabled,
346
502
  ref: forwardRef
347
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledRadioContainer, null, /* @__PURE__ */ React__default["default"].createElement(StyledPill, null), /* @__PURE__ */ React__default["default"].createElement(StyledProhibited, null))));
503
+ }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledRadioContainer, null, /* @__PURE__ */ React__default["default"].createElement(StyledPill, null), /* @__PURE__ */ React__default["default"].createElement(StyledProhibited, null)))));
348
504
  });
349
505
 
350
506
  const StyledSeparator = designSystemStitches.styled(RadixDropdownMenu__namespace.Separator, {
351
- borderTop: "1px solid $border-neutrals-subtle",
352
- marginY: "$100"
507
+ borderTop: "1px solid $border-neutrals-subtle"
353
508
  });
354
509
 
355
510
  const Separator = React__default["default"].forwardRef((props, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSeparator, {
@@ -360,7 +515,8 @@ const Separator = React__default["default"].forwardRef((props, forwardRef) => /*
360
515
  const StyledSwitch = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
361
516
  ...designSystemBaseSwitch.styles.default,
362
517
  width: "$7",
363
- height: "$4"
518
+ height: "$4",
519
+ marginTop: "2px"
364
520
  });
365
521
  const StyledSwitchItem = designSystemStitches.styled(RadixDropdownMenu__namespace.CheckboxItem, {
366
522
  ...itemDefaults,
@@ -376,30 +532,29 @@ const StyledSwitchItem = designSystemStitches.styled(RadixDropdownMenu__namespac
376
532
  const SwitchItem = React__default["default"].forwardRef(
377
533
  ({ disabled = false, checked, onChange, children, ...restProps }, forwardRef) => {
378
534
  const ariaDisabledProps = useAriaDisabled(restProps, true);
379
- return /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
535
+ return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
380
536
  ...restProps,
381
537
  ...ariaDisabledProps,
382
538
  disabled,
383
539
  checked,
384
540
  onCheckedChange: onChange,
385
541
  ref: forwardRef
386
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledSwitch, null, /* @__PURE__ */ React__default["default"].createElement(designSystemBaseSwitch.Thumb, null))));
542
+ }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledSwitch, null, /* @__PURE__ */ React__default["default"].createElement(designSystemBaseSwitch.Thumb, null)))));
387
543
  }
388
544
  );
389
545
 
390
- const defaultStyles = {
391
- boxSizing: "border-box",
392
- cursor: "pointer",
393
- ...designSystemStyles.focus.defaults
394
- };
395
546
  const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.Trigger, {
396
547
  variants: {
397
548
  unstyled: {
398
549
  true: {
399
550
  all: "unset",
400
- ...defaultStyles
551
+ boxSizing: "border-box",
552
+ cursor: "pointer",
553
+ ...designSystemStyles.focus.defaults
401
554
  },
402
- false: defaultStyles
555
+ false: {
556
+ cursor: "pointer"
557
+ }
403
558
  }
404
559
  }
405
560
  });
@@ -413,7 +568,8 @@ const Trigger = React__default["default"].forwardRef(({ asChild = false, onPress
413
568
  }));
414
569
 
415
570
  const StyledIconContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
416
- color: "$icon-neutrals-with-text"
571
+ color: "$icon-neutrals-with-text",
572
+ marginRight: "-4px"
417
573
  });
418
574
  const StyledSubTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.SubTrigger, {
419
575
  ...itemDefaults,
@@ -456,7 +612,7 @@ const SubContent = React__default["default"].forwardRef(
456
612
  hideWhenDetached = false,
457
613
  sticky = "partial",
458
614
  ...restProps
459
- }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSubContent, {
615
+ }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(ContentProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledSubContent, {
460
616
  ...restProps,
461
617
  ref: forwardRef,
462
618
  sideOffset,
@@ -465,7 +621,7 @@ const SubContent = React__default["default"].forwardRef(
465
621
  loop,
466
622
  hideWhenDetached,
467
623
  sticky
468
- })
624
+ }))
469
625
  );
470
626
 
471
627
  const StyledSub = designSystemStitches.styled(RadixDropdownMenu__namespace.Sub, {});
@@ -492,7 +648,7 @@ const Portal = (props) => /* @__PURE__ */ React__default["default"].createElemen
492
648
  });
493
649
 
494
650
  const StyledIconSlot = designSystemStitches.styled(LeftSlot, {
495
- square: "$5",
651
+ paddingTop: "2px",
496
652
  variants: {
497
653
  customIcon: {
498
654
  true: {
@@ -503,13 +659,18 @@ const StyledIconSlot = designSystemStitches.styled(LeftSlot, {
503
659
  });
504
660
 
505
661
  const IconSlot = React__default["default"].forwardRef(({ children, ...restProps }, forwardRef) => {
662
+ const { leftSlotMount, leftSlotDestroy } = useItem();
506
663
  const child = React__default["default"].Children.only(children);
507
- const isIcon = designSystemIcons.isIconComponent(child);
664
+ const isIcon = designSystemBaseIcon.isIconComponent(child);
508
665
  const formattedChild = isIcon ? React__default["default"].cloneElement(child, {
509
666
  ...child.props,
510
667
  size: "small",
511
668
  weight: "thin"
512
669
  }) : child;
670
+ React.useEffect(() => {
671
+ leftSlotMount();
672
+ return () => leftSlotDestroy();
673
+ }, [leftSlotMount, leftSlotDestroy]);
513
674
  return /* @__PURE__ */ React__default["default"].createElement(StyledIconSlot, {
514
675
  ref: forwardRef,
515
676
  ...restProps,