storybook/docs/snippets/svelte/button-implementation.js.mdx
2022-09-26 09:41:44 +02:00

37 lines
718 B
Plaintext

```html
<!-- Button.svelte -->
<script>
import { createEventDispatcher } from 'svelte';
/**
* Is this the principal call to action on the page?
*/
export let primary = false;
/**
* What background color to use
*/
export let backgroundColor;
/**
* How large should the button be?
*/
export let size = 'medium';
/**
* Button contents
*/
export let label = '';
$: style = backgroundColor ? `background-color: ${backgroundColor}` : '';
const dispatch = createEventDispatcher();
/**
* Optional click handler
*/
export let onClick = (event) => {
dispatch('click', event);
};
</script>
<button type="button" {style} on:click="{onClick}">{label}</button>
```