1+ import { useState } from "react" ;
2+
13import * as Dialog from "@radix-ui/react-dialog" ;
24import * as VisuallyHidden from "@radix-ui/react-visually-hidden" ;
35import classNames from "classnames" ;
@@ -8,12 +10,25 @@ import Icon from "@/components/ui/Icon/Icon";
810import Input from "@/components/ui/Input/Input" ;
911import Text from "@/components/ui/Text/Text" ;
1012
13+ import { useFocus } from "@/hooks/common/useFocus" ;
14+
1115interface TagSheetProps {
1216 isOpen : boolean ;
1317 handleClose : ( ) => void ;
1418}
1519
1620const TagSheet = ( { isOpen, handleClose } : TagSheetProps ) => {
21+ const { isFocus, onFocus, onBlur } = useFocus ( { defaultFocus : true } ) ;
22+
23+ const [ newTag , setNewTag ] = useState ( "" ) ;
24+
25+ const isInputError = newTag . length > 20 ;
26+ const isInputEmpty = newTag . length === 0 ;
27+
28+ const handleInputChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
29+ setNewTag ( e . target . value ) ;
30+ } ;
31+
1732 return (
1833 < Dialog . Root open = { isOpen } >
1934 < Dialog . Portal >
@@ -36,19 +51,38 @@ const TagSheet = ({ isOpen, handleClose }: TagSheetProps) => {
3651 < Text variant = "titleM" color = "primary" >
3752 더 넣고 싶은 내용이 있나요?
3853 </ Text >
39- < Input variant = "secondary" placeholder = "의견을 입력해주세요." className = { styles . Input } />
54+ < Input
55+ variant = "secondary"
56+ placeholder = "의견을 입력해주세요."
57+ className = { styles . Input }
58+ value = { newTag }
59+ onChange = { handleInputChange }
60+ isFocus = { isFocus }
61+ onFocus = { onFocus }
62+ onBlur = { onBlur }
63+ isError = { isInputError }
64+ />
4065 < div className = { styles . LengthText } >
41- < Text variant = "bodyXsm" color = "tertiary" >
42- *
43- </ Text >
44- < Text variant = "bodyXsm" color = "secondary" >
45- 0
46- </ Text >
47- < Text variant = "bodyXsm" color = "tertiary" >
48- /20
49- </ Text >
66+ { isInputError ? (
67+ < Text variant = "bodyXsm" color = "error" >
68+ *20글자 이내로 입력할 수 있어요.
69+ </ Text >
70+ ) : (
71+ < >
72+ < Text variant = "bodyXsm" color = "tertiary" >
73+ *
74+ </ Text >
75+ < Text variant = "bodyXsm" color = "secondary" >
76+ { newTag . length }
77+ </ Text >
78+ < Text variant = "bodyXsm" color = "tertiary" >
79+ /20
80+ </ Text >
81+ </ >
82+ ) }
5083 </ div >
51- < Button text = "추가하기" />
84+
85+ < Button text = "추가하기" disabled = { isInputError || isInputEmpty } />
5286 </ Dialog . Content >
5387 </ Dialog . Portal >
5488 </ Dialog . Root >
0 commit comments