{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inline-validation-message",
  "title": "Inline Validation Message",
  "description": "A field-level validation message with error, warning, success and info states: it slides open under the field, crossfades when the text changes, shakes once when an error appears, and lives in a live region so screen readers announce it.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/inline-validation-message/inline-validation-message.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type ValidationState = \"error\" | \"warning\" | \"success\" | \"info\";\nexport type InlineValidationSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface InlineValidationMessageProps {\n  /** Point the field's aria-describedby at this id so the message is read with the field. */\n  id?: string;\n  state?: ValidationState;\n  /** One message, or several (e.g. every rule that still fails). Empty hides the message. */\n  message?: string | string[];\n  /** Hide without clearing the message. */\n  show?: boolean;\n  /** Shake once when an error first appears. */\n  shake?: boolean;\n  showIcon?: boolean;\n  size?: InlineValidationSize;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.6)\", error: \"#FF7A6B\", warning: \"#F2A841\", success: \"#5BD68A\", info: \"rgba(245,244,241,0.6)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.6)\", error: \"#E5484D\", warning: \"#B7791F\", success: \"#16A34A\", info: \"rgba(10,10,10,0.6)\" },\n};\n\nconst SIZES: Record<InlineValidationSize, { font: number; icon: number; gap: number; pad: number }> = {\n  sm: { font: 12, icon: 13, gap: 6, pad: 6 },\n  md: { font: 13, icon: 14, gap: 7, pad: 7 },\n  lg: { font: 14.5, icon: 16, gap: 8, pad: 8 },\n};\n\nfunction StateIcon({ state, size }: { state: ValidationState; size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"shrink-0\">\n      {state === \"warning\" ? <path d=\"M8 2.2 14.3 13.3H1.7L8 2.2Z\" /> : <circle cx=\"8\" cy=\"8\" r=\"6.2\" />}\n      {state === \"error\" && <path d=\"M8 4.8v3.8M8 11.1h.01\" />}\n      {state === \"warning\" && <path d=\"M8 6.6v2.9M8 11.6h.01\" />}\n      {state === \"success\" && <motion.path d=\"M5.3 8.2 7.2 10.1 10.8 6.3\" initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.28, ease: \"easeOut\" }} />}\n      {state === \"info\" && <path d=\"M8 7.3v3.6M8 5.1h.01\" />}\n    </svg>\n  );\n}\n\nexport function InlineValidationMessage({\n  id,\n  state = \"error\",\n  message,\n  show = true,\n  shake = true,\n  showIcon = true,\n  size = \"md\",\n  theme = \"dark\",\n  className,\n}: InlineValidationMessageProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const reduce = Boolean(useReducedMotion());\n  const lines = (Array.isArray(message) ? message : message ? [message] : []).filter(Boolean);\n  const visible = show && lines.length > 0;\n  const color = p[state];\n  const key = `${state}:${lines.join(\"|\")}`;\n\n  // Only shake when an error appears or replaces a non-error; editing the error text stays still.\n  const [shakeKey, setShakeKey] = React.useState(0);\n  const [prev, setPrev] = React.useState({ visible, state });\n  if (prev.visible !== visible || prev.state !== state) {\n    if (visible && state === \"error\" && (!prev.visible || prev.state !== \"error\")) setShakeKey((k) => k + 1);\n    setPrev({ visible, state });\n  }\n\n  return (\n    // Always mounted, so screen readers announce the text that appears inside it.\n    <div id={id} aria-live={state === \"error\" ? \"assertive\" : \"polite\"} aria-atomic=\"true\" className={cn(\"w-full\", className)} style={{ fontFamily: \"Inter, sans-serif\" }}>\n      <AnimatePresence initial={false}>\n        {visible && (\n          <motion.div\n            key=\"box\"\n            initial={reduce ? { opacity: 0 } : { opacity: 0, height: 0 }}\n            animate={{ opacity: 1, height: \"auto\" }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, height: 0 }}\n            transition={{ duration: 0.2, ease: [0.22, 1, 0.36, 1] }}\n            className=\"overflow-hidden\"\n          >\n            <motion.div\n              key={shakeKey}\n              animate={shake && !reduce && shakeKey > 0 ? { x: [0, -5, 5, -3, 3, 0] } : { x: 0 }}\n              transition={{ duration: 0.36, ease: \"easeOut\" }}\n              style={{ paddingTop: s.pad }}\n            >\n              <AnimatePresence mode=\"wait\" initial={false}>\n                <motion.ul\n                  key={key}\n                  initial={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  exit={reduce ? { opacity: 0 } : { opacity: 0, y: 3 }}\n                  transition={{ duration: 0.14 }}\n                  className=\"m-0 flex list-none flex-col p-0\"\n                  style={{ gap: 4 }}\n                >\n                  {lines.map((line) => (\n                    <li key={line} className=\"flex items-start font-medium\" style={{ gap: s.gap, color, fontSize: s.font, lineHeight: 1.4 }}>\n                      {showIcon && (\n                        <span className=\"flex items-center\" style={{ height: s.font * 1.4 }}>\n                          <StateIcon state={state} size={s.icon} />\n                        </span>\n                      )}\n                      <span>\n                        <span className=\"sr-only\">{state === \"error\" ? \"Error: \" : state === \"warning\" ? \"Warning: \" : \"\"}</span>\n                        {line}\n                      </span>\n                    </li>\n                  ))}\n                </motion.ul>\n              </AnimatePresence>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default InlineValidationMessage;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}