Skip to content

Commit

Permalink
refactor(member): select, textarea component UI 개선 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwansikk committed Apr 8, 2024
1 parent 76f134a commit 9addda3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 73 deletions.
59 changes: 28 additions & 31 deletions apps/member/src/components/common/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { ComponentPropsWithRef } from 'react';
import { ComponentPropsWithRef, forwardRef } from 'react';

interface SelectOptions {
name: string | number;
Expand All @@ -11,36 +11,33 @@ interface SelectProps extends ComponentPropsWithRef<'select'> {
options: readonly SelectOptions[];
}

const Select = ({
options = [],
label,
className,
id,
...rest
}: SelectProps) => {
return (
<div className={classNames('flex flex-col h-full', className)}>
{label && (
<label htmlFor={id} className="mb-1 ml-1 text-xs">
{label}
</label>
)}
<select
id={id}
className="w-full p-2 border rounded-md grow disabled:bg-gray-50"
{...rest}
>
<option disabled value={'none'}>
미선택
</option>
{options.map(({ name, value }) => (
<option key={value} value={value}>
{name}
const Select = forwardRef<HTMLSelectElement, SelectProps>(
({ options = [], label, className, id, ...rest }, ref) => {
return (
<div className={classNames('flex flex-col', className)}>
{label && (
<label htmlFor={id} className="mb-1 ml-1 text-xs">
{label}
</label>
)}
<select
ref={ref}
id={id}
className="w-full p-2 border rounded-md grow disabled:bg-gray-50"
{...rest}
>
<option disabled value={'none'}>
미선택
</option>
))}
</select>
</div>
);
};
{options.map(({ name, value }) => (
<option key={value} value={value}>
{name}
</option>
))}
</select>
</div>
);
},
);

export default Select;
78 changes: 36 additions & 42 deletions apps/member/src/components/common/Textarea/Textarea.tsx
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;

0 comments on commit 9addda3

Please sign in to comment.