📄 useVibrate¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 9 |
| 📐 Interfaces | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useVibrate/index.ts
📦 Imports¶
| Name | Source |
|---|---|
Arrayable |
@vueuse/shared |
Pausable |
@vueuse/shared |
MaybeRefOrGetter |
vue |
ConfigurableNavigator |
../_configurable |
ConfigurableScheduler |
../_configurable |
Supportable |
../types |
toRef |
@vueuse/shared |
defaultNavigator |
../_configurable |
useSupported |
../useSupported |
Functions¶
useVibrate(options: UseVibrateOptions): UseVibrateReturn¶
Reactive vibrate
Parameters:
optionsany: No description
See: https://vueuse.org/useVibrate, https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
Tags: @__NO_SIDE_EFFECTS__
Raw JSDoc
Calls:
useSupported (from ../useSupported)toRef (from @vueuse/shared)navigator!.vibrateschedulerintervalControls?.pause
Internal Comments:
Code
export function useVibrate(options?: UseVibrateOptions): UseVibrateReturn {
const {
pattern = [],
scheduler,
navigator = defaultNavigator,
} = options || {}
const isSupported = useSupported(() => typeof navigator !== 'undefined' && 'vibrate' in navigator)
const patternRef = toRef(pattern)
const vibrate = (pattern = patternRef.value) => {
if (isSupported.value)
navigator!.vibrate(pattern)
}
const intervalControls = scheduler?.(vibrate)
// Attempt to stop the vibration:
const stop = () => {
// Stope the vibration if we need to:
if (isSupported.value)
navigator!.vibrate(0)
intervalControls?.pause()
}
return {
isSupported,
pattern,
intervalControls,
vibrate,
stop,
}
}
Internal helpers¶
Declared inside another function in this file.
vibrate(pattern: any): void¶
Parameters:
patternany
Returns: void
Calls:
navigator!.vibrate
stop(): void¶
Returns: void
Calls:
navigator!.vibrateintervalControls?.pause
Internal Comments:
Code
Interfaces¶
UseVibrateOptions¶
Interface Code
export interface UseVibrateOptions extends ConfigurableNavigator, ConfigurableScheduler {
/**
*
* Vibration Pattern
*
* An array of values describes alternating periods in which the
* device is vibrating and not vibrating. Each value in the array
* is converted to an integer, then interpreted alternately as
* the number of milliseconds the device should vibrate and the
* number of milliseconds it should not be vibrating
*
* @default []
*
*/
pattern?: MaybeRefOrGetter<Arrayable<number>>
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
pattern |
MaybeRefOrGetter<Arrayable<number>> |
✓ | not shown |
UseVibrateReturn¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
pattern |
MaybeRefOrGetter<Arrayable<number>> |
✗ | not shown |
intervalControls |
Pausable |
✓ | not shown |
vibrate |
(pattern?: Arrayable<number>) => void |
✗ | not shown |
stop |
() => void |
✗ | not shown |
Generated by Syntax Scribe