Socket
Socket
Sign inDemoInstall

@anexia/platform-tools

Package Overview
Dependencies
3
Maintainers
6
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anexia/platform-tools


Version published
Weekly downloads
4
decreased by-73.33%
Maintainers
6
Created
Weekly downloads
 

Readme

Source

Platform Tools

Provides Ionic Framework way class mapping of current platform and orientation on the root document node ´html´ for usage inside scss or :host-context selecting.

Usage

Simply inject the service in your root app component and it will add classes to your document.

import {PlatformToolsService} from "./platform-tools.service";

export class AppComponent {
  public constructor(
      // ... 
    private readonly platformService: PlatformToolsService
      // ... 
  ) {

  }
}

Now you're able to use :host-context(.plt-tablet) at Angular Component SCSS level for writing context based css, or use at global.scss/style.scss as selector .plt-tablet > app-component { ... }.

Available class selectors:

Selector NameDescription
plt-androida device running Android
plt-desktopa desktop device
plt-iosa device running iOS
plt-ipadan iPad device
plt-iphonean iPhone device
plt-mobilea mobile device
plt-mobileweba web browser running in a mobile device
plt-phableta phablet device
plt-pwaa PWA app
plt-tableta tablet device
is-landscapea device with landscape orientation
is-portraita device with portrait orientation

Example

Inside your Angular Component Stylesheet SCSS

:host {
  display: block;
  width: 100%;
  height: 100vh;
}

// set color of font to white on ios platform
:host-context(.plt-ios) {
  :host {
    color: white;
  }
}
// set background color to blue on tablet
:host-context(.plt-tablet) {
  :host {
    background-color: blue;
  }
  
  // set background color red if tablet and landscape
  :host-context(.is-landscape) {
    :host {
      background-color: red;
    }
  }
}


Or inside your style.scss / global.scss without :host-context since it is only available inside component scss scopes.

html.plt-ios {
 // ... your rules
}

// or
.plt-tablet{

}

Notes

Platform class mapping won't change if simply changing device emulator inside Chrome since platform evaluation is done only on boot. A Reload will be needed. Screen orientation will be update on screenorientation change by listening to the window resize event.

Author

  • Sven Graziani

Credits

To the Ionic Framework core team for the inspiration.

Keywords

FAQs

Last updated on 22 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc