Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
add @storybook/addon-svelte-csf storybook addon
Browse files Browse the repository at this point in the history
Allows for stories to be written in .svelte syntax making it possible to pass slotted content

https://storybook.js.org/addons/@storybook/addon-svelte-csf
  • Loading branch information
joekrump committed Oct 18, 2023
1 parent 339ba0a commit 46074ab
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 deletions.
7 changes: 6 additions & 1 deletion .storybook/main.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
"stories": ["../app/javascript/**/*.stories.mdx", "../app/javascript/**/*.stories.@(js|ts|svelte)"],
"addons": ["@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions"],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@storybook/addon-svelte-csf"
],
"framework": "@storybook/svelte-vite",
"core": {
"builder": "@storybook/builder-vite",
Expand Down
20 changes: 0 additions & 20 deletions app/javascript/components/ClickButton.stories.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/javascript/components/ClickButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<button
type="button"
on:click={sendClick}
on:click={() => 'hi'}
class="mt-3 w-full rounded bg-rose py-2 font-medium text-black transition hover:bg-rails-light hover:text-white active:outline-none active:ring-2 active:ring-rails-light active:ring-offset-1"
>
Click me!
Expand Down
30 changes: 30 additions & 0 deletions app/javascript/components/PageTitle.stories.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script context="module">
import PageTitle from './PageTitle.svelte';
export const meta = {
title: 'Example Page Title',
component: PageTitle,
argTypes: {
children: {
control: {
type: 'text',
},
},
},
};
</script>

<script>
import { Story, Template } from '@storybook/addon-svelte-csf';
</script>

<Template let:args>
<!--👇 'on:click' allows to forward event to addon-actions -->
<PageTitle {...args}></PageTitle>
</Template>

<Story name="With Slotted content">
<PageTitle>I am a title</PageTitle>
</Story>

<Story name="Default" />
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@storybook/addon-interactions": "^7.5.0",
"@storybook/addon-links": "^7.5.0",
"@storybook/addon-mdx-gfm": "^7.5.0",
"@storybook/addon-svelte-csf": "^4.0.9",
"@storybook/svelte": "^7.5.0",
"@storybook/svelte-vite": "^7.5.0",
"@storybook/testing-library": "^0.2.2",
Expand Down
43 changes: 41 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46074ab

Please sign in to comment.