Animated Input
smoothui-registry/animated-inputFreeComponent
A AnimatedInput component for SmoothUI.
Install it
npx shadcn@latest add https://www.smoothui.dev/r/animated-input.jsonSource
1import { motion, useReducedMotion } from "motion/react";2import { useId, useRef, useState } from "react";34const EASE_IN_OUT_CUBIC_X1 = 0.4;5const EASE_IN_OUT_CUBIC_Y1 = 0;6const EASE_IN_OUT_CUBIC_X2 = 0.2;7const EASE_IN_OUT_CUBIC_Y2 = 1;89const LABEL_TRANSITION = {10 duration: 0.28,11 ease: [12 EASE_IN_OUT_CUBIC_X1,13 EASE_IN_OUT_CUBIC_Y1,14 EASE_IN_OUT_CUBIC_X2,15 EASE_IN_OUT_CUBIC_Y2,16 ] as [number, number, number, number], // cubic-bezier tuple17};1819export interface AnimatedInputProps {20 className?: string;21 defaultValue?: string;22 disabled?: boolean;23 icon?: React.ReactNode;24 inputClassName?: string;25 label: string;26 labelClassName?: string;27 onChange?: (value: string) => void;28 placeholder?: string;29 value?: string;30}3132export default function AnimatedInput({33 value,34 defaultValue = "",35 onChange,36 label,37 placeholder = "",38 disabled = false,39 className = "",40 inputClassName = "",41 labelClassName = "",42 icon,43}: AnimatedInputProps) {44 const [internalValue, setInternalValue] = useState(defaultValue);45 const isControlled = value !== undefined;46 const val = isControlled ? value : internalValue;47 const inputRef = useRef<HTMLInputElement>(null);48 const [isFocused, setIsFocused] = useState(false);49 const isFloating = !!val || isFocused;50 const shouldReduceMotion = useReducedMotion();51 const reactId = useId();52 const inputId = `animated-input-${reactId.replace(/:/g, "")}`;5354 const getLabelAnimation = () => {55 if (shouldReduceMotion) {56 return {};57 }58 if (isFloating) {59 return {60 borderColor: "var(--color-brand)",61 color: "var(--color-brand)",62 scale: 0.85,63 y: -24,64 };65 }66 return { color: "#6b7280", scale: 1, y: 0 };67 };6869 const getLabelStyle = () => {70 if (!shouldReduceMotion) {71 return {};72 }73 if (isFloating) {74 return {75 borderColor: "var(--color-brand)",76 color: "var(--color-brand)",77 transform: "translateY(-24px) scale(0.85)",78 };79 }80 return {81 color: "#6b7280",82 transform: "translateY(0) scale(1)",83 };84 };8586 return (87 <div className={`relative flex items-center ${className}`}>88 {icon ? (89 <span90 aria-hidden="true"91 className="absolute top-1/2 left-3 -translate-y-1/2"92 >93 {icon}94 </span>95 ) : null}96 <input97 aria-label={label}98// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from SmoothUI Registry
All 178 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Avataragent-avatar | SmoothUI Registry | Components | Free | no deps | |
| Ai Approvalai-approval | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Artifactai-artifact | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Branchai-branch | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Citationai-citation | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Context Meterai-context-meter | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Conversationai-conversation | SmoothUI Registry | Components | Free | 2 deps | |
| Ai Coreai-core | SmoothUI Registry | Components | Free | 1 dep |
