generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back example stories for tests
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script context="module" lang="ts"> | ||
import { action } from '@storybook/addon-actions'; | ||
import { | ||
defineMeta, | ||
setTemplate, | ||
type Args, | ||
type StoryContext, | ||
} from '@storybook/addon-svelte-csf'; | ||
import Example from './Example.svelte'; | ||
/** | ||
* Description set explicitly in the comment above `defineMeta`. | ||
* | ||
* Multiline supported. And also Markdown syntax: | ||
* | ||
* * **Bold**, | ||
* * _Italic_, | ||
* * `Code`. | ||
*/ | ||
const { Story } = defineMeta({ | ||
title: 'Example', | ||
component: Example, | ||
tags: ['autodocs'], | ||
args: { | ||
onclick: action('onclick'), | ||
onmouseenter: action('onmouseenter'), | ||
onmouseleave: action('onmouseleave'), | ||
}, | ||
}); | ||
</script> | ||
|
||
<script lang="ts"> | ||
let count = $state(0); | ||
function handleClick() { | ||
count += 1; | ||
} | ||
setTemplate(render); | ||
</script> | ||
|
||
{#snippet render(args: Args<typeof Story>, context: StoryContext<typeof Story>)} | ||
<Example {...args} onclick={handleClick}> | ||
<p>{args.id}</p> | ||
<p>{context.name}</p> | ||
You clicked: {count}<br /> | ||
</Example> | ||
{/snippet} | ||
|
||
<!-- Description for the default story --> | ||
<Story name="Default" /> | ||
|
||
<!-- Description for the rounded story --> | ||
<Story name="Rounded" args={{ rounded: true }} /> | ||
|
||
<!-- Description for the squared story --> | ||
<Story name="Square" args={{ rounded: false }} /> | ||
|
||
<Story name="Without template"> | ||
<Example>Label</Example> | ||
</Story> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from 'svelte'; | ||
import type { HTMLAttributes } from 'svelte/elements'; | ||
interface Props extends HTMLAttributes<HTMLButtonElement> { | ||
children?: Snippet; | ||
rounded?: boolean; | ||
} | ||
let { children, rounded = true, ...restProps }: Props = $props(); | ||
</script> | ||
|
||
<button class="button" class:rounded {...restProps}> | ||
<strong>{rounded ? 'Round' : 'Square'} corners</strong> | ||
<hr /> | ||
{#if children} | ||
{@render children()} | ||
{/if} | ||
</button> | ||
|
||
<style> | ||
.rounded { | ||
border-radius: 35px; | ||
} | ||
.button { | ||
border: 3px solid; | ||
padding: 10px 20px; | ||
background-color: white; | ||
outline: none; | ||
} | ||
</style> |