Skip to content

Commit e3e1e14

Browse files
authored
feat(ui): TextField에 maxLength Error 처리 로직을 추가합니다. (#96)
1 parent 69b8fab commit e3e1e14

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

.changeset/brave-zebras-cross.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@setaday/ui": minor
3+
---
4+
5+
Add maxlength error handling logic in TextField
+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cva } from "class-variance-authority";
22

33
export const textFieldVariants = cva(
4-
`rounded-[0.8rem] bg-gray-1 flex justify-between items-center px-[2rem] gap-[1rem]`,
4+
"rounded-[0.8rem] mb-[0.4rem] bg-gray-1 flex justify-between items-center px-[2rem] gap-[1rem]",
55
{
66
variants: {
77
isError: {
@@ -10,8 +10,16 @@ export const textFieldVariants = cva(
1010
inputSize: {
1111
desktop: "w-[33.5rem] h-[5.7rem]",
1212
desktop_lg: "w-[51rem] h-[6.1rem]",
13-
mobile: "w-[33.5rem] h-[4.8rem]",
13+
mobile: "w-[100%] h-[4.8rem]",
1414
},
1515
},
16-
},
16+
}
1717
);
18+
19+
export const textCountVariants = cva("", {
20+
variants: {
21+
isError: {
22+
true: "text-red-100",
23+
},
24+
},
25+
});

packages/ui/src/TextField/TextField.tsx

+38-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,52 @@
11
import { cn } from "@setaday/util";
22
import type { InputHTMLAttributes } from "react";
3-
import { textFieldVariants } from "./TextField.styles";
3+
import { textCountVariants, textFieldVariants } from "./TextField.styles";
44

55
interface TextFieldProps extends InputHTMLAttributes<HTMLInputElement> {
66
isError?: boolean;
7+
errorMessage?: string;
78
maxLength: number;
89
inputSize: "desktop" | "desktop_lg" | "mobile";
910
value: string;
1011
}
1112

12-
const TextField = ({ isError = false, value, maxLength, inputSize, ...inputProps }: TextFieldProps) => {
13+
const TextField = ({ isError = false, errorMessage, value, maxLength, inputSize, ...inputProps }: TextFieldProps) => {
1314
return (
14-
<div className={cn(textFieldVariants({ isError, inputSize }))}>
15-
<input
16-
{...inputProps}
17-
value={value}
18-
className="bg-gray-1 text-gray-6 font-body7_m_16 w-full focus:outline-none"
19-
/>
20-
<span className="text-gray-2 font-body6_m_12">
21-
{value.length}/{maxLength}
22-
</span>
23-
</div>
15+
<>
16+
<div
17+
className={cn(
18+
textFieldVariants({
19+
isError: isError || value.length > maxLength,
20+
inputSize,
21+
})
22+
)}
23+
>
24+
<input
25+
{...inputProps}
26+
value={value}
27+
className="bg-gray-1 text-gray-6 font-body7_m_16 w-full focus:outline-none"
28+
/>
29+
<span className="text-gray-2 font-body6_m_12">
30+
<span
31+
className={cn(
32+
textCountVariants({
33+
isError: isError || value.length > maxLength,
34+
})
35+
)}
36+
>
37+
{value.length}
38+
</span>
39+
/{maxLength}
40+
</span>
41+
</div>
42+
<div className="h-[1.45rem]">
43+
{value.length > maxLength || (isError && errorMessage) ? (
44+
<span className="text-red-100 font-caption1_m_12">
45+
{value.length > maxLength ? `${maxLength}자가 초과되었어요` : errorMessage}
46+
</span>
47+
) : null}
48+
</div>
49+
</>
2450
);
2551
};
2652

0 commit comments

Comments
 (0)