@cypress-design/react-docmenu 0.3.0 → 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 +22 -0
- package/DocMenu.tsx +16 -4
- package/DocMenuReact.cy.tsx +47 -2
- package/ReadMe.md +91 -57
- package/_DocGroup.tsx +35 -17
- package/_DocLink.tsx +13 -5
- 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 +39 -22
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +39 -22
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
- package/DocMenu.rootstory.tsx +0 -7
package/dist/index.es.mjs
CHANGED
|
@@ -17,7 +17,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
17
17
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
20
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
var __assign$1 = function() {
|
|
@@ -51,10 +51,15 @@ function __spreadArray(to, from, pack) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
54
|
-
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
57
|
+
var e = new Error(message);
|
|
58
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
59
|
+
};
|
|
55
60
|
|
|
56
61
|
var DocLink = function (_a) {
|
|
57
|
-
var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive;
|
|
62
|
+
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;
|
|
58
63
|
var activeLIRef = React.useRef(null);
|
|
59
64
|
// on mount, if the item is active,
|
|
60
65
|
// send the top position to the parent
|
|
@@ -63,11 +68,11 @@ var DocLink = function (_a) {
|
|
|
63
68
|
if (item.active) {
|
|
64
69
|
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);
|
|
65
70
|
}
|
|
66
|
-
}, []);
|
|
71
|
+
}, [onActive, item.active]);
|
|
67
72
|
return (React.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
|
|
68
73
|
'pl-[16px]': depth >= 0,
|
|
69
74
|
}) },
|
|
70
|
-
React.createElement(
|
|
75
|
+
React.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
|
|
71
76
|
'text-indigo-500': item.active,
|
|
72
77
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
73
78
|
'py-[12px] leading-[20px] text-[14px]': depth >= 0,
|
|
@@ -77,7 +82,7 @@ var DocLink = function (_a) {
|
|
|
77
82
|
}), style: {
|
|
78
83
|
left: "-".concat(18.5 + depth * 8, "px"),
|
|
79
84
|
} })) : null,
|
|
80
|
-
item.
|
|
85
|
+
item.label)));
|
|
81
86
|
};
|
|
82
87
|
|
|
83
88
|
/******************************************************************************
|
|
@@ -94,7 +99,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
94
99
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
95
100
|
PERFORMANCE OF THIS SOFTWARE.
|
|
96
101
|
***************************************************************************** */
|
|
97
|
-
/* global Reflect, Promise */
|
|
102
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
98
103
|
|
|
99
104
|
|
|
100
105
|
var __assign = function() {
|
|
@@ -118,7 +123,12 @@ function __rest(s, e) {
|
|
|
118
123
|
t[p[i]] = s[p[i]];
|
|
119
124
|
}
|
|
120
125
|
return t;
|
|
121
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
129
|
+
var e = new Error(message);
|
|
130
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
131
|
+
};
|
|
122
132
|
|
|
123
133
|
var compileReactIconProperties = function (_a) {
|
|
124
134
|
var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name"]);
|
|
@@ -132,6 +142,7 @@ var compileReactIconProperties = function (_a) {
|
|
|
132
142
|
}
|
|
133
143
|
return newAttributes;
|
|
134
144
|
}, {});
|
|
145
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
135
146
|
React.useEffect(function () {
|
|
136
147
|
var iconFileId = "".concat(name, "_").concat(size);
|
|
137
148
|
if (defs) {
|
|
@@ -145,7 +156,7 @@ var compileReactIconProperties = function (_a) {
|
|
|
145
156
|
svgElement.innerHTML = defs;
|
|
146
157
|
document.body.appendChild(svgElement);
|
|
147
158
|
}
|
|
148
|
-
}, [defs]);
|
|
159
|
+
}, [defs, name, size]);
|
|
149
160
|
var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
|
|
150
161
|
__html: body,
|
|
151
162
|
}, className: undefined }, filteredAttributes);
|
|
@@ -187,31 +198,37 @@ const classes = {
|
|
|
187
198
|
|
|
188
199
|
var DocGroup = function (_a) {
|
|
189
200
|
var _b;
|
|
190
|
-
var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight;
|
|
191
|
-
var
|
|
192
|
-
var
|
|
201
|
+
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;
|
|
202
|
+
var _e = React.useState(depth === 0), open = _e[0], setOpen = _e[1];
|
|
203
|
+
var _f = React.useState(Array(group.items.length).fill(1)), itemsHeights = _f[0], setItemsHeights = _f[1];
|
|
193
204
|
React.useEffect(function () {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
// if this group contains other groups, ignore this effect
|
|
206
|
+
// it will be triggered by a leaf and trickle up
|
|
207
|
+
if (group.items.some(function (item) { return 'items' in item; })) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
var newHeight = open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1;
|
|
211
|
+
setHeight === null || setHeight === void 0 ? void 0 : setHeight(newHeight);
|
|
212
|
+
}, [itemsHeights, open, setHeight, group.items, group.label]);
|
|
213
|
+
var _g = React.useState(0), activeTop = _g[0], setActiveTop = _g[1];
|
|
197
214
|
React.useEffect(function () {
|
|
198
215
|
var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
|
|
199
216
|
if (activeItem >= 0) {
|
|
200
217
|
setActiveTop(itemsHeights.slice(0, activeItem).reduce(function (a, b) { return a + b; }, 1) * 44);
|
|
201
218
|
}
|
|
202
|
-
}, [itemsHeights]);
|
|
219
|
+
}, [itemsHeights, group.items]);
|
|
203
220
|
function toggleMenu(open) {
|
|
204
221
|
if (!collapsible)
|
|
205
222
|
return;
|
|
206
223
|
setOpen(open);
|
|
207
224
|
}
|
|
208
|
-
function
|
|
225
|
+
var onSetHeightCallback = React.useCallback(function (height) {
|
|
209
226
|
setItemsHeights(function (prev) {
|
|
210
227
|
var newHeights = __spreadArray([], prev, true);
|
|
211
228
|
newHeights[index] = height;
|
|
212
229
|
return newHeights;
|
|
213
230
|
});
|
|
214
|
-
}
|
|
231
|
+
}, [setItemsHeights, index]);
|
|
215
232
|
var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
|
|
216
233
|
return (React.createElement(React.Fragment, null,
|
|
217
234
|
React.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
|
|
@@ -225,7 +242,7 @@ var DocGroup = function (_a) {
|
|
|
225
242
|
'-rotate-90': !open,
|
|
226
243
|
'ml-[16px]': depth,
|
|
227
244
|
}) })) : null,
|
|
228
|
-
group.
|
|
245
|
+
group.label),
|
|
229
246
|
collapsible &&
|
|
230
247
|
depth >= 0 &&
|
|
231
248
|
open &&
|
|
@@ -238,15 +255,15 @@ var DocGroup = function (_a) {
|
|
|
238
255
|
hidden: !open,
|
|
239
256
|
}) }, group.items.map(function (item, index) {
|
|
240
257
|
return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
241
|
-
React.createElement(DocGroup, { group: item, depth: depth + 1, setHeight:
|
|
258
|
+
React.createElement(DocGroup, { group: item, depth: depth + 1, setHeight: onSetHeightCallback, index: index, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, depth: depth, onActive: function (top) { return setActiveTop(top); }, LinkComponent: LinkComponent }));
|
|
242
259
|
}))));
|
|
243
260
|
};
|
|
244
261
|
|
|
245
262
|
var DocMenu = function (_a) {
|
|
246
|
-
var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, rest = __rest$1(_a, ["items", "collapsible"]);
|
|
263
|
+
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"]);
|
|
247
264
|
return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', rest.className) }), items.map(function (item, index) {
|
|
248
265
|
return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
249
|
-
React.createElement(DocGroup, { group: item, collapsible: collapsible }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible }));
|
|
266
|
+
React.createElement(DocGroup, { index: index, group: item, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, LinkComponent: LinkComponent }));
|
|
250
267
|
})));
|
|
251
268
|
};
|
|
252
269
|
|