1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.useLocaleReceiver = exports["default"] = void 0;
|
9 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _context = _interopRequireDefault(require("./context"));
|
12 | var _en_US = _interopRequireDefault(require("../locale/en_US"));
|
13 | var LocaleReceiver = function LocaleReceiver(props) {
|
14 | var _props$componentName = props.componentName,
|
15 | componentName = _props$componentName === void 0 ? 'global' : _props$componentName,
|
16 | defaultLocale = props.defaultLocale,
|
17 | children = props.children;
|
18 | var antLocale = React.useContext(_context["default"]);
|
19 | var getLocale = React.useMemo(function () {
|
20 | var _a;
|
21 | var locale = defaultLocale || _en_US["default"][componentName];
|
22 | var localeFromContext = (_a = antLocale === null || antLocale === void 0 ? void 0 : antLocale[componentName]) !== null && _a !== void 0 ? _a : {};
|
23 | return (0, _extends2["default"])((0, _extends2["default"])({}, locale instanceof Function ? locale() : locale), localeFromContext || {});
|
24 | }, [componentName, defaultLocale, antLocale]);
|
25 | var getLocaleCode = React.useMemo(function () {
|
26 | var localeCode = antLocale && antLocale.locale;
|
27 |
|
28 | if (antLocale && antLocale.exist && !localeCode) {
|
29 | return _en_US["default"].locale;
|
30 | }
|
31 | return localeCode;
|
32 | }, [antLocale]);
|
33 | return children(getLocale, getLocaleCode, antLocale);
|
34 | };
|
35 | var _default = LocaleReceiver;
|
36 | exports["default"] = _default;
|
37 | var useLocaleReceiver = function useLocaleReceiver(componentName, defaultLocale) {
|
38 | var antLocale = React.useContext(_context["default"]);
|
39 | var getLocale = React.useMemo(function () {
|
40 | var _a;
|
41 | var locale = defaultLocale || _en_US["default"][componentName];
|
42 | var localeFromContext = (_a = antLocale === null || antLocale === void 0 ? void 0 : antLocale[componentName]) !== null && _a !== void 0 ? _a : {};
|
43 | return (0, _extends2["default"])((0, _extends2["default"])({}, typeof locale === 'function' ? locale() : locale), localeFromContext || {});
|
44 | }, [componentName, defaultLocale, antLocale]);
|
45 | return [getLocale];
|
46 | };
|
47 | exports.useLocaleReceiver = useLocaleReceiver; |
\ | No newline at end of file |