Skip to content

Commit ae70be4

Browse files
committed
refactor: input 수정
1 parent e11fc9c commit ae70be4

File tree

3 files changed

+61
-53
lines changed

3 files changed

+61
-53
lines changed

src/components/ReceiptEdit/ReceiptEdit.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const ReceiptEdit = () => {
1717

1818
const { setOcrText } = useCreateReviewStore();
1919

20-
const [formData, setFormData] = useState<{ [key: string]: string }[]>([]);
20+
const [formData, setFormData] = useState<{ [key: string]: string }[]>([
21+
{ test: "abc" },
22+
{ test2: "aadsasf" },
23+
]);
2124
const [focusState, setFocusState] = useState<{ [key: string]: boolean }>({});
2225

2326
useEffect(() => {

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
@use "@/styles/_mixins.scss" as *;
22

33
.InputWrapper {
4+
position: relative;
5+
display: flex;
6+
align-items: center;
7+
8+
button {
9+
position: absolute;
10+
right: 0.875rem;
11+
color: var(--color-primary-purple);
12+
line-height: 1.3125rem;
13+
14+
@include bodySm;
15+
}
16+
}
17+
18+
.Input {
419
width: 100%;
520
height: 3rem;
621
border-radius: 0.875rem;
722
padding: 0.75rem 0.875rem;
823
border: 1px solid transparent;
9-
display: flex;
10-
align-items: center;
11-
gap: 0.625rem;
24+
color: var(--color-text-primary);
25+
line-height: 1.5rem;
26+
27+
@include bodyM;
28+
29+
&::placeholder {
30+
color: var(--color-text-tertiary);
31+
}
1232

1333
&.style-primary {
1434
background-color: var(--color-white);
1535
box-shadow: 0 0.125rem 1rem rgba(0, 0, 0, 0.04);
16-
17-
& > input {
18-
width: calc(100% - 2.25rem);
19-
}
2036
}
2137

2238
&.style-secondary {
2339
background-color: var(--color-gray100);
40+
}
2441

25-
& > input {
26-
width: 100%;
27-
}
42+
&:focus {
43+
border-color: var(--color-primary-purple);
2844
}
2945

3046
&.Focused {
@@ -34,22 +50,6 @@
3450
&.Error {
3551
border-color: var(--color-text-error);
3652
}
37-
38-
.Input {
39-
@include bodyM;
40-
color: var(--color-text-primary);
41-
line-height: 1.5rem;
42-
43-
&::placeholder {
44-
color: var(--color-text-tertiary);
45-
}
46-
}
47-
48-
button {
49-
@include bodySm;
50-
color: var(--color-primary-purple);
51-
line-height: 1.3125rem;
52-
}
5353
}
5454

5555
.InputStory {

src/components/ui/Input/Input.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { forwardRef, useRef } from "react";
1+
import { forwardRef, useEffect, useState } from "react";
22

33
import classNames from "classnames";
44

@@ -7,37 +7,42 @@ import type { InputProps } from "@/components/ui/Input/Input.types";
77

88
const Input = forwardRef<HTMLInputElement, InputProps>(
99
({ className, type, variant = "primary", onFocus, isFocus, onBlur, isError, ...props }, ref) => {
10-
const inputRef = useRef<HTMLInputElement>(null);
10+
const [focused, setFocused] = useState(isFocus || false);
1111

12-
const handleDivClick = () => {
13-
if (onFocus) {
14-
const fakeEvent = { target: inputRef.current } as React.FocusEvent<HTMLInputElement>;
15-
onFocus(fakeEvent);
16-
}
12+
const inputRef = ref as React.RefObject<HTMLInputElement>;
13+
14+
const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {
15+
setFocused(true);
16+
onFocus && onFocus(e);
1717
};
1818

19-
const handleDivBlur = () => {
20-
if (onBlur) {
21-
const fakeEvent = { target: inputRef.current } as React.FocusEvent<HTMLInputElement>;
22-
onBlur(fakeEvent);
23-
}
19+
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
20+
setFocused(false);
21+
onBlur && onBlur(e);
2422
};
2523

24+
useEffect(() => {
25+
if (isFocus !== undefined) {
26+
setFocused(isFocus);
27+
}
28+
}, [isFocus]);
29+
2630
return (
27-
<div
28-
className={classNames(
29-
styles.InputWrapper,
30-
styles[`style-${variant}`],
31-
{
32-
[styles.Focused]: isFocus,
33-
[styles.Error]: isError,
34-
},
35-
className,
36-
)}
37-
onClick={handleDivClick}
38-
onBlur={handleDivBlur}
39-
>
40-
<input type={type} ref={ref} className={styles.Input} {...props} onBlur={handleDivBlur} />
31+
<div className={styles.InputWrapper}>
32+
<input
33+
type={type}
34+
ref={inputRef}
35+
className={classNames(
36+
styles.Input,
37+
styles[`style-${variant}`],
38+
focused && styles.Focused,
39+
isError && styles.Error,
40+
className,
41+
)}
42+
onFocus={handleFocus}
43+
onBlur={handleBlur}
44+
{...props}
45+
/>
4146
{variant === "primary" && <button>수정</button>}
4247
</div>
4348
);

0 commit comments

Comments
 (0)