Skip to content

Instantly share code, notes, and snippets.

@whisher
Created May 13, 2022 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whisher/33bac45c38d8ff968893302235bfaa01 to your computer and use it in GitHub Desktop.
Save whisher/33bac45c38d8ff968893302235bfaa01 to your computer and use it in GitHub Desktop.
<script context="module" lang="ts">
import type {SvelteComponent} from 'svelte'
export const getItemId = (index: number, carouselName = 'carousel') =>
`${carouselName}-item-${index}`
export type Item = {
props: Record<string, any>
component: typeof SvelteComponent
}
</script>
<script lang="ts">
export let items: Item[]
export const name = 'carousel'
</script>
<ul
class="flex overflow-x-auto gap-6 snap-x snap-mandatory before:shrink-0 before:w-[30vw] after:shrink-0 after:w-[30vw] pb-6"
>
{#each items as { props, component }, index}
<svelte:component this={component} id={getItemId(index)} {...props} />
{/each}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment