@arcblock/ux 2.0.1 → 2.0.2
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/Switch/index.js +58 -58
- package/package.json +4 -4
- package/src/Switch/index.js +42 -46
package/lib/Switch/index.js
CHANGED
|
@@ -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 = ["
|
|
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://
|
|
28
|
-
const IOSSwitch = (0, _styles.
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
'
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
}
|
|
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,
|
|
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(
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"react": ">=18.1.0",
|
|
54
54
|
"react-ga": "^2.7.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "319d3e6d884b5f79311edca8aab7a9ed17a17b74",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@arcblock/icons": "^2.0.
|
|
59
|
-
"@arcblock/react-hooks": "^2.0.
|
|
58
|
+
"@arcblock/icons": "^2.0.2",
|
|
59
|
+
"@arcblock/react-hooks": "^2.0.2",
|
|
60
60
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
61
61
|
"@emotion/react": "^11.9.0",
|
|
62
62
|
"@emotion/styled": "^11.8.1",
|
package/src/Switch/index.js
CHANGED
|
@@ -1,78 +1,74 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
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://
|
|
8
|
-
const IOSSwitch =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
padding: 1,
|
|
17
|
-
'&$checked': {
|
|
16
|
+
margin: 2,
|
|
17
|
+
transitionDuration: '300ms',
|
|
18
|
+
'&.Mui-checked': {
|
|
18
19
|
transform: 'translateX(16px)',
|
|
19
|
-
color:
|
|
20
|
-
'& +
|
|
21
|
-
backgroundColor: '#
|
|
20
|
+
color: '#fff',
|
|
21
|
+
'& + .MuiSwitch-track': {
|
|
22
|
+
backgroundColor: theme.palette.mode === 'dark' ? '#2ECA45' : '#65C466',
|
|
22
23
|
opacity: 1,
|
|
23
|
-
border:
|
|
24
|
+
border: 0,
|
|
25
|
+
},
|
|
26
|
+
'&.Mui-disabled + .MuiSwitch-track': {
|
|
27
|
+
opacity: 0.5,
|
|
24
28
|
},
|
|
25
29
|
},
|
|
26
|
-
'
|
|
27
|
-
color: '#
|
|
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
|
-
|
|
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',
|
|
50
|
+
transition: theme.transitions.create(['background-color'], {
|
|
51
|
+
duration: 500,
|
|
52
|
+
}),
|
|
43
53
|
},
|
|
44
|
-
|
|
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
|
-
|
|
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;
|