{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-ripple-button",
  "type": "registry:component",
  "title": "Ripple button",
  "description": "An action whose press spreads a wash from the pointer",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-components.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/ripple-button.tsx",
      "target": "@ui/gpuixui/fx/ripple-button.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport type { MotionLevel } from \"../motion/timing.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n  Button,\n  actionOnColor,\n  type ButtonProps,\n  measuredBox,\n  type MeasuredBox,\n  transitionWindowMs,\n  useMotionPreference,\n  useSurfaceTiming,\n  alpha,\n  useTheme,\n} from \"../components/authoring.js\";\nimport {\n  rippleFrames,\n  rippleOpacity,\n  ripplePoint,\n  rippleReach,\n  type RipplePoint,\n} from \"./ripple-button/logic.js\";\n\ninterface Ripple {\n  readonly id: number;\n  readonly point: RipplePoint;\n  readonly reach: number;\n}\n\nexport interface RippleButtonProps extends ButtonProps {\n  readonly level?: MotionLevel;\n\n  readonly rippleColor?: string;\n}\n\nconst RippleCircle = ({\n  id,\n  point,\n  reach,\n  level,\n  wash,\n  onDone,\n}: Ripple & {\n  readonly level: MotionLevel;\n  readonly wash: string;\n  readonly onDone: (id: number) => void;\n}) => {\n  const timing = useSurfaceTiming(level).enter;\n  const windowMs = transitionWindowMs(timing);\n\n  useEffect(() => {\n    if (windowMs === 0) {\n      onDone(id);\n      return;\n    }\n    const handle = setTimeout(() => onDone(id), windowMs);\n    return () => clearTimeout(handle);\n  }, [id, onDone, windowMs]);\n\n  return (\n    <div\n      testId=\"ripple\"\n      motion={{\n        ...rippleFrames(point, reach),\n        transition: timing,\n      }}\n      style={{\n        position: \"absolute\",\n        backgroundColor: wash,\n        pointerEvents: \"none\",\n      }}\n    />\n  );\n};\n\nexport const RippleButton = ({\n  variant = \"secondary\",\n  size = \"md\",\n  disabled = false,\n  level = \"notice\",\n  rippleColor,\n  onClick,\n  onLayout,\n  style,\n  children,\n  ...rest\n}: RippleButtonProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const box = useRef<Option.Option<MeasuredBox>>(Option.none());\n  const nextId = useRef(0);\n  const [ripples, setRipples] = useState<ReadonlyArray<Ripple>>([]);\n  const wash =\n    rippleColor ?? alpha(actionOnColor(theme, variant), rippleOpacity);\n\n  const removeRipple = useCallback((id: number) => {\n    setRipples((current) => Arr.filter(current, (ripple) => ripple.id !== id));\n  }, []);\n\n  const measure = (event: EventPayload) => {\n    box.current = measuredBox(event);\n    onLayout?.(event);\n  };\n\n  const press = (event: EventPayload) => {\n    onClick?.(event);\n    if (preference === \"reduced\") return;\n    const measured = box.current;\n    if (Option.isNone(measured)) return;\n    const point = ripplePoint(event, measured.value);\n    const id = nextId.current;\n    nextId.current = id + 1;\n    setRipples((current) =>\n      Arr.append(current, {\n        id,\n        point,\n        reach: rippleReach(point, measured.value),\n      }),\n    );\n  };\n\n  return (\n    <Button\n      {...rest}\n      variant={variant}\n      size={size}\n      disabled={disabled}\n      onClick={press}\n      onLayout={measure}\n      style={mergeStyles({ position: \"relative\", overflow: \"hidden\" }, style)}\n    >\n      {children}\n      {Arr.map(ripples, (ripple) => (\n        <RippleCircle\n          key={ripple.id}\n          {...ripple}\n          level={level}\n          wash={wash}\n          onDone={removeRipple}\n        />\n      ))}\n    </Button>\n  );\n};\n\nexport const rippleButtonMeta = {\n  name: \"Ripple button\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"the circle grows by inset geometry, not a transform: the runtime scales nothing (upstream issue #102)\",\n    \"a reduced-motion reader gets no ripple at all; the button's pressed fill is the remaining feedback\",\n    \"each press mounts a painted layer for the length of the tween, so a rapid burst is a burst of layers\",\n  ],\n  docs: \"docs/ripple-button.mdx\",\n  example: \"examples/ripple-button.example.tsx\",\n  testFile: \"src/behaviour/ripple-button.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/ripple-button/logic.ts",
      "target": "@ui/gpuixui/fx/ripple-button/logic.ts",
      "type": "registry:lib",
      "content": "import type { EventPayload, MotionStyle } from \"@gpuix/react\";\nimport * as Option from \"effect/Option\";\nimport { measuredPoint, type MeasuredBox } from \"../../components/authoring.js\";\n\nexport interface RipplePoint {\n  readonly x: number;\n  readonly y: number;\n}\n\nexport interface RippleFrames {\n  readonly initial: MotionStyle;\n  readonly animate: MotionStyle;\n}\n\nexport const rippleOpacity = 0.28;\n\nexport const ripplePoint = (\n  event: EventPayload,\n  box: MeasuredBox,\n): RipplePoint =>\n  measuredPoint(event).pipe(\n    Option.map((point) => ({ x: point.x - box.x, y: point.y - box.y })),\n    Option.getOrElse(() => ({ x: box.width / 2, y: box.height / 2 })),\n  );\n\nexport const rippleReach = (point: RipplePoint, box: MeasuredBox): number =>\n  Math.ceil(\n    Math.max(\n      Math.hypot(point.x, point.y),\n      Math.hypot(point.x - box.width, point.y),\n      Math.hypot(point.x, point.y - box.height),\n      Math.hypot(point.x - box.width, point.y - box.height),\n    ),\n  );\n\nexport const rippleFrames = (\n  point: RipplePoint,\n  reach: number,\n): RippleFrames => ({\n  initial: {\n    width: 0,\n    height: 0,\n    left: point.x,\n    top: point.y,\n    borderRadius: 0,\n    opacity: rippleOpacity,\n  },\n  animate: {\n    width: reach * 2,\n    height: reach * 2,\n    left: point.x - reach,\n    top: point.y - reach,\n    borderRadius: reach,\n    opacity: 0,\n  },\n});\n"
    }
  ],
  "docs": "[Ripple button](https://gpuixui.sudokw.com/effects/ripple-button) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/effects/ripple-button",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}