Skip to content

Commit a6a213b

Browse files
feat(accordion & website): accordion examples, feats, critical fix, website font build fix
1 parent fe901bb commit a6a213b

File tree

14 files changed

+490
-133
lines changed

14 files changed

+490
-133
lines changed

apps/website/src/global.css

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,6 @@
22
@tailwind base;
33
@tailwind utilities;
44

5-
@font-face {
6-
font-family: 'Poppins';
7-
font-style: normal;
8-
font-weight: 400;
9-
font-display: swap;
10-
src: url('/fonts/poppins-400.woff2') format('woff2');
11-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
12-
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
13-
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
14-
}
15-
16-
@font-face {
17-
font-family: 'Poppins';
18-
font-style: normal;
19-
font-weight: 500;
20-
font-display: swap;
21-
src: url('/fonts/poppins-500.woff2') format('woff2');
22-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
23-
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
24-
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
25-
}
26-
27-
@font-face {
28-
font-family: 'Poppins';
29-
font-style: normal;
30-
font-weight: 700;
31-
font-display: swap;
32-
src: url('/fonts/poppins-700.woff2') format('woff2');
33-
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
34-
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
35-
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
36-
}
37-
385
:root {
396
--qwik-dark-blue: #006ce9;
407
--qwik-light-blue: #18b6f6;
@@ -111,3 +78,18 @@ body {
11178
grid-template-columns: 25% 70%;
11279
grid-template-areas: 'sidebar content';
11380
}
81+
82+
/* Utilities layer for animations. The current arbitrary & docs tailwind animation guidelines are not maintainable long term.
83+
It would make more sense to supply the user with the animation declaration in the docs.
84+
*/
85+
@layer utilities {
86+
.accordion-animation-1[data-state='open'] {
87+
animation: 500ms cubic-bezier(0.87, 0, 0.13, 1) 0s 1 normal forwards
88+
accordion-open;
89+
}
90+
91+
.accordion-animation-1[data-state='closed'] {
92+
animation: 500ms cubic-bezier(0.87, 0, 0.13, 1) 0s 1 normal forwards
93+
accordion-close;
94+
}
95+
}

apps/website/src/routes/docs/headless/(components)/accordion/examples.tsx

Lines changed: 174 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ import {
55
AccordionHeader,
66
AccordionTrigger,
77
AccordionContent,
8-
Checkbox,
98
} from '@qwik-ui/headless';
109
import { PreviewCodeExample } from '../../../../../components/preview-code-example/preview-code-example';
1110

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
2912
export const Example01 = component$(() => {
3013
return (
3114
<PreviewCodeExample>
@@ -44,7 +27,7 @@ export const Example01 = component$(() => {
4427
</span>
4528
</AccordionTrigger>
4629
</AccordionHeader>
47-
<AccordionContent>
30+
<AccordionContent class="accordion-animation-1">
4831
<p class="bg-violet-200 dark:bg-gray-900 p-4 ">
4932
Yes, if you wrap a heading around the trigger, screen readers
5033
will announce it properly.
@@ -60,7 +43,7 @@ export const Example01 = component$(() => {
6043
</span>
6144
</AccordionTrigger>
6245
</AccordionHeader>
63-
<AccordionContent>
46+
<AccordionContent class="accordion-animation-1">
6447
<p class="bg-violet-200 dark:bg-gray-900 p-4">
6548
Yup! You can even use animations or CSS transitions from display
6649
none, using the <strong>animated</strong> prop on the accordion
@@ -77,7 +60,7 @@ export const Example01 = component$(() => {
7760
</span>
7861
</AccordionTrigger>
7962
</AccordionHeader>
80-
<AccordionContent>
63+
<AccordionContent class="accordion-animation-1">
8164
<p class="bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]">
8265
You can do that by setting the <strong>behavior</strong> prop to
8366
"multi" on the Accordion
@@ -94,6 +77,7 @@ export const Example01 = component$(() => {
9477
);
9578
});
9679

80+
// multiple items
9781
export const Example02 = component$(() => {
9882
return (
9983
<PreviewCodeExample>
@@ -115,7 +99,7 @@ export const Example02 = component$(() => {
11599
</span>
116100
</AccordionTrigger>
117101
</AccordionHeader>
118-
<AccordionContent>
102+
<AccordionContent class="accordion-animation-1">
119103
<p class="bg-violet-200 dark:bg-gray-900 p-4 ">
120104
100%. The trigger has a <strong>[data-state]</strong> selector
121105
that can be styled when opened or closed.
@@ -133,7 +117,7 @@ export const Example02 = component$(() => {
133117
</span>
134118
</AccordionTrigger>
135119
</AccordionHeader>
136-
<AccordionContent>
120+
<AccordionContent class="accordion-animation-1">
137121
<p class="bg-violet-200 dark:bg-gray-900 p-4">
138122
It's typed using <strong>QwikIntrinsicElements</strong>, meaning
139123
you can treat it like an element!
@@ -151,7 +135,7 @@ export const Example02 = component$(() => {
151135
</span>
152136
</AccordionTrigger>
153137
</h3>
154-
<AccordionContent>
138+
<AccordionContent class="accordion-animation-1">
155139
<p class="bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]">
156140
You can use onClick$, onKeyDown$, any handlers you'd normally
157141
use with Qwik!
@@ -168,6 +152,7 @@ export const Example02 = component$(() => {
168152
);
169153
});
170154

155+
// non-collapsible
171156
export const Example03 = component$(() => {
172157
return (
173158
<PreviewCodeExample>
@@ -188,7 +173,7 @@ export const Example03 = component$(() => {
188173
</span>
189174
</AccordionTrigger>
190175
</AccordionHeader>
191-
<AccordionContent>
176+
<AccordionContent class="accordion-animation-1">
192177
<p class="bg-violet-200 dark:bg-gray-900 p-4 ">
193178
You can turn it off by setting the <strong>collapsible</strong>{' '}
194179
prop to false.
@@ -206,7 +191,7 @@ export const Example03 = component$(() => {
206191
</span>
207192
</AccordionTrigger>
208193
</AccordionHeader>
209-
<AccordionContent>
194+
<AccordionContent class="accordion-animation-1">
210195
<p class="bg-violet-200 dark:bg-gray-900 p-4">
211196
It's typed using <strong>QwikIntrinsicElements</strong>, meaning
212197
you can treat it like an element!
@@ -224,7 +209,7 @@ export const Example03 = component$(() => {
224209
</span>
225210
</AccordionTrigger>
226211
</h3>
227-
<AccordionContent>
212+
<AccordionContent class="accordion-animation-1">
228213
<p class="bg-violet-200 dark:bg-gray-900 p-4 dark:border-gray-600 border-t-[1px]">
229214
You can use onClick$, onKeyDown$, any handlers you'd normally
230215
use with Qwik!
@@ -240,3 +225,165 @@ export const Example03 = component$(() => {
240225
</PreviewCodeExample>
241226
);
242227
});
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

Comments
 (0)