@cypress-design/react-docmenu 0.3.1 → 0.4.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +22 -0
- package/DocMenu.tsx +44 -14
- package/DocMenuReact.cy.tsx +155 -3
- package/ReadMe.md +90 -57
- package/_DocGroup.tsx +227 -87
- package/_DocLink.tsx +69 -49
- package/dist/DocMenu.d.ts +3 -0
- package/dist/DocMenu.d.ts.map +1 -1
- package/dist/_DocGroup.d.ts +32 -3
- package/dist/_DocGroup.d.ts.map +1 -1
- package/dist/_DocLink.d.ts +15 -2
- package/dist/_DocLink.d.ts.map +1 -1
- package/dist/index.es.mjs +149 -84
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +149 -84
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/DocMenu.rootstory.tsx +0 -7
package/dist/index.umd.js
CHANGED
|
@@ -64,50 +64,11 @@ function __rest$1(s, e) {
|
|
|
64
64
|
return t;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function __spreadArray(to, from, pack) {
|
|
68
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
-
if (ar || !(i in from)) {
|
|
70
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
-
ar[i] = from[i];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
67
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
78
68
|
var e = new Error(message);
|
|
79
69
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
80
70
|
};
|
|
81
71
|
|
|
82
|
-
var DocLink = function (_a) {
|
|
83
|
-
var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive;
|
|
84
|
-
var activeLIRef = React__namespace.useRef(null);
|
|
85
|
-
// on mount, if the item is active,
|
|
86
|
-
// send the top position to the parent
|
|
87
|
-
React__namespace.useEffect(function () {
|
|
88
|
-
var _a;
|
|
89
|
-
if (item.active) {
|
|
90
|
-
onActive === null || onActive === void 0 ? void 0 : onActive(((_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) || 0);
|
|
91
|
-
}
|
|
92
|
-
// supposed to happen only on mount
|
|
93
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
-
}, []);
|
|
95
|
-
return (React__namespace.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
|
|
96
|
-
'pl-[16px]': depth >= 0,
|
|
97
|
-
}) },
|
|
98
|
-
React__namespace.createElement("a", { className: clsx('group relative inline-block pl-[24px]', {
|
|
99
|
-
'text-indigo-500': item.active,
|
|
100
|
-
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
101
|
-
'py-[12px] leading-[20px] text-[14px]': depth >= 0,
|
|
102
|
-
}), href: item.href },
|
|
103
|
-
depth >= 0 ? (React__namespace.createElement("div", { className: clsx('absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden', {
|
|
104
|
-
'group-hover:block bg-gray-300': !item.active && collapsible,
|
|
105
|
-
}), style: {
|
|
106
|
-
left: "-".concat(18.5 + depth * 8, "px"),
|
|
107
|
-
} })) : null,
|
|
108
|
-
item.text)));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
72
|
/******************************************************************************
|
|
112
73
|
Copyright (c) Microsoft Corporation.
|
|
113
74
|
|
|
@@ -219,72 +180,176 @@ const classes = {
|
|
|
219
180
|
leafButton: 'leading-[20px] text-[14px] pl-[40px]',
|
|
220
181
|
};
|
|
221
182
|
|
|
222
|
-
var
|
|
223
|
-
var _b;
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
React__namespace.useEffect(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
183
|
+
var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
184
|
+
var item = _a.item, active = _a.active, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive, _c = _a.LinkComponent, LinkComponent = _c === void 0 ? 'a' : _c;
|
|
185
|
+
var activeLIRef = React__namespace.useRef(null);
|
|
186
|
+
// on mount, if the item is active,
|
|
187
|
+
// send the top position to the parent
|
|
188
|
+
React__namespace.useEffect(setActiveMarkerPosition, [onActive, active]);
|
|
189
|
+
function setActiveMarkerPosition() {
|
|
190
|
+
var _a;
|
|
191
|
+
if (active) {
|
|
192
|
+
var box = (_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
193
|
+
onActive === null || onActive === void 0 ? void 0 : onActive({
|
|
194
|
+
top: (box === null || box === void 0 ? void 0 : box.top) || 0,
|
|
195
|
+
height: (box === null || box === void 0 ? void 0 : box.height) || 0,
|
|
196
|
+
});
|
|
235
197
|
}
|
|
236
|
-
}
|
|
198
|
+
}
|
|
199
|
+
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
200
|
+
setActiveMarkerPosition: setActiveMarkerPosition,
|
|
201
|
+
}); });
|
|
202
|
+
return (React__namespace.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
|
|
203
|
+
'pl-[16px]': depth >= 0,
|
|
204
|
+
}) },
|
|
205
|
+
React__namespace.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
|
|
206
|
+
'text-indigo-500': active,
|
|
207
|
+
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
208
|
+
'py-[12px] leading-[20px] text-[14px]': depth >= 0,
|
|
209
|
+
}), href: item.href },
|
|
210
|
+
depth >= 0 ? (React__namespace.createElement("div", { className: clsx('absolute w-[4px] z-10 top-[4px] bottom-[4px] rounded-full hidden', {
|
|
211
|
+
'group-hover:block bg-gray-300': !active && collapsible,
|
|
212
|
+
}), style: {
|
|
213
|
+
left: "-".concat(18.5 + depth * 8, "px"),
|
|
214
|
+
} })) : null,
|
|
215
|
+
item.label)));
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
219
|
+
var _b;
|
|
220
|
+
var group = _a.group, activePath = _a.activePath, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d, hideMarker = _a.hideMarker;
|
|
221
|
+
var _e = React__namespace.useState(group.collapsed !== true), open = _e[0], setOpen = _e[1];
|
|
222
|
+
var $groupElements = React__namespace.useRef(null);
|
|
237
223
|
function toggleMenu(open) {
|
|
238
224
|
if (!collapsible)
|
|
239
225
|
return;
|
|
240
226
|
setOpen(open);
|
|
241
227
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
228
|
+
var hasActiveItemRecursively = React__namespace.useCallback(function (items) {
|
|
229
|
+
if (items === void 0) { items = group.items; }
|
|
230
|
+
return items.some(function (item) {
|
|
231
|
+
if ('items' in item) {
|
|
232
|
+
return hasActiveItemRecursively(item.items);
|
|
233
|
+
}
|
|
234
|
+
return item.href === activePath;
|
|
247
235
|
});
|
|
248
|
-
}
|
|
236
|
+
}, [group.items, activePath]);
|
|
249
237
|
var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
|
|
238
|
+
var setActivePosition = React__namespace.useCallback(function (_a) {
|
|
239
|
+
var top = _a.top, height = _a.height;
|
|
240
|
+
if (open) {
|
|
241
|
+
onActivePosition({ top: top, height: height });
|
|
242
|
+
}
|
|
243
|
+
}, [onActivePosition, open]);
|
|
244
|
+
function reTriggerSetActiveGroup() {
|
|
245
|
+
var _a;
|
|
246
|
+
(_a = $groupElements.current) === null || _a === void 0 ? void 0 : _a.reTriggerSetActiveGroup();
|
|
247
|
+
}
|
|
248
|
+
React__namespace.useEffect(function () {
|
|
249
|
+
if (hasActiveItemRecursively()) {
|
|
250
|
+
if (open) {
|
|
251
|
+
reTriggerSetActiveGroup();
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
hideMarker();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
259
|
+
}
|
|
260
|
+
}, [open, updateMarkerPosition, hideMarker, hasActiveItemRecursively]);
|
|
261
|
+
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
262
|
+
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
263
|
+
}); });
|
|
264
|
+
var onUpdateMarkerPosition = React__namespace.useCallback(function () {
|
|
265
|
+
if (hasActiveItemRecursively()) {
|
|
266
|
+
reTriggerSetActiveGroup();
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
270
|
+
}
|
|
271
|
+
}, [hasActiveItemRecursively, updateMarkerPosition]);
|
|
250
272
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
251
|
-
React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
|
|
252
|
-
'text-indigo-500': group.active
|
|
253
|
-
},
|
|
273
|
+
React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
|
|
254
274
|
_b[classes.topButton] = depth === 0,
|
|
255
275
|
_b[classes.leafButton] = depth,
|
|
276
|
+
_b['text-indigo-500'] = activePath === group.href,
|
|
256
277
|
_b)) },
|
|
257
278
|
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx('absolute transform transition-transform left-0', {
|
|
258
279
|
'rotate-0': open,
|
|
259
280
|
'-rotate-90': !open,
|
|
260
281
|
'ml-[16px]': depth,
|
|
261
282
|
}) })) : null,
|
|
262
|
-
group.
|
|
263
|
-
collapsible
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
})
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
group.label),
|
|
284
|
+
React__namespace.createElement(DocGroupElements, { ref: $groupElements, className: !open ? 'hidden' : undefined, items: group.items, activePath: activePath, collapsible: collapsible, depth: depth, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent, hideMarker: hideMarker })));
|
|
285
|
+
});
|
|
286
|
+
var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
287
|
+
var items = _a.items, activePath = _a.activePath, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? 0 : _b, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, LinkComponent = _a.LinkComponent, hideMarker = _a.hideMarker, className = _a.className, rest = __rest$1(_a, ["items", "activePath", "collapsible", "depth", "onActivePosition", "updateMarkerPosition", "LinkComponent", "hideMarker", "className"]);
|
|
288
|
+
var $groups = React__namespace.useRef([]);
|
|
289
|
+
var $items = React__namespace.useRef([]);
|
|
290
|
+
var hasActiveItemRecursively = React__namespace.useCallback(function (localItems) {
|
|
291
|
+
if (localItems === void 0) { localItems = items; }
|
|
292
|
+
return localItems.some(function (item) {
|
|
293
|
+
if ('items' in item) {
|
|
294
|
+
return hasActiveItemRecursively(item.items);
|
|
295
|
+
}
|
|
296
|
+
return item.href === activePath;
|
|
297
|
+
});
|
|
298
|
+
}, [items, activePath]);
|
|
299
|
+
function reTriggerSetActiveGroup() {
|
|
300
|
+
$groups.current.forEach(function (group) {
|
|
301
|
+
group === null || group === void 0 ? void 0 : group.reTriggerSetActiveGroup();
|
|
302
|
+
});
|
|
303
|
+
$items.current.forEach(function (item) {
|
|
304
|
+
item === null || item === void 0 ? void 0 : item.setActiveMarkerPosition();
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
308
|
+
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
309
|
+
}); });
|
|
310
|
+
var onUpdateMarkerPosition = React__namespace.useCallback(function () {
|
|
311
|
+
if (hasActiveItemRecursively()) {
|
|
312
|
+
reTriggerSetActiveGroup();
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
316
|
+
}
|
|
317
|
+
}, [hasActiveItemRecursively, updateMarkerPosition]);
|
|
318
|
+
return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className, {
|
|
319
|
+
'border-l border-gray-100': depth === 0 && collapsible,
|
|
320
|
+
'ml-[8px]': depth >= 0,
|
|
321
|
+
}) }), items.map(function (item, index) {
|
|
282
322
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
283
|
-
React__namespace.createElement(DocGroup, {
|
|
323
|
+
React__namespace.createElement(DocGroup, { ref: function (el) {
|
|
324
|
+
$groups.current[index] = el;
|
|
325
|
+
}, group: item, activePath: activePath, depth: depth + 1, collapsible: collapsible, LinkComponent: LinkComponent, hideMarker: hideMarker, onActivePosition: onActivePosition, updateMarkerPosition: onUpdateMarkerPosition }))) : (React__namespace.createElement(DocLink, { ref: function (el) {
|
|
326
|
+
$items.current[index] = el;
|
|
327
|
+
}, key: index, item: item, active: item.href === activePath, collapsible: collapsible, depth: depth, onActive: onActivePosition, LinkComponent: LinkComponent }));
|
|
284
328
|
})));
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
var DocMenu = function (_a) {
|
|
332
|
+
var items = _a.items, _b = _a.activePath, activePath = _b === void 0 ? '<unknown>' : _b, _c = _a.collapsible, collapsible = _c === void 0 ? true : _c, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d, rest = __rest$1(_a, ["items", "activePath", "collapsible", "LinkComponent"]);
|
|
333
|
+
var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
|
|
334
|
+
var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
|
|
335
|
+
var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
|
|
336
|
+
var container = React__namespace.useRef(null);
|
|
337
|
+
var setActivePosition = React__namespace.useCallback(function (opts) {
|
|
338
|
+
var _a;
|
|
339
|
+
var containerTop = ((_a = container.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().top) || 0;
|
|
340
|
+
setShowMarker(true);
|
|
341
|
+
setActiveTop(opts.top - containerTop);
|
|
342
|
+
setActiveHeight(opts.height);
|
|
343
|
+
}, []);
|
|
344
|
+
return (React__namespace.createElement("div", { ref: container, className: "relative" },
|
|
345
|
+
showMarker && collapsible ? (React__namespace.createElement("div", { className: "absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 transition-all duration-300 ml-[6.5px] mt-[4px]", style: {
|
|
346
|
+
top: "".concat(activeTop + 4, "px"),
|
|
347
|
+
height: "".concat(activeHeight - 8, "px"),
|
|
348
|
+
} })) : null,
|
|
349
|
+
React__namespace.createElement(DocGroupElements, __assign$1({}, rest, { className: !open ? 'hidden' : undefined, items: items, activePath: activePath, collapsible: collapsible, depth: -1, onActivePosition: setActivePosition, LinkComponent: LinkComponent, hideMarker: function () { return setShowMarker(false); } }))));
|
|
285
350
|
};
|
|
286
351
|
|
|
287
352
|
module.exports = DocMenu;
|
|
288
353
|
//# sourceMappingURL=index.umd.js.map
|
|
289
354
|
|
|
290
|
-
/* <wind-keep class="
|
|
355
|
+
/* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 transition-all duration-300 ml-[6.5px] mt-[4px] hidden text-indigo-500 transform transition-transform left-0 rotate-0 -rotate-90 ml-[16px] list-none p-0 border-l border-gray-100 ml-[8px] pl-[16px] inline-block pl-[24px] py-[8px] text-[16px] leading-[24px] py-[12px] leading-[20px] text-[14px] z-10 top-[4px] bottom-[4px] group-hover:block bg-gray-300 flex py-[10px] items-center w-full font-medium pl-[40px]"> */
|