@cypress-design/react-docmenu 0.5.1 → 0.5.3
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 +44 -27
- package/DocMenuReact.cy.tsx +5 -3
- package/_DocGroup.tsx +83 -87
- package/_DocLink.tsx +19 -14
- 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 +95 -78
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +95 -77
- 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/.turbo/turbo-build.log
CHANGED
|
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
|
|
|
2
2
|
$ rollup -c ./rollup.config.mjs
|
|
3
3
|
[36m
|
|
4
4
|
[1m./index.ts[22m → [1m./dist/index.umd.js, ./dist/index.es.mjs[22m...[39m
|
|
5
|
-
[32mcreated [1m./dist/index.umd.js, ./dist/index.es.mjs[22m in [1m12.
|
|
5
|
+
[32mcreated [1m./dist/index.umd.js, ./dist/index.es.mjs[22m in [1m12.9s[22m[39m
|
|
6
6
|
$ tsc --project ./tsconfig.build.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @cypress-design/react-docmenu
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`9f750c5`](https://github.com/cypress-io/cypress-design/commit/9f750c57722351c43d8dda136796a1ea98c203c8) Thanks [@elevatebart](https://github.com/elevatebart)! - adjust colors according to designs and refactor react side to use context
|
|
8
|
+
|
|
9
|
+
## 0.5.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`5927136`](https://github.com/cypress-io/cypress-design/commit/59271366a460cbdc411a6bec75feb663d3991029) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: make sure when dynamic marker reappear, it does not bounce up
|
|
14
|
+
|
|
3
15
|
## 0.5.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/DocMenu.tsx
CHANGED
|
@@ -2,7 +2,6 @@ import * as React from 'react'
|
|
|
2
2
|
import { NavGroup, NavItemLink } from '@cypress-design/constants-docmenu'
|
|
3
3
|
import type { LinkComponentType } from './_DocLink'
|
|
4
4
|
import { DocGroupElements } from './_DocGroup'
|
|
5
|
-
import { MarkerIsMovingContext } from './markerIsMoving'
|
|
6
5
|
|
|
7
6
|
export type NavItem = NavGroup | NavItemLink
|
|
8
7
|
|
|
@@ -23,7 +22,8 @@ export const DocMenu: React.FC<DocMenuProps> = ({
|
|
|
23
22
|
const [activeTop, setActiveTop] = React.useState(0)
|
|
24
23
|
const [activeHeight, setActiveHeight] = React.useState(36)
|
|
25
24
|
const [showMarker, setShowMarker] = React.useState(false)
|
|
26
|
-
const [markerIsMoving,
|
|
25
|
+
const [markerIsMoving, localSetMarkerIsMoving] = React.useState(false)
|
|
26
|
+
const [hasCSSTransition, setHasCSSTransition] = React.useState(true)
|
|
27
27
|
|
|
28
28
|
const container = React.useRef<HTMLDivElement>(null)
|
|
29
29
|
|
|
@@ -37,34 +37,51 @@ export const DocMenu: React.FC<DocMenuProps> = ({
|
|
|
37
37
|
[],
|
|
38
38
|
)
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const hideMarker = React.useCallback(() => setShowMarker(false), [])
|
|
41
|
+
const setMarkerIsMoving = React.useCallback(
|
|
42
|
+
(val: boolean) => {
|
|
43
|
+
localSetMarkerIsMoving(val)
|
|
44
|
+
if (!val) return
|
|
45
|
+
// make sure the animation does not fire "after"
|
|
46
|
+
// the marker has reappeared at its right place
|
|
47
|
+
setHasCSSTransition(false)
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
setHasCSSTransition(true)
|
|
50
|
+
}, 300)
|
|
51
|
+
},
|
|
52
|
+
[localSetMarkerIsMoving],
|
|
53
|
+
)
|
|
41
54
|
|
|
42
55
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
height
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
) : null}
|
|
56
|
-
<DocGroupElements
|
|
57
|
-
{...rest}
|
|
58
|
-
items={items}
|
|
59
|
-
activePath={activePath}
|
|
60
|
-
collapsible={collapsible}
|
|
61
|
-
depth={-1}
|
|
62
|
-
onActivePosition={setActivePosition}
|
|
63
|
-
LinkComponent={LinkComponent}
|
|
64
|
-
hideMarker={setShowMarkerFalse}
|
|
56
|
+
<div ref={container} className="relative">
|
|
57
|
+
{showMarker && !markerIsMoving && collapsible ? (
|
|
58
|
+
<div
|
|
59
|
+
data-cy="doc-menu-active-marker"
|
|
60
|
+
className="absolute h-[36px] w-[4px] z-50 rounded-full bg-indigo-500 dark:bg-indigo-400 ml-[6.5px] mt-[4px]"
|
|
61
|
+
style={{
|
|
62
|
+
top: `${activeTop}px`,
|
|
63
|
+
height: `${activeHeight - 8}px`,
|
|
64
|
+
transition: hasCSSTransition
|
|
65
|
+
? 'height .3s ease-in-out, top .3s ease-in-out'
|
|
66
|
+
: 'none',
|
|
67
|
+
}}
|
|
65
68
|
/>
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
) : null}
|
|
70
|
+
<DocGroupElements
|
|
71
|
+
{...rest}
|
|
72
|
+
items={items}
|
|
73
|
+
depth={-1}
|
|
74
|
+
markerIsMoving={markerIsMoving}
|
|
75
|
+
onActivePosition={setActivePosition}
|
|
76
|
+
LinkComponent={LinkComponent}
|
|
77
|
+
context={{
|
|
78
|
+
setMarkerIsMoving,
|
|
79
|
+
activePath,
|
|
80
|
+
collapsible,
|
|
81
|
+
hideMarker,
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
68
85
|
)
|
|
69
86
|
}
|
|
70
87
|
|
package/DocMenuReact.cy.tsx
CHANGED
|
@@ -39,13 +39,13 @@ describe('<DocMenu/>', () => {
|
|
|
39
39
|
|
|
40
40
|
it(
|
|
41
41
|
'wraps items correctly',
|
|
42
|
-
{ viewportHeight: 950, viewportWidth:
|
|
42
|
+
{ viewportHeight: 950, viewportWidth: 550 },
|
|
43
43
|
() => {
|
|
44
44
|
const Sut = () => {
|
|
45
45
|
const [activeHref, setActiveHref] = React.useState<string | undefined>()
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
|
-
<div className="w-[
|
|
48
|
+
<div className="w-[400px] mt-[60px] mx-[24px] absolute">
|
|
49
49
|
<DocMenu
|
|
50
50
|
activePath={activeHref}
|
|
51
51
|
LinkComponent={({ href, className, children, style }) => (
|
|
@@ -133,10 +133,12 @@ describe('<DocMenu/>', () => {
|
|
|
133
133
|
mount(<Sut />)
|
|
134
134
|
|
|
135
135
|
cy.findByText('Bar').click()
|
|
136
|
-
cy.findByText('Code').click()
|
|
136
|
+
cy.findByText('Code').click().click()
|
|
137
137
|
cy.findByText(
|
|
138
138
|
'lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos',
|
|
139
139
|
).click()
|
|
140
|
+
cy.findByText('Code').click()
|
|
141
|
+
cy.get('[data-cy=doc-menu-active-marker]').should('not.exist')
|
|
140
142
|
},
|
|
141
143
|
)
|
|
142
144
|
|
package/_DocGroup.tsx
CHANGED
|
@@ -8,63 +8,74 @@ import {
|
|
|
8
8
|
} from '@cypress-design/constants-docmenu'
|
|
9
9
|
import {
|
|
10
10
|
DocLink,
|
|
11
|
+
type Context,
|
|
11
12
|
type DocLinkForward,
|
|
12
13
|
type LinkComponentType,
|
|
13
14
|
} from './_DocLink'
|
|
14
|
-
import { MarkerIsMovingContext } from './markerIsMoving'
|
|
15
15
|
|
|
16
16
|
export interface DocGroupProps {
|
|
17
17
|
group: NavGroup
|
|
18
|
-
|
|
19
|
-
collapsible: boolean
|
|
18
|
+
context: Context
|
|
20
19
|
onActivePosition: (opts: { top: number; height: number }) => void
|
|
21
|
-
updateMarkerPosition
|
|
20
|
+
updateMarkerPosition: () => void
|
|
21
|
+
markerIsMoving: boolean
|
|
22
22
|
depth?: number
|
|
23
23
|
LinkComponent?: LinkComponentType
|
|
24
|
-
hideMarker: () => void
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export interface DocGroupForward {
|
|
28
27
|
reTriggerSetActiveGroup: () => void
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
const hasActiveItemRecursively = (
|
|
31
|
+
items: (NavGroup | NavItemLink)[],
|
|
32
|
+
localActivePath: string,
|
|
33
|
+
): boolean => {
|
|
34
|
+
return items.some((item) => {
|
|
35
|
+
if ('items' in item) {
|
|
36
|
+
return hasActiveItemRecursively(item.items, localActivePath)
|
|
37
|
+
}
|
|
38
|
+
return item.href === localActivePath
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
32
43
|
(
|
|
33
44
|
{
|
|
34
45
|
group,
|
|
35
|
-
activePath,
|
|
36
|
-
collapsible,
|
|
37
46
|
depth = 0,
|
|
38
47
|
onActivePosition,
|
|
48
|
+
markerIsMoving,
|
|
49
|
+
context,
|
|
39
50
|
updateMarkerPosition,
|
|
40
51
|
LinkComponent = 'a',
|
|
41
|
-
hideMarker,
|
|
42
52
|
},
|
|
43
53
|
ref,
|
|
44
54
|
) => {
|
|
45
|
-
const
|
|
55
|
+
const { setMarkerIsMoving, activePath, collapsible, hideMarker } = context
|
|
56
|
+
|
|
57
|
+
const hasActiveItemRecursivelyMemo = React.useMemo(() => {
|
|
58
|
+
return hasActiveItemRecursively(group.items, activePath)
|
|
59
|
+
}, [group.items, activePath])
|
|
60
|
+
|
|
61
|
+
const [open, setOpen] = React.useState(!group.collapsed)
|
|
62
|
+
const [markerIsMovingTimeout, setMarkerIsMovingTimeout] =
|
|
63
|
+
React.useState<NodeJS.Timeout>()
|
|
46
64
|
const $groupElements = React.useRef<DocGroupElementsForward>(null)
|
|
47
|
-
const $listWrapper = React.useRef<HTMLDivElement>(null)
|
|
48
65
|
|
|
49
|
-
|
|
50
|
-
if (!collapsible) return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
const toggleMenu = (localOpen: boolean) => {
|
|
67
|
+
if (!collapsible || markerIsMoving) return
|
|
68
|
+
setMarkerIsMoving(true)
|
|
69
|
+
// on browsers than do not support transitionend event
|
|
70
|
+
// we need to set a timeout to remove the markerIsMoving
|
|
71
|
+
const timeout = setTimeout(function () {
|
|
72
|
+
setMarkerIsMoving(false)
|
|
73
|
+
}, 350)
|
|
74
|
+
setMarkerIsMovingTimeout(timeout)
|
|
75
|
+
setOpen(localOpen)
|
|
76
|
+
readjustMarkerPosition(localOpen)
|
|
54
77
|
}
|
|
55
78
|
|
|
56
|
-
const hasActiveItemRecursively = React.useCallback(
|
|
57
|
-
(items = group.items): boolean => {
|
|
58
|
-
return items.some((item) => {
|
|
59
|
-
if ('items' in item) {
|
|
60
|
-
return hasActiveItemRecursively(item.items)
|
|
61
|
-
}
|
|
62
|
-
return item.href === activePath
|
|
63
|
-
})
|
|
64
|
-
},
|
|
65
|
-
[group.items, activePath],
|
|
66
|
-
)
|
|
67
|
-
|
|
68
79
|
const Head = collapsible ? 'button' : group.href ? 'a' : 'div'
|
|
69
80
|
|
|
70
81
|
const setActivePosition = React.useCallback(
|
|
@@ -76,8 +87,6 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
76
87
|
[onActivePosition, open],
|
|
77
88
|
)
|
|
78
89
|
|
|
79
|
-
const { setMarkerIsMoving } = React.useContext(MarkerIsMovingContext)
|
|
80
|
-
|
|
81
90
|
function reTriggerSetActiveGroupParent() {
|
|
82
91
|
$groupElements.current?.reTriggerSetActiveGroup()
|
|
83
92
|
}
|
|
@@ -87,35 +96,25 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
87
96
|
* We replace the absolute marker by one in the link. After the transition, the
|
|
88
97
|
* marker is replaced by the absolute one again.
|
|
89
98
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
$listWrapper.current?.addEventListener(
|
|
99
|
-
'transitionend',
|
|
100
|
-
() => {
|
|
101
|
-
if (open || !hasActiveItemRecursively()) {
|
|
102
|
-
updateMarkerPosition?.()
|
|
103
|
-
}
|
|
104
|
-
setMarkerIsMoving(false)
|
|
105
|
-
},
|
|
106
|
-
{ once: true },
|
|
107
|
-
)
|
|
99
|
+
const restoreActiveMarkerAfterTransition = () => {
|
|
100
|
+
if (!markerIsMovingTimeout) {
|
|
101
|
+
clearTimeout(markerIsMovingTimeout)
|
|
102
|
+
}
|
|
103
|
+
if (open || !hasActiveItemRecursivelyMemo) {
|
|
104
|
+
updateMarkerPosition()
|
|
105
|
+
}
|
|
106
|
+
setMarkerIsMoving(false)
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
function readjustMarkerPosition() {
|
|
111
|
-
if (
|
|
112
|
-
if (
|
|
109
|
+
function readjustMarkerPosition(localOpen: boolean) {
|
|
110
|
+
if (hasActiveItemRecursivelyMemo) {
|
|
111
|
+
if (localOpen) {
|
|
113
112
|
reTriggerSetActiveGroupParent()
|
|
114
113
|
} else {
|
|
115
114
|
hideMarker()
|
|
116
115
|
}
|
|
117
116
|
} else {
|
|
118
|
-
updateMarkerPosition
|
|
117
|
+
updateMarkerPosition()
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
@@ -124,12 +123,12 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
124
123
|
}))
|
|
125
124
|
|
|
126
125
|
const onUpdateMarkerPosition = React.useCallback(() => {
|
|
127
|
-
if (
|
|
126
|
+
if (hasActiveItemRecursivelyMemo) {
|
|
128
127
|
reTriggerSetActiveGroupParent()
|
|
129
128
|
} else {
|
|
130
129
|
updateMarkerPosition?.()
|
|
131
130
|
}
|
|
132
|
-
}, [
|
|
131
|
+
}, [hasActiveItemRecursivelyMemo, updateMarkerPosition])
|
|
133
132
|
|
|
134
133
|
return (
|
|
135
134
|
<>
|
|
@@ -139,7 +138,11 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
139
138
|
className={clsx(classes.button, {
|
|
140
139
|
[classes.topButton]: depth === 0,
|
|
141
140
|
[classes.leafButton]: depth,
|
|
142
|
-
'text-indigo-500': activePath === group.href,
|
|
141
|
+
'text-indigo-500 dark:text-indigo-400': activePath === group.href,
|
|
142
|
+
'text-gray-900 dark:text-gray-100':
|
|
143
|
+
hasActiveItemRecursivelyMemo && activePath !== group.href,
|
|
144
|
+
'text-gray-800 dark:text-gray-200':
|
|
145
|
+
!hasActiveItemRecursivelyMemo && activePath !== group.href,
|
|
143
146
|
})}
|
|
144
147
|
>
|
|
145
148
|
{collapsible ? (
|
|
@@ -156,11 +159,17 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
156
159
|
{group.label}
|
|
157
160
|
</Head>
|
|
158
161
|
<div
|
|
159
|
-
className={clsx(
|
|
160
|
-
'
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
className={clsx(
|
|
163
|
+
'relative',
|
|
164
|
+
collapsible
|
|
165
|
+
? {
|
|
166
|
+
'transition-all grid': true,
|
|
167
|
+
'grid-rows-[0fr]': !open,
|
|
168
|
+
'grid-rows-[1fr]': open,
|
|
169
|
+
}
|
|
170
|
+
: null,
|
|
171
|
+
)}
|
|
172
|
+
onTransitionEnd={restoreActiveMarkerAfterTransition}
|
|
164
173
|
>
|
|
165
174
|
{open && collapsible && depth === 0 ? (
|
|
166
175
|
<div className={classes.openListBorderLeft} />
|
|
@@ -169,13 +178,12 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
169
178
|
ref={$groupElements}
|
|
170
179
|
className="overflow-hidden"
|
|
171
180
|
items={group.items}
|
|
172
|
-
activePath={activePath}
|
|
173
|
-
collapsible={collapsible}
|
|
174
181
|
depth={depth}
|
|
182
|
+
context={context}
|
|
183
|
+
markerIsMoving={markerIsMoving}
|
|
175
184
|
onActivePosition={setActivePosition}
|
|
176
185
|
updateMarkerPosition={onUpdateMarkerPosition}
|
|
177
186
|
LinkComponent={LinkComponent}
|
|
178
|
-
hideMarker={hideMarker}
|
|
179
187
|
/>
|
|
180
188
|
</div>
|
|
181
189
|
</>
|
|
@@ -186,14 +194,13 @@ export const DocGroup = React.forwardRef<DocGroupForward, DocGroupProps>(
|
|
|
186
194
|
export interface DocGroupElementsProps
|
|
187
195
|
extends React.HTMLAttributes<HTMLUListElement> {
|
|
188
196
|
items: (NavGroup | NavItemLink)[]
|
|
189
|
-
activePath: string
|
|
190
|
-
collapsible: boolean
|
|
191
197
|
onActivePosition: (opts: { top: number; height: number }) => void
|
|
198
|
+
markerIsMoving: boolean
|
|
192
199
|
updateMarkerPosition?: () => void
|
|
193
200
|
depth: number
|
|
194
201
|
LinkComponent: LinkComponentType
|
|
195
|
-
hideMarker: () => void
|
|
196
202
|
className?: string
|
|
203
|
+
context: Context
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
export interface DocGroupElementsForward {
|
|
@@ -207,14 +214,13 @@ export const DocGroupElements = React.forwardRef<
|
|
|
207
214
|
(
|
|
208
215
|
{
|
|
209
216
|
items,
|
|
210
|
-
activePath,
|
|
211
|
-
collapsible,
|
|
212
217
|
depth = 0,
|
|
213
218
|
onActivePosition,
|
|
214
219
|
updateMarkerPosition,
|
|
220
|
+
markerIsMoving,
|
|
215
221
|
LinkComponent,
|
|
216
|
-
hideMarker,
|
|
217
222
|
className,
|
|
223
|
+
context,
|
|
218
224
|
...rest
|
|
219
225
|
},
|
|
220
226
|
ref,
|
|
@@ -222,24 +228,13 @@ export const DocGroupElements = React.forwardRef<
|
|
|
222
228
|
const $groups = React.useRef<DocGroupForward[]>([])
|
|
223
229
|
const $items = React.useRef<DocLinkForward[]>([])
|
|
224
230
|
|
|
225
|
-
const hasActiveItemRecursively = React.useCallback(
|
|
226
|
-
(localItems = items): boolean => {
|
|
227
|
-
return localItems.some((item) => {
|
|
228
|
-
if ('items' in item) {
|
|
229
|
-
return hasActiveItemRecursively(item.items)
|
|
230
|
-
}
|
|
231
|
-
return item.href === activePath
|
|
232
|
-
})
|
|
233
|
-
},
|
|
234
|
-
[items, activePath],
|
|
235
|
-
)
|
|
236
|
-
|
|
237
231
|
const reTriggerSetActiveGroup = React.useCallback(
|
|
238
232
|
(index: number = 0) => {
|
|
239
233
|
$items.current.forEach((item) => {
|
|
240
234
|
item?.setActiveMarkerPosition()
|
|
241
235
|
})
|
|
242
236
|
// calculate the index of the calling group in the list of groups
|
|
237
|
+
// "index" is the index of the calling group in the list of items (groups and links)
|
|
243
238
|
const indexGroup =
|
|
244
239
|
index -
|
|
245
240
|
// remove all the items that are not groups from the array and count them
|
|
@@ -259,15 +254,17 @@ export const DocGroupElements = React.forwardRef<
|
|
|
259
254
|
reTriggerSetActiveGroup,
|
|
260
255
|
}))
|
|
261
256
|
|
|
257
|
+
const { activePath, hideMarker } = context
|
|
258
|
+
|
|
262
259
|
const onUpdateMarkerPosition = React.useCallback(
|
|
263
260
|
(index: number) => {
|
|
264
|
-
if (hasActiveItemRecursively()) {
|
|
261
|
+
if (hasActiveItemRecursively(items, activePath)) {
|
|
265
262
|
reTriggerSetActiveGroup(index)
|
|
266
263
|
} else {
|
|
267
264
|
updateMarkerPosition?.()
|
|
268
265
|
}
|
|
269
266
|
},
|
|
270
|
-
[
|
|
267
|
+
[updateMarkerPosition, reTriggerSetActiveGroup, items, activePath],
|
|
271
268
|
)
|
|
272
269
|
|
|
273
270
|
return (
|
|
@@ -280,11 +277,10 @@ export const DocGroupElements = React.forwardRef<
|
|
|
280
277
|
$groups.current[index] = el
|
|
281
278
|
}}
|
|
282
279
|
group={item}
|
|
283
|
-
activePath={activePath}
|
|
284
280
|
depth={depth + 1}
|
|
285
|
-
collapsible={collapsible}
|
|
286
281
|
LinkComponent={LinkComponent}
|
|
287
|
-
|
|
282
|
+
markerIsMoving={markerIsMoving}
|
|
283
|
+
context={context}
|
|
288
284
|
onActivePosition={onActivePosition}
|
|
289
285
|
updateMarkerPosition={() => onUpdateMarkerPosition(index)}
|
|
290
286
|
/>
|
|
@@ -296,9 +292,9 @@ export const DocGroupElements = React.forwardRef<
|
|
|
296
292
|
}}
|
|
297
293
|
key={index}
|
|
298
294
|
item={item}
|
|
299
|
-
active={item.href === activePath}
|
|
300
|
-
collapsible={collapsible}
|
|
301
295
|
depth={depth}
|
|
296
|
+
markerIsMoving={markerIsMoving}
|
|
297
|
+
context={context}
|
|
302
298
|
onActive={(opts) =>
|
|
303
299
|
depth < 0 ? hideMarker() : onActivePosition(opts)
|
|
304
300
|
}
|
package/_DocLink.tsx
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import clsx from 'clsx'
|
|
3
3
|
import { NavItemLink } from '@cypress-design/constants-docmenu'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export interface Context {
|
|
6
|
+
setMarkerIsMoving: (markerIsMoving: boolean) => void
|
|
7
|
+
collapsible: boolean
|
|
8
|
+
activePath: string
|
|
9
|
+
hideMarker: () => void
|
|
10
|
+
}
|
|
5
11
|
|
|
6
12
|
export type LinkComponentType = React.ElementType<{
|
|
7
13
|
href: string
|
|
@@ -12,11 +18,11 @@ export type LinkComponentType = React.ElementType<{
|
|
|
12
18
|
|
|
13
19
|
export interface DocLinkProps {
|
|
14
20
|
item: NavItemLink
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
onActive
|
|
19
|
-
LinkComponent
|
|
21
|
+
depth: number
|
|
22
|
+
markerIsMoving: boolean
|
|
23
|
+
context: Context
|
|
24
|
+
onActive: (opts: { top: number; height: number }) => void
|
|
25
|
+
LinkComponent: LinkComponentType
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
export interface DocLinkForward {
|
|
@@ -24,19 +30,18 @@ export interface DocLinkForward {
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export const DocLink = React.forwardRef<DocLinkForward, DocLinkProps>(
|
|
27
|
-
(
|
|
28
|
-
{ item, active, collapsible, depth = -1, onActive, LinkComponent = 'a' },
|
|
29
|
-
ref,
|
|
30
|
-
) => {
|
|
33
|
+
({ item, depth, markerIsMoving, context, onActive, LinkComponent }, ref) => {
|
|
31
34
|
const activeLIRef = React.useRef<HTMLLIElement>(null)
|
|
32
35
|
|
|
33
|
-
const {
|
|
36
|
+
const { collapsible, activePath } = context
|
|
37
|
+
|
|
38
|
+
const active = item.href === activePath
|
|
34
39
|
|
|
35
40
|
const setActiveMarkerPosition = () => {
|
|
36
41
|
if (active) {
|
|
37
42
|
const box = activeLIRef?.current?.getBoundingClientRect()
|
|
38
43
|
|
|
39
|
-
onActive
|
|
44
|
+
onActive({
|
|
40
45
|
top: box?.top || 0,
|
|
41
46
|
height: box?.height || 0,
|
|
42
47
|
})
|
|
@@ -55,7 +60,7 @@ export const DocLink = React.forwardRef<DocLinkForward, DocLinkProps>(
|
|
|
55
60
|
<li ref={activeLIRef} className="list-none p-0">
|
|
56
61
|
<LinkComponent
|
|
57
62
|
className={clsx('group relative block w-full pl-[24px]', {
|
|
58
|
-
'text-indigo-500': active,
|
|
63
|
+
'text-indigo-500 dark:text-indigo-400': active,
|
|
59
64
|
'text-gray-700 dark:text-gray-500': !active,
|
|
60
65
|
'py-[8px] text-[16px] leading-[24px]': depth < 0,
|
|
61
66
|
'leading-[20px] text-[14px] py-[12px]': depth >= 0,
|
|
@@ -72,7 +77,7 @@ export const DocLink = React.forwardRef<DocLinkForward, DocLinkProps>(
|
|
|
72
77
|
{
|
|
73
78
|
hidden: !markerIsMoving || !active,
|
|
74
79
|
'group-hover:block bg-gray-300': !active && collapsible,
|
|
75
|
-
'bg-indigo-500': active && markerIsMoving,
|
|
80
|
+
'bg-indigo-500 dark:bg-indigo-400': active && markerIsMoving,
|
|
76
81
|
},
|
|
77
82
|
)}
|
|
78
83
|
/>
|
package/dist/DocMenu.d.ts.map
CHANGED
|
@@ -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,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,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,CAuE1C,CAAA;AAED,eAAe,OAAO,CAAA"}
|
package/dist/_DocGroup.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type NavGroup, type NavItemLink } from '@cypress-design/constants-docmenu';
|
|
3
|
-
import { type LinkComponentType } from './_DocLink';
|
|
3
|
+
import { type Context, type LinkComponentType } from './_DocLink';
|
|
4
4
|
export interface DocGroupProps {
|
|
5
5
|
group: NavGroup;
|
|
6
|
-
|
|
7
|
-
collapsible: boolean;
|
|
6
|
+
context: Context;
|
|
8
7
|
onActivePosition: (opts: {
|
|
9
8
|
top: number;
|
|
10
9
|
height: number;
|
|
11
10
|
}) => void;
|
|
12
|
-
updateMarkerPosition
|
|
11
|
+
updateMarkerPosition: () => void;
|
|
12
|
+
markerIsMoving: boolean;
|
|
13
13
|
depth?: number;
|
|
14
14
|
LinkComponent?: LinkComponentType;
|
|
15
|
-
hideMarker: () => void;
|
|
16
15
|
}
|
|
17
16
|
export interface DocGroupForward {
|
|
18
17
|
reTriggerSetActiveGroup: () => void;
|
|
@@ -20,17 +19,16 @@ export interface DocGroupForward {
|
|
|
20
19
|
export declare const DocGroup: React.ForwardRefExoticComponent<DocGroupProps & React.RefAttributes<DocGroupForward>>;
|
|
21
20
|
export interface DocGroupElementsProps extends React.HTMLAttributes<HTMLUListElement> {
|
|
22
21
|
items: (NavGroup | NavItemLink)[];
|
|
23
|
-
activePath: string;
|
|
24
|
-
collapsible: boolean;
|
|
25
22
|
onActivePosition: (opts: {
|
|
26
23
|
top: number;
|
|
27
24
|
height: number;
|
|
28
25
|
}) => void;
|
|
26
|
+
markerIsMoving: boolean;
|
|
29
27
|
updateMarkerPosition?: () => void;
|
|
30
28
|
depth: number;
|
|
31
29
|
LinkComponent: LinkComponentType;
|
|
32
|
-
hideMarker: () => void;
|
|
33
30
|
className?: string;
|
|
31
|
+
context: Context;
|
|
34
32
|
}
|
|
35
33
|
export interface DocGroupElementsForward {
|
|
36
34
|
reTriggerSetActiveGroup: (index?: number) => void;
|
package/dist/_DocGroup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_DocGroup.d.ts","sourceRoot":"./","sources":["_DocGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,WAAW,EAEjB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"_DocGroup.d.ts","sourceRoot":"./","sources":["_DocGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,WAAW,EAEjB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAEL,KAAK,OAAO,EAEZ,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,QAAQ,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,gBAAgB,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACjE,oBAAoB,EAAE,MAAM,IAAI,CAAA;IAChC,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,uBAAuB,EAAE,MAAM,IAAI,CAAA;CACpC;AAcD,eAAO,MAAM,QAAQ,uFAsJpB,CAAA;AAED,MAAM,WAAW,qBACf,SAAQ,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAC9C,KAAK,EAAE,CAAC,QAAQ,GAAG,WAAW,CAAC,EAAE,CAAA;IACjC,gBAAgB,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACjE,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAA;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,iBAAiB,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,uBAAuB,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAClD;AAED,eAAO,MAAM,gBAAgB,uGAkG5B,CAAA"}
|
package/dist/_DocLink.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { NavItemLink } from '@cypress-design/constants-docmenu';
|
|
3
|
+
export interface Context {
|
|
4
|
+
setMarkerIsMoving: (markerIsMoving: boolean) => void;
|
|
5
|
+
collapsible: boolean;
|
|
6
|
+
activePath: string;
|
|
7
|
+
hideMarker: () => void;
|
|
8
|
+
}
|
|
3
9
|
export type LinkComponentType = React.ElementType<{
|
|
4
10
|
href: string;
|
|
5
11
|
className: string;
|
|
@@ -8,14 +14,14 @@ export type LinkComponentType = React.ElementType<{
|
|
|
8
14
|
}>;
|
|
9
15
|
export interface DocLinkProps {
|
|
10
16
|
item: NavItemLink;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onActive
|
|
17
|
+
depth: number;
|
|
18
|
+
markerIsMoving: boolean;
|
|
19
|
+
context: Context;
|
|
20
|
+
onActive: (opts: {
|
|
15
21
|
top: number;
|
|
16
22
|
height: number;
|
|
17
23
|
}) => void;
|
|
18
|
-
LinkComponent
|
|
24
|
+
LinkComponent: LinkComponentType;
|
|
19
25
|
}
|
|
20
26
|
export interface DocLinkForward {
|
|
21
27
|
setActiveMarkerPosition: () => void;
|
package/dist/_DocLink.d.ts.map
CHANGED
|
@@ -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;
|
|
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,OAAO;IACtB,iBAAiB,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAA;IACpD,WAAW,EAAE,OAAO,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB;AAED,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAC,aAAa,CAAA;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAC,CAAA;AAEF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,OAAO,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACzD,aAAa,EAAE,iBAAiB,CAAA;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,uBAAuB,EAAE,MAAM,IAAI,CAAA;CACpC;AAED,eAAO,MAAM,OAAO,qFA0DnB,CAAA"}
|