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

[Feat] showcase 페이지 category chip 구현 #60

Merged
merged 13 commits into from
Jul 9, 2024
22 changes: 22 additions & 0 deletions src/page/showcase/component/CategoryChip/CategoryChip.style.ts
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,
},
});
30 changes: 30 additions & 0 deletions src/page/showcase/component/CategoryChip/CategoryChip.tsx
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;
Copy link
Member

Choose a reason for hiding this comment

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

클릭된 여부에 따라 string값보다 boolean 타입으로 isSelected와 같은 값으로 전달해주는 건 어떤가요?
그리고 그 불리언 값에 따라 스타일 변화하는 식으로 작성해주면 좋을 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

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

clickedChip은 현재 어떠한 chip이 클릭되어있는지 알기 위한 prop인거 같아서 현재 코드에서는 boolean 값으로 받는게 맞는거 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네! 문자열로 받은 이유는 이 컴포넌트가 ref를 반환하지 않아서 어떤 버튼을 클릭했는지 알지 못합니다
그래서 다른 버튼을 눌렀을 때 클릭되어 있던 버튼을 언클릭하는 로직을 각 컴포넌트 안에 넣은 것 입니다
(+이 로직을 밖으로 뺄 경우 사용할 때 복잡해질 것 같아서)

}

const CategoryChip = ({ children, onClick, clickedChip = '', ...props }: CategoryChipProps) => {
const [isClicked, setIsClicked] = useState(false);

useEffect(() => {
clickedChip === children?.toString() ? setIsClicked(true) : setIsClicked(false);
}, [clickedChip, children]);
Copy link
Contributor

Choose a reason for hiding this comment

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

위에서 다른 팀원들이 말한 것처럼, chip 컴포넌트는 isSelected라는 불리언 값을 전달받고 그에 따른 UI를 표시해주는 것이 더 좋을 것 같아요 !

부모 컴포넌트에서 selectedChip을 관리하고, prop으로 selectedChip === currentChip을 넘겨주는 정도로 구현하면 될 것 같네요 !

또한 안에서 handleClick을 만들어주지 않아도 될 것 같습니다. chip은 그냥 click 핸들러를 연결만 해주고, 위에서 해당 chip을 클릭했을 시의 동작을 핸들러로 생성하여 넘겨주면 될 것 같네요 !!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
11 changes: 11 additions & 0 deletions src/page/showcase/constant/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const CATEGORY = [
'전체',
'문화/예술/공연',
'봉사/사회활동',
'학술/교양',
'창업/취업',
'어학',
'체육',
'친목',
'기타',
];
15 changes: 15 additions & 0 deletions src/story/page/showcase/CategoryChip.stories.tsx
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 = {};
2 changes: 1 addition & 1 deletion src/story/page/showcase/ClubProfileCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ClubProfileCard from '@/page/showcase/component/ClubProfileCard/ClubProfi
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
title: 'Page/ClubProfileCard',
title: 'page/showcase/ClubProfileCard',
component: ClubProfileCard,
parameters: {
layout: 'centered',
Expand Down