Svelte - easy way to inherit from sveltestrap component?

Viewed 121

I'm trying out Svelte for the first time and I'm wanting to do something like below. Where I take a button from an existing component library and just add a single parameter to it. I'd like to be able to still have access to all the sveltestrap options from original button. Or is this not possible in Svelte?

<script lang="ts">
    import { Button, Spinner } from 'sveltestrap';
    export let loading = false;
</script>

<Button>
    {#if loading }
        <Spinner />
    {:else}
        <slot/>
    {/if}
</Button>
1 Answers

The closest thing is probably spreading $$restProps and forwarding the events that are of interest (there currently is no method of just forwarding all).

<script lang="ts">
    import { Button, Spinner } from 'sveltestrap';
    export let loading = false;
</script>

<Button {...$$restProps} on:click > <!-- add more events as needed -->
    {#if loading }
        <Spinner />
    {:else}
        <slot/>
    {/if}
</Button>

REPL example

Related