Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/apaleslimghost/react-element-breakpoints

Element Queries in React, using the ResizeObserver polyfill.
https://github.com/apaleslimghost/react-element-breakpoints

css element-queries react resize-observer styled-components

Last synced: 19 days ago
JSON representation

Element Queries in React, using the ResizeObserver polyfill.

Awesome Lists containing this project

README

        

react-element-breakpoints
===

A higher-order-component for Element Queries in React, using the ResizeObserver polyfill.

usage
---

```js
import {withBreakpoints, bp} from 'react-element-breakpoints';

const FancyHeader = withBreakpoints({
wide: ({width}) => width >= 400,
tall: ({height}) => height >= 200,
})(props =>


It works!

);
```

The breakpoint functions are called with the `contentRect` from the ResizeObserver entry, which contains `left`, `top`, `right`, `bottom`, `width` and `height`.

### with styled-components

The `bp` helper works well with styled-components:

```js
const FancyHeader = withBreakpoints({
wide: ({width}) => width >= 400,
tall: ({height}) => height >= 200,
})(styled.h1`
font-size: ${bp('18px', {
wide: '30px'
})},

color: ${bp('black', {tall: 'red'})},
`);
```