Skip to content

Commit

Permalink
Bring back example stories for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Jul 14, 2024
1 parent 05e273f commit 26b0f68
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/stories/Example.stories.svelte
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>
32 changes: 32 additions & 0 deletions tests/stories/Example.svelte
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>

0 comments on commit 26b0f68

Please sign in to comment.