-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(member): select, textarea component UI 개선 (#86)
- Loading branch information
Showing
2 changed files
with
64 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,49 @@ | ||
import classNames from 'classnames'; | ||
import { ComponentPropsWithRef } from 'react'; | ||
import { ComponentPropsWithRef, forwardRef } from 'react'; | ||
|
||
interface TextareaProps extends ComponentPropsWithRef<'textarea'> { | ||
id?: string; | ||
label?: string; | ||
value?: string; | ||
className?: string; | ||
} | ||
|
||
const Textarea = ({ | ||
id, | ||
label, | ||
className, | ||
value = '', | ||
maxLength, | ||
...rest | ||
}: TextareaProps) => { | ||
const hasValue = value.length > 0; | ||
const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>( | ||
({ id, label, className, value = '', maxLength, ...rest }, ref) => { | ||
const hasValue = value.length > 0; | ||
|
||
return ( | ||
<div className="relative w-full"> | ||
{label && ( | ||
<label htmlFor={id} className="mb-1 ml-1 text-xs"> | ||
{label} | ||
</label> | ||
)} | ||
<textarea | ||
id={id} | ||
className={classNames( | ||
'border p-2 rounded-lg focus:bg-white outline-none transition-colors', | ||
hasValue ? 'bg-white' : 'bg-gray-100', | ||
className, | ||
return ( | ||
<div className="relative flex w-full"> | ||
{label && ( | ||
<label htmlFor={id} className="mb-1 ml-1 text-xs"> | ||
{label} | ||
</label> | ||
)} | ||
value={value} | ||
maxLength={maxLength} | ||
{...rest} | ||
/> | ||
{maxLength && ( | ||
<div | ||
<textarea | ||
id={id} | ||
ref={ref} | ||
className={classNames( | ||
'absolute bottom-4 right-2 bg-white text-xs px-2 rounded-lg boarder font-medium border', | ||
{ | ||
'text-red-500': value.length >= maxLength, | ||
}, | ||
'border p-2 rounded-lg focus:bg-white outline-none transition-colors', | ||
hasValue ? 'bg-white' : 'bg-gray-100', | ||
className, | ||
)} | ||
> | ||
{value.length}/{maxLength} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
value={value} | ||
maxLength={maxLength} | ||
{...rest} | ||
/> | ||
{maxLength && ( | ||
<div | ||
className={classNames( | ||
'absolute bottom-4 right-2 bg-white text-xs px-2 rounded-lg boarder font-medium border', | ||
{ | ||
'text-red-500': value.length >= maxLength, | ||
}, | ||
)} | ||
> | ||
{value.length}/{maxLength} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default Textarea; |