@alifd/next
Version:
A configurable component library for web built on React.
57 lines (56 loc) • 1.74 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var prop_types_1 = tslib_1.__importDefault(require("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: prop_types_1.default.func,
};
/**
* ContextTypes (legacy context)
*/
Consumer.contextTypes = {
nextPrefix: prop_types_1.default.string,
nextLocale: prop_types_1.default.object,
nextPure: prop_types_1.default.bool,
newRtl: prop_types_1.default.bool,
nextWarning: prop_types_1.default.bool,
nextDevice: prop_types_1.default.oneOf(['tablet', 'desktop', 'phone']),
nextPopupContainer: prop_types_1.default.any,
};
exports.default = Consumer;