@cypress-design/react-docmenu 0.5.1 → 0.5.3
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 +12 -0
- package/DocMenu.tsx +44 -27
- package/DocMenuReact.cy.tsx +5 -3
- package/_DocGroup.tsx +83 -87
- package/_DocLink.tsx +19 -14
- package/dist/DocMenu.d.ts.map +1 -1
- package/dist/_DocGroup.d.ts +6 -8
- package/dist/_DocGroup.d.ts.map +1 -1
- package/dist/_DocLink.d.ts +11 -5
- package/dist/_DocLink.d.ts.map +1 -1
- package/dist/index.es.mjs +95 -78
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +95 -77
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/dist/markerIsMoving.d.ts +0 -6
- package/dist/markerIsMoving.d.ts.map +0 -1
- package/markerIsMoving.ts +0 -9
package/dist/index.umd.js
CHANGED
|
@@ -182,20 +182,16 @@ const classes = {
|
|
|
182
182
|
openListBorderLeft: 'absolute left-[8px] top-0 w-[1px] h-full bg-gray-100 dark:bg-gray-900',
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
-
var MarkerIsMovingContext = React.createContext({
|
|
186
|
-
setMarkerIsMoving: function () { },
|
|
187
|
-
markerIsMoving: false,
|
|
188
|
-
});
|
|
189
|
-
|
|
190
185
|
var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
191
|
-
var item = _a.item,
|
|
186
|
+
var item = _a.item, depth = _a.depth, markerIsMoving = _a.markerIsMoving, context = _a.context, onActive = _a.onActive, LinkComponent = _a.LinkComponent;
|
|
192
187
|
var activeLIRef = React__namespace.useRef(null);
|
|
193
|
-
var
|
|
188
|
+
var collapsible = context.collapsible, activePath = context.activePath;
|
|
189
|
+
var active = item.href === activePath;
|
|
194
190
|
var setActiveMarkerPosition = function () {
|
|
195
191
|
var _a;
|
|
196
192
|
if (active) {
|
|
197
193
|
var box = (_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
198
|
-
onActive
|
|
194
|
+
onActive({
|
|
199
195
|
top: (box === null || box === void 0 ? void 0 : box.top) || 0,
|
|
200
196
|
height: (box === null || box === void 0 ? void 0 : box.height) || 0,
|
|
201
197
|
});
|
|
@@ -209,7 +205,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
|
209
205
|
}); });
|
|
210
206
|
return (React__namespace.createElement("li", { ref: activeLIRef, className: "list-none p-0" },
|
|
211
207
|
React__namespace.createElement(LinkComponent, { className: clsx('group relative block w-full pl-[24px]', {
|
|
212
|
-
'text-indigo-500': active,
|
|
208
|
+
'text-indigo-500 dark:text-indigo-400': active,
|
|
213
209
|
'text-gray-700 dark:text-gray-500': !active,
|
|
214
210
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
215
211
|
'leading-[20px] text-[14px] py-[12px]': depth >= 0,
|
|
@@ -219,33 +215,42 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
|
|
|
219
215
|
depth >= 0 ? (React__namespace.createElement("div", { className: clsx('left-[6.5px] absolute top-[4px] bottom-[4px] w-[4px] z-10 rounded-full', {
|
|
220
216
|
hidden: !markerIsMoving || !active,
|
|
221
217
|
'group-hover:block bg-gray-300': !active && collapsible,
|
|
222
|
-
'bg-indigo-500': active && markerIsMoving,
|
|
218
|
+
'bg-indigo-500 dark:bg-indigo-400': active && markerIsMoving,
|
|
223
219
|
}) })) : null,
|
|
224
220
|
item.label)));
|
|
225
221
|
});
|
|
226
222
|
|
|
223
|
+
var hasActiveItemRecursively = function (items, localActivePath) {
|
|
224
|
+
return items.some(function (item) {
|
|
225
|
+
if ('items' in item) {
|
|
226
|
+
return hasActiveItemRecursively(item.items, localActivePath);
|
|
227
|
+
}
|
|
228
|
+
return item.href === localActivePath;
|
|
229
|
+
});
|
|
230
|
+
};
|
|
227
231
|
var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
228
232
|
var _b;
|
|
229
|
-
var group = _a.group,
|
|
230
|
-
var
|
|
233
|
+
var group = _a.group, _c = _a.depth, depth = _c === void 0 ? 0 : _c, onActivePosition = _a.onActivePosition, markerIsMoving = _a.markerIsMoving, context = _a.context, updateMarkerPosition = _a.updateMarkerPosition, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d;
|
|
234
|
+
var setMarkerIsMoving = context.setMarkerIsMoving, activePath = context.activePath, collapsible = context.collapsible, hideMarker = context.hideMarker;
|
|
235
|
+
var hasActiveItemRecursivelyMemo = React__namespace.useMemo(function () {
|
|
236
|
+
return hasActiveItemRecursively(group.items, activePath);
|
|
237
|
+
}, [group.items, activePath]);
|
|
238
|
+
var _e = React__namespace.useState(!group.collapsed), open = _e[0], setOpen = _e[1];
|
|
239
|
+
var _f = React__namespace.useState(), markerIsMovingTimeout = _f[0], setMarkerIsMovingTimeout = _f[1];
|
|
231
240
|
var $groupElements = React__namespace.useRef(null);
|
|
232
|
-
var
|
|
233
|
-
|
|
234
|
-
if (!collapsible)
|
|
241
|
+
var toggleMenu = function (localOpen) {
|
|
242
|
+
if (!collapsible || markerIsMoving)
|
|
235
243
|
return;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return item.href === activePath;
|
|
247
|
-
});
|
|
248
|
-
}, [group.items, activePath]);
|
|
244
|
+
setMarkerIsMoving(true);
|
|
245
|
+
// on browsers than do not support transitionend event
|
|
246
|
+
// we need to set a timeout to remove the markerIsMoving
|
|
247
|
+
var timeout = setTimeout(function () {
|
|
248
|
+
setMarkerIsMoving(false);
|
|
249
|
+
}, 350);
|
|
250
|
+
setMarkerIsMovingTimeout(timeout);
|
|
251
|
+
setOpen(localOpen);
|
|
252
|
+
readjustMarkerPosition(localOpen);
|
|
253
|
+
};
|
|
249
254
|
var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
|
|
250
255
|
var setActivePosition = React__namespace.useCallback(function (_a) {
|
|
251
256
|
var top = _a.top, height = _a.height;
|
|
@@ -253,7 +258,6 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
253
258
|
onActivePosition({ top: top, height: height });
|
|
254
259
|
}
|
|
255
260
|
}, [onActivePosition, open]);
|
|
256
|
-
var setMarkerIsMoving = React__namespace.useContext(MarkerIsMovingContext).setMarkerIsMoving;
|
|
257
261
|
function reTriggerSetActiveGroupParent() {
|
|
258
262
|
var _a;
|
|
259
263
|
(_a = $groupElements.current) === null || _a === void 0 ? void 0 : _a.reTriggerSetActiveGroup();
|
|
@@ -263,21 +267,18 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
263
267
|
* We replace the absolute marker by one in the link. After the transition, the
|
|
264
268
|
* marker is replaced by the absolute one again.
|
|
265
269
|
*/
|
|
266
|
-
function
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
function readjustMarkerPosition() {
|
|
279
|
-
if (hasActiveItemRecursively()) {
|
|
280
|
-
if (open) {
|
|
270
|
+
var restoreActiveMarkerAfterTransition = function () {
|
|
271
|
+
if (!markerIsMovingTimeout) {
|
|
272
|
+
clearTimeout(markerIsMovingTimeout);
|
|
273
|
+
}
|
|
274
|
+
if (open || !hasActiveItemRecursivelyMemo) {
|
|
275
|
+
updateMarkerPosition();
|
|
276
|
+
}
|
|
277
|
+
setMarkerIsMoving(false);
|
|
278
|
+
};
|
|
279
|
+
function readjustMarkerPosition(localOpen) {
|
|
280
|
+
if (hasActiveItemRecursivelyMemo) {
|
|
281
|
+
if (localOpen) {
|
|
281
282
|
reTriggerSetActiveGroupParent();
|
|
282
283
|
}
|
|
283
284
|
else {
|
|
@@ -285,25 +286,27 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
else {
|
|
288
|
-
updateMarkerPosition
|
|
289
|
+
updateMarkerPosition();
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
292
293
|
reTriggerSetActiveGroup: reTriggerSetActiveGroupParent,
|
|
293
294
|
}); });
|
|
294
295
|
var onUpdateMarkerPosition = React__namespace.useCallback(function () {
|
|
295
|
-
if (
|
|
296
|
+
if (hasActiveItemRecursivelyMemo) {
|
|
296
297
|
reTriggerSetActiveGroupParent();
|
|
297
298
|
}
|
|
298
299
|
else {
|
|
299
300
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
300
301
|
}
|
|
301
|
-
}, [
|
|
302
|
+
}, [hasActiveItemRecursivelyMemo, updateMarkerPosition]);
|
|
302
303
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
303
304
|
React__namespace.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
|
|
304
305
|
_b[classes.topButton] = depth === 0,
|
|
305
306
|
_b[classes.leafButton] = depth,
|
|
306
|
-
_b['text-indigo-500'] = activePath === group.href,
|
|
307
|
+
_b['text-indigo-500 dark:text-indigo-400'] = activePath === group.href,
|
|
308
|
+
_b['text-gray-900 dark:text-gray-100'] = hasActiveItemRecursivelyMemo && activePath !== group.href,
|
|
309
|
+
_b['text-gray-800 dark:text-gray-200'] = !hasActiveItemRecursivelyMemo && activePath !== group.href,
|
|
307
310
|
_b)) },
|
|
308
311
|
collapsible ? (React__namespace.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
|
|
309
312
|
'rotate-0': open,
|
|
@@ -311,32 +314,27 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
|
|
|
311
314
|
'ml-[28px]': depth,
|
|
312
315
|
}) })) : null,
|
|
313
316
|
group.label),
|
|
314
|
-
React__namespace.createElement("div", { className: clsx('
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
317
|
+
React__namespace.createElement("div", { className: clsx('relative', collapsible
|
|
318
|
+
? {
|
|
319
|
+
'transition-all grid': true,
|
|
320
|
+
'grid-rows-[0fr]': !open,
|
|
321
|
+
'grid-rows-[1fr]': open,
|
|
322
|
+
}
|
|
323
|
+
: null), onTransitionEnd: restoreActiveMarkerAfterTransition },
|
|
318
324
|
open && collapsible && depth === 0 ? (React__namespace.createElement("div", { className: classes.openListBorderLeft })) : null,
|
|
319
|
-
React__namespace.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items,
|
|
325
|
+
React__namespace.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items, depth: depth, context: context, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent }))));
|
|
320
326
|
});
|
|
321
327
|
var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
322
|
-
var items = _a.items,
|
|
328
|
+
var items = _a.items, _b = _a.depth, depth = _b === void 0 ? 0 : _b, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, markerIsMoving = _a.markerIsMoving, LinkComponent = _a.LinkComponent, className = _a.className, context = _a.context, rest = __rest$1(_a, ["items", "depth", "onActivePosition", "updateMarkerPosition", "markerIsMoving", "LinkComponent", "className", "context"]);
|
|
323
329
|
var $groups = React__namespace.useRef([]);
|
|
324
330
|
var $items = React__namespace.useRef([]);
|
|
325
|
-
var hasActiveItemRecursively = React__namespace.useCallback(function (localItems) {
|
|
326
|
-
if (localItems === void 0) { localItems = items; }
|
|
327
|
-
return localItems.some(function (item) {
|
|
328
|
-
if ('items' in item) {
|
|
329
|
-
return hasActiveItemRecursively(item.items);
|
|
330
|
-
}
|
|
331
|
-
return item.href === activePath;
|
|
332
|
-
});
|
|
333
|
-
}, [items, activePath]);
|
|
334
331
|
var reTriggerSetActiveGroup = React__namespace.useCallback(function (index) {
|
|
335
332
|
if (index === void 0) { index = 0; }
|
|
336
333
|
$items.current.forEach(function (item) {
|
|
337
334
|
item === null || item === void 0 ? void 0 : item.setActiveMarkerPosition();
|
|
338
335
|
});
|
|
339
336
|
// calculate the index of the calling group in the list of groups
|
|
337
|
+
// "index" is the index of the calling group in the list of items (groups and links)
|
|
340
338
|
var indexGroup = index -
|
|
341
339
|
// remove all the items that are not groups from the array and count them
|
|
342
340
|
items.slice(0, index).filter(function (item) { return !('items' in item); }).length;
|
|
@@ -350,21 +348,22 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
|
|
|
350
348
|
React__namespace.useImperativeHandle(ref, function () { return ({
|
|
351
349
|
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
352
350
|
}); });
|
|
351
|
+
var activePath = context.activePath, hideMarker = context.hideMarker;
|
|
353
352
|
var onUpdateMarkerPosition = React__namespace.useCallback(function (index) {
|
|
354
|
-
if (hasActiveItemRecursively()) {
|
|
353
|
+
if (hasActiveItemRecursively(items, activePath)) {
|
|
355
354
|
reTriggerSetActiveGroup(index);
|
|
356
355
|
}
|
|
357
356
|
else {
|
|
358
357
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
359
358
|
}
|
|
360
|
-
}, [
|
|
359
|
+
}, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
|
|
361
360
|
return (React__namespace.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
|
|
362
361
|
return 'items' in item ? (React__namespace.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
363
362
|
React__namespace.createElement(DocGroup, { ref: function (el) {
|
|
364
363
|
$groups.current[index] = el;
|
|
365
|
-
}, group: item,
|
|
364
|
+
}, group: item, depth: depth + 1, LinkComponent: LinkComponent, markerIsMoving: markerIsMoving, context: context, onActivePosition: onActivePosition, updateMarkerPosition: function () { return onUpdateMarkerPosition(index); } }))) : (React__namespace.createElement(DocLink, { ref: function (el) {
|
|
366
365
|
$items.current[index] = el;
|
|
367
|
-
}, key: index, item: item,
|
|
366
|
+
}, key: index, item: item, depth: depth, markerIsMoving: markerIsMoving, context: context, onActive: function (opts) {
|
|
368
367
|
return depth < 0 ? hideMarker() : onActivePosition(opts);
|
|
369
368
|
}, LinkComponent: LinkComponent }));
|
|
370
369
|
})));
|
|
@@ -375,7 +374,8 @@ var DocMenu = function (_a) {
|
|
|
375
374
|
var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
|
|
376
375
|
var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
|
|
377
376
|
var _g = React__namespace.useState(false), showMarker = _g[0], setShowMarker = _g[1];
|
|
378
|
-
var _h = React__namespace.useState(false), markerIsMoving = _h[0],
|
|
377
|
+
var _h = React__namespace.useState(false), markerIsMoving = _h[0], localSetMarkerIsMoving = _h[1];
|
|
378
|
+
var _j = React__namespace.useState(true), hasCSSTransition = _j[0], setHasCSSTransition = _j[1];
|
|
379
379
|
var container = React__namespace.useRef(null);
|
|
380
380
|
var setActivePosition = React__namespace.useCallback(function (opts) {
|
|
381
381
|
var _a;
|
|
@@ -384,17 +384,35 @@ var DocMenu = function (_a) {
|
|
|
384
384
|
setActiveTop(opts.top - containerTop);
|
|
385
385
|
setActiveHeight(opts.height);
|
|
386
386
|
}, []);
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
387
|
+
var hideMarker = React__namespace.useCallback(function () { return setShowMarker(false); }, []);
|
|
388
|
+
var setMarkerIsMoving = React__namespace.useCallback(function (val) {
|
|
389
|
+
localSetMarkerIsMoving(val);
|
|
390
|
+
if (!val)
|
|
391
|
+
return;
|
|
392
|
+
// make sure the animation does not fire "after"
|
|
393
|
+
// the marker has reappeared at its right place
|
|
394
|
+
setHasCSSTransition(false);
|
|
395
|
+
setTimeout(function () {
|
|
396
|
+
setHasCSSTransition(true);
|
|
397
|
+
}, 300);
|
|
398
|
+
}, [localSetMarkerIsMoving]);
|
|
399
|
+
return (React__namespace.createElement("div", { ref: container, className: "relative" },
|
|
400
|
+
showMarker && !markerIsMoving && collapsible ? (React__namespace.createElement("div", { "data-cy": "doc-menu-active-marker", className: "absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 dark:bg-indigo-400 ml-[6.5px] mt-[4px]", style: {
|
|
401
|
+
top: "".concat(activeTop, "px"),
|
|
402
|
+
height: "".concat(activeHeight - 8, "px"),
|
|
403
|
+
transition: hasCSSTransition
|
|
404
|
+
? 'height .3s ease-in-out, top .3s ease-in-out'
|
|
405
|
+
: 'none',
|
|
406
|
+
} })) : null,
|
|
407
|
+
React__namespace.createElement(DocGroupElements, __assign$1({}, rest, { items: items, depth: -1, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, LinkComponent: LinkComponent, context: {
|
|
408
|
+
setMarkerIsMoving: setMarkerIsMoving,
|
|
409
|
+
activePath: activePath,
|
|
410
|
+
collapsible: collapsible,
|
|
411
|
+
hideMarker: hideMarker,
|
|
412
|
+
} }))));
|
|
395
413
|
};
|
|
396
414
|
|
|
397
415
|
module.exports = DocMenu;
|
|
398
416
|
//# sourceMappingURL=index.umd.js.map
|
|
399
417
|
|
|
400
|
-
/* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500
|
|
418
|
+
/* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 dark:bg-indigo-400 ml-[6.5px] mt-[4px] transition ease-in-out text-indigo-500 dark:text-indigo-400 text-gray-900 dark:text-gray-100 text-gray-800 dark:text-gray-200 rotate-0 -rotate-90 ml-[28px] transition-all 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-indigo-400 text-gray-500 bg-indigo-400 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"> */
|