7
7
useTask$ ,
8
8
} from '@builder.io/qwik' ;
9
9
import styles from './showcase.css?inline' ;
10
-
11
10
import { Tab , TabList , TabPanel , Tabs } from '@qwik-ui/headless' ;
12
11
import { useLocation } from '@builder.io/qwik-city' ;
13
12
import { isDev } from '@builder.io/qwik/build' ;
@@ -18,12 +17,15 @@ import { Highlight } from '../highlight/highlight';
18
17
// /src/routes/docs/components/fluffy/modal/examples/hero.tsx
19
18
// /src/routes/docs/components/headless/modal/examples/hero.tsx
20
19
21
- const components : any = import . meta. glob ( '/src/routes/docs/**/**/examples/*.tsx' , {
22
- import : 'default' ,
23
- eager : isDev ? false : true ,
24
- } ) ;
20
+ const metaGlobComponents : any = import . meta. glob (
21
+ '/src/routes/docs/**/**/examples/*.tsx' ,
22
+ {
23
+ import : 'default' ,
24
+ eager : isDev ? false : true ,
25
+ } ,
26
+ ) ;
25
27
26
- const componentsRaw : any = import . meta. glob ( '/src/routes/docs/**/**/examples/*.tsx' , {
28
+ const rawComponents : any = import . meta. glob ( '/src/routes/docs/**/**/examples/*.tsx' , {
27
29
as : 'raw' ,
28
30
eager : isDev ? false : true ,
29
31
} ) ;
@@ -34,27 +36,22 @@ type ShowcaseProps = QwikIntrinsicElements['div'] & {
34
36
35
37
export const Showcase = component$ < ShowcaseProps > ( ( { name, ...props } ) => {
36
38
const location = useLocation ( ) ;
37
-
38
39
const componentPath = `/src/routes${ location . url . pathname } examples/${ name } .tsx` ;
39
40
40
- console . log ( 'componentPath' , componentPath ) ;
41
-
42
- const ComponentSig = useSignal < Component < any > > ( ) ;
43
- const ComponentRawSig = useSignal < string > ( ) ;
41
+ const MetaGlobComponentSig = useSignal < Component < any > > ( ) ;
42
+ const componentCodeSig = useSignal < string > ( ) ;
44
43
45
44
useTask$ ( async ( ) => {
46
- // We need to call `await components[componentPath]()` in development as it is `eager:false`
47
- if ( isDev ) {
48
- ComponentSig . value = await components [ componentPath ] ( ) ;
49
- ComponentRawSig . value = await componentsRaw [ componentPath ] ( ) ;
50
- // We need to directly access the `components[componentPath]` expression in preview/production as it is `eager:true`
51
- } else {
52
- ComponentSig . value = components [ componentPath ] ;
53
- ComponentRawSig . value = componentsRaw [ componentPath ] ;
54
- }
45
+ MetaGlobComponentSig . value = isDev
46
+ ? await metaGlobComponents [ componentPath ] ( ) // We need to call `await metaGlobComponents[componentPath]()` in development as it is `eager:false`
47
+ : metaGlobComponents [ componentPath ] ; // We need to directly access the `metaGlobComponents[componentPath]` expression in preview/production as it is `eager:true`
48
+ componentCodeSig . value = isDev
49
+ ? await rawComponents [ componentPath ] ( )
50
+ : rawComponents [ componentPath ] ;
55
51
} ) ;
56
52
57
53
useStyles$ ( styles ) ;
54
+
58
55
return (
59
56
< Tabs
60
57
{ ...props }
@@ -69,15 +66,15 @@ export const Showcase = component$<ShowcaseProps>(({ name, ...props }) => {
69
66
Code
70
67
</ Tab >
71
68
</ TabList >
72
- < 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" >
69
+ < 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" >
73
70
< section class = "flex flex-col items-center" >
74
- { ComponentSig . value && < ComponentSig . value /> }
71
+ { MetaGlobComponentSig . value && < MetaGlobComponentSig . value /> }
75
72
</ section >
76
73
</ TabPanel >
77
74
< TabPanel class = "border-qwikui-blue-300 dark:border-qwikui-purple-200 relative rounded-b-xl border-[1.5px]" >
78
75
< Highlight
79
76
class = "rounded-b-xl rounded-t-none"
80
- code = { ComponentRawSig . value || '' }
77
+ code = { componentCodeSig . value || '' }
81
78
/>
82
79
</ TabPanel >
83
80
</ Tabs >
0 commit comments