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

DropdownField 컴포넌트 구현 #20

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
585 changes: 585 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
54 changes: 54 additions & 0 deletions features/common/components/DropdownField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import { type Control, Controller } from 'react-hook-form'
import Select from 'react-select'

interface Option {
value: string
label: string
}

interface DropdownFieldProps {
label: string
name: string
control: Control<any>
options: Option[]
}

const DropdownField: React.FC<DropdownFieldProps> = ({
label,
name,
control,
options,
}) => {
return (
<div>
<label>{label}</label>
{/* figma 내에서는 존재하지 않는 요소, 확인용으로 첨부 */}
<Controller
name={name}
control={control}
render={({ field: { onChange, value, ref } }) => (
<Select
options={options}
ref={ref}
onChange={onChange}
value={options.find((option) => option.value === value)}
placeholder=""
theme={(theme) => ({
...theme,
borderRadius: 0,
colors: {
...theme.colors,
primary25: '#ebe4d9',
primary: '#665a48',
},
})}
className="border border-beige text-dark-brown "
/>
)}
/>
</div>
)
}

export default DropdownField
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.45.4",
"react-select": "^5.7.4",
"tailwindcss": "3.3.3",
"typescript": "5.1.6"
},
Expand Down
31 changes: 31 additions & 0 deletions pages/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { useForm } from 'react-hook-form'

import Button from '@/features/common/components/Button'
import DropdownField from '@/features/common/components/DropdownField'

export default function Page() {
const options = [
{ value: '생활용품', label: '생활용품' },
{ value: '욕실용품', label: '욕실용품' },
]

const { control, handleSubmit } = useForm()
const onSubmit = (data: any) => {
console.log(data)
}

return (
<form onSubmit={handleSubmit(onSubmit)}>
<DropdownField
label="category"
name="product-category"
control={control}
options={options}
/>
<Button className="mt-6 h-12 w-full" type="submit">
submit
</Button>
</form>
)
}
Loading