Skip to content
Back to search

web-haptics

SkillWorks with Claude CodeGitHub

Add haptic feedback to web apps using the web-haptics library. Use when building mobile-facing UIs that need tactile feedback on buttons, toggles, forms, pickers, and other interactive elements.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/lochie--web-haptics/badge.svg)](/listings/lochie--web-haptics)

HTML

<a href="/listings/lochie--web-haptics"><img src="/api/listings/lochie--web-haptics/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

npm i web-haptics

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 141 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ---
  2. name: web-haptics
  3. description: Add haptic feedback to web apps using the web-haptics library. Use when building mobile-facing UIs that need tactile feedback on buttons, toggles, forms, pickers, and other interactive elements.
  4. license: MIT
  5. metadata:
  6. author: lochie
  7. version: "1.0"
  8. ---
  9. Install `web-haptics` (`npm i web-haptics`) and add haptic feedback to the app following these rules:
  10. ## Package: web-haptics
  11. Repository: https://github.com/lochie/web-haptics | License: MIT | Zero dependencies
  12. Uses the Web Vibration API. Silently no-ops on unsupported platforms (desktop). No error handling or feature detection needed.
  13. ## Trigger Types
  14. `trigger()` accepts one of these strings (empty value defaults to a sensible "medium" impact):
  15. Notification (task outcomes):
  16. - "success" -- form saved, payment confirmed, upload complete
  17. - "warning" -- destructive action ahead, approaching limit, irreversible step
  18. - "error" -- validation failure, network error, permission denied
  19. Impact (physical collisions):
  20. - "light" -- small toggle, subtle tap, minor interaction
  21. - "medium" -- button press, card snap-to-position, drop into place
  22. - "heavy" -- major state change, heavy element landed, force press
  23. Selection (discrete stepping):
  24. - "selection" -- picker scroll, stepper increment, slider detent, segment switch
  25. ## Framework Imports
  26. React:
  27. ```tsx
  28. import { useWebHaptics } from "web-haptics/react";
  29. const haptic = useWebHaptics();
  30. <button onClick={() => haptic.trigger()}>Tap me</button>;
  31. ```
  32. Vue:
  33. ```vue
  34. <script setup>
  35. import { useWebHaptics } from "web-haptics/vue";
  36. const haptic = useWebHaptics();
  37. </script>
  38. <template>
  39. <button @click="haptic.trigger()">Tap me</button>
  40. </template>
  41. ```
  42. Svelte:
  43. ```svelte
  44. <script>
  45. import { createWebHaptics } from "web-haptics/svelte";
  46. import { onDestroy } from "svelte";
  47. const haptic = createWebHaptics();
  48. onDestroy(() => haptic.destroy());
  49. </script>
  50. <button on:click={() => haptic.trigger()}>Tap me</button>
  51. ```
  52. Vanilla JS:
  53. ```js
  54. import { WebHaptics } from "web-haptics";
  55. const haptics = new WebHaptics();
  56. haptics.trigger(); // medium impact
  57. haptics.trigger("success");
  58. ```
  59. Next.js: add "use client" to any component using useWebHaptics().
  60. Nuxt/SvelteKit: works directly, library handles SSR.
  61. ## Trigger Presets & defaultPatterns
  62. All named string presets have a corresponding object in `defaultPatterns`. Use when you need to pass a preset as a value rather than a string literal:
  63. ```ts
  64. import { WebHaptics, defaultPatterns } from 'web-haptics'
  65. const haptics = new WebHaptics()
  66. haptics.trigger(defaultPatterns.light)
  67. ```
  68. Extra presets not listed above: `"soft"`, `"rigid"`, `"nudge"`, `"buzz"`. See `defaultPatterns` for all available values.
  69. ## Apple HIG Design Rules -- FOLLOW THESE
  70. 1. Haptics supplement, never replace. Always pair with visual feedback. UI must work fully without haptics.
  71. 2. Build causal relationships. The haptic must feel like a direct physical consequence of the user action.
  72. 3. Match intensity to significance. Light interactions = light/selection. Standard = medium/success. Major = heavy/error/warning.
  73. 4. Do not overuse. If every tap vibrates, nothing feels special. Reserve for meaningful moments only.
  74. 5. Synchronize perfectly. Fire haptic at the exact instant the visual change occurs.
  75. 6. Respect conventions. success=positive, error=negative, warning=cautionary, selection=discrete ticks only.
  76. 7. For async ops, trigger when the RESULT arrives, synced with the visual state change:
  77. ```js
  78. try {
  79. await submit();
  80. haptic.trigger("success");
  81. } catch {
  82. haptic.trigger("error");
  83. }
  84. ```
  85. ## Interaction to Type Quick Reference
  86. Primary button tap = "medium" | Secondary button = "light"
  87. Form success = "success" | Validation error = "error" | Network error = "error"
  88. Toggle switch = "light" | Delete before confirm = "warning"
  89. Picker/wheel = "selection" | Slider detents = "selection" | Tab switch = "selection"
  90. Drag-drop snap = "medium" | Long press = "heavy" | Modal appear = "medium"
  91. Pull-to-refresh threshold = "light" | Swipe dismiss threshold = "light"
  92. Payment confirmed = "success"
  93. ## Anti-Patterns -- AVOID
  94. - Haptic on every tap (fatigue)
  95. - "error" for non-errors (breaks conventions)
  96. - Haptic without visual feedback (some devices cannot vibrate)
  97. - Haptic on page load or passive scroll (invasive)
  98. - "heavy" for minor interactions (jarring)
  99. - Long continuous vibrations (web haptics = brief transient pulses)
  100. ## Before implementing, confirm with the user:
  101. - Which interactive elements to target
  102. - Whether to add at shared component level or individual call sites
README.md · README · 58 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # WebHaptics
  2. Haptic feedback for the mobile web. Supports React, Vue, and Svelte.
  3. ## Installation
  4. ```sh
  5. npm i web-haptics
  6. ```
  7. ## Usage
  8. ```tsx
  9. import { useWebHaptics } from "web-haptics/react";
  10. function App() {
  11. const { trigger } = useWebHaptics();
  12. return <button onClick={() => trigger("success")}>Tap me</button>;
  13. }
  14. ```
  15. See the [package README](packages/web-haptics/README.md) for Vue, Svelte, and vanilla examples.
  16. # Contributing
  17. ## Install dependencies
  18. ```sh
  19. pnpm install:all
  20. ```
  21. ## Dev/Watch Library and Example
  22. ```sh
  23. pnpm dev
  24. ```
  25. ## Build Library
  26. ```sh
  27. pnpm build
  28. ```
  29. ## Found this useful?
  30. Follow me on [Twitter](https://twitter.com/lochieaxon).
  31. ## Other projects
  32. You might also like:
  33. - [Torph](https://torph.lochie.me) - Dependency-free animated text component.
  34. - [easing.dev](https://easing.dev) - Easily create custom easing graphs.
  35. # Acknowledgements
  36. - Special thanks to [Alex](https://x.com/alexvanderzon) for assistance with the site design.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.