@arcblock/ux 1.16.15 → 1.16.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.LocaleProvider = LocaleProvider;
7
- exports.useLocaleContext = useLocaleContext;
8
- exports.languages = exports.getLocale = exports.setLocale = exports.LocaleContext = exports.LocaleConsumer = void 0;
6
+ exports.create = exports.languages = exports.getLocale = exports.setLocale = exports.useLocaleContext = exports.LocaleContext = exports.LocaleConsumer = exports.LocaleProvider = void 0;
9
7
 
10
8
  var _react = _interopRequireWildcard(require("react"));
11
9
 
@@ -70,60 +68,78 @@ exports.setLocale = setLocale;
70
68
 
71
69
  const replace = (template, data) => template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
72
70
 
73
- const LocaleContext = /*#__PURE__*/_react.default.createContext();
74
-
75
- exports.LocaleContext = LocaleContext;
76
- const {
77
- Provider,
78
- Consumer
79
- } = LocaleContext;
80
- exports.LocaleConsumer = Consumer;
81
-
82
- function LocaleProvider(_ref) {
83
- let {
84
- children,
85
- locale,
86
- translations
87
- } = _ref,
88
- rest = _objectWithoutProperties(_ref, _excluded);
89
-
90
- const [currentLocale, setCurrentLocale] = (0, _react.useState)(getLocale(locale));
91
- (0, _react.useEffect)(() => {
92
- setLocale(currentLocale);
93
- }, [currentLocale]);
94
-
95
- const changeLocale = newLocale => {
96
- setCurrentLocale(newLocale);
97
- };
71
+ const create = () => {
72
+ const LocaleContext = /*#__PURE__*/_react.default.createContext();
73
+
74
+ const {
75
+ Provider,
76
+ Consumer
77
+ } = LocaleContext;
78
+
79
+ function LocaleProvider(_ref) {
80
+ let {
81
+ children,
82
+ locale,
83
+ translations
84
+ } = _ref,
85
+ rest = _objectWithoutProperties(_ref, _excluded);
86
+
87
+ const [currentLocale, setCurrentLocale] = (0, _react.useState)(getLocale(locale));
88
+ (0, _react.useEffect)(() => {
89
+ setLocale(currentLocale);
90
+ }, [currentLocale]);
91
+
92
+ const changeLocale = newLocale => {
93
+ setCurrentLocale(newLocale);
94
+ };
95
+
96
+ const translate = (key, data) => {
97
+ if (!translations[currentLocale] || !translations[currentLocale][key]) {
98
+ console.warn("Warning: no ".concat(key, " translation of ").concat(currentLocale));
99
+ return key;
100
+ }
101
+
102
+ return replace(translations[currentLocale][key], data);
103
+ };
104
+
105
+ return /*#__PURE__*/_react.default.createElement(Provider, {
106
+ value: _objectSpread({
107
+ locale: currentLocale,
108
+ changeLocale,
109
+ t: translate
110
+ }, rest)
111
+ }, children);
112
+ }
98
113
 
99
- const translate = (key, data) => {
100
- if (!translations[currentLocale] || !translations[currentLocale][key]) {
101
- console.warn("Warning: no ".concat(key, " translation of ").concat(currentLocale));
102
- return key;
103
- }
114
+ function useLocaleContext() {
115
+ const context = (0, _react.useContext)(LocaleContext);
116
+ return context;
117
+ }
104
118
 
105
- return replace(translations[currentLocale][key], data);
119
+ LocaleProvider.propTypes = {
120
+ children: _propTypes.default.any.isRequired,
121
+ translations: _propTypes.default.object.isRequired,
122
+ locale: _propTypes.default.string
123
+ };
124
+ LocaleProvider.defaultProps = {
125
+ locale: ''
126
+ };
127
+ return {
128
+ Consumer,
129
+ LocaleProvider,
130
+ LocaleContext,
131
+ useLocaleContext
106
132
  };
107
-
108
- return /*#__PURE__*/_react.default.createElement(Provider, {
109
- value: _objectSpread({
110
- locale: currentLocale,
111
- changeLocale,
112
- t: translate
113
- }, rest)
114
- }, children);
115
- }
116
-
117
- function useLocaleContext() {
118
- const context = (0, _react.useContext)(LocaleContext);
119
- return context;
120
- }
121
-
122
- LocaleProvider.propTypes = {
123
- children: _propTypes.default.any.isRequired,
124
- translations: _propTypes.default.object.isRequired,
125
- locale: _propTypes.default.string
126
133
  };
127
- LocaleProvider.defaultProps = {
128
- locale: ''
129
- };
134
+
135
+ exports.create = create;
136
+ const {
137
+ Consumer,
138
+ LocaleProvider,
139
+ LocaleContext,
140
+ useLocaleContext
141
+ } = create();
142
+ exports.useLocaleContext = useLocaleContext;
143
+ exports.LocaleContext = LocaleContext;
144
+ exports.LocaleProvider = LocaleProvider;
145
+ exports.LocaleConsumer = Consumer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "1.16.15",
3
+ "version": "1.16.16",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -53,10 +53,10 @@
53
53
  "react": ">=16.12.0",
54
54
  "react-ga": "^2.7.0"
55
55
  },
56
- "gitHead": "34ef9d96c3a84d9f2ee694f5bfe89eca22450e48",
56
+ "gitHead": "91f4d85a39882abbb825e38fdc740617ea3e3ee5",
57
57
  "dependencies": {
58
- "@arcblock/icons": "^1.16.15",
59
- "@arcblock/react-hooks": "^1.16.15",
58
+ "@arcblock/icons": "^1.16.16",
59
+ "@arcblock/react-hooks": "^1.16.16",
60
60
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
61
61
  "@material-ui/core": "^4.12.3",
62
62
  "@material-ui/icons": "4.11.2",
@@ -32,50 +32,55 @@ const setLocale = locale => Cookie.set(cookieName, locale, getCookieOptions());
32
32
  const replace = (template, data) =>
33
33
  template.replace(/{(\w*)}/g, (m, key) => (data.hasOwnProperty(key) ? data[key] : ''));
34
34
 
35
- const LocaleContext = React.createContext();
36
- const { Provider, Consumer } = LocaleContext;
37
-
38
- function LocaleProvider({ children, locale, translations, ...rest }) {
39
- const [currentLocale, setCurrentLocale] = useState(getLocale(locale));
35
+ const create = () => {
36
+ const LocaleContext = React.createContext();
37
+ const { Provider, Consumer } = LocaleContext;
38
+ function LocaleProvider({ children, locale, translations, ...rest }) {
39
+ const [currentLocale, setCurrentLocale] = useState(getLocale(locale));
40
+
41
+ useEffect(() => {
42
+ setLocale(currentLocale);
43
+ }, [currentLocale]);
44
+
45
+ const changeLocale = newLocale => {
46
+ setCurrentLocale(newLocale);
47
+ };
48
+
49
+ const translate = (key, data) => {
50
+ if (!translations[currentLocale] || !translations[currentLocale][key]) {
51
+ console.warn(`Warning: no ${key} translation of ${currentLocale}`);
52
+ return key;
53
+ }
54
+
55
+ return replace(translations[currentLocale][key], data);
56
+ };
57
+
58
+ return (
59
+ <Provider value={{ locale: currentLocale, changeLocale, t: translate, ...rest }}>
60
+ {children}
61
+ </Provider>
62
+ );
63
+ }
40
64
 
41
- useEffect(() => {
42
- setLocale(currentLocale);
43
- }, [currentLocale]);
65
+ function useLocaleContext() {
66
+ const context = useContext(LocaleContext);
67
+ return context;
68
+ }
44
69
 
45
- const changeLocale = newLocale => {
46
- setCurrentLocale(newLocale);
70
+ LocaleProvider.propTypes = {
71
+ children: PropTypes.any.isRequired,
72
+ translations: PropTypes.object.isRequired,
73
+ locale: PropTypes.string,
47
74
  };
48
75
 
49
- const translate = (key, data) => {
50
- if (!translations[currentLocale] || !translations[currentLocale][key]) {
51
- console.warn(`Warning: no ${key} translation of ${currentLocale}`);
52
- return key;
53
- }
54
-
55
- return replace(translations[currentLocale][key], data);
76
+ LocaleProvider.defaultProps = {
77
+ locale: '',
56
78
  };
57
79
 
58
- return (
59
- <Provider value={{ locale: currentLocale, changeLocale, t: translate, ...rest }}>
60
- {children}
61
- </Provider>
62
- );
63
- }
64
-
65
- function useLocaleContext() {
66
- const context = useContext(LocaleContext);
67
- return context;
68
- }
69
-
70
- LocaleProvider.propTypes = {
71
- children: PropTypes.any.isRequired,
72
- translations: PropTypes.object.isRequired,
73
- locale: PropTypes.string,
80
+ return { Consumer, LocaleProvider, LocaleContext, useLocaleContext };
74
81
  };
75
82
 
76
- LocaleProvider.defaultProps = {
77
- locale: '',
78
- };
83
+ const { Consumer, LocaleProvider, LocaleContext, useLocaleContext } = create();
79
84
 
80
85
  export {
81
86
  LocaleProvider,
@@ -85,4 +90,5 @@ export {
85
90
  setLocale,
86
91
  getLocale,
87
92
  languages,
93
+ create,
88
94
  };