Skip to content

Commit

Permalink
feat: setup storybook+vite as the components package base (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu authored Nov 21, 2024
1 parent 30a381b commit 3df3add
Show file tree
Hide file tree
Showing 32 changed files with 3,284 additions and 614 deletions.
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 90,
"tabWidth": 2,
"endOfLine": "auto",
"bracketSpacing": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"build": "yarn workspace web3-plugin-circle build",
"build:docs": "yarn workspace web3-plugin-circle build:docs",
"test": "yarn workspace web3-plugin-circle test"
}
},
"packageManager": "yarn@1.22.22"
}
26 changes: 26 additions & 0 deletions packages/circle-react-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

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

import { join, dirname } from 'path';

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string) {
return dirname(require.resolve(join(value, 'package.json')));
}
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [getAbsolutePath('@storybook/addon-essentials')],
framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
core: {
disableTelemetry: true,
},
};
export default config;
15 changes: 15 additions & 0 deletions packages/circle-react-components/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from '@storybook/react';
import '../src/index.css';

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

export default preview;
3 changes: 3 additions & 0 deletions packages/circle-react-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Circle React Components

A collection of components for building apps with [Circle](https://developers.circle.com/).
21 changes: 21 additions & 0 deletions packages/circle-react-components/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}
43 changes: 43 additions & 0 deletions packages/circle-react-components/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import globals from 'globals';
import js from '@eslint/js';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-plugin-prettier';

export default tseslint.config(
{ ignores: ['dist', '.storybook'] },
{
extends: [
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked, // or tseslint.configs.strictTypeChecked
...tseslint.configs.stylisticTypeChecked,
],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
react,
prettier,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
settings: { react: { version: '18.3' } },
},
);
13 changes: 13 additions & 0 deletions packages/circle-react-components/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions packages/circle-react-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "circle-react-components",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"prettier": "prettier . --write",
"preview": "vite preview",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.456.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@storybook/addon-essentials": "^8.4.2",
"@storybook/blocks": "^8.4.2",
"@storybook/react": "^8.4.2",
"@storybook/react-vite": "^8.4.2",
"@storybook/test": "^8.4.2",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"eslint": "^9.13.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-storybook": "^0.11.0",
"globals": "^15.11.0",
"postcss": "^8.4.48",
"prettier": "^3.3.3",
"storybook": "^8.4.2",
"tailwindcss": "^3.4.14",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
},
"eslintConfig": {
"extends": [
"plugin:storybook/recommended"
]
}
}
6 changes: 6 additions & 0 deletions packages/circle-react-components/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
18 changes: 18 additions & 0 deletions packages/circle-react-components/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { WalletBalance } from '@/components/WalletBalance';

export function App() {
const [count, setCount] = useState(0);

return (
<>
<h1 className="text-3xl font-bold">Vite + React</h1>
<div className="card">
<Button onClick={() => setCount((count) => count + 1)}>count is {count}</Button>
<WalletBalance />
</div>
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';

import { NativeTransferForm } from './NativeTransferForm';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: 'NativeTransferForm',
component: NativeTransferForm,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
// 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
args: { onClick: fn() },
} satisfies Meta<typeof NativeTransferForm>;

export default meta;
type Story = StoryObj<typeof meta>;

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Default: Story = {
args: {
label: 'NativeTransferForm',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Button } from '@/components/ui/button';

export const NativeTransferForm = () => {
return (
<Card>
<CardHeader>
<CardTitle>Card Title</CardTitle>
<CardDescription>Card Description</CardDescription>
</CardHeader>
<CardContent>
<p>Card Content</p>
</CardContent>
<CardFooter>
<Button>Submit</Button>
</CardFooter>
</Card>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react';

import { WalletBalance } from './WalletBalance';

const meta = {
title: 'WalletBalance',
component: WalletBalance,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof WalletBalance>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useCircleSdk } from '@/hooks/useCircleSdk';

export interface WalletBalanceProps {
format?: (balance: bigint) => string;
}

function defaultFormat(balance: bigint) {
return `${balance.toString()} ETH`;
}

export const WalletBalance = ({ format = defaultFormat }: WalletBalanceProps = {}) => {
const { client } = useCircleSdk();

return <span>{format(client.getBalance())}</span>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './WalletBalance';
Loading

0 comments on commit 3df3add

Please sign in to comment.