Giter VIP home page Giter VIP logo

isw-responsive-behavior's Introduction

<isw-responsive-behavior>

Deprecated! New approach with isw-responsive.

Provides feedback about device and orientation, using material design breakpoints.

https://material.io/guidelines/layout/responsive-ui.html#responsive-ui-breakpoints

Properties

  • screenWidth (Number)
  • screenHeight (Number)
  • device (String, "mobile", "tablet", "desktop")
  • orientation (String, "portrait", "landscape")

Add behavior

It's recommended to use it only once (e.g. in the app) and propagate it to the children (e.g. the views) via properties. Make sure to set reflectToAttribute if attribute selectors are used in the view.

Polymer 2.0:

class MyApp extends Polymer.mixinBehaviors([ iswResponsiveBehavior ], Polymer.Element ) {
  ...
}

Polymer 1.0:

Polymer({
  is: 'my-app',
  behaviors: [ iswResponsiveBehavior ]

  ...
});

CSS

The device and orientation properties reflect to attribute, so attribute selectors can be used.

:host([device="desktop"]) .someSelector { ... }
:host([device="mobile"][orientation="landscape"]) .someSelector { ... }

Elements

Some of our elements, e.g. isw-toolbar, are using device and orientation to display. Simply bind these properties to make them responsive.

<isw-toolbar device="[[device]]" orientation=[[orientation]]> ... </isw-toolbar>

Imperative

iswResponsiveBehavior gets the onResize function called, with Polymer 2.0 classes it can be used like a lifecycle function.

onResize() {
  super.onResize();

  switch( this.device ) {
    case 'desktop':
      // Desktop.
      break;
    case 'tablet':
      // Tablet.
      break;
    default:
      // Mobile.
  }
}

isw-responsive-behavior's People

Contributors

rene-lindner-isw avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.