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

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
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var RadixDropdownMenu = require('@radix-ui/react-dropdown-menu');
7
7
  var designSystemIcons = require('@mirohq/design-system-icons');
8
+ var designSystemUtils = require('@mirohq/design-system-utils');
8
9
  var designSystemPrimitive = require('@mirohq/design-system-primitive');
9
10
  var designSystemStitches = require('@mirohq/design-system-stitches');
10
11
  var designSystemStyles = require('@mirohq/design-system-styles');
@@ -44,6 +45,24 @@ const ItemDescription = designSystemStitches.styled(designSystemPrimitive.Primit
44
45
  color: "$text-neutrals-subtle"
45
46
  });
46
47
 
48
+ const LeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
49
+ display: "flex",
50
+ placeContent: "center",
51
+ marginRight: "$100",
52
+ gridArea: "left-slot"
53
+ });
54
+ const IllustrationSlot = designSystemStitches.styled(LeftSlot, {
55
+ width: "$13"
56
+ });
57
+ const RightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
58
+ display: "flex",
59
+ alignItems: "center",
60
+ marginLeft: "auto",
61
+ paddingLeft: "$200",
62
+ gridArea: "right-slot"
63
+ });
64
+ const HotkeySlot = RightSlot;
65
+
47
66
  const itemDefaults = {
48
67
  all: "unset",
49
68
  boxSizing: "border-box",
@@ -64,18 +83,28 @@ const itemDefaults = {
64
83
  position: "relative",
65
84
  userSelect: "none",
66
85
  cursor: "pointer",
67
- "&[data-disabled]": {
68
- color: "rgba(9, 9, 9, 0.4)",
69
- pointerEvents: "none"
70
- },
71
86
  ...designSystemStyles.focus.defaults,
72
- "&:hover": {
73
- background: "rgba(232, 236, 255, 1)",
74
- boxShadow: "none",
87
+ '&:disabled, &[aria-disabled="true"], &[data-disabled]': {
88
+ pointerEvents: "none",
75
89
  [`&, & ${ItemDescription}`]: {
76
- color: "$text-primary-hover"
90
+ color: "$text-neutrals-disabled"
91
+ },
92
+ [`& ${IllustrationSlot}`]: {
93
+ filter: "grayscale(1)"
94
+ }
95
+ },
96
+ "&:hover": {
97
+ background: "$background-primary-subtle-hover",
98
+ color: "$text-primary-hover",
99
+ '&:not([aria-disabled="true"])': {
100
+ boxShadow: "none"
77
101
  }
78
102
  },
103
+ "&:active": {
104
+ background: "$background-primary-subtle-active",
105
+ boxShadow: "none",
106
+ color: "$text-primary-active"
107
+ },
79
108
  '&[tabindex="0"]': {
80
109
  zIndex: "1"
81
110
  }
@@ -90,48 +119,54 @@ const StyledCheckboxItem = designSystemStitches.styled(RadixDropdownMenu__namesp
90
119
  [`&[data-state="checked"]:hover ${StyledIndicator}`]: {
91
120
  color: "$icon-primary-hover"
92
121
  },
93
- [`&[data-disabled] ${StyledIndicator}`]: {
122
+ [`
123
+ &[aria-disabled="true"] ${StyledIndicator},
124
+ &[data-disabled] ${StyledIndicator}
125
+ `]: {
94
126
  color: "$icon-neutrals-disabled"
95
127
  }
96
128
  });
97
129
 
98
- const LeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
99
- display: "flex",
100
- placeContent: "center",
101
- marginRight: "$100",
102
- gridArea: "left-slot"
103
- });
104
- const IconSlot = designSystemStitches.styled(LeftSlot, {
105
- width: "$6"
106
- });
107
- const IllustrationSlot = designSystemStitches.styled(LeftSlot, {
108
- width: "$13"
109
- });
110
- const RightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
111
- display: "flex",
112
- alignItems: "center",
113
- marginLeft: "auto",
114
- paddingLeft: "$200",
115
- gridArea: "right-slot"
116
- });
130
+ const useAriaDisabled = ({ "aria-disabled": ariaDisabled, onKeyDown, onSelect }, preventDefault = false) => React.useMemo(
131
+ () => ({
132
+ "aria-disabled": designSystemUtils.booleanify(ariaDisabled) ? ariaDisabled : void 0,
133
+ onKeyDown: (e) => {
134
+ if (designSystemUtils.booleanify(ariaDisabled) && e.code !== "ArrowUp" && e.code !== "ArrowDown") {
135
+ e.preventDefault();
136
+ e.stopPropagation();
137
+ return;
138
+ }
139
+ onKeyDown == null ? void 0 : onKeyDown(e);
140
+ },
141
+ onSelect: (e) => {
142
+ if (preventDefault) {
143
+ e.preventDefault();
144
+ }
145
+ if (designSystemUtils.booleanify(ariaDisabled)) {
146
+ return;
147
+ }
148
+ onSelect == null ? void 0 : onSelect(e);
149
+ }
150
+ }),
151
+ [ariaDisabled, onKeyDown, onSelect, preventDefault]
152
+ );
117
153
 
