Files
honey-fe/src/components/form/TextInput/TextInput.tsx

32 lines
831 B
TypeScript
Raw Normal View History

2026-03-12 00:42:41 +02:00
import { motion, type HTMLMotionProps } from "motion/react";
import clsx, { type ClassValue } from "clsx";
2026-03-22 17:48:35 +02:00
import type { FocusEvent } from "react";
2026-03-12 00:42:41 +02:00
import classes from "./TextInput.module.css";
type Props = Omit<HTMLMotionProps<"input">, "className"> & {
className?: ClassValue;
error?: boolean;
};
2026-03-22 17:48:35 +02:00
export default function TextInput({ className, error, onFocus, ...props }: Props) {
const handleFocus = (e: FocusEvent<HTMLInputElement>) => {
onFocus?.(e);
const target = e.target;
setTimeout(() => {
if (target.isConnected) {
target.scrollIntoView({ block: "center", behavior: "smooth" });
}
}, 100);
};
2026-03-12 00:42:41 +02:00
return (
<motion.input
{...props}
type="text"
2026-03-22 17:48:35 +02:00
onFocus={handleFocus}
2026-03-12 00:42:41 +02:00
className={clsx(classes.input, error && classes.error, className)}
/>
);
}