{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"status-icon","type":"registry:component","title":"Status Icon","description":"One status icon that morphs instead of swapping: a breathing arc spins while syncing, then sweeps on to close the ring, which fills green, amber or red as a white check, exclamation or cross draws in.","author":"Saurabh <saurabh10102@gmail.com>","dependencies":["clsx","motion","tailwind-merge"],"registryDependencies":[],"docs":"Status Icon: usage, props and types at https://beui.dev/micro-interactions/status-icon.md","files":[{"path":"components/motion/status-icon.tsx","type":"registry:component","target":"@components/motion/status-icon.tsx","content":"\"use client\";\n// beui.dev/micro-interactions/status-icon\n\nimport {\n  type AnimationPlaybackControls,\n  animate,\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useReducedMotion,\n} from \"motion/react\";\nimport { type ComponentProps, useEffect, useRef } from \"react\";\nimport { EASE_IN_OUT, EASE_OUT, SPRING_SWAP } from \"@/lib/ease\";\nimport { useMessages } from \"@/lib/i18n\";\nimport { cn } from \"@/lib/utils\";\n\nexport type StatusIconStatus = \"idle\" | \"syncing\" | \"success\" | \"warning\" | \"error\";\n\n/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */\nexport const statusIconMessages = {\n  idle: \"Idle\",\n  syncing: \"Syncing\",\n  success: \"Done\",\n  warning: \"Needs attention\",\n  error: \"Failed\",\n};\n\nexport type StatusIconMessages = typeof statusIconMessages;\n\nexport interface StatusIconProps extends Omit<ComponentProps<\"span\">, \"children\"> {\n  /** Which state to show. The icon morphs from one state to the next. Default: \"idle\" */\n  status?: StatusIconStatus;\n  /** Width and height in px. Default: 20 */\n  size?: number;\n  /** Hides the icon from assistive technology, for when nearby text already says the status. Default: false */\n  decorative?: boolean;\n  /** Override any built-in string, e.g. for translation. */\n  labels?: Partial<StatusIconMessages>;\n}\n\nconst COLOR: Record<StatusIconStatus, string> = {\n  idle: \"text-muted-foreground/45\",\n  syncing: \"text-foreground\",\n  success: \"text-emerald-500\",\n  warning: \"text-amber-500\",\n  error: \"text-rose-500\",\n};\n\n// The arc turns like a wheel: syncing spins it up to a steady speed, and when\n// the work settles it coasts on with the speed it had and eases to a stop at\n// the top. Its length breathes while it turns, like a system spinner.\nconst SPEED = 420; // degrees per second at full spin\nconst SPIN_UP = { duration: 0.4, ease: EASE_OUT } as const;\n// Coasting: an ease-out quad starts at twice its average speed, so a coast of\n// COAST_S seconds over (speed × COAST_S / 2) degrees leaves at exactly the\n// speed the wheel had and slows to rest. A full ring hides its angle, so the\n// stop can be anywhere. The curve is easeOutQuad, local because its starting\n// slope (2) is what makes the hand-off seamless.\nconst COAST_S = 0.42;\nconst COAST_EASE = [0.5, 1, 0.89, 1] as const;\nconst BREATH = {\n  duration: 1.4,\n  ease: EASE_IN_OUT,\n  repeat: Number.POSITIVE_INFINITY,\n  repeatType: \"reverse\",\n} as const;\nconst ARC_SHORT = 0.16;\nconst ARC_LONG = 0.62;\n// Settling is one motion, not three steps: the ring closes as the arc slows,\n// the fill swells in while it finishes, and the mark draws as the fill lands.\nconst CLOSE = { type: \"spring\", duration: 0.5, bounce: 0 } as const;\nconst FILL = { ...SPRING_SWAP, delay: 0.1 } as const;\nconst MARK_IN = { duration: 0.24, ease: EASE_OUT, delay: 0.18 } as const;\nconst OPEN = { duration: 0.3, ease: EASE_OUT } as const;\nconst OUT = { duration: 0.14, ease: EASE_OUT } as const;\n\n/**\n * One status icon that morphs instead of swapping glyphs. Syncing turns an arc\n * whose length breathes. On success, warning or error the arc carries on from\n * wherever it is and sweeps round to close the ring, the ring fills in that\n * state's colour with a small spring, and a white check, exclamation or cross\n * draws in. Going back to syncing empties it and the arc opens again. Idle is\n * a faint ring.\n */\nexport function StatusIcon({\n  status = \"idle\",\n  size = 20,\n  decorative = false,\n  labels,\n  className,\n  ...props\n}: StatusIconProps) {\n  const t = useMessages(\"statusIcon\", statusIconMessages, labels);\n  const reduce = useReducedMotion() ?? false;\n  const syncing = status === \"syncing\";\n  const settled = status === \"success\" || status === \"warning\" || status === \"error\";\n\n  // The arc's angle, spin speed and length are driven by hand, so every change\n  // starts from where the arc really is and how fast it is really turning.\n  const rotate = useMotionValue(0);\n  const speed = useMotionValue(0);\n  const spinning = useRef(false);\n  const length = useMotionValue(settled ? 1 : ARC_SHORT);\n  const arcOpacity = useMotionValue(syncing || settled ? 1 : 0);\n  const running = useRef<AnimationPlaybackControls[]>([]);\n\n  // While spinning, the angle advances by the current speed every frame, so\n  // speeding up and slowing down are just changes to `speed`.\n  useAnimationFrame((_, delta) => {\n    if (!spinning.current) return;\n    rotate.set(rotate.get() + (speed.get() * Math.min(delta, 50)) / 1000);\n  });\n\n  // Bumped on every state change, so a step queued by an older state is dropped.\n  const sessionRef = useRef(0);\n\n  useEffect(() => {\n    const session = ++sessionRef.current;\n    for (const controls of running.current) controls.stop();\n    running.current = [];\n    const run = (controls: AnimationPlaybackControls) => running.current.push(controls);\n\n    // Hand the wheel's momentum to a coast that eases it to rest.\n    const coast = () => {\n      const velocity = spinning.current ? speed.get() : 0;\n      spinning.current = false;\n      speed.set(0);\n      if (velocity <= 0) return;\n      run(\n        animate(rotate, rotate.get() + (velocity * COAST_S) / 2, {\n          duration: COAST_S,\n          ease: COAST_EASE,\n        }),\n      );\n    };\n\n    if (syncing) {\n      run(animate(arcOpacity, 1, OUT));\n      if (reduce) {\n        length.set(0.3);\n        return;\n      }\n      // Spin up from whatever speed it has, never from a standing jolt.\n      speed.set(spinning.current ? speed.get() : Math.max(0, rotate.getVelocity()));\n      spinning.current = true;\n      run(animate(speed, SPEED, SPIN_UP));\n      // Coming from a closed ring, the arc first opens to its short length,\n      // then starts breathing.\n      run(\n        animate(length, ARC_SHORT, {\n          ...OPEN,\n          onComplete: () => {\n            if (session !== sessionRef.current) return;\n            run(animate(length, [ARC_SHORT, ARC_LONG], BREATH));\n          },\n        }),\n      );\n    } else if (settled) {\n      run(animate(arcOpacity, 1, OUT));\n      if (reduce) {\n        length.set(1);\n        return;\n      }\n      coast();\n      run(animate(length, 1, { ...CLOSE, velocity: length.getVelocity() }));\n    } else {\n      run(animate(arcOpacity, 0, OUT));\n      if (!reduce) coast();\n    }\n    return () => {\n      for (const controls of running.current) controls.stop();\n    };\n  }, [syncing, settled, reduce, rotate, speed, length, arcOpacity]);\n\n  useEffect(\n    () => () => {\n      spinning.current = false;\n    },\n    [],\n  );\n\n  // A mark draws while its state is shown and fades away when it leaves.\n  const mark = (shown: boolean) => ({\n    initial: false as const,\n    animate: reduce\n      ? { opacity: shown ? 1 : 0 }\n      : { pathLength: shown ? 1 : 0, opacity: shown ? 1 : 0 },\n    transition: reduce ? { duration: 0.12 } : shown ? MARK_IN : OUT,\n  });\n\n  const frame = {\n    \"data-status\": status,\n    className: cn(\n      \"inline-grid shrink-0 place-items-center transition-colors duration-200\",\n      COLOR[status],\n      className,\n    ),\n    style: { width: size, height: size },\n    ...props,\n  };\n\n  const icon = (\n    <>\n      {/* The arc gets an svg of its own and turns as a whole. An svg element's\n          box is the full 24×24 icon, so it spins round the true centre; a\n          group inside one would turn round the centre of the arc's own\n          bounding box, which moves as the arc changes length. */}\n      <motion.svg\n        aria-hidden=\"true\"\n        viewBox=\"0 0 24 24\"\n        fill=\"none\"\n        style={{ rotate }}\n        className=\"col-start-1 row-start-1 size-full overflow-visible\"\n      >\n        <motion.circle\n          cx=\"12\"\n          cy=\"12\"\n          r=\"9.5\"\n          stroke=\"currentColor\"\n          strokeWidth=\"2\"\n          strokeLinecap=\"round\"\n          transform=\"rotate(-90 12 12)\"\n          style={{ pathLength: length, opacity: arcOpacity }}\n        />\n      </motion.svg>\n      <svg\n        aria-hidden=\"true\"\n        viewBox=\"0 0 24 24\"\n        fill=\"none\"\n        className=\"col-start-1 row-start-1 size-full overflow-visible\"\n      >\n      {/* Idle: a faint ring. */}\n      <motion.circle\n        cx=\"12\"\n        cy=\"12\"\n        r=\"9.5\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2\"\n        initial={false}\n        animate={{ opacity: status === \"idle\" ? 0.9 : 0 }}\n        transition={OUT}\n      />\n      {/* The fill: pops in once the ring has closed, from the icon's centre\n          (a full circle's own box shares that centre). */}\n      <motion.circle\n        cx=\"12\"\n        cy=\"12\"\n        r=\"10.5\"\n        fill=\"currentColor\"\n        initial={false}\n        animate={reduce ? { opacity: settled ? 1 : 0 } : { opacity: settled ? 1 : 0, scale: settled ? 1 : 0.6 }}\n        transition={settled ? (reduce ? { duration: 0.15 } : FILL) : OUT}\n      />\n      {/* Marks, drawn in white on the fill. */}\n      <motion.path\n        d=\"M7.8 12.3l2.8 2.8 5.6-5.8\"\n        stroke=\"white\"\n        strokeWidth=\"2.2\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        {...mark(status === \"success\")}\n      />\n      <motion.path\n        d=\"M12 7.4v5.2\"\n        stroke=\"white\"\n        strokeWidth=\"2.2\"\n        strokeLinecap=\"round\"\n        {...mark(status === \"warning\")}\n      />\n      <motion.path\n        d=\"M12 16.3v.01\"\n        stroke=\"white\"\n        strokeWidth=\"2.6\"\n        strokeLinecap=\"round\"\n        {...mark(status === \"warning\")}\n      />\n      <motion.path\n        d=\"M9.2 9.2l5.6 5.6M14.8 9.2l-5.6 5.6\"\n        stroke=\"white\"\n        strokeWidth=\"2.2\"\n        strokeLinecap=\"round\"\n        {...mark(status === \"error\")}\n      />\n      </svg>\n    </>\n  );\n\n  return decorative ? (\n    <span aria-hidden=\"true\" {...frame}>\n      {icon}\n    </span>\n  ) : (\n    <span role=\"img\" aria-label={t(status)} {...frame}>\n      {icon}\n    </span>\n  );\n}\n"},{"path":"lib/ease.ts","type":"registry:lib","target":"@lib/ease.ts","content":"// Shared motion tokens. Easing curves mirror the CSS custom properties in\n// globals.css; springs are the canonical physics used across components.\n// Strong custom variants — defaults like `ease-in`/`ease-out` feel weak.\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. */\nexport const EASE_IN = [0.55, 0, 1, 0.45] as const;\nexport const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;\nexport const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;\n\n/** CSS string form of EASE_OUT for inline style transitions. */\nexport const EASE_OUT_CSS = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\n/** Press feedback on buttons and other tappable surfaces. */\nexport const SPRING_PRESS = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 30,\n  mass: 0.6,\n} as const;\n\n/** Content swaps — label/icon slots trading places inside a control. */\nexport const SPRING_SWAP = {\n  type: \"spring\",\n  stiffness: 460,\n  damping: 30,\n  mass: 0.55,\n} as const;\n\n/** Overlay panel entrances — modals and sheets summoned by pointer. */\nexport const SPRING_PANEL = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 40,\n  mass: 0.5,\n} as const;\n\n/** Shared-layout glides — pills, indicators and panels morphing between positions. */\nexport const SPRING_LAYOUT = {\n  type: \"spring\",\n  stiffness: 360,\n  damping: 32,\n  mass: 0.6,\n} as const;\n\n/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */\nexport const SPRING_MOUSE = {\n  stiffness: 200,\n  damping: 15,\n  mass: 0.3,\n} as const;\n\n/** Dragged handles and fills (sliders) — critically damped `useSpring` config,\n * so the value follows the pointer butterily and never rebounds off an end. */\nexport const SPRING_GLIDE = {\n  stiffness: 700,\n  damping: 50,\n  mass: 0.5,\n} as const;\n\n/** Shared-surface morphs: a trigger growing into its panel and back on one\n * weighted spring, so opening and closing travel the same path. */\nexport const SPRING_MORPH = {\n  type: \"spring\",\n  duration: 0.5,\n  bounce: 0.22,\n} as const;\n"},{"path":"lib/i18n.tsx","type":"registry:lib","target":"@lib/i18n.tsx","content":"\"use client\";\n\nimport {\n  createContext,\n  type ReactNode,\n  useCallback,\n  useContext,\n  useMemo,\n} from \"react\";\n\n/**\n * A component's messages. Plain strings with `{name}` placeholders, so a\n * dictionary stays JSON-serializable and can be passed from a server layout.\n * There are no plural forms: write messages that read correctly for any count.\n */\nexport type Messages = Record<string, string>;\n\n/** A language file: component namespace → any subset of that component's messages. */\nexport type LocaleMessages = Record<string, Partial<Messages>>;\n\ntype LocaleContextValue = {\n  locale?: string;\n  messages: LocaleMessages;\n};\n\nconst NO_MESSAGES: LocaleMessages = {};\n\nconst LocaleContext = createContext<LocaleContextValue>({ messages: NO_MESSAGES });\n\n/** Without a locale, digits stay plain so server and client render the same text. */\nexport function formatNumber(value: number, locale?: string) {\n  return locale ? new Intl.NumberFormat(locale).format(value) : String(value);\n}\n\nexport interface LocaleProviderProps {\n  /** BCP 47 tag, e.g. `de`, `pt-BR`. Drives `Intl` number formatting. */\n  locale: string;\n  /**\n   * Component namespace → translated strings. Missing keys fall back to English.\n   * Pass a stable object (a module constant, imported JSON or a memoized value):\n   * a new object each render gives every translated component a new `t`.\n   */\n  messages?: LocaleMessages;\n  children: ReactNode;\n}\n\nexport function LocaleProvider({ locale, messages = NO_MESSAGES, children }: LocaleProviderProps) {\n  const value = useMemo(() => ({ locale, messages }), [locale, messages]);\n  return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;\n}\n\nexport function useLocale(): { locale?: string } {\n  return { locale: useContext(LocaleContext).locale };\n}\n\n/**\n * Resolves a component's strings: `labels` prop, then the provider's\n * messages for `namespace`, then the component's English `defaults`.\n * Numbers passed as values are formatted for the provider's locale.\n */\nexport function useMessages<T extends Messages>(\n  namespace: string,\n  defaults: T,\n  labels?: Partial<T>,\n) {\n  const { locale, messages } = useContext(LocaleContext);\n  const provided = messages[namespace];\n  // Inline `labels={{ … }}` is a new object every render. Keying it by content\n  // keeps `t` one identity until a label changes, so effects and memos that\n  // depend on `t` don't re-run per render, and render-time reads never lag.\n  const labelsKey = labels ? JSON.stringify(labels) : \"\";\n  const stableLabels = useMemo(\n    () => (labelsKey ? (JSON.parse(labelsKey) as Partial<T>) : undefined),\n    [labelsKey],\n  );\n\n  return useCallback(\n    (key: keyof T & string, values?: Record<string, string | number>) => {\n      const template = stableLabels?.[key] ?? provided?.[key] ?? defaults[key];\n      if (!values) return template;\n      return template.replace(/\\{(\\w+)\\}/g, (match, name: string) => {\n        const value = values[name];\n        if (value === undefined) return match;\n        return typeof value === \"number\" ? formatNumber(value, locale) : value;\n      });\n    },\n    [defaults, stableLabels, locale, provided],\n  );\n}\n"},{"path":"lib/utils.ts","type":"registry:lib","target":"@lib/utils.ts","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"}]}