118
- const CheckboxItem = React__default["default"].forwardRef(
119
- ({ children, checked, onChange, onSelect, disabled, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
154
+ const CheckboxItem = React__default["default"].forwardRef(({ children, checked, onChange, disabled, ...restProps }, forwardRef) => {
155
+ const ariaDisabledProps = useAriaDisabled(restProps, true);
156
+ const { "aria-disabled": ariaDisabled } = ariaDisabledProps;
157
+ return /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
120
158
  ...restProps,
159
+ ...ariaDisabledProps,
121
160
  ref: forwardRef,
122
161
  checked,
123
162
  disabled,
124
- onCheckedChange: onChange,
125
- onSelect: (event) => {
126
- event.preventDefault();
127
- onSelect == null ? void 0 : onSelect(event);
128
- }
129
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledIndicator, null, disabled === true && !checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconProhibit, {
163
+ onCheckedChange: onChange
164
+ }, 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, {
130
165
  size: "small"
131
166
  }), checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconCheckMark, {
132
167
  size: "small"
133
- }))))
134
- );
168
+ }))));
169
+ });
135
170
 
136
171
  const GUTTER_TOKEN = 150;
137
172
  const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[GUTTER_TOKEN]);
@@ -212,20 +247,28 @@ const Content = React__default["default"].forwardRef(
212
247
  const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item, itemDefaults);
213
248
 
214
249
  const Item = React__default["default"].forwardRef(
215
- ({ disabled = false, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
216
- ...restProps,
217
- ref: forwardRef,
218
- disabled
219
- })
250
+ ({ disabled = false, ...restProps }, forwardRef) => {
251
+ const ariaDisabledProps = useAriaDisabled(restProps);
252
+ return /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
253
+ ...restProps,
254
+ ...ariaDisabledProps,
255
+ disabled,
256
+ ref: forwardRef
257
+ });
258
+ }
220
259
  );
221
260
 
