@cypress-design/react-docmenu 0.5.2 → 0.5.4
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 +29 -29
- package/DocMenuReact.cy.tsx +10 -4
- package/_DocGroup.tsx +85 -84
- package/_DocLink.tsx +28 -13
- 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 +87 -83
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +87 -82
- 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
|
|
165
|
+
var _b = _a.item, label = _b.label, itemRest = __rest$1(_b, ["label"]), 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 = itemRest.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
|
});
|
|
@@ -188,44 +183,53 @@ var DocLink = React.forwardRef(function (_a, ref) {
|
|
|
188
183
|
setActiveMarkerPosition: setActiveMarkerPosition,
|
|
189
184
|
}); });
|
|
190
185
|
return (React.createElement("li", { ref: activeLIRef, className: "list-none p-0" },
|
|
191
|
-
React.createElement(LinkComponent, { className: clsx('group relative block w-full pl-[24px]', {
|
|
192
|
-
'text-indigo-500': active,
|
|
186
|
+
React.createElement(LinkComponent, __assign$1({}, itemRest, { className: clsx('group relative block w-full pl-[24px]', {
|
|
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,
|
|
196
|
-
}),
|
|
191
|
+
}), style: {
|
|
197
192
|
paddingLeft: depth >= 0 ? "".concat(depth * 12 + 48, "px") : undefined,
|
|
198
|
-
} },
|
|
193
|
+
} }),
|
|
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
|
+
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,52 +265,51 @@ 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,
|
|
287
|
-
_b
|
|
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,
|
|
289
|
+
_b)), style: {
|
|
290
|
+
paddingLeft: depth >= 1 ? "".concat((depth - 1) * 12 + 48, "px") : undefined,
|
|
291
|
+
} },
|
|
288
292
|
collapsible ? (React.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx(classes.expandedIcon, {
|
|
289
293
|
'rotate-0': open,
|
|
290
294
|
'-rotate-90': !open,
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
}), style: {
|
|
296
|
+
marginLeft: depth >= 1 ? "".concat((depth - 1) * 12 + 28, "px") : undefined,
|
|
297
|
+
} })) : null,
|
|
293
298
|
group.label),
|
|
294
|
-
React.createElement("div", { className: clsx('
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
299
|
+
React.createElement("div", { className: clsx('relative', collapsible
|
|
300
|
+
? {
|
|
301
|
+
'transition-all grid': true,
|
|
302
|
+
'grid-rows-[0fr]': !open,
|
|
303
|
+
'grid-rows-[1fr]': open,
|
|
304
|
+
}
|
|
305
|
+
: null), onTransitionEnd: restoreActiveMarkerAfterTransition },
|
|
298
306
|
open && collapsible && depth === 0 ? (React.createElement("div", { className: classes.openListBorderLeft })) : null,
|
|
299
|
-
React.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items,
|
|
307
|
+
React.createElement(DocGroupElements, { ref: $groupElements, className: "overflow-hidden", items: group.items, depth: depth, context: context, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent }))));
|
|
300
308
|
});
|
|
301
309
|
var DocGroupElements = React.forwardRef(function (_a, ref) {
|
|
302
|
-
var items = _a.items,
|
|
310
|
+
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
311
|
var $groups = React.useRef([]);
|
|
304
312
|
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
313
|
var reTriggerSetActiveGroup = React.useCallback(function (index) {
|
|
315
314
|
if (index === void 0) { index = 0; }
|
|
316
315
|
$items.current.forEach(function (item) {
|
|
@@ -331,21 +330,22 @@ var DocGroupElements = React.forwardRef(function (_a, ref) {
|
|
|
331
330
|
React.useImperativeHandle(ref, function () { return ({
|
|
332
331
|
reTriggerSetActiveGroup: reTriggerSetActiveGroup,
|
|
333
332
|
}); });
|
|
333
|
+
var activePath = context.activePath, hideMarker = context.hideMarker;
|
|
334
334
|
var onUpdateMarkerPosition = React.useCallback(function (index) {
|
|
335
|
-
if (hasActiveItemRecursively()) {
|
|
335
|
+
if (hasActiveItemRecursively(items, activePath)) {
|
|
336
336
|
reTriggerSetActiveGroup(index);
|
|
337
337
|
}
|
|
338
338
|
else {
|
|
339
339
|
updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
|
|
340
340
|
}
|
|
341
|
-
}, [
|
|
341
|
+
}, [updateMarkerPosition, reTriggerSetActiveGroup, items, activePath]);
|
|
342
342
|
return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className) }), items.map(function (item, index) {
|
|
343
343
|
return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
|
|
344
344
|
React.createElement(DocGroup, { ref: function (el) {
|
|
345
345
|
$groups.current[index] = el;
|
|
346
|
-
}, group: item,
|
|
346
|
+
}, 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
347
|
$items.current[index] = el;
|
|
348
|
-
}, key: index, item: item,
|
|
348
|
+
}, key: index, item: item, depth: depth, markerIsMoving: markerIsMoving, context: context, onActive: function (opts) {
|
|
349
349
|
return depth < 0 ? hideMarker() : onActivePosition(opts);
|
|
350
350
|
}, LinkComponent: LinkComponent }));
|
|
351
351
|
})));
|
|
@@ -366,7 +366,7 @@ var DocMenu = function (_a) {
|
|
|
366
366
|
setActiveTop(opts.top - containerTop);
|
|
367
367
|
setActiveHeight(opts.height);
|
|
368
368
|
}, []);
|
|
369
|
-
var
|
|
369
|
+
var hideMarker = React.useCallback(function () { return setShowMarker(false); }, []);
|
|
370
370
|
var setMarkerIsMoving = React.useCallback(function (val) {
|
|
371
371
|
localSetMarkerIsMoving(val);
|
|
372
372
|
if (!val)
|
|
@@ -378,19 +378,23 @@ var DocMenu = function (_a) {
|
|
|
378
378
|
setHasCSSTransition(true);
|
|
379
379
|
}, 300);
|
|
380
380
|
}, [localSetMarkerIsMoving]);
|
|
381
|
-
return (React.createElement(
|
|
382
|
-
React.createElement("div", {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
381
|
+
return (React.createElement("div", { ref: container, className: "relative" },
|
|
382
|
+
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: {
|
|
383
|
+
top: "".concat(activeTop, "px"),
|
|
384
|
+
height: "".concat(activeHeight - 8, "px"),
|
|
385
|
+
transition: hasCSSTransition
|
|
386
|
+
? 'height .3s ease-in-out, top .3s ease-in-out'
|
|
387
|
+
: 'none',
|
|
388
|
+
} })) : null,
|
|
389
|
+
React.createElement(DocGroupElements, __assign$1({}, rest, { items: items, depth: -1, markerIsMoving: markerIsMoving, onActivePosition: setActivePosition, LinkComponent: LinkComponent, context: {
|
|
390
|
+
setMarkerIsMoving: setMarkerIsMoving,
|
|
391
|
+
activePath: activePath,
|
|
392
|
+
collapsible: collapsible,
|
|
393
|
+
hideMarker: hideMarker,
|
|
394
|
+
} }))));
|
|
391
395
|
};
|
|
392
396
|
|
|
393
397
|
export { DocMenu as default };
|
|
394
398
|
//# sourceMappingURL=index.es.mjs.map
|
|
395
399
|
|
|
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
|
|
400
|
+
/* <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 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"> */
|