@arcblock/ux 2.6.9 → 2.7.1

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.
Files changed (164) hide show
  1. package/babel.config.es.js +12 -0
  2. package/es/ActionButton/index.js +99 -0
  3. package/es/ActivityIndicator/index.js +180 -0
  4. package/es/Address/compact-text.js +105 -0
  5. package/es/Address/did-address.js +211 -0
  6. package/es/Address/index.js +23 -0
  7. package/es/Address/responsive-did-address.js +88 -0
  8. package/es/Alert/index.js +134 -0
  9. package/es/AnimationWaiter/default-animation.json +1 -0
  10. package/es/AnimationWaiter/index.js +239 -0
  11. package/es/Async/index.js +38 -0
  12. package/es/Avatar/did-motif.js +64 -0
  13. package/es/Avatar/etherscan-blockies.js +83 -0
  14. package/es/Avatar/index.js +176 -0
  15. package/es/Badge/index.js +98 -0
  16. package/es/Blocklet/blocklet.js +298 -0
  17. package/es/Blocklet/index.js +4 -0
  18. package/es/Blocklet/utils.js +52 -0
  19. package/es/BlockletNFT/index.js +412 -0
  20. package/es/Button/index.js +8 -0
  21. package/es/Button/wrap.js +140 -0
  22. package/es/ButtonGroup/index.js +6 -0
  23. package/es/CardSelector/index.js +131 -0
  24. package/es/Center/index.js +41 -0
  25. package/es/ClickToCopy/copy-button.js +72 -0
  26. package/es/ClickToCopy/hook.js +39 -0
  27. package/es/ClickToCopy/index.js +93 -0
  28. package/es/CodeBlock/LightBox.js +85 -0
  29. package/es/CodeBlock/index.js +226 -0
  30. package/es/Colors/index.js +2 -0
  31. package/es/Colors/themes/default.js +78 -0
  32. package/es/ContactForm/index.js +230 -0
  33. package/es/CookieConsent/index.js +113 -0
  34. package/es/CountDown/index.js +178 -0
  35. package/es/DID/index.js +105 -0
  36. package/es/Datatable/CustomToolbar.js +396 -0
  37. package/es/Datatable/DatatableContext.js +34 -0
  38. package/es/Datatable/TableSearch.js +165 -0
  39. package/es/Datatable/index.js +627 -0
  40. package/es/Datatable/utils.js +132 -0
  41. package/es/Dialog/confirm.js +90 -0
  42. package/es/Dialog/dialog.js +192 -0
  43. package/es/Dialog/index.js +3 -0
  44. package/es/DidLogo/index.js +31 -0
  45. package/es/DriftBot/index.js +70 -0
  46. package/es/Earth/countries.json +8057 -0
  47. package/es/Earth/index.js +521 -0
  48. package/es/Earth/util.js +51 -0
  49. package/es/Empty/index.js +64 -0
  50. package/es/ErrorBoundary/fallback.js +73 -0
  51. package/es/ErrorBoundary/index.js +1 -0
  52. package/es/Footer/index.js +172 -0
  53. package/es/Header/auto-hidden.js +35 -0
  54. package/es/Header/header.js +211 -0
  55. package/es/Header/index.js +2 -0
  56. package/es/Header/responsive-header.js +111 -0
  57. package/es/Icon/image.js +65 -0
  58. package/es/Icon/index.js +84 -0
  59. package/es/Img/index.js +217 -0
  60. package/es/InfoRow/index.js +87 -0
  61. package/es/Layout/dashboard/external-link.js +58 -0
  62. package/es/Layout/dashboard/full-page.js +53 -0
  63. package/es/Layout/dashboard/index.js +275 -0
  64. package/es/Layout/dashboard/sidebar.js +209 -0
  65. package/es/Layout/dashboard-legacy/header.js +174 -0
  66. package/es/Layout/dashboard-legacy/index.js +149 -0
  67. package/es/Layout/dashboard-legacy/sidebar.js +129 -0
  68. package/es/Layout/index.js +335 -0
  69. package/es/Locale/browser-lang.js +52 -0
  70. package/es/Locale/context.js +114 -0
  71. package/es/Locale/languages.js +60 -0
  72. package/es/Locale/selector.js +180 -0
  73. package/es/Locale/util.js +13 -0
  74. package/es/Logo/images/logo-dark-text.svg +3 -0
  75. package/es/Logo/images/logo-dark-top.svg +6 -0
  76. package/es/Logo/images/logo-light-text.svg +3 -0
  77. package/es/Logo/images/logo-light-top.svg +6 -0
  78. package/es/Logo/index.js +136 -0
  79. package/es/Metric/index.js +132 -0
  80. package/es/NFTDisplay/README.md +59 -0
  81. package/es/NFTDisplay/aspect-ratio-container.js +39 -0
  82. package/es/NFTDisplay/broken.js +18 -0
  83. package/es/NFTDisplay/demo/data/asset-state-display-url.json +7 -0
  84. package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-1-1.json +10 -0
  85. package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-374-130.json +10 -0
  86. package/es/NFTDisplay/demo/data/asset-state-gzipped-svg-with-foreign-object.json +20 -0
  87. package/es/NFTDisplay/demo/data/asset-state-svg.json +29 -0
  88. package/es/NFTDisplay/demo/data/asset-state-url.json +10 -0
  89. package/es/NFTDisplay/index.js +323 -0
  90. package/es/NFTDisplay/loading.js +18 -0
  91. package/es/NFTDisplay/svg-embedder/img.js +45 -0
  92. package/es/NFTDisplay/svg-embedder/inline-svg.js +39 -0
  93. package/es/NavMenu/index.js +2 -0
  94. package/es/NavMenu/nav-menu.js +286 -0
  95. package/es/NavMenu/style.js +176 -0
  96. package/es/PageScroller/index.js +286 -0
  97. package/es/PageScroller/story/FifthComponent.js +9 -0
  98. package/es/PageScroller/story/FirstComponent.js +9 -0
  99. package/es/PageScroller/story/FourthComponent.js +12 -0
  100. package/es/PageScroller/story/FullPage.js +47 -0
  101. package/es/PageScroller/story/PageContain.js +59 -0
  102. package/es/PageScroller/story/SecondComponent.js +9 -0
  103. package/es/PageScroller/story/ThirdComponent.js +9 -0
  104. package/es/PageScroller/story/index.css +115 -0
  105. package/es/PageScroller/usePrevValue.js +9 -0
  106. package/es/PricingTable/PricingPlan.js +124 -0
  107. package/es/PricingTable/index.js +53 -0
  108. package/es/QRCode/index.js +72 -0
  109. package/es/RelativeTime/index.js +98 -0
  110. package/es/Result/common.js +140 -0
  111. package/es/Result/demo/fixtures/result-image-404.svg +1 -0
  112. package/es/Result/index.js +33 -0
  113. package/es/Result/result.js +59 -0
  114. package/es/Result/translations.js +54 -0
  115. package/es/Screenshot/BaseScreenshot/index.js +91 -0
  116. package/es/Screenshot/BaseScreenshot/shells/Macbook.js +51 -0
  117. package/es/Screenshot/BaseScreenshot/shells/Phone.js +36 -0
  118. package/es/Screenshot/demo/images/bg-00.jpg +0 -0
  119. package/es/Screenshot/demo/images/bg-01.jpg +0 -0
  120. package/es/Screenshot/demo/images/bg-02.jpg +0 -0
  121. package/es/Screenshot/demo/images/bg-03.jpg +0 -0
  122. package/es/Screenshot/demo/images/bg-04.jpg +0 -0
  123. package/es/Screenshot/demo/images/bg-05.jpg +0 -0
  124. package/es/Screenshot/demo/images/bg-06.jpg +0 -0
  125. package/es/Screenshot/demo/images/bg-07.jpg +0 -0
  126. package/es/Screenshot/demo/images/bg-08.jpg +0 -0
  127. package/es/Screenshot/demo/images/bg-09.jpg +0 -0
  128. package/es/Screenshot/devices.css +1366 -0
  129. package/es/Screenshot/index.js +299 -0
  130. package/es/SessionManager/federated-login-detecter.js +166 -0
  131. package/es/SessionManager/index.js +468 -0
  132. package/es/SessionManager/user-popper.js +132 -0
  133. package/es/Sparkline/index.js +193 -0
  134. package/es/Spinner/index.js +28 -0
  135. package/es/SplitButton/index.js +144 -0
  136. package/es/Switch/index.js +96 -0
  137. package/es/Tabs/index.js +48 -0
  138. package/es/Tag/index.js +108 -0
  139. package/es/TextCollapse/index.js +92 -0
  140. package/es/Theme/index.js +16 -0
  141. package/es/Theme/theme-provider.js +39 -0
  142. package/es/Theme/theme.js +133 -0
  143. package/es/Toast/index.js +95 -0
  144. package/es/Util/deprecate.js +28 -0
  145. package/es/Util/index.js +298 -0
  146. package/es/Util/wallet.js +32 -0
  147. package/es/Video/index.js +89 -0
  148. package/es/Wallet/Action.js +119 -0
  149. package/es/Wallet/Download.js +331 -0
  150. package/es/Wallet/Open.js +45 -0
  151. package/es/Wallet/images/abtwallet.png +0 -0
  152. package/es/Wallet/images/android_download.svg +23 -0
  153. package/es/Wallet/images/app-store.svg +20 -0
  154. package/es/Wallet/images/google-play.svg +70 -0
  155. package/es/WebWalletSWKeeper/index.js +115 -0
  156. package/es/WechatPrompt/images/android.png +0 -0
  157. package/es/WechatPrompt/images/ios.png +0 -0
  158. package/es/WechatPrompt/index.js +88 -0
  159. package/es/index.js +38 -0
  160. package/es/withTheme/index.js +69 -0
  161. package/es/withTracker/README.md +34 -0
  162. package/es/withTracker/error_boundary.js +34 -0
  163. package/es/withTracker/index.js +56 -0
  164. package/package.json +272 -5
