@cypress-design/react-docmenu 0.5.0 → 0.5.2

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/dist/index.umd.js CHANGED
@@ -190,7 +190,7 @@ var MarkerIsMovingContext = React.createContext({
190
190
  var DocLink = React__namespace.forwardRef(function (_a, ref) {
191
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;
192
192
  var activeLIRef = React__namespace.useRef(null);
193
- var _d = React__namespace.useContext(MarkerIsMovingContext), markerIsMoving = _d.markerIsMoving, setMarkerIsMoving = _d.setMarkerIsMoving;
193
+ var markerIsMoving = React__namespace.useContext(MarkerIsMovingContext).markerIsMoving;
194
194
  var setActiveMarkerPosition = function () {
195
195
  var _a;
196
196
  if (active) {
@@ -203,11 +203,7 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
203
203
  };
204
204
  // on mount, if the item is active,
205
205
  // send the top position to the parent
206
- React__namespace.useEffect(setActiveMarkerPosition, [
207
- onActive,
208
- active,
209
- setMarkerIsMoving,
210
- ]);
206
+ React__namespace.useEffect(setActiveMarkerPosition, [onActive, active]);
211
207
  React__namespace.useImperativeHandle(ref, function () { return ({
212
208
  setActiveMarkerPosition: setActiveMarkerPosition,
213
209
  }); });
@@ -228,27 +224,18 @@ var DocLink = React__namespace.forwardRef(function (_a, ref) {
228
224
  item.label)));
229
225
  });
230
226
 
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
- };
241
227
  var DocGroup = React__namespace.forwardRef(function (_a, ref) {
242
228
  var _b;
243
229
  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;
244
230
  var _e = React__namespace.useState(group.collapsed !== true), open = _e[0], setOpen = _e[1];
245
231
  var $groupElements = React__namespace.useRef(null);
246
232
  var $listWrapper = React__namespace.useRef(null);
247
- var didMount = useIsMounted();
248
- function toggleMenu(open) {
233
+ function toggleMenu(localOpen) {
249
234
  if (!collapsible)
250
235
  return;
251
- setOpen(open);
236
+ hideShowAbsoluteMarker(localOpen);
237
+ setOpen(localOpen);
238
+ readjustMarkerPosition(localOpen);
252
239
  }
253
240
  var hasActiveItemRecursively = React__namespace.useCallback(function (items) {
254
241
  if (items === void 0) { items = group.items; }
@@ -271,47 +258,36 @@ var DocGroup = React__namespace.forwardRef(function (_a, ref) {
271
258
  var _a;
272
259
  (_a = $groupElements.current) === null || _a === void 0 ? void 0 : _a.reTriggerSetActiveGroup();
273
260
  }
274
- React__namespace.useEffect(function () {
261
+ /**
262
+ * To make the marker follow smooth open/close animation of the menu groups
263
+ * We replace the absolute marker by one in the link. After the transition, the
264
+ * marker is replaced by the absolute one again.
265
+ */
266
+ function hideShowAbsoluteMarker(localOpen) {
275
267
  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
- }
268
+ (_a = $listWrapper.current) === null || _a === void 0 ? void 0 : _a.addEventListener('transitionstart', function () {
269
+ setMarkerIsMoving(true);
270
+ }, { once: true });
271
+ (_b = $listWrapper.current) === null || _b === void 0 ? void 0 : _b.addEventListener('transitionend', function () {
272
+ if (localOpen || !hasActiveItemRecursively()) {
273
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
274
+ }
275
+ setMarkerIsMoving(false);
276
+ }, { once: true });
277
+ }
278
+ function readjustMarkerPosition(localOpen) {
279
+ if (hasActiveItemRecursively()) {
280
+ if (localOpen) {
281
+ reTriggerSetActiveGroupParent();
303
282
  }
304
283
  else {
305
- updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
284
+ hideMarker();
306
285
  }
307
286
  }
308
- }, [
309
- open,
310
- updateMarkerPosition,
311
- hideMarker,
312
- hasActiveItemRecursively,
313
- didMount,
314
- ]);
287
+ else {
288
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
289
+ }
290
+ }
315
291
  React__namespace.useImperativeHandle(ref, function () { return ({
316
292
  reTriggerSetActiveGroup: reTriggerSetActiveGroupParent,
317
293
  }); });
@@ -361,6 +337,7 @@ var DocGroupElements = React__namespace.forwardRef(function (_a, ref) {
361
337
  item === null || item === void 0 ? void 0 : item.setActiveMarkerPosition();
362
338
  });
363
339
  // calculate the index of the calling group in the list of groups
340
+ // "index" is the index of the calling group in the list of items (groups and links)
364
341
  var indexGroup = index -
365
342
  // remove all the items that are not groups from the array and count them
366
343
  items.slice(0, index).filter(function (item) { return !('items' in item); }).length;
@@ -399,7 +376,8 @@ var DocMenu = function (_a) {
399
376
  var _e = React__namespace.useState(0), activeTop = _e[0], setActiveTop = _e[1];
400
377
  var _f = React__namespace.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
401
378
  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];
379
+ var _h = React__namespace.useState(false), markerIsMoving = _h[0], localSetMarkerIsMoving = _h[1];
380
+ var _j = React__namespace.useState(true), hasCSSTransition = _j[0], setHasCSSTransition = _j[1];
403
381
  var container = React__namespace.useRef(null);
404
382
  var setActivePosition = React__namespace.useCallback(function (opts) {
405
383
  var _a;
@@ -409,11 +387,25 @@ var DocMenu = function (_a) {
409
387
  setActiveHeight(opts.height);
410
388
  }, []);
411
389
  var setShowMarkerFalse = React__namespace.useCallback(function () { return setShowMarker(false); }, []);
390
+ var setMarkerIsMoving = React__namespace.useCallback(function (val) {
391
+ localSetMarkerIsMoving(val);
392
+ if (!val)
393
+ return;
394
+ // make sure the animation does not fire "after"
395
+ // the marker has reappeared at its right place
396
+ setHasCSSTransition(false);
397
+ setTimeout(function () {
398
+ setHasCSSTransition(true);
399
+ }, 300);
400
+ }, [localSetMarkerIsMoving]);
412
401
  return (React__namespace.createElement(MarkerIsMovingContext.Provider, { value: { markerIsMoving: markerIsMoving, setMarkerIsMoving: setMarkerIsMoving } },
413
402
  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: {
403
+ showMarker && !markerIsMoving && collapsible ? (React__namespace.createElement("div", { className: "absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 ml-[6.5px] mt-[4px]", style: {
415
404
  top: "".concat(activeTop, "px"),
416
405
  height: "".concat(activeHeight - 8, "px"),
406
+ transition: hasCSSTransition
407
+ ? 'height .3s ease-in-out, top .3s ease-in-out'
408
+ : 'none',
417
409
  } })) : null,
418
410
  React__namespace.createElement(DocGroupElements, __assign$1({}, rest, { items: items, activePath: activePath, collapsible: collapsible, depth: -1, onActivePosition: setActivePosition, LinkComponent: LinkComponent, hideMarker: setShowMarkerFalse })))));
419
411
  };
@@ -421,4 +413,4 @@ var DocMenu = function (_a) {
421
413
  module.exports = DocMenu;
422
414
  //# sourceMappingURL=index.umd.js.map
423
415
 
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"> */
416
+ /* <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] grid transition-all 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"> */