Skip to content

Commit 5b3e177

Browse files
committed
feat(component-library): initialize component library
1 parent 29e5c9b commit 5b3e177

29 files changed

+5469
-387
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ patches/
1919
apps/api-reference
2020
apps/staking
2121
governance/pyth_staking_sdk
22+
packages/component-library
23+
packages/fonts
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage/
2+
node_modules/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { createRequire } from "node:module";
2+
3+
import type { StorybookConfig } from "@storybook/nextjs";
4+
5+
const resolve = createRequire(import.meta.url).resolve;
6+
7+
const config = {
8+
framework: "@storybook/nextjs",
9+
10+
stories: [
11+
"../src/**/*.mdx",
12+
"../src/**/?(*.)story.tsx",
13+
"../src/**/?(*.)stories.tsx",
14+
],
15+
16+
addons: [
17+
"@storybook/addon-essentials",
18+
"@storybook/addon-themes",
19+
{
20+
name: "@storybook/addon-styling-webpack",
21+
options: {
22+
rules: [
23+
{
24+
test: /\.css$/,
25+
use: [
26+
"style-loader",
27+
{
28+
loader: "css-loader",
29+
options: { importLoaders: 1 },
30+
},
31+
{
32+
loader: "postcss-loader",
33+
options: { implementation: resolve("postcss") },
34+
},
35+
],
36+
},
37+
],
38+
},
39+
},
40+
],
41+
42+
webpackFinal: (config) => ({
43+
...config,
44+
resolve: {
45+
...config.resolve,
46+
extensionAlias: {
47+
".js": [".js", ".ts", ".tsx"],
48+
},
49+
},
50+
}),
51+
} satisfies StorybookConfig;
52+
export default config;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {
4+
config: `${__dirname}/../tailwind.config.ts`,
5+
},
6+
autoprefixer: {},
7+
},
8+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { sans } from "@pythnetwork/fonts";
2+
import { withThemeByClassName } from "@storybook/addon-themes";
3+
import type { Preview, Decorator } from "@storybook/react";
4+
import { useEffect } from "react";
5+
6+
import "./tailwind.css";
7+
8+
const preview = {
9+
parameters: {
10+
backgrounds: { disable: true },
11+
actions: { argTypesRegex: "^on[A-Z].*" },
12+
},
13+
} satisfies Preview;
14+
15+
export default preview;
16+
17+
const withRootClasses =
18+
(...classes: string[]): Decorator =>
19+
(storyFn) => {
20+
useEffect(() => {
21+
const root = document.querySelector("html");
22+
const classList = classes
23+
.flatMap((cls) => cls.split(" "))
24+
.filter(Boolean);
25+
if (root) {
26+
root.classList.add(...classList);
27+
return () => {
28+
root.classList.remove(...classList);
29+
};
30+
} else {
31+
return;
32+
}
33+
}, []);
34+
return storyFn();
35+
};
36+
37+
export const decorators: Decorator[] = [
38+
withRootClasses("font-sans antialiased", sans.variable),
39+
withThemeByClassName({
40+
themes: {
41+
white: "light bg-white",
42+
light: "light bg-beige-50",
43+
dark: "dark bg-steel-800",
44+
darker: "dark bg-steel-900",
45+
},
46+
defaultTheme: "light",
47+
}),
48+
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

packages/component-library/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @pythnetwork/component-library
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { fileURLToPath } from "node:url";
2+
3+
import { react, tailwind, storybook } from "@cprussin/eslint-config";
4+
5+
const config = [
6+
...react,
7+
...tailwind(fileURLToPath(import.meta.resolve("./tailwind.config.ts"))),
8+
...storybook,
9+
];
10+
export default config;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { base as default } from "@cprussin/jest-config";
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@pythnetwork/component-library",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build:storybook": "storybook build",
8+
"fix": "pnpm fix:lint && pnpm fix:format",
9+
"fix:format": "prettier --write .",
10+
"fix:lint": "eslint --fix .",
11+
"start:storybook": "storybook dev --port 4000 --no-open",
12+
"test": "pnpm test:types && pnpm test:lint && pnpm test:format",
13+
"test:format": "prettier --check .",
14+
"test:lint": "jest --selectProjects lint",
15+
"test:types": "tsc"
16+
},
17+
"peerDependencies": {
18+
"react": "^18.3.1"
19+
},
20+
"dependencies": {
21+
"clsx": "^2.1.1",
22+
"react-aria": "^3.35.0",
23+
"react-aria-components": "^1.4.0"
24+
},
25+
"devDependencies": {
26+
"@cprussin/eslint-config": "^3.0.0",
27+
"@cprussin/jest-config": "^1.4.1",
28+
"@cprussin/prettier-config": "^2.1.1",
29+
"@cprussin/tsconfig": "^3.0.1",
30+
"@phosphor-icons/react": "^2.1.7",
31+
"@pythnetwork/fonts": "workspace:^",
32+
"@storybook/addon-essentials": "^8.3.5",
33+
"@storybook/addon-styling-webpack": "^1.0.0",
34+
"@storybook/addon-themes": "^8.3.5",
35+
"@storybook/blocks": "^8.3.5",
36+
"@storybook/nextjs": "^8.3.5",
37+
"@storybook/react": "^8.3.5",
38+
"@tailwindcss/forms": "^0.5.9",
39+
"@types/jest": "^29.5.13",
40+
"@types/react": "^18.3.11",
41+
"autoprefixer": "^10.4.20",
42+
"css-loader": "^7.1.2",
43+
"eslint": "^9.12.0",
44+
"jest": "^29.7.0",
45+
"postcss": "^8.4.47",
46+
"postcss-loader": "^8.1.1",
47+
"prettier": "^3.3.3",
48+
"react": "^18.3.1",
49+
"storybook": "^8.3.5",
50+
"style-loader": "^4.0.0",
51+
"tailwindcss": "^3.4.13",
52+
"tailwindcss-animate": "^1.0.7",
53+
"tailwindcss-react-aria-components": "^1.1.6",
54+
"typescript": "^5.6.3"
55+
}
56+
}

0 commit comments

Comments
 (0)