@globocom/with-match-media-props

1.1.0 • Public • Published

with-match-media-props NPM CircleCI JavaScript Style Guide

This is a HOC desgined to help you define props according to media queries breakpoints.

Just as CSS media queries, you can combine and/or override props with multi-matching media queries.

Install

npm install --save @globocom/with-match-media-props

Usage

withMatchMediaProps(
  matchMediaMapper: (ownerProps: Object) => Object | Object
): HigherOrderComponent

This HOC accepts a static object mapping media-queries to props, or a function that receives the component props and return the mapped media-queries.

Ex:

import React, { Component } from 'react'

import withMatchMediaProps from '@globocom/with-match-media-props'

const Component = (props) => (
  <div>
    <span>MediaQuery: {props.mediaQuery}</span>
    <span>Is larger or equal to 360px: {!!props.mediaQuery360}</span>
    <span>Is larger or equal to 768px: {!!props.mediaQuery768}</span>
  </div>
)
const EnhancedComponent = withMatchMediaProps({
  'screen and (min-width: 360px)': {
    mediaQuery: 360,
    mediaQuery360: true,
  },
  'screen and (min-width: 768px)': {
    mediaQuery: 768,
    mediaQuery768: true,
  },
})(Component)

class Example extends Component {
  render () {
    return (
      <EnhancedComponent mediaQuery={1} otherProps="example" />
    )
  }
}

📺 Check out live demo

License

MIT © globocom

Readme

Keywords

none

Package Sidebar

Install

npm i @globocom/with-match-media-props

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

36.4 kB

Total Files

4

Last publish

Collaborators