@@ -5,27 +5,10 @@ import {
5
5
AccordionHeader ,
6
6
AccordionTrigger ,
7
7
AccordionContent ,
8
- Checkbox ,
9
8
} from '@qwik-ui/headless' ;
10
9
import { PreviewCodeExample } from '../../../../../components/preview-code-example/preview-code-example' ;
11
10
12
- export function SVG ( props : QwikIntrinsicElements [ 'svg' ] , key : string ) {
13
- return (
14
- < svg
15
- xmlns = "http://www.w3.org/2000/svg"
16
- width = "1em"
17
- height = "1em"
18
- viewBox = "0 0 1024 1024"
19
- { ...props }
20
- >
21
- < path
22
- fill = "currentColor"
23
- d = "M831.872 340.864L512 652.672L192.128 340.864a30.592 30.592 0 0 0-42.752 0a29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728a30.592 30.592 0 0 0-42.752 0z"
24
- > </ path >
25
- </ svg >
26
- ) ;
27
- }
28
-
11
+ // single
29
12
export const Example01 = component$ ( ( ) => {
30
13
return (
31
14
< PreviewCodeExample >
@@ -44,7 +27,7 @@ export const Example01 = component$(() => {
44
27
</ span >
45
28
</ AccordionTrigger >
46
29
</ AccordionHeader >
47
- < AccordionContent >
30
+ < AccordionContent class = "accordion-animation-1" >
48
31
< p class = "bg-violet-200 dark:bg-gray-900 p-4 " >
49
32
Yes, if you wrap a heading around the trigger, screen readers
50
33
will announce it properly.
@@ -60,7 +43,7 @@ export const Example01 = component$(() => {
60
43
</ span >
61
44
</ AccordionTrigger >
62
45
</ AccordionHeader >
63
- < AccordionContent >
46
+ < AccordionContent class = "accordion-animation-1" >
64
47
< p class = "bg-violet-200 dark:bg-gray-900 p-4" >
65
48
Yup! You can even use animations or CSS transitions from display
66
49
none, using the < strong > animated</ strong > prop on the accordion
@@ -77,7 +60,7 @@ export const Example01 = component$(() => {
77
60
</ span >
78
61
</ AccordionTrigger >
79
62
</ AccordionHeader >
80
- < AccordionContent >
63
+ < AccordionContent class = "accordion-animation-1" >
81
64
< p class = "bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]" >
82
65
You can do that by setting the < strong > behavior</ strong > prop to
83
66
"multi" on the Accordion
@@ -94,6 +77,7 @@ export const Example01 = component$(() => {
94
77
) ;
95
78
} ) ;
96
79
80
+ // multiple items
97
81
export const Example02 = component$ ( ( ) => {
98
82
return (
99
83
< PreviewCodeExample >
@@ -115,7 +99,7 @@ export const Example02 = component$(() => {
115
99
</ span >
116
100
</ AccordionTrigger >
117
101
</ AccordionHeader >
118
- < AccordionContent >
102
+ < AccordionContent class = "accordion-animation-1" >
119
103
< p class = "bg-violet-200 dark:bg-gray-900 p-4 " >
120
104
100%. The trigger has a < strong > [data-state]</ strong > selector
121
105
that can be styled when opened or closed.
@@ -133,7 +117,7 @@ export const Example02 = component$(() => {
133
117
</ span >
134
118
</ AccordionTrigger >
135
119
</ AccordionHeader >
136
- < AccordionContent >
120
+ < AccordionContent class = "accordion-animation-1" >
137
121
< p class = "bg-violet-200 dark:bg-gray-900 p-4" >
138
122
It's typed using < strong > QwikIntrinsicElements</ strong > , meaning
139
123
you can treat it like an element!
@@ -151,7 +135,7 @@ export const Example02 = component$(() => {
151
135
</ span >
152
136
</ AccordionTrigger >
153
137
</ h3 >
154
- < AccordionContent >
138
+ < AccordionContent class = "accordion-animation-1" >
155
139
< p class = "bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]" >
156
140
You can use onClick$, onKeyDown$, any handlers you'd normally
157
141
use with Qwik!
@@ -168,6 +152,7 @@ export const Example02 = component$(() => {
168
152
) ;
169
153
} ) ;
170
154
155
+ // non-collapsible
171
156
export const Example03 = component$ ( ( ) => {
172
157
return (
173
158
< PreviewCodeExample >
@@ -188,7 +173,7 @@ export const Example03 = component$(() => {
188
173
</ span >
189
174
</ AccordionTrigger >
190
175
</ AccordionHeader >
191
- < AccordionContent >
176
+ < AccordionContent class = "accordion-animation-1" >
192
177
< p class = "bg-violet-200 dark:bg-gray-900 p-4 " >
193
178
You can turn it off by setting the < strong > collapsible</ strong > { ' ' }
194
179
prop to false.
@@ -206,7 +191,7 @@ export const Example03 = component$(() => {
206
191
</ span >
207
192
</ AccordionTrigger >
208
193
</ AccordionHeader >
209
- < AccordionContent >
194
+ < AccordionContent class = "accordion-animation-1" >
210
195
< p class = "bg-violet-200 dark:bg-gray-900 p-4" >
211
196
It's typed using < strong > QwikIntrinsicElements</ strong > , meaning
212
197
you can treat it like an element!
@@ -224,7 +209,7 @@ export const Example03 = component$(() => {
224
209
</ span >
225
210
</ AccordionTrigger >
226
211
</ h3 >
227
- < AccordionContent >
212
+ < AccordionContent class = "accordion-animation-1" >
228
213
< p class = "bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]" >
229
214
You can use onClick$, onKeyDown$, any handlers you'd normally
230
215
use with Qwik!
@@ -240,3 +225,165 @@ export const Example03 = component$(() => {
240
225
</ PreviewCodeExample >
241
226
) ;
242
227
} ) ;
228
+
229
+ // disabled
230
+ export const Example04 = component$ ( ( ) => {
231
+ return (
232
+ < PreviewCodeExample >
233
+ < div class = "w-full flex justify-center" q :slot = "actualComponent" >
234
+ < AccordionRoot class = "bg-gray-100 dark:bg-gray-700 rounded-sm border-slate-200 dark:border-gray-600 border-[1px] box-border w-[min(400px,_100%)]" >
235
+ < AccordionItem >
236
+ < AccordionHeader as = "h3" >
237
+ < AccordionTrigger class = "px-4 py-2 w-full bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 dark:hover:bg-gray-800 text-left dark:border-gray-600 border-b-[1px] flex items-center justify-between group rounded-t-sm" >
238
+ < span > I'm enabled!</ span >
239
+ < span class = "pl-2" >
240
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
241
+ +
242
+ </ p >
243
+ </ span >
244
+ </ AccordionTrigger >
245
+ </ AccordionHeader >
246
+ < AccordionContent >
247
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4 " >
248
+ Hey, I'm enabled! This is because I don't use the{ ' ' }
249
+ < strong > disabled</ strong > prop on the trigger.
250
+ </ p >
251
+ </ AccordionContent >
252
+ </ AccordionItem >
253
+ < AccordionItem >
254
+ < AccordionHeader as = "h3" >
255
+ < AccordionTrigger class = "px-4 py-2 w-full bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 dark:hover:bg-gray-800 text-left dark:border-gray-600 border-b-[1px] flex items-center justify-between group" >
256
+ < span > I'm enabled!</ span >
257
+ < span class = "pl-2" >
258
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
259
+ +
260
+ </ p >
261
+ </ span >
262
+ </ AccordionTrigger >
263
+ </ AccordionHeader >
264
+ < AccordionContent >
265
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4" >
266
+ Hey, I'm enabled! This is because I don't use the{ ' ' }
267
+ < strong > disabled</ strong > prop on the trigger.
268
+ </ p >
269
+ </ AccordionContent >
270
+ </ AccordionItem >
271
+ < AccordionItem >
272
+ < h3 >
273
+ < AccordionTrigger
274
+ disabled
275
+ class = "bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 px-4 py-2 w-full dark:hover:bg-gray-800 text-left flex items-center justify-between group aria-expanded:rounded-none aria-disabled:cursor-not-allowed"
276
+ >
277
+ < span >
278
+ I'm{ ' ' }
279
+ < span class = "text-[#f87171] dark:text-[#dc2626] font-bold" >
280
+ disabled!
281
+ </ span >
282
+ </ span >
283
+ < span class = "pl-2 flex" >
284
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
285
+ +
286
+ </ p >
287
+ </ span >
288
+ </ AccordionTrigger >
289
+ </ h3 >
290
+ < AccordionContent >
291
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]" >
292
+ You shouldn't be able to see this!
293
+ </ p >
294
+ </ AccordionContent >
295
+ </ AccordionItem >
296
+ </ AccordionRoot >
297
+ </ div >
298
+
299
+ < div q :slot = "codeExample" >
300
+ < Slot />
301
+ </ div >
302
+ </ PreviewCodeExample >
303
+ ) ;
304
+ } ) ;
305
+
306
+ export const DefaultValueAccordion = component$ ( ( ) => {
307
+ return (
308
+ < PreviewCodeExample >
309
+ < div class = "w-full flex justify-center" q :slot = "actualComponent" >
310
+ < AccordionRoot class = "bg-gray-100 dark:bg-gray-700 rounded-sm border-slate-200 dark:border-gray-600 border-[1px] box-border w-[min(400px,_100%)]" >
311
+ < AccordionItem defaultValue >
312
+ < AccordionHeader as = "h3" >
313
+ < AccordionTrigger class = "px-4 py-2 w-full bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 dark:hover:bg-gray-800 text-left dark:border-gray-600 border-b-[1px] flex items-center justify-between group rounded-t-sm" >
314
+ < span > I'm open!</ span >
315
+ < span class = "pl-2" >
316
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
317
+ +
318
+ </ p >
319
+ </ span >
320
+ </ AccordionTrigger >
321
+ </ AccordionHeader >
322
+ < AccordionContent >
323
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4 " >
324
+ Hey, I'm enabled! This is because I don't use the{ ' ' }
325
+ < strong > disabled</ strong > prop on the trigger.
326
+ </ p >
327
+ </ AccordionContent >
328
+ </ AccordionItem >
329
+ < AccordionItem >
330
+ < AccordionHeader as = "h3" >
331
+ < AccordionTrigger class = "px-4 py-2 w-full bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 dark:hover:bg-gray-800 text-left dark:border-gray-600 border-b-[1px] flex items-center justify-between group" >
332
+ < span > Not open by default.</ span >
333
+ < span class = "pl-2" >
334
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
335
+ +
336
+ </ p >
337
+ </ span >
338
+ </ AccordionTrigger >
339
+ </ AccordionHeader >
340
+ < AccordionContent >
341
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4" >
342
+ Hey, I'm enabled! This is because I don't use the{ ' ' }
343
+ < strong > disabled</ strong > prop on the trigger.
344
+ </ p >
345
+ </ AccordionContent >
346
+ </ AccordionItem >
347
+ < AccordionItem >
348
+ < h3 >
349
+ < AccordionTrigger class = "bg-violet-50 hover:bg-violet-100 dark:bg-gray-700 px-4 py-2 w-full dark:hover:bg-gray-800 text-left flex items-center justify-between group aria-expanded:rounded-none" >
350
+ < span > Not open by default.</ span >
351
+ < span class = "pl-2 flex" >
352
+ < p class = "group-aria-expanded:transform group-aria-expanded:rotate-45 scale-150" >
353
+ +
354
+ </ p >
355
+ </ span >
356
+ </ AccordionTrigger >
357
+ </ h3 >
358
+ < AccordionContent >
359
+ < p class = "bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]" >
360
+ You shouldn't be able to see this!
361
+ </ p >
362
+ </ AccordionContent >
363
+ </ AccordionItem >
364
+ </ AccordionRoot >
365
+ </ div >
366
+
367
+ < div q :slot = "codeExample" >
368
+ < Slot />
369
+ </ div >
370
+ </ PreviewCodeExample >
371
+ ) ;
372
+ } ) ;
373
+
374
+ export function SVG ( props : QwikIntrinsicElements [ 'svg' ] , key : string ) {
375
+ return (
376
+ < svg
377
+ xmlns = "http://www.w3.org/2000/svg"
378
+ width = "1em"
379
+ height = "1em"
380
+ viewBox = "0 0 1024 1024"
381
+ { ...props }
382
+ >
383
+ < path
384
+ fill = "currentColor"
385
+ d = "M831.872 340.864L512 652.672L192.128 340.864a30.592 30.592 0 0 0-42.752 0a29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728a30.592 30.592 0 0 0-42.752 0z"
386
+ > </ path >
387
+ </ svg >
388
+ ) ;
389
+ }
0 commit comments