{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-shake",
  "title": "Input shake",
  "description": "Validation wrapper for any input that shakes and slides in an error with an icon when invalid, and draws a check circle when valid.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/inputs/input-shake.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useAnimate, useReducedMotion } from \"motion/react\"\nimport { AlertCircle } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { spring, ease as easing } from \"@/lib/goodui-motion\"\n\nexport type InputShakeStatus = \"idle\" | \"invalid\" | \"valid\"\n\ntype ChildProps = {\n  id?: string\n  className?: string\n  \"aria-invalid\"?: React.AriaAttributes[\"aria-invalid\"]\n  \"aria-describedby\"?: string\n}\n\nexport type InputShakeProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** \"invalid\" shakes the field (on entry) and shows `message`; \"valid\" draws a check and shows `successMessage`. */\n  status?: InputShakeStatus\n  /** Error text shown while invalid. */\n  message?: React.ReactNode\n  /** Optional text shown while valid. */\n  successMessage?: React.ReactNode\n  /** Change this (e.g. a submit counter) to shake again while the field is still invalid. */\n  shakeKey?: number | string\n  /** Visible label rendered as a <label> linked to the child's id. */\n  label?: React.ReactNode\n  /** Helper text shown when there is no message. */\n  hint?: React.ReactNode\n  /** A single input-like element (native input, shadcn Input, select…). */\n  children: React.ReactElement<ChildProps>\n}\n\nfunction DrawnCheck({ reduce }: { reduce: boolean }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" className=\"size-[18px]\" fill=\"none\" aria-hidden=\"true\">\n      <motion.circle\n        cx=\"10\"\n        cy=\"10\"\n        r=\"8.25\"\n        className=\"fill-emerald-500/12 stroke-emerald-500\"\n        strokeWidth=\"1.5\"\n        initial={reduce ? false : { pathLength: 0, opacity: 0 }}\n        animate={{ pathLength: 1, opacity: 1 }}\n        transition={{ duration: 0.35, ease: \"easeOut\" }}\n      />\n      <motion.path\n        d=\"M6.5 10.4 8.9 12.7 13.6 7.6\"\n        className=\"stroke-emerald-600 dark:stroke-emerald-400\"\n        strokeWidth=\"1.8\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={reduce ? false : { pathLength: 0 }}\n        animate={{ pathLength: 1 }}\n        transition={{ duration: 0.25, delay: reduce ? 0 : 0.18, ease: \"easeOut\" }}\n      />\n    </svg>\n  )\n}\n\n/** Validation wrapper: shakes the field and slides in an error when invalid, draws a check when valid. */\nexport function InputShake({ status = \"idle\", message, successMessage, shakeKey, label, hint, children, className, ...props }: InputShakeProps) {\n  const reduce = useReducedMotion() ?? false\n  const [scope, animate] = useAnimate<HTMLDivElement>()\n  const uid = React.useId()\n  const childId = children.props.id ?? `${uid}-field`\n  const msgId = `${uid}-msg`\n  const prev = React.useRef(status)\n  const prevKey = React.useRef(shakeKey)\n\n  React.useEffect(() => {\n    const becameInvalid = status === \"invalid\" && prev.current !== \"invalid\"\n    const reShake = status === \"invalid\" && shakeKey !== prevKey.current\n    prev.current = status\n    prevKey.current = shakeKey\n    if ((becameInvalid || reShake) && !reduce && scope.current) {\n      animate(scope.current, { x: [0, -8, 8, -6, 6, -3, 3, 0] }, { duration: 0.42, ease: \"easeInOut\" })\n    }\n  }, [status, shakeKey, reduce, animate, scope])\n\n  const text = status === \"invalid\" ? message : status === \"valid\" ? successMessage : undefined\n  const describedBy = [children.props[\"aria-describedby\"], (text || hint) && msgId].filter(Boolean).join(\" \") || undefined\n\n  const field = React.cloneElement(children, {\n    id: childId,\n    \"aria-invalid\": status === \"invalid\" ? true : children.props[\"aria-invalid\"],\n    \"aria-describedby\": describedBy,\n    className: cn(\n      children.props.className,\n      \"pe-9\",\n      status === \"invalid\" && \"border-destructive focus-visible:border-destructive focus-visible:ring-destructive/20\",\n      status === \"valid\" && \"border-emerald-500/70 focus-visible:border-emerald-500 focus-visible:ring-emerald-500/20\",\n    ),\n  })\n\n  return (\n    <div className={cn(\"grid gap-1.5\", className)} {...props}>\n      {label && (\n        <label htmlFor={childId} className=\"text-sm font-medium\">\n          {label}\n        </label>\n      )}\n      <div ref={scope} className=\"relative flex items-center\">\n        {field}\n        <span className=\"pointer-events-none absolute end-2.5 grid size-5 place-items-center\">\n          <AnimatePresence mode=\"wait\" initial={false}>\n            {status === \"invalid\" && (\n              <motion.span\n                key=\"invalid\"\n                initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.4, rotate: -45 }}\n                animate={{ opacity: 1, scale: 1, rotate: 0 }}\n                exit={{ opacity: 0, scale: reduce ? 1 : 0.5 }}\n                transition={reduce ? { duration: 0.1 } : spring.play}\n                className=\"text-destructive\"\n              >\n                <AlertCircle className=\"size-[18px]\" aria-hidden=\"true\" />\n              </motion.span>\n            )}\n            {status === \"valid\" && (\n              <motion.span key=\"valid\" initial={{ opacity: 1 }} animate={{ opacity: 1 }} exit={{ opacity: 0, transition: { duration: 0.1 } }}>\n                <DrawnCheck reduce={reduce} />\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </span>\n      </div>\n      <AnimatePresence initial={false} mode=\"wait\">\n        {text ? (\n          <motion.p\n            key={`${status}-msg`}\n            id={msgId}\n            role={status === \"invalid\" ? \"alert\" : \"status\"}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, height: 0, y: -4 }}\n            animate={{ opacity: 1, height: \"auto\", y: 0 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, height: 0, y: -4 }}\n            transition={{ duration: reduce ? 0.1 : 0.2, ease: easing.out }}\n            className={cn(\n              \"overflow-hidden text-xs font-medium\",\n              status === \"invalid\" ? \"text-destructive\" : \"text-emerald-700 dark:text-emerald-400\",\n            )}\n          >\n            {text}\n          </motion.p>\n        ) : hint ? (\n          <motion.p key=\"hint\" id={msgId} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0, transition: { duration: 0.08 } }} className=\"text-xs text-muted-foreground\">\n            {hint}\n          </motion.p>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/input-shake.tsx"
    }
  ],
  "categories": [
    "components",
    "inputs"
  ],
  "type": "registry:component"
}