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

공통 버튼 컴포넌트 구현 #31

Merged
merged 28 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1f3af88
feat: (#15) 추가 버튼(글쓰기, 선택지 추가용) 구현
chsua Jul 10, 2023
58a0527
test: (#15) 추가 버튼(글쓰기, 선택지 추가용) 크기별 테스트 생성
chsua Jul 10, 2023
224f5d8
feat: (#15) 네모버튼 구현
chsua Jul 11, 2023
42c0bd5
test: (#15) 네모버튼 테마별 테스트 생성
chsua Jul 11, 2023
50cf5cf
feat: (#15) 헤더에 들어갈 글자버튼 구현
chsua Jul 11, 2023
68d95a7
test: (#15) 헤더에 들어갈 글자버튼 테스트 생성
chsua Jul 11, 2023
a4658b9
design: (#15) 더하기버튼, 네모버튼 컴포넌트 cursor를 포인터로 수정
chsua Jul 11, 2023
970fa4c
feat: (#15) 아이콘, 로고, 프로젝트 이름 svg파일 생성
chsua Jul 11, 2023
3f69b4b
chore: svg import를 위한 설정
chsua Jul 11, 2023
2e59d78
feat: (#15) 아이콘 버튼 구현
chsua Jul 11, 2023
82a64e7
test: (#15) 아이콘버튼 테스트 생성
chsua Jul 11, 2023
b54dbbb
feat: (#15) 웹 접근성을 위한 aria-label 속성 추가
chsua Jul 11, 2023
9b44dd8
chore: npm 설치하기
chsua Jul 11, 2023
34d8d80
refactor: 삭제된 컴포넌트 코드에서 제거
chsua Jul 11, 2023
ab8da0c
feat: (#15) 클릭이벤트를 인자로 받아 속성 부여
chsua Jul 11, 2023
92eadb4
test: (#15) 클릭이벤트 프롭스추가, 테스트에 반영
chsua Jul 11, 2023
d06254a
refactor: (#15) 추가 버튼 스타일 컴포넌트 중 사이즈 상수화
chsua Jul 12, 2023
ed780be
test: 중복되는 아이콘 버튼 테스트명 생략
chsua Jul 12, 2023
4dec47b
design: (#15) 헤더글씨버튼 굵기 수정
chsua Jul 12, 2023
eaaba03
refactor: (#15) 아이콘 관련 타입 정의 및 상수 분리
chsua Jul 12, 2023
a034b7b
design: (#15) 네모버튼 outline -> border로 수정
chsua Jul 12, 2023
bed584f
refactor: (#15) 웹접근성 향상을 위한 aria-label, alt 수정
chsua Jul 12, 2023
7cc3992
refactor: (#15) 버튼 컴포넌트 프롭스가 버튼 엘리먼트 상속 받도록 수정
chsua Jul 12, 2023
863dc26
refactor: (#15) 사이즈 단위 타입 파일로 분리 및 이름 수정
chsua Jul 12, 2023
200f87e
test: (#15) 버튼 컴포넌트 프롭스 변경에 따른 테스트 코드 수정
chsua Jul 12, 2023
b93528f
refactor: (#15) 추가 버튼 코드 리팩토링
chsua Jul 12, 2023
6ed7993
refactor: (#15) 웹접근성 향상을 위한 aria-label, alt 수정
chsua Jul 12, 2023
45e04a1
Merge branch 'dev' into feat/#15
chsua Jul 12, 2023
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
552 changes: 444 additions & 108 deletions frontend/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions frontend/src/assets/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions frontend/src/assets/category.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions frontend/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/projectName.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/search.svg
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 frontend/src/components/common/AddButton/AddButton.stories.tsx
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" />,
};
19 changes: 19 additions & 0 deletions frontend/src/components/common/AddButton/index.tsx
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>
);
}
28 changes: 28 additions & 0 deletions frontend/src/components/common/AddButton/style.ts
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;
`;
1 change: 1 addition & 0 deletions frontend/src/components/common/AddButton/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Size = 'sm' | 'md' | 'lg';
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>,
};
14 changes: 14 additions & 0 deletions frontend/src/components/common/HeaderTextButton/index.tsx
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>;
}
10 changes: 10 additions & 0 deletions frontend/src/components/common/HeaderTextButton/style.ts
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 frontend/src/components/common/IconButton/IconButton.stories.tsx
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>],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 모든 스토리에 원하는 부모 설정을 해 줄 수 있군요👍! 몰랐는데 배워갑니다! 🔥🔥

};

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" />,
};
41 changes: 41 additions & 0 deletions frontend/src/components/common/IconButton/index.tsx
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>
);
}
7 changes: 7 additions & 0 deletions frontend/src/components/common/IconButton/style.ts
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;
`;
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>,
};
20 changes: 20 additions & 0 deletions frontend/src/components/common/SquareButton/index.tsx
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';
Copy link
Member

Choose a reason for hiding this comment

The 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>
);
}
21 changes: 21 additions & 0 deletions frontend/src/components/common/SquareButton/style.ts
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;
`;
4 changes: 4 additions & 0 deletions frontend/src/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멋져요👍👍👍

const content: any;
export default content;
}
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
},
"outDir": "./dist"
},
"include": ["src"],
"include": ["src", "src/custom.d.ts"],
"exclude": ["node_modules"]
}