-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup storybook+vite as the components package base (#37)
- Loading branch information
Showing
32 changed files
with
3,284 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } }, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
...s/circle-react-components/src/components/NativeTransferForm/NativeTransferForm.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/circle-react-components/src/components/NativeTransferForm/NativeTransferForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
packages/circle-react-components/src/components/WalletBalance/WalletBalance.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/circle-react-components/src/components/WalletBalance/WalletBalance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/circle-react-components/src/components/WalletBalance/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './WalletBalance'; |
Oops, something went wrong.