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