@cypress-design/react-docmenu 0.5.0 → 0.5.1

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
233
  function toggleMenu(open) {
249
234
  if (!collapsible)
250
235
  return;
251
236
  setOpen(open);
237
+ hideShowAbsoluteMarker();
238
+ readjustMarkerPosition();
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() {
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 (open || !hasActiveItemRecursively()) {
273
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
274
+ }
275
+ setMarkerIsMoving(false);
276
+ }, { once: true });
277
+ }
278
+ function readjustMarkerPosition() {
279
+ if (hasActiveItemRecursively()) {
280
+ if (open) {
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
  }); });
@@ -421,4 +397,4 @@ var DocMenu = function (_a) {
421
397
  module.exports = DocMenu;
422
398
  //# sourceMappingURL=index.umd.js.map
423
399
 
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"> */
400
+ /* <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] transition 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"> */