All Projects → malte-wessel → react-matchmedia-connect

malte-wessel / react-matchmedia-connect

Licence: MIT license
Higher order components for matchMedia

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-matchmedia-connect

Responsive Bootstrap Toolkit
Responsive Bootstrap Toolkit allows for easy breakpoint detection in JavaScript
Stars: ✭ 364 (+642.86%)
Mutual labels:  responsive, breakpoint
react-context-responsive
A package that provides a responsive context to your application, using React Context API.
Stars: ✭ 25 (-48.98%)
Mutual labels:  responsive, matchmedia
use-breakpoint
React `useBreakpoint` hook to have different values for a variable based on a breakpoints.
Stars: ✭ 17 (-65.31%)
Mutual labels:  responsive, breakpoint
Match Media
Universal polyfill for match media API using Expo APIs on mobile
Stars: ✭ 95 (+93.88%)
Mutual labels:  responsive, breakpoint
React Flexa
Responsive React Flexbox (CSS Flexible Box Layout Module) grid system based heavily on the standard CSS API.
Stars: ✭ 120 (+144.9%)
Mutual labels:  responsive, breakpoint
Flexi
Just a layout framework. Design for cross-platform with ease.
Stars: ✭ 220 (+348.98%)
Mutual labels:  responsive, breakpoint
Mq Scss
Extremely powerful Sass media query mixin. Allows you to create almost any media query you can imagine.
Stars: ✭ 122 (+148.98%)
Mutual labels:  responsive, breakpoint
breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (-26.53%)
Mutual labels:  responsive, breakpoint
mainsail
Mainsail is the popular web interface for Klipper
Stars: ✭ 960 (+1859.18%)
Mutual labels:  responsive
tb-grid
tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.
Stars: ✭ 19 (-61.22%)
Mutual labels:  responsive
Portfolio-Demo-1
A portfolio build by using flutter for web.
Stars: ✭ 74 (+51.02%)
Mutual labels:  responsive
ionic-login-component
Free sample of Premium Ionic Login Component
Stars: ✭ 17 (-65.31%)
Mutual labels:  responsive
Tech-Writing-Linktree
✨ tech writer portfolio in the style of linktree ✨
Stars: ✭ 26 (-46.94%)
Mutual labels:  responsive
ekzo
💫 Functional Sass framework for rapid and painless development
Stars: ✭ 32 (-34.69%)
Mutual labels:  responsive
soosyze
🌠 Soosyze CMS is a minimalist content management system in PHP, without database to create and manage your website easily. https://soosyze.com
Stars: ✭ 39 (-20.41%)
Mutual labels:  responsive
responsivebootstrap
This is the repository for my course, Bootstrap Layouts: Responsive Single-Page Design on LinkedIn Learning and Lynda.com.
Stars: ✭ 49 (+0%)
Mutual labels:  responsive
pichichi
Simple one page responsive portfolio template
Stars: ✭ 54 (+10.2%)
Mutual labels:  responsive
vue-responsive-text
↔ Vue component that scales its child node in relation to its parent node's width
Stars: ✭ 23 (-53.06%)
Mutual labels:  responsive
cookie
Landing website + Blog using Jekyll & Tailwind CSS
Stars: ✭ 61 (+24.49%)
Mutual labels:  responsive
flutter-ui-boilerplate
Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.
Stars: ✭ 114 (+132.65%)
Mutual labels:  responsive

react-matchmedia-connect

npm npm version npm downloads

Check out the demo

Installation

npm install react-matchmedia-connect --save

Usage

createMatchMediaConnect

createMatchMediaConnect lets you register a set of media queries. If one of the queries changes, you component will be updated.

import { createMatchMediaConnect } from 'react-matchmedia-connect';

// Define some media queries and give them a key
const connect = createMatchMediaConnect({
  isLandscape: '(orientation: landscape)',
  isMin400: '(min-width: 400px)',
  isTablet: '(min-width: 700px), handheld and (orientation: landscape)'
});

Then use this connect function throughout your app:

const Component = ({ isLandscape, isMin400 }) => (
  <div>
    <div>{isLandscape ? 'landscape' : 'portrait'}</div>
    <div>{isMin400 ? 'at least 400' : 'less than 400'}</div>
  </div>
);
// This component only needs `isLandscape` and `isMin400`
const ConnectedComponent = connect(['isLandscape', 'isMin400'])(Component);
const OtherComponent = ({ isTablet }) => (
  isTablet ? <div>Tablet</div> : <div>No tablet</div>
);
// This component only needs `isTablet`
const OtherConnectedComponent = connect(['isTablet'])(Component);

createResponsiveConnect

createResponsiveConnect expects a list of breakpoints and creates the respective media queries with createMatchMediaConnect. You'll get a isMin<Size> and isMax<Size> property for each breakpoint as well as a isPortrait and isLandscape property.

import { createResponsiveConnect } from 'react-matchmedia-connect';
const connect = createResponsiveConnect({
  xs: 480,
  sm: 768,
  md: 992,
  lg: 1200
});
const Component = ({ isMinMd, isMaxMd }) => (
  <div>
    <div>{isMinMd ? 'greater than 992px' : 'less than 992px'}</div>
    <div>{isMaxMd ? 'less than 1200px' : 'greater than 1199px'}</div>
    <div>{isMinMd && isMaxMd ? 'between 992px and 1199px' : 'other'}</div>
  </div>
);
// Only connect to `isMinMd` and `isMaxMd`
const ConnectedComponent = connect(['isMinMd', 'isMaxMd'])(Component);

API

createMatchMediaConnect(mediaQueries)

  • mediaQueries (Object): A set of media queries.
  • returns (Function): connect function that connects your components to changes
const connect = createMatchMediaConnect({
  isLandscape: '(orientation: landscape)',
  isMin400: '(min-width: 400px)'
});
connect(properties)
  • properties (Array): An array of properties that your component should receive
  • returns (Function): wrapWithConnect higher order function
const wrapWithConnect = connect(['isMin400']);
wrapWithConnect(Component)
  • Component (Component): The component that you want to connect
  • returns (Component): Connected component
const Component = ({ isMin400 }) => (
  <div>{isMin400 ? 'at least 400' : 'less than 400'}</div>
);
// This component only needs `isLandscape` and `isMin400`
const ConnectedComponent = wrapWithConnect(Component);

createResponsiveConnect(breakpoints)

  • breakpoints (Object): A set of breakpoints
  • returns (Function): connect function that connects your components to changes

Default breakpoints:

const defaultBreakpoints = {
  xs: 480,
  sm: 768,
  md: 992,
  lg: 1200
};

Examples

Run the simple example:

# Make sure that you've installed the dependencies
npm install
# Move to example directory
cd react-matchmedia-connect/examples/simple
npm install
npm start

Tests

# Make sure that you've installed the dependencies
npm install
# Run tests
npm test

Code Coverage

# Run code coverage. Results can be found in `./coverage`
npm run test:cov

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].