UNPKG

@alifd/next

Version:

A configurable component library for web built on React.

54 lines (53 loc) 1.51 kB
import PropTypes from 'prop-types'; /** * Creates an object with the same values as object and keys * generated by running each own enumerable string keyed property * of object thru iteratee. */ var mapKeys = function (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. */ var replaceKey = function (key) { return key.replace(/^(next)([A-Z])/, function (match, p1, p2) { return p2.toLowerCase(); }); }; var transformContext = function (source) { return mapKeys(source, replaceKey); }; /** * Consumer */ var Consumer = function (_a, context) { var children = _a.children; return typeof children === 'function' ? children(transformContext(context)) : null; }; /** * PropTypes */ Consumer.propTypes = { // Render context as function // Function(context: object): ReactElement children: PropTypes.func, }; /** * ContextTypes (legacy context) */ Consumer.contextTypes = { nextPrefix: PropTypes.string, nextLocale: PropTypes.object, nextPure: PropTypes.bool, newRtl: PropTypes.bool, nextWarning: PropTypes.bool, nextDevice: PropTypes.oneOf(['tablet', 'desktop', 'phone']), nextPopupContainer: PropTypes.any, }; export default Consumer;