Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
782f2fb
✨[Feat] 드롭다운 컴포넌트 브랜치 생성 #47
sunnwave Dec 2, 2024
df51bb2
✅[Test] 드롭다운 스토리북 테스트코드 구현 #48 (#50)
sunnwave Dec 3, 2024
8265ce9
💄[Design] DropDown UI 구현 (#67)
sunnwave Dec 6, 2024
a4bde09
♻️[Refactor] dropdown 리팩토링. dropdown과 sorting 버튼 분류
sunnwave Dec 6, 2024
81434df
✨[Feat] 드롭다운 컴포넌트 브랜치 생성 #47
sunnwave Dec 2, 2024
ebbe98b
✅[Test] 드롭다운 스토리북 테스트코드 구현 #48 (#50)
sunnwave Dec 3, 2024
d7b013e
Merge branch '47-feature-common-dropdown' into 84-refactor-common-dro…
sunnwave Dec 8, 2024
cc48427
♻️[Refactor] storybook 테스트코드 리팩토링- navbar, filtering small, filtering…
sunnwave Dec 8, 2024
e342212
♻️[Refactor] Avatar 컴포넌트 사용 #84
sunnwave Dec 8, 2024
e5b465b
✅[Test] 임시 테스트코드 수정 #84
sunnwave Dec 8, 2024
f7747d2
🔥[Remove] SortingButton.tes.tsx 파일 삭제
sunnwave Dec 8, 2024
42fc1b1
💄[Design] SortingButton UI 변경 적용, ✅[Test] 스토리북 테스트코드 수정
sunnwave Dec 8, 2024
d7fc225
Merge branch 'develop' into 94-feature-common-sortingbutton
sunnwave Dec 9, 2024
43ca3b4
🎨[Style] 컬러 시스템 이름 변경 적용 #94
sunnwave Dec 9, 2024
06f1240
Merge branch 'develop' into 94-feature-common-sortingbutton
sunnwave Dec 9, 2024
a9f0147
✨[Feat] sorting button onclick 이벤트 추가 #94
sunnwave Dec 10, 2024
3e853ff
✅[Test] SortingButton jest 테스트코드 작성
sunnwave Dec 10, 2024
5d24a30
Merge branch 'develop' into 94-feature-common-sortingbutton
sunnwave Dec 10, 2024
e27c537
🔥[Remove]DroptDown.stories.tsx 삭제(파일명 오타로 인해 변경했으나 merge 과정 중 삭제되지 않음…
sunnwave Dec 10, 2024
eb8ee2e
Merge branch 'develop' into 94-feature-common-sortingbutton
sunnwave Dec 11, 2024
2667ebd
🐛[Fix] 최신순, 오래된순 정렬 버튼일 때는 일괄적으로 그레이 컬러로 표시되도록 변경 #94
sunnwave Dec 11, 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
11 changes: 6 additions & 5 deletions public/icons/IcSorting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function IcSorting({
width = 24,
height = 24,
isActive = false,
color = '#111827',
color,
}: IcSortingProps) {
return (
<svg
Expand All @@ -20,18 +20,19 @@ function IcSorting({
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={`${isActive ? color : 'stroke-gray-dark-02'}`}
>
<path
d="M3 11L7 7M7 7L11 11M7 7V17"
stroke={isActive ? '#F9FAFB' : color}
strokeWidth="1.8"
stroke={isActive ? color : '#909192'}
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M21 13L17 17M17 17L13 13M17 17V7"
stroke={isActive ? '#F9FAFB' : color}
strokeWidth="1.8"
stroke={isActive ? color : '#909192'}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
Expand Down
27 changes: 27 additions & 0 deletions src/components/sorting-button/SortingButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta, StoryObj } from '@storybook/react';
import SortingButton from './SortingButton';

const meta = {
title: 'Components/SortingButton',
component: SortingButton,
parameters: {
componentSubtitle: '목록의 아이템들의 순서를 정렬하게 만드는 컴포넌트',
},
} satisfies Meta<typeof SortingButton>;

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

export const byDate: Story = {
args: {
variant: 'byDate',
onClickSorting: (e) => alert(e),
},
};

export const byDeadline: Story = {
args: {
variant: 'byDeadline',
onClickSorting: (e) => alert(e),
},
};
43 changes: 43 additions & 0 deletions src/components/sorting-button/SortingButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { render, screen } from '@testing-library/react';
import SortingButton from './SortingButton';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';

describe('SortingButton', () => {
const mockOnClickSorting = jest.fn();

it('마감임박순 Sorting Button 렌더링 확인', async () => {
render(
<SortingButton
variant="byDeadline"
onClickSorting={mockOnClickSorting}
/>,
);

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();

//유저가 최초 클릭 시 최신순->마감임박 순으로 전환. 'DEADLINE'으로 onClickSorting 함수 호출
await userEvent.click(button);
expect(mockOnClickSorting).toHaveBeenCalledWith('DEADLINE');
//유저가 두번째 클릭 시 마감임박->최신순 순으로 전환. 'NEWEST'으로 onClickSorting 함수 호출
await userEvent.click(button);
expect(mockOnClickSorting).toHaveBeenCalledWith('NEWEST');
});

it('날짜순 SortingButton 렌더링 확인', async () => {
render(
<SortingButton variant="byDate" onClickSorting={mockOnClickSorting} />,
);

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();

//유저가 최초 클릭 시 최신순->오래된 순으로 전환. 'OLDEST'으로 onClickSorting 함수 호출
await userEvent.click(button);
expect(mockOnClickSorting).toHaveBeenCalledWith('OLDEST');
//유저가 두번째 클릭 시 오래된 순->최신순 순으로 전환. 'NEWEST'으로 onClickSorting 함수 호출
await userEvent.click(button);
expect(mockOnClickSorting).toHaveBeenCalledWith('NEWEST');
});
});
57 changes: 57 additions & 0 deletions src/components/sorting-button/SortingButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useState } from 'react';
import { IcSorting } from '../../../public/icons/index';

interface SortingButtonProps {
variant: 'byDeadline' | 'byDate';
onClickSorting: (sortBy: string) => void;
}

function SortingButton({ variant, onClickSorting }: SortingButtonProps) {
const [isActive, setIsActive] = useState(false);

const onClick = (): void => {
let sortBy;
setIsActive(!isActive);
switch (variant) {
case 'byDeadline':
sortBy = isActive ? 'NEWEST' : 'DEADLINE';
break;

case 'byDate':
sortBy = isActive ? 'NEWEST' : 'OLDEST';
break;
}
onClickSorting(sortBy);
};

const renderLabel = () => {
switch (variant) {
case 'byDeadline':
return '마감임박순';

case 'byDate':
return isActive ? '오래된순' : '최신순';
}
};

return (
<button
className={`flex h-[40px] items-center rounded-xl border px-[12px] py-[8px] text-sm font-medium ${
variant === 'byDeadline' && isActive
? 'border-green-normal-01 text-green-normal-01'
: 'border-gray-normal-02 text-gray-dark-02'
}`}
onClick={onClick}
>
<span className="pr-[4px]">
<IcSorting
isActive={variant === 'byDeadline' ? isActive : false}
color="stroke-green-normal-02"
/>
</span>
{renderLabel()}
</button>
);
}

export default SortingButton;