0.2.2 • Published 3 years ago

media-queries-min v0.2.2

Weekly downloads
39
License
-
Repository
github
Last release
3 years ago

🔀 media-queries-min

Simplest way to use media query with Child Functions and Hooks

Installation

yarn add media-queries-min

Child Function

import { MediaQuery } from 'media-queries-min'

function App() {
  // ...

  return (
    <div>
      <MediaQuery size="md">
        {({ matches }) => <>{matches ? '🎉' : '😥'}</>}
      </MediaQuery>
    </div>
  )
}

Hooks

import { useMediaQuery } from 'media-queries-min'

function App() {
  const { matches } = useMediaQuery('md')
  // ...

  return <div>{matches ? '🎉' : '😥'}</div>
}

API

useMediaQuery

const state = useMediaQuery(initialState)

state

Type: Object
KeyTypeDescription
matchesBooleanBecomes true when the window's size matches.

initialState

Default: xs
Type: <String,Object>
KeyTypeDescription
xsstringAssign a new value query to <= 576px.
smstringAssign a new value query to >= 576px.
mdstringAssign a new value query to >= 768px.
lgstringAssign a new value query to >= 992px.
xlstringAssign a new value query to >= 1200px.
paramsObject<size, maxWidth, minWidth>Provide with the following values { size: , maxWidth: 400 , minWidth: 500 }

MediaQuery

<MediaQuery {...props}>{(state) => {}}</MediaQuery>

state

Type: Object
KeyTypeDescription
matchesBooleanBecomes true when the window's size matches.

Props

Key/Type: size=<String>
Default: xs
KeyTypeDescription
xsstringAssign a new value query to <= 576px
smstringAssign a new value query to >= 576px
mdstringAssign a new value query to >= 768px
lgstringAssign a new value query to >= 992px
xlstringAssign a new value query to >= 1200px
Key/Type: maxWidth=<String,Number>
<MediaQuery maxWidth={'30vw'}>{(state) => {}}</MediaQuery>
Key/Type: minWidth=<String,Number>
<MediaQuery minWidth={'20vw'}>{(state) => {}}</MediaQuery>

Templates

Tag: emerald-ui

import { MediaQuery } from 'media-queries-min/lib/emerald-ui'

function App() {
  return (
    <div>
      <MediaQuery size="xs">
        {({ matches }) => <> {matches ? '🎉 ' : '😥'} </>}
      </MediaQuery>
    </div>
  )
}
Default: xs
KeyTypeDescription
xsstringAssign a new value query to <= 480px
smstringAssign a new value query to >= 768px
mdstringAssign a new value query to >= 992px
lgstringAssign a new value query to >= 1200px

Contribution

All the feedbacks/issues are very welcome! 😄

Please, contact me if any update about this repo @clouby

0.2.1

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.2.2

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago