Skip to content

Commit 311fa86

Browse files
committed
refactor: input 컴포넌트 variant 스타일 추가
1 parent b4ca21a commit 311fa86

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

src/components/ui/Input/Input.module.scss

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@
55
height: 3rem;
66
border-radius: 0.875rem;
77
box-shadow: 0 0.125rem 1rem rgba(0, 0, 0, 0.04);
8-
background-color: var(--color-white);
98
padding: 0.75rem 0.875rem;
109
border: 1px solid transparent;
1110
display: flex;
1211
align-items: center;
1312
gap: 0.625rem;
1413
z-index: 1;
1514

15+
&.style-primary {
16+
background-color: var(--color-white);
17+
18+
& > input {
19+
width: calc(100% - 2.25rem);
20+
}
21+
}
22+
23+
&.style-secondary {
24+
background-color: var(--color-gray100);
25+
26+
& > input {
27+
width: 100%;
28+
}
29+
}
30+
1631
&.Focused {
1732
border-color: var(--color-purple);
1833
}
@@ -21,7 +36,6 @@
2136
@include bodyMd;
2237
color: var(--color-text-primary);
2338
line-height: 1.5rem;
24-
width: calc(100% - 2.25rem);
2539

2640
&::placeholder {
2741
color: var(--color-text-tertiary);

src/components/ui/Input/Input.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,31 @@ import classNames from "classnames";
55
import styles from "@/components/ui/Input/Input.module.scss";
66
import type { InputProps } from "@/components/ui/Input/Input.types";
77

8-
const Input = forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
9-
const [isFocused, setIsFocused] = useState(false);
8+
const Input = forwardRef<HTMLInputElement, InputProps>(
9+
({ className, type, variant = "primary", ...props }, ref) => {
10+
const [isFocused, setIsFocused] = useState(false);
1011

11-
const handleFocus = () => setIsFocused(true);
12-
const handleBlur = () => setIsFocused(false);
12+
const handleFocus = () => setIsFocused(true);
13+
const handleBlur = () => setIsFocused(false);
1314

14-
return (
15-
<div className={classNames(styles.InputWrapper, { [styles.Focused]: isFocused })}>
16-
<input
17-
type={type}
18-
ref={ref}
19-
className={classNames(styles.Input, className)}
20-
onFocus={handleFocus}
21-
onBlur={handleBlur}
22-
{...props}
23-
/>
24-
<button>수정</button>
25-
</div>
26-
);
27-
});
15+
return (
16+
<div
17+
className={classNames(styles.InputWrapper, styles[`style-${variant}`], {
18+
[styles.Focused]: isFocused,
19+
})}
20+
>
21+
<input
22+
type={type}
23+
ref={ref}
24+
className={classNames(styles.Input, className)}
25+
onFocus={handleFocus}
26+
onBlur={handleBlur}
27+
{...props}
28+
/>
29+
{variant === "primary" && <button>수정</button>}
30+
</div>
31+
);
32+
},
33+
);
2834

2935
export default Input;

0 commit comments

Comments
 (0)