Skip to content

Commit dd8b732

Browse files
committed
feat: migrate to vite and add storybook
1 parent 896fd94 commit dd8b732

35 files changed

+11680
-7523
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ parcel-bundle-reports
2626
npm-debug.log*
2727
yarn-debug.log*
2828
yarn-error.log*
29+
30+
*storybook.log

.lintstagedrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"**/*.{js,jsx,ts,tsx}": ["eslint"]
2+
"**/*.{js,jsx,ts,tsx}": ["eslint --fix"]
33
}

.storybook/main.ts

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

.storybook/preview.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Preview } from "@storybook/react";
2+
3+
const preview: Preview = {
4+
parameters: {
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/i,
9+
},
10+
},
11+
},
12+
};
13+
14+
export default preview;

package.json

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,41 @@
66
"main": "dist/index.js",
77
"types": "dist/types.d.ts",
88
"isLibrary": true,
9+
"type": "module",
910
"browserslist": "> 0.5%, last 2 versions, not dead",
1011
"repository": "git@github.com:kleros/ui-components-library",
1112
"author": "Kleros",
1213
"license": "MIT",
1314
"scripts": {
14-
"clear": "rm -r .parcel-cache",
15-
"clean": "rm dist/bundle.js",
16-
"start": "parcel src/index.html",
17-
"build": "parcel build",
18-
"prepare": "husky install",
15+
"build": "vite build",
16+
"build-storybook": "storybook build",
1917
"check-style": "eslint 'src/**/*.{ts,tsx}'",
20-
"check-types": "tsc --noEmit"
18+
"check-types": "tsc --noEmit",
19+
"clean": "rm -rf dist",
20+
"prepare": "husky install",
21+
"preview": "vite preview",
22+
"start": "vite",
23+
"storybook": "storybook dev -p 6006"
2124
},
2225
"files": [
2326
"dist"
2427
],
2528
"devDependencies": {
29+
"@chromatic-com/storybook": "^3.2.5",
2630
"@commitlint/cli": "^15.0.0",
2731
"@commitlint/config-conventional": "^15.0.0",
2832
"@eslint/compat": "^1.2.7",
2933
"@eslint/eslintrc": "^3.3.0",
3034
"@eslint/js": "^9.21.0",
31-
"@parcel/packager-ts": "^2.2.1",
32-
"@parcel/transformer-svg-react": "^2.0.1",
33-
"@parcel/transformer-typescript-types": "^2.2.1",
35+
"@storybook/addon-essentials": "^8.6.4",
36+
"@storybook/addon-interactions": "^8.6.4",
37+
"@storybook/addon-onboarding": "^8.6.4",
38+
"@storybook/blocks": "^8.6.4",
39+
"@storybook/react": "^8.6.4",
40+
"@storybook/react-vite": "^8.6.4",
41+
"@storybook/test": "^8.6.4",
3442
"@tailwindcss/postcss": "^4.0.11",
43+
"@types/node": "^22.13.10",
3544
"@types/react": "^18.0.9",
3645
"@types/react-dom": "^18.0.3",
3746
"@types/styled-components": "^5.1.20",
@@ -46,16 +55,19 @@
4655
"eslint-plugin-react": "^7.37.4",
4756
"eslint-plugin-react-hooks": "^5.2.0",
4857
"eslint-plugin-security": "^3.0.1",
58+
"eslint-plugin-storybook": "^0.11.4",
4959
"globals": "^16.0.0",
5060
"husky": "^7.0.0",
5161
"lint-staged": "^12.1.2",
52-
"parcel": "^2.13.3",
5362
"prettier": "^3.5.3",
5463
"prettier-plugin-tailwindcss": "^0.6.11",
5564
"process": "^0.11.10",
65+
"storybook": "^8.6.4",
5666
"styled-components": "^5.3.3",
5767
"tailwindcss": "^4.0.11",
58-
"typescript": "^5.8.2"
68+
"typescript": "^5.8.2",
69+
"vite": "^6.2.1",
70+
"vite-plugin-svgr": "^4.3.0"
5971
},
6072
"peerDependencies": {
6173
"@tailwindcss/postcss": "^4.0.11",
@@ -87,5 +99,10 @@
8799
"node": "20.18.3",
88100
"yarn": "1.22.19"
89101
},
90-
"packageManager": "yarn@1.22.19+sha256.732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e"
102+
"packageManager": "yarn@4.7.0",
103+
"eslintConfig": {
104+
"extends": [
105+
"plugin:storybook/recommended"
106+
]
107+
}
91108
}

src/stories/Button.stories.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { fn } from "@storybook/test";
3+
4+
import { Button } from "./Button";
5+
6+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
7+
const meta = {
8+
title: "Example/Button",
9+
component: Button,
10+
parameters: {
11+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
12+
layout: "centered",
13+
},
14+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
15+
tags: ["autodocs"],
16+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
17+
argTypes: {
18+
backgroundColor: { control: "color" },
19+
},
20+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
21+
args: { onClick: fn() },
22+
} satisfies Meta<typeof Button>;
23+
24+
export default meta;
25+
type Story = StoryObj<typeof meta>;
26+
27+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
28+
export const Primary: Story = {
29+
args: {
30+
primary: true,
31+
label: "Button",
32+
},
33+
};
34+
35+
export const Secondary: Story = {
36+
args: {
37+
label: "Button",
38+
},
39+
};
40+
41+
export const Large: Story = {
42+
args: {
43+
size: "large",
44+
label: "Button",
45+
},
46+
};
47+
48+
export const Small: Story = {
49+
args: {
50+
size: "small",
51+
label: "Button",
52+
},
53+
};

src/stories/Button.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
3+
import "./button.css";
4+
5+
export interface ButtonProps {
6+
/** Is this the principal call to action on the page? */
7+
primary?: boolean;
8+
/** What background color to use */
9+
backgroundColor?: string;
10+
/** How large should the button be? */
11+
size?: "small" | "medium" | "large";
12+
/** Button contents */
13+
label: string;
14+
/** Optional click handler */
15+
onClick?: () => void;
16+
}
17+
18+
/** Primary UI component for user interaction */
19+
export const Button = ({
20+
primary = false,
21+
size = "medium",
22+
backgroundColor,
23+
label,
24+
...props
25+
}: ButtonProps) => {
26+
const mode = primary
27+
? "storybook-button--primary"
28+
: "storybook-button--secondary";
29+
return (
30+
<button
31+
type="button"
32+
className={["storybook-button", `storybook-button--${size}`, mode].join(
33+
" ",
34+
)}
35+
style={{ backgroundColor }}
36+
{...props}
37+
>
38+
{label}
39+
</button>
40+
);
41+
};

0 commit comments

Comments
 (0)