-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Feature] 디자인 시스템 기반 컴포넌트 일부 구현 #8
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Binary file not shown.
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,7 @@ | ||
import localFont from 'next/font/local' | ||
|
||
export const pretendard = localFont({ | ||
src: './PretendardVariable.woff2', | ||
display: 'swap', | ||
weight: '45 920', | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import './storybook.css' | ||
|
||
const preview = { | ||
parameters: { | ||
controls: { | ||
|
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,36 @@ | ||
@import url('https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-dynamic-subset.min.css'); | ||
|
||
* { | ||
font-family: 'Pretendard', 'Noto Sans KR', sans-serif; | ||
} | ||
|
||
.storybook-list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
.storybook-subtitle { | ||
margin-bottom: 8px; | ||
color: rgb(157, 157, 157); | ||
font-weight: 700; | ||
} | ||
|
||
.navy-background { | ||
background-color: #0e0933; | ||
} | ||
|
||
.default-padding { | ||
padding: 50px; | ||
} | ||
|
||
.section-wrapper { | ||
width: 1280px; | ||
} | ||
|
||
#storybook-root { | ||
position: relative; | ||
} |
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 |
---|---|---|
|
@@ -44,5 +44,8 @@ | |
"workspaces": [ | ||
"apps/*", | ||
"packages/*" | ||
] | ||
], | ||
"dependencies": { | ||
"@testing-library/user-event": "^14.5.2" | ||
} | ||
} |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
packages/ui/package.json → packages/design-system/package.json
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
87 changes: 87 additions & 0 deletions
87
packages/design-system/src/components/Button/Button.css.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,87 @@ | ||
import { recipe, RecipeVariants } from '@vanilla-extract/recipes' | ||
|
||
import { vars } from '../../styles/global.css' | ||
|
||
export const button = recipe({ | ||
base: { | ||
border: 'none', | ||
borderRadius: 6, | ||
}, | ||
variants: { | ||
size: { | ||
large: { | ||
height: 48, | ||
padding: '12px 26px', | ||
}, | ||
middle: { | ||
height: 40, | ||
padding: '8px 16px', | ||
}, | ||
small: { | ||
height: 34, | ||
padding: '8px 14px', | ||
}, | ||
mini: { | ||
height: 30, | ||
padding: '6px 10px', | ||
borderRadius: 4, | ||
}, | ||
}, | ||
filled: { | ||
true: { | ||
backgroundColor: vars.colors['semantic-primary-normal'], | ||
color: vars.colors['common-white'], | ||
}, | ||
false: { | ||
backgroundColor: 'transparent', | ||
borderWidth: 1, | ||
borderStyle: 'solid', | ||
}, | ||
}, | ||
blueLine: { | ||
true: { | ||
borderColor: vars.colors['semantic-primary-normal'], | ||
}, | ||
false: { | ||
borderColor: vars.colors['semantic-line-normal'], | ||
}, | ||
}, | ||
disabled: { | ||
true: { | ||
borderColor: vars.colors['palette-gray-100'], | ||
':hover': { | ||
cursor: 'not-allowed', | ||
}, | ||
}, | ||
false: { | ||
':hover': { | ||
cursor: 'pointer', | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
compoundVariants: [ | ||
{ | ||
variants: { | ||
filled: true, | ||
disabled: true, | ||
}, | ||
style: { | ||
backgroundColor: vars.colors['palette-gray-100'], | ||
color: vars.colors['semantic-label-disabled'], | ||
}, | ||
}, | ||
{ | ||
variants: { | ||
filled: false, | ||
disabled: true, | ||
}, | ||
style: { | ||
color: vars.colors['semantic-label-disabled'], | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
export type ButtonVariants = RecipeVariants<typeof button> |
46 changes: 46 additions & 0 deletions
46
packages/design-system/src/components/Button/Button.spec.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,46 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import { Button } from '.' | ||
|
||
describe('Button Test', () => { | ||
it('Button은 정상적으로 렌더링된다.', () => { | ||
render(<Button>Button</Button>) | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: /Button/i, | ||
}), | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('Button 클릭 시 onClick 함수가 실행된다.', async () => { | ||
// given | ||
const onClick = vi.fn() | ||
render(<Button onClick={onClick}>Button</Button>) | ||
|
||
// when | ||
const button = screen.getByRole('button') | ||
await userEvent.click(button) | ||
|
||
// then | ||
expect(onClick).toBeCalledTimes(1) | ||
}) | ||
|
||
it('Button은 disabled 상태일 때 클릭되지 않는다.', async () => { | ||
// given | ||
const onClick = vi.fn() | ||
render( | ||
<Button onClick={onClick} disabled> | ||
Button | ||
</Button>, | ||
) | ||
|
||
// when | ||
const button = screen.getByRole('button') | ||
await userEvent.click(button) | ||
|
||
// then | ||
expect(onClick).not.toBeCalled() | ||
}) | ||
}) |
126 changes: 126 additions & 0 deletions
126
packages/design-system/src/components/Button/Button.stories.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,126 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { Button, ButtonProps } from './Button' | ||
|
||
const BUTTON_SIZES: Array<ButtonProps['size']> = [ | ||
'large', | ||
'middle', | ||
'small', | ||
'mini', | ||
] | ||
|
||
const meta = { | ||
title: 'Button', | ||
component: Button, | ||
tags: ['autodocs'], | ||
args: { | ||
children: 'Button', | ||
size: 'large', | ||
filled: true, | ||
blueLine: true, | ||
disabled: false, | ||
}, | ||
argTypes: { | ||
children: { control: 'text', description: '버튼 텍스트' }, | ||
size: { | ||
options: BUTTON_SIZES, | ||
control: { type: 'select' }, | ||
description: '버튼 크기', | ||
}, | ||
filled: { control: 'boolean', description: '버튼 색상 채움 여부' }, | ||
blueLine: { | ||
control: 'boolean', | ||
description: '버튼 테두리 여부', | ||
}, | ||
disabled: { | ||
control: 'boolean', | ||
description: '버튼 비활성화 여부', | ||
}, | ||
}, | ||
} satisfies Meta<typeof Button> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Button> | ||
|
||
export const Playground: Story = {} | ||
|
||
export const Size: Story = { | ||
argTypes: { | ||
size: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}, | ||
render: (props) => { | ||
return ( | ||
<ul className="storybook-list"> | ||
{BUTTON_SIZES.map((size) => ( | ||
<li key={size}> | ||
<p className="storybook-subtitle">{size}</p> | ||
<Button {...props} size={size}> | ||
{props.children} | ||
</Button> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
}, | ||
} | ||
|
||
export const Type: Story = { | ||
argTypes: { | ||
filled: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
blueLine: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
disabled: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}, | ||
render: (props) => { | ||
return ( | ||
<ul className="storybook-list"> | ||
<li> | ||
<p className="storybook-subtitle">Filled</p> | ||
<Button {...props} filled> | ||
{props.children} | ||
</Button> | ||
</li> | ||
<li> | ||
<p className="storybook-subtitle">Filled Disabled</p> | ||
<Button {...props} filled disabled> | ||
{props.children} | ||
</Button> | ||
</li> | ||
<li> | ||
<p className="storybook-subtitle">Blue Line</p> | ||
<Button {...props} filled={false} blueLine> | ||
{props.children} | ||
</Button> | ||
</li> | ||
<li> | ||
<p className="storybook-subtitle">No Blue Line</p> | ||
<Button {...props} filled={false}> | ||
{props.children} | ||
</Button> | ||
</li> | ||
<li> | ||
<p className="storybook-subtitle">Disabled</p> | ||
<Button {...props} filled={false} disabled> | ||
{props.children} | ||
</Button> | ||
</li> | ||
</ul> | ||
) | ||
}, | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엄청 중요한 부분은 아닌데 작업하면서 보니
<Button {...props} filled={false} blueLine={false}>
으로 작성해야 Story Book에서 blueline이 제거된 상태로 올바르게 표기되더라구요!