match-media-mock
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/match-media-mock package

0.1.1 • Public • Published

MatchMediaMock

Build Status npm

Simple server-side compatible substitution for Window.matchMedia() based on css-mediaquery. Designed for use with Radium.

Basic usage

var matchMediaMock = require('match-media-mock').create()
matchMediaMock.setConfig({type: 'screen', width: 1200})
 
matchMediaMock('(max-width: 991px)').matches // false
matchMediaMock('(max-width: 1240px)').matches // true
 
var mediaQueryList = matchMediaMock(mediaQuery)
mediaQueryList.addListener(listener)
mediaQueryList.removeListener(listener)
mediaQueryList.callListeners()

For more details about matching check out css-mediaquery!

Example usage with Radium

var Radium = require('radium')
var matchMediaMock = require('match-media-mock').create()
Radium.config.setMatchMedia(matchMediaMock)
 
app.get('/app/:width/:height', function(req, res) {
  matchMediaMock.setConfig({
    type: 'screen',
    width: req.params.width,
    height: req.params.height
  })
  var html = React.renderToString(<RadiumApp/>)
  res.end(html)
})

For more details see the Radium docs

Package Sidebar

Install

npm i match-media-mock

Weekly Downloads

9,170

Version

0.1.1

License

MIT

Unpacked Size

11 kB

Total Files

10

Last publish

Collaborators

  • azazdeaz
  • lucianbuzzo