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

반응형 디자인 유틸리티 추가. chip 일부 컴포넌트 구현 #5

Merged
merged 9 commits into from
Jun 1, 2024
17 changes: 10 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ module.exports = {
'plugin:jsx-a11y/recommended',
'airbnb', // Airbnb 스타일 가이드 사용
'airbnb/hooks',
'airbnb-typescript',
'airbnb-typescript'
],
plugins: ['@typescript-eslint'],
parserOptions: {
project: './tsconfig.json',
project: './tsconfig.json'
},
rules: {
// 추가적인 규칙 설정
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/comma-dangle': [
'error',
'always-multiline'
],
'linebreak-style': 0,
'react/react-in-jsx-scope': 'off',
'react/jsx-props-no-spreading': 'off',
},
},
],
'react/jsx-props-no-spreading': 'off'
}
}
]
};
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"printWidth": 70,
"proseWrap": "always"
}
30 changes: 30 additions & 0 deletions src/components/chip/ColorCircle/ColorCircle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface CircleProps {
color: string;
diameter: number;
children?: React.ReactNode;
}

// 색상코드, 지름, 내부요소 prop을 받아 원을 만들어줍니다.
// 색상코드는 가능하면 #이 붙는 RGB로, 지름은 숫자만 쓰면 px단위로 지정됩니다.
// 내부요소는 필수가 아니며, 있을 시 중앙정렬됩니다.
function ColorCircle({ color, diameter, children }: CircleProps) {
const circleStyle = {
backgroundColor: color,
width: `${diameter}px`,
height: `${diameter}px`,
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
textAlign: 'center',
} as React.CSSProperties;

return <div style={circleStyle}>{children}</div>;
}

ColorCircle.defaultProps = {
children: undefined,
};

export default ColorCircle;
22 changes: 22 additions & 0 deletions src/components/chip/ColorCircle/ColorDot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ColorCircle from './ColorCircle';

interface ColorDotProps {
color: string;
}

// 작은 점이 여럿 사용되서 컴포넌트로 분리했습니다.
// useMemo를 사용하면 같은 색 컴포넌트는 렌더링을 한번만 하게 할 수 있습니다.
function ColorDot({ color }: ColorDotProps) {
const colorCircleProps = {
color,
diameter: 8,
};

return <ColorCircle {...colorCircleProps} />;
}

export default ColorDot;

// 사용예시
// <ColorDot color="#00ff37" />
// <ColorDot color="#ff0000" />
30 changes: 30 additions & 0 deletions src/components/chip/ColorCircle/ColoredTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface CircleProps {
color: string;
diameter: number;
children?: React.ReactNode;
}

// 색상코드, 지름, 내부요소 prop을 받아 원을 만들어줍니다.
// 색상코드는 가능하면 #이 붙는 RGB로, 지름은 숫자만 쓰면 px단위로 지정됩니다.
// 내부요소는 필수가 아니며, 있을 시 중앙정렬됩니다.
function ColorCircle({ color, diameter, children }: CircleProps) {
const circleStyle = {
backgroundColor: color,
width: `${diameter}px`,
height: `${diameter}px`,
borderRadius: '50%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
textAlign: 'center',
} as React.CSSProperties;

return <div style={circleStyle}>{children}</div>;
}

ColorCircle.defaultProps = {
children: undefined,
};

export default ColorCircle;
5 changes: 3 additions & 2 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ $pink_E876EA: #e876ea;
margin: 0;
}

html, body {
html,
body {
height: 100%;
margin: 0;
padding: 0;
Expand All @@ -36,4 +37,4 @@ html, body {
height: 100%;
margin: 0;
padding: 0;
}
}
40 changes: 40 additions & 0 deletions src/styles/media.scss
Copy link
Owner

Choose a reason for hiding this comment

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

반응형 관련 기준이 되는 파일이 있으면 좋겠다고 생각했는데
잘 작성해주신 것 같습니다. 감사합니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 장치별 사이즈 정의
$size-mobile: 767px;
$size-tablet: 768px;
$size-tablet-max: 1023px;
$size-desktop: 1024px;

// [모바일]가로 767px 이하일 때
@mixin mobile {
@media (max-width: $size-mobile) {
@content;
}
}

// [태블릿]가로 768px 이상, 1023px이하
@mixin tablet {
@media (min-width: $size-tablet) and (max-width: $size-tablet-max) {
@content;
}
}

// [데스크탑]가로 1024px 이상
@mixin desktop {
@media (min-width: $size-desktop) {
@content;
}
}

// 사용 예시
// @include mobile{
// /*브라우저 사이즈767px이하일때*/
// background: black;
// }
// @include tablet{
// /*브라우저 사이즈1023px이하일때*/
// background: white;
// }
// @include desktop{
// /*브라우저 사이즈1024px이상일때*/
// background: gray;
// }
1 change: 1 addition & 0 deletions src/styles/utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './media.scss';
32 changes: 32 additions & 0 deletions src/utils/useWindowSize.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useState, useEffect } from 'react';

const useWindowSize = () => {
// windowSize는 화면의 가로, 세로 크기를 객체로 갖습니다.
const [windowSize, setWindowSize] = useState({
width: window.innerWidth,
height: window.innerHeight,
});

const handleResize = () => {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
};

// 초기값 설정
useEffect(() => {
window.addEventListener('resize', handleResize);
handleResize();
return () => window.removeEventListener('resize', handleResize);
}, []);
return windowSize;
};

export default useWindowSize;

// 컴포넌트에서 반응형 디자인을 구현하기 위한 커스텀 훅입니다.
// scss에서의 반응형 디자인은 styles/media.scss를 참고해주세요.

// import useWindowSize from './useWindowSize';
// const { width } = useWindowSize(); 하여 width나 height를 추출합니다.
Loading