@@ -13,6 +13,19 @@ import {
1313 AccordionItemState ,
1414} from '../../src' ;
1515
16+ import Code from './components/Code' ;
17+
18+ // tslint:disable-next-line no-import-side-effect ordered-imports
19+ import {
20+ ExampleDefault ,
21+ ExampleAllowMultipleExpanded ,
22+ ExampleAllowZeroExpanded ,
23+ ExamplePreExpanded ,
24+ ExampleOnChange ,
25+ ExampleAccordionItemState ,
26+ ExampleDangerouslySetExpanded ,
27+ } from './code-examples' ;
28+
1629// tslint:disable-next-line no-import-side-effect
1730import './main.css' ;
1831
@@ -28,8 +41,8 @@ const App = (): JSX.Element => (
2841 React Component for creating an 'Accordion' that adheres to the{ ' ' }
2942 < a
3043 href = "https://www.w3.org/TR/wai-aria-practices-1.1/#accordion"
31- target = "_BLANK "
32- rel = "noreferrer, nofollow"
44+ target = "_blank "
45+ rel = "noreferrer nofollow"
3346 >
3447 WAI ARIA spec
3548 </ a > { ' ' }
@@ -56,6 +69,8 @@ const App = (): JSX.Element => (
5669 ) ) }
5770 </ Accordion >
5871
72+ < Code code = { ExampleDefault } />
73+
5974 < h2 className = "u-margin-top" > Expanding multiple items at once</ h2 >
6075
6176 < p >
@@ -77,6 +92,8 @@ const App = (): JSX.Element => (
7792 ) ) }
7893 </ Accordion >
7994
95+ < Code code = { ExampleAllowMultipleExpanded } />
96+
8097 < h2 className = "u-margin-top" > Collapsing the last expanded item</ h2 >
8198
8299 < p >
@@ -98,6 +115,8 @@ const App = (): JSX.Element => (
98115 ) ) }
99116 </ Accordion >
100117
118+ < Code code = { ExampleAllowZeroExpanded } />
119+
101120 < h2 className = "u-margin-top" > Pre-expanded items</ h2 >
102121
103122 < p >
@@ -114,8 +133,8 @@ const App = (): JSX.Element => (
114133 < Accordion preExpanded = { [ placeholders [ 0 ] . uuid ] } >
115134 { placeholders . map ( ( placeholder : Placeholder ) => (
116135 < AccordionItem
117- key = { placeholder . heading }
118- uuid = { placeholder . uuid }
136+ key = { placeholder . heading }
137+ uuid = { placeholder . uuid }
119138 >
120139 < AccordionItemHeading >
121140 < AccordionItemButton >
@@ -127,6 +146,8 @@ const App = (): JSX.Element => (
127146 ) ) }
128147 </ Accordion >
129148
149+ < Code code = { ExamplePreExpanded } />
150+
130151 < h2 className = "u-margin-top" > Informative onChange</ h2 >
131152
132153 < p >
@@ -149,8 +170,8 @@ const App = (): JSX.Element => (
149170 >
150171 { placeholders . map ( ( placeholder : Placeholder ) => (
151172 < AccordionItem
152- key = { placeholder . heading }
153- uuid = { placeholder . uuid }
173+ key = { placeholder . heading }
174+ uuid = { placeholder . uuid }
154175 >
155176 < AccordionItemHeading >
156177 < AccordionItemButton >
@@ -161,6 +182,8 @@ const App = (): JSX.Element => (
161182 </ AccordionItem >
162183 ) ) }
163184 </ Accordion >
185+
186+ < Code code = { ExampleOnChange } />
164187
165188 < h2 className = "u-margin-top" > Accessing Item State</ h2 >
166189
@@ -194,17 +217,17 @@ const App = (): JSX.Element => (
194217 ) ) }
195218 </ Accordion >
196219
220+ < Code code = { ExampleAccordionItemState } />
221+
197222 < h2 className = "u-margin-top" > Manual state</ h2 >
198223
199224 < p >
200- When you use the < strong > onChange </ strong > prop, you can get
201- feedback about which items are expanded.
225+ When you use the < strong > dangerouslySetExpanded </ strong > prop, you can
226+ manually override whether an < strong > AccordionItem </ strong > is expanded.
202227 </ p >
203228
204229 < p >
205- In this example, we are simply logging the uuids of the expanded
206- items to the console. Have a click around then check your console to
207- see this in action.
230+ < strong > Warning: This can impact accessibility negatively.</ strong >
208231 </ p >
209232
210233 < Accordion >
@@ -230,6 +253,8 @@ const App = (): JSX.Element => (
230253 ) ;
231254 } ) }
232255 </ Accordion >
256+
257+ < Code code = { ExampleDangerouslySetExpanded } />
233258 </ >
234259) ;
235260
0 commit comments