@cypress-design/react-docmenu 0.3.1 → 0.4.0

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.
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
2
2
  $ rollup -c ./rollup.config.mjs
3
3
  
4
4
  ./index.ts → ./dist/index.umd.js, ./dist/index.es.mjs...
5
- created ./dist/index.umd.js, ./dist/index.es.mjs in 33.9s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 11.9s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @cypress-design/react-docmenu
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#350](https://github.com/cypress-io/cypress-design/pull/350) [`abc414d`](https://github.com/cypress-io/cypress-design/commit/abc414da149eb6fe0cfa61497a0aa8630d8d8d6e) Thanks [@elevatebart](https://github.com/elevatebart)! - feat: allow usage of a custom link component
8
+
9
+ ### Patch Changes
10
+
11
+ - [#347](https://github.com/cypress-io/cypress-design/pull/347) [`de67952`](https://github.com/cypress-io/cypress-design/commit/de679522ea2269854ec8ac8de925fcf930ce96e4) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: docmenu docusaurus style items structure
12
+
13
+ - Updated dependencies [[`de67952`](https://github.com/cypress-io/cypress-design/commit/de679522ea2269854ec8ac8de925fcf930ce96e4)]:
14
+ - @cypress-design/constants-docmenu@0.1.1
15
+
3
16
  ## 0.3.1
4
17
 
5
18
  ### Patch Changes
package/DocMenu.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { NavGroup, NavItemLink } from '@cypress-design/constants-docmenu'
3
- import { DocLink } from './_DocLink'
3
+ import { DocLink, LinkComponentType } from './_DocLink'
4
4
  import { DocGroup } from './_DocGroup'
5
5
  import clsx from 'clsx'
6
6
 
@@ -9,11 +9,13 @@ export type NavItem = NavGroup | NavItemLink
9
9
  export interface DocMenuProps extends React.HTMLAttributes<HTMLUListElement> {
10
10
  items: NavItem[]
11
11
  collapsible?: boolean
12
+ LinkComponent?: LinkComponentType
12
13
  }
13
14
 
14
15
  export const DocMenu: React.FC<DocMenuProps> = ({
15
16
  items,
16
17
  collapsible = true,
18
+ LinkComponent = 'a',
17
19
  ...rest
18
20
  }) => {
19
21
  return (
@@ -21,11 +23,21 @@ export const DocMenu: React.FC<DocMenuProps> = ({
21
23
  {items.map((item, index) =>
22
24
  'items' in item ? (
23
25
  <li key={index} className="relative list-none p-0">
24
- <DocGroup group={item} collapsible={collapsible} />
26
+ <DocGroup
27
+ index={index}
28
+ group={item}
29
+ collapsible={collapsible}
30
+ LinkComponent={LinkComponent}
31
+ />
25
32
  </li>
26
33
  ) : (
27
- <DocLink key={index} item={item} collapsible={collapsible} />
28
- )
34
+ <DocLink
35
+ key={index}
36
+ item={item}
37
+ collapsible={collapsible}
38
+ LinkComponent={LinkComponent}
39
+ />
40
+ ),
29
41
  )}
30
42
  </ul>
31
43
  )
@@ -2,13 +2,58 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { mount } from 'cypress/react18'
5
- import DocMenuStory from './DocMenu.rootstory'
5
+ import DocMenu from './index'
6
6
  import assertions from '../assertions'
7
7
  import { NavGroup, NavItemLink } from '../constants'
8
8
 
9
9
  describe('<DocMenu/>', () => {
10
+ it('works with 1 level of items', () => {
11
+ mount(<DocMenu items={[{ href: '/foo', label: 'Foo' }]} />)
12
+ })
13
+
14
+ it('works with 2 level of items', () => {
15
+ mount(
16
+ <DocMenu
17
+ items={[{ label: 'Bar', items: [{ href: '/foo', label: 'Foo' }] }]}
18
+ />,
19
+ )
20
+ })
21
+
22
+ it('works with 3 level of items', () => {
23
+ mount(
24
+ <DocMenu
25
+ items={[
26
+ {
27
+ label: 'Baaaaaaz',
28
+ items: [{ label: 'Bar', items: [{ href: '/foo', label: 'Foo' }] }],
29
+ },
30
+ ]}
31
+ />,
32
+ )
33
+ })
34
+
35
+ it('renders the custom link components', () => {
36
+ mount(
37
+ <DocMenu
38
+ items={[
39
+ {
40
+ label: 'Baaaaaaz',
41
+ items: [{ label: 'Bar', items: [{ href: '/foo', label: 'Foo' }] }],
42
+ },
43
+ ]}
44
+ LinkComponent={({ href, className, children }) => (
45
+ <div className={className}>
46
+ {children} + href: {href}
47
+ </div>
48
+ )}
49
+ />,
50
+ )
51
+ cy.findByText('Bar').click()
52
+ cy.findByText('Foo + href: /foo', { selector: 'div' }).should('be.visible')
53
+ })
54
+
10
55
  function mountStory(items: (NavItemLink | NavGroup)[] = []) {
11
- mount(<DocMenuStory items={items} />)
56
+ mount(<DocMenu items={items} />)
12
57
  }
13
58
  assertions(mountStory)
14
59
  })
package/ReadMe.md CHANGED
@@ -18,62 +18,96 @@ yarn add @cypress-design/react-docmenu
18
18
  import DocMenu from '@cypress-design/react-docmenu'
19
19
  ```
20
20
 
21
+ ### Default usage
22
+
23
+ ```tsx live
24
+ export default () => (
25
+ <DocMenu
26
+ items={[
27
+ {
28
+ label: 'Get Started',
29
+ href: '#',
30
+ },
31
+ {
32
+ label: 'Overview',
33
+ items: [
34
+ {
35
+ label: 'Overview Item 1',
36
+ href: '#',
37
+ },
38
+ {
39
+ label: 'Overview Item 2',
40
+ href: '#',
41
+ active: true,
42
+ },
43
+ ],
44
+ },
45
+ {
46
+ label: 'Getting Started',
47
+ items: [
48
+ {
49
+ label: 'Item 1',
50
+ href: '#',
51
+ },
52
+ {
53
+ label: 'Group',
54
+ items: [
55
+ {
56
+ label: 'Item 1',
57
+ href: '#',
58
+ },
59
+ {
60
+ label: 'Item 2',
61
+ href: '#',
62
+ },
63
+ {
64
+ label: 'Item 3',
65
+ href: '#',
66
+ },
67
+ {
68
+ label: 'Item 4',
69
+ href: '#',
70
+ },
71
+ ],
72
+ },
73
+ {
74
+ label: 'Item 5',
75
+ href: '#',
76
+ active: true,
77
+ },
78
+ ],
79
+ },
80
+ ]}
81
+ />
82
+ )
83
+ ```
84
+
85
+ ### With a custom link
86
+
21
87
  ```tsx live
22
- <DocMenu
23
- items={[
24
- {
25
- text: 'Get Started',
26
- href: '#',
27
- },
28
- {
29
- text: 'Overview',
30
- items: [
31
- {
32
- text: 'Overview Item 1',
33
- href: '#',
34
- },
35
- {
36
- text: 'Overview Item 2',
37
- href: '#',
38
- active: true,
39
- },
40
- ],
41
- },
42
- {
43
- text: 'Getting Started',
44
- items: [
45
- {
46
- text: 'Item 1',
47
- href: '#',
48
- },
49
- {
50
- text: 'Group',
51
- items: [
52
- {
53
- text: 'Item 1',
54
- href: '#',
55
- },
56
- {
57
- text: 'Item 2',
58
- href: '#',
59
- },
60
- {
61
- text: 'Item 3',
62
- href: '#',
63
- },
64
- {
65
- text: 'Item 4',
66
- href: '#',
67
- },
68
- ],
69
- },
70
- {
71
- text: 'Item 5',
72
- href: '#',
73
- active: true,
74
- },
75
- ],
76
- },
77
- ]}
78
- />
88
+ const CustomLink = ({ href, children, className }) => {
89
+ return (
90
+ <a
91
+ href={href}
92
+ className={className}
93
+ onClick={(evt) => {
94
+ console.log('The link was clicked.', { target: evt.target })
95
+ }}
96
+ >
97
+ {children} 🔗
98
+ </a>
99
+ )
100
+ }
101
+
102
+ export default () => (
103
+ <DocMenu
104
+ LinkComponent={CustomLink}
105
+ items={[
106
+ {
107
+ label: 'Install',
108
+ href: '#with-a-custom-link',
109
+ },
110
+ ]}
111
+ />
112
+ )
79
113
  ```
package/_DocGroup.tsx CHANGED
@@ -2,13 +2,15 @@ import * as React from 'react'
2
2
  import { IconChevronDownSmall } from '@cypress-design/react-icon'
3
3
  import clsx from 'clsx'
4
4
  import { NavGroup, classes } from '@cypress-design/constants-docmenu'
5
- import { DocLink } from './_DocLink'
5
+ import { DocLink, LinkComponentType } from './_DocLink'
6
6
 
7
7
  export interface DocGroupProps {
8
+ index: number
8
9
  group: NavGroup
9
10
  collapsible: boolean
10
11
  depth?: number
11
12
  setHeight?: (height: number) => void
13
+ LinkComponent?: LinkComponentType
12
14
  }
13
15
 
14
16
  export const DocGroup: React.FC<DocGroupProps> = ({
@@ -16,6 +18,8 @@ export const DocGroup: React.FC<DocGroupProps> = ({
16
18
  collapsible,
17
19
  depth = 0,
18
20
  setHeight,
21
+ index,
22
+ LinkComponent = 'a',
19
23
  }) => {
20
24
  const [open, setOpen] = React.useState(depth === 0)
21
25
  const [itemsHeights, setItemsHeights] = React.useState<number[]>(
@@ -23,8 +27,16 @@ export const DocGroup: React.FC<DocGroupProps> = ({
23
27
  )
24
28
 
25
29
  React.useEffect(() => {
26
- setHeight?.(open ? itemsHeights.reduce((a, b) => a + b, 1) : 1)
27
- }, [itemsHeights, open, setHeight])
30
+ // if this group contains other groups, ignore this effect
31
+ // it will be triggered by a leaf and trickle up
32
+ if (group.items.some((item) => 'items' in item)) {
33
+ return
34
+ }
35
+
36
+ const newHeight = open ? itemsHeights.reduce((a, b) => a + b, 1) : 1
37
+
38
+ setHeight?.(newHeight)
39
+ }, [itemsHeights, open, setHeight, group.items, group.label])
28
40
 
29
41
  const [activeTop, setActiveTop] = React.useState(0)
30
42
 
@@ -44,13 +56,16 @@ export const DocGroup: React.FC<DocGroupProps> = ({
44
56
  setOpen(open)
45
57
  }
46
58
 
47
- function onSetHeight(index: number, height: number) {
48
- setItemsHeights((prev) => {
49
- const newHeights = [...prev]
50
- newHeights[index] = height
51
- return newHeights
52
- })
53
- }
59
+ const onSetHeightCallback = React.useCallback(
60
+ (height: number) => {
61
+ setItemsHeights((prev) => {
62
+ const newHeights = [...prev]
63
+ newHeights[index] = height
64
+ return newHeights
65
+ })
66
+ },
67
+ [setItemsHeights, index],
68
+ )
54
69
 
55
70
  const Head = collapsible ? 'button' : group.href ? 'a' : 'div'
56
71
 
@@ -76,7 +91,7 @@ export const DocGroup: React.FC<DocGroupProps> = ({
76
91
  })}
77
92
  />
78
93
  ) : null}
79
- {group.text}
94
+ {group.label}
80
95
  </Head>
81
96
  {collapsible &&
82
97
  depth >= 0 &&
@@ -102,8 +117,10 @@ export const DocGroup: React.FC<DocGroupProps> = ({
102
117
  <DocGroup
103
118
  group={item}
104
119
  depth={depth + 1}
105
- setHeight={(height) => onSetHeight(index, height)}
120
+ setHeight={onSetHeightCallback}
121
+ index={index}
106
122
  collapsible={collapsible}
123
+ LinkComponent={LinkComponent}
107
124
  />
108
125
  </li>
109
126
  ) : (
@@ -113,6 +130,7 @@ export const DocGroup: React.FC<DocGroupProps> = ({
113
130
  collapsible={collapsible}
114
131
  depth={depth}
115
132
  onActive={(top) => setActiveTop(top)}
133
+ LinkComponent={LinkComponent}
116
134
  />
117
135
  ),
118
136
  )}
package/_DocLink.tsx CHANGED
@@ -2,11 +2,18 @@ import * as React from 'react'
2
2
  import clsx from 'clsx'
3
3
  import { NavItemLink } from '@cypress-design/constants-docmenu'
4
4
 
5
+ export type LinkComponentType = React.ElementType<{
6
+ href: string
7
+ className?: string
8
+ children?: React.ReactNode
9
+ }>
10
+
5
11
  export interface DocLinkProps {
6
12
  item: NavItemLink
7
13
  collapsible: boolean
8
14
  depth?: number
9
15
  onActive?: (top: number) => void
16
+ LinkComponent?: LinkComponentType
10
17
  }
11
18
 
12
19
  export const DocLink: React.FC<DocLinkProps> = ({
@@ -14,6 +21,7 @@ export const DocLink: React.FC<DocLinkProps> = ({
14
21
  collapsible,
15
22
  depth = -1,
16
23
  onActive,
24
+ LinkComponent = 'a',
17
25
  }) => {
18
26
  const activeLIRef = React.useRef<HTMLLIElement>(null)
19
27
 
@@ -23,9 +31,7 @@ export const DocLink: React.FC<DocLinkProps> = ({
23
31
  if (item.active) {
24
32
  onActive?.(activeLIRef?.current?.offsetTop || 0)
25
33
  }
26
- // supposed to happen only on mount
27
- // eslint-disable-next-line react-hooks/exhaustive-deps
28
- }, [])
34
+ }, [onActive, item.active])
29
35
 
30
36
  return (
31
37
  <li
@@ -34,7 +40,7 @@ export const DocLink: React.FC<DocLinkProps> = ({
34
40
  'pl-[16px]': depth >= 0,
35
41
  })}
36
42
  >
37
- <a
43
+ <LinkComponent
38
44
  className={clsx('group relative inline-block pl-[24px]', {
39
45
  'text-indigo-500': item.active,
40
46
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
@@ -55,8 +61,8 @@ export const DocLink: React.FC<DocLinkProps> = ({
55
61
  }}
56
62
  />
57
63
  ) : null}
58
- {item.text}
59
- </a>
64
+ {item.label}
65
+ </LinkComponent>
60
66
  </li>
61
67
  )
62
68
  }
package/dist/DocMenu.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { NavGroup, NavItemLink } from '@cypress-design/constants-docmenu';
3
+ import { LinkComponentType } from './_DocLink';
3
4
  export type NavItem = NavGroup | NavItemLink;
4
5
  export interface DocMenuProps extends React.HTMLAttributes<HTMLUListElement> {
5
6
  items: NavItem[];
6
7
  collapsible?: boolean;
8
+ LinkComponent?: LinkComponentType;
7
9
  }
8
10
  export declare const DocMenu: React.FC<DocMenuProps>;
9
11
  export default DocMenu;
@@ -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;AAKzE,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;CACtB;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAkB1C,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,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,10 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import { NavGroup } from '@cypress-design/constants-docmenu';
3
+ import { LinkComponentType } from './_DocLink';
3
4
  export interface DocGroupProps {
5
+ index: number;
4
6
  group: NavGroup;
5
7
  collapsible: boolean;
6
8
  depth?: number;
7
9
  setHeight?: (height: number) => void;
10
+ LinkComponent?: LinkComponentType;
8
11
  }
9
12
  export declare const DocGroup: React.FC<DocGroupProps>;
10
13
  //# 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;AAGrE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,QAAQ,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA4G5C,CAAA"}
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,MAAM,YAAY,CAAA;AAEvD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,QAAQ,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA4H5C,CAAA"}
@@ -1,10 +1,16 @@
1
1
  import * as React from 'react';
2
2
  import { NavItemLink } from '@cypress-design/constants-docmenu';
3
+ export type LinkComponentType = React.ElementType<{
4
+ href: string;
5
+ className?: string;
6
+ children?: React.ReactNode;
7
+ }>;
3
8
  export interface DocLinkProps {
4
9
  item: NavItemLink;
5
10
  collapsible: boolean;
6
11
  depth?: number;
7
12
  onActive?: (top: number) => void;
13
+ LinkComponent?: LinkComponentType;
8
14
  }
9
15
  export declare const DocLink: React.FC<DocLinkProps>;
10
16
  //# 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,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACjC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAkD1C,CAAA"}
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,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAiD1C,CAAA"}
package/dist/index.es.mjs CHANGED
@@ -59,7 +59,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
59
59
  };
60
60
 
61
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;
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
63
  var activeLIRef = React.useRef(null);
64
64
  // on mount, if the item is active,
65
65
  // send the top position to the parent
@@ -68,13 +68,11 @@ var DocLink = function (_a) {
68
68
  if (item.active) {
69
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
70
  }
71
- // supposed to happen only on mount
72
- // eslint-disable-next-line react-hooks/exhaustive-deps
73
- }, []);
71
+ }, [onActive, item.active]);
74
72
  return (React.createElement("li", { ref: activeLIRef, className: clsx('list-none p-0', {
75
73
  'pl-[16px]': depth >= 0,
76
74
  }) },
77
- React.createElement("a", { className: clsx('group relative inline-block pl-[24px]', {
75
+ React.createElement(LinkComponent, { className: clsx('group relative inline-block pl-[24px]', {
78
76
  'text-indigo-500': item.active,
79
77
  'py-[8px] text-[16px] leading-[24px]': depth < 0,
80
78
  'py-[12px] leading-[20px] text-[14px]': depth >= 0,
@@ -84,7 +82,7 @@ var DocLink = function (_a) {
84
82
  }), style: {
85
83
  left: "-".concat(18.5 + depth * 8, "px"),
86
84
  } })) : null,
87
- item.text)));
85
+ item.label)));
88
86
  };
89
87
 
90
88
  /******************************************************************************
@@ -200,13 +198,19 @@ const classes = {
200
198
 
201
199
  var DocGroup = function (_a) {
202
200
  var _b;
203
- var group = _a.group, collapsible = _a.collapsible, _c = _a.depth, depth = _c === void 0 ? 0 : _c, setHeight = _a.setHeight;
204
- var _d = React.useState(depth === 0), open = _d[0], setOpen = _d[1];
205
- var _e = React.useState(Array(group.items.length).fill(1)), itemsHeights = _e[0], setItemsHeights = _e[1];
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];
206
204
  React.useEffect(function () {
207
- setHeight === null || setHeight === void 0 ? void 0 : setHeight(open ? itemsHeights.reduce(function (a, b) { return a + b; }, 1) : 1);
208
- }, [itemsHeights, open, setHeight]);
209
- var _f = React.useState(0), activeTop = _f[0], setActiveTop = _f[1];
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];
210
214
  React.useEffect(function () {
211
215
  var activeItem = group.items.findIndex(function (item) { return 'href' in item && item.active; });
212
216
  if (activeItem >= 0) {
@@ -218,13 +222,13 @@ var DocGroup = function (_a) {
218
222
  return;
219
223
  setOpen(open);
220
224
  }
221
- function onSetHeight(index, height) {
225
+ var onSetHeightCallback = React.useCallback(function (height) {
222
226
  setItemsHeights(function (prev) {
223
227
  var newHeights = __spreadArray([], prev, true);
224
228
  newHeights[index] = height;
225
229
  return newHeights;
226
230
  });
227
- }
231
+ }, [setItemsHeights, index]);
228
232
  var Head = collapsible ? 'button' : group.href ? 'a' : 'div';
229
233
  return (React.createElement(React.Fragment, null,
230
234
  React.createElement(Head, { onClick: function () { return toggleMenu(!open); }, href: group.href, className: clsx(classes.button, (_b = {
@@ -238,7 +242,7 @@ var DocGroup = function (_a) {
238
242
  '-rotate-90': !open,
239
243
  'ml-[16px]': depth,
240
244
  }) })) : null,
241
- group.text),
245
+ group.label),
242
246
  collapsible &&
243
247
  depth >= 0 &&
244
248
  open &&
@@ -251,15 +255,15 @@ var DocGroup = function (_a) {
251
255
  hidden: !open,
252
256
  }) }, group.items.map(function (item, index) {
253
257
  return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
254
- React.createElement(DocGroup, { group: item, depth: depth + 1, setHeight: function (height) { return onSetHeight(index, height); }, collapsible: collapsible }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, depth: depth, onActive: function (top) { return setActiveTop(top); } }));
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 }));
255
259
  }))));
256
260
  };
257
261
 
258
262
  var DocMenu = function (_a) {
259
- var items = _a.items, _b = _a.collapsible, collapsible = _b === void 0 ? true : _b, rest = __rest$1(_a, ["items", "collapsible"]);
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"]);
260
264
  return (React.createElement("ul", __assign$1({}, rest, { className: clsx('list-none p-0', rest.className) }), items.map(function (item, index) {
261
265
  return 'items' in item ? (React.createElement("li", { key: index, className: "relative list-none p-0" },
262
- React.createElement(DocGroup, { group: item, collapsible: collapsible }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible }));
266
+ React.createElement(DocGroup, { index: index, group: item, collapsible: collapsible, LinkComponent: LinkComponent }))) : (React.createElement(DocLink, { key: index, item: item, collapsible: collapsible, LinkComponent: LinkComponent }));
263
267
  })));
264
268
  };
265
269