@@ -21,134 +21,7 @@ JumpLinks has a scrollspy built-in to make your implementation easier. When impl
2121
2222This demo expands on the previous to show the JumpLinks in a vertical layout with subsections. It scrolls the [ Page] ( /components/page ) 's ` mainContainerId ` with an ` offset ` calculated based on the height of the masthead and the nav list when it appears above the content. The headings are given a tab index to allow the jump links to focus on them.
2323
24- ``` js isFullscreen
25- import { useEffect , useState } from ' react' ;
26- import {
27- PageSection ,
28- JumpLinks ,
29- JumpLinksItem ,
30- JumpLinksList ,
31- PageGroup ,
32- Sidebar ,
33- SidebarContent ,
34- SidebarPanel ,
35- Switch ,
36- Title ,
37- Content ,
38- getResizeObserver
39- } from ' @patternfly/react-core' ;
40- import { DashboardWrapper } from ' @patternfly/react-core/dist/js/demos/DashboardWrapper' ;
41- import mastheadStyles from ' @patternfly/react-styles/css/components/Masthead/masthead' ;
42-
43- ScrollspyH2 = () => {
44- const headings = [1 , 2 , 3 , 4 , 5 ];
45-
46- const [isVertical , setIsVertical ] = useState (true );
47- const [offsetHeight , setOffsetHeight ] = useState (10 );
48- const offsetForPadding = 10 ;
49- let masthead;
50-
51- // Update offset based on the masthead and jump links nav heights.
52- useEffect (() => {
53- masthead = document .getElementsByClassName (mastheadStyles .masthead )[0 ];
54-
55- if (isVertical) {
56- setOffsetHeight (masthead .offsetHeight + offsetForPadding);
57- } else {
58- // Append jump links nav height to the masthead height when value exists.
59- const jumpLinksHeaderHeight = document .getElementsByClassName (' pf-m-sticky' )[0 ].offsetHeight ;
60- jumpLinksHeaderHeight && setOffsetHeight (masthead .offsetHeight + jumpLinksHeaderHeight + offsetForPadding);
61- }
62-
63-
64- }, [isVertical]);
65-
66- getResizeObserver (
67- document .getElementsByClassName (mastheadStyles .masthead )[0 ],
68- () => {
69- if (isVertical) {
70- setOffsetHeight (masthead .offsetHeight + offsetForPadding);
71- } else {
72- // Append jump links nav height to the masthead height when value exists.
73- const jumpLinksHeaderHeight = document .getElementsByClassName (' pf-m-sticky' )[0 ].offsetHeight ;
74- jumpLinksHeaderHeight && setOffsetHeight (masthead .offsetHeight + jumpLinksHeaderHeight + offsetForPadding);
75- }
76- },
77- true
78- );
79-
80- return (
81- < DashboardWrapper breadcrumb= {null } mainContainerId= " scrollable-element" >
82- < PageSection aria- labelledby= ' main-title' >
83- < Title headingLevel= " h1" size= " 2xl" id= ' main-title' >
84- Main title
85- < / Title>
86- < Switch
87- id= " is-vertical"
88- label= " Vertical jump links"
89- isChecked= {isVertical}
90- onChange= {(_event , check ) => setIsVertical (check)}
91- / >
92- < / PageSection>
93- < PageSection padding= {{ default: ' noPadding' }} >
94- < Sidebar hasGutter orientation= {! isVertical && ' stack' }>
95- < SidebarPanel variant= " sticky" >
96- < PageSection aria- label= ' Jump links navigation' >
97- < JumpLinks
98- isVertical= {isVertical}
99- isCentered= {! isVertical}
100- label= " Jump to section"
101- scrollableSelector= " .pf-v6-c-page__main-container"
102- offset= {offsetHeight}
103- expandable= {{ default: isVertical ? ' expandable' : ' nonExpandable' , md: ' nonExpandable' }}
104- isExpanded
105- >
106- {headings .map (i => (
107- < JumpLinksItem key= {i} href= {` #heading-${ i} ` }>
108- {` Heading ${ i} ` }
109- < JumpLinksList>< / JumpLinksList>
110- < / JumpLinksItem>
111- ))}
112- < / JumpLinks>
113- < / PageSection>
114- < / SidebarPanel>
115- < SidebarContent hasNoBackground>
116- < PageSection aria- label= ' Main content' >
117- < Content>
118- {headings .map (i => (
119- < div key= {i} style= {{ maxWidth: ' 800px' , marginBottom: ' 32px' }}>
120- < h2 id= {` heading-${ i} ` } tabIndex= {- 1 }>
121- {` Heading ${ i} ` }
122- < / h2>
123- < p>
124- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
125- labore et dolore magna aliqua . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
126- nisi ut aliquip ex ea commodo consequat . Duis aute irure dolor in reprehenderit in voluptate velit
127- esse cillum dolore eu fugiat nulla pariatur . Excepteur sint occaecat cupidatat non proident, sunt
128- in culpa qui officia deserunt mollit anim id est laborum.
129- < / p>
130- < br / >
131- < p>
132- At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum
133- deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non
134- provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum
135- fuga . Et harum quidem rerum facilis est et expedita distinctio . Nam libero tempore, cum soluta
136- nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus,
137- omnis voluptas assumenda est, omnis dolor repellendus . Temporibus autem quibusdam et aut officiis
138- debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non
139- recusandae . Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus
140- maiores alias consequatur aut perferendis doloribus asperiores repellat.
141- < / p>
142- < / div>
143- ))}
144- < / Content>
145- < / PageSection>
146- < / SidebarContent>
147- < / Sidebar>
148- < / PageSection>
149- < / DashboardWrapper>
150- );
151- };
24+ ``` ts file="examples/JumpLinks/JumpLinksScrollspy.tsx" isFullscreen
15225```
15326
15427### With drawer
@@ -157,5 +30,5 @@ This demo shows how jump links can be used in combination with a drawer.
15730
15831This demo uses a ` scrollableRef ` prop on the JumpLinks component, which is a React ref to the ` DrawerContent ` component.
15932
160- ``` js isFullscreen file="./ examples/JumpLinks/JumpLinksWithDrawer.js"
33+ ``` ts file="examples/JumpLinks/JumpLinksWithDrawer.tsx" isFullscreen
16134```
0 commit comments