@mirohq/design-system-dropdown-menu 3.3.0-dropdown.5 → 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 +132 -63
- package/dist/main.js.map +1 -1
- package/dist/module.js +134 -65
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +225 -562
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -46,13 +46,66 @@ const ItemDescription = designSystemStitches.styled(designSystemPrimitive.Primit
|
|
|
46
46
|
color: "$text-neutrals-subtle"
|
|
47
47
|
});
|
|
48
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
|
+
|
|
49
102
|
const LeftSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
50
103
|
display: "flex",
|
|
51
104
|
placeContent: "center",
|
|
52
105
|
marginRight: "$100",
|
|
53
106
|
gridArea: "left-slot"
|
|
54
107
|
});
|
|
55
|
-
const
|
|
108
|
+
const StyledIllustrationSlot = designSystemStitches.styled(LeftSlot, {
|
|
56
109
|
width: "$13"
|
|
57
110
|
});
|
|
58
111
|
const StyledRightSlot = designSystemStitches.styled(designSystemPrimitive.Primitive.div, {
|
|
@@ -68,6 +121,66 @@ const StyledRightSlot = designSystemStitches.styled(designSystemPrimitive.Primit
|
|
|
68
121
|
}
|
|
69
122
|
});
|
|
70
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
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
71
184
|
const itemDefaults = {
|
|
72
185
|
all: "unset",
|
|
73
186
|
boxSizing: "border-box",
|
|
@@ -76,7 +189,7 @@ const itemDefaults = {
|
|
|
76
189
|
color: "$text-neutrals",
|
|
77
190
|
borderRadius: "$50",
|
|
78
191
|
display: "grid",
|
|
79
|
-
gridTemplateColumns: "auto 1fr auto",
|
|
192
|
+
gridTemplateColumns: "auto 1fr minmax(auto, var(--right-slot-max-width))",
|
|
80
193
|
gridTemplateRows: "1fr auto",
|
|
81
194
|
gridTemplateAreas: `'left-slot item-text right-slot'
|
|
82
195
|
'left-slot item-description right-slot'`,
|
|
@@ -87,7 +200,7 @@ const itemDefaults = {
|
|
|
87
200
|
userSelect: "none",
|
|
88
201
|
cursor: "pointer",
|
|
89
202
|
"&[data-no-left-slot]": {
|
|
90
|
-
gridTemplateColumns: "1fr auto",
|
|
203
|
+
gridTemplateColumns: "1fr minmax(auto, var(--right-slot-max-width))",
|
|
91
204
|
gridTemplateRows: "auto",
|
|
92
205
|
gridTemplateAreas: `'item-text right-slot'
|
|
93
206
|
'item-description right-slot'`
|
|
@@ -144,53 +257,6 @@ const StyledCheckboxItem = designSystemStitches.styled(RadixDropdownMenu__namesp
|
|
|
144
257
|
}
|
|
145
258
|
});
|
|
146
259
|
|
|
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
|
-
|
|
194
260
|
const useAriaDisabled = ({ "aria-disabled": ariaDisabled, onKeyDown, onSelect }, preventDefault = false) => React.useMemo(
|
|
195
261
|
() => ({
|
|
196
262
|
"aria-disabled": designSystemUtils.booleanify(ariaDisabled) ? ariaDisabled : void 0,
|
|
@@ -218,7 +284,7 @@ const useAriaDisabled = ({ "aria-disabled": ariaDisabled, onKeyDown, onSelect },
|
|
|
218
284
|
const CheckboxItem = React__default["default"].forwardRef(({ children, checked, onChange, disabled, ...restProps }, forwardRef) => {
|
|
219
285
|
const ariaDisabledProps = useAriaDisabled(restProps, true);
|
|
220
286
|
const { "aria-disabled": ariaDisabled } = ariaDisabledProps;
|
|
221
|
-
return /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
|
|
287
|
+
return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledCheckboxItem, {
|
|
222
288
|
...restProps,
|
|
223
289
|
...ariaDisabledProps,
|
|
224
290
|
ref: forwardRef,
|
|
@@ -229,7 +295,7 @@ const CheckboxItem = React__default["default"].forwardRef(({ children, checked,
|
|
|
229
295
|
size: "small"
|
|
230
296
|
}), checked && /* @__PURE__ */ React__default["default"].createElement(designSystemIcons.IconCheckMark, {
|
|
231
297
|
css: { width: "12px", display: "block" }
|
|
232
|
-
}))));
|
|
298
|
+
})))));
|
|
233
299
|
});
|
|
234
300
|
|
|
235
301
|
const CONTENT_GUTTER = parseInt(designSystemStitches.theme.space[150]);
|
|
@@ -306,7 +372,7 @@ const Content = React__default["default"].forwardRef(
|
|
|
306
372
|
hideWhenDetached = false,
|
|
307
373
|
containerSpacing = "medium",
|
|
308
374
|
...restProps
|
|
309
|
-
}, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(
|
|
375
|
+
}, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(ContentProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledContent, {
|
|
310
376
|
...restProps,
|
|
311
377
|
ref: forwardRef,
|
|
312
378
|
loop,
|
|
@@ -335,15 +401,13 @@ const StyledItem = designSystemStitches.styled(RadixDropdownMenu__namespace.Item
|
|
|
335
401
|
|
|
336
402
|
const Item = React__default["default"].forwardRef(
|
|
337
403
|
({ disabled = false, ...restProps }, forwardRef) => {
|
|
338
|
-
const { counter } = useSlots();
|
|
339
404
|
const ariaDisabledProps = useAriaDisabled(restProps);
|
|
340
|
-
return /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
|
|
405
|
+
return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledItem, {
|
|
341
406
|
...restProps,
|
|
342
407
|
...ariaDisabledProps,
|
|
343
408
|
disabled,
|
|
344
|
-
ref: forwardRef
|
|
345
|
-
|
|
346
|
-
});
|
|
409
|
+
ref: forwardRef
|
|
410
|
+
}));
|
|
347
411
|
}
|
|
348
412
|
);
|
|
349
413
|
|
|
@@ -431,12 +495,12 @@ const StyledRadioItem = designSystemStitches.styled(RadixDropdownMenu__namespace
|
|
|
431
495
|
|
|
432
496
|
const RadioItem = React__default["default"].forwardRef(({ disabled = false, children, ...restProps }, forwardRef) => {
|
|
433
497
|
const ariaDisabledProps = useAriaDisabled(restProps, true);
|
|
434
|
-
return /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
|
|
498
|
+
return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledRadioItem, {
|
|
435
499
|
...restProps,
|
|
436
500
|
...ariaDisabledProps,
|
|
437
501
|
disabled,
|
|
438
502
|
ref: forwardRef
|
|
439
|
-
}, 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)))));
|
|
440
504
|
});
|
|
441
505
|
|
|
442
506
|
const StyledSeparator = designSystemStitches.styled(RadixDropdownMenu__namespace.Separator, {
|
|
@@ -468,14 +532,14 @@ const StyledSwitchItem = designSystemStitches.styled(RadixDropdownMenu__namespac
|
|
|
468
532
|
const SwitchItem = React__default["default"].forwardRef(
|
|
469
533
|
({ disabled = false, checked, onChange, children, ...restProps }, forwardRef) => {
|
|
470
534
|
const ariaDisabledProps = useAriaDisabled(restProps, true);
|
|
471
|
-
return /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
|
|
535
|
+
return /* @__PURE__ */ React__default["default"].createElement(ItemProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledSwitchItem, {
|
|
472
536
|
...restProps,
|
|
473
537
|
...ariaDisabledProps,
|
|
474
538
|
disabled,
|
|
475
539
|
checked,
|
|
476
540
|
onCheckedChange: onChange,
|
|
477
541
|
ref: forwardRef
|
|
478
|
-
}, 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)))));
|
|
479
543
|
}
|
|
480
544
|
);
|
|
481
545
|
|
|
@@ -548,7 +612,7 @@ const SubContent = React__default["default"].forwardRef(
|
|
|
548
612
|
hideWhenDetached = false,
|
|
549
613
|
sticky = "partial",
|
|
550
614
|
...restProps
|
|
551
|
-
}, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(
|
|
615
|
+
}, forwardRef) => /* @__PURE__ */ React__default["default"].createElement(ContentProvider, null, /* @__PURE__ */ React__default["default"].createElement(StyledSubContent, {
|
|
552
616
|
...restProps,
|
|
553
617
|
ref: forwardRef,
|
|
554
618
|
sideOffset,
|
|
@@ -595,6 +659,7 @@ const StyledIconSlot = designSystemStitches.styled(LeftSlot, {
|
|
|
595
659
|
});
|
|
596
660
|
|
|
597
661
|
const IconSlot = React__default["default"].forwardRef(({ children, ...restProps }, forwardRef) => {
|
|
662
|
+
const { leftSlotMount, leftSlotDestroy } = useItem();
|
|
598
663
|
const child = React__default["default"].Children.only(children);
|
|
599
664
|
const isIcon = designSystemBaseIcon.isIconComponent(child);
|
|
600
665
|
const formattedChild = isIcon ? React__default["default"].cloneElement(child, {
|
|
@@ -602,6 +667,10 @@ const IconSlot = React__default["default"].forwardRef(({ children, ...restProps
|
|
|
602
667
|
size: "small",
|
|
603
668
|
weight: "thin"
|
|
604
669
|
}) : child;
|
|
670
|
+
React.useEffect(() => {
|
|
671
|
+
leftSlotMount();
|
|
672
|
+
return () => leftSlotDestroy();
|
|
673
|
+
}, [leftSlotMount, leftSlotDestroy]);
|
|
605
674
|
return /* @__PURE__ */ React__default["default"].createElement(StyledIconSlot, {
|
|
606
675
|
ref: forwardRef,
|
|
607
676
|
...restProps,
|