Coder Social home page Coder Social logo

pixelize / react-styled-mediaquery Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 830 KB

Simple and practical utility for managing media queries in react with styled components

License: MIT License

JavaScript 72.17% TypeScript 27.83%
breakpoints responsive styled-components react rwd media-queries media query mediaquery custom-breakpoints

react-styled-mediaquery's Introduction

react-styled-mediaquery

Description

react-styled-mediaquery is a simple and practical function for managing media queries in react with styled components.

Demo

Github page

Also: See example folder in gatsby/pages. You can run it locally using Gatsby just clone the repos and use yarn start in your CLI. Demo is running on localhost:8000

Installation

yarn npm
yarn add react-styled-mediaquery npm add react-styled-mediaquery

Usage

import React from "react";
import { mediaQuery } from "react-styled-mediaquery";

const  Card  =  styled.div`
  background: red;

  ${mediaQuery("<", "tablet")`
    background: blue;
  `}

  ${mediaQuery(">", "desktop")`
    background: yellow;
  `}
`

const App = () => {
  return (
    <div>
      <Card>hello world</Card>
    </div>
  )
}

Conditions & default breakpoints

You can either use the default breakpoints shortcuts using the string mobile | phablet | tablet | desktop. Just mix your condition and breakpoints as you wish !

>

Element will be blue above the tablet breakpoint

${mediaQuery(">", "tablet")`
  background: blue;
`}

=>

Element will be blue above & including the mobile breakpoint

${mediaQuery("=>", "mobile")`
  background: blue;
`}

<

Element will be blue below desktop breakpoints

${mediaQuery("<", "desktop")`
  background: blue;
`}

<=

Element will be blue below & including the phablet breakpoint

${mediaQuery("<=", "phablet")`
  background: blue;
`}

between

Element will be blue between the phablet and desktop breakpoint

${mediaQuery("between", "phablet", "desktop")`
  background: blue;
`}

Custom Breakpoints

These are the default settings, you can overwrite with your own breakpoints

const devices = {
  mobile: "412px",
  phablet: "600px",
  tablet: "768px",
  desktop: "1024px"
};

You can also use the function with a custom declarative breakpoint in pixel i.e:

${mediaQuery("<", "638px")`
  background: blue;
`}

react-styled-mediaquery's People

Contributors

pixelize avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-styled-mediaquery's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.