@@ -6,24 +6,26 @@ import {
6
6
useStyles$ ,
7
7
useTask$ ,
8
8
} from '@builder.io/qwik' ;
9
- import styles from './show-example.css?inline' ;
10
-
9
+ import styles from './showcase.css?inline' ;
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' ;
14
13
import { Highlight } from '../highlight/highlight' ;
15
14
16
- // The below patterns are here so that import.meta.glob works both for fluffy and headless routes.
15
+ // The below `/src/routes/docs/**/**/examples/*.tsx` patterns are here so that import.meta.glob works both for fluffy and headless routes.
17
16
// For example:
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,25 +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 Component = useSignal < Component < any > > ( ) ;
43
- const ComponentRaw = useSignal < string > ( ) ;
41
+ const MetaGlobComponentSig = useSignal < Component < any > > ( ) ;
42
+ const componentCodeSig = useSignal < string > ( ) ;
44
43
45
44
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
- }
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 ] ;
53
51
} ) ;
54
52
55
53
useStyles$ ( styles ) ;
54
+
56
55
return (
57
56
< Tabs
58
57
{ ...props }
@@ -67,13 +66,16 @@ export const Showcase = component$<ShowcaseProps>(({ name, ...props }) => {
67
66
Code
68
67
</ Tab >
69
68
</ 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" >
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" >
71
70
< section class = "flex flex-col items-center" >
72
- { Component . value && < Component . value /> }
71
+ { MetaGlobComponentSig . value && < MetaGlobComponentSig . value /> }
73
72
</ section >
74
73
</ TabPanel >
75
74
< 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 || '' } />
75
+ < Highlight
76
+ class = "rounded-b-xl rounded-t-none"
77
+ code = { componentCodeSig . value || '' }
78
+ />
77
79
</ TabPanel >
78
80
</ Tabs >
79
81
) ;
0 commit comments