@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
41 lines (32 loc) • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withDictionary = withDictionary;
exports.default = exports.DictionaryContext = void 0;
var React = _interopRequireWildcard(require("react"));
var _Translate = require("../Translate");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var DictionaryContext = React.createContext({});
exports.DictionaryContext = DictionaryContext;
var Dictionary = function Dictionary(_ref) {
var values = _ref.values,
children = _ref.children;
return React.createElement(DictionaryContext.Provider, {
value: values
}, children);
};
function withDictionary(Component) {
return function DictionaryComponent(props) {
return React.createElement(DictionaryContext.Consumer, null, function (dictionary) {
return React.createElement(Component, _extends({}, props, {
translate: function translate(tKey, values) {
return (0, _Translate.pureTranslate)(dictionary, tKey, values);
}
}));
});
};
}
var _default = Dictionary;
exports.default = _default;