npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-screen

v2.0.0

Published

A screen size service for Ember

Downloads

1,492

Readme

Ember Screen

Codeship Status for mitchlloyd/ember-screen

This addon adds a screen service to your Ember application that will report the current height and width of the window.

import Ember from 'ember';
const { Component, computed, inject } = Ember;

export default Ember.Component({
  screen: inject.service(),

  showTopNavigation: computed('screen.width', function() {
    return this.get('screen.width') > 1000;
  })
})

Installation

ember install ember-screen

Using Media Queries

Ember Screen is configured with a set of properties that correspond to Bootstrap 4's media queries. This is the default implementation of app/services/screen.js.

import EmberScreen, { breakpoint } from 'ember-screen';

export default EmberScreen.extend({
  isSmallAndUp: breakpoint('(min-width: 34em)'),
  isMediumAndUp: breakpoint('(min-width: 48em)'),
  isLargeAndUp: breakpoint('(min-width: 62em)'),
  isExtraLargeAndUp: breakpoint('(min-width: 75em)'),

  isExtraSmallAndDown: breakpoint('(max-width: 33.9999em)'),
  isSmallAndDown: breakpoint('(max-width: 47.9999em)'),
  isMediumAndDown: breakpoint('(max-width: 61.9999em)'),
  isLargeAndDown: breakpoint('(max-width: 74.9999em)')
});

If you inject screen into a component, you could use a media query property like this:

{{#if screen.isSmallAndDown}}
  ☰ <!-- obligatory hamburger -->
{{/if}}

To configure your own media queries, create an app/services/screen.js file in your application and extend from the Ember Screen service.

import EmberScreen, { breakpoint } from 'ember-screen';

export default EmberScreen.extend({
  isMobile: breakpoint('(max-width: 479px)'),
  isDesktop: breakpoint('(min-width: 480px)')
});

Testing Media Queries

Creating automated tests for different screen sizes is often neglected because it is not practical to programmatically resize a web browser during tests. Ember Screen lets you to stub media features to run tests that are integrated with your screen service logic.

// An example acceptance test

test('shows large logo on HD tv', function(assert) {
  let screen = this.owner.lookup('service:screen');
  screen.stubMediaFeatures({ type: 'tv', width: 1920 });

  visit('/');

  andThen(function() {
    assert.equal(find('.logo-large').length, 1, "HD TVs have large logo");
  });
});

This feature uses css-mediaquery to parse your configured breakpoints and see if they match with the stubbed values.

Running in FastBoot

Ember screen is compatible with FastBoot out of the box. However in a FastBoot environment running on a server there is no way to access the screen properties of the client. If your UI depends on the device's screen size then you can use the screen service's stubMediaFeatures method to provide defaults. See this simple example of a FastBoot-only instance initializer.

Running the Tests for this Addon

Running tests that resize a web browser is challenging because web browsers disable window.resizeTo and window.resizeBy APIs. Chrome will allow these methods to work for popup windows that have been programatically created with window.open. The current test suite has some finicky configuration will only succeed when running with Testem, so the proper way to run tests locally is to use:

ember test

or

ember test --server