Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#43] Storybook 을 도입하여 Atoms 컴포넌트 관리 #45

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .ladle/UnoptimizedImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const UnoptimizedImage = (props: any) => {
return <img {...props} />;
};
export default UnoptimizedImage;
4 changes: 4 additions & 0 deletions .ladle/UnoptimizedLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const UnoptimizedLink = (props: any) => {
return <a {...props} />;
};
export default UnoptimizedLink;
6 changes: 6 additions & 0 deletions .ladle/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import type { GlobalProvider } from '@ladle/react';

import '@/styles/globals.css';

export const Provider: GlobalProvider = ({ children }) => <>{children}</>;
8,584 changes: 6,310 additions & 2,274 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"docker:build": "DOCKER_BUILDKIT=1 docker build -t scrum-dice --secret id=npm,src=./.npmrc .",
"docker:run": "docker run --env-file=.env --rm --name scrum-dice -p 3000:3000 -d scrum-dice",
"docker:stop": "docker stop scrum-dice",
"docker:dev": "docker-compose rm -fsv && COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build && docker-compose up && docker-compose rm -fsv"
"docker:dev": "docker-compose rm -fsv && COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build && docker-compose up && docker-compose rm -fsv",
"story": "ladle serve"
},
"dependencies": {
"@ladle/react": "^2.12.2",
"@types/node": "18.15.10",
"@types/react": "18.0.29",
"@types/react-dom": "18.0.11",
Expand Down
6 changes: 5 additions & 1 deletion src/components/atoms/button/CountDownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classnames from 'classnames';

import { ButtonProps } from './Button';

type CountDownButtonProps = ButtonProps & {
export type CountDownButtonProps = ButtonProps & {
counter: number;
onReset?: () => void;
};
Expand All @@ -12,6 +12,10 @@ export const CountDownButton = ({ children, className, counter, onReset, ...prop
const [count, setCount] = useState(counter);
const [isCounting, setIsCounting] = useState(false);

useEffect(() => {
setCount(counter);
}, [counter]);

useEffect(() => {
let intervalId: NodeJS.Timeout;
if (isCounting) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/button/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classnames from 'classnames';

import { ButtonProps } from './Button';

type LinkButtonProps = ButtonProps &
export type LinkButtonProps = ButtonProps &
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'target' | 'href'> & {
href: string;
target?: '_blank' | '_self';
Expand Down
44 changes: 44 additions & 0 deletions src/components/atoms/button/atoms-Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Button as ButtonComponent } from './Button';
import { CountDownButton as CountDownButtonComponent } from './CountDownButton';
import { LinkButton as LinkButtonComponent } from './LinkButton';

import type { ButtonProps, CountDownButtonProps, LinkButtonProps } from './index';
import type { Story } from '@ladle/react';

export const Button: Story<ButtonProps> = props => <ButtonComponent {...props}>button</ButtonComponent>;
export const CountDownButton: Story<CountDownButtonProps> = props => <CountDownButtonComponent {...props} />;
export const LinkButton: Story<LinkButtonProps> = props => (
<LinkButtonComponent {...props}>{props.href}</LinkButtonComponent>
);

Button.args = {
disabled: false,
loading: false,
};

Button.argTypes = {
state: {
options: ['info', 'success', 'warning', 'error'],
control: { type: 'inline-radio' },
defaultValue: 'info',
},
};

CountDownButton.argTypes = {
counter: {
control: { type: 'range', min: 1, max: 180, step: 1 },
defaultValue: 90,
},
};

LinkButton.args = {
href: 'https://www.google.com/',
};

LinkButton.argTypes = {
target: {
options: ['_blank', '_self'],
control: { type: 'inline-radio' },
defaultValue: '_blank',
},
};
6 changes: 3 additions & 3 deletions src/components/atoms/button/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Button } from './Button';
export { LinkButton } from './LinkButton';
export { CountDownButton } from './CountDownButton';
export * from './Button';
export * from './LinkButton';
export * from './CountDownButton';
23 changes: 0 additions & 23 deletions src/components/atoms/button/link_button.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/atoms/card/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Card } from './Card';
export * from './Card';
Empty file.
2 changes: 1 addition & 1 deletion src/components/atoms/title/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HTMLAttributes } from 'react';
import classnames from 'classnames';

type TitleProps = HTMLAttributes<HTMLHeadingElement> & {
export type TitleProps = HTMLAttributes<HTMLHeadingElement> & {
headingLevel: 'h1' | 'h2' | 'h3';
emoji?: string;
};
Expand Down
17 changes: 17 additions & 0 deletions src/components/atoms/title/atoms-Title.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Title } from './Title';

import type { TitleProps } from './Title';
import type { Story } from '@ladle/react';

export const h1: Story<TitleProps> = () => <Title headingLevel="h1">h1 : text-5xl</Title>;
export const h2: Story<TitleProps> = () => <Title headingLevel="h2">h2 : text-4xl</Title>;
export const h3: Story<TitleProps> = () => <Title headingLevel="h3">h2 : text-3xl</Title>;
export const EmojiWithTitle: Story<TitleProps> = ({ emoji }) => (
<Title headingLevel="h3" emoji={emoji}>
h2 : text-3xl
</Title>
);

EmojiWithTitle.args = {
emoji: '😎',
};
2 changes: 1 addition & 1 deletion src/components/atoms/title/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Title } from './Title';
export * from './Title';
4 changes: 1 addition & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default function Home() {
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={classNames(notoSansKr.className, lato.variable)}>
</main>
<main />
</>
);
}
11 changes: 11 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
resolve: {
alias: {
'next/image': path.resolve(__dirname, './.ladle/UnoptimizedImage.tsx'),
'next/link': path.resolve(__dirname, './.ladle/UnoptimizedLink.tsx'),
},
},
});