-
Notifications
You must be signed in to change notification settings - Fork 3
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: add gdsc-grass component #27
Draft
kanghyun98
wants to merge
12
commits into
main
Choose a base branch
from
feat/9_gdsc-grass-front
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1350b1f
feat: add GrassGraphItem component
kanghyun98 6cd0e90
feat: add GrassGraph component
kanghyun98 9dd8db3
feat: add GrassExplain component
kanghyun98 93d27b0
feat: add GrassTip component
kanghyun98 6180b6f
feat: add Grass component
kanghyun98 fd6c596
feat: add constants
kanghyun98 1f8c5ac
feat: add point and move tip area by cursor location
kanghyun98 fc15567
chore: add global.css and apply to page and storybook
kanghyun98 f2a1ec9
refactor: use constant and add design to Grass component
kanghyun98 419a43c
refactor: add design to GrassExplain component
kanghyun98 c311df3
refactor: change design and mouseenter event about GrassGraph component
kanghyun98 6f67441
refactor: change style about GrassTip component
kanghyun98 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 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
This file contains 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,10 @@ | ||
*, | ||
*:before, | ||
*:after { | ||
font-family: Pretendard; | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} |
This file contains 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,16 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const grassWrapperStyle = style({ | ||
position: 'relative', | ||
maxWidth: '1060px', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
backgroundColor: 'transparent', | ||
margin: '0 10px', | ||
}); | ||
|
||
// TODO: style, 반응형, constant | ||
export const grassInfoStyle = style({ | ||
fontSize: '18px', | ||
color: '#D6D6D6', | ||
}); |
This file contains 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,22 @@ | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import Grass, { GrassPropsType } from './Grass'; | ||
|
||
// dummy data | ||
const dummyData = [] as any[]; | ||
for (let i = 1; i <= 365; i++) { | ||
const dayObj = { date: new Date(new Date().setDate(i)), count: i % 5 }; | ||
dummyData.push(dayObj); | ||
} | ||
|
||
export default { | ||
title: 'github-contest/Grass', | ||
component: Grass, | ||
} as ComponentMeta<typeof Grass>; | ||
|
||
const Template: ComponentStory<typeof Grass> = ({ data }: GrassPropsType) => ( | ||
<Grass data={data} /> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { data: dummyData }; |
This file contains 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,66 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
import { CountType } from '@/constants/github'; | ||
import GrassGraph, { GrassGraphDataType } from './GrassGraph'; | ||
import GrassTip, { GrassTipDataType } from './GrassTip'; | ||
import GrassExplain from './GrassExplain'; | ||
|
||
import * as styles from './Grass.css'; | ||
|
||
export interface GrassPropsType { | ||
data: GrassGraphDataType[]; | ||
} | ||
|
||
const Grass = ({ data }: GrassPropsType) => { | ||
const [grassTipData, setGrassTipData] = useState<GrassTipDataType>({ | ||
x: 0, | ||
y: 0, | ||
infoText: '', | ||
isHover: false, | ||
}); | ||
|
||
const totalCount = data.reduce((acc, cur) => { | ||
return acc + cur.count; | ||
}, 0); | ||
|
||
const onMouseEnter = useCallback( | ||
(x?: number, y?: number, infoText?: string) => { | ||
if (x === undefined || y === undefined || infoText === undefined) { | ||
return; | ||
} | ||
|
||
setGrassTipData((prev) => ({ | ||
...prev, | ||
x, | ||
y, | ||
infoText, | ||
isHover: true, | ||
})); | ||
}, | ||
[], | ||
); | ||
|
||
const onMouseLeave = useCallback(() => { | ||
setGrassTipData((prev) => ({ | ||
...prev, | ||
isHover: false, | ||
})); | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.grassWrapperStyle}> | ||
<div | ||
className={styles.grassInfoStyle} | ||
>{`${totalCount} ${CountType}s in the last year`}</div> | ||
<GrassGraph | ||
data={data} | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
/> | ||
<GrassExplain /> | ||
<GrassTip grassTipData={grassTipData} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Grass; |
33 changes: 33 additions & 0 deletions
33
src/components/github-contest/Grass/GrassExplain/GrassExplain.css.ts
This file contains 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,33 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
// TODO: style(사이즈), 반응형, constant | ||
export const explainWrapper = style({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
width: '100%', | ||
fontSize: '18px', | ||
color: '#D6D6D6', | ||
paddingLeft: '40px', | ||
marginTop: '3px', | ||
}); | ||
|
||
export const explainLinkStyle = style({ | ||
textDecoration: 'none', | ||
color: '#D6D6D6', | ||
|
||
':hover': { | ||
color: '#4286F5', | ||
}, | ||
}); | ||
|
||
export const colorExampleWrapperStyle = style({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}); | ||
|
||
export const colorExampleStyle = style({ | ||
width: '91px', | ||
height: '15px', | ||
margin: '0 8px', | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/components/github-contest/Grass/GrassExplain/GrassExplain.stories.tsx
This file contains 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,8 @@ | ||
import GrassExplain from './GrassExplain'; | ||
|
||
export default { | ||
title: 'github-contest/Grass/GrassExplain', | ||
component: GrassExplain, | ||
}; | ||
|
||
export const Default = GrassExplain; |
33 changes: 33 additions & 0 deletions
33
src/components/github-contest/Grass/GrassExplain/GrassExplain.tsx
This file contains 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,33 @@ | ||
import Link from 'next/link'; | ||
import GrassGraphItem, { | ||
GrassLevelType, | ||
} from '@/components/github-contest/Grass/GrassGraph/GrassGraphItem'; | ||
import * as styles from './GrassExplain.css'; | ||
|
||
const GrassExplain = () => { | ||
const levels = [0, 1, 2, 3, 4] as GrassLevelType[]; | ||
|
||
// TODO: 커밋 개수 가져오는 로직 설명 링크 추가 (노션 or new page) | ||
const explainURL = '/'; | ||
|
||
return ( | ||
<div className={styles.explainWrapper}> | ||
<Link className={styles.explainLinkStyle} href={explainURL}> | ||
Learn how we count commits | ||
</Link> | ||
<div className={styles.colorExampleWrapperStyle}> | ||
<span>Less</span> | ||
<svg className={styles.colorExampleStyle}> | ||
{levels.map((level) => { | ||
return ( | ||
<GrassGraphItem x={level * 19} y={0} level={level} key={level} /> | ||
); | ||
})} | ||
</svg> | ||
<span>More</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GrassExplain; |
This file contains 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,4 @@ | ||
import GrassExplain from './GrassExplain'; | ||
|
||
export * from './GrassExplain'; | ||
export default GrassExplain; |
22 changes: 22 additions & 0 deletions
22
src/components/github-contest/Grass/GrassGraph/GrassGraph.css.ts
This file contains 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,22 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
// TODO: stlye(font size), constant, 반응형 | ||
export const grassGraphFontStyle = style({ | ||
fontSize: '18px', | ||
fill: '#D6D6D6', | ||
}); | ||
|
||
export const grassGraphBaseStyle = style({ | ||
position: 'relative', | ||
width: '100%', | ||
overflowX: 'scroll', | ||
|
||
'::-webkit-scrollbar': { | ||
height: '0px', | ||
}, | ||
}); | ||
|
||
export const grassGraphSvgStyle = style({ | ||
minWidth: '1060px', | ||
height: '160px', | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/components/github-contest/Grass/GrassGraph/GrassGraph.stories.tsx
This file contains 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,22 @@ | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import GrassGraph, { GrassGraphPropsType } from './GrassGraph'; | ||
|
||
// dummy data | ||
const dummyData = [] as any[]; | ||
for (let i = 1; i <= 365; i++) { | ||
const dayObj = { date: new Date(new Date().setDate(i)), count: i % 5 }; | ||
dummyData.push(dayObj); | ||
} | ||
|
||
export default { | ||
title: 'github-contest/Grass/GrassGraph', | ||
component: GrassGraph, | ||
} as ComponentMeta<typeof GrassGraph>; | ||
|
||
const Template: ComponentStory<typeof GrassGraph> = ({ | ||
data, | ||
}: GrassGraphPropsType) => <GrassGraph data={data} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { data: dummyData }; |
115 changes: 115 additions & 0 deletions
115
src/components/github-contest/Grass/GrassGraph/GrassGraph.tsx
This file contains 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,115 @@ | ||
import { DayInfo, MonthInfo, MonthTxtTrans } from '@/constants/date'; | ||
import { CountType } from '@/constants/github'; | ||
import GrassGraphItem from './GrassGraphItem'; | ||
import * as styles from './GrassGraph.css'; | ||
|
||
export interface GrassGraphDataType { | ||
date: Date; | ||
count: number; | ||
} | ||
|
||
export interface GrassGraphPropsType { | ||
data: GrassGraphDataType[]; | ||
onMouseEnter?: (x?: number, y?: number, infoText?: string) => void; | ||
onMouseLeave?: () => void; | ||
} | ||
|
||
function getLevel(count: number) { | ||
if (count === 0) return 0; | ||
if (count <= 2) return 1; | ||
if (count <= 5) return 2; | ||
if (count <= 8) return 3; | ||
if (count >= 9) return 4; | ||
return 0; | ||
} | ||
|
||
// TODO: 디자인에 따라 rectX, rectY 이동값 반영 | ||
const GrassGraph = ({ | ||
data, | ||
onMouseEnter, | ||
onMouseLeave, | ||
}: GrassGraphPropsType) => { | ||
const grass = () => { | ||
let rectX = 45; | ||
|
||
const monthArea = [] as JSX.Element[]; // 상단의 월 표시 | ||
const dayArea = [] as JSX.Element[]; // 좌측의 요일 표시 | ||
|
||
const grassGraphArea = data?.map(({ date, count }, idx) => { | ||
const thisYear = date.getFullYear(); | ||
const thisMonth = date.getMonth(); | ||
const thisDate = date.getDate(); | ||
const thisDay = date.getDay(); | ||
|
||
// 텍스트 (2 commits on January 19, 2023) | ||
const dateInfo = `${MonthTxtTrans[thisMonth]} ${thisDate}, ${thisYear}`; | ||
const countInfo = | ||
count > 1 ? `${count} ${CountType}s` : `${count} ${CountType}`; // 복수 처리 | ||
const infoText = `${countInfo} on ${dateInfo}`; | ||
|
||
// 위치 | ||
if (thisDay === 0 && idx !== 0) { | ||
rectX += 19; // 일요일 나올 때마다 우로 이동 | ||
} | ||
const rectY = 30 + thisDay * 19; | ||
const monthY = 20; | ||
const dayY = rectY + 10; | ||
|
||
// 색상 기준 레벨 | ||
const level = getLevel(count); | ||
if ((thisDay === 1 || thisDay === 3 || thisDay === 5) && idx < 7) { | ||
dayArea.push( | ||
<text | ||
x={0} | ||
y={dayY} | ||
key={thisDay} | ||
className={styles.grassGraphFontStyle} | ||
> | ||
{DayInfo[thisDay]} | ||
</text>, | ||
); | ||
} | ||
|
||
if (thisDate === 1) { | ||
monthArea.push( | ||
<text | ||
x={rectX} | ||
y={monthY} | ||
key={thisMonth} | ||
className={styles.grassGraphFontStyle} | ||
> | ||
{MonthInfo[thisMonth]} | ||
</text>, | ||
); | ||
} | ||
|
||
return ( | ||
<GrassGraphItem | ||
infoText={infoText} | ||
x={rectX} | ||
y={rectY} | ||
key={dateInfo} | ||
level={level} | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<g>{dayArea}</g> | ||
<g>{monthArea}</g> | ||
<g>{grassGraphArea}</g> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={styles.grassGraphBaseStyle}> | ||
<svg className={styles.grassGraphSvgStyle}>{grass()}</svg> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GrassGraph; |
16 changes: 16 additions & 0 deletions
16
src/components/github-contest/Grass/GrassGraph/GrassGraphItem/GrassGraphItem.css.ts
This file contains 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,16 @@ | ||
import { style, styleVariants } from '@vanilla-extract/css'; | ||
|
||
export const base = style({ | ||
outline: '1px solid rgba(27, 31, 35, 0.06);', | ||
outlineOffset: '-1px', | ||
borderRadius: '2px', | ||
}); | ||
|
||
// TODO: constant | ||
export const grassGraphItemStyle = styleVariants({ | ||
'0': [base, { fill: '#EDEDED' }], | ||
'1': [base, { fill: '#AAFFFF' }], | ||
'2': [base, { fill: '#58C4C4' }], | ||
'3': [base, { fill: '#00A4CA' }], | ||
'4': [base, { fill: '#00688F' }], | ||
}); |
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.
ㅋㅋㅋ와 이거 그래프 구현하기 꽤 어렵겠다 생각했는데,, 역시,, 👍 이강현이 이강현했네요