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] 공통 컴포넌트 제작(4-1) UserContentBlock #23

Merged
merged 20 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
681f8b4
:lipstick: UserContentBlock 레이아웃 기초 작성
loevray Jan 1, 2024
37fe0db
:lipstick: UserContentBlock 프롭스 할당 및 레이아웃 완성
loevray Jan 1, 2024
b5e49d4
:sparkles: UserContentBlock컴포넌트 navigate추가 및 아바타 클릭이벤트 받아올수 있게 추가
loevray Jan 1, 2024
90662ca
:heavy_plus_sign: react-router-dom을 storybook에서 사용하기위한 addon 추가
loevray Jan 1, 2024
99dba99
:sparkles: UserContentBlock storybook에 withRouter추가하여 router관련 오류 제거
loevray Jan 1, 2024
8eb509f
:lipstick: UserContentBlock에 subcontent추가
loevray Jan 1, 2024
3c68ef1
:art: UserContentBlock 컴포넌트 이미지 클릭 이벤트 핸들러 제거
loevray Jan 1, 2024
d01af74
:lipstick: UserContentBlock에 isOnline프롭스로 판단하여 AvatarBadge 추가
loevray Jan 1, 2024
a78a73c
:sparkles: UserContentBlock storybook에 argTypes 추가 및 기본값 설정
loevray Jan 1, 2024
e4c5e5d
Merge branch 'dev' of https://github.com/prgrms-fe-devcourse/FEDC5_do…
loevray Jan 2, 2024
8cae1a7
:art: Footer컴포넌트 props타입을 flexbox타입으로 변경
loevray Jan 2, 2024
c9c6e54
:art: Footer 컴포넌트 props를 전부 rest로 받아오게 변경
loevray Jan 2, 2024
fbf84af
:lipstick: UserContentBlock subcontent 포지션 absolute로 변경 및 테마 수정
loevray Jan 2, 2024
b3c8cc7
:art: UserContentBlock 프롭스 변경 및 타입 FlexProps상속
loevray Jan 2, 2024
254f253
:art: UserContentBlock isOnline 조건문 변경 및 테마 green색상 추가
loevray Jan 2, 2024
96f4b06
:lipstick: UserContentBlock Avatar에 그림자 추가
loevray Jan 2, 2024
4d42ced
:art: subcontent에 onClick핸들러 등록시 커서모양 변경및 등록
loevray Jan 2, 2024
fd1574b
:art: UserContentBlock isOnline조건부 렌더링 삼항연산자에서 &&로 변경
loevray Jan 2, 2024
5f65d70
:art: UserContentBlock props와 type 정렬
loevray Jan 2, 2024
9f0bfbb
:art: UserContentBlock 내부 href프롭스 및 useNavigate로직 삭제
loevray Jan 2, 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
3 changes: 2 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const config: StorybookConfig = {
'@storybook/addon-essentials',
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
'@chakra-ui/storybook-addon'
'@chakra-ui/storybook-addon',
'storybook-addon-react-router-v6'
],
framework: {
name: '@storybook/react-vite',
Expand Down
46 changes: 46 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"storybook": "^7.6.6",
"storybook-addon-react-router-v6": "^2.0.10",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vitest": "^1.1.0"
Expand Down
17 changes: 5 additions & 12 deletions src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_HEADER_HEIGHT, DEFAULT_WIDTH } from '@/constants/style';
import { Flex } from '@chakra-ui/react';
import { Flex, FlexProps } from '@chakra-ui/react';
import {
MdHome,
MdEmojiEvents,
Expand All @@ -9,15 +9,7 @@ import {
} from 'react-icons/md';
import TextIconButton from '../common/TextIconButton';

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

const Footer = ({
width = DEFAULT_WIDTH,
height = DEFAULT_HEADER_HEIGHT,
}: FooterProps) => {
const Footer = ({ ...props }: FlexProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

FlexProps 로 받아주면 ...props 도 대처가 되는군요 !! 유익한 기능을 알아갑니다 :)

return (
<Flex
pl="31px"
Expand All @@ -27,8 +19,9 @@ const Footer = ({
borderColor="gray.450"
align="center"
bg="gray.50"
w={typeof width === 'string' ? width : `${width}px`}
h={typeof height === 'string' ? height : `${height}px`}
w={DEFAULT_WIDTH}
h={DEFAULT_HEADER_HEIGHT}
{...props}
>
{/* [{icon:MdHome, textContent:"홈"}, ...] 이렇게 받아와서 map을 돌려도 좋아보입니다*/}
<TextIconButton TheIcon={MdHome} textContent="홈" />
Expand Down
107 changes: 107 additions & 0 deletions src/components/common/UserContentBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { DEFAULT_PAGE_PADDING, DEFAULT_WIDTH } from '@/constants/style';
import {
Avatar,
AvatarBadge,
Flex,
FlexProps,
Text,
VStack,
} from '@chakra-ui/react';
import { useNavigate } from 'react-router-dom';

interface UserContentBlockProps extends FlexProps {
userImage?: string;
userImageSize?: string | number;
isOnline?: boolean;
username: string;
content: string;
subContent?: string;
usernameFontSize?: string | number;
contentFontSize?: string | number;
href?: string;
onSubContentClick?: () => void;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

정말 별건 아니지만... username , content 관련 속성들이 정렬되면 좋을 것 같습니다

{username,
usernameFontSize,
content,
contentFontsize
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

음 이거는 컨벤션으로 정해도 될만큼 중요해보이네요
항상 꼼꼼하게 봐주셔서 감사합니다 ㅎㅎ


const UserContentBlock = ({
userImage = '',
userImageSize = '50px',
href,
content,
isOnline,
subContent,
onSubContentClick,
username = '테스트용',
usernameFontSize = '1.4rem',
contentFontSize = '1.2rem',
...props
}: UserContentBlockProps) => {
const navigate = useNavigate();
const onNavigate = () => navigate(`${href}`);
return (
<Flex
w={DEFAULT_WIDTH}
align="center"
gap="17px"
onClick={() => href && onNavigate()}
cursor="pointer"
pl={DEFAULT_PAGE_PADDING}
pr={DEFAULT_PAGE_PADDING}
{...props}
>
<Avatar
src={userImage}
boxSize={
userImageSize && typeof userImageSize === 'string'
? userImageSize
: `${userImageSize}px`
}
Comment on lines +49 to +52
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분이 하나의 함수로 처리되어도 좋을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

좋습니다 numberToPixel 이런 함수로 만들어서 사용해보겠습니다 ㅎㅎ

boxShadow="0px 5px 15px -5px gray"
>
{isOnline ? (
<AvatarBadge
boxSize="14px"
border="2px solid white"
bg="green.100"
right="5%"
bottom="5%"
/>
) : null}
Copy link
Collaborator

Choose a reason for hiding this comment

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

isOnline && 이런 식으로 처리해도 좋을 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 수정사항 반영하겠습니다

</Avatar>
<VStack flex="1" align="left" color="black">
<Flex w="100%" position="relative">
<Text
fontWeight="semibold"
fontSize={
typeof usernameFontSize === 'string'
? usernameFontSize
: `${usernameFontSize}px`
}
>
{username}
</Text>
<Text
fontSize="1.2rem"
position="absolute"
right="0"
zIndex="normal"
cursor={onSubContentClick && 'pointer'}
onClick={() => onSubContentClick && onSubContentClick()}
Copy link
Collaborator

Choose a reason for hiding this comment

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

지금 최상위 컴포넌트에도 click 이벤트가 있고, Text에도 이벤트가 있는데 관련해서 문제는 없는지 궁금합니다.
해당 컴포넌트 클릭 시 url 이동 말고 필요한 다른 이벤트가 뭔가 생각이 잘 안나네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기획중 둘을 동시에 사용하는 경우가 없었습니다. 아직 정해지지 않은 부분이기도 하구요

  1. 알림,메시지는 최상위 컴포넌트 클릭시 페이지 이동
  2. 댓글부분에서는 subcontent클릭시 삭제기능. => 이때는 아직 정해지지 않았지만, 아마 사용하진 않을 것 같습니다

>
{subContent}
</Text>
</Flex>
<Text
fontSize={
typeof contentFontSize === 'string'
? contentFontSize
: `${contentFontSize}px`
}
>
{content}
</Text>
</VStack>
</Flex>
);
};

export default UserContentBlock;
2 changes: 1 addition & 1 deletion src/pages/MainPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import GuestProfile from '@/pages/MainPage/GuestProfile';
import LoginProfile from '@/pages/MainPage/LoginProfile';

interface MainPageProps {
isLoggedIn: boolean;
isLoggedIn?: boolean;
}

const MainPage = ({ isLoggedIn = false }: MainPageProps) => {
Expand Down
50 changes: 50 additions & 0 deletions src/stories/components/UserContentBlock.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import UserContentBlock from '@/components/common/UserContentBlock';
import { Meta, StoryObj } from '@storybook/react';
import { withRouter } from 'storybook-addon-react-router-v6';
const meta: Meta<typeof UserContentBlock> = {
component: UserContentBlock,
decorators: [withRouter],
argTypes: {
width: {
control: 'number',
},
height: {
control: 'number',
},
username: {
control: 'text',
},
content: {
control: 'text',
},
isOnline: {
control: 'boolean',
},
userImage: {
control: 'text',
},
usernameFontSize: {
control: 'number',
},
contentFontSize: {
control: 'number',
},
subContent: {
control: 'text',
},
},
};

export default meta;
type Story = StoryObj<typeof UserContentBlock>;

export const Deafult: Story = {
args: {
width: 428,
height: 80,
username: '테스트닉',
content: '테스트용 내용',
isOnline: true,
subContent: '7일 전',
},
};
6 changes: 6 additions & 0 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const theme = extendTheme({
red: {
100: '#EF4444',
},
green: {
100: '#44DE82',
},
black: '#222222',

white: '#FFFFFF',
Expand Down Expand Up @@ -64,4 +67,7 @@ export const theme = extendTheme({
sizes: {
icon: '2.4rem',
},
zIndices: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 z-index를 의미하는 것이겠죠 ??!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 맞습니다 chakra ui 링크에서 theme-key로 되어있는 부분이 테마변수명입니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

아하 확인했습니다 !!

normal: 100,
},
});