Spaces:
Sleeping
Sleeping
File size: 3,006 Bytes
5463318 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import React, { useState } from "react";
import { cn } from "../../utils/cn";
import { CopyIcon, CheckIcon, AlertCircle } from "lucide-react";
export const Input = React.forwardRef(
({ className, type = "text", error, label, ...props }, ref) => {
const [focused, setFocused] = useState(false);
return (
<div className={cn("relative mb-6", className)}>
{/* Input Wrapper */}
<div
className={cn(
"relative w-full rounded-lg border bg-input/20 px-3 py-2 text-sm transition-all duration-300 ring-offset-background",
focused ? "border-primary shadow-[0_0_10px_rgba(var(--primary),0.3)]" : "border-border",
error ? "border-destructive shadow-[0_0_10px_rgba(var(--destructive),0.3)]" : "",
props.disabled ? "opacity-50 cursor-not-allowed" : ""
)}
>
{/* Floating Label */}
{label && (
<label
className={cn(
"absolute left-3 transition-all duration-300 pointer-events-none bg-background/0 px-1",
focused || (props.value && props.value !== '') || props.defaultValue
? "-top-2.5 text-xs text-primary bg-background dark:bg-card z-10 font-semibold"
: "top-2.5 text-sm text-muted-foreground",
error && (focused || props.value) ? "text-destructive" : ""
)}
>
{label}
</label>
)}
<input
type={type}
ref={ref}
onFocus={(e) => {
setFocused(true);
props.onFocus?.(e);
}}
onBlur={(e) => {
setFocused(false);
props.onBlur?.(e);
}}
className={cn(
"flex w-full bg-transparent p-1 shadow-sm placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed",
"text-foreground placeholder:text-muted-foreground",
)}
{...props}
/>
</div>
{/* Error Validation Feedback */}
{error && (
<div className="absolute -bottom-5 left-1 text-xs text-destructive flex flex-row items-center gap-1 mt-1 font-medium transition-all duration-300">
<AlertCircle size={12} /> {error}
</div>
)}
</div>
);
}
);
Input.displayName = "Input";
|