-
Notifications
You must be signed in to change notification settings - Fork 3
카드 투두 구현 #43
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
Merged
Merged
카드 투두 구현 #43
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import type { Meta, StoryObj } from '@storybook/nextjs-vite'; | ||
| import type { ComponentProps } from 'react'; | ||
|
|
||
| import { useState } from 'react'; | ||
| import { fn } from 'storybook/test'; | ||
|
|
||
| import TodoCard from './TodoCard'; | ||
| import type { TodoItem } from './types/types'; | ||
|
|
||
| const sampleItems: TodoItem[] = [ | ||
| { id: '1', text: '법인 설립 안내 드리기', checked: false }, | ||
| { id: '2', text: '법인 설립 혹은 변경 등기 비용 안내 드리기', checked: false }, | ||
| { id: '3', text: '입력해주신 정보를 바탕으로 등기신청서 제...', checked: true }, | ||
| ]; | ||
|
|
||
| const completedItems: TodoItem[] = [ | ||
| { id: '1', text: '법인 설립 안내 드리기', checked: true }, | ||
| { id: '2', text: '법인 설립 혹은 변경 등기 비용 안내 드리기', checked: true }, | ||
| { id: '3', text: '입력해주신 정보를 바탕으로 등기신청서 제...', checked: true }, | ||
| ]; | ||
|
|
||
| const meta = { | ||
| title: 'Components/TodoCard', | ||
| component: TodoCard, | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| tags: ['autodocs'], | ||
| args: { | ||
| title: '법인 설립', | ||
| items: sampleItems, | ||
| onKebabClick: fn(), | ||
| }, | ||
| argTypes: { | ||
| expanded: { control: 'boolean' }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div style={{ width: 300 }}> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| } satisfies Meta<typeof TodoCard>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| const ControlledTodoCard = (args: ComponentProps<typeof TodoCard>) => { | ||
| const [items, setItems] = useState(args.items); | ||
|
|
||
| const handleCheckedChange = (id: string, checked: boolean) => { | ||
| setItems((prev) => prev.map((item) => (item.id === id ? { ...item, checked } : item))); | ||
| }; | ||
|
|
||
| return <TodoCard {...args} items={items} onItemCheckedChange={handleCheckedChange} />; | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| render: (args) => <ControlledTodoCard {...args} />, | ||
| }; | ||
|
|
||
| export const AllCompleted: Story = { | ||
| render: (args) => <ControlledTodoCard {...args} />, | ||
| args: { | ||
| items: completedItems, | ||
| }, | ||
| }; | ||
|
|
||
| export const Collapsed: Story = { | ||
| render: (args) => <ControlledTodoCard {...args} />, | ||
| args: { | ||
| expanded: false, | ||
| }, | ||
| }; | ||
|
|
||
| export const CollapsedCompleted: Story = { | ||
| render: (args) => <ControlledTodoCard {...args} />, | ||
| args: { | ||
| items: completedItems, | ||
| expanded: false, | ||
| }, | ||
| }; | ||
|
|
||
| export const Overview: Story = { | ||
| render: (args) => { | ||
| const [items1, setItems1] = useState(sampleItems); | ||
| const [items2, setItems2] = useState(completedItems); | ||
|
|
||
| return ( | ||
| <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}> | ||
| <TodoCard | ||
| {...args} | ||
| title="진행 중인 할일" | ||
| items={items1} | ||
| onItemCheckedChange={(id, checked) => | ||
| setItems1((prev) => prev.map((item) => (item.id === id ? { ...item, checked } : item))) | ||
| } | ||
| /> | ||
| <TodoCard | ||
| {...args} | ||
| title="완료된 할일" | ||
| items={items2} | ||
| onItemCheckedChange={(id, checked) => | ||
| setItems2((prev) => prev.map((item) => (item.id === id ? { ...item, checked } : item))) | ||
| } | ||
| /> | ||
| <TodoCard {...args} title="접힌 상태 (진행 중)" items={sampleItems} expanded={false} /> | ||
| <TodoCard {...args} title="접힌 상태 (완료)" items={completedItems} expanded={false} /> | ||
| </div> | ||
| ); | ||
| }, | ||
| parameters: { | ||
| controls: { disable: true }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||
| 'use client'; | ||||||
|
|
||||||
| import clsx from 'clsx'; | ||||||
| import Image from 'next/image'; | ||||||
|
|
||||||
| import Badge from '@/components/badge/Badge'; | ||||||
| import CheckBox from '@/components/checkbox/CheckBox'; | ||||||
|
|
||||||
| import styles from './styles/TodoCard.module.css'; | ||||||
| import { TODO_CARD_ICONS } from './constants/todoCardConstants'; | ||||||
| import type { TodoCardProps } from './types/types'; | ||||||
|
|
||||||
| /** | ||||||
| * 할일 카드 컴포넌트. | ||||||
| * 제목, 진행 상태 뱃지, 체크박스 리스트를 포함합니다. | ||||||
| * expanded가 false이면 헤더만 표시됩니다. | ||||||
| */ | ||||||
| export default function TodoCard({ | ||||||
| title, | ||||||
| items, | ||||||
| onItemCheckedChange, | ||||||
| onKebabClick, | ||||||
| expanded = true, | ||||||
| className, | ||||||
| }: TodoCardProps) { | ||||||
| const checkedCount = items.filter((item) => item.checked).length; | ||||||
|
Contributor
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.
이를 위해
Suggested change
|
||||||
| const totalCount = items.length; | ||||||
| const badgeLabel = `${checkedCount}/${totalCount}`; | ||||||
| const badgeState = checkedCount === totalCount && totalCount > 0 ? 'done' : 'ongoing'; | ||||||
|
|
||||||
| return ( | ||||||
| <div className={clsx(styles.card, className)}> | ||||||
| <div className={styles.header}> | ||||||
| <span className={styles.title}>{title}</span> | ||||||
| <Badge state={badgeState} size="small" label={badgeLabel} /> | ||||||
| <button type="button" className={styles.kebab} onClick={onKebabClick} aria-label="더보기"> | ||||||
| <Image src={TODO_CARD_ICONS.kebab} alt="" width={16} height={16} /> | ||||||
| </button> | ||||||
| </div> | ||||||
|
|
||||||
| {expanded && items.length > 0 && ( | ||||||
| <div className={styles.body}> | ||||||
| {items.map((item) => ( | ||||||
| <div key={item.id} className={clsx(styles.item, item.checked && styles.itemChecked)}> | ||||||
| <CheckBox | ||||||
| checked={item.checked} | ||||||
| size="small" | ||||||
| label={<span className={styles.itemLabel}>{item.text}</span>} | ||||||
| onCheckedChange={ | ||||||
| onItemCheckedChange | ||||||
| ? (checked) => onItemCheckedChange(item.id, checked) | ||||||
| : undefined | ||||||
| } | ||||||
| /> | ||||||
| </div> | ||||||
| ))} | ||||||
| </div> | ||||||
| )} | ||||||
| </div> | ||||||
| ); | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import kebabSmall from '@/assets/icons/kebab/kebabSmall.svg'; | ||
|
|
||
| export const TODO_CARD_ICONS = { | ||
| kebab: kebabSmall, | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default as TodoCard } from './TodoCard'; | ||
| export type { TodoCardProps, TodoItem } from './types/types'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| .card { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| padding: 12px; | ||
| border-radius: 12px; | ||
| background-color: var(--color-background-inverse); | ||
| box-shadow: | ||
| 0 1px 2px rgba(0, 0, 0, 0.06), | ||
| 0 1px 3px rgba(0, 0, 0, 0.1); | ||
| } | ||
|
|
||
| .header { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .title { | ||
| flex: 1; | ||
| min-width: 0; | ||
| font-size: 14px; | ||
| font-weight: 600; | ||
| line-height: 1.4; | ||
| color: var(--color-text-primary); | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .kebab { | ||
| flex-shrink: 0; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 24px; | ||
| height: 24px; | ||
| padding: 0; | ||
| border: none; | ||
| background: none; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .kebab:hover { | ||
| background-color: var(--color-background-tertiary); | ||
| } | ||
|
|
||
| .body { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 6px; | ||
| } | ||
|
|
||
| .item { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .itemLabel { | ||
| font-size: 12px; | ||
| font-weight: 400; | ||
| line-height: 1.4; | ||
| color: var(--color-text-secondary); | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .itemChecked .itemLabel { | ||
| color: var(--color-text-disabled); | ||
| text-decoration: line-through; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export type TodoItem = { | ||
| /** 항목 고유 ID */ | ||
| id: string; | ||
| /** 항목 텍스트 */ | ||
| text: string; | ||
| /** 체크 여부 */ | ||
| checked: boolean; | ||
| }; | ||
|
|
||
| export type TodoCardProps = { | ||
| /** 카드 제목 */ | ||
| title: string; | ||
| /** 체크박스 항목 목록 */ | ||
| items: TodoItem[]; | ||
| /** 항목 체크 상태 변경 시 호출되는 콜백 */ | ||
| onItemCheckedChange?: (id: string, checked: boolean) => void; | ||
| /** 케밥(⋮) 버튼 클릭 시 호출되는 콜백 */ | ||
| onKebabClick?: () => void; | ||
| /** 체크리스트 펼침 여부 (기본값: true) */ | ||
| expanded?: boolean; | ||
| /** 추가 CSS 클래스 */ | ||
| className?: string; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Overview스토리 내에서setItems1과setItems2에 전달되는 상태 업데이트 로직이 중복됩니다. 이 로직은ControlledTodoCard컴포넌트의handleCheckedChange함수에도 동일하게 존재합니다. 코드 중복을 줄이고 유지보수성을 높이기 위해 이 로직을 별도의 헬퍼 함수로 추출하여 재사용하는 것을 고려해 보세요.예를 들어, 다음과 같은 헬퍼 함수를 정의할 수 있습니다.
그리고 이 함수를
handleCheckedChange와Overview스토리에서 사용하면 코드가 더 간결해집니다.