@@ -0,0 +1,193 @@
1
+ /* eslint-disable guard-for-in */
2
+ /* eslint-disable no-restricted-syntax */
3
+ // origin: https://github.com/fnando/sparkline
4
+ function getY(max, height, diff, value) {
5
+ return parseFloat((height - value * height / max + diff).toFixed(2));
6
+ }
7
+ function removeChildren(svg) {
8
+ [...svg.querySelectorAll('*')].forEach(element => svg.removeChild(element));
9
+ }
10
+ function defaultFetch(entry) {
11
+ return entry.value;
12
+ }
13
+ function buildElement(tag, attrs) {
14
+ const element = document.createElementNS('http://www.w3.org/2000/svg', tag);
15
+ for (const name in attrs) {
16
+ element.setAttribute(name, attrs[name]);
17
+ }
18
+ return element;
19
+ }
20
+ export default function sparkline(svg, entries, options) {
21
+ removeChildren(svg);
22
+ if (entries.length <= 1) {
23
+ return;
24
+ }
25
+
26
+ // eslint-disable-next-line no-param-reassign
27
+ options = options || {};
28
+ if (typeof entries[0] === 'number') {
29
+ // eslint-disable-next-line no-param-reassign
30
+ entries = entries.map(entry => {
31
+ return {
32
+ value: entry
33
+ };
34
+ });
35
+ }
36
+
37
+ // This function will be called whenever the mouse moves
38
+ // over the SVG. You can use it to render something like a
39
+ // tooltip.
40
+ const {
41
+ onmousemove
42
+ } = options;
43
+
44
+ // This function will be called whenever the mouse leaves
45
+ // the SVG area. You can use it to hide the tooltip.
46
+ const {
47
+ onmouseout
48
+ } = options;
49
+
50
+ // Should we run in interactive mode? If yes, this will handle the
51
+ // cursor and spot position when moving the mouse.
52
+ const interactive = 'interactive' in options ? options.interactive : !!onmousemove;
53
+
54
+ // Define how big should be the spot area.
55
+ const spotRadius = options.spotRadius || 2;
56
+ const spotDiameter = spotRadius * 2;
57
+
58
+ // Define how wide should be the cursor area.
59
+ const cursorWidth = options.cursorWidth || 2;
60
+
61
+ // Get the stroke width; this is used to compute the
62
+ // rendering offset.
63
+ const strokeWidth = parseFloat(svg.attributes['stroke-width'].value);
64
+
65
+ // By default, data must be formatted as an array of numbers or
66
+ // an array of objects with the value key (like `[{value: 1}]`).
67
+ // You can set a custom function to return data for a different
68
+ // data structure.
69
+ const fetch = options.fetch || defaultFetch;
70
+
71
+ // Retrieve only values, easing the find for the maximum value.
72
+ const values = entries.map(entry => fetch(entry));
73
+
74
+ // The rendering width will account for the spot size.
75
+ const width = parseFloat(svg.attributes.width.value) - spotDiameter * 2;
76
+
77
+ // Get the SVG element's full height.
78
+ // This is used
79
+ const fullHeight = parseFloat(svg.attributes.height.value);
80
+
81
+ // The rendering height accounts for stroke width and spot size.
82
+ const height = fullHeight - strokeWidth * 2 - spotDiameter;
83
+
84
+ // The maximum value. This is used to calculate the Y coord of
85
+ // each sparkline datapoint.
86
+ const max = Math.max(...values) === 0 ? 1 : Math.max(...values);
87
+
88
+ // Some arbitrary value to remove the cursor and spot out of
89
+ // the viewing canvas.
90
+ const offscreen = -1000;
91
+
92
+ // Cache the last item index.
93
+ const lastItemIndex = values.length - 1;
94
+
95
+ // Calculate the X coord base step.
96
+ const offset = width / lastItemIndex;
97
+
98
+ // Hold all datapoints, which is whatever we got as the entry plus
99
+ // x/y coords and the index.
100
+ const datapoints = [];
101
+
102
+ // Hold the line coordinates.
103
+ const pathY = getY(max, height, strokeWidth + spotRadius, values[0]);
104
+ let pathCoords = `M${spotDiameter} ${pathY}`;
105
+ values.forEach((value, index) => {
106
+ const x = index * offset + spotDiameter;
107
+ const y = getY(max, height, strokeWidth + spotRadius, value);
108
+ datapoints.push(Object.assign({}, entries[index], {
109
+ index,
110
+ x,
111
+ y
112
+ }));
113
+ pathCoords += ` L ${x} ${y}`;
114
+ });
115
+ const path = buildElement('path', {
116
+ class: 'sparkline--line',
117
+ d: pathCoords,
118
+ fill: 'none'
119
+ });
120
+ const fillCoords = `${pathCoords} V ${fullHeight} L ${spotDiameter} ${fullHeight} Z`;
121
+ const fill = buildElement('path', {
122
+ class: 'sparkline--fill',
123
+ d: fillCoords,
124
+ stroke: 'none'
125
+ });
126
+ svg.appendChild(fill);
127
+ svg.appendChild(path);
128
+ if (!interactive) {
129
+ return;
130
+ }
131
+ const cursor = buildElement('line', {
132
+ class: 'sparkline--cursor',
133
+ x1: offscreen,
134
+ x2: offscreen,
135
+ y1: 0,
136
+ y2: fullHeight,
137
+ 'stroke-width': cursorWidth
138
+ });
139
+ const spot = buildElement('circle', {
140
+ class: 'sparkline--spot',
141
+ cx: offscreen,
142
+ cy: offscreen,
143
+ r: spotRadius
144
+ });
145
+ svg.appendChild(cursor);
146
+ svg.appendChild(spot);
147
+ const interactionLayer = buildElement('rect', {
148
+ width: svg.attributes.width.value,
149
+ height: svg.attributes.height.value,
150
+ style: 'fill: transparent; stroke: transparent',
151
+ class: 'sparkline--interaction-layer'
152
+ });
153
+ svg.appendChild(interactionLayer);
154
+ interactionLayer.addEventListener('mouseout', event => {
155
+ cursor.setAttribute('x1', offscreen);
156
+ cursor.setAttribute('x2', offscreen);
157
+ spot.setAttribute('cx', offscreen);
158
+ if (onmouseout) {
159
+ onmouseout(event);
160
+ }
161
+ });
162
+ interactionLayer.addEventListener('mousemove', event => {
163
+ const mouseX = event.offsetX;
164
+ let nextDataPoint = datapoints.find(entry => {
165
+ return entry.x >= mouseX;
166
+ });
167
+ if (!nextDataPoint) {
168
+ nextDataPoint = datapoints[lastItemIndex];
169
+ }
170
+ const previousDataPoint = datapoints[datapoints.indexOf(nextDataPoint) - 1];
171
+ let currentDataPoint;
172
+ let halfway;
173
+ if (previousDataPoint) {
174
+ halfway = previousDataPoint.x + (nextDataPoint.x - previousDataPoint.x) / 2;
175
+ currentDataPoint = mouseX >= halfway ? nextDataPoint : previousDataPoint;
176
+ } else {
177
+ currentDataPoint = nextDataPoint;
178
+ }
179
+ const {
180
+ x
181
+ } = currentDataPoint;
182
+ const {
183
+ y
184
+ } = currentDataPoint;
185
+ spot.setAttribute('cx', x);
186
+ spot.setAttribute('cy', y);
187
+ cursor.setAttribute('x1', x);
188
+ cursor.setAttribute('x2', x);
189
+ if (onmousemove) {
190
+ onmousemove(event, currentDataPoint);
191
+ }
192
+ });
193
+ }
@@ -0,0 +1,28 @@
1
+ import CircularProgress from '@mui/material/CircularProgress';
2
+ import { withDeprecated } from '../Util/deprecate';
3
+
4
+ /**
5
+ * Spinner
6
+ *
7
+ * 之前的 Spinner 实现由内外 2 个环构成, 现在改为基于 @mui/material/CircularProgress 的实现
8
+ *
9
+ * - 之前 size prop 是 array 类型, 需要与 CircularProgress#size 兼容
10
+ * - color 默认使用 #4598fa, 如果调用方传入了 color prop 或 style#color, 则默认 color 被覆盖
11
+ */
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ function Spinner(props) {
14
+ const _props = {
15
+ ...props
16
+ };
17
+ // 兼容之前的 size prop (设置外圈/内圈的尺寸)
18
+ if (_props.size && Array.isArray(_props.size)) {
19
+ [_props.size] = _props.size;
20
+ }
21
+ return /*#__PURE__*/_jsx(CircularProgress, {
22
+ ..._props
23
+ });
24
+ }
25
+ export default withDeprecated(Spinner, {
26
+ name: 'Spinner',
27
+ alternative: '@mui/material/CircularProgress'
28
+ });
@@ -0,0 +1,144 @@
1
+ import { useState, useRef, isValidElement } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ExpandMore from '@mui/icons-material/ExpandMore';
4
+ import Popper from '@mui/material/Popper';
5
+ import Paper from '@mui/material/Paper';
6
+ import ClickAwayListener from '@mui/material/ClickAwayListener';
7
+ import MenuList from '@mui/material/MenuList';
8
+ import MenuItem from '@mui/material/MenuItem';
9
+ import ButtonGroup from '@mui/material/ButtonGroup';
10
+ import Button from '@mui/material/Button';
11
+ import { styled } from '../Theme';
12
+
13
+ /**
14
+ * SplitButton 组件 Props
15
+ * @typedef {{
16
+ * size?: 'small' | 'medium' | 'large';
17
+ * color?: 'primary' | 'secondary' | 'inherit';
18
+ * menu?: Array<import('@mui/material').MenuItem> | import('@mui/material').MenuItem;
19
+ * children?: JSX.Element | (() => JSX.Element);
20
+ * variant?: 'outlined' | 'contained';
21
+ * onClick?: () => void;
22
+ * menuButtonProps?: import('@mui/material').ButtonProps;
23
+ * } & import('@mui/material').ButtonGroupProps } SplitButtonProps
24
+ */
25
+
26
+ /**
27
+ * @description SplitButton allows the user to execute a default action which is bound to a Button or to choose a predefined action from a drop-down list.
28
+ * @export
29
+ * @param {SplitButtonProps} props
30
+ * @return {JSX.Element}
31
+ */
32
+ import { createElement as _createElement } from "react";
33
+ import { jsx as _jsx } from "react/jsx-runtime";
34
+ import { jsxs as _jsxs } from "react/jsx-runtime";
35
+ import { Fragment as _Fragment } from "react/jsx-runtime";
36
+ export default function SplitButton(props) {
37
+ const {
38
+ size,
39
+ color,
40
+ menu,
41
+ children,
42
+ variant,
43
+ onClick,
44
+ menuButtonProps,
45
+ ...rest
46
+ } = props;
47
+ const [open, setOpen] = useState(false);
48
+ const anchorRef = useRef(null);
49
+ const menuItems = Array.isArray(menu) ? menu.map((item, index) => /*#__PURE__*/isValidElement(item) ? item : /*#__PURE__*/_createElement(MenuItem, {
50
+ ...item,
51
+ key: index
52
+ })) // eslint-disable-line react/no-array-index-key
53
+ : menu;
54
+ const onToggle = () => {
55
+ setOpen(prevOpen => !prevOpen);
56
+ };
57
+ const handleClose = e => {
58
+ if (anchorRef.current && anchorRef.current.contains(e.target)) {
59
+ return;
60
+ }
61
+ setOpen(false);
62
+ };
63
+
64
+ // 点击 item 后收起下拉菜单, 如果想要点击 action 后不收起下拉菜单, 可以在 item#onClick 时调用 e.stopPropagation()
65
+ const handleItemClick = e => {
66
+ if (e.target.closest('.MuiMenuItem-root')) {
67
+ setOpen(false);
68
+ }
69
+ };
70
+ return /*#__PURE__*/_jsxs(_Fragment, {
71
+ children: [/*#__PURE__*/_jsxs(StyledButtonGroup, {
72
+ variant: variant,
73
+ size: size,
74
+ color: color,
75
+ ref: anchorRef,
76
+ ...rest,
77
+ children: [typeof children === 'function' ? children() : /*#__PURE__*/_jsx(Button, {
78
+ onClick: onClick,
79
+ color: color,
80
+ children: children
81
+ }), /*#__PURE__*/_jsx(Button, {
82
+ onClick: onToggle,
83
+ color: color,
84
+ ...menuButtonProps,
85
+ "aria-label": "more functions",
86
+ children: /*#__PURE__*/_jsx(ExpandMore, {})
87
+ })]
88
+ }), /*#__PURE__*/_jsx(StyledPopper, {
89
+ open: open,
90
+ anchorEl: anchorRef.current,
91
+ placement: "bottom-end",
92
+ disablePortal: false,
93
+ children: /*#__PURE__*/_jsx(Paper, {
94
+ children: /*#__PURE__*/_jsx(ClickAwayListener, {
95
+ onClickAway: handleClose,
96
+ children: /*#__PURE__*/_jsx(MenuList, {
97
+ onClick: handleItemClick,
98
+ children: menuItems
99
+ })
100
+ })
101
+ })
102
+ })]
103
+ });
104
+ }
105
+ SplitButton.propTypes = {
106
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
107
+ color: PropTypes.oneOf(['primary', 'secondary', 'inherit']),
108
+ menu: PropTypes.oneOfType([PropTypes.node, PropTypes.array]),
109
+ // 也可以是用于渲染主按钮的 function
110
+ children: PropTypes.node,
111
+ variant: PropTypes.oneOf(['outlined', 'contained']),
112
+ onClick: PropTypes.func,
113
+ menuButtonProps: PropTypes.object
114
+ };
115
+ SplitButton.defaultProps = {
116
+ size: 'medium',
117
+ color: 'primary',
118
+ menu: [],
119
+ children: null,
120
+ variant: 'contained',
121
+ onClick: () => {},
122
+ menuButtonProps: {}
123
+ };
124
+ /**
125
+ * @type {import('@mui/material').MenuItem}
126
+ */
127
+ SplitButton.Item = MenuItem;
128
+ const StyledButtonGroup = styled(ButtonGroup)`
129
+ > .MuiButtonBase-root:last-of-type {
130
+ min-width: 2em;
131
+ padding-left: 0;
132
+ padding-right: 0;
133
+ }
134
+ `;
135
+ const StyledPopper = styled(Popper)`
136
+ z-index: ${props => props.theme.zIndex.tooltip};
137
+ .MuiList-root {
138
+ padding: 4px 0;
139
+ }
140
+ .MuiListItem-root {
141
+ padding-top: 4px;
142
+ padding-bottom: 4px;
143
+ }
144
+ `;
@@ -0,0 +1,96 @@
1
+ import PropTypes from 'prop-types';
2
+ import FormControlLabel from '@mui/material/FormControlLabel';
3
+ import MuiSwitch from '@mui/material/Switch';
4
+ import { styled } from '../Theme';
5
+
6
+ // 参考: https://mui.com/material-ui/react-switch/#customization
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const IOSSwitch = styled(props => /*#__PURE__*/_jsx(MuiSwitch, {
9
+ focusVisibleClassName: ".Mui-focusVisible",
10
+ disableRipple: true,
11
+ ...props
12
+ }))(({
13
+ theme
14
+ }) => ({
15
+ width: 42,
16
+ height: 26,
17
+ padding: 0,
18
+ '& .MuiSwitch-switchBase': {
19
+ padding: 0,
20
+ margin: 2,
21
+ transitionDuration: '300ms',
22
+ '&.Mui-checked': {
23
+ transform: 'translateX(16px)',
24
+ color: '#fff',
25
+ '& + .MuiSwitch-track': {
26
+ backgroundColor: theme.palette.mode === 'dark' ? '#2ECA45' : '#65C466',
27
+ opacity: 1,
28
+ border: 0
29
+ },
30
+ '&.Mui-disabled + .MuiSwitch-track': {
31
+ opacity: 0.5
32
+ }
33
+ },
34
+ '&.Mui-focusVisible .MuiSwitch-thumb': {
35
+ color: '#33cf4d',
36
+ border: '6px solid #fff'
37
+ },
38
+ '&.Mui-disabled .MuiSwitch-thumb': {
39
+ color: theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[600]
40
+ },
41
+ '&.Mui-disabled + .MuiSwitch-track': {
42
+ opacity: theme.palette.mode === 'light' ? 0.7 : 0.3
43
+ }
44
+ },
45
+ '& .MuiSwitch-thumb': {
46
+ boxSizing: 'border-box',
47
+ width: 22,
48
+ height: 22
49
+ },
50
+ '& .MuiSwitch-track': {
51
+ borderRadius: 26 / 2,
52
+ backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D',
53
+ opacity: 1,
54
+ transition: theme.transitions.create(['background-color'], {
55
+ duration: 500
56
+ })
57
+ }
58
+ }));
59
+
60
+ /**
61
+ * Switch 组件 Props
62
+ * @typedef {{
63
+ * labelProps?: import('@mui/material').FormControlLabelProps;
64
+ * } & import('@mui/material').SwitchProps } SwitchProps
65
+ */
66
+
67
+ /**
68
+ * 抽取 blocklet server 中使用的 iOS 风格的 Switch,
69
+ * 该组件把 FormControlLabel 和 MuiSwitch 组合在一起,
70
+ * 兼容 mui Switch props, 使用 labelProps 控制 FormControlLabel
71
+ * @param {SwitchProps} props
72
+ * @returns {JSX.Element}
73
+ */
74
+ function Switch({
75
+ labelProps,
76
+ ...rest
77
+ }) {
78
+ if (labelProps) {
79
+ return /*#__PURE__*/_jsx(FormControlLabel, {
80
+ control: /*#__PURE__*/_jsx(IOSSwitch, {
81
+ ...rest
82
+ }),
83
+ ...labelProps
84
+ });
85
+ }
86
+ return /*#__PURE__*/_jsx(IOSSwitch, {
87
+ ...rest
88
+ });
89
+ }
90
+ Switch.propTypes = {
91
+ labelProps: PropTypes.object
92
+ };
93
+ Switch.defaultProps = {
94
+ labelProps: null
95
+ };
96
+ export default Switch;
@@ -0,0 +1,48 @@
1
+ import PropTypes from 'prop-types';
2
+ import MuiTabs from '@mui/material/Tabs';
3
+ import MuiTab from '@mui/material/Tab';
4
+ import { styled } from '../Theme';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const PREFIX = 'index';
7
+ const classes = {
8
+ tabs: `${PREFIX}-tabs`,
9
+ tab: `${PREFIX}-tab`
10
+ };
11
+ const StyledMuiTabs = styled(MuiTabs)(({
12
+ theme
13
+ }) => ({
14
+ [`& .${classes.tabs}`]: {},
15
+ [`& .${classes.tab}`]: {
16
+ fontSize: '0.875rem',
17
+ [theme.breakpoints.up('md')]: {
18
+ fontSize: '1rem'
19
+ }
20
+ }
21
+ }));
22
+ export default function Tabs({
23
+ tabs,
24
+ current,
25
+ onChange,
26
+ ...rest
27
+ }) {
28
+ return /*#__PURE__*/_jsx(StyledMuiTabs, {
29
+ scrollButtons: "auto",
30
+ variant: "scrollable",
31
+ value: current,
32
+ onChange: (_, newValue) => onChange(newValue),
33
+ indicatorColor: "primary",
34
+ ...rest,
35
+ className: [classes.tabs, rest.className || ''].join(' '),
36
+ children: tabs.map(x => /*#__PURE__*/_jsx(MuiTab, {
37
+ className: classes.tab,
38
+ value: x.value,
39
+ label: x.label,
40
+ icon: x.icon || null
41
+ }, x.value))
42
+ });
43
+ }
44
+ Tabs.propTypes = {
45
+ tabs: PropTypes.array.isRequired,
46
+ current: PropTypes.string.isRequired,
47
+ onChange: PropTypes.func.isRequired
48
+ };
@@ -0,0 +1,108 @@
1
+ import { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Typography from '@mui/material/Typography';
4
+ import { mergeProps } from '../Util';
5
+ import colors from '../Colors';
6
+ import { useTheme, styled } from '../Theme';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const types = {
9
+ error: {
10
+ color: colors.common.white,
11
+ backgroundColor: colors.error.main
12
+ },
13
+ warning: {
14
+ color: colors.common.white,
15
+ backgroundColor: colors.warning.main
16
+ },
17
+ success: {
18
+ color: colors.common.white,
19
+ backgroundColor: colors.success.main
20
+ },
21
+ primary: {
22
+ color: colors.common.white,
23
+ backgroundColor: colors.primary.main
24
+ },
25
+ reverse: {
26
+ color: '#fff',
27
+ backgroundColor: '#222'
28
+ }
29
+ };
30
+
31
+ /**
32
+ * @typedef {{
33
+ * type: 'error' | 'warning' | 'success' | 'primary' | 'reverse',
34
+ * content: string,
35
+ * className: string;
36
+ * children: import('react').ReactNode,
37
+ * style: import('react').CSSProperties
38
+ * }} TagProps
39
+ */
40
+
41
+ /**
42
+ * @description
43
+ * @param {TagProps} props
44
+ * @return {import('react').ReactNode}
45
+ */
46
+ function Tag(props) {
47
+ const newProps = mergeProps(props, Tag, ['style']);
48
+ const {
49
+ type,
50
+ content,
51
+ children,
52
+ style,
53
+ className,
54
+ forwardedRef,
55
+ ...rest
56
+ } = newProps;
57
+ const {
58
+ palette
59
+ } = useTheme();
60
+ const styles = Object.assign({}, types[type] || types.primary, style);
61
+ if (palette[type]) {
62
+ Object.assign(styles, {
63
+ color: palette[type].contrastText || colors.common.white,
64
+ backgroundColor: palette[type].main
65
+ });
66
+ }
67
+ return /*#__PURE__*/_jsx(Span, {
68
+ ref: forwardedRef,
69
+ component: "span",
70
+ className: className,
71
+ style: styles,
72
+ ...rest,
73
+ children: content || children
74
+ });
75
+ }
76
+ Tag.propTypes = {
77
+ children: PropTypes.any.isRequired,
78
+ type: PropTypes.oneOf(Object.keys(types)),
79
+ content: PropTypes.string,
80
+ className: PropTypes.string,
81
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
82
+ };
83
+ Tag.defaultProps = {
84
+ type: 'primary',
85
+ content: '',
86
+ className: '',
87
+ style: {}
88
+ };
89
+
90
+ /** @type {React.ForwardRefExoticComponent<React.PropsWithoutRef<TagProps> & React.RefAttributes<HTMLSpanElement>>} */
91
+ const TagComponent = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(Tag, {
92
+ ...props,
93
+ forwardedRef: ref
94
+ }));
95
+ export default TagComponent;
96
+ const Span = styled(Typography)`
97
+ && {
98
+ display: inline-flex;
99
+ justify-content: center;
100
+ align-items: center;
101
+ padding: 2px 10px;
102
+ height: 20px;
103
+ line-height: 20px;
104
+ font-size: 12px;
105
+ font-weight: 500;
106
+ border-radius: 4px;
107
+ }
108
+ `;