-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Feat] showcase 페이지 category chip 구현 #60
Changes from 11 commits
9254cd9
e925abf
0ea5416
8d1dade
4c2378a
361e484
3e3b89a
082c7a1
5bf976d
fe73711
a9a67f3
19f4fd6
e25e030
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
import { theme } from '@/common/style/theme/theme'; | ||
|
||
export const buttonStyle = (isClicked: boolean) => | ||
css({ | ||
padding: '1.3rem 1.6rem', | ||
|
||
backgroundColor: theme.colors.white, | ||
borderRadius: '100px', | ||
border: `1.2px solid ${isClicked ? theme.colors.blue_900 : theme.colors.gray_400}`, | ||
|
||
...theme.text.body04, | ||
color: `${isClicked ? theme.colors.blue_900 : theme.colors.gray_800}`, | ||
fontWeight: 500, | ||
|
||
cursor: 'pointer', | ||
|
||
'&:hover': { | ||
backgroundColor: theme.colors.blue_100, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { buttonStyle } from '@/page/showcase/component/CategoryChip/CategoryChip.style'; | ||
|
||
import { ComponentPropsWithRef, useEffect, useState } from 'react'; | ||
|
||
interface CategoryChipProps extends Omit<ComponentPropsWithRef<'button'>, 'onClick'> { | ||
onClick?: (id: string) => void; | ||
clickedChip?: string; | ||
} | ||
|
||
const CategoryChip = ({ children, onClick, clickedChip = '', ...props }: CategoryChipProps) => { | ||
const [isClicked, setIsClicked] = useState(false); | ||
|
||
useEffect(() => { | ||
clickedChip === children?.toString() ? setIsClicked(true) : setIsClicked(false); | ||
}, [clickedChip, children]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위에서 다른 팀원들이 말한 것처럼, 부모 컴포넌트에서 또한 안에서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 인정합니다! 👍 수정했습니다 ~ |
||
|
||
const handleClick = () => { | ||
if (onClick && children) { | ||
onClick(children.toString()); | ||
} | ||
}; | ||
|
||
return ( | ||
<button css={buttonStyle(isClicked)} onClick={handleClick} {...props}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default CategoryChip; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const CATEGORY = [ | ||
'전체', | ||
'문화/예술/공연', | ||
'봉사/사회활동', | ||
'학술/교양', | ||
'창업/취업', | ||
'어학', | ||
'체육', | ||
'친목', | ||
'기타', | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import CategoryChip from '@/page/showcase/component/CategoryChip/CategoryChip'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta = { | ||
title: 'page/showcase/CategoryChip', | ||
component: CategoryChip, | ||
|
||
args: { children: '어학' }, | ||
argTypes: {}, | ||
} satisfies Meta<typeof CategoryChip>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클릭된 여부에 따라 string값보다 boolean 타입으로
isSelected
와 같은 값으로 전달해주는 건 어떤가요?그리고 그 불리언 값에 따라 스타일 변화하는 식으로 작성해주면 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clickedChip은 현재 어떠한 chip이 클릭되어있는지 알기 위한 prop인거 같아서 현재 코드에서는 boolean 값으로 받는게 맞는거 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네! 문자열로 받은 이유는 이 컴포넌트가 ref를 반환하지 않아서 어떤 버튼을 클릭했는지 알지 못합니다
그래서 다른 버튼을 눌렀을 때 클릭되어 있던 버튼을 언클릭하는 로직을 각 컴포넌트 안에 넣은 것 입니다
(+이 로직을 밖으로 뺄 경우 사용할 때 복잡해질 것 같아서)