-
-
Save leejoramo-d51/4b7bb0ba5465c54861137ea1c743ed52 to your computer and use it in GitHub Desktop.
A svelte component you can drop into your svelte kit app to view a list of all your components (poor man's Storybook)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script context="module"> | |
const modules = import.meta.glob('/src/sections/*.svelte') | |
const componentNames = Object.keys(modules) | |
</script> | |
<script> | |
import cx from 'clsx' | |
let current = componentNames[0] | |
$: importComponent = modules[current] | |
const onClickForName = (name) => () => { | |
current = name | |
} | |
</script> | |
<div class="flex"> | |
<ul class="w-1/5 p-4"> | |
{#each componentNames as name (name)} | |
<li class={cx({ | |
'opacity-40': name === current | |
})}> | |
<button on:click={onClickForName(name)}> | |
{name.split('/src/sections/')[1] || ''} | |
</button> | |
</li> | |
{/each} | |
</ul> | |
<div class="flex-1"> | |
{#await importComponent()} | |
<div>Loading</div> | |
{:then component} | |
<svelte:component this={component.default} /> | |
{:catch err} | |
<div>{JSON.stringify(err)}</div> | |
{/await} | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment