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

컴포넌트 스타일 일관성 리팩토링 #98

Merged
merged 42 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f5a13b6
refactor(Button): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
3141d79
refactor(Flex): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
0154e6d
refactor(Header): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
f667658
refactor(Input): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
55caec3
refactor(Text): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
9dbcec9
refactor(SelectList): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
3c241e3
refactor(SnippetEditor): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
7443538
refactor(Layout): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
38874ab
refactor(TemplateTitleInput): 스타일 일관성 리팩토링
vi-wolhwa Jul 21, 2024
528e36f
feat(components): import 'type' 키워드 사용 및 type > interface 리팩토링
vi-wolhwa Jul 21, 2024
7fcbc53
refactor(SelectList): style 기본값 선언 방식 변경
vi-wolhwa Jul 21, 2024
9e280b6
refactor(Flex): style props 객체분해할당
vi-wolhwa Jul 21, 2024
8588a3d
fix(Button): 버튼 텍스트 중앙 정렬
vi-wolhwa Jul 21, 2024
caf244d
chore: stylelint 불필요한 구문 제거 및 shortHand 규칙 비활성화
vi-wolhwa Jul 21, 2024
9d3108b
refactor(Flex): flex-flow -> flex-direction 수정
vi-wolhwa Jul 21, 2024
fedf8e2
refactor(Flex): 스타일 props 전달 방식 props.gap > {gap} 변경
vi-wolhwa Jul 22, 2024
46e03c3
Merge branch 'dev/fe' into refactor/component_style_consistency
vi-wolhwa Jul 22, 2024
c82aa17
fix(SelectList): isSelected 스타일 구문 오류 수정
vi-wolhwa Jul 22, 2024
86652b3
refactor(Input): formNoValidate 조건 간략화
vi-wolhwa Jul 22, 2024
af6afd9
refactor(SnippetEditor): 컴포넌트 변경사항 롤백
vi-wolhwa Jul 22, 2024
664851a
refactor(SelectList): Text-color isSelected 조건 수정
vi-wolhwa Jul 22, 2024
3ac5438
Merge branch 'refactor/component_style_consistency' of https://github…
vi-wolhwa Jul 22, 2024
b103632
refactor(components): 컴포넌트 Props에서 불필요한 optional 제거 및 반영
vi-wolhwa Jul 23, 2024
45cb24e
refactor(components): styled-components에서 컴포넌트의 Props 사용
vi-wolhwa Jul 23, 2024
49fc2d3
refactor(components): children 대신 PropsWithChildren 사용
vi-wolhwa Jul 23, 2024
6c3c996
refactor(components): 컴포넌트 매개변수에서 기본값 정의 및 수정사항 반영
vi-wolhwa Jul 23, 2024
4ea2c24
refactor(Text): Text 서브컴포넌트 assign 방식 변경
vi-wolhwa Jul 23, 2024
0a9c4ac
fix(SelectList): Text color 값 오류 해결
vi-wolhwa Jul 23, 2024
968bbb9
refactor(Text): Text 컴포넌트 prop color Optional 제거
vi-wolhwa Jul 23, 2024
06b1909
fix(Text): TextWrapper 'size' 단위 'rem' 추가
vi-wolhwa Jul 23, 2024
68f0117
fix(Flex): 타입 확장 (HTMLAttributes<HTMLDivElement>)
vi-wolhwa Jul 23, 2024
8285a33
refactor(components): import 'React' 생략
vi-wolhwa Jul 23, 2024
290db3d
refactor(Header): 불필요한 styled-component 삭제
vi-wolhwa Jul 23, 2024
00bfc9a
refactor(components): import 구문에 path-alias 사용
vi-wolhwa Jul 23, 2024
4a94100
refactor(Button): 'variant' 이름 변경 (default > contained>
vi-wolhwa Jul 23, 2024
a0c3643
refactor(Button): Props 타입 변경, 속성 변경
Jaymyong66 Jul 23, 2024
915218e
refactor(Flex): React 객체 제거
Jaymyong66 Jul 23, 2024
8c34417
feat(Button): size 속성에 filled 타입 추가
Jaymyong66 Jul 24, 2024
fddcf6b
feat(.storybook): storybook에 path alias 설정 추가
Jaymyong66 Jul 24, 2024
bc6af7d
refactor(Flex): props 변수명을 rests로 변경
Jaymyong66 Jul 24, 2024
a319156
style(Header): import 순서 변경
Jaymyong66 Jul 24, 2024
90e2a72
refactor(Input): Props의 타입을 InputHTMLAttributes를 extend하도록 변경
Jaymyong66 Jul 24, 2024
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
11 changes: 8 additions & 3 deletions frontend/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StorybookConfig } from '@storybook/react-webpack5';
import { Configuration } from 'webpack';

import path from 'path';
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
Expand All @@ -27,10 +27,15 @@ const config: StorybookConfig = {
},
],
});

config.resolve = {
...config.resolve,
alias: {
...config.resolve?.alias,
'@': path.resolve(__dirname, '../src'),
},
};
return config;
},

framework: {
name: '@storybook/react-webpack5',
options: {},
Expand Down
29 changes: 6 additions & 23 deletions frontend/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@ const ButtonGroup = ({ disabled }: { disabled: boolean }) => (
<div css={colStyle}>
<div css={rowStyle}>
<div css={buttonWrapper}>
<Button type='default' size='small' disabled={disabled}>
<Button variant='contained' size='small' disabled={disabled}>
버튼
</Button>
</div>
<div css={buttonWrapper}>
<Button type='default' size='medium' disabled={disabled}>
<Button variant='contained' size='medium' disabled={disabled}>
버튼
</Button>
</div>
</div>
<div css={rowStyle}>
<div css={buttonWrapper}>
<Button type='outlined' size='small' disabled={disabled}>
<Button variant='outlined' size='small' disabled={disabled}>
버튼
</Button>
</div>
<div css={buttonWrapper}>
<Button type='outlined' size='medium' disabled={disabled}>
<Button variant='outlined' size='medium' disabled={disabled}>
버튼
</Button>
</div>
</div>
<div css={rowStyle}>
<div css={buttonWrapper}>
<Button type='text' size='small' disabled={disabled}>
<Button variant='text' size='small' disabled={disabled}>
버튼
</Button>
</div>
<div css={buttonWrapper}>
<Button type='text' size='medium' disabled={disabled}>
<Button variant='text' size='medium' disabled={disabled}>
버튼
</Button>
</div>
Expand All @@ -71,20 +71,3 @@ export const Enabled: Story = {
export const Disabled: Story = {
render: () => <ButtonGroup disabled={true} />,
};

export const CustomSized: Story = {
render: () => (
<div css={colStyle}>
<Button type='default' width='10rem'>
10rem
</Button>
<Button type='outlined' width='20rem'>
20rem
</Button>
<Button type='text' width='30rem'>
30rem
</Button>
<p style={{ color: '#888888', fontSize: '1.2rem' }}>(text 타입 버튼의 사이즈는 텍스트 길이에 비례합니다.)</p>
</div>
),
};
24 changes: 8 additions & 16 deletions frontend/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import React from 'react';
import { buttonStyle, stylesBySize, stylesByType, textTypeStyle } from './style';
import { ButtonHTMLAttributes } from 'react';
import * as S from './style';

interface Props {
children: React.ReactNode;
onClick?: (e?: React.MouseEvent<HTMLButtonElement>) => void;
type?: 'default' | 'outlined' | 'text';
size?: 'small' | 'medium';
width?: string | number;
disabled?: boolean;
export interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
variant: 'contained' | 'outlined' | 'text';
size: 'small' | 'medium' | 'filled';
}

const Button = ({ children, onClick, type = 'default', size = 'medium', width, disabled = false }: Props) => (
<button
css={[buttonStyle, stylesByType[type], stylesBySize[size], type === 'text' ? textTypeStyle : width && { width }]}
disabled={disabled}
onClick={onClick}
>
const Button = ({ children, onClick, variant, size, ...rest }: Props) => (
<S.Button variant={variant} size={size} onClick={onClick} {...rest}>
{children}
</button>
</S.Button>
);

export default Button;
129 changes: 72 additions & 57 deletions frontend/src/components/Button/style.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,81 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import type { Props } from './Button';

export const buttonStyle = css({
cursor: 'pointer',
borderRadius: '8px',
textAlign: 'center',
padding: '0.8rem 1.6rem',
display: 'flex',
alignItems: 'center',
gap: '0.8rem',
const variants = {
vi-wolhwa marked this conversation as resolved.
Show resolved Hide resolved
contained: css`
color: rgb(52 60 72 / 100%);
background: rgb(255 211 105 / 100%);
`,
outlined: css`
color: rgb(255 211 105 / 100%);
background: none;
border: 0.1rem solid rgb(255 211 105 / 100%);
`,
text: css`
display: inline-block;

'&:not(:disabled):focus': {
outline: 'none',
},
width: fit-content;
height: fit-content;
padding: 0;

'&:not(:disabled):hover': {
opacity: 0.8,
},
color: rgb(255 211 105 / 100%);

'&:not(:disabled):active': {
opacity: 0.6,
},

'&:disabled': {
cursor: 'default',
opacity: 0.6,
},
});

export const stylesByType = {
default: css({
background: 'rgb(255 211 105 / 100%)',
color: 'rgb(52 60 72 / 100%)',
}),
outlined: css({
background: 'none',
border: '0.1rem solid rgb(255 211 105 / 100%)',
color: 'rgb(255 211 105 / 100%)',
}),
text: css({
background: 'none',
color: 'rgb(255 211 105 / 100%)',
}),
background: none;
border: none;
`,
};

export const stylesBySize = {
small: css({
height: '3rem',
fontWeight: 700,
fontSize: '1.4rem',
}),
medium: css({
height: '4rem',
fontWeight: 700,
fontSize: '1.8rem',
}),
const sizes = {
small: css`
height: 3rem;
font-size: 1.4rem;
font-weight: 700;
`,
medium: css`
height: 4rem;
font-size: 1.8rem;
font-weight: 700;
`,
filled: css`
width: 100%;
height: 4rem;
font-size: 1.8rem;
font-weight: 700%;
`,
};

export const textTypeStyle = css({
padding: '0',
background: 'none',
border: 'none',
width: 'fit-content',
height: 'fit-content',
display: 'inline-block',
});
export const Button = styled.button<Props>`
cursor: pointer;

display: flex;
gap: 0.8rem;
align-items: center;
justify-content: center;

padding: 0.8rem 1.6rem;

text-align: center;

border-radius: 8px;

${({ size }) => sizes[size]};
${({ variant }) => variants[variant]};

&:disabled {
cursor: default;
opacity: 0.6;
}

&:not(:disabled):focus {
outline: none;
}

&:not(:disabled):hover {
opacity: 0.8;
}

&:not(:disabled):active {
opacity: 0.6;
}
`;
37 changes: 18 additions & 19 deletions frontend/src/components/Flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ReactNode } from 'react';
import { FlexContainer } from './style';
import { HTMLAttributes, PropsWithChildren } from 'react';
import * as S from './style';

export interface Props {
children: ReactNode;
export interface Props extends HTMLAttributes<HTMLDivElement> {
direction?: 'row' | 'row-reverse' | 'column' | 'column-reverse';
justify?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly';
align?: 'stretch' | 'flex-start' | 'flex-end' | 'center' | 'baseline';
Expand All @@ -17,19 +16,19 @@ export interface Props {

const Flex = ({
children,
direction = 'row',
justify = 'flex-start',
align = 'stretch',
wrap = 'nowrap',
gap = '0',
width = 'auto',
height = 'auto',
padding = '0',
margin = '0',
flex = 'none',
...props
}: Props) => (
<FlexContainer
direction,
justify,
align,
wrap,
gap,
width,
height,
padding,
margin,
flex,
...rests
}: PropsWithChildren<Props>) => (
<S.FlexContainer
direction={direction}
justify={justify}
align={align}
Expand All @@ -40,10 +39,10 @@ const Flex = ({
padding={padding}
margin={margin}
flex={flex}
{...props}
{...rests}
>
{children}
</FlexContainer>
</S.FlexContainer>
);

export default Flex;
19 changes: 10 additions & 9 deletions frontend/src/components/Flex/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import type { Props } from './Flex';

export const FlexContainer = styled.div<Props>`
display: flex;
flex: ${(props) => props.flex};
flex-flow: ${(props) => props.direction} ${(props) => props.wrap};
gap: ${(props) => props.gap};
align-items: ${(props) => props.align};
justify-content: ${(props) => props.justify};
flex: ${({ flex }) => flex};
flex-direction: ${({ direction }) => direction};
flex-wrap: ${({ wrap }) => wrap};
gap: ${({ gap }) => gap};
align-items: ${({ align }) => align};
justify-content: ${({ justify }) => justify};

width: ${(props) => props.width};
height: ${(props) => props.height};
margin: ${(props) => props.margin};
padding: ${(props) => props.padding};
width: ${({ width }) => width};
height: ${({ height }) => height};
margin: ${({ margin }) => margin};
padding: ${({ padding }) => padding};
`;
8 changes: 8 additions & 0 deletions frontend/src/components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { MemoryRouter } from 'react-router-dom';
import Header from './Header';
import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof Header> = {
title: 'Header',
component: Header,
decorators: [
(Story) => (
<MemoryRouter>
<Story />
</MemoryRouter>
vi-wolhwa marked this conversation as resolved.
Show resolved Hide resolved
),
],
};

export default meta;
Expand Down
Loading