Skip to content

Commit d8bd7c4

Browse files
committed
feat: 태그 시트 input 기능 추가
1 parent 51180ad commit d8bd7c4

File tree

9 files changed

+64
-19
lines changed

9 files changed

+64
-19
lines changed

src/components/ReceiptEdit/ReceiptEdit.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ const ReceiptEdit = () => {
1111
const [placeName, setPlaceName] = useState("청담커피 앤 토스트");
1212
const [foodName, setFoodName] = useState("카야토스트+음료세트");
1313

14-
const { isFocus: isPlaceFocus, onFocus: handlePlaceFocus, onBlur: handlePlaceBlur } = useFocus();
15-
const { isFocus: isFoodFocus, onFocus: handleFoodFocus, onBlur: handleFoodBlur } = useFocus();
14+
const {
15+
isFocus: isPlaceFocus,
16+
onFocus: handlePlaceFocus,
17+
onBlur: handlePlaceBlur,
18+
} = useFocus({});
19+
const { isFocus: isFoodFocus, onFocus: handleFoodFocus, onBlur: handleFoodBlur } = useFocus({});
1620

1721
return (
1822
<div className={styles.ReceiptEdit}>

src/components/SelectTag/TagSheet/TagSheet.tsx

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useState } from "react";
2+
13
import * as Dialog from "@radix-ui/react-dialog";
24
import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
35
import classNames from "classnames";
@@ -8,12 +10,25 @@ import Icon from "@/components/ui/Icon/Icon";
810
import Input from "@/components/ui/Input/Input";
911
import Text from "@/components/ui/Text/Text";
1012

13+
import { useFocus } from "@/hooks/common/useFocus";
14+
1115
interface TagSheetProps {
1216
isOpen: boolean;
1317
handleClose: () => void;
1418
}
1519

1620
const TagSheet = ({ isOpen, handleClose }: TagSheetProps) => {
21+
const { isFocus, onFocus, onBlur } = useFocus({ defaultFocus: true });
22+
23+
const [newTag, setNewTag] = useState("");
24+
25+
const isInputError = newTag.length > 20;
26+
const isInputEmpty = newTag.length === 0;
27+
28+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
29+
setNewTag(e.target.value);
30+
};
31+
1732
return (
1833
<Dialog.Root open={isOpen}>
1934
<Dialog.Portal>
@@ -36,19 +51,38 @@ const TagSheet = ({ isOpen, handleClose }: TagSheetProps) => {
3651
<Text variant="titleM" color="primary">
3752
더 넣고 싶은 내용이 있나요?
3853
</Text>
39-
<Input variant="secondary" placeholder="의견을 입력해주세요." className={styles.Input} />
54+
<Input
55+
variant="secondary"
56+
placeholder="의견을 입력해주세요."
57+
className={styles.Input}
58+
value={newTag}
59+
onChange={handleInputChange}
60+
isFocus={isFocus}
61+
onFocus={onFocus}
62+
onBlur={onBlur}
63+
isError={isInputError}
64+
/>
4065
<div className={styles.LengthText}>
41-
<Text variant="bodyXsm" color="tertiary">
42-
*
43-
</Text>
44-
<Text variant="bodyXsm" color="secondary">
45-
0
46-
</Text>
47-
<Text variant="bodyXsm" color="tertiary">
48-
/20
49-
</Text>
66+
{isInputError ? (
67+
<Text variant="bodyXsm" color="error">
68+
*20글자 이내로 입력할 수 있어요.
69+
</Text>
70+
) : (
71+
<>
72+
<Text variant="bodyXsm" color="tertiary">
73+
*
74+
</Text>
75+
<Text variant="bodyXsm" color="secondary">
76+
{newTag.length}
77+
</Text>
78+
<Text variant="bodyXsm" color="tertiary">
79+
/20
80+
</Text>
81+
</>
82+
)}
5083
</div>
51-
<Button text="추가하기" />
84+
85+
<Button text="추가하기" disabled={isInputError || isInputEmpty} />
5286
</Dialog.Content>
5387
</Dialog.Portal>
5488
</Dialog.Root>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
border-color: var(--color-primary-purple);
3232
}
3333

34+
&.Error {
35+
border-color: var(--color-text-error);
36+
}
37+
3438
.Input {
3539
@include bodyM;
3640
color: var(--color-text-primary);

src/components/ui/Input/Input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import styles from "@/components/ui/Input/Input.module.scss";
66
import type { InputProps } from "@/components/ui/Input/Input.types";
77

88
const Input = forwardRef<HTMLInputElement, InputProps>(
9-
({ className, type, variant = "primary", isFocus, ...props }, ref) => {
9+
({ className, type, variant = "primary", isFocus, isError, ...props }, ref) => {
1010
return (
1111
<div
1212
className={classNames(
1313
styles.InputWrapper,
1414
styles[`style-${variant}`],
1515
{
1616
[styles.Focused]: isFocus,
17+
[styles.Error]: isError,
1718
},
1819
className,
1920
)}

src/components/ui/Input/Input.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ type InputFieldVariant = "primary" | "secondary";
33
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
44
variant?: InputFieldVariant;
55
isFocus?: boolean;
6+
isError?: boolean;
67
}

src/components/ui/Text/Text.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
line-height: 1.5;
55

66
@each $color-name
7-
in ("white", "black", "primary", "secondary", "tertiary", "quarternary", "gradient")
7+
in ("white", "black", "primary", "secondary", "tertiary", "quarternary", "gradient", "error")
88
{
99
@if $color-name == "gradient" {
1010
&.color-#{$color-name} {

src/components/ui/Text/Text.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type TextColor =
1919
| "secondary"
2020
| "tertiary"
2121
| "quarternary"
22-
| "gradient";
22+
| "gradient"
23+
| "error";
2324

2425
export interface TextProps extends React.HTMLAttributes<HTMLSpanElement> {
2526
as?: React.ElementType;

src/hooks/common/useFocus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from "react";
22

3-
export const useFocus = () => {
4-
const [isFocus, setIsFocus] = useState(false);
3+
export const useFocus = ({ defaultFocus }: { defaultFocus?: boolean }) => {
4+
const [isFocus, setIsFocus] = useState(defaultFocus);
55

66
const onFocus = () => {
77
setIsFocus(true);

src/styles/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var(--color-primary-pink),
2424
var(--color-primary-purple)
2525
);
26+
--color-text-error: #d45085;
2627

2728
--color-white: #ffffff;
2829
--color-black: #000000;
@@ -35,7 +36,6 @@
3536
--color-gray600: #363642;
3637
--color-gray700: #161636;
3738
--color-bg-gradient: linear-gradient(180deg, #ffffff, #dcdce8);
38-
--color-bg-error: #d45085;
3939
--color-primary-purple: #443fb6;
4040
--color-primary-pink: #d444ba;
4141
}

0 commit comments

Comments
 (0)