Skip to content

Instantly share code, notes, and snippets.

@matryer
Last active November 20, 2020 19:03
Show Gist options
  • Save matryer/8eda4036144efa1d0d0b4303fe5502db to your computer and use it in GitHub Desktop.
Save matryer/8eda4036144efa1d0d0b4303fe5502db to your computer and use it in GitHub Desktop.
Simple Accordian component for Svelte (from https://firesearch.dev)
<script lang='ts'>
import { slide } from 'svelte/transition'
export let open: boolean = false
export function toggle() {
open = !open
}
</script>
<a
href='#open'
on:click|preventDefault={ toggle }
><slot name='link' {open}></slot></a>
{#if open}
<div transition:slide>
<slot name='content'></slot>
</div>
{/if}
<script lang='ts'>
import Accordian from './Accordian.svelte'
</script>
<Accordian let:open>
<span slot='link'>
{#if !open}
Show more
{:else}
Hide
{/if}
</span>
<div slot='content'>
Content goes here
</div>
</Accordian>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment