77 useTask$ ,
88} from '@builder.io/qwik' ;
99import styles from './showcase.css?inline' ;
10-
1110import { Tab , TabList , TabPanel , Tabs } from '@qwik-ui/headless' ;
1211import { useLocation } from '@builder.io/qwik-city' ;
1312import { isDev } from '@builder.io/qwik/build' ;
@@ -18,12 +17,15 @@ import { Highlight } from '../highlight/highlight';
1817// /src/routes/docs/components/fluffy/modal/examples/hero.tsx
1918// /src/routes/docs/components/headless/modal/examples/hero.tsx
2019
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+ ) ;
2527
26- const componentsRaw : any = import . meta. glob ( '/src/routes/docs/**/**/examples/*.tsx' , {
28+ const rawComponents : any = import . meta. glob ( '/src/routes/docs/**/**/examples/*.tsx' , {
2729 as : 'raw' ,
2830 eager : isDev ? false : true ,
2931} ) ;
@@ -34,27 +36,22 @@ type ShowcaseProps = QwikIntrinsicElements['div'] & {
3436
3537export const Showcase = component$ < ShowcaseProps > ( ( { name, ...props } ) => {
3638 const location = useLocation ( ) ;
37-
3839 const componentPath = `/src/routes${ location . url . pathname } examples/${ name } .tsx` ;
3940
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 > ( ) ;
4443
4544 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 ] ;
5551 } ) ;
5652
5753 useStyles$ ( styles ) ;
54+
5855 return (
5956 < Tabs
6057 { ...props }
@@ -69,15 +66,15 @@ export const Showcase = component$<ShowcaseProps>(({ name, ...props }) => {
6966 Code
7067 </ Tab >
7168 </ 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" >
7370 < section class = "flex flex-col items-center" >
74- { ComponentSig . value && < ComponentSig . value /> }
71+ { MetaGlobComponentSig . value && < MetaGlobComponentSig . value /> }
7572 </ section >
7673 </ TabPanel >
7774 < TabPanel class = "border-qwikui-blue-300 dark:border-qwikui-purple-200 relative rounded-b-xl border-[1.5px]" >
7875 < Highlight
7976 class = "rounded-b-xl rounded-t-none"
80- code = { ComponentRawSig . value || '' }
77+ code = { componentCodeSig . value || '' }
8178 />
8279 </ TabPanel >
8380 </ Tabs >
0 commit comments