{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "morph-text",
  "title": "Morph Text",
  "description": "Text that morphs when it changes: shared characters slide to their new place and digits roll by place value. Used across 0xui for phase labels ('Confirm in wallet…' to 'Pending…') and live numbers such as block height, gas and balances. Strings and numbers animate; any other child renders as-is. Screen readers get the plain text, prefers-reduced-motion is respected, and it renders plain text where the Web Animations API is missing (jsdom tests). Wraps TextMorph from torph.",
  "dependencies": [
    "torph"
  ],
  "files": [
    {
      "path": "registry/default/components/morph-text.tsx",
      "content": "// Docs: https://0xui.io/components/morph-text.md\nimport type { ReactNode } from \"react\";\nimport { TextMorph, type TextMorphProps } from \"torph/react\";\n\nexport type MorphTextProps = Omit<TextMorphProps, \"children\" | \"as\"> & {\n  /**\n   * Text to show. Strings and numbers, alone or mixed like `Approve {symbol}`,\n   * animate from the old value to the new one. Children that hold an element\n   * render as-is.\n   */\n  children?: ReactNode;\n};\n\n// torph animates with the Web Animations API and throws without it. jsdom\n// doesn't implement it, so tests render plain text instead.\nconst noWebAnimations =\n  typeof Element !== \"undefined\" && typeof Element.prototype.getAnimations !== \"function\";\n\n/** The text of plain children, or undefined when they hold an element. */\nfunction textOf(node: ReactNode): string | undefined {\n  if (typeof node === \"string\") return node;\n  if (typeof node === \"number\" || typeof node === \"bigint\") return String(node);\n  if (node == null || typeof node === \"boolean\") return \"\";\n  if (!Array.isArray(node)) return undefined;\n  let text = \"\";\n  for (const child of node) {\n    const part = textOf(child);\n    if (part === undefined) return undefined;\n    text += part;\n  }\n  return text;\n}\n\n/**\n * Text that morphs when it changes: shared characters slide to their new\n * place, and digits roll by place value. Screen readers get the plain text.\n * Honors `prefers-reduced-motion`. Pass `disabled` to turn the animation off.\n */\nexport function MorphText({ children, className, style, ...options }: MorphTextProps) {\n  // A lone number stays a number, so torph formats it with `locale` and `decimals`.\n  const text = typeof children === \"number\" ? children : textOf(children);\n  if (text === undefined) return <>{children}</>;\n\n  if (noWebAnimations) {\n    return (\n      <span className={className} style={style}>\n        {text}\n      </span>\n    );\n  }\n\n  return (\n    <TextMorph className={className} style={style} {...options}>\n      {text}\n    </TextMorph>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/morph-text.md",
  "categories": [
    "utilities"
  ],
  "type": "registry:component"
}