-
Notifications
You must be signed in to change notification settings - Fork 2
[Refactor/#67] 만다라트 분기 추가 v.2 #72
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
Changes from all commits
79f3891
6c71e96
77e7f54
0a9e085
33c1f1a
4ecb495
66d1b39
1bd3c53
0513386
89601e3
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 |
|---|---|---|
| @@ -1,17 +1,28 @@ | ||
| import { style } from '@vanilla-extract/css'; | ||
|
|
||
| export const gridDefault = style({ | ||
| const baseGrid = { | ||
| display: 'grid', | ||
| gridTemplateColumns: 'repeat(3, 1fr)', | ||
| gap: '1.6rem', | ||
| width: 'fit-content', | ||
| gap: '1.2rem', | ||
| margin: '0 auto', | ||
| }); | ||
|
|
||
| export const gridSmall = style({ | ||
| display: 'grid', | ||
| gridTemplateColumns: 'repeat(3, 1fr)', | ||
| gap: '2rem', | ||
| width: 'fit-content', | ||
| margin: '0 auto', | ||
| }); | ||
| }; | ||
|
|
||
| export const grid = { | ||
| TODO_SUB: style({ | ||
| ...baseGrid, | ||
| gap: '1rem', | ||
| }), | ||
| TODO_MAIN: style({ | ||
| ...baseGrid, | ||
| gap: '1.6rem', | ||
| }), | ||
| TODO_EDIT: style({ | ||
| ...baseGrid, | ||
| gap: '2rem', | ||
| }), | ||
| MY_MANDAL: style({ | ||
| ...baseGrid, | ||
| gap: '3rem', | ||
| }), | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| import { Square } from './Square'; | ||
| import { Main, Sub } from './Square'; | ||
| import * as styles from './Mandalart.css'; | ||
| import { MOCK_MANDALART_DATA } from './mock'; | ||
|
|
||
| export type Cycle = 'DAILY' | 'WEEKLY' | 'ONCE'; | ||
|
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. p3) 여기 부분은 다른 컴포넌트에서도 사용돼서 타입으로 따로 분리해주셔도 좋을 것 같아요 ..!
Contributor
Author
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. 이건 따로 이슈 파서 진행하는 게 좋을 것 같아요! |
||
| export type MandalartSize = 'small' | 'default'; | ||
| export type MandalartType = 'TODO_SUB' | 'TODO_MAIN' | 'TODO_EDIT' | 'MY_MANDAL'; | ||
|
|
||
| export interface SubGoal { | ||
| title: string; | ||
|
|
@@ -16,37 +16,40 @@ export interface SubGoal { | |
| interface MandalartProps { | ||
| mainGoal?: string; | ||
| subGoals?: SubGoal[]; | ||
| size?: MandalartSize; | ||
| type: MandalartType; | ||
| onGoalClick?: (position: number) => void; | ||
| } | ||
|
|
||
| const CENTER_INDEX = 4; | ||
|
|
||
| const Mandalart = ({ | ||
| mainGoal = MOCK_MANDALART_DATA.mainGoal, | ||
| subGoals = MOCK_MANDALART_DATA.subGoals, | ||
| size = 'default', | ||
| type, | ||
| onGoalClick, | ||
| }: MandalartProps) => { | ||
| const [selectedGoal, setSelectedGoal] = useState<number | null>(null); | ||
|
|
||
| const handleGoalClick = (position: number) => { | ||
| setSelectedGoal(selectedGoal === position ? null : position); | ||
| onGoalClick?.(position); | ||
| }; | ||
|
Comment on lines
33
to
36
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. p3) onGoalClick 호출을 상태 업데이트 전에 하는 게 좋지 않을까요 ?? 부모 컴포넌트에서 최신 상태를 받을 수 있도록 하면 좋을 것 같다는 생각이 들었습니다 !! |
||
|
|
||
| const renderSquare = (index: number) => { | ||
| if (index === CENTER_INDEX) { | ||
| return <Square.Main key={index} content={mainGoal} size={size} />; | ||
| return <Main key={index} content={mainGoal} type={type} />; | ||
| } | ||
|
|
||
| const subGoalIndex = index > CENTER_INDEX ? index - 1 : index; | ||
| const subGoal = subGoals[subGoalIndex]; | ||
|
|
||
| return ( | ||
| <Square.Sub | ||
| <Sub | ||
| key={index} | ||
| content={subGoal.title} | ||
| isCompleted={selectedGoal === subGoalIndex} | ||
| onClick={() => handleGoalClick(subGoalIndex)} | ||
| size={size} | ||
| type={type} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
@@ -55,7 +58,7 @@ const Mandalart = ({ | |
| .fill(null) | ||
| .map((_, index) => renderSquare(index)); | ||
|
|
||
| return <div className={size === 'small' ? styles.gridSmall : styles.gridDefault}>{squares}</div>; | ||
| return <div className={styles.grid[type]}>{squares}</div>; | ||
| }; | ||
|
|
||
| export default Mandalart; | ||
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.
p5) 스토리북에서 직접 타입을 선택할 수 있게 한 게 너무 좋네요 !! 컴포넌트 테스트가 훨씬 편해질 것 같아요 ㅡㅡ