222
- const LinkItem = React__default["default"].forwardRef(({ children, href, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(Item, {
223
- asChild: true,
224
- ref: forwardRef,
225
- ...restProps
226
- }, /* @__PURE__ */ React__default["default"].createElement("a", {
227
- href
228
- }, children)));
261
+ const LinkItem = React__default["default"].forwardRef(({ children, href, ...restProps }, forwardRef) => {
262
+ const ariaDisabledProps = useAriaDisabled(restProps);
263
+ return /* @__PURE__ */ React__default["default"].createElement(Item, {
264
+ asChild: true,
265
+ ref: forwardRef,
266
+ ...restProps,
267
+ ...ariaDisabledProps
268
+ }, /* @__PURE__ */ React__default["default"].createElement("a", {
269
+ href
270
+ }, children));
271
+ });
229
272
 
230
273
  const StyledRadioGroup = designSystemStitches.styled(RadixDropdownMenu__namespace.RadioGroup);
231
274
 
@@ -274,30 +317,38 @@ const StyledRadioItem = designSystemStitches.styled(RadixDropdownMenu__namespace
274
317
  backgroundColor: "$background-primary-prominent-hover"
275
318
  }
276
319
  },
277
- [`&[data-disabled] ${StyledRadioContainer}`]: {
320
+ [`
321
+ &[aria-disabled="true"] ${StyledRadioContainer},
322
+ &[data-disabled] ${StyledRadioContainer}
323
+ `]: {
278
324
  color: "$icon-neutrals-disabled",
279
325
  borderColor: "$border-neutrals-disabled",
280
326
  [`& ${StyledPill}`]: {
281
327
  backgroundColor: "$icon-neutrals-disabled"
282
328
  }
283
329
  },
284
- [`&[data-state="unchecked"][data-disabled] ${StyledProhibited}`]: {
285
- display: "block"
330
+ '&[data-state="unchecked"]': {
331
+ [`
332
+ &[aria-disabled="true"] ${StyledProhibited},
333
+ &[data-disabled] ${StyledProhibited}
334
+ `]: {
335
+ display: "flex"
336
+ }
286
337
  }
287
338
  });
288
339
 
289
- const RadioItem = React__default["default"].forwardRef(({ disabled = false, onSelect, children, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
290
- ...restProps,
291
- ref: forwardRef,
292
- disabled,
293
- onSelect: (event) => {
294
- event.preventDefault();
295
- onSelect == null ? void 0 : onSelect(event);
296
- }
297
- }, 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)))));
340
+ const RadioItem = React__default["default"].forwardRef(({ disabled = false, children, ...restProps }, forwardRef) => {
341
+ const ariaDisabledProps = useAriaDisabled(restProps, true);
342
+ return /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
343
+ ...restProps,
344
+ ...ariaDisabledProps,
345
+ disabled,
346
+ 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))));
348
+ });
298
349
 
299
350
  const StyledSeparator = designSystemStitches.styled(RadixDropdownMenu__namespace.Separator, {
300
- borderTop: "1px solid rgba(235, 235, 239, 1)",
351
+ borderTop: "1px solid $border-neutrals-subtle",
301
352
  marginY: "$100"
302
353
  });
303
354
 
@@ -316,21 +367,24 @@ const StyledSwitchItem = designSystemStitches.styled(RadixDropdownMenu__namespac
316
367
  [`&[data-state="checked"] ${StyledSwitch}`]: designSystemBaseSwitch.styles.checked,
317
368
  [`&[data-state="checked"]:hover ${StyledSwitch}`]: designSystemBaseSwitch.styles.checkedHovered,
318
369
  [`&:hover ${StyledSwitch}`]: designSystemBaseSwitch.styles.hovered,
319
- [`&[data-disabled] ${StyledSwitch}`]: designSystemBaseSwitch.styles.disabled
370
+ [`
371
+ &[aria-disabled="true"] ${StyledSwitch},
372
+ &[data-disabled] ${StyledSwitch}
373
+ `]: designSystemBaseSwitch.styles.disabled
320
374
  });
321
375
 
322
376
  const SwitchItem = React__default["default"].forwardRef(
323
- ({ disabled = false, checked, onChange, onSelect, children, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
324
- ...restProps,
325
- ref: forwardRef,
326
- disabled,
327
- checked,
328
- onCheckedChange: onChange,
329
- onSelect: (event) => {
330
- event.preventDefault();
331
- onSelect == null ? void 0 : onSelect(event);
332
- }
333
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledSwitch, null, /* @__PURE__ */ React__default["default"].createElement(designSystemBaseSwitch.Thumb, null))))
377
+ ({ disabled = false, checked, onChange, children, ...restProps }, forwardRef) => {
378
+ const ariaDisabledProps = useAriaDisabled(restProps, true);
379
+ return /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
380
+ ...restProps,
381
+ ...ariaDisabledProps,
382
+ disabled,
383
+ checked,
384
+ onCheckedChange: onChange,
385
+ 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))));
387
+ }
334
388
  );
335
389
 
