Skip to content

Commit 87c7e82

Browse files
authored
Merge pull request #20 from Team-Sttock/feature/common-components
DropdownField 컴포넌트 구현
2 parents fb88cba + cab3476 commit 87c7e82

File tree

58 files changed

+1181
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1181
-4
lines changed

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
"simple-import-sort/exports": "error",
1818
"@typescript-eslint/explicit-function-return-type": "off",
1919
"@typescript-eslint/no-use-before-define": "off",
20+
"@typescript-eslint/strict-boolean-expressions": "off",
2021
"react/jsx-props-no-spreading": "off",
2122
"consistent-return": "off",
2223
"@typescript-eslint/no-misused-promises": [2, {
2324
"checksVoidReturn": {
2425
"attributes": false
2526
}
26-
}]
27+
}],
28+
"@next/next/no-img-element": "off"
2729
}
2830
}

.pnp.cjs

+585
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { CheckIcon } from '@heroicons/react/20/solid'
2+
import React, { useId } from 'react'
3+
import { type Control, Controller } from 'react-hook-form'
4+
import Select from 'react-select'
5+
6+
interface Option {
7+
value: string
8+
label: string
9+
}
10+
11+
interface DropdownFieldProps {
12+
label: string
13+
name: string
14+
control: Control<any>
15+
options: Option[]
16+
}
17+
18+
const CustomOption = ({ innerProps, data, isSelected }: any) => {
19+
return (
20+
<div
21+
{...innerProps}
22+
className="px-2 py-2 flex items-center justify-between hover:bg-beige"
23+
>
24+
{data.label} {isSelected && <CheckIcon className="w-6 h-6"></CheckIcon>}
25+
</div>
26+
)
27+
}
28+
29+
const DropdownField: React.FC<DropdownFieldProps> = ({
30+
name,
31+
control,
32+
options,
33+
}) => {
34+
const id = useId()
35+
return (
36+
<div>
37+
<Controller
38+
name={name}
39+
control={control}
40+
render={({ field: { onChange, value, ref } }) => (
41+
<Select
42+
options={options}
43+
ref={ref}
44+
onChange={onChange}
45+
value={options.find((option) => option.value === value)}
46+
placeholder=""
47+
theme={(theme) => ({
48+
...theme,
49+
borderRadius: 0,
50+
colors: {
51+
...theme.colors,
52+
primary25: '#ebe4d9',
53+
primary: '#0f0e0d',
54+
},
55+
})}
56+
className="border border-beige text-dark-brown"
57+
components={{ Option: CustomOption }}
58+
instanceId={id}
59+
/>
60+
)}
61+
/>
62+
</div>
63+
)
64+
}
65+
66+
export default DropdownField

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"react": "18.2.0",
2424
"react-dom": "18.2.0",
2525
"react-hook-form": "^7.45.4",
26+
"react-select": "^5.7.4",
2627
"tailwindcss": "3.3.3",
2728
"typescript": "5.1.6"
2829
},

pages/test.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import { useForm } from 'react-hook-form'
3+
4+
import Button from '@/features/common/components/Button'
5+
import DropdownField from '@/features/common/components/DropdownField'
6+
7+
export default function Page() {
8+
const options = [
9+
{ value: '생활용품', label: '생활용품' },
10+
{ value: '욕실용품', label: '욕실용품' },
11+
]
12+
13+
const { control, handleSubmit } = useForm()
14+
const onSubmit = (data: any) => {
15+
console.log(data)
16+
}
17+
18+
return (
19+
<form onSubmit={handleSubmit(onSubmit)}>
20+
<DropdownField
21+
label="category"
22+
name="product-category"
23+
control={control}
24+
options={options}
25+
/>
26+
<Button className="mt-6 h-12 w-full" type="submit">
27+
submit
28+
</Button>
29+
</form>
30+
)
31+
}

0 commit comments

Comments
 (0)