8
8
PageContextConsumer ,
9
9
capitalize ,
10
10
Flex ,
11
- FlexItem ,
11
+ FlexItem
12
12
} from '@patternfly/react-core' ;
13
13
import { css } from '@patternfly/react-styles' ;
14
14
import { Location } from '@reach/router' ;
@@ -24,8 +24,7 @@ const getIsActive = (location, section, subsection = null) => {
24
24
const defaultValue = 50 ;
25
25
26
26
const NavItem = ( { text, href, isDeprecated, isBeta, isDemo } ) => {
27
- const isMobileView =
28
- window . innerWidth < Number . parseInt ( globalBreakpointXl . value , 10 ) ;
27
+ const isMobileView = window . innerWidth < Number . parseInt ( globalBreakpointXl . value , 10 ) ;
29
28
return (
30
29
< PageContextConsumer key = { href + text } >
31
30
{ ( { onSidebarToggle, isSidebarOpen } ) => (
@@ -39,11 +38,7 @@ const NavItem = ({ text, href, isDeprecated, isBeta, isDemo }) => {
39
38
getProps = { ( { isCurrent, href, location } ) => {
40
39
const { pathname } = location ;
41
40
return {
42
- className : css (
43
- 'pf-v6-c-nav__link' ,
44
- ( isCurrent || pathname . startsWith ( href + '/' ) ) &&
45
- 'pf-m-current'
46
- ) ,
41
+ className : css ( 'pf-v6-c-nav__link' , ( isCurrent || pathname . startsWith ( href + '/' ) ) && 'pf-m-current' )
47
42
} ;
48
43
} }
49
44
tabIndex = { isSidebarOpen ? undefined : - 1 }
@@ -77,17 +72,10 @@ const NavItem = ({ text, href, isDeprecated, isBeta, isDemo }) => {
77
72
) ;
78
73
} ;
79
74
80
- const ExpandableNav = ( {
81
- groupedRoutes,
82
- location,
83
- section,
84
- subsection = null ,
85
- } ) => {
75
+ const ExpandableNav = ( { groupedRoutes, location, section, subsection = null } ) => {
86
76
const isActive = getIsActive ( location , section , subsection ) ;
87
77
const isSubsection = subsection ;
88
- const routes = isSubsection
89
- ? groupedRoutes [ section ] [ subsection ]
90
- : groupedRoutes [ section ] ;
78
+ const routes = isSubsection ? groupedRoutes [ section ] [ subsection ] : groupedRoutes [ section ] ;
91
79
const currentSection = isSubsection ? subsection : section ;
92
80
const analyticsName = isSubsection ? `${ section } /${ subsection } ` : section ;
93
81
@@ -102,92 +90,57 @@ const ExpandableNav = ({
102
90
event . stopPropagation ( ) ;
103
91
// Don't trigger for bubbled events from NavItems
104
92
if ( ! event . target . href ) {
105
- const isExpanded =
106
- event . currentTarget . classList . contains ( 'pf-m-expanded' ) ;
93
+ const isExpanded = event . currentTarget . classList . contains ( 'pf-m-expanded' ) ;
107
94
// 1 === expand section, 0 === collapse section
108
- trackEvent (
109
- 'sidenav_section_click' ,
110
- 'click_event' ,
111
- analyticsName ,
112
- isExpanded ? 0 : 1
113
- ) ;
95
+ trackEvent ( 'sidenav_section_click' , 'click_event' , analyticsName , isExpanded ? 0 : 1 ) ;
114
96
}
115
97
} }
116
98
>
117
99
{ Object . entries ( routes || { } )
118
- . filter (
119
- ( [ id , navObj ] ) =>
120
- ! Boolean ( navObj . hideNavItem ) && Object . entries ( navObj ) . length > 0
121
- )
100
+ . filter ( ( [ id , navObj ] ) => ! Boolean ( navObj . hideNavItem ) && Object . entries ( navObj ) . length > 0 )
122
101
. map (
123
102
( [
124
103
id ,
125
- {
126
- slug,
127
- isSubsection = false ,
128
- sortValue = defaultValue ,
129
- subsectionSortValue = defaultValue ,
130
- sources,
131
- } ,
104
+ { slug, isSubsection = false , sortValue = defaultValue , subsectionSortValue = defaultValue , sources }
132
105
] ) => ( {
133
106
text : id ,
134
107
href : slug ,
135
108
isSubsection,
136
109
sortValue : isSubsection ? subsectionSortValue : sortValue ,
137
- sources,
110
+ sources
138
111
} )
139
112
)
140
- . sort (
141
- (
142
- { text : text1 , sortValue : sortValue1 } ,
143
- { text : text2 , sortValue : sortValue2 }
144
- ) => {
145
- if ( sortValue1 === sortValue2 ) {
146
- return text1 . localeCompare ( text2 ) ;
147
- }
148
- return sortValue1 > sortValue2 ? 1 : - 1 ;
113
+ . sort ( ( { text : text1 , sortValue : sortValue1 } , { text : text2 , sortValue : sortValue2 } ) => {
114
+ if ( sortValue1 === sortValue2 ) {
115
+ return text1 . localeCompare ( text2 ) ;
149
116
}
150
- )
117
+ return sortValue1 > sortValue2 ? 1 : - 1 ;
118
+ } )
151
119
. map ( ( navObj ) => {
152
120
return navObj . isSubsection
153
121
? ExpandableNav ( {
154
122
groupedRoutes,
155
123
location,
156
124
section,
157
- subsection : navObj . text ,
125
+ subsection : navObj . text
158
126
} )
159
127
: NavItem ( {
160
128
...navObj ,
161
129
isDeprecated :
162
130
navObj . href ?. includes ( 'components' ) &&
163
131
navObj . sources . some (
164
132
( source ) =>
165
- ( source . source === 'react-deprecated' ||
166
- source . source === 'html-deprecated' ) &&
167
- // TODO: remove hardcoded Tile when Core PR merges
168
- // https://github.com/patternfly/patternfly/pull/7178
169
- ( source . id === 'Tile' ||
170
- ! navObj . sources . some (
171
- ( source ) =>
172
- source . source === 'react' ||
173
- source . source === 'html'
174
- ) )
133
+ ( source . source === 'react-deprecated' || source . source === 'html-deprecated' ) &&
134
+ ! navObj . sources . some ( ( source ) => source . source === 'react' || source . source === 'html' )
175
135
) ,
176
136
isBeta : navObj . sources . some (
177
- ( source ) =>
178
- source . beta &&
179
- source . source !== 'react-next' &&
180
- source . source !== 'react-templates'
137
+ ( source ) => source . beta && source . source !== 'react-next' && source . source !== 'react-templates'
181
138
) ,
182
139
isDemo : navObj . sources . some (
183
140
( source ) =>
184
- ( source . source === 'react-demos' ||
185
- source . source === 'html-demos' ) &&
186
- ! navObj . sources . some (
187
- ( source ) =>
188
- source . source === 'react' || source . source === 'html'
189
- )
190
- ) ,
141
+ ( source . source === 'react-demos' || source . source === 'html-demos' ) &&
142
+ ! navObj . sources . some ( ( source ) => source . source === 'react' || source . source === 'html' )
143
+ )
191
144
} ) ;
192
145
} ) }
193
146
</ NavExpandable >
@@ -203,8 +156,7 @@ export const SideNav = ({ groupedRoutes = {}, navItems = [] }) => {
203
156
if ( ! overflowElement ) {
204
157
return ;
205
158
}
206
- const activeElements =
207
- overflowElement . getElementsByClassName ( 'pf-m-current' ) ;
159
+ const activeElements = overflowElement . getElementsByClassName ( 'pf-m-current' ) ;
208
160
if ( activeElements . length > 0 ) {
209
161
const lastElement = activeElements [ activeElements . length - 1 ] ;
210
162
lastElement . scrollIntoView ( { block : 'center' } ) ;
@@ -216,16 +168,11 @@ export const SideNav = ({ groupedRoutes = {}, navItems = [] }) => {
216
168
< NavList className = "ws-side-nav-list" >
217
169
{ navItems . map ( ( { section, text, href } ) =>
218
170
section ? (
219
- < Location key = { section } >
220
- { ( { location } ) =>
221
- ExpandableNav ( { groupedRoutes, location, section } )
222
- }
223
- </ Location >
171
+ < Location key = { section } > { ( { location } ) => ExpandableNav ( { groupedRoutes, location, section } ) } </ Location >
224
172
) : (
225
173
NavItem ( {
226
- text :
227
- text || capitalize ( href . replace ( / \/ / g, '' ) . replace ( / - / g, ' ' ) ) ,
228
- href : href ,
174
+ text : text || capitalize ( href . replace ( / \/ / g, '' ) . replace ( / - / g, ' ' ) ) ,
175
+ href : href
229
176
} )
230
177
)
231
178
) }
0 commit comments