336
390
  const defaultStyles = {
@@ -358,26 +412,34 @@ const Trigger = React__default["default"].forwardRef(({ asChild = false, onPress
358
412
  asChild
359
413
  }));
360
414
 
415
+ const StyledIconContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
416
+ color: "$icon-neutrals-with-text"
417
+ });
361
418
  const StyledSubTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.SubTrigger, {
362
419
  ...itemDefaults,
363
- '&[data-state="open"]': itemDefaults["&:hover"]
420
+ '&[data-state="open"]': itemDefaults["&:hover"],
421
+ [`&[data-state="open"] ${StyledIconContainer}, &:hover ${StyledIconContainer}`]: {
422
+ color: "$icon-primary-hover"
423
+ }
364
424
  });
365
425
 
366
- const ArrowIcon = () => /* @__PURE__ */ React__default["default"].createElement("svg", {
367
- width: "16",
368
- height: "16",
369
- viewBox: "0 0 16 16",
370
- fill: "currentColor",
371
- xmlns: "http://www.w3.org/2000/svg",
372
- "data-testid": "submenu-arrow-icon"
373
- }, /* @__PURE__ */ React__default["default"].createElement("path", {
374
- 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"
375
- }));
376
- const SubTrigger = React__default["default"].forwardRef(({ children, disabled = false, ...restProps }, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(StyledSubTrigger, {
377
- ...restProps,
378
- ref: forwardRef,
379
- disabled
380
- }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(ArrowIcon, null))));
426
+ const SubTrigger = React__default["default"].forwardRef(({ children, disabled = false, ...restProps }, forwardRef) => {
427
+ const { onSelect, ...ariaDisabledProps } = useAriaDisabled({
428
+ onKeyDown: restProps.onKeyDown,
429
+ "aria-disabled": restProps["aria-disabled"]
430
+ });
431
+ return /* @__PURE__ */ React__default["default"].createElement(StyledSubTrigger, {
432
+ ...restProps,
433
+ ...ariaDisabledProps,
434
+ disabled,
435
+ ref: forwardRef
436
+ }, children, /* @__PURE__ */ React__default["default"].createElement(RightSlot, null, /* @__PURE__ */ React__default["default"].createElement(StyledIconContainer, {
437
+ "data-testid": process.env.NODE_ENV === "test" ? "submenu-arrow-icon" : void 0
438
+ }, /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconChevronRight, {
439
+ size: "small",
440
+ weight: "thin"
441
+ }))));
442
+ });
381
443
 
382
444
  const StyledSubContent = designSystemStitches.styled(
383
445
  RadixDropdownMenu__namespace.SubContent,
@@ -429,6 +491,32 @@ const Portal = (props) => /* @__PURE__ */ React__default["default"].createElemen
429
491
  ...props
430
492
  });
431
493
 
494
+ const StyledIconSlot = designSystemStitches.styled(LeftSlot, {
495
+ square: "$5",
496
+ variants: {
497
+ customIcon: {
498
+ true: {
499
+ square: "$icon-200"
500
+ }
501
+ }
502
+ }
503
+ });
504
+
505
+ const IconSlot = React__default["default"].forwardRef(({ children, ...restProps }, forwardRef) => {
506
+ const child = React__default["default"].Children.only(children);
507
+ const isIcon = designSystemIcons.isIconComponent(child);
508
+ const formattedChild = isIcon ? React__default["default"].cloneElement(child, {
509
+ ...child.props,
510
+ size: "small",
511
+ weight: "thin"
512
+ }) : child;
513
+ return /* @__PURE__ */ React__default["default"].createElement(StyledIconSlot, {
514
+ ref: forwardRef,
515
+ ...restProps,
516
+ customIcon: !isIcon
517
+ }, formattedChild);
518
+ });
519
+
432
520
  const DropdownMenu = ({
433
521
  defaultOpen = false,
434
522
  direction = "ltr",
@@ -454,6 +542,7 @@ const DropdownMenu = ({
454
542
  };
455
543
  DropdownMenu.CheckboxItem = CheckboxItem;
456
544
  DropdownMenu.Content = Content;
545
+ DropdownMenu.HotkeySlot = HotkeySlot;
457
546
  DropdownMenu.IconSlot = IconSlot;
458
547
  DropdownMenu.IllustrationSlot = IllustrationSlot;
459
548
  DropdownMenu.Item = Item;