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

pmx-responsive-state

v2.0.0-0

Published

Module to manage the state of a component through media queries.

Downloads

4

Readme

Responsive State:

Intro

Module to handle app state and event handlers based on media queries.

Getting Started

Create and instance of responsiveState and add a state

JavaScript:

import responsiveState from 'pmx-responsive-state';

const rs = responsiveState().add({
  id: 'mobile',
  query: 'screen and (max-width: 767px)',
  onEnter: () => { console.log('ENTERING Mobile mode >>>>>>>>>>>>>>>') },
  onLeave: () => { console.log('LEAVING Tablet mode <<<<<<<<<<<<<<<') },
});

How to use

Setup

The module is exported as an UMD module so it can be used with AMD, CommonJS, ES Modules and in the browser.

  • Install the dependency Using Yarn
yarn add pmx-responsive-state

or using NPM

npm install pmx-responsive-state --save
  • Include the module

CommonJS

const responsiveState = require('pmx-responsive-state').default;

ES2015 modules

import responsiveState from 'pmx-responsive-state';

API

.add(options)

options: options can be an array or an object. For each object, the options could be:

  • id: optional. The module will ensure that the passed id will always be unique. If omitted, a unique ID will be generated and you could grab it by saving saving the call to this method in a var (that will return an object containing the unique ID).
  • query: optional. Media query to be used to detect when the state will become active or not. Note: If omitted the query will always match.
  • onEnter: optional Function to be executed every time the states gets active.
  • onEnterOnce: optional Function to be executed only the first time the states gets active.
  • onLeave: optional Function to be executed every time the states gets inactive.
  • onLeaveOnce: optional Function to be executed only the first time the states gets inactive. returns: an object containing the ID used to generate the state.

.remove(id|[id])

options: id can be an array or a string detailing the IDs to be removed returns: a Boolean or an Array of Booleans detailing the status of the process of removing the state/s

.removeAll()

returns: an Array of Booleans detailing the status of the process of removing all the states

.getState(id)

options: a string detailing the state ID to be retrieved returns: an object containing all the details of the retrieved state

.getStates([id])

options: an array detailing the states IDs to be retrieved returns: an array of object containing all the details of the retrieved states

Browser Support

  • IE 10+
  • Chrome
  • Firefox
  • Safari

This library has been written with some ES2015 features that need to be polyfilled:

  • Map
  • Object.assign