GithubHelp home page GithubHelp logo

styled-media-responsive's Introduction

styled-media-responsive

Everything needed to make your styled-components 💅 React Application responsive using media queries.

Installation:

npm install styled-media-responsive

Breakpoints:

you can use the default breakpoints or set your own by passing them to the function. See example below

Default breakpoints:

  defaultDevices: {
    phone: {
      max: 768
    },
    tablet: {
      min: 768,
      max: 1160
    },
    desktop: {
      min: 1160,
      max: 1400
    },
    large: {
      min: 1400
    }
  }

Importing the default breakpoints into your app (if needed):

 import { defaultBreakpoints } from 'styled-media-responsive'

mediaQuery Usage:

The order in which we declare these matter since they share a starting and ending point, the best practice would be to declare the media queries in descending order (unless that's not the desired behaviour)

  // If using the default breakpoints:
  import mediaQuery from 'styled-media-responsive'

  export const media = mediaQuery()


  // If using your own breakpoints:

  import mediaQuery from 'styled-media-responsive'

  const breakpoints = {
    smallPhone: {
      max: 576
    },
    mediumPhone: {
      min: 576,
      max: 768
    },
    tablet: {
      min: 768,
      max: 992
    },
    desktop: {
      min: 992,
      max: 1200
    },
    reallyLarge: {
      min: 1200,
    }
  }

  export const media = mediaQuery(breakpoints)

 ---------------------------------

 // on your styled components definitions
  import styled from 'styled-components'
  import { media } from '../path-to-where-defined'

  // this example assumes you are not defining your own breakpoints, if you are,
  // you would do media.nameOfYourBreakpoint

  export const SuperComponent = styled.div`
    background-color: yellow;
    ${media.desktop`
      background-color: red;
    `}
    ${media.tablet`
      background-color: blue;
    `}
    ${media.phone`
      background-color: green;
    `}
  `

styled-media-responsive's People

Contributors

arovillard avatar

Stargazers

Radu Paraschiv avatar Sabin Tudor avatar  avatar

Watchers

 avatar

styled-media-responsive's Issues

Duplicate React Problem

Hey,
I'm trying to use hooks that have conflicts with this library. I read this in React docs:

If you see more than one React, you’ll need to figure out why this happens and fix your dependency tree. For example, maybe a library you’re using incorrectly specifies react as a dependency (rather than a peer dependency)

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.