QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.71k stars 1.29k forks source link

Is there a way to see the code input inside a Slot #5518

Closed Nedimko123 closed 3 months ago

Nedimko123 commented 10 months ago

For example in Quasar when you click show Source code: https://quasar.dev/vue-components/chip/ it will show you the source code used, is there a way to do that with , I know this can be done through props as a raw string, but I would love to have it be dynamic with so I don't have to insert the same code twice:

 <ComponentOverview title="Sizes">
                <div class="flex flex-row gap-4 items-center">
                    <Toggle
                        checked={state.isChecked}
                        checkedIcon="fa-solid fa-check"
                        uncheckedIcon="fa-solid fa-xmark"
                        checkedColor="positive"
                        uncheckedColor="negative"
                        tooltip="Size: xs"
                        size="xs"
                        onClick$={() => {
                            state.isChecked = !state.isChecked
                        }}
                    ></Toggle>
                        </div>
            </ComponentOverview>

And my ComponentOverview:


import { Slot, component$ } from '@builder.io/qwik'

export const ComponentOverview = component$((props: { title: string }) => {
    return (
        <>
            <div class="flex flex-col border-default rounded items-center my-4">
                {/* Title  */}
                <div class="py-1 px-2 w-full items-center uppercase font-bold border-default bg-slate-200 dark:bg-slate-900">
                    <p class="pt-1 text-xl">{props.title}</p>
                </div>
                <div class="p-4 w-full items-center uppercase font-bold border-default bg-white dark:bg-dark-background">
                    <Slot />
                </div>
            </div>
        </>
    )
})
wmertens commented 10 months ago

In qwik-ui we solved it with a glob import https://github.com/qwikifiers/qwik-ui/blob/532214d51ea3478d66c56ca20f5ee18c937b091c/apps/website/src/components/showcase/showcase.tsx#L45

gioboa commented 3 months ago

@Nedimko123 Did you solve your issue with the @wmertens solution?

github-actions[bot] commented 3 months ago

Hello @Nedimko123. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