11import { useState } from "react" ;
22
33const RetrospectCommentContent = ( {
4- retrospectContent,
5- setRetrospectContent,
6- } : RetrospectContentProps ) => {
7- const MAX_LENGTH = 100 ;
4+ retrospectContent,
5+ setRetrospectContent,
6+ } : RetrospectContentProps ) => {
7+ const MAX_LENGTH = 100 ;
88
9- const [ isFocused , setIsFocused ] = useState ( false ) ;
10- const [ isOverMaxLength , setIsOverMaxLength ] = useState ( false ) ;
9+ const [ isFocused , setIsFocused ] = useState ( false ) ;
10+ const [ isOverMaxLength , setIsOverMaxLength ] = useState ( false ) ;
1111
12- const handleChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
13- const value = e . target . value ;
14- if ( value . length <= MAX_LENGTH ) {
15- setRetrospectContent ( ( prev ) => ( {
16- ...prev ,
17- comment : value ,
18- } ) ) ;
19- setIsOverMaxLength ( false ) ;
20- } else {
21- setIsOverMaxLength ( true ) ;
22- }
23- }
12+ const handleChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
13+ const value = e . target . value ;
14+ if ( value . length <= MAX_LENGTH ) {
15+ setRetrospectContent ( ( prev ) => ( {
16+ ...prev ,
17+ comment : value ,
18+ } ) ) ;
19+ setIsOverMaxLength ( false ) ;
20+ } else {
21+ setIsOverMaxLength ( true ) ;
22+ }
23+ } ;
2424
25- const setUnfocused = ( ) => {
26- setIsFocused ( false ) ;
27- setIsOverMaxLength ( false ) ;
28- }
25+ const setUnfocused = ( ) => {
26+ setIsFocused ( false ) ;
27+ setIsOverMaxLength ( false ) ;
28+ } ;
2929
30- const commentBoxBorder = ( ) => {
31- if ( isOverMaxLength ) {
32- return commentBoxBorders . error ;
33- }
34- if ( isFocused ) {
35- return commentBoxBorders . focused ;
36- }
37- return commentBoxBorders . default ;
38- }
39- const commentBoxBorders = {
40- default : "" ,
41- focused : "outline outline-line-accent" ,
42- error : "outline outline-line-error" ,
43- }
30+ const commentBoxBorder = ( ) => {
31+ if ( isOverMaxLength ) {
32+ return commentBoxBorders . error ;
33+ }
34+ if ( isFocused ) {
35+ return commentBoxBorders . focused ;
36+ }
37+ return commentBoxBorders . default ;
38+ } ;
39+ const commentBoxBorders = {
40+ default : "" ,
41+ focused : "outline outline-line-accent" ,
42+ error : "outline outline-line-error" ,
43+ } ;
4444
45- const commentBoxInfoTextColor = ( ) => {
46- if ( isOverMaxLength ) {
47- return "text-component-accent-red" ;
48- }
49- return "text-gray-alternative" ;
50- }
45+ const commentBoxInfoTextColor = ( ) => {
46+ if ( isOverMaxLength ) {
47+ return "text-component-accent-red" ;
48+ }
49+ return "text-gray-alternative" ;
50+ } ;
5151
52- return (
53- < div className = { `flex flex-col w-full gap-3 px-4 py-3 bg-component-gray-tertiary rounded-[11.25px] ${ commentBoxBorder ( ) } ` } >
54- < textarea
55- value = { retrospectContent . comment }
56- onChange = { handleChange }
57- onFocus = { ( ) => setIsFocused ( true ) }
58- onBlur = { ( ) => setUnfocused ( ) }
59- placeholder = "좋았던 점과 개선할 점을 간단히 작성해주세요."
60- className = "w-full h-20 bg-component-gray-tertiary b3 text-gray-normal placeholder-text-gray-normal
52+ return (
53+ < div
54+ className = { `flex flex-col w-full gap-3 px-4 py-3 bg-component-gray-tertiary rounded-[11.25px] ${ commentBoxBorder ( ) } ` }
55+ >
56+ < textarea
57+ value = { retrospectContent . comment }
58+ onChange = { handleChange }
59+ onFocus = { ( ) => setIsFocused ( true ) }
60+ onBlur = { ( ) => setUnfocused ( ) }
61+ placeholder = "좋았던 점과 개선할 점을 간단히 작성해주세요."
62+ className = "w-full h-20 bg-component-gray-tertiary b2 text-gray-normal placeholder-text-gray-normal
6163 resize-none focus:outline-none"
62- />
64+ />
6365
64- < div className = { `flex justify-between c2 text-right ${ commentBoxInfoTextColor ( ) } ` } >
65- < span > { isOverMaxLength ? "100자 이내로 입력할 수 있어요." : "" } </ span >
66- < span > { retrospectContent . comment . length } / { MAX_LENGTH } 자</ span >
67- </ div >
68- </ div >
69- )
70- }
66+ < div
67+ className = { `flex justify-between c2 text-right ${ commentBoxInfoTextColor ( ) } ` }
68+ >
69+ < span > { isOverMaxLength ? "100자 이내로 입력할 수 있어요." : "" } </ span >
70+ < span >
71+ { retrospectContent . comment . length } / { MAX_LENGTH } 자
72+ </ span >
73+ </ div >
74+ </ div >
75+ ) ;
76+ } ;
7177
72- export default RetrospectCommentContent ;
78+ export default RetrospectCommentContent ;
0 commit comments