mirror of
https://github.com/ershisan99/lib-live-03-07.git
synced 2025-12-17 05:09:26 +00:00
working storybook
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
env: { browser: true, es2020: true },
|
env: { browser: true, es2020: true },
|
||||||
extends: [
|
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended', 'plugin:storybook/recommended'],
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:react-hooks/recommended',
|
|
||||||
],
|
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
plugins: ['react-refresh'],
|
plugins: ['react-refresh'],
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@ dist-ssr
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
|
*storybook.log
|
||||||
1
.ladle/components.tsx
Normal file
1
.ladle/components.tsx
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import "../src/index.css";
|
||||||
19
package.json
19
package.json
@@ -7,7 +7,9 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"storybook": "storybook dev -p 6006",
|
||||||
|
"build-storybook": "storybook build"
|
||||||
},
|
},
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -23,13 +25,24 @@
|
|||||||
"default": "./dist/index.cjs"
|
"default": "./dist/index.cjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"./css": "./dist/style.css"
|
"./style.css": "./dist/style.css"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@ladle/react": "^4.1.0",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1"
|
"react-dom": "^18.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@chromatic-com/storybook": "^1.6.1",
|
||||||
|
"@storybook/addon-essentials": "^8.2.7",
|
||||||
|
"@storybook/addon-interactions": "^8.2.7",
|
||||||
|
"@storybook/addon-links": "^8.2.7",
|
||||||
|
"@storybook/addon-onboarding": "^8.2.7",
|
||||||
|
"@storybook/blocks": "^8.2.7",
|
||||||
|
"@storybook/react": "^8.2.7",
|
||||||
|
"@storybook/react-vite": "^8.2.7",
|
||||||
|
"@storybook/test": "^8.2.7",
|
||||||
"@types/node": "^22.1.0",
|
"@types/node": "^22.1.0",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.3",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
@@ -39,7 +52,9 @@
|
|||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react-hooks": "^4.6.2",
|
"eslint-plugin-react-hooks": "^4.6.2",
|
||||||
"eslint-plugin-react-refresh": "^0.4.7",
|
"eslint-plugin-react-refresh": "^0.4.7",
|
||||||
|
"eslint-plugin-storybook": "^0.8.0",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
|
"storybook": "^8.2.7",
|
||||||
"typescript": "5.4.2",
|
"typescript": "5.4.2",
|
||||||
"vite": "^5.3.4",
|
"vite": "^5.3.4",
|
||||||
"vite-plugin-dts": "4.0.0-beta.2"
|
"vite-plugin-dts": "4.0.0-beta.2"
|
||||||
|
|||||||
7066
pnpm-lock.yaml
generated
7066
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
|||||||
import { ComponentPropsWithoutRef } from "react";
|
|
||||||
|
|
||||||
type Props = ComponentPropsWithoutRef<"button">;
|
|
||||||
|
|
||||||
export function Button(props: Props) {
|
|
||||||
console.log("button");
|
|
||||||
return <button {...props}>Hello World</button>;
|
|
||||||
}
|
|
||||||
28
src/components/button/button.module.css
Normal file
28
src/components/button/button.module.css
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
.buttonRoot {
|
||||||
|
all: unset;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonRoot.primary {
|
||||||
|
background-color: blue;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonRoot.secondary {
|
||||||
|
background-color: gray;
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonRoot:focus-visible{
|
||||||
|
outline: 2px solid blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonRoot.fullWidth {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
40
src/components/button/button.stories.tsx
Normal file
40
src/components/button/button.stories.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { Button } from "./button";
|
||||||
|
import { Meta, StoryObj } from "@storybook/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
component: Button,
|
||||||
|
title: "Components/Button",
|
||||||
|
} satisfies Meta<typeof Button>;
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
|
||||||
|
type Story = StoryObj<typeof meta>;
|
||||||
|
|
||||||
|
export const Primary: Story = {
|
||||||
|
args: {
|
||||||
|
variant: "primary",
|
||||||
|
children: "Primary",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Secondary: Story = {
|
||||||
|
args: {
|
||||||
|
variant: "secondary",
|
||||||
|
children: "Secondary",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FullWidth: Story = {
|
||||||
|
args: {
|
||||||
|
...Primary.args,
|
||||||
|
fullWidth: true,
|
||||||
|
children: "Full Width",
|
||||||
|
},
|
||||||
|
render: (args) => {
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
return (
|
||||||
|
<Button {...args} onClick={() => setCount(count + 1)} children={count} />
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
16
src/components/button/button.tsx
Normal file
16
src/components/button/button.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { ComponentPropsWithoutRef } from "react";
|
||||||
|
import s from "./button.module.css";
|
||||||
|
import clsx from "clsx";
|
||||||
|
type Props = ComponentPropsWithoutRef<"button"> & {
|
||||||
|
variant?: "primary" | "secondary";
|
||||||
|
fullWidth?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Button({ variant = "primary", fullWidth, ...props }: Props) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
{...props}
|
||||||
|
className={clsx(s.buttonRoot, s[variant], fullWidth && s.fullWidth)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
export * from "./button";
|
export * from "./button/button.tsx";
|
||||||
|
|||||||
4
src/index.css
Normal file
4
src/index.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
:root {
|
||||||
|
background-color: navy;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
@@ -1 +1,3 @@
|
|||||||
|
import "./index.css";
|
||||||
|
|
||||||
export * from "./components";
|
export * from "./components";
|
||||||
|
|||||||
Reference in New Issue
Block a user