Skip to content

Commit bfdfe2c

Browse files
committed
Add storybook
When working on UI elements it is a lot easier to iterate and test in storybook where you can put up the interesting cases as stories and browse through them instead of having construct scenarios in a live running app. Signed-off-by: Dobes Vandermeer <dobes.vandermeer@newsela.com>
1 parent 8e680af commit bfdfe2c

28 files changed

+5874
-1283
lines changed

ui/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
43+
# storybook
44+
/storybook-static

ui/.storybook/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { StorybookConfig } from '@storybook/nextjs-vite';
2+
3+
const config: StorybookConfig = {
4+
"stories": [
5+
"../src/**/*.mdx",
6+
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
7+
],
8+
"addons": [
9+
"@chromatic-com/storybook",
10+
"@storybook/addon-vitest",
11+
"@storybook/addon-a11y",
12+
"@storybook/addon-docs",
13+
"@storybook/addon-onboarding"
14+
],
15+
"framework": "@storybook/nextjs-vite"
16+
};
17+
export default config;

ui/.storybook/preview.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Preview } from '@storybook/nextjs-vite'
2+
import '../src/app/globals.css'
3+
4+
const preview: Preview = {
5+
parameters: {
6+
controls: {
7+
matchers: {
8+
color: /(background|color)$/i,
9+
date: /Date$/i,
10+
},
11+
},
12+
a11y: {
13+
test: 'todo'
14+
}
15+
},
16+
decorators: [
17+
(Story) => {
18+
document.documentElement.classList.add('dark');
19+
return Story();
20+
},
21+
],
22+
};
23+
24+
export default preview;

ui/.storybook/vitest.setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview";
2+
import { setProjectAnnotations } from '@storybook/nextjs-vite';
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+
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]);

ui/eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
2+
import storybook from "eslint-plugin-storybook";
3+
14
import { defineConfig, globalIgnores } from "eslint/config";
25
import nextVitals from "eslint-config-next/core-web-vitals";
36
import nextTs from "eslint-config-next/typescript";
@@ -27,6 +30,7 @@ const eslintConfig = defineConfig([
2730
"build/**",
2831
"next-env.d.ts",
2932
]),
33+
...storybook.configs["flat/recommended"],
3034
]);
3135

3236
export default eslintConfig;

0 commit comments

Comments
 (0)