Skip to content

Commit d5a0c5f

Browse files
authored
feat: add storybook (#45)
* feat: add storybook * update: lockfile
1 parent 3e22a55 commit d5a0c5f

34 files changed

+5057
-2187
lines changed

infrastructure/eid-wallet/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ node_modules
88
!.env.example
99
vite.config.js.timestamp-*
1010
vite.config.ts.timestamp-*
11+
12+
*storybook.log
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { StorybookConfig } from "@storybook/sveltekit";
2+
3+
import { join, dirname } from "path";
4+
5+
/**
6+
* This function is used to resolve the absolute path of a package.
7+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
8+
*/
9+
function getAbsolutePath(value: string): any {
10+
return dirname(require.resolve(join(value, "package.json")));
11+
}
12+
const config: StorybookConfig = {
13+
// add back support for .svelte files when addon csf works
14+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|ts)"],
15+
addons: [
16+
getAbsolutePath("@storybook/addon-essentials"),
17+
getAbsolutePath("@storybook/addon-svelte-csf"),
18+
getAbsolutePath("@chromatic-com/storybook"),
19+
getAbsolutePath("@storybook/experimental-addon-test"),
20+
],
21+
framework: {
22+
name: getAbsolutePath("@storybook/sveltekit"),
23+
options: {},
24+
},
25+
};
26+
export default config;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Preview } from '@storybook/svelte'
2+
3+
const preview: Preview = {
4+
parameters: {
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/i,
9+
},
10+
},
11+
},
12+
};
13+
14+
export default preview;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { beforeAll } from 'vitest';
2+
import { setProjectAnnotations } from '@storybook/sveltekit';
3+
import * as projectAnnotations from './preview';
4+
5+
// This is an important step to apply the right configuration when testing your stories.
6+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
7+
const project = setProjectAnnotations([projectAnnotations]);
8+
9+
beforeAll(project.beforeAll);

infrastructure/eid-wallet/package.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"preview": "vite preview",
1010
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1111
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12-
"tauri": "tauri"
12+
"tauri": "tauri",
13+
"storybook": "svelte-kit sync && storybook dev -p 6006",
14+
"build-storybook": "storybook build"
1315
},
1416
"license": "MIT",
1517
"dependencies": {
@@ -20,20 +22,34 @@
2022
"tailwind-merge": "^3.0.2"
2123
},
2224
"devDependencies": {
25+
"@chromatic-com/storybook": "^3",
26+
"@storybook/addon-essentials": "^8.6.7",
27+
"@storybook/addon-svelte-csf": "^5.0.0-next.28",
28+
"@storybook/blocks": "^8.6.7",
29+
"@storybook/experimental-addon-test": "^8.6.7",
30+
"@storybook/svelte": "^8.6.7",
31+
"@storybook/sveltekit": "^8.6.7",
32+
"@storybook/test": "^8.6.7",
2333
"@sveltejs/adapter-static": "^3.0.6",
2434
"@sveltejs/kit": "^2.9.0",
2535
"@sveltejs/vite-plugin-svelte": "^5.0.0",
36+
"@tauri-apps/cli": "^2",
37+
"@types/node": "^22.13.10",
38+
"@vitest/browser": "^3.0.9",
39+
"@vitest/coverage-v8": "^3.0.9",
40+
"playwright": "^1.51.1",
41+
"storybook": "^8.6.7",
2642
"@tailwindcss/forms": "^0.5.10",
2743
"@tailwindcss/typography": "^0.5.16",
2844
"@tailwindcss/vite": "^4.0.14",
29-
"@tauri-apps/cli": "^2",
3045
"autoprefixer": "^10.4.21",
3146
"daisyui": "^5.0.6",
3247
"postcss": "^8.5.3",
3348
"svelte": "^5.0.0",
3449
"svelte-check": "^4.0.0",
3550
"tailwindcss": "^4.0.14",
3651
"typescript": "~5.6.2",
37-
"vite": "^6.0.3"
52+
"vite": "^6.0.3",
53+
"vitest": "^3.0.9"
3854
}
3955
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script module>
2+
import { defineMeta } from '@storybook/addon-svelte-csf';
3+
import Button from './Button.svelte';
4+
import { fn } from '@storybook/test';
5+
6+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7+
const { Story } = defineMeta({
8+
title: 'Example/Button',
9+
component: Button,
10+
tags: ['autodocs'],
11+
argTypes: {
12+
backgroundColor: { control: 'color' },
13+
size: {
14+
control: { type: 'select' },
15+
options: ['small', 'medium', 'large'],
16+
},
17+
},
18+
args: {
19+
onClick: fn(),
20+
}
21+
});
22+
</script>
23+
24+
<!-- More on writing stories with args: https://storybook.js.org/docs/writing-stories/args -->
25+
<Story name="Primary" args={{ primary: true, label: 'Button' }} />
26+
27+
<Story name="Secondary" args={{ label: 'Button' }} />
28+
29+
<Story name="Large" args={{ size: 'large', label: 'Button' }} />
30+
31+
<Story name="Small" args={{ size: 'small', label: 'Button' }} />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script lang="ts">
2+
import './button.css';
3+
4+
interface Props {
5+
/** Is this the principal call to action on the page? */
6+
primary?: boolean;
7+
/** What background color to use */
8+
backgroundColor?: string;
9+
/** How large should the button be? */
10+
size?: 'small' | 'medium' | 'large';
11+
/** Button contents */
12+
label: string;
13+
/** The onclick event handler */
14+
onClick?: () => void;
15+
}
16+
17+
const { primary = false, backgroundColor, size = 'medium', label, onClick }: Props = $props();
18+
</script>
19+
20+
<button
21+
type="button"
22+
class={['storybook-button', `storybook-button--${size}`].join(' ')}
23+
class:storybook-button--primary={primary}
24+
class:storybook-button--secondary={!primary}
25+
style:background-color={backgroundColor}
26+
onclick={onClick}
27+
>
28+
{label}
29+
</button>

0 commit comments

Comments
 (0)