File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
src/components/common/input Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import { IcSearch } from '@/assets/IconList'
2+ import { useState } from 'react'
3+ import { Controller , useFormContext } from 'react-hook-form'
4+
5+ import { DeletableChip } from '../chip'
6+ import { TextInput , TextInputProps } from './TextInput'
7+
8+ interface TagInputProps extends Omit < TextInputProps , 'endAdornment' > {
9+ name : string
10+ }
11+
12+ export const TagInput = ( { name, ...props } : TagInputProps ) => {
13+ const { control, setValue, getValues } = useFormContext ( )
14+ const [ inputValue , setInputValue ] = useState < string > ( '' )
15+
16+ const handleKeyDown = ( event : React . KeyboardEvent < HTMLInputElement > ) => { }
17+
18+ const handleTagDelete = ( id : string ) => { }
19+
20+ return (
21+ < div >
22+ < Controller
23+ name = { name }
24+ control = { control }
25+ render = { ( { field : { value, onChange } } ) => (
26+ < TextInput
27+ value = { inputValue }
28+ onChange = { e => setInputValue ( e . target . value ) }
29+ onKeyDown = { handleKeyDown }
30+ endAdornment = {
31+ < IcSearch width = { 24 } height = { 24 } aria-label = '검색 아이콘' />
32+ }
33+ />
34+ ) }
35+ />
36+ < div className = 'mt-10 flex flex-wrap gap-2' >
37+ { getValues ( name ) ?. map ( ( tag : { id : string ; label : string } ) => (
38+ < DeletableChip
39+ key = { tag . id }
40+ label = { tag . label }
41+ onDelete = { ( ) => handleTagDelete ( tag . id ) }
42+ />
43+ ) ) }
44+ </ div >
45+ </ div >
46+ )
47+ }
You can’t perform that action at this time.
0 commit comments