feat: input params

This commit is contained in:
2025-04-16 14:33:55 +03:00
parent a2b1f761ac
commit ae73b5d256
2 changed files with 23 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
@reference "../../index.scss"; @reference "../../index.scss";
.input_field { .input_field {
@apply rounded-[4xl] border border-gray-300 bg-white p-2 leading-8 placeholder:transition focus:outline-0 focus:placeholder:opacity-25; @apply w-full rounded-[4rem] border border-gray-300 bg-white p-2 leading-8 placeholder:transition focus:outline-0 focus:placeholder:opacity-25;
} }

View File

@@ -1,4 +1,5 @@
import { FunctionComponent } from "preact"; import { cn } from "@/utils/class-merge";
import { FunctionComponent, Ref } from "preact";
import { tv } from "tailwind-variants"; import { tv } from "tailwind-variants";
import classes from "./Input.module.scss"; import classes from "./Input.module.scss";
@@ -19,15 +20,29 @@ interface InputProps {
isPassword?: boolean; isPassword?: boolean;
placeholder?: string; placeholder?: string;
textAlign?: "center" | "left"; textAlign?: "center" | "left";
error?: string;
ref: Ref<HTMLInputElement> | null;
} }
const Input: FunctionComponent<InputProps> = ({ isPassword = false, placeholder = "", textAlign }: InputProps) => { const Input: FunctionComponent<InputProps> = ({
isPassword = false,
placeholder = "",
textAlign,
error = "",
ref = null,
}: InputProps) => {
return ( return (
<input <div class="flex w-full flex-col items-center gap-1">
type={isPassword ? "password" : "text"} <input
class={input({ "text-align": textAlign })} type={isPassword ? "password" : "text"}
placeholder={placeholder} class={input({ "text-align": textAlign })}
/> placeholder={placeholder}
ref={ref}
/>
<p class={cn("invisible h-10 w-[80%] text-center text-sm break-words text-red-500", { visible: error !== "" })}>
{error}
</p>
</div>
); );
}; };