Skip to content

Commit 1649720

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 1649720

29 files changed

+5962
-1285
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.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { Preview } from '@storybook/nextjs-vite'
2+
import React, { ReactNode } from 'react'
3+
import '../src/app/globals.css'
4+
import { AgentsContext } from '../src/components/AgentsProvider'
5+
import type { AgentsContextType } from '../src/components/AgentsProvider'
6+
import type { Agent } from '../src/types'
7+
8+
const mockContextValue: AgentsContextType = {
9+
agents: [],
10+
models: [],
11+
loading: false,
12+
error: "",
13+
tools: [],
14+
refreshAgents: async () => {},
15+
refreshModels: async () => {},
16+
refreshTools: async () => {},
17+
createNewAgent: async () => ({ message: "mock", data: {} as Agent }),
18+
updateAgent: async () => ({ message: "mock", data: {} as Agent }),
19+
getAgent: async () => null,
20+
validateAgentData: () => ({}),
21+
};
22+
23+
interface MockAgentsProviderProps {
24+
children: ReactNode;
25+
value?: Partial<AgentsContextType>;
26+
}
27+
28+
function MockAgentsProvider({ children, value }: MockAgentsProviderProps) {
29+
return (
30+
<AgentsContext.Provider value={{ ...mockContextValue, ...value }}>
31+
{children}
32+
</AgentsContext.Provider>
33+
);
34+
}
35+
36+
const preview: Preview = {
37+
parameters: {
38+
nextjs: {
39+
appDirectory: true,
40+
},
41+
controls: {
42+
matchers: {
43+
color: /(background|color)$/i,
44+
date: /Date$/i,
45+
},
46+
},
47+
a11y: {
48+
test: 'todo'
49+
}
50+
},
51+
decorators: [
52+
(Story) => {
53+
document.documentElement.classList.add('dark');
54+
return (
55+
<MockAgentsProvider>
56+
<Story />
57+
</MockAgentsProvider>
58+
);
59+
},
60+
],
61+
};
62+
63+
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)