@arcblock/ux 2.1.32 → 2.1.33
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.
- package/lib/Locale/selector.js +34 -12
- package/package.json +4 -4
- package/src/Locale/selector.js +35 -5
package/lib/Locale/selector.js
CHANGED
|
@@ -41,7 +41,7 @@ var _globeLight = _interopRequireDefault(require("./images/globe-light.png"));
|
|
|
41
41
|
|
|
42
42
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
43
43
|
|
|
44
|
-
const _excluded = ["dark", "showText", "popperProps"];
|
|
44
|
+
const _excluded = ["dark", "showText", "popperProps", "popperType", "icon"];
|
|
45
45
|
|
|
46
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
47
|
|
|
@@ -59,7 +59,9 @@ function LocaleSelector(props) {
|
|
|
59
59
|
const {
|
|
60
60
|
dark,
|
|
61
61
|
showText,
|
|
62
|
-
popperProps
|
|
62
|
+
popperProps,
|
|
63
|
+
popperType,
|
|
64
|
+
icon: Icon
|
|
63
65
|
} = props,
|
|
64
66
|
rest = _objectWithoutProperties(props, _excluded);
|
|
65
67
|
|
|
@@ -88,23 +90,39 @@ function LocaleSelector(props) {
|
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
const ButtonComponent = showText ? _Button.default : _IconButton.default;
|
|
91
|
-
|
|
93
|
+
const handleEventProps = popperType === 'hover' ? {
|
|
94
|
+
onMouseEnter: () => {
|
|
95
|
+
setOpen(true);
|
|
96
|
+
},
|
|
97
|
+
onMouseLeave: onClose
|
|
98
|
+
} : {
|
|
99
|
+
onClick: () => {
|
|
100
|
+
setOpen(!open);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const renderIcon = (0, _react.useMemo)(() => {
|
|
104
|
+
if (Icon) {
|
|
105
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
109
|
+
src: dark ? _globeDark.default : _globeLight.default,
|
|
110
|
+
className: "trigger-image",
|
|
111
|
+
alt: "globe"
|
|
112
|
+
});
|
|
113
|
+
}, [Icon, dark]);
|
|
114
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Div, _objectSpread(_objectSpread(_objectSpread({
|
|
92
115
|
component: "div",
|
|
93
116
|
dark: dark,
|
|
94
117
|
theme: theme
|
|
95
|
-
}, rest), {}, {
|
|
118
|
+
}, rest), handleEventProps), {}, {
|
|
96
119
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ButtonComponent, {
|
|
97
120
|
ref: anchorEl,
|
|
98
121
|
className: "trigger",
|
|
99
|
-
onClick: () => setOpen(!open),
|
|
100
122
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
101
123
|
display: "flex",
|
|
102
124
|
alignItems: "center",
|
|
103
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
104
|
-
src: dark ? _globeDark.default : _globeLight.default,
|
|
105
|
-
className: "trigger-image",
|
|
106
|
-
alt: "globe"
|
|
107
|
-
}), showText ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
125
|
+
children: [renderIcon, showText ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
108
126
|
component: "strong",
|
|
109
127
|
className: "trigger-text",
|
|
110
128
|
children: _context.languages.find(x => x.value === locale).text
|
|
@@ -146,14 +164,18 @@ LocaleSelector.propTypes = {
|
|
|
146
164
|
size: _propTypes.default.number,
|
|
147
165
|
showText: _propTypes.default.bool,
|
|
148
166
|
popperProps: _propTypes.default.object,
|
|
149
|
-
onChange: _propTypes.default.func
|
|
167
|
+
onChange: _propTypes.default.func,
|
|
168
|
+
popperType: _propTypes.default.oneOf(['hover', 'click']),
|
|
169
|
+
icon: _propTypes.default.any
|
|
150
170
|
};
|
|
151
171
|
LocaleSelector.defaultProps = {
|
|
152
172
|
dark: false,
|
|
153
173
|
showText: true,
|
|
154
174
|
size: 24,
|
|
155
175
|
popperProps: {},
|
|
156
|
-
onChange: () => {}
|
|
176
|
+
onChange: () => {},
|
|
177
|
+
popperType: 'click',
|
|
178
|
+
icon: null
|
|
157
179
|
};
|
|
158
180
|
var _default = LocaleSelector;
|
|
159
181
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.33",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"react": ">=18.1.0",
|
|
53
53
|
"react-ga": "^2.7.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "616c11e20c48d33f153258bcf00eba030dabf648",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/icons": "^2.1.
|
|
58
|
-
"@arcblock/react-hooks": "^2.1.
|
|
57
|
+
"@arcblock/icons": "^2.1.33",
|
|
58
|
+
"@arcblock/react-hooks": "^2.1.33",
|
|
59
59
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
60
60
|
"@emotion/react": "^11.9.0",
|
|
61
61
|
"@emotion/styled": "^11.8.1",
|
package/src/Locale/selector.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable react/jsx-no-bind */
|
|
2
|
-
import { useState, useContext, useRef } from 'react';
|
|
2
|
+
import { useState, useContext, useRef, useMemo } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
|
|
@@ -22,7 +22,7 @@ import globeDark from './images/globe-dark.png';
|
|
|
22
22
|
import globeLight from './images/globe-light.png';
|
|
23
23
|
|
|
24
24
|
function LocaleSelector(props) {
|
|
25
|
-
const { dark, showText, popperProps, ...rest } = props;
|
|
25
|
+
const { dark, showText, popperProps, popperType, icon: Icon, ...rest } = props;
|
|
26
26
|
const { locale, changeLocale } = useContext(LocaleContext);
|
|
27
27
|
const anchorEl = useRef(null);
|
|
28
28
|
const [open, setOpen] = useState(false);
|
|
@@ -43,11 +43,34 @@ function LocaleSelector(props) {
|
|
|
43
43
|
|
|
44
44
|
const ButtonComponent = showText ? Button : IconButton;
|
|
45
45
|
|
|
46
|
+
const handleEventProps =
|
|
47
|
+
popperType === 'hover'
|
|
48
|
+
? {
|
|
49
|
+
onMouseEnter: () => {
|
|
50
|
+
setOpen(true);
|
|
51
|
+
},
|
|
52
|
+
onMouseLeave: onClose,
|
|
53
|
+
}
|
|
54
|
+
: {
|
|
55
|
+
onClick: () => {
|
|
56
|
+
setOpen(!open);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const renderIcon = useMemo(() => {
|
|
61
|
+
if (Icon) {
|
|
62
|
+
return <Icon />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return <img src={dark ? globeDark : globeLight} className="trigger-image" alt="globe" />;
|
|
66
|
+
}, [Icon, dark]);
|
|
67
|
+
|
|
46
68
|
return (
|
|
47
|
-
<Div component="div" dark={dark} theme={theme} {...rest}>
|
|
48
|
-
<ButtonComponent ref={anchorEl} className="trigger"
|
|
69
|
+
<Div component="div" dark={dark} theme={theme} {...rest} {...handleEventProps}>
|
|
70
|
+
<ButtonComponent ref={anchorEl} className="trigger">
|
|
49
71
|
<Box display="flex" alignItems="center">
|
|
50
|
-
|
|
72
|
+
{renderIcon}
|
|
73
|
+
|
|
51
74
|
{showText ? (
|
|
52
75
|
<Typography component="strong" className="trigger-text">
|
|
53
76
|
{languages.find((x) => x.value === locale).text}
|
|
@@ -57,6 +80,7 @@ function LocaleSelector(props) {
|
|
|
57
80
|
)}
|
|
58
81
|
</Box>
|
|
59
82
|
</ButtonComponent>
|
|
83
|
+
|
|
60
84
|
<Popper open={open} anchorEl={anchorEl.current} {...popperProps} disablePortal>
|
|
61
85
|
<div className="locales">
|
|
62
86
|
<ClickAwayListener onClickAway={onClose}>
|
|
@@ -84,6 +108,8 @@ LocaleSelector.propTypes = {
|
|
|
84
108
|
showText: PropTypes.bool,
|
|
85
109
|
popperProps: PropTypes.object,
|
|
86
110
|
onChange: PropTypes.func,
|
|
111
|
+
popperType: PropTypes.oneOf(['hover', 'click']),
|
|
112
|
+
icon: PropTypes.any,
|
|
87
113
|
};
|
|
88
114
|
|
|
89
115
|
LocaleSelector.defaultProps = {
|
|
@@ -92,6 +118,8 @@ LocaleSelector.defaultProps = {
|
|
|
92
118
|
size: 24,
|
|
93
119
|
popperProps: {},
|
|
94
120
|
onChange: () => {},
|
|
121
|
+
popperType: 'click',
|
|
122
|
+
icon: null,
|
|
95
123
|
};
|
|
96
124
|
|
|
97
125
|
export default LocaleSelector;
|
|
@@ -102,10 +130,12 @@ const Div = styled.div`
|
|
|
102
130
|
flex-direction: column;
|
|
103
131
|
justify-content: center;
|
|
104
132
|
font-size: 14px;
|
|
133
|
+
|
|
105
134
|
.trigger-image {
|
|
106
135
|
width: ${(props) => props.size}px;
|
|
107
136
|
height: ${(props) => props.size}px;
|
|
108
137
|
}
|
|
138
|
+
|
|
109
139
|
.trigger-text {
|
|
110
140
|
margin-left: 5px;
|
|
111
141
|
font-size: 14px;
|