diff --git a/packages/frontend/src/components/ui/field.tsx b/packages/frontend/src/components/ui/field.tsx index 588c9b2..bd09dd4 100644 --- a/packages/frontend/src/components/ui/field.tsx +++ b/packages/frontend/src/components/ui/field.tsx @@ -14,6 +14,7 @@ export function Field({ tabIndex, spellcheck, maxLength, + showCounter = true, }: { label: string; value?: string; @@ -26,6 +27,7 @@ export function Field({ tabIndex?: number; spellcheck?: boolean; maxLength?: number; + showCounter?: boolean; }) { const [internalTouched, setInternalTouched] = useState(false); const isTouched = submitAttempted || internalTouched; @@ -59,6 +61,7 @@ export function Field({ tabIndex={tabIndex} spellCheck={spellcheck} maxLength={maxLength} + showCounter={showCounter} />
{error || invalidMessage !== "" ? ( diff --git a/packages/frontend/src/components/ui/input.tsx b/packages/frontend/src/components/ui/input.tsx index 997e2ab..e1cfe50 100644 --- a/packages/frontend/src/components/ui/input.tsx +++ b/packages/frontend/src/components/ui/input.tsx @@ -2,30 +2,15 @@ import type * as React from "react"; import { cn } from "@/lib/utils"; -function Input({ className, type, ...props }: React.ComponentProps<"input">) { +function Input({ + className, + type, + showCounter = true, + ...props +}: React.ComponentProps<"input"> & { showCounter?: boolean }) { const maxLength = typeof props.maxLength === "number" ? props.maxLength : undefined; const currentLength = typeof props.value === "string" ? props.value.length : undefined; - const showCounter = typeof maxLength === "number" && maxLength > 0 && typeof currentLength === "number"; - - if (!showCounter) { - return ( - - ); - } - - const counterPercent = currentLength / maxLength; - return (
) { )} {...props} /> - = 1 - ? "text-destructive" - : counterPercent >= 0.8 - ? "text-amber-500" - : "text-muted-foreground", - )} - > - {currentLength}/{maxLength} - + {showCounter && currentLength !== undefined && maxLength !== undefined && ( + = 1 + ? "text-destructive" + : currentLength / maxLength >= 0.75 + ? "text-amber-500" + : "text-muted-foreground", + )} + > + {currentLength}/{maxLength} + + )}
); }