1 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | 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); }
|
4 |
|
5 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6 |
|
7 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
8 |
|
9 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
10 |
|
11 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
12 |
|
13 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
14 |
|
15 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
16 |
|
17 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
18 |
|
19 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
20 |
|
21 | import * as React from 'react';
|
22 | import * as PropTypes from 'prop-types';
|
23 | import * as moment from 'moment';
|
24 | import interopDefault from '../_util/interopDefault';
|
25 | import { changeConfirmLocale } from '../modal/locale';
|
26 | import warning from '../_util/warning';
|
27 | export var ANT_MARK = 'internalMark';
|
28 |
|
29 | function setMomentLocale(locale) {
|
30 | if (locale && locale.locale) {
|
31 | interopDefault(moment).locale(locale.locale);
|
32 | } else {
|
33 | interopDefault(moment).locale('en');
|
34 | }
|
35 | }
|
36 |
|
37 | var LocaleProvider =
|
38 |
|
39 | function (_React$Component) {
|
40 | _inherits(LocaleProvider, _React$Component);
|
41 |
|
42 | function LocaleProvider(props) {
|
43 | var _this;
|
44 |
|
45 | _classCallCheck(this, LocaleProvider);
|
46 |
|
47 | _this = _possibleConstructorReturn(this, _getPrototypeOf(LocaleProvider).call(this, props));
|
48 | setMomentLocale(props.locale);
|
49 | changeConfirmLocale(props.locale && props.locale.Modal);
|
50 | warning(props._ANT_MARK__ === ANT_MARK, 'LocaleProvider', '`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale');
|
51 | return _this;
|
52 | }
|
53 |
|
54 | _createClass(LocaleProvider, [{
|
55 | key: "getChildContext",
|
56 | value: function getChildContext() {
|
57 | return {
|
58 | antLocale: _extends(_extends({}, this.props.locale), {
|
59 | exist: true
|
60 | })
|
61 | };
|
62 | }
|
63 | }, {
|
64 | key: "componentDidUpdate",
|
65 | value: function componentDidUpdate(prevProps) {
|
66 | var locale = this.props.locale;
|
67 |
|
68 | if (prevProps.locale !== locale) {
|
69 | setMomentLocale(locale);
|
70 | changeConfirmLocale(locale && locale.Modal);
|
71 | }
|
72 | }
|
73 | }, {
|
74 | key: "componentWillUnmount",
|
75 | value: function componentWillUnmount() {
|
76 | changeConfirmLocale();
|
77 | }
|
78 | }, {
|
79 | key: "render",
|
80 | value: function render() {
|
81 | return this.props.children;
|
82 | }
|
83 | }]);
|
84 |
|
85 | return LocaleProvider;
|
86 | }(React.Component);
|
87 |
|
88 | export { LocaleProvider as default };
|
89 | LocaleProvider.propTypes = {
|
90 | locale: PropTypes.object
|
91 | };
|
92 | LocaleProvider.defaultProps = {
|
93 | locale: {}
|
94 | };
|
95 | LocaleProvider.childContextTypes = {
|
96 | antLocale: PropTypes.object
|
97 | };
|
98 |
|