@cypress-design/react-docmenu 0.4.2 → 0.5.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 +17 -0
- package/DocMenu.tsx +28 -21
- package/DocMenuReact.cy.tsx +6 -2
- package/_DocGroup.tsx +128 -56
- package/_DocLink.tsx +27 -18
- package/dist/DocMenu.d.ts.map +1 -1
- package/dist/_DocGroup.d.ts +2 -2
- package/dist/_DocGroup.d.ts.map +1 -1
- package/dist/_DocLink.d.ts +3 -2
- package/dist/_DocLink.d.ts.map +1 -1
- package/dist/index.es.mjs +121 -51
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +120 -51
- package/dist/index.umd.js.map +1 -1
- package/dist/markerIsMoving.d.ts +6 -0
- package/dist/markerIsMoving.d.ts.map +1 -0
- package/markerIsMoving.ts +9 -0
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -175,18 +175,23 @@ var IconChevronDownSmall = function (props) { return React__namespace.createElem
|
|
|
175
175
|
/* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
|
|
176
176
|
|
|
177
177
|
const classes = {
|
|
178
|
+
expandedIcon: 'absolute left-0 transform transition-transform text-gray-400 dark:text-gray-700',
|
|
178
179
|
button: 'flex leading-[24px] py-[10px] items-center relative w-full text-start',
|
|
179
180
|
topButton: 'leading-[24px] text-[16px] pl-[24px] font-medium',
|
|
180
|
-
leafButton: 'leading-[20px] text-[14px] pl-[
|
|
181
|
+
leafButton: 'leading-[20px] text-[14px] pl-[48px]',
|
|
182
|
+
openListBorderLeft: 'absolute left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900',
|
|
181
183
|
};
|
|
182
184
|
|
|
185
|
+
var MarkerIsMovingContext = React.createContext({
|
|
186
|
+
setMarkerIsMoving: function () { },
|
|
187
|
+
markerIsMoving: false,
|
|
188
|
+
});
|
|
189
|
+
|
|
183
190
|
var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
184
191
|
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
192
|
var activeLIRef = React__namespace.useRef(null);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
React__namespace.useEffect(setActiveMarkerPosition, [onActive, active]);
|
|
189
|
-
function setActiveMarkerPosition() {
|
|
193
|
+
var _d = React__namespace.useContext(MarkerIsMovingContext), markerIsMoving = _d.markerIsMoving, setMarkerIsMoving = _d.setMarkerIsMoving;
|
|
194
|
+
var setActiveMarkerPosition = function () {
|
|
190
195
|
var _a;
|
|
191
196
|
if (active) {
|
|
192
197
|
var box = (_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
@@ -195,31 +200,51 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
|
195
200
|
height: (box === null || box === void 0 ? void 0 : box.height) || 0,
|
|
196
201
|
});
|
|
197
202
|
}
|
|
198
|
-
}
|
|
203
|
+
};
|
|
204
|
+
// on mount, if the item is active,
|
|
205
|
+
// send the top position to the parent
|
|
206
|
+
React__namespace.useEffect(setActiveMarkerPosition, [
|
|
207
|
+
onActive,
|
|
208
|
+
active,
|
|
209
|
+
setMarkerIsMoving,
|
|
210
|
+
]);
|
|
199
211
|
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
200
212
|
setActiveMarkerPosition: setActiveMarkerPosition,
|
|
201
213
|
}); });
|
|
202
|
-
return (React__namespace.createElement("li", { ref: activeLIRef, className:
|
|
203
|
-
|
|
204
|
-
}) },
|
|
205
|
-
React__namespace.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
|
|
214
|
+
return (React__namespace.createElement("li", { ref: activeLIRef, className: "list-none p-0" },
|
|
215
|
+
React__namespace.createElement(LinkComponent, { className: clsx('group relative block w-full pl-[24px]', {
|
|
206
216
|
'text-indigo-500': active,
|
|
217
|
+
'text-gray-700 dark:text-gray-500': !active,
|
|
207
218
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
208
|
-
'
|
|
209
|
-
}), href: item.href
|
|
210
|
-
|
|
219
|
+
'leading-[20px] text-[14px] py-[12px]': depth >= 0,
|
|
220
|
+
}), href: item.href, style: {
|
|
221
|
+
paddingLeft: depth >= 0 ? "".concat(depth * 12 + 48, "px") : undefined,
|
|
222
|
+
} },
|
|
223
|
+
depth >= 0 ? (React__namespace.createElement("div", { className: clsx('left-[6.5px] absolute top-[4px] bottom-[4px] w-[4px] z-10 rounded-full', {
|
|
224
|
+
hidden: !markerIsMoving || !active,
|
|
211
225
|
'group-hover:block bg-gray-300': !active && collapsible,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
} })) : null,
|
|
226
|
+
'bg-indigo-500': active && markerIsMoving,
|
|
227
|
+
}) })) : null,
|
|
215
228
|
item.label)));
|
|
216
229
|
});
|
|
217
230
|
|
|
231
|
+
var useIsMounted = function () {
|
|
232
|
+
var isMounted = React__namespace.useRef(false);
|
|
233
|
+
React__namespace.useEffect(function () {
|
|
234
|
+
isMounted.current = true;
|
|
235
|
+
return function () {
|
|
236
|
+
isMounted.current = false;
|
|
237
|
+
};
|
|
238
|
+
}, []);
|
|
239
|
+
return isMounted;
|
|
240
|
+
};
|
|
218
241
|
var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
219
242
|
var _b;
|
|
220
243
|
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
244
|
var _e = React__namespace.useState(group.collapsed !== true), open = _e[0], setOpen = _e[1];
|
|
222
245
|
var $groupElements = React__namespace.useRef(null);
|
|
246
|
+
var $listWrapper = React__namespace.useRef(null);
|
|
247
|
+
var didMount = useIsMounted();
|
|
223
248
|
function toggleMenu(open) {
|
|
224
249
|
if (!collapsible)
|
|
225
250
|
return;
|
|
@@ -241,29 +266,58 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
241
266
|
onActivePosition({ top: top, height: height });
|
|
242
267
|
}
|
|
243
268
|
}, [onActivePosition, open]);
|
|
244
|
-
|
|
269
|
+
var setMarkerIsMoving = React__namespace.useContext(MarkerIsMovingContext).setMarkerIsMoving;
|
|
270
|
+
function reTriggerSetActiveGroupParent() {
|
|
245
271
|
var _a;
|
|
246
272
|
(_a = $groupElements.current) === null || _a === void 0 ? void 0 : _a.reTriggerSetActiveGroup();
|
|
247
273
|
}
|
|
248
274
|
React__namespace.useEffect(function () {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
275
|
+
var _a, _b;
|
|
276
|
+
if (didMount.current) {
|
|
277
|
+
(_a = $listWrapper.current) === null || _a === void 0 ? void 0 : _a.addEventListener('transitionstart', function () {
|
|
278
|
+
setMarkerIsMoving(true);
|
|
279
|
+
}, { once: true });
|
|
280
|
+
(_b = $listWrapper.current) === null || _b === void 0 ? void 0 : _b.addEventListener('transitionend', function () {
|
|
281
|
+
setMarkerIsMoving(false);
|
|
282
|
+
if (open || !hasActiveItemRecursively()) {
|
|
283
|
+
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
284
|
+
}
|
|
285
|
+
}, { once: true });
|
|
286
|
+
}
|
|
287
|
+
}, [
|
|
288
|
+
open,
|
|
289
|
+
setMarkerIsMoving,
|
|
290
|
+
updateMarkerPosition,
|
|
291
|
+
hasActiveItemRecursively,
|
|
292
|
+
didMount,
|
|
293
|
+
]);
|
|
294
|
+
React__namespace.useEffect(function () {
|
|
295
|
+
if (didMount.current) {
|
|
296
|
+
if (hasActiveItemRecursively()) {
|
|
297
|
+
if (open) {
|
|
298
|
+
reTriggerSetActiveGroupParent();
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
hideMarker();
|
|
302
|
+
}
|
|
252
303
|
}
|
|
253
304
|
else {
|
|
254
|
-
|
|
305
|
+
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
255
306
|
}
|
|
256
307
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
308
|
+
}, [
|
|
309
|
+
open,
|
|
310
|
+
updateMarkerPosition,
|
|
311
|
+
hideMarker,
|
|
312
|
+
hasActiveItemRecursively,
|
|
313
|
+
didMount,
|
|
314
|
+
]);
|
|
261
315
|
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
262
|
-
reTriggerSetActiveGroup:
|
|
316
|
+
reTriggerSetActiveGroup: reTriggerSetActiveGroupParent,
|
|
263
317
|
}); });
|
|
264
318
|
var onUpdateMarkerPosition = React__namespace.useCallback(function () {
|
|
265
319
|
if (hasActiveItemRecursively()) {
|
|
266
|
-
|
|
320
|
+
reTriggerSetActiveGroupParent();
|
|
267
321
|
}
|
|
268
322
|
else {
|
|
269
323
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
@@ -275,13 +329,18 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
275
329
|
_b[classes.leafButton] = depth,
|
|
276
330
|
_b['text-indigo-500'] = activePath === group.href,
|
|
277
331
|
_b)) },
|
|
278
|
-
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(
|
|
332
|
+
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
|
|
279
333
|
'rotate-0': open,
|
|
280
334
|
'-rotate-90': !open,
|
|
281
|
-
'ml-[
|
|
335
|
+
'ml-[28px]': depth,
|
|
282
336
|
}) })) : null,
|
|
283
337
|
group.label),
|
|
284
|
-
React__namespace.createElement(
|
|
338
|
+
React__namespace.createElement("div", { className: clsx('grid transition-all relative', {
|
|
339
|
+
'grid-rows-[0fr]': !open && collapsible,
|
|
340
|
+
'grid-rows-[1fr]': open || !collapsible,
|
|
341
|
+
}), ref: $listWrapper },
|
|
342
|
+
open && collapsible && depth === 0 ? (React__namespace.createElement("div", { className: classes.openListBorderLeft })) : null,
|
|
343
|
+
React__namespace.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items, activePath: activePath, collapsible: collapsible, depth: depth, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent, hideMarker: hideMarker }))));
|
|
285
344
|
});
|
|
286
345
|
var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
287
346
|
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"]);
|
|
@@ -296,35 +355,42 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
|
296
355
|
return item.href === activePath;
|
|
297
356
|
});
|
|
298
357
|
}, [items, activePath]);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
group === null || group === void 0 ? void 0 : group.reTriggerSetActiveGroup();
|
|
302
|
-
});
|
|
358
|
+
var reTriggerSetActiveGroup = React__namespace.useCallback(function (index) {
|
|
359
|
+
if (index === void 0) { index = 0; }
|
|
303
360
|
$items.current.forEach(function (item) {
|
|
304
361
|
item === null || item === void 0 ? void 0 : item.setActiveMarkerPosition();
|
|
305
362
|
});
|
|
306
|
-
|
|
363
|
+
// calculate the index of the calling group in the list of groups
|
|
364
|
+
var indexGroup = index -
|
|
365
|
+
// remove all the items that are not groups from the array and count them
|
|
366
|
+
items.slice(0, index).filter(function (item) { return !('items' in item); }).length;
|
|
367
|
+
// only update groups that come after the toggled one
|
|
368
|
+
// others will not need to update the marker
|
|
369
|
+
// since they are "before" in the rendering tree
|
|
370
|
+
$groups.current.slice(indexGroup + 1).forEach(function (group) {
|
|
371
|
+
group === null || group === void 0 ? void 0 : group.reTriggerSetActiveGroup();
|
|
372
|
+
});
|
|
373
|
+
}, [items]);
|
|
307
374
|
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
308
375
|
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
309
376
|
}); });
|
|
310
|
-
var onUpdateMarkerPosition = React__namespace.useCallback(function () {
|
|
377
|
+
var onUpdateMarkerPosition = React__namespace.useCallback(function (index) {
|
|
311
378
|
if (hasActiveItemRecursively()) {
|
|
312
|
-
reTriggerSetActiveGroup();
|
|
379
|
+
reTriggerSetActiveGroup(index);
|
|
313
380
|
}
|
|
314
381
|
else {
|
|
315
382
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
316
383
|
}
|
|
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) {
|
|
384
|
+
}, [hasActiveItemRecursively, updateMarkerPosition, reTriggerSetActiveGroup]);
|
|
385
|
+
return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
|
|
322
386
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
323
387
|
React__namespace.createElement(DocGroup, { ref: function (el) {
|
|
324
388
|
$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) {
|
|
389
|
+
}, group: item, activePath: activePath, depth: depth + 1, collapsible: collapsible, LinkComponent: LinkComponent, hideMarker: hideMarker, onActivePosition: onActivePosition, updateMarkerPosition: function () { return onUpdateMarkerPosition(index); } }))) : (React__namespace.createElement(DocLink, { ref: function (el) {
|
|
326
390
|
$items.current[index] = el;
|
|
327
|
-
}, key: index, item: item, active: item.href === activePath, collapsible: collapsible, depth: depth, onActive:
|
|
391
|
+
}, key: index, item: item, active: item.href === activePath, collapsible: collapsible, depth: depth, onActive: function (opts) {
|
|
392
|
+
return depth < 0 ? hideMarker() : onActivePosition(opts);
|
|
393
|
+
}, LinkComponent: LinkComponent }));
|
|
328
394
|
})));
|
|
329
395
|
});
|
|
330
396
|
|
|
@@ -333,6 +399,7 @@ var DocMenu = function (_a) {
|
|
|
333
399
|
var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
|
|
334
400
|
var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
|
|
335
401
|
var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
|
|
402
|
+
var _h = React__namespace.useState(false), markerIsMoving = _h[0], setMarkerIsMoving = _h[1];
|
|
336
403
|
var container = React__namespace.useRef(null);
|
|
337
404
|
var setActivePosition = React__namespace.useCallback(function (opts) {
|
|
338
405
|
var _a;
|
|
@@ -341,15 +408,17 @@ var DocMenu = function (_a) {
|
|
|
341
408
|
setActiveTop(opts.top - containerTop);
|
|
342
409
|
setActiveHeight(opts.height);
|
|
343
410
|
}, []);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
411
|
+
var setShowMarkerFalse = React__namespace.useCallback(function () { return setShowMarker(false); }, []);
|
|
412
|
+
return (React__namespace.createElement(MarkerIsMovingContext.Provider, { value: { markerIsMoving: markerIsMoving, setMarkerIsMoving: setMarkerIsMoving } },
|
|
413
|
+
React__namespace.createElement("div", { ref: container, className: "relative" },
|
|
414
|
+
showMarker && !markerIsMoving && 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: {
|
|
415
|
+
top: "".concat(activeTop, "px"),
|
|
416
|
+
height: "".concat(activeHeight - 8, "px"),
|
|
417
|
+
} })) : null,
|
|
418
|
+
React__namespace.createElement(DocGroupElements, __assign$1({}, rest, { items: items, activePath: activePath, collapsible: collapsible, depth: -1, onActivePosition: setActivePosition, LinkComponent: LinkComponent, hideMarker: setShowMarkerFalse })))));
|
|
350
419
|
};
|
|
351
420
|
|
|
352
421
|
module.exports = DocMenu;
|
|
353
422
|
//# sourceMappingURL=index.umd.js.map
|
|
354
423
|
|
|
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]
|
|
424
|
+
/* <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] text-indigo-500 rotate-0 -rotate-90 ml-[28px] grid grid-rows-[0fr] grid-rows-[1fr] overflow-hidden filter list-none p-0 block w-full pl-[24px] text-gray-700 dark:text-gray-500 py-[8px] text-[16px] leading-[24px] leading-[20px] text-[14px] py-[12px] left-[6.5px] top-[4px] bottom-[4px] z-10 hidden group-hover:block bg-gray-300 text-gray-500 left-0 transform transition-transform text-gray-400 dark:text-gray-700 flex py-[10px] items-center text-start font-medium pl-[48px] left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900"> */
|