Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Storybook #765

Merged
merged 24 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ package-lock.json
# VitePress
docs/.vitepress/cache
docs/.vitepress/dist

*storybook.log
storybook-static/
18 changes: 18 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
'@storybook/addon-a11y',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
};

export default config;
16 changes: 16 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Preview } from '@storybook/react';
import '../src/styles.css';

const preview: Preview = {
parameters: {
layout: 'centered',
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"coverage",
"esm",
"framegear",
"dist",
"site/docs/dist/"
]
}
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"repository": "https://github.com/coinbase/onchainkit.git",
"license": "MIT",
"scripts": {
"build": "packemon build --addEngines --addFiles --declaration && npx packemon validate --no-license --no-people --no-repo && tailwindcss -i ./src/styles/index.css -o ./src/tailwind.css --minify && tailwindcss -i ./src/styles/index-with-tailwind.css -o ./src/styles.css --minify",
"build": "yarn build:ts && yarn build:css",
"build:ts": "packemon build --addEngines --addFiles --declaration && npx packemon validate --no-license --no-people --no-repo",
"build:css": "tailwindcss -i ./src/styles/index.css -o ./src/tailwind.css --minify && tailwindcss -i ./src/styles/index-with-tailwind.css -o ./src/styles.css --minify",
"ci:format": "biome ci --linter-enabled=false --organize-imports-enabled=false",
"ci:lint": "biome ci --formatter-enabled=false --organize-imports-enabled=false",
"format": "biome format --write .",
"lint": "biome lint --write .",
"lint:unsafe": "biome lint --write --unsafe .",
"storybook:dev": "storybook dev -p 6006",
"storybook:build": "storybook build",
"storybook:test": "test-storybook",
"test": "jest",
"test:coverage": "jest . --coverage ",
"release:check": "changeset status --verbose --since=origin/main",
Expand Down Expand Up @@ -38,6 +43,16 @@
"@biomejs/biome": "^1.8.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@chromatic-com/storybook": "^1.6.1",
"@storybook/addon-a11y": "^8.1.11",
"@storybook/addon-essentials": "^8.1.11",
"@storybook/addon-interactions": "^8.1.11",
"@storybook/addon-links": "^8.1.11",
"@storybook/blocks": "^8.1.11",
"@storybook/react": "^8.1.11",
"@storybook/react-vite": "^8.1.11",
"@storybook/test": "^8.1.11",
"@storybook/test-runner": "^0.19.0",
"@tanstack/react-query": "^5.24.1",
"@testing-library/jest-dom": "^6.4.0",
"@testing-library/react": "^14.2.0",
Expand All @@ -56,10 +71,12 @@
"react": "^18",
"react-dom": "^18",
"rimraf": "^5.0.5",
"storybook": "^8.1.11",
"tailwindcss": "^3.4.3",
"ts-jest": "^29.1.2",
"typescript": "~5.3.3",
"viem": "^2.10.5",
"vite": "^5.3.3",
"wagmi": "^2.8.7"
},
"resolutions": {
Expand Down
18 changes: 18 additions & 0 deletions src/identity/components/Address.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Address } from './Address';

const meta = {
title: 'Identity/Address',
component: Address,
tags: ['autodocs'],
argTypes: {},
args: {
address: '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1',
},
} satisfies Meta<typeof Address>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
72 changes: 72 additions & 0 deletions src/identity/components/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Meta, StoryObj } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Avatar } from './Avatar';
import { Badge } from './Badge';
import { OnchainKitProvider } from '../../OnchainKitProvider';
import { base } from 'viem/chains';

const meta = {
title: 'Identity/Avatar',
component: Avatar,
decorators: [
(Story) => {
return (
<QueryClientProvider client={new QueryClient()}>
<Story />
</QueryClientProvider>
);
},
],
tags: ['autodocs'],
args: {
address: '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1',
},
} satisfies Meta<typeof Avatar>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};

export const Loading: Story = {
args: {
loadingComponent: <div>...</div>,
},
};

export const Fallback: Story = {
args: {
address: '0x1234567891234567881234567891234567891234',
defaultComponent: (
<div
style={{
width: '32px',
height: '32px',
border: '3px solid red',
borderRadius: '50%',
}}
/>
),
},
};

