{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "haptic",
  "title": "Haptic Feedback",
  "author": "ncdai <dai@chanhdai.com>",
  "description": "Trigger haptic feedback on mobile devices.",
  "files": [
    {
      "path": "src/registry/lib/haptic/haptic.ts",
      "content": "const isTouchDevice =\n  typeof window !== \"undefined\"\n    ? window.matchMedia(\"(pointer: coarse)\").matches\n    : false\n\n/**\n * Trigger haptic feedback on mobile devices.\n * Uses Vibration API on Android/modern browsers, and iOS checkbox trick on iOS.\n *\n * @param pattern - Vibration duration (ms) or pattern.\n * Custom patterns only work on Android devices. iOS uses fixed feedback.\n * See [Vibration API](https://developer.mozilla.org/docs/Web/API/Vibration_API)\n *\n * @example\n * import { haptic } from \"@/lib/haptic\"\n *\n * <Button onClick={() => haptic()}>Haptic</Button>\n */\nexport function haptic(pattern: number | number[] = 50) {\n  try {\n    if (!isTouchDevice) return\n\n    if (\"vibrate\" in navigator) {\n      navigator.vibrate(pattern)\n      return\n    }\n\n    // iOS haptic trick via checkbox switch element\n    const label = document.createElement(\"label\")\n    label.ariaHidden = \"true\"\n    label.style.display = \"none\"\n\n    const input = document.createElement(\"input\")\n    input.type = \"checkbox\"\n    input.setAttribute(\"switch\", \"\")\n    label.appendChild(input)\n\n    try {\n      document.head.appendChild(label)\n      label.click()\n    } finally {\n      document.head.removeChild(label)\n    }\n  } catch {}\n}\n",
      "type": "registry:lib",
      "target": "@lib/haptic.ts"
    }
  ],
  "docs": "https://chanhdai.com/components/haptic-feedback",
  "categories": [
    "utilities"
  ],
  "type": "registry:lib"
}