-
Notifications
You must be signed in to change notification settings - Fork 4
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
공통 버튼 컴포넌트 구현 #31
Merged
공통 버튼 컴포넌트 구현 #31
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1f3af88
feat: (#15) 추가 버튼(글쓰기, 선택지 추가용) 구현
chsua 58a0527
test: (#15) 추가 버튼(글쓰기, 선택지 추가용) 크기별 테스트 생성
chsua 224f5d8
feat: (#15) 네모버튼 구현
chsua 42c0bd5
test: (#15) 네모버튼 테마별 테스트 생성
chsua 50cf5cf
feat: (#15) 헤더에 들어갈 글자버튼 구현
chsua 68d95a7
test: (#15) 헤더에 들어갈 글자버튼 테스트 생성
chsua a4658b9
design: (#15) 더하기버튼, 네모버튼 컴포넌트 cursor를 포인터로 수정
chsua 970fa4c
feat: (#15) 아이콘, 로고, 프로젝트 이름 svg파일 생성
chsua 3f69b4b
chore: svg import를 위한 설정
chsua 2e59d78
feat: (#15) 아이콘 버튼 구현
chsua 82a64e7
test: (#15) 아이콘버튼 테스트 생성
chsua b54dbbb
feat: (#15) 웹 접근성을 위한 aria-label 속성 추가
chsua 9b44dd8
chore: npm 설치하기
chsua 34d8d80
refactor: 삭제된 컴포넌트 코드에서 제거
chsua ab8da0c
feat: (#15) 클릭이벤트를 인자로 받아 속성 부여
chsua 92eadb4
test: (#15) 클릭이벤트 프롭스추가, 테스트에 반영
chsua d06254a
refactor: (#15) 추가 버튼 스타일 컴포넌트 중 사이즈 상수화
chsua ed780be
test: 중복되는 아이콘 버튼 테스트명 생략
chsua 4dec47b
design: (#15) 헤더글씨버튼 굵기 수정
chsua eaaba03
refactor: (#15) 아이콘 관련 타입 정의 및 상수 분리
chsua a034b7b
design: (#15) 네모버튼 outline -> border로 수정
chsua bed584f
refactor: (#15) 웹접근성 향상을 위한 aria-label, alt 수정
chsua 7cc3992
refactor: (#15) 버튼 컴포넌트 프롭스가 버튼 엘리먼트 상속 받도록 수정
chsua 863dc26
refactor: (#15) 사이즈 단위 타입 파일로 분리 및 이름 수정
chsua 200f87e
test: (#15) 버튼 컴포넌트 프롭스 변경에 따른 테스트 코드 수정
chsua b93528f
refactor: (#15) 추가 버튼 코드 리팩토링
chsua 6ed7993
refactor: (#15) 웹접근성 향상을 위한 aria-label, alt 수정
chsua 45e04a1
Merge branch 'dev' into feat/#15
chsua 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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
frontend/src/components/common/AddButton/AddButton.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,22 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import AddButton from '.'; | ||
|
||
const meta: Meta<typeof AddButton> = { | ||
component: AddButton, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof AddButton>; | ||
|
||
export const size_S: Story = { | ||
render: () => <AddButton size="sm" />, | ||
}; | ||
|
||
export const size_M: Story = { | ||
render: () => <AddButton size="md" />, | ||
}; | ||
|
||
export const size_L: Story = { | ||
render: () => <AddButton size="lg" />, | ||
}; |
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,19 @@ | ||
import { ButtonHTMLAttributes } from 'react'; | ||
|
||
import * as S from './style'; | ||
import { Size } from './type'; | ||
|
||
interface AddButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
size: Size; | ||
} | ||
|
||
/* 글쓰기 버튼, 선택지 추가 버튼 등 크기가 다른 용도로 사용할 예정이기 때문에 | ||
* props로 s/m/l 크기를 받음 | ||
*/ | ||
export default function AddButton({ size, ...rest }: AddButtonProps) { | ||
return ( | ||
<S.Button size={size} aria-label="더하기" {...rest}> | ||
+ | ||
</S.Button> | ||
); | ||
} |
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,28 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
import { Size } from './type'; | ||
|
||
interface ButtonProps { | ||
size: Size; | ||
} | ||
|
||
const size = { | ||
sm: { button: '25px', font: '13px' }, | ||
md: { button: '40px', font: '30px' }, | ||
lg: { button: '60px', font: '50px' }, | ||
}; | ||
|
||
export const Button = styled.button<ButtonProps>` | ||
display: block; | ||
|
||
width: ${props => size[props.size].button}; | ||
height: ${props => size[props.size].button}; | ||
border-radius: 50%; | ||
|
||
background-color: #ff7877; | ||
color: #ffffff; | ||
|
||
font-size: ${props => size[props.size].font}; | ||
|
||
cursor: pointer; | ||
`; |
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 type Size = 'sm' | 'md' | 'lg'; |
14 changes: 14 additions & 0 deletions
14
frontend/src/components/common/HeaderTextButton/HeaderTextButton.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,14 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import HeaderTextButton from '.'; | ||
|
||
const meta: Meta<typeof HeaderTextButton> = { | ||
component: HeaderTextButton, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof HeaderTextButton>; | ||
|
||
export const defaultButton: Story = { | ||
render: () => <HeaderTextButton>확 인</HeaderTextButton>, | ||
}; |
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,14 @@ | ||
import { ButtonHTMLAttributes } from 'react'; | ||
|
||
import * as S from './style'; | ||
|
||
interface HeaderTextButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
children: string; | ||
} | ||
|
||
/* 헤더에 포함되어 취소, 확인, 신고 등 사용될 버튼 | ||
* props로 s/m/l 크기를 받음 | ||
*/ | ||
export default function HeaderTextButton({ children, ...rest }: HeaderTextButtonProps) { | ||
return <S.Button {...rest}>{children}</S.Button>; | ||
} |
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,10 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
export const Button = styled.button` | ||
background-color: rgba(0, 0, 0, 0); | ||
|
||
font-size: 14px; | ||
font-weight: 500; | ||
|
||
cursor: pointer; | ||
`; |
23 changes: 23 additions & 0 deletions
23
frontend/src/components/common/IconButton/IconButton.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,23 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import IconButton from '.'; | ||
|
||
const meta: Meta<typeof IconButton> = { | ||
component: IconButton, | ||
decorators: [storyFn => <div style={{ backgroundColor: 'black' }}>{storyFn()}</div>], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof IconButton>; | ||
|
||
export const category: Story = { | ||
render: () => <IconButton category="category" />, | ||
}; | ||
|
||
export const back: Story = { | ||
render: () => <IconButton category="back" />, | ||
}; | ||
|
||
export const search: Story = { | ||
render: () => <IconButton category="search" />, | ||
}; |
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,41 @@ | ||
import { ButtonHTMLAttributes } from 'react'; | ||
|
||
import backIcon from '@assets/back.svg'; | ||
import categoryIcon from '@assets/category.svg'; | ||
import searchIcon from '@assets/search.svg'; | ||
|
||
import * as S from './style'; | ||
|
||
type IconCategory = 'category' | 'back' | 'search'; | ||
|
||
const iconCategory: { [key in IconCategory]: { name: string; url: string } } = { | ||
category: { | ||
name: '카테고리', | ||
url: categoryIcon, | ||
}, | ||
back: { | ||
name: '뒤로가기', | ||
url: backIcon, | ||
}, | ||
search: { | ||
name: '검색', | ||
url: searchIcon, | ||
}, | ||
}; | ||
|
||
interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
category: IconCategory; | ||
} | ||
|
||
/* 뒤로가기, 카테고리 열기 등에 사용될 아이콘 버튼 | ||
*/ | ||
export default function IconButton({ category, ...rest }: IconButtonProps) { | ||
const src = iconCategory[category].url; | ||
const ariaLabelText = iconCategory[category].name; | ||
|
||
return ( | ||
<S.Button aria-label={ariaLabelText} {...rest}> | ||
<img src={src} alt={`${ariaLabelText} 버튼`} /> | ||
</S.Button> | ||
); | ||
} |
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 { styled } from 'styled-components'; | ||
|
||
export const Button = styled.button` | ||
background-color: rgba(0, 0, 0, 0); | ||
|
||
cursor: pointer; | ||
`; |
19 changes: 19 additions & 0 deletions
19
frontend/src/components/common/SquareButton/SquareButton.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,19 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import SquareButton from '.'; | ||
|
||
const meta: Meta<typeof SquareButton> = { | ||
component: SquareButton, | ||
decorators: [storyFn => <div style={{ width: '100px', height: '50px' }}>{storyFn()}</div>], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof SquareButton>; | ||
|
||
export const color_blank: Story = { | ||
render: () => <SquareButton theme="blank">확 인</SquareButton>, | ||
}; | ||
|
||
export const color_fill: Story = { | ||
render: () => <SquareButton theme="fill">버 튼</SquareButton>, | ||
}; |
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 { ButtonHTMLAttributes } from 'react'; | ||
|
||
import * as S from './style'; | ||
|
||
interface SquareButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
theme: 'blank' | 'fill'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 theme 이라는 props 좋은걸요?👍👍 |
||
children: string; | ||
} | ||
|
||
/* 마감시간, 확인, 취소 등 사용될 버튼 | ||
* 부모에서 크기를 조절, 내용(children) 전달 | ||
* props로 테마를 받음 | ||
*/ | ||
export default function SquareButton({ theme, children, ...rest }: SquareButtonProps) { | ||
return ( | ||
<S.Button theme={theme} {...rest}> | ||
{children} | ||
</S.Button> | ||
); | ||
} |
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 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
interface ButtonProps { | ||
theme: 'blank' | 'fill'; | ||
} | ||
|
||
export const Button = styled.button<ButtonProps>` | ||
display: block; | ||
|
||
width: 100%; | ||
height: 100%; | ||
border: 2px solid #ff7877; | ||
border-radius: 5px; | ||
|
||
background-color: ${props => (props.theme === 'blank' ? 'rgba(0,0,0,0)' : '#ff7877')}; | ||
color: ${props => (props.theme === 'blank' ? '#ff7877' : '#ffffff')}; | ||
|
||
font-size: 16px; | ||
|
||
cursor: pointer; | ||
`; |
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,4 @@ | ||
declare module '*.svg' { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 멋져요👍👍👍 |
||
const content: any; | ||
export default content; | ||
} |
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
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.
이렇게 모든 스토리에 원하는 부모 설정을 해 줄 수 있군요👍! 몰랐는데 배워갑니다! 🔥🔥