{"id":13432141,"url":"https://github.com/renatorib/react-bps","last_synced_at":"2025-04-13T10:02:45.343Z","repository":{"id":57332951,"uuid":"104380630","full_name":"renatorib/react-bps","owner":"renatorib","description":":trident: Create breakpoints to your component props","archived":false,"fork":false,"pushed_at":"2017-09-23T01:08:58.000Z","size":36,"stargazers_count":62,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T01:22:50.463Z","etag":null,"topics":["bps","breakpoints","higher-order-component","hoc","props","react","react-component","reactjs","responsive"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renatorib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-21T17:53:59.000Z","updated_at":"2025-02-11T15:49:41.000Z","dependencies_parsed_at":"2022-08-24T18:31:51.218Z","dependency_job_id":null,"html_url":"https://github.com/renatorib/react-bps","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatorib%2Freact-bps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatorib%2Freact-bps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatorib%2Freact-bps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatorib%2Freact-bps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renatorib","download_url":"https://codeload.github.com/renatorib/react-bps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248695327,"owners_count":21146953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bps","breakpoints","higher-order-component","hoc","props","react","react-component","reactjs","responsive"],"created_at":"2024-07-31T02:01:08.890Z","updated_at":"2025-04-13T10:02:45.308Z","avatar_url":"https://github.com/renatorib.png","language":"JavaScript","readme":"![react-bps](./logo.png)\n\n[![npm](https://img.shields.io/npm/v/react-bps.svg?style=flat-square)](https://www.npmjs.com/package/react-bps)\n[![npm](https://img.shields.io/npm/dt/react-bps.svg?style=flat-square)](https://www.npmjs.com/package/react-bps)\n[![GitHub issues](https://img.shields.io/github/issues/renatorib/react-bps.svg?style=flat-square)](https://github.com/renatorib/react-bps/issues)\n[![GitHub stars](https://img.shields.io/github/stars/renatorib/react-bps.svg?style=flat-square)](https://github.com/renatorib/react-bps/stargazers)\n[![Twitter](https://img.shields.io/twitter/url/https/github.com/renatorib/react-bps.svg?style=social\u0026style=flat-square)](https://twitter.com/intent/tweet?url=https://github.com/renatorib/react-bps)\n\n:trident: Create breakpoints to your component props\n\n---\n\n**React Bps** – *where bps means **breakpoints*** – is a small and zero-config HOC that enable you to pass breakpoints to your component based on window width size.  \nIt uses [react-sizes](http://github.com/renatorib/react-sizes) to automatically track window width for you.\n\nReact Bps was heavily inspired by Ken Wheeler's [Slick](http://kenwheeler.github.io/slick/) \"responsive display\" pattern.\n\n[Play with live examples on CodeSandBox](https://codesandbox.io/s/zk04n4m2jp)\n\n\u003e *You can [follow me on twitter](http://twitter.com/renatorib_) to stay connected in the news of react-bps and other projects of mine*\n\n---\n\n# How to use\n\nCreate your component and attach **withBps** HOC\n```jsx\n// Slider.jsx\nimport React from 'react'\nimport { withBps } from 'react-bps'\n\n// create your component normally\nconst Slider = ({ arrows, itemsPerSlide }) =\u003e (\n  /* all slider comp logic */\n)\n\nexport default withBps()(Slider)\n```\n\nAnd now you can use `bps` prop additionally in your component\n```jsx\n// App.jsx\nimport React from 'react'\nimport { render } from 'react-dom'\nimport Slider from './Slider'\n\nconst App = () =\u003e (\n  \u003cSlider\n    arrows={true} itemsPerSlide={3}\n    bps={{ 600: { arrows: false, itemsPerSlide: 1 } }}\n  \u003e\n    \u003cdiv\u003eSlide1\u003c/div\u003e\n    \u003cdiv\u003eSlide2\u003c/div\u003e\n    \u003cdiv\u003eSlide3\u003c/div\u003e\n  \u003c/Slider\u003e\n)\n\nrender(\u003cApp /\u003e, document.getElementById('root))\n```\n\nIn this example your `\u003cSlider\u003e` will normally receive this props: `{ arrow: true, itemsPerSlide: 3 }`  \nBut if *window width is smaller (or equal) than **600***, so it will reflect this props: `{ arrow: false, itemsPerSlide: 1 }`\nby **overwriting**.\n\nIn order to facilitate you can do something like this:\n```jsx\nconst bps = {\n  600: {\n    arrows: false,\n    itemsPerSlide: 1,\n  }\n}\n\n\u003cSlider arrows={true} itemsPerSlide={3} bps={bps}\u003e\n  \u003cdiv\u003eSlide1\u003c/div\u003e\n  \u003cdiv\u003eSlide2\u003c/div\u003e\n  \u003cdiv\u003eSlide3\u003c/div\u003e\n\u003c/Slider\u003e\n```\n\nOr this:\n```jsx\nconst bps = {\n  600: {\n    arrows: false,\n    itemsPerSlide: 1,\n  }\n}\n\nconst sliderConfig = {\n  arrows: true,\n  itemsPerSlide: 1,\n  bps,\n}\n\n\u003cSlider {...sliderConfg}\u003e\n  \u003cdiv\u003eSlide1\u003c/div\u003e\n  \u003cdiv\u003eSlide2\u003c/div\u003e\n  \u003cdiv\u003eSlide3\u003c/div\u003e\n\u003c/Slider\u003e\n```\n\nIn fact it's up to you.\n\n# Creating breakpoints\n\nYou can create as many breakpoints as you want, just pass the width and the config.  \nThe config will be overwritted into your props, so if you pass a empty object this\nwill not change existing props.\n\n```jsx\nconst bps = {\n  1000: {},\n  700: { a: 2 },\n  500: { a: 2, b: false },\n}\n\n\u003cFoo a={1} b={2} bps={bps} /\u003e\n\n// in width \u003c= 1000px will reflect:\n\u003cFoo a={1} b={2} /\u003e\n\n// width \u003c= 700px\n\u003cFoo a={2} b={2} /\u003e\n\n// width \u003c= 500px\n\u003cFoo a={2} b={false} /\u003e\n```\n\n# Mobile first strategy\n\nBy default, the rules are applied by desktop first strategy.  \nIf you want to use mobile first strategy, you can pass by a configuration\n\n```js\nwithBps({ mobileFirst: true })(Component)\n```\n\nThis way, the rules will be applied when width are higher or equals than setted breakpoint.\n\n# Change prop `bps`\n\nYou can chose the name you want as prop to override `bps` by a `propName` config\n\n```js\nwithBps({ propName: 'breakpoints' })(Component)\n```\n\n```jsx\n\u003cFoo a={1} b={2} breakpoints={{ /* my breakpoints rules */ }} /\u003e\n```\n\n# Install\n\n### Node Module\n```\nyarn add react-bps\n```\n```\nnpm i react-bps\n```\n\n### UMD library\n```html\n\u003cscript src=\"https://unpkg.com/react-bps/dist/react-bps.min.js\"\u003e\u003c/script\u003e\n```\nexposed as `ReactBps`\n\n# Contribute\n\nYou can help improving this project sending PRs and helping with issues.  \nAlso you can ping me at [Twitter](http://twitter.com/renatorib_)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenatorib%2Freact-bps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenatorib%2Freact-bps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenatorib%2Freact-bps/lists"}