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

[#20] 아이디어 유형 선택 컴포넌트 #21

Merged
merged 9 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
129 changes: 129 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-toggle-group": "^1.0.4",
"@tanstack/react-query": "^5.34.1",
"axios": "^1.6.8",
"dayjs": "^1.11.11",
Expand Down
62 changes: 62 additions & 0 deletions src/components/IdeaTypeGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use client'

import React from 'react'
import { ToggleGroupItem, ToggleGroupRoot } from './common/ToggleGroup'
import { typeDatas } from '@/constants/idea'
import styled from 'styled-components'
import { theme } from '@/styles/theme'
import { useAtom } from 'jotai'
import { selectedIdeaTypeAtom } from '@/store/atoms/idea'

const StyledToggleGroupRoot = styled(ToggleGroupRoot)`
display: grid;
grid-template-columns: repeat(5, 60px);
row-gap: 4px;
column-gap: 4px;
justify-content: center;
`
const StyledToggleGroupItem = styled(ToggleGroupItem)`
/* 기본 스타일 */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 60px;
height: 24px;
font-size: 0.8125rem;
font-weight: ${theme.fontWeight.bold};
color: #767676;
background-color: ${theme.color.white};
border: 1px solid ${theme.color.grey500};
border-radius: 12px;
cursor: pointer;

/* 선택 시 스타일 */
&[data-state='on'] {
background-color: ${theme.color.purple700};
color: ${theme.color.white};
border: none;
}
`

const IdeaTypeGroup = () => {
const [value, setValue] = useAtom(selectedIdeaTypeAtom)

return (
<StyledToggleGroupRoot
type="single"
value={value}
onValueChange={(value) => {
if (value) setValue(value)
}}
>
{typeDatas.map((content, idx) => (
<StyledToggleGroupItem key={`${content}-${idx}`} value={content}>
{content}
</StyledToggleGroupItem>
))}
</StyledToggleGroupRoot>
)
}

export default IdeaTypeGroup
15 changes: 15 additions & 0 deletions src/components/common/ToggleGroup/Item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client'

import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group'
import React from 'react'

export interface ToggleGroupItemProps
extends ToggleGroupPrimitive.ToggleGroupItemProps {}

const ToggleGroupItem = ({ children, ...props }: ToggleGroupItemProps) => {
return (
<ToggleGroupPrimitive.Item {...props}>{children}</ToggleGroupPrimitive.Item>
)
}

export default ToggleGroupItem
7 changes: 7 additions & 0 deletions src/components/common/ToggleGroup/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client'

import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group'

const ToggleGroupRoot = ToggleGroupPrimitive.Root

export default ToggleGroupRoot
4 changes: 4 additions & 0 deletions src/components/common/ToggleGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ToggleGroupRoot from '@/components/common/ToggleGroup/Root'
import ToggleGroupItem from '@/components/common/ToggleGroup/Item'

export { ToggleGroupItem, ToggleGroupRoot }
22 changes: 22 additions & 0 deletions src/constants/idea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const typeDatas = [
'식품',
'헬스케어',
'과학',
'경제',
'교육',
'AI',
'통신',
'제조',
'블록체인',
'데이터',
'비즈니스',
'딥테크',
'하드웨어',
'STO',
'커머스',
'인사',
'법률',
'바이오',
'핀테크',
'커피',
]
Empty file removed src/store/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions src/store/atoms/idea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { typeDatas } from '@/constants/idea'
import { atom } from 'jotai'

export const selectedIdeaTypeAtom = atom(typeDatas[0])
1 change: 1 addition & 0 deletions src/store/atoms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@/store/atoms/idea'
1 change: 1 addition & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@/store/atoms'
Loading