export const WithBadge: Story = {
decorators: [
(Story) => {
return (
<QueryClientProvider client={new QueryClient()}>
<OnchainKitProvider
chain={base}
schemaId="0xf8b05c79f090979bf4a80270aba232dff11a10d9ca55c4f88de95317970f0de9"
>
<Story />
</OnchainKitProvider>
</QueryClientProvider>
);
},
],
args: {
children: <Badge />,
},
};
14 changes: 14 additions & 0 deletions src/identity/components/Badge.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Badge } from './Badge';

const meta = {
title: 'Identity/Badge',
component: Badge,
tags: ['autodocs'],
} satisfies Meta<typeof Badge>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
38 changes: 38 additions & 0 deletions src/identity/components/EthBalance.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Meta, StoryObj } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { EthBalance } from './EthBalance';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { baseSepolia } from 'viem/chains';

const wagmiConfig = createConfig({
chains: [baseSepolia],
transports: {
[baseSepolia.id]: http(),
},
});

const meta = {
title: 'Identity/EthBalance',
component: EthBalance,
decorators: [
(Story) => {
return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={new QueryClient()}>
<Story />
</QueryClientProvider>
</WagmiProvider>
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this to preview.ts as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd favor explicitness because:

  • Not every components needs to be wrapped inside
  • Some components only need to be wrapped inside QueryClientProvider

More verbose but it's clear what's needed when reading stories.

);
},
],
tags: ['autodocs'],
args: {
address: '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1',
},
} satisfies Meta<typeof EthBalance>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
35 changes: 35 additions & 0 deletions src/identity/components/Name.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta, StoryObj } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Name } from './Name';

const meta = {
title: 'Identity/Name',
component: Name,
decorators: [
(Story) => {
return (
<QueryClientProvider client={new QueryClient()}>
<Story />
</QueryClientProvider>
);
},
],
tags: ['autodocs'],
args: {
address: '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1',
sliced: false,
},
} satisfies Meta<typeof Name>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};

export const Sliced: Story = {
args: {
address: '0x1234567891234567881234567891234567891234',
sliced: true,
},
};
1 change: 1 addition & 0 deletions src/styles/tailwind-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
}

@tailwind utilities;
@tailwind components;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? @roushou

We have not see the need to have those in a Tailwind application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right it's not needed here. I added it because I'm used to have it and I often define custom classes in @layer components but there's none in OnchainKit.

46 changes: 46 additions & 0 deletions src/swap/components/SwapButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Meta, StoryObj } from '@storybook/react';
import { SwapProvider } from './SwapProvider';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { baseSepolia } from 'viem/chains';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SwapButton } from './SwapButton';
import { fn } from '@storybook/test';

const wagmiConfig = createConfig({
chains: [baseSepolia],
transports: {
[baseSepolia.id]: http(),
},
});

const meta = {
title: 'Swap/Button',
decorators: [
(Story) => (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={new QueryClient()}>
<SwapProvider address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1">
<Story />
</SwapProvider>
</QueryClientProvider>
</WagmiProvider>
),
],
component: SwapButton,
tags: ['autodocs'],
argTypes: {
className: {
control: 'text',
},
},
args: {
disabled: true,
onSubmit: fn(),
},
} satisfies Meta<typeof SwapButton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
36 changes: 36 additions & 0 deletions src/swap/components/SwapToggleButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Meta, StoryObj } from '@storybook/react';
import { SwapToggleButton } from './SwapToggleButton';
import { SwapProvider } from './SwapProvider';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { baseSepolia } from 'viem/chains';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const wagmiConfig = createConfig({
chains: [baseSepolia],
transports: {
[baseSepolia.id]: http(),
},
});

const meta = {
title: 'Swap/ToggleButton',
decorators: [
(Story) => (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={new QueryClient()}>
<SwapProvider address="0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1">
<Story />
</SwapProvider>
</QueryClientProvider>
</WagmiProvider>
),
],
component: SwapToggleButton,
tags: ['autodocs'],
} satisfies Meta<typeof SwapToggleButton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
17 changes: 17 additions & 0 deletions src/token/components/SearchIcon.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import { SearchIcon } from './SearchIcon';

const meta = {
title: 'Token/SearchIcon',
component: SearchIcon,
tags: ['autodocs'],
argTypes: {},
args: { onClick: fn() },
} satisfies Meta<typeof SearchIcon>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
Loading
Loading