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

[Wip] 공통컴포넌트 제작(메인 헤더 컴포넌트 완료 및 배지 컴포넌트 제작) #10

Merged
merged 19 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
496aa47
:sparkles: MainHeader컴포넌트 레이아웃과 스토리 작성완료
loevray Dec 28, 2023
c6c4146
:heavy_plus_sign: 아이콘용도 @chakra-ui/icons 추가
loevray Dec 28, 2023
33e15af
:heavy_plus_sign: chakra-ui와 storybook호환을위한 @chakra-ui/storybook-addo…
loevray Dec 28, 2023
4a22203
:lipstick: 메인헤더 레이아웃 완료 및 스타일 조정
loevray Dec 28, 2023
0417839
:lipstick: 벨 아이콘 사이즈업
loevray Dec 28, 2023
8718611
:sparkles: 달 모양 아이콘에 다크모드 토글 추가
loevray Dec 28, 2023
9240387
:recycle: 메인헤더 컴포넌트의 Image컴포넌트 높이를 부모와 똑같이 받게 변경
loevray Dec 28, 2023
8f0f36b
:lipstick: 메인헤더컴포넌트 감싸는 flexbox의 배경색 제거
loevray Dec 28, 2023
3f1751d
:sparkles: Badge 컴포넌트 추가
loevray Dec 29, 2023
3bbdf17
:recycle: Badge컴포넌트 사이즈 스타일 컴포넌트 props로 전달하여 사이징하게 만듬
loevray Dec 29, 2023
cd9a186
:truck: MainHeader컴포넌트 폴더 위치 변경
loevray Dec 29, 2023
4cf0da2
:lipstick: Badge컴포넌트가 Iconbutton을 감싸지않고 Icon을 감싸게 변경
loevray Dec 29, 2023
7bdf9bf
:recycle: MainHeader컴포넌트 높이,너비 string과 number타입 지원
loevray Dec 29, 2023
9604fd7
:lipstick: html 폰트사이즈 62.5%로 변경(rem편의), MainHeader컴포넌트 내부 아이콘 크기 them…
loevray Dec 29, 2023
526df00
:lipstick: MainHeader컴포넌트 내부 아이콘버튼크기 변경
loevray Dec 29, 2023
3ad94f5
:art: Badge컴포넌트내부 스타일드 컴포넌트를 로직 아래로 이동
loevray Dec 29, 2023
e7761a0
:art: Badge컴포넌트의 badge변수 colorStyle과 위치 변경
loevray Dec 29, 2023
9b2d34e
:art: App.tsx에서 파일 불러올때 경로별칭 사용
loevray Dec 29, 2023
cfa0d11
:truck: common 폴더 components폴더 하위로 이동
loevray Dec 29, 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
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config: StorybookConfig = {
'@storybook/addon-essentials',
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
'@chakra-ui/storybook-addon'
],
framework: {
name: '@storybook/react-vite',
Expand Down
4 changes: 4 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { Preview } from '@storybook/react';
import {theme} from "../src/theme"

const preview: Preview = {
parameters: {
chakra:{
theme,
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build-storybook": "storybook build"
},
"dependencies": {
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
Expand All @@ -25,6 +26,7 @@
"react-router-dom": "^6.21.1"
},
"devDependencies": {
"@chakra-ui/storybook-addon": "^5.1.0",
"@storybook/addon-essentials": "^7.6.6",
"@storybook/addon-interactions": "^7.6.6",
"@storybook/addon-links": "^7.6.6",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Test from '@/components/Test';
import MainHeader from '@/components/MainHeader';

const App = () => {
return <Test />;
return <MainHeader width={428} height={80} />;
};

export default App;
75 changes: 75 additions & 0 deletions src/components/MainHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Badge from '@/common/Badge';
import {
BellIcon,
ChatIcon,
MoonIcon,
SearchIcon,
SunIcon,
} from '@chakra-ui/icons';
import {
Flex,
IconButton,
Image,
useColorMode,
useColorModeValue,
} from '@chakra-ui/react';

interface MainHeaderProps {
width?: number | string;
height?: number | string;
}

const MainHeader = ({ width = 428, height = 80 }: MainHeaderProps) => {
const { toggleColorMode } = useColorMode();
const DarkModeIcon = useColorModeValue(MoonIcon, SunIcon);

return (
<Flex
w={typeof width === 'string' ? width : `${width}px`}
h={typeof height === 'string' ? height : `${height}px`}
justify="space-between"
align="center"
>
{/* 로고 들어갈 자리입니다. 로고 사이즈에 맞춰서 사용해주세요*/}
<Image
alt="dopen logo"
w="130px"
h={typeof height === 'string' ? height : `${height}px`}
src="https://via.placeholder.com/80"
/>
<Flex gap="20px">
<IconButton
aria-label="toggleDarkMode"
icon={<DarkModeIcon color="black" boxSize="icon" />}
bgColor="white"
size="md"
onClick={toggleColorMode}
/>
<IconButton
aria-label="message"
icon={<ChatIcon color="black" boxSize="icon" />}
bgColor="white"
size="md"
/>
<IconButton
aria-label="search"
icon={<SearchIcon color="black" boxSize="icon" />}
bgColor="white"
size="md"
/>
<IconButton
aria-label="notify"
icon={
<Badge count={1}>
<BellIcon color="black" boxSize="icon" />
</Badge>
}
bgColor="white"
size="md"
/>
</Flex>
</Flex>
);
};

export default MainHeader;
88 changes: 88 additions & 0 deletions src/components/common/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import styled from '@emotion/styled';
import { ReactNode } from 'react';

interface BadgeProps {
children: ReactNode;
count: number;
size?: string;
maxCount?: number;
backgroundColor?: string;
textColor?: string;
dot?: boolean;
showZero?: boolean;
}

const Badge = ({
children,
count,
maxCount,
size = '16px',
backgroundColor = 'red',
textColor = 'white',
dot = false,
showZero = false,
...props
}: BadgeProps) => {
const colorStyle = {
backgroundColor,
color: textColor,
};

let badge = null;

if (count) {
badge = (
<Super size={size} style={colorStyle}>
{maxCount && count > maxCount ? `${maxCount}+` : count}
</Super>
);
} else {
if (count !== undefined) {
badge = showZero ? (
<Super size={size} style={colorStyle}>
0
</Super>
) : null;
} else if (dot) {
badge = (
<Super size={size} className="dot" style={colorStyle}>
0
</Super>
);
}
}

return (
<BadgeContainer {...props}>
{children}
{count > 0 || (count === 0 && showZero) ? badge : null}
</BadgeContainer>
);
};

const BadgeContainer = styled.div`
position: relative;
width: 24px;
height: 24px;
`;

const Super = styled.span<{ size: string }>`
position: absolute;
display: inline-flex;
align-items: center;
justify-content: center;
right: 0;
bottom: 0;
transform: translate(25%, 25%);
height: ${({ size }) => size};
width: ${({ size }) => size};
font-size: 12px;
border-radius: 50%;
color: white;
background-color: #f44;
&.dot {
border-radius: 50%;
}
`;

export default Badge;
50 changes: 0 additions & 50 deletions src/stories/Button.stories.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/stories/Button.tsx

This file was deleted.

Loading