UNPKG

react-bps

Version:

Create breakpoints to your component props

38 lines (28 loc) 1.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _reactSizes = require('react-sizes'); var _reactSizes2 = _interopRequireDefault(_reactSizes); var _utils = require('./utils'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var getBreakpointsProps = function getBreakpointsProps(width, breakpoints, mobileFirst) { var getPropsByKey = function getPropsByKey(key) { return key && breakpoints[key] || {}; }; return (0, _utils.pipe)(_utils.keys, (0, _utils.map)(Number), (0, _utils.filter)((mobileFirst ? _utils.gte : _utils.lte)(width)), (0, _utils.sort)(mobileFirst ? _utils.desc : _utils.asc), _utils.head, getPropsByKey)(breakpoints); }; var withBps = function withBps() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$propName = _ref.propName, propName = _ref$propName === undefined ? 'bps' : _ref$propName, _ref$mobileFirst = _ref.mobileFirst, mobileFirst = _ref$mobileFirst === undefined ? false : _ref$mobileFirst; return (0, _reactSizes2.default)(function (_ref2, _ref3) { var width = _ref2.width; var _ref3$propName = _ref3[propName], breakpoints = _ref3$propName === undefined ? {} : _ref3$propName; return getBreakpointsProps(width, breakpoints, mobileFirst); }); }; exports.default = withBps;