@arcblock/ux 2.0.1 → 2.0.4

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.
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = RelativeTime;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));
13
+
14
+ var _dayjs = _interopRequireDefault(require("dayjs"));
15
+
16
+ require("dayjs/locale/zh-cn");
17
+
18
+ var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
19
+
20
+ var _localizedFormat = _interopRequireDefault(require("dayjs/plugin/localizedFormat"));
21
+
22
+ var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
23
+
24
+ var _timezone = _interopRequireDefault(require("dayjs/plugin/timezone"));
25
+
26
+ var _Util = require("../Util");
27
+
28
+ const _excluded = ["value", "locale"];
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+
34
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
+
36
+ _dayjs.default.extend(_localizedFormat.default);
37
+
38
+ _dayjs.default.extend(_utc.default);
39
+
40
+ _dayjs.default.extend(_timezone.default);
41
+
42
+ _dayjs.default.extend(_relativeTime.default);
43
+
44
+ (0, _Util.setDateTool)(_dayjs.default);
45
+
46
+ function RelativeTime(_ref) {
47
+ let {
48
+ value,
49
+ locale
50
+ } = _ref,
51
+ rest = _objectWithoutProperties(_ref, _excluded);
52
+
53
+ if (!value) {
54
+ return '-';
55
+ }
56
+
57
+ const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
58
+ const innerContent = (0, _dayjs.default)().locale(localeOption).to(value);
59
+ return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
60
+ title: (0, _Util.formatToDatetime)(value, {
61
+ locale: localeOption
62
+ }),
63
+ placement: "top-end",
64
+ enterTouchDelay: 0
65
+ }, /*#__PURE__*/_react.default.createElement("span", rest, innerContent));
66
+ }
67
+
68
+ RelativeTime.propTypes = {
69
+ value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
70
+ locale: _propTypes.default.string
71
+ };
72
+ RelativeTime.defaultProps = {
73
+ value: '',
74
+ locale: 'en'
75
+ };
@@ -9,14 +9,13 @@ var _react = _interopRequireDefault(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
- var _styles = require("@mui/styles");
12
+ var _styles = require("@mui/material/styles");
13
13
 
14
14
  var _FormControlLabel = _interopRequireDefault(require("@mui/material/FormControlLabel"));
15
15
 
16
16
  var _Switch = _interopRequireDefault(require("@mui/material/Switch"));
17
17
 
18
- const _excluded = ["classes"],
19
- _excluded2 = ["labelProps"];
18
+ const _excluded = ["labelProps"];
20
19
 
21
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
21
 
@@ -24,62 +23,59 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
24
23
 
25
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
26
25
 
27
- // 参考: https://v4.mui.com/components/switches/
28
- const IOSSwitch = (0, _styles.withStyles)(theme => ({
29
- root: {
26
+ // 参考: https://mui.com/material-ui/react-switch/#customization
27
+ const IOSSwitch = (0, _styles.styled)(props => /*#__PURE__*/_react.default.createElement(_Switch.default, Object.assign({
28
+ focusVisibleClassName: ".Mui-focusVisible",
29
+ disableRipple: true
30
+ }, props)))(_ref => {
31
+ let {
32
+ theme
33
+ } = _ref;
34
+ return {
30
35
  width: 42,
31
36
  height: 26,
32
37
  padding: 0,
33
- margin: theme.spacing(1)
34
- },
35
- switchBase: {
36
- padding: 1,
37
- '&$checked': {
38
- transform: 'translateX(16px)',
39
- color: theme.palette.common.white,
40
- '& + $track': {
41
- backgroundColor: '#52d869',
42
- opacity: 1,
43
- border: 'none'
38
+ '& .MuiSwitch-switchBase': {
39
+ padding: 0,
40
+ margin: 2,
41
+ transitionDuration: '300ms',
42
+ '&.Mui-checked': {
43
+ transform: 'translateX(16px)',
44
+ color: '#fff',
45
+ '& + .MuiSwitch-track': {
46
+ backgroundColor: theme.palette.mode === 'dark' ? '#2ECA45' : '#65C466',
47
+ opacity: 1,
48
+ border: 0
49
+ },
50
+ '&.Mui-disabled + .MuiSwitch-track': {
51
+ opacity: 0.5
52
+ }
53
+ },
54
+ '&.Mui-focusVisible .MuiSwitch-thumb': {
55
+ color: '#33cf4d',
56
+ border: '6px solid #fff'
57
+ },
58
+ '&.Mui-disabled .MuiSwitch-thumb': {
59
+ color: theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[600]
60
+ },
61
+ '&.Mui-disabled + .MuiSwitch-track': {
62
+ opacity: theme.palette.mode === 'light' ? 0.7 : 0.3
44
63
  }
45
64
  },
46
- '&$focusVisible $thumb': {
47
- color: '#52d869',
48
- border: '6px solid #fff'
49
- }
50
- },
51
- thumb: {
52
- width: 24,
53
- height: 24
54
- },
55
- track: {
56
- // fix: 下边框截断问题
57
- boxSizing: 'border-box',
58
- borderRadius: 26 / 2,
59
- border: "1px solid ".concat(theme.palette.grey[400]),
60
- backgroundColor: theme.palette.grey[50],
61
- opacity: 1,
62
- transition: theme.transitions.create(['background-color', 'border'])
63
- },
64
- checked: {},
65
- focusVisible: {}
66
- }))(_ref => {
67
- let {
68
- classes
69
- } = _ref,
70
- props = _objectWithoutProperties(_ref, _excluded);
71
-
72
- return /*#__PURE__*/_react.default.createElement(_Switch.default, Object.assign({
73
- focusVisibleClassName: classes.focusVisible,
74
- disableRipple: true,
75
- classes: {
76
- root: classes.root,
77
- switchBase: classes.switchBase,
78
- thumb: classes.thumb,
79
- track: classes.track,
80
- checked: classes.checked
65
+ '& .MuiSwitch-thumb': {
66
+ boxSizing: 'border-box',
67
+ width: 22,
68
+ height: 22
69
+ },
70
+ '& .MuiSwitch-track': {
71
+ borderRadius: 26 / 2,
72
+ backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D',
73
+ opacity: 1,
74
+ transition: theme.transitions.create(['background-color'], {
75
+ duration: 500
76
+ })
81
77
  }
82
- }, props));
78
+ };
83
79
  });
84
80
  /**
85
81
  * 抽取 blocklet server 中使用的 iOS 风格的 Switch, 该组件把 FormControlLabel 和 MuiSwitch 组合在一起,
@@ -90,18 +86,22 @@ function Switch(_ref2) {
90
86
  let {
91
87
  labelProps
92
88
  } = _ref2,
93
- rest = _objectWithoutProperties(_ref2, _excluded2);
89
+ rest = _objectWithoutProperties(_ref2, _excluded);
90
+
91
+ if (labelProps) {
92
+ return /*#__PURE__*/_react.default.createElement(_FormControlLabel.default, Object.assign({
93
+ control: /*#__PURE__*/_react.default.createElement(IOSSwitch, rest)
94
+ }, labelProps));
95
+ }
94
96
 
95
- return /*#__PURE__*/_react.default.createElement(_FormControlLabel.default, Object.assign({
96
- control: /*#__PURE__*/_react.default.createElement(IOSSwitch, rest)
97
- }, labelProps));
97
+ return /*#__PURE__*/_react.default.createElement(IOSSwitch, rest);
98
98
  }
99
99
 
100
100
  Switch.propTypes = {
101
101
  labelProps: _propTypes.default.object
102
102
  };
103
103
  Switch.defaultProps = {
104
- labelProps: {}
104
+ labelProps: null
105
105
  };
106
106
  var _default = Switch;
107
107
  exports.default = _default;
package/lib/index.js CHANGED
@@ -105,6 +105,12 @@ Object.defineProperty(exports, "Logo", {
105
105
  return _Logo.default;
106
106
  }
107
107
  });
108
+ Object.defineProperty(exports, "RelativeTime", {
109
+ enumerable: true,
110
+ get: function get() {
111
+ return _RelativeTime.default;
112
+ }
113
+ });
108
114
  Object.defineProperty(exports, "Tabs", {
109
115
  enumerable: true,
110
116
  get: function get() {
@@ -222,6 +228,8 @@ var _selector = _interopRequireDefault(require("./Locale/selector"));
222
228
 
223
229
  var _Logo = _interopRequireDefault(require("./Logo"));
224
230
 
231
+ var _RelativeTime = _interopRequireDefault(require("./RelativeTime"));
232
+
225
233
  var _Tabs = _interopRequireDefault(require("./Tabs"));
226
234
 
227
235
  var _Tag = _interopRequireDefault(require("./Tag"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -43,7 +43,7 @@
43
43
  "@babel/preset-react": "^7.8.3",
44
44
  "babel-plugin-inline-react-svg": "^1.1.1",
45
45
  "babel-plugin-styled-components": "^1.10.7",
46
- "dayjs": "^1.10.6",
46
+ "dayjs": "^1.11.2",
47
47
  "eslint-plugin-react-hooks": "^4.2.0",
48
48
  "jest": "^24.1.0",
49
49
  "moment-timezone": "^0.5.33"
@@ -53,10 +53,10 @@
53
53
  "react": ">=18.1.0",
54
54
  "react-ga": "^2.7.0"
55
55
  },
56
- "gitHead": "9fa98015ebb44b81cc813dad0196cc48c14c5cf7",
56
+ "gitHead": "1e32c65bb4114f310ebbabd65632caa0c5f24c76",
57
57
  "dependencies": {
58
- "@arcblock/icons": "^2.0.1",
59
- "@arcblock/react-hooks": "^2.0.1",
58
+ "@arcblock/icons": "^2.0.4",
59
+ "@arcblock/react-hooks": "^2.0.4",
60
60
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
61
61
  "@emotion/react": "^11.9.0",
62
62
  "@emotion/styled": "^11.8.1",
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import relativeTime from 'dayjs/plugin/relativeTime';
4
+ import dayjs from 'dayjs';
5
+ import 'dayjs/locale/zh-cn';
6
+ import Tooltip from '@mui/material/Tooltip';
7
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
8
+ import utc from 'dayjs/plugin/utc';
9
+ import timezone from 'dayjs/plugin/timezone';
10
+ import { formatToDatetime, setDateTool } from '../Util';
11
+
12
+ dayjs.extend(localizedFormat);
13
+ dayjs.extend(utc);
14
+ dayjs.extend(timezone);
15
+ dayjs.extend(relativeTime);
16
+ setDateTool(dayjs);
17
+
18
+ export default function RelativeTime({ value, locale, ...rest }) {
19
+ if (!value) {
20
+ return '-';
21
+ }
22
+
23
+ const localeOption = locale === 'zh' ? 'zh-cn' : 'zh-us';
24
+
25
+ const innerContent = dayjs().locale(localeOption).to(value);
26
+
27
+ return (
28
+ <Tooltip
29
+ title={formatToDatetime(value, { locale: localeOption })}
30
+ placement="top-end"
31
+ enterTouchDelay={0}>
32
+ <span {...rest}>{innerContent}</span>
33
+ </Tooltip>
34
+ );
35
+ }
36
+
37
+ RelativeTime.propTypes = {
38
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
39
+ locale: PropTypes.string,
40
+ };
41
+
42
+ RelativeTime.defaultProps = {
43
+ value: '',
44
+ locale: 'en',
45
+ };
@@ -1,78 +1,74 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@mui/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
  import FormControlLabel from '@mui/material/FormControlLabel';
5
5
  import MuiSwitch from '@mui/material/Switch';
6
6
 
7
- // 参考: https://v4.mui.com/components/switches/
8
- const IOSSwitch = withStyles(theme => ({
9
- root: {
10
- width: 42,
11
- height: 26,
7
+ // 参考: https://mui.com/material-ui/react-switch/#customization
8
+ const IOSSwitch = styled(props => (
9
+ <MuiSwitch focusVisibleClassName=".Mui-focusVisible" disableRipple {...props} />
10
+ ))(({ theme }) => ({
11
+ width: 42,
12
+ height: 26,
13
+ padding: 0,
14
+ '& .MuiSwitch-switchBase': {
12
15
  padding: 0,
13
- margin: theme.spacing(1),
14
- },
15
- switchBase: {
16
- padding: 1,
17
- '&$checked': {
16
+ margin: 2,
17
+ transitionDuration: '300ms',
18
+ '&.Mui-checked': {
18
19
  transform: 'translateX(16px)',
19
- color: theme.palette.common.white,
20
- '& + $track': {
21
- backgroundColor: '#52d869',
20
+ color: '#fff',
21
+ '& + .MuiSwitch-track': {
22
+ backgroundColor: theme.palette.mode === 'dark' ? '#2ECA45' : '#65C466',
22
23
  opacity: 1,
23
- border: 'none',
24
+ border: 0,
25
+ },
26
+ '&.Mui-disabled + .MuiSwitch-track': {
27
+ opacity: 0.5,
24
28
  },
25
29
  },
26
- '&$focusVisible $thumb': {
27
- color: '#52d869',
30
+ '&.Mui-focusVisible .MuiSwitch-thumb': {
31
+ color: '#33cf4d',
28
32
  border: '6px solid #fff',
29
33
  },
34
+ '&.Mui-disabled .MuiSwitch-thumb': {
35
+ color: theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[600],
36
+ },
37
+ '&.Mui-disabled + .MuiSwitch-track': {
38
+ opacity: theme.palette.mode === 'light' ? 0.7 : 0.3,
39
+ },
30
40
  },
31
- thumb: {
32
- width: 24,
33
- height: 24,
34
- },
35
- track: {
36
- // fix: 下边框截断问题
41
+ '& .MuiSwitch-thumb': {
37
42
  boxSizing: 'border-box',
43
+ width: 22,
44
+ height: 22,
45
+ },
46
+ '& .MuiSwitch-track': {
38
47
  borderRadius: 26 / 2,
39
- border: `1px solid ${theme.palette.grey[400]}`,
40
- backgroundColor: theme.palette.grey[50],
48
+ backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D',
41
49
  opacity: 1,
42
- transition: theme.transitions.create(['background-color', 'border']),
50
+ transition: theme.transitions.create(['background-color'], {
51
+ duration: 500,
52
+ }),
43
53
  },
44
- checked: {},
45
- focusVisible: {},
46
- }))(({ classes, ...props }) => {
47
- return (
48
- <MuiSwitch
49
- focusVisibleClassName={classes.focusVisible}
50
- disableRipple
51
- classes={{
52
- root: classes.root,
53
- switchBase: classes.switchBase,
54
- thumb: classes.thumb,
55
- track: classes.track,
56
- checked: classes.checked,
57
- }}
58
- {...props}
59
- />
60
- );
61
- });
54
+ }));
62
55
 
63
56
  /**
64
57
  * 抽取 blocklet server 中使用的 iOS 风格的 Switch, 该组件把 FormControlLabel 和 MuiSwitch 组合在一起,
65
58
  * 兼容 mui Switch props, 使用 labelProps 控制 FormControlLabel
66
59
  */
67
60
  function Switch({ labelProps, ...rest }) {
68
- return <FormControlLabel control={<IOSSwitch {...rest} />} {...labelProps} />;
61
+ if (labelProps) {
62
+ return <FormControlLabel control={<IOSSwitch {...rest} />} {...labelProps} />;
63
+ }
64
+ return <IOSSwitch {...rest} />;
69
65
  }
70
66
 
71
67
  Switch.propTypes = {
72
68
  labelProps: PropTypes.object,
73
69
  };
74
70
  Switch.defaultProps = {
75
- labelProps: {},
71
+ labelProps: null,
76
72
  };
77
73
 
78
74
  export default Switch;
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ import Footer from './Footer';
14
14
  import Icon from './Icon';
15
15
  import LocaleSelector from './Locale/selector';
16
16
  import Logo from './Logo';
17
+ import RelativeTime from './RelativeTime';
17
18
  import Tabs from './Tabs';
18
19
  import Tag from './Tag';
19
20
  import Terminal from './Terminal';
@@ -48,6 +49,7 @@ export {
48
49
  LocaleSelector,
49
50
  Logo,
50
51
  Tabs,
52
+ RelativeTime,
51
53
  Tag,
52
54
  Terminal,
53
55
  TerminalPlayer,