Skip to content

Commit 82fbb1a

Browse files
Merge pull request #672 from thejackshelton/shiki-utf8
fix: docs examples
2 parents 72e69ea + d199f56 commit 82fbb1a

File tree

15 files changed

+135
-19
lines changed

15 files changed

+135
-19
lines changed

apps/website/src/components/highlight/highlight.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import { ClassList, PropsOf, component$, useSignal, useTask$ } from '@builder.io/qwik';
1+
import {
2+
ClassList,
3+
PropsOf,
4+
component$,
5+
useSignal,
6+
useTask$,
7+
useVisibleTask$,
8+
$,
9+
} from '@builder.io/qwik';
210
import { CodeCopy } from '../code-copy/code-copy';
311
import { getHighlighterCore } from 'shiki';
412
import { cn } from '@qwik-ui/utils';
13+
import { isDev } from '@builder.io/qwik/build';
514

615
export type HighlightProps = PropsOf<'div'> & {
716
code: string;
@@ -22,8 +31,7 @@ export const Highlight = component$(
2231
}: HighlightProps) => {
2332
const codeSig = useSignal('');
2433

25-
// eslint-disable-next-line qwik/no-use-visible-task
26-
useTask$(async function createHighlightedCode() {
34+
const addShiki$ = $(async () => {
2735
let modifiedCode: string = code;
2836

2937
let partsOfCode = modifiedCode.split(splitCommentStart);
@@ -59,6 +67,22 @@ export const Highlight = component$(
5967
codeSig.value = str.toString();
6068
});
6169

70+
useTask$(async function createHighlightedCode() {
71+
if (!isDev) {
72+
await addShiki$();
73+
}
74+
});
75+
76+
// eslint-disable-next-line qwik/no-use-visible-task
77+
useVisibleTask$(
78+
async () => {
79+
if (isDev) {
80+
await addShiki$();
81+
}
82+
},
83+
{ strategy: 'document-ready' },
84+
);
85+
6286
return (
6387
<div class="code-example relative max-h-[31.25rem]">
6488
<CodeCopy

apps/website/src/routes/docs/headless/accordion/examples/custom-heading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default component$(() => {
1111
return (
1212
<>
1313
<div class="flex w-full justify-center">
14-
<AccordionRoot>
14+
<AccordionRoot class="w-full">
1515
<AccordionItem class="border-b">
1616
<AccordionHeader as="h4">
1717
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/default-value.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default component$(() => {
1111
return (
1212
<>
1313
<div class="flex w-full justify-center">
14-
<AccordionRoot>
14+
<AccordionRoot class="w-full">
1515
<AccordionItem class="border-b">
1616
<AccordionHeader as="h3">
1717
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/disabled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default component$(() => {
1212
return (
1313
<>
1414
<div class="flex w-full justify-center">
15-
<AccordionRoot>
15+
<AccordionRoot class="w-full">
1616
<AccordionItem class="border-b">
1717
<AccordionHeader as="h3">
1818
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/dynamic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default component$(({ itemsLength = 3 }: DynamicAccordionProps) => {
5353
</label>
5454
</div>
5555

56-
<AccordionRoot>
56+
<AccordionRoot class="w-full">
5757
{itemStore.map(({ label, id }, index) => {
5858
return (
5959
<AccordionItem id={`${id}`} key={id} class="border-b">

apps/website/src/routes/docs/headless/accordion/examples/focused-index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default component$(() => {
1414
<>
1515
<div class="flex w-full flex-col items-center gap-4">
1616
<AccordionRoot
17+
class="w-full"
1718
onFocusIndexChange$={(index: number) => {
1819
focusedIndexSig.value = index;
1920
}}

apps/website/src/routes/docs/headless/accordion/examples/hero.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default component$(() => {
1212
return (
1313
<>
1414
<div class="flex w-full justify-center">
15-
<AccordionRoot animated enhance={true}>
15+
<AccordionRoot class="w-full" animated enhance={true}>
1616
<AccordionItem class="border-b">
1717
<AccordionHeader as="h3">
1818
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/multi.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default component$(() => {
1212
return (
1313
<>
1414
<div class="flex w-full justify-center">
15-
<AccordionRoot collapsible animated behavior="multi">
15+
<AccordionRoot class="w-full" collapsible animated behavior="multi">
1616
<AccordionItem class="border-b">
1717
<AccordionHeader as="h3">
1818
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/non-collapsible.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default component$(() => {
1313
return (
1414
<>
1515
<div class="flex w-full justify-center">
16-
<AccordionRoot animated collapsible={false}>
16+
<AccordionRoot class="w-full" animated collapsible={false}>
1717
<AccordionItem class="border-b">
1818
<AccordionHeader as="h3">
1919
<AccordionTrigger class="group flex w-full items-center justify-between rounded-t-sm py-4 text-left hover:underline">

apps/website/src/routes/docs/headless/accordion/examples/selected-index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default component$(() => {
1414
<>
1515
<div class="flex w-full flex-col items-center gap-4">
1616
<AccordionRoot
17+
class="w-full"
1718
onSelectedIndexChange$={(index: number) => {
1819
selectedIndexSig.value = index;
1920
}}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@qwik-ui/headless';
3+
import styles from '../snippets/collapsible.css?inline';
4+
5+
export default component$(() => {
6+
useStyles$(styles);
7+
const isOpen = useSignal<boolean>(false);
8+
9+
return (
10+
<>
11+
<p>
12+
is open: <strong>{isOpen.value ? 'true' : 'false'}</strong>
13+
</p>
14+
15+
<Collapsible class="collapsible" bind:open={isOpen}>
16+
<CollapsibleTrigger class="collapsible-trigger">Trigger</CollapsibleTrigger>
17+
<CollapsibleContent class="collapsible-content">
18+
<p class="collapsible-content-outline">Content</p>
19+
</CollapsibleContent>
20+
</Collapsible>
21+
</>
22+
);
23+
});

apps/website/src/routes/docs/headless/collapsible/index.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,17 @@ This is because the content is rendered on the server. Animations applied to `da
8484

8585
We can pass reactive state by using the bind:open prop to the `<Collapsible />` component.
8686

87+
<Showcase name="bind-open" />
88+
89+
bind:open is a signal prop, and allows us to pass in our own signal to control the expanded state of the collapsible.
90+
91+
### Programmatic changes
92+
93+
Now that we have a controlled state, we can programmatically change the state of the collapsible by changing the value of the signal.
94+
8795
<Showcase name="programmatic" />
8896

89-
bind:open is a signal prop, it allows us to programmatically control the expanded state of the collapsible.
97+
The example above toggles the expanded state of the collapsible by changing the value of the `isOpen` signal when the checkbox is clicked.
9098

9199
### Handling open / close
92100

@@ -136,6 +144,21 @@ Every code example uses the following CSS:
136144

137145
Some CSS variables are specific to the docs, feel free to plug in your own values or variables!
138146

147+
## Keyboard Interaction
148+
149+
<KeyboardInteractionTable
150+
keyDescriptors={[
151+
{
152+
keyTitle: 'Space',
153+
description: `When focus is on the trigger, open or close the collapsible.`,
154+
},
155+
{
156+
keyTitle: 'Enter',
157+
description: `When focus is on the trigger open or close the collapsible.`,
158+
},
159+
]}
160+
/>
161+
139162
## API
140163

141164
### Data Attributes

apps/website/src/routes/docs/headless/select/index.mdx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ The consumer misspelled the the value, and so the fallback is displayed.
265265

266266
> Side note: would appreciate some help on TypeScript to make misspelled option values a thing of the past. Ideally, a union of the user's passed in options.
267267
268-
## Forms
269-
270-
<Showcase name="form" />
271-
272268
## Example CSS
273269

274270
Every code example uses the following CSS:
@@ -277,6 +273,49 @@ Every code example uses the following CSS:
277273

278274
Some CSS variables are specific to the docs, feel free to plug in your own values or variables!
279275

276+
## Keyboard Interaction
277+
278+
<KeyboardInteractionTable
279+
keyDescriptors={[
280+
{
281+
keyTitle: 'Space',
282+
description: `Opens the menu and selects a highlighted option.`,
283+
},
284+
{
285+
keyTitle: 'Enter',
286+
description: `Opens the menu and selects a highlighted option.`,
287+
},
288+
{
289+
keyTitle: 'ArrowDown',
290+
description: `Opens the menu or moves focus down.`,
291+
},
292+
{
293+
keyTitle: 'ArrowUp',
294+
description: `Opens the menu or moves focus up.`,
295+
},
296+
{
297+
keyTitle: 'Home',
298+
description: `When focus is on an item, moves focus to first item.`,
299+
},
300+
{
301+
keyTitle: 'End',
302+
description: `When focus is on an item, moves focus to last item.`,
303+
},
304+
{
305+
keyTitle: 'ArrowRight',
306+
description: `When focus is on the trigger, change the selection to the next item.`,
307+
},
308+
{
309+
keyTitle: 'ArrowLeft',
310+
description: `When focus is on the trigger, change the selection to the previous item.`,
311+
},
312+
{
313+
keyTitle: 'Esc',
314+
description: `Closes the select and moves focus to the trigger.`,
315+
},
316+
]}
317+
/>
318+
280319
## API
281320

282321
### Data Attributes

apps/website/src/routes/docs/headless/tabs/examples/disabled.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export default component$(() => {
1111
<Tabs>
1212
<TabList>
1313
<Tab
14+
style={{ width: '125px' }}
1415
class="aria-disabled:cursor-not-allowed"
15-
style="width: 25%"
1616
disabled={true}
1717
>
1818
Disabled Tab
1919
</Tab>
20-
<Tab style="width: 25%">Joke 2</Tab>
21-
<Tab style="width: 25%">Joke 3</Tab>
22-
<Tab style="width: 25%">Joke 4</Tab>
20+
<Tab style={{ width: '125px' }}>Joke 2</Tab>
21+
<Tab style={{ width: '125px' }}>Joke 3</Tab>
22+
<Tab style={{ width: '125px' }}>Joke 4</Tab>
2323
</TabList>
2424
<TabPanel>"What did the coffee report to the police", " A mugging."</TabPanel>
2525
<TabPanel>"What's brown and sticky", " A stick."</TabPanel>

apps/website/src/routes/docs/headless/tabs/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.tabs-example {
2+
width: 100%;
3+
}
4+
15
.tabs-example [role='tab'] {
26
width: 148px;
37
background: hsl(var(--muted));
@@ -16,6 +20,7 @@
1620
.tabs-example [role='tablist'] {
1721
border: 1px solid;
1822
margin-bottom: 1rem;
23+
max-width: fit-content;
1924
}
2025

2126
.tabs-example h3 {

0 commit comments

Comments
 (0)