@cypress-design/react-docmenu 0.4.0 → 0.4.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/_DocLink.tsx CHANGED
@@ -10,59 +10,73 @@ export type LinkComponentType = React.ElementType<{
10
10
 
11
11
  export interface DocLinkProps {
12
12
  item: NavItemLink
13
+ active: boolean
13
14
  collapsible: boolean
14
15
  depth?: number
15
- onActive?: (top: number) => void
16
+ onActive?: (opts: { top: number; height: number }) => void
16
17
  LinkComponent?: LinkComponentType
17
18
  }
18
19
 
19
- export const DocLink: React.FC<DocLinkProps> = ({
20
- item,
21
- collapsible,
22
- depth = -1,
23
- onActive,
24
- LinkComponent = 'a',
25
- }) => {
26
- const activeLIRef = React.useRef<HTMLLIElement>(null)
20
+ export interface DocLinkForward {
21
+ setActiveMarkerPosition: () => void
22
+ }
23
+
24
+ export const DocLink = React.forwardRef<DocLinkForward, DocLinkProps>(
25
+ (
26
+ { item, active, collapsible, depth = -1, onActive, LinkComponent = 'a' },
27
+ ref,
28
+ ) => {
29
+ const activeLIRef = React.useRef<HTMLLIElement>(null)
30
+
31
+ // on mount, if the item is active,
32
+ // send the top position to the parent
33
+ React.useEffect(setActiveMarkerPosition, [onActive, active])
27
34
 
28
- // on mount, if the item is active,
29
- // send the top position to the parent
30
- React.useEffect(() => {
31
- if (item.active) {
32
- onActive?.(activeLIRef?.current?.offsetTop || 0)
35
+ function setActiveMarkerPosition() {
36
+ if (active) {
37
+ const box = activeLIRef?.current?.getBoundingClientRect()
38
+ onActive?.({
39
+ top: box?.top || 0,
40
+ height: box?.height || 0,
41
+ })
42
+ }
33
43
  }
34
- }, [onActive, item.active])
35
44
 
36
- return (
37
- <li
38
- ref={activeLIRef}
39
- className={clsx('list-none p-0', {
40
- 'pl-[16px]': depth >= 0,
41
- })}
42
- >
43
- <LinkComponent
44
- className={clsx('group relative inline-block pl-[24px]', {
45
- 'text-indigo-500': item.active,
46
- 'py-[8px] text-[16px] leading-[24px]': depth < 0,
47
- 'py-[12px] leading-[20px] text-[14px]': depth >= 0,
45
+ React.useImperativeHandle(ref, () => ({
46
+ setActiveMarkerPosition,
47
+ }))
48
+
49
+ return (
50
+ <li
51
+ ref={activeLIRef}
52
+ className={clsx('list-none p-0', {
53
+ 'pl-[16px]': depth >= 0,
48
54
  })}
49
- href={item.href}
50
55
  >
51
- {depth >= 0 ? (
52
- <div
53
- className={clsx(
54
- 'absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden',
55
- {
56
- 'group-hover:block bg-gray-300': !item.active && collapsible,
57
- },
58
- )}
59
- style={{
60
- left: `-${18.5 + depth * 8}px`,
61
- }}
62
- />
63
- ) : null}
64
- {item.label}
65
- </LinkComponent>
66
- </li>
67
- )
68
- }
56
+ <LinkComponent
57
+ className={clsx('group relative inline-block pl-[24px]', {
58
+ 'text-indigo-500': active,
59
+ 'py-[8px] text-[16px] leading-[24px]': depth < 0,
60
+ 'py-[12px] leading-[20px] text-[14px]': depth >= 0,
61
+ })}
62
+ href={item.href}
63
+ >
64
+ {depth >= 0 ? (
65
+ <div
66
+ className={clsx(
67
+ 'absolute w-[4px] z-10 top-[4px] bottom-[4px] rounded-full hidden',
68
+ {
69
+ 'group-hover:block bg-gray-300': !active && collapsible,
70
+ },
71
+ )}
72
+ style={{
73
+ left: `-${18.5 + depth * 8}px`,
74
+ }}
75
+ />
76
+ ) : null}
77
+ {item.label}
78
+ </LinkComponent>
79
+ </li>
80
+ )
81
+ },
82
+ )
package/dist/DocMenu.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { NavGroup, NavItemLink } from '@cypress-design/constants-docmenu';
3
- import { LinkComponentType } from './_DocLink';
3
+ import type { LinkComponentType } from './_DocLink';
4
4
  export type NavItem = NavGroup | NavItemLink;
5
5
  export interface DocMenuProps extends React.HTMLAttributes<HTMLUListElement> {
6
6
  items: NavItem[];
7
+ activePath?: string;
7
8
  collapsible?: boolean;
8
9
  LinkComponent?: LinkComponentType;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DocMenu.d.ts","sourceRoot":"./","sources":["DocMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,EAAW,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAIvD,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAA;AAE5C,MAAM,WAAW,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAC1E,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA6B1C,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"DocMenu.d.ts","sourceRoot":"./","sources":["DocMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGnD,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAA;AAE5C,MAAM,WAAW,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAC1E,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA+C1C,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,13 +1,39 @@
1
1
  import * as React from 'react';
2
- import { NavGroup } from '@cypress-design/constants-docmenu';
3
- import { LinkComponentType } from './_DocLink';
2
+ import { type NavGroup, type NavItemLink } from '@cypress-design/constants-docmenu';
3
+ import { type LinkComponentType } from './_DocLink';
4
4
  export interface DocGroupProps {
5
- index: number;
6
5
  group: NavGroup;
6
+ activePath: string;
7
7
  collapsible: boolean;
8
+ onActivePosition: (opts: {
9
+ top: number;
10
+ height: number;
11
+ }) => void;
12
+ updateMarkerPosition?: () => void;
8
13
  depth?: number;
9
- setHeight?: (height: number) => void;
10
14
  LinkComponent?: LinkComponentType;
15
+ hideMarker: () => void;
11
16
  }
12
- export declare const DocGroup: React.FC<DocGroupProps>;
17
+ export interface DocGroupForward {
18
+ reTriggerSetActiveGroup: () => void;
19
+ }
20
+ export declare const DocGroup: React.ForwardRefExoticComponent<DocGroupProps & React.RefAttributes<DocGroupForward>>;
21
+ export interface DocGroupElementsProps extends React.HTMLAttributes<HTMLUListElement> {
22
+ items: (NavGroup | NavItemLink)[];
23
+ activePath: string;
24
+ collapsible: boolean;
25
+ onActivePosition: (opts: {
26
+ top: number;
27
+ height: number;
28
+ }) => void;
29
+ updateMarkerPosition?: () => void;
30
+ depth: number;
31
+ LinkComponent: LinkComponentType;
32
+ hideMarker: () => void;
33
+ className: string | undefined;
34
+ }
35
+ export interface DocGroupElementsForward {
36
+ reTriggerSetActiveGroup: () => void;
37
+ }
38
+ export declare const DocGroupElements: React.ForwardRefExoticComponent<DocGroupElementsProps & React.RefAttributes<DocGroupElementsForward>>;
13
39
  //# sourceMappingURL=_DocGroup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_DocGroup.d.ts","sourceRoot":"./","sources":["_DocGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,QAAQ,EAAW,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAW,iBAAiB,EAAE,MA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EAAE,CAAA;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,OAAO,CAAA;IACpB,gBAAgB,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACjE,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,iBAAiB,CAAA;IAChC,UAAU,EAAE,MAAM,IAAI,CAAA;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,WAAW,uBAAuB;IACtC,uBAAuB,EAAE,MAAM,IAAI,CAAA;CACpC;AAED,eAAO,MAAM,gBAAgB,uGAkG5B,CAAA"}
@@ -7,10 +7,17 @@ export type LinkComponentType = React.ElementType<{
7
7
  }>;
8
8
  export interface DocLinkProps {
9
9
  item: NavItemLink;
10
+ active: boolean;
10
11
  collapsible: boolean;
11
12
  depth?: number;
12
- onActive?: (top: number) => void;
13
+ onActive?: (opts: {
14
+ top: number;
15
+ height: number;
16
+ }) => void;
13
17
  LinkComponent?: LinkComponentType;
14
18
  }
15
- export declare const DocLink: React.FC<DocLinkProps>;
19
+ export interface DocLinkForward {
20
+ setActiveMarkerPosition: () => void;
21
+ }
22
+ export declare const DocLink: React.ForwardRefExoticComponent<DocLinkProps & React.RefAttributes<DocLinkForward>>;
16
23
  //# sourceMappingURL=_DocLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_DocLink.d.ts","sourceRoot":"./","sources":["_DocLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAA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  return t;
44
44
  }
45
45
 
46
- function __spreadArray(to, from, pack) {
47
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
48
- if (ar || !(i in from)) {
49
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
50
- ar[i] = from[i];
51
- }
52
- }
53
- return to.concat(ar || Array.prototype.slice.call(from));
54
- }
55
-
56
46
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
57
47
  var e = new Error(message);
58
48
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
49
  };
60
50
 
61
- var DocLink = function (_a) {
62
- var item = _a.item, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? -1 : _b, onActive = _a.onActive, _c = _a.LinkComponent, LinkComponent = _c === void 0 ? 'a' : _c;
63
- var activeLIRef = React.useRef(null);
64
- // on mount, if the item is active,
65
- // send the top position to the parent
66
- React.useEffect(function () {
67
- var _a;
68
- if (item.active) {
69
- onActive === null || onActive === void 0 ? void 0 : onActive(((_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) || 0);
70
- }
71
- }, [onActive, item.active]);
72
- return (React.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
73
- 'pl-[16px]': depth >= 0,
74
- }) },
75
- React.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
76
- 'text-indigo-500': item.active,
77
- 'py-[8px] text-[16px] leading-[24px]': depth < 0,
78
- 'py-[12px] leading-[20px] text-[14px]': depth >= 0,
79
- }), href: item.href },
80
- depth >= 0 ? (React.createElement("div", { className: clsx('absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden', {
81
- 'group-hover:block bg-gray-300': !item.active && collapsible,
82
- }), style: {
83
- left: "-".concat(18.5 + depth * 8, "px"),
84
- } })) : null,
85
- item.label)));
86
- };
87
-
88
51
  /******************************************************************************
89
52
  Copyright (c) Microsoft Corporation.
90
53
 
@@ -191,51 +154,105 @@ var IconChevronDownSmall = function (props) { return React.createElement('svg',
191
154
  /* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
192
155
 
193
156
  const classes = {
194
- button: 'flex leading-[24px] py-[10px] items-center relative w-full',
157
+ button: 'flex leading-[24px] py-[10px] items-center relative w-full text-start',
195
158
  topButton: 'leading-[24px] text-[16px] pl-[24px] font-medium',
196
159
  leafButton: 'leading-[20px] text-[14px] pl-[40px]',
197
160
  };
198
161
 
199
- var DocGroup = function (_a) {
200
- var _b;
201
- var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight, index = _a.index, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d;
202
- var _e = React.useState(depth === 0), open = _e[0], setOpen = _e[1];
203
- var _f = React.useState(Array(group.items.length).fill(1)), itemsHeights = _f[0], setItemsHeights = _f[1];
204
- React.useEffect(function () {
205
- // if this group contains other groups, ignore this effect
206
- // it will be triggered by a leaf and trickle up
207
- if (group.items.some(function (item) { return 'items' in item; })) {
208
- return;
209
- }
210
- var newHeight = open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1;
211
- setHeight === null || setHeight === void 0 ? void 0 : setHeight(newHeight);
212
- }, [itemsHeights, open, setHeight, group.items, group.label]);
213
- var _g = React.useState(0), activeTop = _g[0], setActiveTop = _g[1];
214
- React.useEffect(function () {
215
- var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
216
- if (activeItem >= 0) {
217
- setActiveTop(itemsHeights.slice(0, activeItem).reduce(function (a, b) { return a + b; }, 1) * 44);
162
+ var DocLink = React.forwardRef(function (_a, ref) {
163
+ 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;
164
+ var activeLIRef = React.useRef(null);
165
+ // on mount, if the item is active,
166
+ // send the top position to the parent
167
+ React.useEffect(setActiveMarkerPosition, [onActive, active]);
168
+ function setActiveMarkerPosition() {
169
+ var _a;
170
+ if (active) {
171
+ var box = (_a = activeLIRef === null || activeLIRef === void 0 ? void 0 : activeLIRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
172
+ onActive === null || onActive === void 0 ? void 0 : onActive({
173
+ top: (box === null || box === void 0 ? void 0 : box.top) || 0,
174
+ height: (box === null || box === void 0 ? void 0 : box.height) || 0,
175
+ });
218
176
  }
219
- }, [itemsHeights, group.items]);
177
+ }
178
+ React.useImperativeHandle(ref, function () { return ({
179
+ setActiveMarkerPosition: setActiveMarkerPosition,
180
+ }); });
181
+ return (React.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
182
+ 'pl-[16px]': depth >= 0,
183
+ }) },
184
+ React.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
185
+ 'text-indigo-500': active,
186
+ 'py-[8px] text-[16px] leading-[24px]': depth < 0,
187
+ 'py-[12px] leading-[20px] text-[14px]': depth >= 0,
188
+ }), href: item.href },
189
+ depth >= 0 ? (React.createElement("div", { className: clsx('absolute w-[4px] z-10 top-[4px] bottom-[4px] rounded-full hidden', {
190
+ 'group-hover:block bg-gray-300': !active && collapsible,
191
+ }), style: {
192
+ left: "-".concat(18.5 + depth * 8, "px"),
193
+ } })) : null,
194
+ item.label)));
195
+ });
196
+
197
+ var DocGroup = React.forwardRef(function (_a, ref) {
198
+ var _b;
199
+ 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;
200
+ var _e = React.useState(group.collapsed !== true), open = _e[0], setOpen = _e[1];
201
+ var $groupElements = React.useRef(null);
220
202
  function toggleMenu(open) {
221
203
  if (!collapsible)
222
204
  return;
223
205
  setOpen(open);
224
206
  }
225
- var onSetHeightCallback = React.useCallback(function (height) {
226
- setItemsHeights(function (prev) {
227
- var newHeights = __spreadArray([], prev, true);
228
- newHeights[index] = height;
229
- return newHeights;
207
+ var hasActiveItemRecursively = React.useCallback(function (items) {
208
+ if (items === void 0) { items = group.items; }
209
+ return items.some(function (item) {
210
+ if ('items' in item) {
211
+ return hasActiveItemRecursively(item.items);
212
+ }
213
+ return item.href === activePath;
230
214
  });
231
- }, [setItemsHeights, index]);
215
+ }, [group.items, activePath]);
232
216
  var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
217
+ var setActivePosition = React.useCallback(function (_a) {
218
+ var top = _a.top, height = _a.height;
219
+ if (open) {
220
+ onActivePosition({ top: top, height: height });
221
+ }
222
+ }, [onActivePosition, open]);
223
+ function reTriggerSetActiveGroup() {
224
+ var _a;
225
+ (_a = $groupElements.current) === null || _a === void 0 ? void 0 : _a.reTriggerSetActiveGroup();
226
+ }
227
+ React.useEffect(function () {
228
+ if (hasActiveItemRecursively()) {
229
+ if (open) {
230
+ reTriggerSetActiveGroup();
231
+ }
232
+ else {
233
+ hideMarker();
234
+ }
235
+ }
236
+ else {
237
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
238
+ }
239
+ }, [open, updateMarkerPosition, hideMarker, hasActiveItemRecursively]);
240
+ React.useImperativeHandle(ref, function () { return ({
241
+ reTriggerSetActiveGroup: reTriggerSetActiveGroup,
242
+ }); });
243
+ var onUpdateMarkerPosition = React.useCallback(function () {
244
+ if (hasActiveItemRecursively()) {
245
+ reTriggerSetActiveGroup();
246
+ }
247
+ else {
248
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
249
+ }
250
+ }, [hasActiveItemRecursively, updateMarkerPosition]);
233
251
  return (React.createElement(React.Fragment, null,
234
- React.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
235
- 'text-indigo-500': group.active
236
- },
252
+ React.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {},
237
253
  _b[classes.topButton] = depth === 0,
238
254
  _b[classes.leafButton] = depth,
255
+ _b['text-indigo-500'] = activePath === group.href,
239
256
  _b)) },
240
257
  collapsible ? (React.createElement(IconChevronDownSmall, { "stroke-color": "gray-400", size: depth ? '8' : '16', className: clsx('absolute transform transition-transform left-0', {
241
258
  'rotate-0': open,
@@ -243,31 +260,75 @@ var DocGroup = function (_a) {
243
260
  'ml-[16px]': depth,
244
261
  }) })) : null,
245
262
  group.label),
246
- collapsible &&
247
- depth >= 0 &&
248
- open &&
249
- group.items.some(function (item) { return 'href' in item && item.active; }) ? (React.createElement("div", { className: "absolute h-[36px] w-[4px] z-10 rounded-full bg-indigo-500 transition-all duration-300 ml-[6px] mt-[4px]", style: {
250
- top: "".concat(activeTop, "px"),
251
- left: "".concat(depth === 0 ? 0.5 : -(depth * 8) - 0.5, "px"),
252
- } })) : null,
253
- React.createElement("ul", { className: clsx('ml-[8px] list-none p-0', {
254
- 'border-l border-gray-100': depth === 0 && collapsible,
255
- hidden: !open,
256
- }) }, group.items.map(function (item, index) {
257
- return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
258
- React.createElement(DocGroup, { group: item, depth: depth + 1, setHeight: onSetHeightCallback, index: index, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, depth: depth, onActive: function (top) { return setActiveTop(top); }, LinkComponent: LinkComponent }));
259
- }))));
260
- };
261
-
262
- var DocMenu = function (_a) {
263
- var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, _c = _a.LinkComponent, LinkComponent = _c === void 0 ? 'a' : _c, rest = __rest$1(_a, ["items", "collapsible", "LinkComponent"]);
264
- return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', rest.className) }), items.map(function (item, index) {
263
+ React.createElement(DocGroupElements, { ref: $groupElements, className: !open ? 'hidden' : undefined, items: group.items, activePath: activePath, collapsible: collapsible, depth: depth, onActivePosition: setActivePosition, updateMarkerPosition: onUpdateMarkerPosition, LinkComponent: LinkComponent, hideMarker: hideMarker })));
264
+ });
265
+ var DocGroupElements = React.forwardRef(function (_a, ref) {
266
+ var items = _a.items, activePath = _a.activePath, collapsible = _a.collapsible, _b = _a.depth, depth = _b === void 0 ? 0 : _b, onActivePosition = _a.onActivePosition, updateMarkerPosition = _a.updateMarkerPosition, LinkComponent = _a.LinkComponent, hideMarker = _a.hideMarker, className = _a.className, rest = __rest$1(_a, ["items", "activePath", "collapsible", "depth", "onActivePosition", "updateMarkerPosition", "LinkComponent", "hideMarker", "className"]);
267
+ var $groups = React.useRef([]);
268
+ var $items = React.useRef([]);
269
+ var hasActiveItemRecursively = React.useCallback(function (localItems) {
270
+ if (localItems === void 0) { localItems = items; }
271
+ return localItems.some(function (item) {
272
+ if ('items' in item) {
273
+ return hasActiveItemRecursively(item.items);
274
+ }
275
+ return item.href === activePath;
276
+ });
277
+ }, [items, activePath]);
278
+ function reTriggerSetActiveGroup() {
279
+ $groups.current.forEach(function (group) {
280
+ group === null || group === void 0 ? void 0 : group.reTriggerSetActiveGroup();
281
+ });
282
+ $items.current.forEach(function (item) {
283
+ item === null || item === void 0 ? void 0 : item.setActiveMarkerPosition();
284
+ });
285
+ }
286
+ React.useImperativeHandle(ref, function () { return ({
287
+ reTriggerSetActiveGroup: reTriggerSetActiveGroup,
288
+ }); });
289
+ var onUpdateMarkerPosition = React.useCallback(function () {
290
+ if (hasActiveItemRecursively()) {
291
+ reTriggerSetActiveGroup();
292
+ }
293
+ else {
294
+ updateMarkerPosition === null || updateMarkerPosition === void 0 ? void 0 : updateMarkerPosition();
295
+ }
296
+ }, [hasActiveItemRecursively, updateMarkerPosition]);
297
+ return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', className, {
298
+ 'border-l border-gray-100': depth === 0 && collapsible,
299
+ 'ml-[8px]': depth >= 0,
300
+ }) }), items.map(function (item, index) {
265
301
  return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
266
- React.createElement(DocGroup, { index: index, group: item, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, LinkComponent: LinkComponent }));
302
+ React.createElement(DocGroup, { ref: function (el) {
303
+ $groups.current[index] = el;
304
+ }, group: item, activePath: activePath, depth: depth + 1, collapsible: collapsible, LinkComponent: LinkComponent, hideMarker: hideMarker, onActivePosition: onActivePosition, updateMarkerPosition: onUpdateMarkerPosition }))) : (React.createElement(DocLink, { ref: function (el) {
305
+ $items.current[index] = el;
306
+ }, key: index, item: item, active: item.href === activePath, collapsible: collapsible, depth: depth, onActive: onActivePosition, LinkComponent: LinkComponent }));
267
307
  })));
308
+ });
309
+
310
+ var DocMenu = function (_a) {
311
+ var items = _a.items, _b = _a.activePath, activePath = _b === void 0 ? '<unknown>' : _b, _c = _a.collapsible, collapsible = _c === void 0 ? true : _c, _d = _a.LinkComponent, LinkComponent = _d === void 0 ? 'a' : _d, rest = __rest$1(_a, ["items", "activePath", "collapsible", "LinkComponent"]);
312
+ var _e = React.useState(0), activeTop = _e[0], setActiveTop = _e[1];
313
+ var _f = React.useState(36), activeHeight = _f[0], setActiveHeight = _f[1];
314
+ var _g = React.useState(false), showMarker = _g[0], setShowMarker = _g[1];
315
+ var container = React.useRef(null);
316
+ var setActivePosition = React.useCallback(function (opts) {
317
+ var _a;
318
+ var containerTop = ((_a = container.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().top) || 0;
319
+ setShowMarker(true);
320
+ setActiveTop(opts.top - containerTop);
321
+ setActiveHeight(opts.height);
322
+ }, []);
323
+ return (React.createElement("div", { ref: container, className: "relative" },
324
+ showMarker && collapsible ? (React.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: {
325
+ top: "".concat(activeTop + 4, "px"),
326
+ height: "".concat(activeHeight - 8, "px"),
327
+ } })) : null,
328
+ React.createElement(DocGroupElements, __assign$1({}, rest, { className: !open ? 'hidden' : undefined, items: items, activePath: activePath, collapsible: collapsible, depth: -1, onActivePosition: setActivePosition, LinkComponent: LinkComponent, hideMarker: function () { return setShowMarker(false); } }))));
268
329
  };
269
330
 
270
331
  export { DocMenu as default };
271
332
  //# sourceMappingURL=index.es.mjs.map
272
333
 
273
- /* <wind-keep class="list-none p-0 relative pl-[16px] inline-block pl-[24px] text-indigo-500 py-[8px] text-[16px] leading-[24px] py-[12px] leading-[20px] text-[14px] absolute w-[4px] z-10 top-[10%] h-[80%] rounded-full hidden group-hover:block bg-gray-300 transform transition-transform left-0 rotate-0 -rotate-90 ml-[16px] h-[36px] bg-indigo-500 transition-all duration-300 ml-[6px] mt-[4px] ml-[8px] border-l border-gray-100 flex py-[10px] items-center w-full font-medium pl-[40px]"> */
334
+ /* <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] hidden text-indigo-500 transform transition-transform left-0 rotate-0 -rotate-90 ml-[16px] list-none p-0 border-l border-gray-100 ml-[8px] pl-[16px] inline-block pl-[24px] py-[8px] text-[16px] leading-[24px] py-[12px] leading-[20px] text-[14px] z-10 top-[4px] bottom-[4px] group-hover:block bg-gray-300 flex py-[10px] items-center w-full text-start font-medium pl-[40px]"> */