@cypress-design/react-docmenu 0.5.2 → 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/CHANGELOG.md +6 -0
- package/DocMenu.tsx +29 -29
- package/DocMenuReact.cy.tsx +5 -3
- package/_DocGroup.tsx +78 -83
- 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 +77 -76
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +77 -75
- 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
|
-
|
|
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);
|
|
217
230
|
setOpen(localOpen);
|
|
218
231
|
readjustMarkerPosition(localOpen);
|
|
219
|
-
}
|
|
220
|
-
var hasActiveItemRecursively = React.useCallback(function (items) {
|
|
221
|
-
if (items === void 0) { items = group.items; }
|
|
222
|
-
return items.some(function (item) {
|
|
223
|
-
if ('items' in item) {
|
|
224
|
-
return hasActiveItemRecursively(item.items);
|
|
225
|
-
}
|
|
226
|
-
return item.href === activePath;
|
|
227
|
-
});
|
|
228
|
-
}, [group.items, activePath]);
|
|
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,20 +246,17 @@ 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
|
-
setMarkerIsMoving(false);
|
|
256
|
-
}, { once: true });
|
|
257
|
-
}
|
|
249
|
+
var restoreActiveMarkerAfterTransition = function () {
|
|
250
|
+
if (!markerIsMovingTimeout) {
|
|
251
|
+
clearTimeout(markerIsMovingTimeout);
|
|
252
|
+
}
|
|
253
|
+
if (open || !hasActiveItemRecursivelyMemo) {
|
|
254
|
+
updateMarkerPosition();
|
|
255
|
+
}
|
|
256
|
+
setMarkerIsMoving(false);
|
|
257
|
+
};
|
|
258
258
|
function readjustMarkerPosition(localOpen) {
|
|
259
|
-
if (
|
|
259
|
+
if (hasActiveItemRecursivelyMemo) {
|
|
260
260
|
if (localOpen) {
|
|
261
261
|
reTriggerSetActiveGroupParent();
|
|
262
262
|
}
|
|
@@ -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,26 +293,20 @@ 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) {
|
|
@@ -331,21 +327,22 @@ var DocGroupElements = React.forwardRef(function (_a, ref) {
|
|
|
331
327
|
React.useImperativeHandle(ref, function () { return ({
|
|
332
328
|
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
333
329
|
}); });
|
|
330
|
+
var activePath = context.activePath, hideMarker = context.hideMarker;
|
|
334
331
|
var onUpdateMarkerPosition = React.useCallback(function (index) {
|
|
335
|
-
if (hasActiveItemRecursively()) {
|
|
332
|
+
if (hasActiveItemRecursively(items, activePath)) {
|
|
336
333
|
reTriggerSetActiveGroup(index);
|
|
337
334
|
}
|
|
338
335
|
else {
|
|
339
336
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
340
337
|
}
|
|
341
|
-
}, [
|
|
338
|
+
}, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
|
|
342
339
|
return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
|
|
343
340
|
return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
344
341
|
React.createElement(DocGroup, { ref: function (el) {
|
|
345
342
|
$groups.current[index] = el;
|
|
346
|
-
}, 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) {
|
|
347
344
|
$items.current[index] = el;
|
|
348
|
-
}, key: index, item: item,
|
|
345
|
+
}, key: index, item: item, depth: depth, markerIsMoving: markerIsMoving, context: context, onActive: function (opts) {
|
|
349
346
|
return depth < 0 ? hideMarker() : onActivePosition(opts);
|
|
350
347
|
}, LinkComponent: LinkComponent }));
|
|
351
348
|
})));
|
|
@@ -366,7 +363,7 @@ var DocMenu = function (_a) {
|
|
|
366
363
|
setActiveTop(opts.top - containerTop);
|
|
367
364
|
setActiveHeight(opts.height);
|
|
368
365
|
}, []);
|
|
369
|
-
var
|
|
366
|
+
var hideMarker = React.useCallback(function () { return setShowMarker(false); }, []);
|
|
370
367
|
var setMarkerIsMoving = React.useCallback(function (val) {
|
|
371
368
|
localSetMarkerIsMoving(val);
|
|
372
369
|
if (!val)
|
|
@@ -378,19 +375,23 @@ var DocMenu = function (_a) {
|
|
|
378
375
|
setHasCSSTransition(true);
|
|
379
376
|
}, 300);
|
|
380
377
|
}, [localSetMarkerIsMoving]);
|
|
381
|
-
return (React.createElement(
|
|
382
|
-
React.createElement("div", {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
+
} }))));
|
|
391
392
|
};
|
|
392
393
|
|
|
393
394
|
export { DocMenu as default };
|
|
394
395
|
//# sourceMappingURL=index.es.mjs.map
|
|
395
396
|
|
|
396
|
-
/* <wind-keep class="container relative absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 ml-[6.5px] mt-[4px] transition ease-in-out text-indigo-500 rotate-0 -rotate-90 ml-[28px]
|
|
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"> */
|