{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cycling-placeholder","type":"registry:ui","title":"Cycling placeholder","description":"A text field whose placeholder rolls through examples of what to type, so an empty search box teaches what it can find. The roll pauses while the field has focus and the examples disappear once anything is typed.","dependencies":["clsx","tailwind-merge"],"registryDependencies":["https://caliperui.site/r/styles.json"],"files":[{"path":"ui/cycling-placeholder.tsx","type":"registry:ui","target":"components/ui/cycling-placeholder.tsx","content":"\"use client\";\nimport { useEffect, useId, useState, type ComponentProps } from \"react\";\nimport { cn } from \"./lib/cn\";\nimport \"./cycling-placeholder.css\";\n\nexport type CyclingPlaceholderProps = Omit<ComponentProps<\"input\">, \"placeholder\"> & {\n  /** Examples shown in turn while the field is empty, such as \"overdue invoices\". */\n  examples: string[];\n  /** Words before each example, such as \"Search for\". */\n  prefix?: string;\n  /** Milliseconds each example stays. */\n  interval?: number;\n};\n\n/**\n * A text field whose placeholder rolls through examples of what to type, so an empty search box teaches what it can\n * find. The roll pauses while the field has focus and the examples disappear once anything is typed. The field is\n * described by the first example, so assistive technology hears one stable hint. Under reduced motion the examples\n * cross-fade instead of rolling.\n */\nexport function CyclingPlaceholder({ examples, prefix = \"\", interval = 2600, className, value, defaultValue, onChange, onFocus, onBlur, ...props }: CyclingPlaceholderProps) {\n  const [index, setIndex] = useState(0);\n  const [focused, setFocused] = useState(false);\n  const [own, setOwn] = useState(String(defaultValue ?? \"\"));\n  const text = value === undefined ? own : String(value);\n  const hintId = useId();\n\n  useEffect(() => {\n    if (focused || text || examples.length < 2) return;\n    const timer = window.setInterval(() => setIndex((current) => (current + 1) % examples.length), interval);\n    return () => window.clearInterval(timer);\n  }, [focused, text, examples.length, interval]);\n\n  return (\n    <span data-slot=\"cycling-placeholder\" className={cn(\"relative block\", className)}>\n      <input\n        data-slot=\"cp-input\"\n        aria-describedby={examples[0] ? hintId : undefined}\n        value={text}\n        onChange={(event) => {\n          if (value === undefined) setOwn(event.target.value);\n          onChange?.(event);\n        }}\n        onFocus={(event) => {\n          setFocused(true);\n          onFocus?.(event);\n        }}\n        onBlur={(event) => {\n          setFocused(false);\n          onBlur?.(event);\n        }}\n        {...props}\n      />\n      <span id={hintId} className=\"sr-only\">\n        For example, {examples[0]}\n      </span>\n      {!text && (\n        <span data-slot=\"cp-hint\" aria-hidden=\"true\">\n          {prefix && <span>{prefix} </span>}\n          <span data-slot=\"cp-window\">\n            <span key={index} data-slot=\"cp-example\">\n              {examples[index]}\n            </span>\n          </span>\n        </span>\n      )}\n    </span>\n  );\n}\n"},{"path":"ui/lib/cn.ts","type":"registry:ui","target":"components/ui/lib/cn.ts","content":"import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n  extend: { theme: { radius: [\"control\", \"surface\", \"overlay\"], shadow: [\"overlay\"] } },\n});\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"},{"path":"ui/cycling-placeholder.css","type":"registry:file","target":"components/ui/cycling-placeholder.css","content":"/* cycling-placeholder.tsx's styles; it imports this file. Edit freely. */\n@layer theme, base, components, utilities;\n\n@layer components {\n  /* Cycling placeholder: the example rolls up through a one-line window over the empty field. */\n  [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-input\"] { width: 100%; height: var(--control-height); padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--background); color: var(--foreground); font: inherit; font-size: 14px; outline: none; transition: border-color var(--duration-fast) var(--ease-out); }\n  [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-input\"]:focus-visible { border-color: var(--ring); box-shadow: 0 0 0 2px color-mix(in oklab, var(--ring) 30%, transparent); }\n  [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-hint\"] { position: absolute; top: 0; left: 13px; right: 12px; display: flex; align-items: center; height: var(--control-height); overflow: hidden; color: var(--muted-foreground); font-size: 14px; white-space: pre; pointer-events: none; }\n  [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-window\"] { display: inline-block; min-width: 0; overflow: hidden; height: 1.4em; line-height: 1.4em; text-overflow: ellipsis; }\n  [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-example\"] { display: block; overflow: hidden; text-overflow: ellipsis; animation: cp-roll 0.42s var(--ease-out); }\n  @media (prefers-reduced-motion: reduce) {\n    [data-slot=\"cycling-placeholder\"] [data-slot=\"cp-example\"] { animation: cp-fade 0.3s linear; }\n  }\n  @keyframes cp-roll { from { opacity: 0; translate: 0 70%; } }\n  @media (prefers-reduced-motion: reduce) {\n    @keyframes cp-fade { from { opacity: 0; } }\n  }\n}\n"}],"categories":["motion"],"meta":{"tier":"free","license":"MIT","family":"text-motion","docs":"/docs/components/cycling-placeholder"}}