UNPKG

qt-public-ui

Version:

新设计规范下业务组件库

48 lines 1.91 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; /* eslint-disable */ import * as React from 'react'; import * as PropTypes from 'prop-types'; import defaultLocaleData from './default'; var LocaleReceiver = /*#__PURE__*/function (_React$Component) { function LocaleReceiver() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this; _this.context = void 0; return _this; } _inheritsLoose(LocaleReceiver, _React$Component); var _proto = LocaleReceiver.prototype; _proto.getLocale = function getLocale() { var _this$props = this.props, componentName = _this$props.componentName, defaultLocale = _this$props.defaultLocale; var locale = defaultLocale || defaultLocaleData[componentName || 'global']; var antLocale = this.context.antLocale; var localeFromContext = componentName && antLocale ? antLocale[componentName] : {}; return _extends({}, typeof locale === 'function' ? locale() : locale, localeFromContext || {}); }; _proto.getLocaleCode = function getLocaleCode() { var antLocale = this.context.antLocale; var localeCode = antLocale && antLocale.locale; // Had use LocaleProvide but didn't set locale if (antLocale && antLocale.exist && !localeCode) { return defaultLocaleData.locale; } return localeCode; }; _proto.render = function render() { return this.props.children(this.getLocale(), this.getLocaleCode(), this.context.antLocale); }; return LocaleReceiver; }(React.Component); LocaleReceiver.defaultProps = { componentName: 'global' }; LocaleReceiver.contextTypes = { antLocale: PropTypes.object }; export { LocaleReceiver as default };