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

riot-viewport-mixin

v1.1.0

Published

Mixin for updating riot tags when viewport changes

Downloads

9

Readme

riot-viewport-mixin

Relies on matchMedia, which is supported in all browsers

Updates the riot tag when the results of a media query change

Installation

npm i -S riot-viewport-mixin

API

riot-viewport-mixin exports two values

viewport will let you configure media queries

Alternatively you can execute and listen to the media queries you configure

viewportMixin will actually create the mixins to be used in riot

Configure and use in javascript

import { viewport } from 'riot-viewport-mixin'

// Define a config, naming your media queries with the object keys
const mediaQueryConfig = {
  // mobile
  sm: matchMedia('screen and (max-width: 767px)'),

  // tablet
  md: matchMedia('screen and (min-width: 768px) and (max-width: 1024px)'),

  // desktop
  lg: matchMedia('screen and (min-width: 1025px) and (max-width: 1200px)')
}

viewport.config(mediaQueryConfig)

// on mobile viewport

// attach listener
viewport.on('sm', mql => {
  console.log(mql.matches) // => true
})

// remove listener
viewport.off('sm', listener)

// check specific media query
viewport.is('md') // => false
viewport.isNot('lg') // => true

// get current matching viewport
// note: this will only work correctly if you don't have overlapping media queries
viewport.current() // => 'sm'

Use as a shared mixin

import { viewportMixin } from 'riot-viewport-mixin'

const config = {
  sm: matchMedia('screen and (max-width: 767px)'),
  md: matchMedia('screen and (min-width: 768px) and (max-width: 1024px)'),
  lg: matchMedia('screen and (min-width: 1025px) and (max-width: 1200px)')
}

// Assign the media query `config.sm` to the mixin `mobile`
this.mixin('mobile', viewportMixin('mobile', config.sm))

// Similarly for `tablet` and `config.md`
this.mixin('tablet', viewportMixin('tablet', config.md))
<my-tag>

  <!--
    When component functionality changes drastically between viewports
    for example:
  -->
  <Simple-Inline-List if={ !mobile } />
  <Hidden-Mega-List if={ mobile } />

  <script>
    this.mixin('mobile')
    // `this.mobile` is set according to the media query
    // When the viewport changes to/from mobile, this.update() is called and the variable is updated
  </script>

</my-tag>

Use as a standalone mixin

import { viewport } from 'riot-viewport-mixin'

const config = {
  mobile: matchMedia('screen and (max-width: 767px)')
}

// Set up mixins for `config` values using the `config` keys as mixin names
viewport.config(config)
<my-tag>

  <div if={ mobile }> Mobile view </div>

  <script>
    import { viewportMixin } from 'riot-viewport-mixin'

    this.mixin(viewportMixin('mobile'))
    // `this.mobile` is set as above

    // Alternatively, provide your own callback
    this.mixin(
      viewportMixin('mobile', () => {
        // `this.mobile` is already set with the new result
        console.log(this.mobile)
        this.update()
      })
    )
  </script>

</my-tag>