import { WrHaptics, WrPlatform } from 'ngwr/platform';WrPlatform
SSR-safe browser checks, user-preference signals and haptics.
Installation
Import the class. This entry point has no stylesheet.
Usage
private readonly platform = inject(WrPlatform);
if (this.platform.isBrowser) {
localStorage.setItem('theme', 'dark');
}
protected readonly dark = this.platform.prefersDark; // Signal<boolean>
protected readonly reduce = this.platform.prefersReducedMotion; // Signal<boolean>API
| Name | Description | Type | Default |
|---|---|---|---|
isBrowser / isServer | Synchronous platform check. | boolean | — |
userAgent | navigator.userAgent or null on the server. | string | null | — |
prefersDark | Signal mirroring (prefers-color-scheme: dark). | Signal<boolean> | — |
prefersReducedMotion | Signal mirroring (prefers-reduced-motion: reduce). | Signal<boolean> | — |
WrHaptics
Vibration presets for touch devices; a no-op on the server, in iOS Safari and wherever navigator.vibrate is missing.
private readonly haptics = inject(WrHaptics);
this.haptics.warning(); // before a destructive action
this.haptics.selection(); // on a switch or segmented change
this.haptics.supported; // false on the server and in iOS Safari| Name | Description | Type | Default |
|---|---|---|---|
supported | Whether the Vibration API exists. false on iOS Safari. | boolean | — |
vibrate(pattern) | Vibrate for ms, or a [buzz, pause, …] pattern. 0 or [] cancels. | (number | readonly number[]) => boolean | — |
impact(strength?) | A tap: light, medium or heavy. | ('light'|'medium'|'heavy') => boolean | 'medium' |
selection() | A subtle tick for a discrete change. | () => boolean | — |
success() / warning() / error() | Pulses for a done, risky or failed action. | () => boolean | — |
stop() | Cancel any in-progress vibration. | () => void | — |
See also
Guide Server-side renderingPrerender and hydrate an ngwr app without mismatches.Guide Mobile & responsiveMake ngwr layouts work on touch screens and narrow containers.Component Pull to RefreshPull down from the top of a scrolling list to refresh it.Service WrThemeSwitch between light, dark and auto, and keep the choice.Guide MotionEasing and duration tokens for your transitions and animations.