Skip to content

Commit 6d9a12b

Browse files
committed
chore(plugin-git): add storybook setup
1 parent e354bdb commit 6d9a12b

7 files changed

Lines changed: 420 additions & 8 deletions

File tree

‎plugins/git/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ next-env.d.ts
44
node_modules
55
out
66
.turbo
7+
storybook-static

‎plugins/git/.storybook/main.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { StorybookConfig } from '@storybook/react-vite'
2+
import tailwindcss from '@tailwindcss/vite'
3+
4+
const config: StorybookConfig = {
5+
stories: ['../src/client/**/*.stories.@(ts|tsx)'],
6+
addons: ['@storybook/addon-docs', '@storybook/addon-a11y'],
7+
framework: {
8+
name: '@storybook/react-vite',
9+
options: {},
10+
},
11+
viteFinal(viteConfig) {
12+
viteConfig.plugins ??= []
13+
viteConfig.plugins.push(tailwindcss())
14+
return viteConfig
15+
},
16+
}
17+
18+
export default config

‎plugins/git/.storybook/preview.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { Decorator, Preview } from '@storybook/react-vite'
2+
import { useEffect } from 'react'
3+
import '../src/client/app/globals.css'
4+
5+
const withTheme: Decorator = (Story, context) => {
6+
const theme = context.globals.theme ?? 'dark'
7+
useEffect(() => {
8+
document.documentElement.classList.toggle('dark', theme === 'dark')
9+
}, [theme])
10+
return (
11+
<div className="bg-background text-foreground min-h-svh p-6">
12+
<div className="mx-auto max-w-2xl">
13+
<Story />
14+
</div>
15+
</div>
16+
)
17+
}
18+
19+
const preview: Preview = {
20+
parameters: {
21+
layout: 'fullscreen',
22+
controls: { expanded: true },
23+
},
24+
globalTypes: {
25+
theme: {
26+
description: 'Color theme',
27+
defaultValue: 'dark',
28+
toolbar: {
29+
title: 'Theme',
30+
icon: 'contrast',
31+
items: [
32+
{ value: 'light', title: 'Light', icon: 'sun' },
33+
{ value: 'dark', title: 'Dark', icon: 'moon' },
34+
],
35+
dynamicTitle: true,
36+
},
37+
},
38+
},
39+
decorators: [withTheme],
40+
}
41+
42+
export default preview

‎plugins/git/package.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"dev": "node scripts/dev.mjs",
4040
"dev:server": "node src/cli.ts",
4141
"dev:client": "next dev src/client",
42+
"storybook": "storybook dev -p 6006",
43+
"storybook:build": "storybook build -o storybook-static",
4244
"watch": "tsdown --watch",
4345
"prepack": "pnpm run build",
4446
"test": "vitest run"
@@ -52,7 +54,11 @@
5254
"@radix-ui/react-separator": "catalog:frontend",
5355
"@radix-ui/react-slot": "catalog:frontend",
5456
"@radix-ui/react-tabs": "catalog:frontend",
57+
"@storybook/addon-a11y": "catalog:frontend",
58+
"@storybook/addon-docs": "catalog:frontend",
59+
"@storybook/react-vite": "catalog:frontend",
5560
"@tailwindcss/postcss": "catalog:frontend",
61+
"@tailwindcss/vite": "catalog:frontend",
5662
"@types/react": "catalog:types",
5763
"@types/react-dom": "catalog:types",
5864
"class-variance-authority": "catalog:frontend",
@@ -63,6 +69,7 @@
6369
"next": "catalog:frontend",
6470
"react": "catalog:frontend",
6571
"react-dom": "catalog:frontend",
72+
"storybook": "catalog:frontend",
6673
"tailwind-merge": "catalog:frontend",
6774
"tailwindcss": "catalog:frontend",
6875
"tsdown": "catalog:build",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Meta, StoryObj } from '@storybook/react-vite'
2+
import type { Commit } from '../../../index'
3+
import { LogPanelView } from './log-panel-view'
4+
5+
const now = Date.now()
6+
7+
const commits: Commit[] = [
8+
{ hash: 'a1b2c3d4e5f6', shortHash: 'a1b2c3d', parents: ['b2c3d4e', 'c3d4e5f'], author: 'Ada Lovelace', email: 'ada@example.dev', date: now - 36e5, subject: 'Merge branch feature/graph into main', body: '', refs: ['HEAD -> main'] },
9+
{ hash: 'b2c3d4e', shortHash: 'b2c3d4e', parents: ['d4e5f60'], author: 'Ada Lovelace', email: 'ada@example.dev', date: now - 72e5, subject: 'Tidy up dashboard layout', body: '', refs: [] },
10+
{ hash: 'c3d4e5f', shortHash: 'c3d4e5f', parents: ['d4e5f60'], author: 'Lin Chen', email: 'lin@example.dev', date: now - 9e6, subject: 'Add commit graph lanes', body: '', refs: ['origin/feature/graph'] },
11+
{ hash: 'd4e5f60', shortHash: 'd4e5f60', parents: [], author: 'Ada Lovelace', email: 'ada@example.dev', date: now - 9e8, subject: 'Initial commit', body: '', refs: ['v0.1.0'] },
12+
]
13+
14+
const meta = {
15+
title: 'Panels/Log',
16+
component: LogPanelView,
17+
args: {
18+
rpcConnected: true,
19+
isRepo: true,
20+
commits,
21+
hasMore: false,
22+
loading: false,
23+
error: null,
24+
liveBackend: true,
25+
onRefresh: () => undefined,
26+
onLoadMore: () => undefined,
27+
},
28+
} satisfies Meta<typeof LogPanelView>
29+
30+
export default meta
31+
type Story = StoryObj<typeof meta>
32+
33+
export const Default: Story = {}
34+
export const Connecting: Story = { args: { rpcConnected: false } }
35+
export const Empty: Story = { args: { commits: [] } }
36+
export const NotARepo: Story = { args: { isRepo: false, commits: [] } }
37+
export const HasMore: Story = { args: { hasMore: true } }
38+
export const StaticMode: Story = { args: { hasMore: true, liveBackend: false } }
39+
export const Error: Story = { args: { error: 'fatal: bad revision' } }

0 commit comments

Comments
 (0)