{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rotating-text",
  "type": "registry:ui",
  "title": "Rotating Text",
  "description": "One word in a headline that changes every few seconds (\"Build for [teams / founders / students]\"). It is a familiar pattern done carefully: the line never jumps, a screen reader hears the sentence once, and the reader can stop it.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/rotating-text.tsx",
      "target": "components/ui/effects/rotating-text.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/rotating-text v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/rotating-text\n// What changed since: https://ds.interlace.tools/c/rotating-text#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — RotatingText\n *\n * One word in a headline that changes every few seconds (\"Build for\n * [teams / founders / students]\"). It is a familiar pattern done carefully:\n * the line never jumps, a screen reader hears the sentence once, and the\n * reader can stop it.\n *\n * ## No layout shift\n *\n * Every word is rendered into the same grid cell, and only the current one\n * is visible. The cell is therefore as wide as the widest word from the\n * first paint, so the sentence around it never reflows (CLS 0), and the\n * server HTML already has the right width.\n *\n * ## Accessibility\n *\n * The rotating words are `aria-hidden`. Assistive tech reads one stable\n * label instead (by default the words joined, \"teams, founders or\n * students\"), so nothing is announced every few seconds. Rotation pauses\n * while the pointer is over the words or focus is inside them, and while\n * the tab is hidden. Under `prefers-reduced-motion: reduce` the first word\n * stays and nothing rotates.\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `span` props, minus children                          |\n * | R6   | data-slot per part      | rotating-text / -word                                 |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R23  | CLS=0                   | all words share one grid cell                         |\n * | R25  | Client component        | timers and `Element.animate`                          |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nexport interface RotatingTextProps\n  extends Omit<React.ComponentPropsWithoutRef<'span'>, 'children'> {\n  /** The words to cycle through, in order. */\n  words: readonly string[];\n  /** Milliseconds each word stays, at least 1000 so every word can be read. @default 2800 */\n  interval?: number;\n  /** What assistive tech reads instead of the moving words. @default the words, joined with \"or\" */\n  label?: string;\n  /** Pause while hovered or focused. @default true */\n  pauseOnHover?: boolean;\n  /** Called with the index of the word now showing. */\n  onIndexChange?: (index: number) => void;\n}\n\nfunction joinWords(words: readonly string[]): string {\n  if (words.length <= 1) return words[0] ?? '';\n  return `${words.slice(0, -1).join(', ')} or ${words[words.length - 1]}`;\n}\n\nexport function RotatingText({\n  words,\n  interval = 2800,\n  label,\n  pauseOnHover = true,\n  onIndexChange,\n  className,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...props\n}: RotatingTextProps) {\n  const [index, setIndex] = React.useState(0);\n  const [held, setHeld] = React.useState(false);\n  const reduced = useReducedMotion();\n  const wordRefs = React.useRef<Array<HTMLSpanElement | null>>([]);\n  const changeRef = React.useRef(onIndexChange);\n  changeRef.current = onIndexChange;\n\n  const rotating = words.length > 1 && !reduced && !(pauseOnHover && held);\n\n  React.useEffect(() => {\n    if (!rotating) return;\n    const id = window.setInterval(() => {\n      if (document.hidden) return;\n      setIndex((i) => (i + 1) % words.length);\n    }, Math.max(1000, interval));\n    return () => window.clearInterval(id);\n  }, [rotating, interval, words.length]);\n\n  // Entrance for the word that just became current. Skipped on mount, so\n  // the server-rendered first word does not animate in.\n  const mounted = React.useRef(false);\n  React.useEffect(() => {\n    if (!mounted.current) {\n      mounted.current = true;\n      return;\n    }\n    changeRef.current?.(index);\n    const node = wordRefs.current[index];\n    if (reduced || !node || typeof node.animate !== 'function') return;\n    node.animate(\n      [\n        { opacity: 0, transform: 'translateY(0.35em)', filter: 'blur(3px)' },\n        { opacity: 1, transform: 'none', filter: 'none' },\n      ],\n      { duration: 320, easing: 'cubic-bezier(0.2, 0.8, 0.2, 1)' },\n    );\n  }, [index, reduced]);\n\n  const current = index % Math.max(words.length, 1);\n\n  return (\n    <span\n      data-slot=\"rotating-text\"\n      className={cn('inline-grid align-baseline', className)}\n      onPointerEnter={(e) => {\n        setHeld(true);\n        onPointerEnter?.(e);\n      }}\n      onPointerLeave={(e) => {\n        setHeld(false);\n        onPointerLeave?.(e);\n      }}\n      onFocus={(e) => {\n        setHeld(true);\n        onFocus?.(e);\n      }}\n      onBlur={(e) => {\n        setHeld(false);\n        onBlur?.(e);\n      }}\n      {...props}\n    >\n      <span className=\"sr-only\">{label ?? joinWords(words)}</span>\n      {words.map((word, i) => (\n        <span\n          key={`${i}-${word}`}\n          ref={(node) => {\n            wordRefs.current[i] = node;\n          }}\n          aria-hidden\n          data-slot=\"rotating-text-word\"\n          data-current={i === current ? '' : undefined}\n          className={cn('col-start-1 row-start-1', i === current ? 'visible' : 'invisible')}\n        >\n          {word}\n        </span>\n      ))}\n    </span>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/rotating-text\n\nInstalled to `components/ui/effects/rotating-text.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/rotating-text';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/rotating-text\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
