UNPKG

@alifd/next

Version:

A configurable component library for web built on React.

89 lines (77 loc) 2.17 kB
'use strict'; exports.__esModule = true; var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Creates an object with the same values as object and keys * generated by running each own enumerable string keyed property * of object thru iteratee. * @param {Object} obj * @param {Function} fn * @return {Object} */ var mapKeys = function mapKeys(obj, fn) { var result = {}; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var value = obj[key]; var newKey = fn(key, value); result[newKey] = value; } } return result; }; /** * Replace specific key with prefix `next` * and lowercase first character of the result. * @param {String} key * @return {String} */ var replaceKey = function replaceKey(key) { return key.replace(/^(next)([A-Z])/, function (match, p1, p2) { return p2.toLowerCase(); }); }; /** * @param {Object} source * @return {Object} */ var transformContext = function transformContext(source) { return mapKeys(source, replaceKey); }; /** * Consumer * @param {Object} prop * @param {Object} context */ var Consumer = function Consumer(_ref, context) { var children = _ref.children; return typeof children === 'function' ? children(transformContext(context)) : null; }; /** * PropTypes * @type {Object} * @static */ Consumer.propTypes = { // Render context as function // Function(context: object): ReactElement children: _propTypes2.default.func }; /** * ContextTypes (legacy context) * @type {Object} * @static */ Consumer.contextTypes = { nextPrefix: _propTypes2.default.string, nextLocale: _propTypes2.default.object, nextPure: _propTypes2.default.bool, newRtl: _propTypes2.default.bool, nextWarning: _propTypes2.default.bool, nextDevice: _propTypes2.default.oneOf(['tablet', 'desktop', 'phone']), nextPopupContainer: _propTypes2.default.any }; exports.default = Consumer; module.exports = exports['default'];