Skip to content

Commit 03ef68d

Browse files
Merge pull request #524 from maiieul/provider-meta-glob
refactor/docs: Add Showcase & CodeSnippet components w/ import.meta.glob pattern for .mdx routes
2 parents 72d743a + 4d22dca commit 03ef68d

File tree

214 files changed

+1976
-3040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+1976
-3040
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { QwikIntrinsicElements, component$, useSignal, useTask$ } from '@builder.io/qwik';
2+
import { useLocation } from '@builder.io/qwik-city';
3+
import { isDev } from '@builder.io/qwik/build';
4+
import { Highlight } from '../highlight/highlight';
5+
6+
type CodeSnippetProps = QwikIntrinsicElements['div'] & {
7+
name: string;
8+
};
9+
10+
const rawCodeSnippets: any = import.meta.glob('/src/routes/docs/**/**/snippets/*', {
11+
as: 'raw',
12+
eager: isDev ? false : true,
13+
});
14+
15+
export const CodeSnippet = component$<CodeSnippetProps>(({ name }) => {
16+
const location = useLocation();
17+
18+
let lang = '.tsx';
19+
20+
if (name.endsWith('.tsx')) lang = '';
21+
if (name.endsWith('.ts')) lang = '';
22+
if (name.endsWith('.css')) lang = '';
23+
24+
const snippetPath = `/src/routes${location.url.pathname}snippets/${name}${lang}`;
25+
26+
const CodeSnippet = useSignal<string>();
27+
28+
useTask$(async () => {
29+
if (isDev) {
30+
CodeSnippet.value = await rawCodeSnippets[snippetPath]();
31+
} else {
32+
CodeSnippet.value = rawCodeSnippets[snippetPath];
33+
}
34+
});
35+
return (
36+
<div
37+
class={`shadow-3xl shadow-light-medium dark:shadow-dark-medium mb-6 rounded-xl border-2 border-slate-200 dark:border-slate-400`}
38+
>
39+
<Highlight code={CodeSnippet.value || ''} />
40+
</div>
41+
);
42+
});

apps/website/src/components/mdx-components/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { AnatomyTable } from '../anatomy-table/anatomy-table';
55
import { APITable } from '../api-table/api-table';
66
import { KeyboardInteractionTable } from '../keyboard-interaction-table/keyboard-interaction-table';
77
import { CodeCopy } from '../code-copy/code-copy';
8-
import { statusByComponent } from '~/_state/component-statuses';
8+
import { Showcase } from '../show-example/show-example';
9+
import { CodeSnippet } from '../code-snippet/code-snippet';
910

1011
export const components: Record<string, any> = {
1112
pre: component$<
@@ -41,5 +42,6 @@ export const components: Record<string, any> = {
4142
APITable,
4243
KeyboardInteractionTable,
4344
StatusBanner,
44-
statusByComponent: statusByComponent,
45+
Showcase,
46+
CodeSnippet,
4547
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.dark .previewCodeExampleSelectedTab {
2+
background-color: var(--qwikui-purple-600);
3+
font-weight: 600;
4+
}
5+
6+
.previewCodeExampleSelectedTab {
7+
background-color: var(--qwikui-blue-500);
8+
font-weight: 600;
9+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {
2+
Component,
3+
QwikIntrinsicElements,
4+
component$,
5+
useSignal,
6+
useStyles$,
7+
useTask$,
8+
} from '@builder.io/qwik';
9+
import styles from './show-example.css?inline';
10+
11+
import { Tab, TabList, TabPanel, Tabs } from '@qwik-ui/headless';
12+
import { useLocation } from '@builder.io/qwik-city';
13+
import { isDev } from '@builder.io/qwik/build';
14+
import { Highlight } from '../highlight/highlight';
15+
16+
// The below patterns are here so that import.meta.glob works both for fluffy and headless routes.
17+
// For example:
18+
// /src/routes/docs/components/fluffy/modal/examples/hero.tsx
19+
// /src/routes/docs/components/headless/modal/examples/hero.tsx
20+
21+
const components: any = import.meta.glob('/src/routes/docs/**/**/examples/*.tsx', {
22+
import: 'default',
23+
eager: isDev ? false : true,
24+
});
25+
26+
const componentsRaw: any = import.meta.glob('/src/routes/docs/**/**/examples/*.tsx', {
27+
as: 'raw',
28+
eager: isDev ? false : true,
29+
});
30+
31+
type ShowcaseProps = QwikIntrinsicElements['div'] & {
32+
name?: string;
33+
};
34+
35+
export const Showcase = component$<ShowcaseProps>(({ name, ...props }) => {
36+
const location = useLocation();
37+
38+
const componentPath = `/src/routes${location.url.pathname}examples/${name}.tsx`;
39+
40+
console.log('componentPath', componentPath);
41+
42+
const Component = useSignal<Component<any>>();
43+
const ComponentRaw = useSignal<string>();
44+
45+
useTask$(async () => {
46+
if (isDev) {
47+
Component.value = await components[componentPath]();
48+
ComponentRaw.value = await componentsRaw[componentPath]();
49+
} else {
50+
Component.value = components[componentPath];
51+
ComponentRaw.value = componentsRaw[componentPath];
52+
}
53+
});
54+
55+
useStyles$(styles);
56+
return (
57+
<Tabs
58+
{...props}
59+
class="shadow-light-medium dark:shadow-dark-medium mb-12 rounded-xl"
60+
selectedClassName="previewCodeExampleSelectedTab"
61+
>
62+
<TabList class="bg-qwikui-blue-700 dark:bg-qwikui-purple-800 border-qwikui-blue-300 dark:border-qwikui-purple-200 flex rounded-t-xl border-[1.5px] border-b-0 text-white">
63+
<Tab class="hover:bg-qwikui-blue-500 dark:hover:bg-qwikui-purple-600 text-outline-lg rounded-tl-[.625rem] px-4 py-2">
64+
Preview
65+
</Tab>
66+
<Tab class="hover:bg-qwikui-blue-500 dark:hover:bg-qwikui-purple-600 text-outline-lg px-4 py-2">
67+
Code
68+
</Tab>
69+
</TabList>
70+
<TabPanel class="shadow-light-medium dark:shadow-dark-medium border-qwikui-blue-300 dark:border-qwikui-purple-200 rounded-b-xl border-[1.5px] bg-slate-200 bg-slate-800 p-4 dark:bg-slate-900 md:p-12">
71+
<section class="flex flex-col items-center">
72+
{Component.value && <Component.value />}
73+
</section>
74+
</TabPanel>
75+
<TabPanel class="border-qwikui-blue-300 dark:border-qwikui-purple-200 relative rounded-b-xl border-[1.5px]">
76+
<Highlight class="rounded-b-xl rounded-t-none" code={ComponentRaw.value || ''} />
77+
</TabPanel>
78+
</Tabs>
79+
);
80+
});

apps/website/src/routes/docs/fluffy/(components)/accordion/exports.ts

Whitespace-only changes.

apps/website/src/routes/docs/fluffy/(components)/button/examples.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

apps/website/src/routes/docs/fluffy/(components)/button/index.mdx

Lines changed: 0 additions & 48 deletions
This file was deleted.

apps/website/src/routes/docs/fluffy/(getting-started)/install/examples.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)