Skip to content

Commit 831bd55

Browse files
committed
Add a storybook for the Vue side
1 parent 7059687 commit 831bd55

5 files changed

Lines changed: 731 additions & 0 deletions

File tree

.storybook/main.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type {StorybookConfig} from '@storybook/vue3-vite';
2+
import {dirname, join} from 'path';
3+
import {mergeConfig} from 'vite';
4+
import vue from '@vitejs/plugin-vue';
5+
import tailwindcss from '@tailwindcss/vite';
6+
7+
/**
8+
* This function is used to resolve the absolute path of a package.
9+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
10+
*/
11+
function getAbsolutePath(value: string): string {
12+
return dirname(require.resolve(join(value, 'package.json')));
13+
}
14+
15+
const config: StorybookConfig = {
16+
stories: ['../resources/js/**/*.mdx', '../resources/js/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
17+
addons: [
18+
getAbsolutePath('@storybook/addon-themes'),
19+
getAbsolutePath('@storybook/addon-docs'),
20+
getAbsolutePath('@storybook/addon-a11y'),
21+
],
22+
framework: {
23+
name: getAbsolutePath('@storybook/vue3-vite') as '@storybook/vue3-vite',
24+
options: {},
25+
},
26+
viteFinal(config) {
27+
return mergeConfig(config, {
28+
plugins: [
29+
tailwindcss(),
30+
vue({
31+
template: {
32+
compilerOptions: {
33+
// Treat craft-* tags as custom elements (web components from @craftcms/cp)
34+
isCustomElement: (tag) => tag.startsWith('craft-'),
35+
},
36+
},
37+
}),
38+
],
39+
resolve: {
40+
alias: {
41+
'@': join(__dirname, '../resources/js'),
42+
vue: 'vue/dist/vue.esm-bundler.js',
43+
},
44+
},
45+
});
46+
},
47+
};
48+
49+
export default config;

.storybook/preview.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Storybook preview utilities */
2+
3+
/* Layout helpers for stories */
4+
.sb-flex {
5+
display: flex;
6+
}
7+
8+
.sb-flex-col {
9+
flex-direction: column;
10+
}
11+
12+
.sb-items-center {
13+
align-items: center;
14+
}
15+
16+
.sb-justify-center {
17+
justify-content: center;
18+
}
19+
20+
.sb-gap-2 {
21+
gap: 0.5rem;
22+
}
23+
24+
.sb-gap-4 {
25+
gap: 1rem;
26+
}
27+
28+
.sb-p-4 {
29+
padding: 1rem;
30+
}
31+
32+
/* Grid utilities */
33+
.sb-grid {
34+
display: grid;
35+
}
36+
37+
.sb-grid-cols-2 {
38+
grid-template-columns: repeat(2, 1fr);
39+
}
40+
41+
.sb-grid-cols-3 {
42+
grid-template-columns: repeat(3, 1fr);
43+
}
44+
45+
/* Stack layout */
46+
.sb-stack {
47+
display: flex;
48+
flex-direction: column;
49+
gap: 1rem;
50+
}
51+
52+
.sb-inline {
53+
display: flex;
54+
flex-wrap: wrap;
55+
gap: 0.5rem;
56+
align-items: center;
57+
}

.storybook/preview.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type {Preview} from '@storybook/vue3';
2+
import {withThemeByDataAttribute} from '@storybook/addon-themes';
3+
import '../resources/css/cp.css';
4+
import './preview.css';
5+
6+
const preview: Preview = {
7+
parameters: {
8+
controls: {
9+
expanded: true,
10+
matchers: {
11+
color: /(background|color)$/i,
12+
date: /Date$/i,
13+
},
14+
},
15+
options: {
16+
storySort: {
17+
method: 'alphabetical',
18+
},
19+
},
20+
a11y: {
21+
// 'todo' - show a11y violations in the test UI only
22+
// 'error' - fail CI on a11y violations
23+
// 'off' - skip a11y checks entirely
24+
test: 'todo',
25+
},
26+
},
27+
decorators: [
28+
withThemeByDataAttribute({
29+
themes: {
30+
light: 'light',
31+
dark: 'dark',
32+
},
33+
defaultTheme: 'light',
34+
attributeName: 'data-theme',
35+
}),
36+
],
37+
tags: ['autodocs'],
38+
};
39+
40+
export default preview;

0 commit comments

Comments
 (0)