Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-zebras-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@setaday/ui": minor
---

Add maxlength error handling logic in TextField
14 changes: 11 additions & 3 deletions packages/ui/src/TextField/TextField.styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cva } from "class-variance-authority";

export const textFieldVariants = cva(
`rounded-[0.8rem] bg-gray-1 flex justify-between items-center px-[2rem] gap-[1rem]`,
"rounded-[0.8rem] mb-[0.4rem] bg-gray-1 flex justify-between items-center px-[2rem] gap-[1rem]",
{
variants: {
isError: {
Expand All @@ -10,8 +10,16 @@ export const textFieldVariants = cva(
inputSize: {
desktop: "w-[33.5rem] h-[5.7rem]",
desktop_lg: "w-[51rem] h-[6.1rem]",
mobile: "w-[33.5rem] h-[4.8rem]",
mobile: "w-[100%] h-[4.8rem]",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿 !! 안그래도 인풋 너비가 고정되어 있어서 추후에 수정해야될 것 같다고 생각했었는데 야무지게 고쳐줬네용 짱

},
},
},
}
);

export const textCountVariants = cva("", {
variants: {
isError: {
true: "text-red-100",
},
},
});
50 changes: 38 additions & 12 deletions packages/ui/src/TextField/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
import { cn } from "@setaday/util";
import type { InputHTMLAttributes } from "react";
import { textFieldVariants } from "./TextField.styles";
import { textCountVariants, textFieldVariants } from "./TextField.styles";

interface TextFieldProps extends InputHTMLAttributes<HTMLInputElement> {
isError?: boolean;
errorMessage?: string;
maxLength: number;
inputSize: "desktop" | "desktop_lg" | "mobile";
value: string;
}

const TextField = ({ isError = false, value, maxLength, inputSize, ...inputProps }: TextFieldProps) => {
const TextField = ({ isError = false, errorMessage, value, maxLength, inputSize, ...inputProps }: TextFieldProps) => {
return (
<div className={cn(textFieldVariants({ isError, inputSize }))}>
<input
{...inputProps}
value={value}
className="bg-gray-1 text-gray-6 font-body7_m_16 w-full focus:outline-none"
/>
<span className="text-gray-2 font-body6_m_12">
{value.length}/{maxLength}
</span>
</div>
<>
<div
className={cn(
textFieldVariants({
isError: isError || value.length > maxLength,
inputSize,
})
)}
>
<input
{...inputProps}
value={value}
className="bg-gray-1 text-gray-6 font-body7_m_16 w-full focus:outline-none"
/>
<span className="text-gray-2 font-body6_m_12">
<span
className={cn(
textCountVariants({
isError: isError || value.length > maxLength,
})
)}
>
{value.length}
</span>
/{maxLength}
</span>
</div>
<div className="h-[1.45rem]">
{value.length > maxLength || (isError && errorMessage) ? (
<span className="text-red-100 font-caption1_m_12">
{value.length > maxLength ? `${maxLength}자가 초과되었어요` : errorMessage}
</span>
) : null}
</div>
</>
);
};

Expand Down