All Projects → renatorib → React Bps

renatorib / React Bps

🔱 Create breakpoints to your component props

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Bps

react-table-hoc-draggable-columns
ReactTable HOC for draggable columns
Stars: ✭ 27 (-57.81%)
Mutual labels:  higher-order-component, hoc
react-example-paginated-list-infinite-scroll
Follow a React tutorial series with three parts to build a powerful component in React.
Stars: ✭ 43 (-32.81%)
Mutual labels:  react-component, higher-order-component
griding
🧱 lean grid & responsive for react
Stars: ✭ 18 (-71.87%)
Mutual labels:  responsive, react-component
rrx
⚛️ Minimal React router using higher order components
Stars: ✭ 69 (+7.81%)
Mutual labels:  higher-order-component, hoc
Shouldcomponentupdate Children
React "Shallow Equal" HOC implementation to optimize shouldComponentUpdate with children / React elements 🐇➰
Stars: ✭ 272 (+325%)
Mutual labels:  hoc, props
react-notification-alert
React bootstrap 4 notification alert
Stars: ✭ 34 (-46.87%)
Mutual labels:  responsive, react-component
react-drip-form
☕ HoC based React forms state manager, Support for validation and normalization.
Stars: ✭ 66 (+3.13%)
Mutual labels:  higher-order-component, hoc
React Nprogress
⌛️ A React primitive for building slim progress bars.
Stars: ✭ 173 (+170.31%)
Mutual labels:  higher-order-component, hoc
Seapig
🌊🐷 Utility for generalized composition of React components
Stars: ✭ 269 (+320.31%)
Mutual labels:  props, react-component
react-tabllist
React-based customizable style table or list components that support event and callback functions.
Stars: ✭ 20 (-68.75%)
Mutual labels:  react-component, props
redux-autoloader
A higher order component for declarative data loading in React and Redux.
Stars: ✭ 56 (-12.5%)
Mutual labels:  react-component, higher-order-component
React Sizes
↔️ Hoc to easily map window sizes to props.
Stars: ✭ 726 (+1034.38%)
Mutual labels:  hoc, responsive
react-app-loader
Production ready library for handling Microfrontends
Stars: ✭ 75 (+17.19%)
Mutual labels:  higher-order-component, hoc
react-super-styled
Responsive JSX layouts with Styled Components
Stars: ✭ 77 (+20.31%)
Mutual labels:  responsive, react-component
React With Direction
Components to provide and consume RTL or LTR direction in React
Stars: ✭ 176 (+175%)
Mutual labels:  higher-order-component, hoc
react-animation-frame
A React higher-order component that invokes a callback in a wrapped component via requestAnimationFrame
Stars: ✭ 47 (-26.56%)
Mutual labels:  higher-order-component, hoc
Hocs
🍱 Higher-Order Components for React
Stars: ✭ 1,784 (+2687.5%)
Mutual labels:  higher-order-component, hoc
Neoform
✅ React form state management and validation
Stars: ✭ 162 (+153.13%)
Mutual labels:  higher-order-component, hoc
addhoc
Handy little helper to create proper React HOC functions complete with hoisted statics and forwarded refs
Stars: ✭ 40 (-37.5%)
Mutual labels:  higher-order-component, hoc
Recompact
⚛ A set of React higher-order components utilities. Drop-in replacement for recompose.
Stars: ✭ 419 (+554.69%)
Mutual labels:  higher-order-component, hoc

react-bps

npm npm GitHub issues GitHub stars Twitter

🔱 Create breakpoints to your component props


React Bpswhere bps means breakpoints – is a small and zero-config HOC that enable you to pass breakpoints to your component based on window width size.
It uses react-sizes to automatically track window width for you.

React Bps was heavily inspired by Ken Wheeler's Slick "responsive display" pattern.

Play with live examples on CodeSandBox

You can follow me on twitter to stay connected in the news of react-bps and other projects of mine


How to use

Create your component and attach withBps HOC

// Slider.jsx
import React from 'react'
import { withBps } from 'react-bps'

// create your component normally
const Slider = ({ arrows, itemsPerSlide }) => (
  /* all slider comp logic */
)

export default withBps()(Slider)

And now you can use bps prop additionally in your component

// App.jsx
import React from 'react'
import { render } from 'react-dom'
import Slider from './Slider'

const App = () => (
  <Slider
    arrows={true} itemsPerSlide={3}
    bps={{ 600: { arrows: false, itemsPerSlide: 1 } }}
  >
    <div>Slide1</div>
    <div>Slide2</div>
    <div>Slide3</div>
  </Slider>
)

render(<App />, document.getElementById('root))

In this example your <Slider> will normally receive this props: { arrow: true, itemsPerSlide: 3 }
But if window width is smaller (or equal) than 600, so it will reflect this props: { arrow: false, itemsPerSlide: 1 } by overwriting.

In order to facilitate you can do something like this:

const bps = {
  600: {
    arrows: false,
    itemsPerSlide: 1,
  }
}

<Slider arrows={true} itemsPerSlide={3} bps={bps}>
  <div>Slide1</div>
  <div>Slide2</div>
  <div>Slide3</div>
</Slider>

Or this:

const bps = {
  600: {
    arrows: false,
    itemsPerSlide: 1,
  }
}

const sliderConfig = {
  arrows: true,
  itemsPerSlide: 1,
  bps,
}

<Slider {...sliderConfg}>
  <div>Slide1</div>
  <div>Slide2</div>
  <div>Slide3</div>
</Slider>

In fact it's up to you.

Creating breakpoints

You can create as many breakpoints as you want, just pass the width and the config.
The config will be overwritted into your props, so if you pass a empty object this will not change existing props.

const bps = {
  1000: {},
  700: { a: 2 },
  500: { a: 2, b: false },
}

<Foo a={1} b={2} bps={bps} />

// in width <= 1000px will reflect:
<Foo a={1} b={2} />

// width <= 700px
<Foo a={2} b={2} />

// width <= 500px
<Foo a={2} b={false} />

Mobile first strategy

By default, the rules are applied by desktop first strategy.
If you want to use mobile first strategy, you can pass by a configuration

withBps({ mobileFirst: true })(Component)

This way, the rules will be applied when width are higher or equals than setted breakpoint.

Change prop bps

You can chose the name you want as prop to override bps by a propName config

withBps({ propName: 'breakpoints' })(Component)
<Foo a={1} b={2} breakpoints={{ /* my breakpoints rules */ }} />

Install

Node Module

yarn add react-bps
npm i react-bps

UMD library

<script src="https://unpkg.com/react-bps/dist/react-bps.min.js"></script>

exposed as ReactBps

Contribute

You can help improving this project sending PRs and helping with issues.
Also you can ping me at Twitter

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].