@cypress-design/react-docmenu 0.3.1 → 0.4.0
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 +13 -0
- package/DocMenu.tsx +16 -4
- package/DocMenuReact.cy.tsx +47 -2
- package/ReadMe.md +91 -57
- package/_DocGroup.tsx +30 -12
- package/_DocLink.tsx +12 -6
- package/dist/DocMenu.d.ts +2 -0
- package/dist/DocMenu.d.ts.map +1 -1
- package/dist/_DocGroup.d.ts +3 -0
- package/dist/_DocGroup.d.ts.map +1 -1
- package/dist/_DocLink.d.ts +6 -0
- package/dist/_DocLink.d.ts.map +1 -1
- package/dist/index.es.mjs +22 -18
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +22 -18
- 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
|
@@ -80,7 +80,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
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;
|
|
83
|
+
var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive, _c = _a.LinkComponent, LinkComponent = _c === void 0 ? 'a' : _c;
|
|
84
84
|
var activeLIRef = React__namespace.useRef(null);
|
|
85
85
|
// on mount, if the item is active,
|
|
86
86
|
// send the top position to the parent
|
|
@@ -89,13 +89,11 @@ var DocLink = function (_a) {
|
|
|
89
89
|
if (item.active) {
|
|
90
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
91
|
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
-
}, []);
|
|
92
|
+
}, [onActive, item.active]);
|
|
95
93
|
return (React__namespace.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
|
|
96
94
|
'pl-[16px]': depth >= 0,
|
|
97
95
|
}) },
|
|
98
|
-
React__namespace.createElement(
|
|
96
|
+
React__namespace.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
|
|
99
97
|
'text-indigo-500': item.active,
|
|
100
98
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
101
99
|
'py-[12px] leading-[20px] text-[14px]': depth >= 0,
|
|
@@ -105,7 +103,7 @@ var DocLink = function (_a) {
|
|
|
105
103
|
}), style: {
|
|
106
104
|
left: "-".concat(18.5 + depth * 8, "px"),
|
|
107
105
|
} })) : null,
|
|
108
|
-
item.
|
|
106
|
+
item.label)));
|
|
109
107
|
};
|
|
110
108
|
|
|
111
109
|
/******************************************************************************
|
|
@@ -221,13 +219,19 @@ const classes = {
|
|
|
221
219
|
|
|
222
220
|
var DocGroup = function (_a) {
|
|
223
221
|
var _b;
|
|
224
|
-
var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight;
|
|
225
|
-
var
|
|
226
|
-
var
|
|
222
|
+
var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight, index = _a.index, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d;
|
|
223
|
+
var _e = React__namespace.useState(depth === 0), open = _e[0], setOpen = _e[1];
|
|
224
|
+
var _f = React__namespace.useState(Array(group.items.length).fill(1)), itemsHeights = _f[0], setItemsHeights = _f[1];
|
|
227
225
|
React__namespace.useEffect(function () {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
// if this group contains other groups, ignore this effect
|
|
227
|
+
// it will be triggered by a leaf and trickle up
|
|
228
|
+
if (group.items.some(function (item) { return 'items' in item; })) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
var newHeight = open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1;
|
|
232
|
+
setHeight === null || setHeight === void 0 ? void 0 : setHeight(newHeight);
|
|
233
|
+
}, [itemsHeights, open, setHeight, group.items, group.label]);
|
|
234
|
+
var _g = React__namespace.useState(0), activeTop = _g[0], setActiveTop = _g[1];
|
|
231
235
|
React__namespace.useEffect(function () {
|
|
232
236
|
var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
|
|
233
237
|
if (activeItem >= 0) {
|
|
@@ -239,13 +243,13 @@ var DocGroup = function (_a) {
|
|
|
239
243
|
return;
|
|
240
244
|
setOpen(open);
|
|
241
245
|
}
|
|
242
|
-
function
|
|
246
|
+
var onSetHeightCallback = React__namespace.useCallback(function (height) {
|
|
243
247
|
setItemsHeights(function (prev) {
|
|
244
248
|
var newHeights = __spreadArray([], prev, true);
|
|
245
249
|
newHeights[index] = height;
|
|
246
250
|
return newHeights;
|
|
247
251
|
});
|
|
248
|
-
}
|
|
252
|
+
}, [setItemsHeights, index]);
|
|
249
253
|
var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
|
|
250
254
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
251
255
|
React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
|
|
@@ -259,7 +263,7 @@ var DocGroup = function (_a) {
|
|
|
259
263
|
'-rotate-90': !open,
|
|
260
264
|
'ml-[16px]': depth,
|
|
261
265
|
}) })) : null,
|
|
262
|
-
group.
|
|
266
|
+
group.label),
|
|
263
267
|
collapsible &&
|
|
264
268
|
depth >= 0 &&
|
|
265
269
|
open &&
|
|
@@ -272,15 +276,15 @@ var DocGroup = function (_a) {
|
|
|
272
276
|
hidden: !open,
|
|
273
277
|
}) }, group.items.map(function (item, index) {
|
|
274
278
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
275
|
-
React__namespace.createElement(DocGroup, { group: item, depth: depth + 1, setHeight:
|
|
279
|
+
React__namespace.createElement(DocGroup, { group: item, depth: depth + 1, setHeight: onSetHeightCallback, index: index, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React__namespace.createElement(DocLink, { key: index, item: item, collapsible: collapsible, depth: depth, onActive: function (top) { return setActiveTop(top); }, LinkComponent: LinkComponent }));
|
|
276
280
|
}))));
|
|
277
281
|
};
|
|
278
282
|
|
|
279
283
|
var DocMenu = function (_a) {
|
|
280
|
-
var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, rest = __rest$1(_a, ["items", "collapsible"]);
|
|
284
|
+
var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, _c = _a.LinkComponent, LinkComponent = _c === void 0 ? 'a' : _c, rest = __rest$1(_a, ["items", "collapsible", "LinkComponent"]);
|
|
281
285
|
return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', rest.className) }), items.map(function (item, index) {
|
|
282
286
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
283
|
-
React__namespace.createElement(DocGroup, { group: item, collapsible: collapsible }))) : (React__namespace.createElement(DocLink, { key: index, item: item, collapsible: collapsible }));
|
|
287
|
+
React__namespace.createElement(DocGroup, { index: index, group: item, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React__namespace.createElement(DocLink, { key: index, item: item, collapsible: collapsible, LinkComponent: LinkComponent }));
|
|
284
288
|
})));
|
|
285
289
|
};
|
|
286
290
|
|