Shopware Design

Device helper

Usage

Device Helper is a Vue plugin that adds a $device helper to every component for reading viewport, screen, and platform information, and for reacting to viewport resizes.

import { DeviceHelperPlugin } from "@shopware-ag/meteor-component-library";

app.use(DeviceHelperPlugin);

Once installed, use this.$device in any component:

const width = this.$device.getViewportWidth();
const platform = this.$device.getPlatform();

API

$device exposes:

MethodReturnsDescription
getViewportWidth()numberCurrent viewport width in pixels.
getViewportHeight()numberCurrent viewport height in pixels.
getScreenWidth()numberScreen width in pixels.
getScreenHeight()numberScreen height in pixels.
getDevicePixelRatio()numberThe device pixel ratio.
getScreenOrientation()ScreenOrientationThe current screen orientation.
getUserAgent()stringThe browser user agent string.
getBrowserLanguage()stringThe browser language.
getPlatform()stringThe operating system platform.
getSystemKey()stringThe platform system modifier key (Control or Command).
onResize({ listener, scope, component })numberRegisters a viewport resize listener and returns its id.
removeResizeListener(component)booleanRemoves the resize listeners registered for a component.