2.0.1 • Published 3 years ago

css-in-js-media v2.0.1

Weekly downloads
922
License
MIT
Repository
github
Last release
3 years ago

css-in-js-media :art:

Minified and Simplified include-media with CSS-in-JS

when you style with css-in-js (emotion, styled-component) you can perfectly and easily deal with responsive design with this css-in-js-media which is similar with include-media and support type system(ts)

If you think this library is helpful, Support by give :star:

Migrate to Typescript at version V2 :tada:

Introduced at


:book: documentation


:rocket: install & default usage

npm install css-in-js-media
import media from "css-in-js-media";

media-query break-point (default breakpoint)

smallPhone: 320
phone: 375
tablet: 768
desktop: 1024
largeDesktop: 1440

:school_satchel: size

image


:question: how-to-use

with css-in-js library (ex: emotion.js , styled-component)

  • example with emotion.js
import media from "css-in-js-media";

export const exampleClass = css`
  color: red;
  ${media(">desktop")} {
    font-size: 15px;
  }
  ${media("<=desktop", ">tablet")} {
    font-size: 20px;
  }
  ${media("<=tablet", ">phone")} {
    font-size: 25px;
  }
  ${media("<=phone")} {
    font-size: 30px;
  }
`;
  • example with styled-component
import media from "css-in-js-media";

const exampleClass = styled.h1`
  color: red;
  ${media(">desktop")} {
    font-size: 15px;
  }
  ${media("<=desktop", ">tablet")} {
    font-size: 20px;
  }
  ${media("<=tablet", ">phone")} {
    font-size: 25px;
  }
  ${media("<=phone")} {
    font-size: 30px;
  }
`;

set flexible breakpoints (optional)

⚠️ You should set this in entry point file (root file)

import { setBreakPoints } from "css-in-js-media";
setBreakPoints({ desktop: 1440, largeDesktop: 1500 });

// or string size
setBreakPoints({ desktop: "140rem", largeDesktop: "calc(30 * 50px)" });

get breakpoints (optional)

import { getBreakPoints } from "css-in-js-media";
getBreakPoints();
// default breakpoints
// {
//   smallPhone: 320;
//   phone: 375;
//   tablet: 768;
//   desktop: 1024;
//   largeDesktop: 1440;
// }

:heart: THANKS

:bug: Bug reporting

Issue

License

MIT

2.0.1

3 years ago

2.0.0

3 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago