Spaces:
Sleeping
Sleeping
Download Frontend/src/components/ui/Input.jsx from smit9604/ExamCraftAI: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/spaces/smit9604/ExamCraftAI/resolve/main/Frontend/src/components/ui/Input.jsx
- Command line
-
hf download hf://spaces/smit9604/ExamCraftAI/Frontend/src/components/ui/Input.jsx
-
curl -L -o Input.jsx https://huggingface.co/spaces/smit9604/ExamCraftAI/resolve/main/Frontend/src/components/ui/Input.jsx
3.01 kB
| 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"; | |