GithubHelp home page GithubHelp logo

karibash / medi-q Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 0.0 2.64 MB

Type-safe media queries.

License: MIT License

JavaScript 4.41% TypeScript 95.59%
react styled-components emotion reactjs css-in-js

medi-q's Introduction

medi-q

npm version codecov @medi-q/core size @medi-q/core gzip size @medi-q/react size @medi-q/react gzip size @medi-q/emotion size @medi-q/emotion gzip size @medi-q/styled size @medi-q/styled gzip size Github Twitter

The medi-q package is a framework agnostic for simply generating media queries.

This package is currently an experimental version.
Please be aware that destructive changes may be made.

๐Ÿ‘€ Demo

๐Ÿ”ง Plugins

๐Ÿ—’ Examples

๐Ÿ‘ Getting Started

Use the ThemeProvider component to pass the Theme object and MediQ object to the subordinate components. If you do not use the styled api, use the MediQProvider in @medi-q/react.

import React from 'react';
import { BreakPoints, createMediQ } from '@medi-q/core';
import { ThemeProvider } from '@medi-q/emotion';
// import { ThemeProvider } from '@medi-q/styled';
// import { MediQProvider } from '@medi-q/react';

import { theme } from './theme';

const breakPoints: BreakPoints = {
  tiny: '400px',
  small: '600px',
  medium: '800px',
  large: '1000px',
};

const App: React.FC = () => {
  return (
    <ThemeProvider theme={theme} mediQ={createMediQ(breakPoints)}>
      ...
    </ThemeProvider>
  );
};

export default App;

By using the useMediQ hook in the lower-level component, you can execute a media query. You can also generate media queries with multiple conditions by connecting the queries with and or.

import React from 'react';
import styled from '@emotion/styled';
import { useMediQ } from '@medi-q/react';

const Wrapper = styled.div`
  background: ${props => props.theme.background};

  ${props => props.theme.mediQ('max-medium')} {
    background: blue;
  }
`;

const Page: React.FC = () => {
  const isLessThanSmall = useMediQ('max-small');
  const isGreaterThanMedium = useMediQ('min-medium');
  const isBetweenSmallAndMedium = useMediQ('min-small-and-max-medium');
  return (
    <Wrapper>
      {isLessThanSmall && <div>isLessThanSmall</div>}
      {isGreaterThanMedium && <div>isGreaterThanMedium</div>}
      {isBetweenSmallAndMedium && <div>isBetweenSmallAndMedium</div>}
    </Wrapper>
  );
};

export default Page;

๐Ÿš€ Installation

$ npm install @medi-q/core @medi-q/react

with emotion

$ npm install @medi-q/core @medi-q/react @medi-q/emotion

with styled-components

$ npm install @medi-q/core @medi-q/react @medi-q/styled

๐Ÿค Contributing

Contributions, issues and feature requests are welcome.

Feel free to check issues page if you want to contribute.

๐Ÿ“ License

Copyright ยฉ 2020 @Karibash.

This project is MIT licensed.

medi-q's People

Contributors

github-actions[bot] avatar karibash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.