@arcblock/ux 0.78.25 → 1.6.59
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/LICENSE +1 -1
- package/README.md +0 -56
- package/lib/ActionButton/index.js +6 -4
- package/lib/ActivityIndicator/index.js +75 -23
- package/lib/Alert/index.js +15 -11
- package/lib/Async/index.js +1 -1
- package/lib/Badge/index.js +17 -15
- package/lib/Blocklet/index.js +261 -0
- package/lib/Button/wrap.js +96 -43
- package/lib/ButtonGroup/index.js +3 -16
- package/lib/Center/index.js +30 -4
- package/lib/ClickToCopy/index.js +10 -8
- package/lib/CodeBlock/index.js +40 -13
- package/lib/Colors/index.js +15 -0
- package/lib/Colors/themes/default.js +85 -0
- package/lib/ContactForm/index.js +9 -10
- package/lib/CookieConsent/index.js +98 -0
- package/lib/CountDown/index.js +18 -14
- package/lib/Dialog/confirm.js +84 -0
- package/lib/Dialog/dialog.js +137 -0
- package/lib/Dialog/index.js +23 -0
- package/lib/Earth/index.js +33 -33
- package/lib/Empty/index.js +61 -0
- package/lib/Footer/index.js +16 -18
- package/lib/Icon/image.js +10 -13
- package/lib/Icon/index.js +10 -8
- package/lib/Img/index.js +212 -0
- package/lib/InfoRow/index.js +7 -6
- package/lib/Layout/dashboard/header.js +60 -42
- package/lib/Layout/dashboard/index.js +72 -60
- package/lib/Layout/dashboard/sidebar.js +41 -25
- package/lib/Layout/index.js +113 -51
- package/lib/Locale/browser-lang.js +0 -2
- package/lib/Locale/context.js +85 -61
- package/lib/Locale/selector.js +33 -20
- package/lib/Logo/index.js +15 -13
- package/lib/Metric/index.js +5 -6
- package/lib/NFTDisplay/README.md +59 -0
- package/lib/NFTDisplay/aspect-ratio-container.js +52 -0
- package/lib/NFTDisplay/broken.js +25 -0
- package/lib/NFTDisplay/index.js +317 -0
- package/lib/NFTDisplay/loading.js +23 -0
- package/lib/NFTDisplay/svg-embedder/img.js +68 -0
- package/lib/NFTDisplay/svg-embedder/inline-svg.js +54 -0
- package/lib/PageScroller/index.js +10 -11
- package/lib/PageScroller/usePrevValue.js +2 -2
- package/lib/PricingTable/PricingPlan.js +12 -15
- package/lib/PricingTable/index.js +5 -5
- package/lib/Result/common.js +176 -0
- package/lib/Result/index.js +61 -0
- package/lib/Result/result.js +69 -0
- package/lib/Result/translations.js +61 -0
- package/lib/Screenshot/index.js +14 -13
- package/lib/Spinner/index.js +37 -0
- package/lib/SplitButton/index.js +126 -0
- package/lib/Switch/index.js +107 -0
- package/lib/Tabs/index.js +24 -47
- package/lib/Tag/index.js +15 -13
- package/lib/Terminal/Player.js +43 -45
- package/lib/Terminal/index.js +3 -1
- package/lib/Terminal/util.js +2 -3
- package/lib/TextCollapse/index.js +21 -14
- package/lib/Theme/index.js +79 -63
- package/lib/Theme/responsiveFontSizes.js +8 -8
- package/lib/Toast/index.js +12 -11
- package/lib/Util/index.js +197 -26
- package/lib/Video/index.js +8 -11
- package/lib/Wallet/Action.js +15 -13
- package/lib/Wallet/Download.js +60 -58
- package/lib/Wallet/Open.js +2 -2
- package/lib/WechatPrompt/index.js +10 -10
- package/lib/index.js +6 -6
- package/lib/withTheme/index.js +5 -17
- package/lib/withTracker/error_boundary.js +3 -3
- package/lib/withTracker/index.js +6 -7
- package/package.json +22 -17
- package/src/ActionButton/index.js +65 -0
- package/src/ActivityIndicator/index.js +141 -0
- package/src/Alert/index.js +104 -0
- package/src/Async/index.js +39 -0
- package/src/Badge/index.js +71 -0
- package/src/Blocklet/index.js +424 -0
- package/src/Button/index.js +4 -0
- package/src/Button/wrap.js +101 -0
- package/src/ButtonGroup/index.js +6 -0
- package/src/Center/index.js +40 -0
- package/src/ClickToCopy/index.js +90 -0
- package/src/CodeBlock/index.js +160 -0
- package/src/Colors/index.js +1 -0
- package/src/Colors/themes/default.js +54 -0
- package/src/ContactForm/index.js +240 -0
- package/src/CookieConsent/index.js +90 -0
- package/src/CountDown/index.js +151 -0
- package/src/Dialog/confirm.js +76 -0
- package/src/Dialog/dialog.js +162 -0
- package/src/Dialog/index.js +2 -0
- package/src/DriftBot/index.js +81 -0
- package/src/Earth/countries.json +8057 -0
- package/src/Earth/index.js +511 -0
- package/src/Earth/util.js +69 -0
- package/src/Empty/index.js +41 -0
- package/src/Footer/index.js +110 -0
- package/src/Icon/image.js +55 -0
- package/src/Icon/index.js +69 -0
- package/src/Img/index.js +172 -0
- package/src/InfoRow/index.js +83 -0
- package/src/Layout/dashboard/header.js +157 -0
- package/src/Layout/dashboard/index.js +150 -0
- package/src/Layout/dashboard/sidebar.js +122 -0
- package/src/Layout/index.js +318 -0
- package/src/Locale/browser-lang.js +63 -0
- package/src/Locale/context.js +94 -0
- package/src/Locale/images/globe-dark.png +0 -0
- package/src/Locale/images/globe-light.png +0 -0
- package/src/Locale/selector.js +135 -0
- package/src/Logo/images/logo-dark-text.svg +3 -0
- package/src/Logo/images/logo-dark-top.svg +6 -0
- package/src/Logo/images/logo-light-text.svg +3 -0
- package/src/Logo/images/logo-light-top.svg +6 -0
- package/src/Logo/index.js +47 -0
- package/src/Metric/index.js +115 -0
- package/src/NFTDisplay/README.md +59 -0
- package/src/NFTDisplay/aspect-ratio-container.js +34 -0
- package/src/NFTDisplay/broken.js +18 -0
- package/src/NFTDisplay/index.js +257 -0
- package/src/NFTDisplay/loading.js +17 -0
- package/src/NFTDisplay/svg-embedder/img.js +36 -0
- package/src/NFTDisplay/svg-embedder/inline-svg.js +37 -0
- package/src/PageScroller/index.js +342 -0
- package/src/PageScroller/usePrevValue.js +12 -0
- package/src/PricingTable/PricingPlan.js +112 -0
- package/src/PricingTable/index.js +43 -0
- package/src/Result/common.js +116 -0
- package/src/Result/index.js +31 -0
- package/src/Result/result.js +57 -0
- package/src/Result/translations.js +56 -0
- package/src/Screenshot/devices.css +1366 -0
- package/src/Screenshot/index.js +181 -0
- package/src/Spinner/index.js +19 -0
- package/src/SplitButton/index.js +112 -0
- package/src/Switch/index.js +78 -0
- package/src/Tabs/index.js +46 -0
- package/src/Tag/index.js +73 -0
- package/src/Terminal/Player.js +364 -0
- package/src/Terminal/index.js +150 -0
- package/src/Terminal/player.css +378 -0
- package/src/Terminal/util.js +167 -0
- package/src/Terminal/xterm.css +171 -0
- package/src/TextCollapse/index.js +92 -0
- package/src/Theme/index.js +184 -0
- package/src/Theme/responsiveFontSizes.js +94 -0
- package/src/Toast/index.js +118 -0
- package/src/Util/index.js +281 -0
- package/src/Video/index.js +72 -0
- package/src/Wallet/Action.js +105 -0
- package/src/Wallet/Download.js +130 -0
- package/src/Wallet/Open.js +50 -0
- package/src/Wallet/images/abtwallet.png +0 -0
- package/src/Wallet/images/android_download.svg +23 -0
- package/src/Wallet/images/app-store.svg +20 -0
- package/src/Wallet/images/google-play.svg +70 -0
- package/src/WechatPrompt/images/android.png +0 -0
- package/src/WechatPrompt/images/ios.png +0 -0
- package/src/WechatPrompt/index.js +81 -0
- package/src/index.js +63 -0
- package/src/withTheme/index.js +72 -0
- package/src/withTracker/README.md +34 -0
- package/src/withTracker/error_boundary.js +34 -0
- package/src/withTracker/index.js +70 -0
- package/lib/GraphQLPlayground/graphiql.css +0 -1850
- package/lib/GraphQLPlayground/index.js +0 -302
- package/lib/GraphQLPlayground/util.js +0 -55
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
|
|
5
|
+
import { mergeProps } from '../Util';
|
|
6
|
+
|
|
7
|
+
import './devices.css';
|
|
8
|
+
|
|
9
|
+
const types = {
|
|
10
|
+
'iphone-x': {
|
|
11
|
+
borderRadius: 32,
|
|
12
|
+
width: 342,
|
|
13
|
+
scale: 0.78,
|
|
14
|
+
},
|
|
15
|
+
'iphone-8': {
|
|
16
|
+
borderRadius: 0,
|
|
17
|
+
width: 336,
|
|
18
|
+
scale: 0.78,
|
|
19
|
+
},
|
|
20
|
+
'ipad-pro': {
|
|
21
|
+
borderRadius: 0,
|
|
22
|
+
width: 560,
|
|
23
|
+
scale: 0.62,
|
|
24
|
+
},
|
|
25
|
+
'imac-pro': {
|
|
26
|
+
borderRadius: 0,
|
|
27
|
+
width: 624,
|
|
28
|
+
scale: 0.56,
|
|
29
|
+
},
|
|
30
|
+
macbook: {
|
|
31
|
+
borderRadius: 0,
|
|
32
|
+
width: 740,
|
|
33
|
+
scale: 0.47,
|
|
34
|
+
},
|
|
35
|
+
'macbook-pro': {
|
|
36
|
+
borderRadius: 0,
|
|
37
|
+
width: 740,
|
|
38
|
+
scale: 0.47,
|
|
39
|
+
},
|
|
40
|
+
'surface-pro': {
|
|
41
|
+
borderRadius: 0,
|
|
42
|
+
width: 561,
|
|
43
|
+
scale: 0.62,
|
|
44
|
+
},
|
|
45
|
+
'surface-book': {
|
|
46
|
+
borderRadius: 0,
|
|
47
|
+
width: 728,
|
|
48
|
+
scale: 0.47,
|
|
49
|
+
},
|
|
50
|
+
'surface-studio': {
|
|
51
|
+
borderRadius: 0,
|
|
52
|
+
width: 640,
|
|
53
|
+
scale: 0.55,
|
|
54
|
+
},
|
|
55
|
+
'galaxy-s8': {
|
|
56
|
+
borderRadius: 0,
|
|
57
|
+
width: 321,
|
|
58
|
+
scale: 0.8,
|
|
59
|
+
},
|
|
60
|
+
'google-pixel': {
|
|
61
|
+
borderRadius: 0,
|
|
62
|
+
width: 360,
|
|
63
|
+
scale: 0.72,
|
|
64
|
+
},
|
|
65
|
+
'google-pixel-2-xl': {
|
|
66
|
+
borderRadius: 0,
|
|
67
|
+
width: 360,
|
|
68
|
+
scale: 0.72,
|
|
69
|
+
},
|
|
70
|
+
'apple-watch': {
|
|
71
|
+
borderRadius: 0,
|
|
72
|
+
width: 200,
|
|
73
|
+
scale: 1,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const childProps = {
|
|
78
|
+
img: ['alt', 'title', 'src', 'srcSet', 'sizes', 'loading', 'key', 'children'],
|
|
79
|
+
video: ['alt', 'title', 'muted', 'autoplay', 'loop', 'key', 'children'],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const createChild = child => [
|
|
83
|
+
React.createElement(
|
|
84
|
+
child.type,
|
|
85
|
+
childProps[child.type].reduce((acc, x) => {
|
|
86
|
+
acc[x] = child.props[x];
|
|
87
|
+
return acc;
|
|
88
|
+
}, {})
|
|
89
|
+
),
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const findChildren = (children, returnArgWhenNotFound = true) => {
|
|
93
|
+
for (let i = 0; i < children.length; i++) {
|
|
94
|
+
const child = children[i];
|
|
95
|
+
|
|
96
|
+
if (['img', 'video'].includes(child.type)) {
|
|
97
|
+
return createChild(child);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (child.props && child.props.children) {
|
|
101
|
+
const subChildren = React.Children.toArray(child.props.children);
|
|
102
|
+
const result = findChildren(subChildren, false);
|
|
103
|
+
if (result) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (returnArgWhenNotFound) {
|
|
110
|
+
return children;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// This component is built upon the awesome device.css lib
|
|
117
|
+
// By default it will find and only render img/video tags in the children
|
|
118
|
+
// If neither of them are found, the whole child tree is rendered
|
|
119
|
+
const Screenshot = props => {
|
|
120
|
+
const newProps = mergeProps(props, Screenshot, ['style', 'width', 'height']);
|
|
121
|
+
const { type, children, style, className, width, height, ...rest } = newProps;
|
|
122
|
+
const { zIndex = 0, borderRadius = 0 } = types[type] || {};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<Div
|
|
126
|
+
{...rest}
|
|
127
|
+
type={type}
|
|
128
|
+
className={`device device-${type} ${className}`.trim()}
|
|
129
|
+
style={style}
|
|
130
|
+
contentRadius={borderRadius}
|
|
131
|
+
contentZIndex={zIndex}>
|
|
132
|
+
<div className="device-frame">
|
|
133
|
+
<div className="device-content">{findChildren(React.Children.toArray(children))}</div>
|
|
134
|
+
</div>
|
|
135
|
+
<div className="device-stripe" />
|
|
136
|
+
<div className="device-header" />
|
|
137
|
+
<div className="device-sensors" />
|
|
138
|
+
<div className="device-btns" />
|
|
139
|
+
<div className="device-power" />
|
|
140
|
+
</Div>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const Div = styled.div`
|
|
145
|
+
@media (max-width: ${props => types[props.type].width}px) {
|
|
146
|
+
transform-origin: 0 0;
|
|
147
|
+
transform: scale(${props => types[props.type].scale});
|
|
148
|
+
}
|
|
149
|
+
.device-content {
|
|
150
|
+
overflow: hidden;
|
|
151
|
+
}
|
|
152
|
+
.device-content video,
|
|
153
|
+
.device-content img {
|
|
154
|
+
border-radius: ${props => props.contentRadius}px;
|
|
155
|
+
background-color: #fff;
|
|
156
|
+
background-position: center center;
|
|
157
|
+
background-size: cover;
|
|
158
|
+
object-fit: cover;
|
|
159
|
+
width: 100.1%;
|
|
160
|
+
height: 100.1%;
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
|
|
164
|
+
Screenshot.propTypes = {
|
|
165
|
+
type: PropTypes.oneOf(Object.keys(types)),
|
|
166
|
+
children: PropTypes.any.isRequired,
|
|
167
|
+
className: PropTypes.string,
|
|
168
|
+
width: PropTypes.number,
|
|
169
|
+
height: PropTypes.number,
|
|
170
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Screenshot.defaultProps = {
|
|
174
|
+
type: 'iphone-x',
|
|
175
|
+
className: '',
|
|
176
|
+
style: '{}',
|
|
177
|
+
width: 0,
|
|
178
|
+
height: 0,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export default Screenshot;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import CircularProgress from '@material-ui/core/CircularProgress';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Spinner
|
|
6
|
+
*
|
|
7
|
+
* 之前的 Spinner 实现由内外 2 个环构成, 现在改为基于 @material-ui/core/CircularProgress 的实现
|
|
8
|
+
*
|
|
9
|
+
* - 之前 size prop 是 array 类型, 需要与 CircularProgress#size 兼容
|
|
10
|
+
* - color 默认使用 #4598fa, 如果调用方传入了 color prop 或 style#color, 则默认 color 被覆盖
|
|
11
|
+
*/
|
|
12
|
+
export default function Spinner(props) {
|
|
13
|
+
const _props = { ...props };
|
|
14
|
+
// 兼容之前的 size prop (设置外圈/内圈的尺寸)
|
|
15
|
+
if (_props.size && Array.isArray(_props.size)) {
|
|
16
|
+
[_props.size] = _props.size;
|
|
17
|
+
}
|
|
18
|
+
return <CircularProgress {..._props} />;
|
|
19
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import ExpandMore from '@material-ui/icons/ExpandMore';
|
|
5
|
+
import Popper from '@material-ui/core/Popper';
|
|
6
|
+
import Paper from '@material-ui/core/Paper';
|
|
7
|
+
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
|
|
8
|
+
import MenuList from '@material-ui/core/MenuList';
|
|
9
|
+
import MenuItem from '@material-ui/core/MenuItem';
|
|
10
|
+
import ButtonGroup from '@material-ui/core/ButtonGroup';
|
|
11
|
+
import Button from '../Button';
|
|
12
|
+
|
|
13
|
+
export default function SplitButton({
|
|
14
|
+
size,
|
|
15
|
+
color,
|
|
16
|
+
menu,
|
|
17
|
+
children,
|
|
18
|
+
variant,
|
|
19
|
+
onClick,
|
|
20
|
+
menuButtonProps,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const anchorRef = useRef(null);
|
|
25
|
+
|
|
26
|
+
const onToggle = () => {
|
|
27
|
+
setOpen(prevOpen => !prevOpen);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handleClose = e => {
|
|
31
|
+
if (anchorRef.current && anchorRef.current.contains(e.target)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setOpen(false);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 点击 item 后收起下拉菜单, 如果想要点击 action 后不收起下拉菜单, 可以在 item#onClick 时调用 e.stopPropagation()
|
|
38
|
+
const handleItemClick = e => {
|
|
39
|
+
if (e.target.classList.contains('MuiListItem-root')) {
|
|
40
|
+
setOpen(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<StyledButtonGroup variant={variant} size={size} color={color} ref={anchorRef} {...rest}>
|
|
47
|
+
{typeof children === 'function' ? (
|
|
48
|
+
children()
|
|
49
|
+
) : (
|
|
50
|
+
<Button onClick={onClick} color={color}>
|
|
51
|
+
{children}
|
|
52
|
+
</Button>
|
|
53
|
+
)}
|
|
54
|
+
<Button onClick={onToggle} color={color} {...menuButtonProps}>
|
|
55
|
+
<ExpandMore />
|
|
56
|
+
</Button>
|
|
57
|
+
</StyledButtonGroup>
|
|
58
|
+
<StyledPopper
|
|
59
|
+
open={open}
|
|
60
|
+
anchorEl={anchorRef.current}
|
|
61
|
+
placement="bottom-end"
|
|
62
|
+
disablePortal={false}>
|
|
63
|
+
<Paper>
|
|
64
|
+
<ClickAwayListener onClickAway={handleClose}>
|
|
65
|
+
<MenuList onClick={handleItemClick}>{menu}</MenuList>
|
|
66
|
+
</ClickAwayListener>
|
|
67
|
+
</Paper>
|
|
68
|
+
</StyledPopper>
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
SplitButton.propTypes = {
|
|
74
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
75
|
+
color: PropTypes.oneOf(['default', 'primary', 'secondary', 'inherit']),
|
|
76
|
+
menu: PropTypes.oneOfType([PropTypes.node, PropTypes.array]),
|
|
77
|
+
// 也可以是用于渲染主按钮的 function
|
|
78
|
+
children: PropTypes.any,
|
|
79
|
+
variant: PropTypes.oneOf(['outlined', 'contained']),
|
|
80
|
+
onClick: PropTypes.func,
|
|
81
|
+
menuButtonProps: PropTypes.object,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
SplitButton.defaultProps = {
|
|
85
|
+
size: 'medium',
|
|
86
|
+
color: 'primary',
|
|
87
|
+
menu: [],
|
|
88
|
+
children: null,
|
|
89
|
+
variant: 'contained',
|
|
90
|
+
onClick: () => {},
|
|
91
|
+
menuButtonProps: {},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
SplitButton.Item = MenuItem;
|
|
95
|
+
|
|
96
|
+
const StyledButtonGroup = styled(ButtonGroup)`
|
|
97
|
+
> .MuiButtonBase-root:last-child {
|
|
98
|
+
min-width: 2em;
|
|
99
|
+
padding-left: 0;
|
|
100
|
+
padding-right: 0;
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
const StyledPopper = styled(Popper)`
|
|
105
|
+
.MuiList-root {
|
|
106
|
+
padding: 4px 0;
|
|
107
|
+
}
|
|
108
|
+
.MuiListItem-root {
|
|
109
|
+
padding-top: 4px;
|
|
110
|
+
padding-bottom: 4px;
|
|
111
|
+
}
|
|
112
|
+
`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
+
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
5
|
+
import MuiSwitch from '@material-ui/core/Switch';
|
|
6
|
+
|
|
7
|
+
// 参考: https://v4.mui.com/components/switches/
|
|
8
|
+
const IOSSwitch = withStyles(theme => ({
|
|
9
|
+
root: {
|
|
10
|
+
width: 42,
|
|
11
|
+
height: 26,
|
|
12
|
+
padding: 0,
|
|
13
|
+
margin: theme.spacing(1),
|
|
14
|
+
},
|
|
15
|
+
switchBase: {
|
|
16
|
+
padding: 1,
|
|
17
|
+
'&$checked': {
|
|
18
|
+
transform: 'translateX(16px)',
|
|
19
|
+
color: theme.palette.common.white,
|
|
20
|
+
'& + $track': {
|
|
21
|
+
backgroundColor: '#52d869',
|
|
22
|
+
opacity: 1,
|
|
23
|
+
border: 'none',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
'&$focusVisible $thumb': {
|
|
27
|
+
color: '#52d869',
|
|
28
|
+
border: '6px solid #fff',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
thumb: {
|
|
32
|
+
width: 24,
|
|
33
|
+
height: 24,
|
|
34
|
+
},
|
|
35
|
+
track: {
|
|
36
|
+
// fix: 下边框截断问题
|
|
37
|
+
boxSizing: 'border-box',
|
|
38
|
+
borderRadius: 26 / 2,
|
|
39
|
+
border: `1px solid ${theme.palette.grey[400]}`,
|
|
40
|
+
backgroundColor: theme.palette.grey[50],
|
|
41
|
+
opacity: 1,
|
|
42
|
+
transition: theme.transitions.create(['background-color', 'border']),
|
|
43
|
+
},
|
|
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
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 抽取 blocklet server 中使用的 iOS 风格的 Switch, 该组件把 FormControlLabel 和 MuiSwitch 组合在一起,
|
|
65
|
+
* 兼容 mui Switch props, 使用 labelProps 控制 FormControlLabel
|
|
66
|
+
*/
|
|
67
|
+
function Switch({ labelProps, ...rest }) {
|
|
68
|
+
return <FormControlLabel control={<IOSSwitch {...rest} />} {...labelProps} />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Switch.propTypes = {
|
|
72
|
+
labelProps: PropTypes.object,
|
|
73
|
+
};
|
|
74
|
+
Switch.defaultProps = {
|
|
75
|
+
labelProps: {},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default Switch;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { makeStyles } from '@material-ui/core';
|
|
4
|
+
import MuiTabs from '@material-ui/core/Tabs';
|
|
5
|
+
import MuiTab from '@material-ui/core/Tab';
|
|
6
|
+
|
|
7
|
+
const useStyles = makeStyles(theme => ({
|
|
8
|
+
tabs: {},
|
|
9
|
+
tab: {
|
|
10
|
+
fontSize: '0.875rem',
|
|
11
|
+
[theme.breakpoints.up('md')]: {
|
|
12
|
+
fontSize: '1rem',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
export default function Tabs({ tabs, current, onChange, ...rest }) {
|
|
18
|
+
const classes = useStyles();
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<MuiTabs
|
|
22
|
+
scrollButtons="on"
|
|
23
|
+
variant="scrollable"
|
|
24
|
+
value={current}
|
|
25
|
+
onChange={(_, newValue) => onChange(newValue)}
|
|
26
|
+
indicatorColor="primary"
|
|
27
|
+
{...rest}
|
|
28
|
+
className={[classes.tabs, rest.className || ''].join(' ')}>
|
|
29
|
+
{tabs.map(x => (
|
|
30
|
+
<MuiTab
|
|
31
|
+
className={classes.tab}
|
|
32
|
+
key={x.value}
|
|
33
|
+
value={x.value}
|
|
34
|
+
label={x.label}
|
|
35
|
+
icon={x.icon || null}
|
|
36
|
+
/>
|
|
37
|
+
))}
|
|
38
|
+
</MuiTabs>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Tabs.propTypes = {
|
|
43
|
+
tabs: PropTypes.array.isRequired,
|
|
44
|
+
current: PropTypes.string.isRequired,
|
|
45
|
+
onChange: PropTypes.func.isRequired,
|
|
46
|
+
};
|
package/src/Tag/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
|
|
5
|
+
import Typography from '@material-ui/core/Typography';
|
|
6
|
+
|
|
7
|
+
import { mergeProps } from '../Util';
|
|
8
|
+
import colors from '../Colors';
|
|
9
|
+
|
|
10
|
+
const types = {
|
|
11
|
+
error: {
|
|
12
|
+
color: colors.error.main,
|
|
13
|
+
backgroundColor: 'rgba(227, 91, 84, 0.2)',
|
|
14
|
+
},
|
|
15
|
+
warning: {
|
|
16
|
+
color: colors.warning.main,
|
|
17
|
+
backgroundColor: 'rgba(247, 208, 64, 0.2)',
|
|
18
|
+
},
|
|
19
|
+
success: {
|
|
20
|
+
color: colors.success.main,
|
|
21
|
+
backgroundColor: '#eafbd9',
|
|
22
|
+
},
|
|
23
|
+
primary: {
|
|
24
|
+
color: colors.primary.main,
|
|
25
|
+
backgroundColor: '#ECEFFF',
|
|
26
|
+
},
|
|
27
|
+
reverse: {
|
|
28
|
+
color: '#fff',
|
|
29
|
+
backgroundColor: '#222',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function Tag(props) {
|
|
34
|
+
const newProps = mergeProps(props, Tag, ['style']);
|
|
35
|
+
const { type, content, children, style, className, forwardedRef, ...rest } = newProps;
|
|
36
|
+
const styles = Object.assign({}, types[type] || types.primary, style);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Span ref={forwardedRef} component="span" className={className} style={styles} {...rest}>
|
|
40
|
+
{content || children}
|
|
41
|
+
</Span>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Tag.propTypes = {
|
|
46
|
+
children: PropTypes.any.isRequired,
|
|
47
|
+
type: PropTypes.oneOf(Object.keys(types)),
|
|
48
|
+
content: PropTypes.string,
|
|
49
|
+
className: PropTypes.string,
|
|
50
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Tag.defaultProps = {
|
|
54
|
+
type: 'primary',
|
|
55
|
+
content: '',
|
|
56
|
+
className: '',
|
|
57
|
+
style: {},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default React.forwardRef((props, ref) => <Tag {...props} forwardedRef={ref} />);
|
|
61
|
+
|
|
62
|
+
const Span = styled(Typography)`
|
|
63
|
+
&& {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
align-items: center;
|
|
67
|
+
padding: 2px 10px;
|
|
68
|
+
height: 20px;
|
|
69
|
+
line-height: 20px;
|
|
70
|
+
font-size: 12px;
|
|
71
|
+
font-weight: 500;
|
|
72
|
+
}
|
|
73
|
+
`;
|