@arcblock/ux 0.78.26 → 1.6.60

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 (174) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +0 -56
  3. package/lib/ActionButton/index.js +6 -4
  4. package/lib/ActivityIndicator/index.js +75 -23
  5. package/lib/Alert/index.js +15 -11
  6. package/lib/Async/index.js +1 -1
  7. package/lib/Badge/index.js +17 -15
  8. package/lib/Blocklet/index.js +261 -0
  9. package/lib/Button/wrap.js +96 -43
  10. package/lib/ButtonGroup/index.js +3 -16
  11. package/lib/Center/index.js +30 -4
  12. package/lib/ClickToCopy/index.js +10 -8
  13. package/lib/CodeBlock/index.js +40 -13
  14. package/lib/Colors/index.js +15 -0
  15. package/lib/Colors/themes/default.js +85 -0
  16. package/lib/ContactForm/index.js +9 -10
  17. package/lib/CookieConsent/index.js +98 -0
  18. package/lib/CountDown/index.js +18 -14
  19. package/lib/Dialog/confirm.js +84 -0
  20. package/lib/Dialog/dialog.js +137 -0
  21. package/lib/Dialog/index.js +23 -0
  22. package/lib/Earth/index.js +33 -33
  23. package/lib/Empty/index.js +61 -0
  24. package/lib/Footer/index.js +16 -18
  25. package/lib/Icon/image.js +10 -13
  26. package/lib/Icon/index.js +10 -8
  27. package/lib/Img/index.js +212 -0
  28. package/lib/InfoRow/index.js +7 -6
  29. package/lib/Layout/dashboard/header.js +60 -42
  30. package/lib/Layout/dashboard/index.js +72 -60
  31. package/lib/Layout/dashboard/sidebar.js +41 -25
  32. package/lib/Layout/index.js +113 -51
  33. package/lib/Locale/browser-lang.js +0 -2
  34. package/lib/Locale/context.js +85 -61
  35. package/lib/Locale/selector.js +33 -20
  36. package/lib/Logo/index.js +15 -13
  37. package/lib/Metric/index.js +5 -6
  38. package/lib/NFTDisplay/README.md +59 -0
  39. package/lib/NFTDisplay/aspect-ratio-container.js +52 -0
  40. package/lib/NFTDisplay/broken.js +25 -0
  41. package/lib/NFTDisplay/index.js +317 -0
  42. package/lib/NFTDisplay/loading.js +23 -0
  43. package/lib/NFTDisplay/svg-embedder/img.js +68 -0
  44. package/lib/NFTDisplay/svg-embedder/inline-svg.js +54 -0
  45. package/lib/PageScroller/index.js +10 -11
  46. package/lib/PageScroller/usePrevValue.js +2 -2
  47. package/lib/PricingTable/PricingPlan.js +12 -15
  48. package/lib/PricingTable/index.js +5 -5
  49. package/lib/QRCode/index.js +89 -0
  50. package/lib/Result/common.js +176 -0
  51. package/lib/Result/index.js +61 -0
  52. package/lib/Result/result.js +69 -0
  53. package/lib/Result/translations.js +61 -0
  54. package/lib/Screenshot/index.js +14 -13
  55. package/lib/Spinner/index.js +37 -0
  56. package/lib/SplitButton/index.js +126 -0
  57. package/lib/Switch/index.js +107 -0
  58. package/lib/Tabs/index.js +24 -47
  59. package/lib/Tag/index.js +15 -13
  60. package/lib/Terminal/Player.js +43 -45
  61. package/lib/Terminal/index.js +3 -1
  62. package/lib/Terminal/util.js +2 -3
  63. package/lib/TextCollapse/index.js +21 -14
  64. package/lib/Theme/index.js +79 -63
  65. package/lib/Theme/responsiveFontSizes.js +8 -8
  66. package/lib/Toast/index.js +12 -11
  67. package/lib/Util/index.js +197 -26
  68. package/lib/Video/index.js +8 -11
  69. package/lib/Wallet/Action.js +15 -13
  70. package/lib/Wallet/Download.js +60 -58
  71. package/lib/Wallet/Open.js +2 -2
  72. package/lib/WechatPrompt/index.js +10 -10
  73. package/lib/index.js +6 -6
  74. package/lib/withTheme/index.js +5 -17
  75. package/lib/withTracker/error_boundary.js +3 -3
  76. package/lib/withTracker/index.js +6 -7
  77. package/package.json +23 -17
  78. package/src/ActionButton/index.js +65 -0
  79. package/src/ActivityIndicator/index.js +141 -0
  80. package/src/Alert/index.js +104 -0
  81. package/src/Async/index.js +39 -0
  82. package/src/Badge/index.js +71 -0
  83. package/src/Blocklet/index.js +424 -0
  84. package/src/Button/index.js +4 -0
  85. package/src/Button/wrap.js +101 -0
  86. package/src/ButtonGroup/index.js +6 -0
  87. package/src/Center/index.js +40 -0
  88. package/src/ClickToCopy/index.js +90 -0
  89. package/src/CodeBlock/index.js +160 -0
  90. package/src/Colors/index.js +1 -0
  91. package/src/Colors/themes/default.js +54 -0
  92. package/src/ContactForm/index.js +240 -0
  93. package/src/CookieConsent/index.js +90 -0
  94. package/src/CountDown/index.js +151 -0
  95. package/src/Dialog/confirm.js +76 -0
  96. package/src/Dialog/dialog.js +162 -0
  97. package/src/Dialog/index.js +2 -0
  98. package/src/DriftBot/index.js +81 -0
  99. package/src/Earth/countries.json +8057 -0
  100. package/src/Earth/index.js +511 -0
  101. package/src/Earth/util.js +69 -0
  102. package/src/Empty/index.js +41 -0
  103. package/src/Footer/index.js +110 -0
  104. package/src/Icon/image.js +55 -0
  105. package/src/Icon/index.js +69 -0
  106. package/src/Img/index.js +172 -0
  107. package/src/InfoRow/index.js +83 -0
  108. package/src/Layout/dashboard/header.js +157 -0
  109. package/src/Layout/dashboard/index.js +150 -0
  110. package/src/Layout/dashboard/sidebar.js +122 -0
  111. package/src/Layout/index.js +318 -0
  112. package/src/Locale/browser-lang.js +63 -0
  113. package/src/Locale/context.js +94 -0
  114. package/src/Locale/images/globe-dark.png +0 -0
  115. package/src/Locale/images/globe-light.png +0 -0
  116. package/src/Locale/selector.js +135 -0
  117. package/src/Logo/images/logo-dark-text.svg +3 -0
  118. package/src/Logo/images/logo-dark-top.svg +6 -0
  119. package/src/Logo/images/logo-light-text.svg +3 -0
  120. package/src/Logo/images/logo-light-top.svg +6 -0
  121. package/src/Logo/index.js +47 -0
  122. package/src/Metric/index.js +115 -0
  123. package/src/NFTDisplay/README.md +59 -0
  124. package/src/NFTDisplay/aspect-ratio-container.js +34 -0
  125. package/src/NFTDisplay/broken.js +18 -0
  126. package/src/NFTDisplay/index.js +257 -0
  127. package/src/NFTDisplay/loading.js +17 -0
  128. package/src/NFTDisplay/svg-embedder/img.js +36 -0
  129. package/src/NFTDisplay/svg-embedder/inline-svg.js +37 -0
  130. package/src/PageScroller/index.js +342 -0
  131. package/src/PageScroller/usePrevValue.js +12 -0
  132. package/src/PricingTable/PricingPlan.js +112 -0
  133. package/src/PricingTable/index.js +43 -0
  134. package/src/QRCode/index.js +56 -0
  135. package/src/Result/common.js +116 -0
  136. package/src/Result/index.js +31 -0
  137. package/src/Result/result.js +57 -0
  138. package/src/Result/translations.js +56 -0
  139. package/src/Screenshot/devices.css +1366 -0
  140. package/src/Screenshot/index.js +181 -0
  141. package/src/Spinner/index.js +19 -0
  142. package/src/SplitButton/index.js +112 -0
  143. package/src/Switch/index.js +78 -0
  144. package/src/Tabs/index.js +46 -0
  145. package/src/Tag/index.js +73 -0
  146. package/src/Terminal/Player.js +364 -0
  147. package/src/Terminal/index.js +150 -0
  148. package/src/Terminal/player.css +378 -0
  149. package/src/Terminal/util.js +167 -0
  150. package/src/Terminal/xterm.css +171 -0
  151. package/src/TextCollapse/index.js +92 -0
  152. package/src/Theme/index.js +184 -0
  153. package/src/Theme/responsiveFontSizes.js +94 -0
  154. package/src/Toast/index.js +118 -0
  155. package/src/Util/index.js +281 -0
  156. package/src/Video/index.js +72 -0
  157. package/src/Wallet/Action.js +105 -0
  158. package/src/Wallet/Download.js +130 -0
  159. package/src/Wallet/Open.js +50 -0
  160. package/src/Wallet/images/abtwallet.png +0 -0
  161. package/src/Wallet/images/android_download.svg +23 -0
  162. package/src/Wallet/images/app-store.svg +20 -0
  163. package/src/Wallet/images/google-play.svg +70 -0
  164. package/src/WechatPrompt/images/android.png +0 -0
  165. package/src/WechatPrompt/images/ios.png +0 -0
  166. package/src/WechatPrompt/index.js +81 -0
  167. package/src/index.js +63 -0
  168. package/src/withTheme/index.js +72 -0
  169. package/src/withTracker/README.md +34 -0
  170. package/src/withTracker/error_boundary.js +34 -0
  171. package/src/withTracker/index.js +70 -0
  172. package/lib/GraphQLPlayground/graphiql.css +0 -1850
  173. package/lib/GraphQLPlayground/index.js +0 -302
  174. package/lib/GraphQLPlayground/util.js +0 -55
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import Typography from '@material-ui/core/Typography';
5
+ import styled from 'styled-components';
6
+
7
+ export default function TextCollapse({
8
+ children,
9
+ startChars,
10
+ endChars,
11
+ scaleFactor,
12
+ maxWidth,
13
+ style,
14
+ fontType,
15
+ ...rest
16
+ }) {
17
+ if (typeof children !== 'string') {
18
+ return null;
19
+ }
20
+
21
+ const isMonospace = fontType === 'monospace';
22
+
23
+ // 由于 css 样式产生的省略号长度是不确定的,所以目前 startChars 的长度只能让开发者自己去加上‘省略号’的宽度去设置这个值,要想完美的实现目标功能,最好是改用 js 动态修改文本内容来实现
24
+ const startWidth = isMonospace ? `${startChars}ch` : `${scaleFactor * (startChars + 3)}em`;
25
+ const endWidth = isMonospace ? `${endChars}ch` : `${scaleFactor * endChars}em`;
26
+ const styles = Object.assign(
27
+ isMonospace ? { fontFamily: '"Courier New", Courier, monospace' } : {},
28
+ { fontSize: 'inherit', color: 'inherit', fontWeight: 'inherit', maxWidth },
29
+ style
30
+ );
31
+
32
+ const [startPart, endPart] = [
33
+ children.slice(0, children.length - endChars),
34
+ children.slice(children.length - endChars),
35
+ ];
36
+
37
+ return (
38
+ <Container
39
+ component="span"
40
+ style={styles}
41
+ startwidth={startWidth}
42
+ endwidth={endWidth}
43
+ {...rest}>
44
+ <span className="start-part">{startPart}</span>
45
+ <span className="end-part">{endPart}</span>
46
+ </Container>
47
+ );
48
+ }
49
+
50
+ TextCollapse.propTypes = {
51
+ children: PropTypes.string.isRequired,
52
+ maxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
53
+ fontType: PropTypes.oneOf(['monospace', 'normal']),
54
+ style: PropTypes.object,
55
+ startChars: PropTypes.number,
56
+ endChars: PropTypes.number,
57
+ scaleFactor: PropTypes.number,
58
+ };
59
+
60
+ TextCollapse.defaultProps = {
61
+ style: {},
62
+ startChars: 5,
63
+ endChars: 5,
64
+ scaleFactor: 0.45,
65
+ fontType: 'normal',
66
+ };
67
+
68
+ const Container = styled(Typography)`
69
+ display: inline-flex;
70
+ align-items: center;
71
+ justify-content: start;
72
+ cursor: pointer;
73
+ white-space: nowrap;
74
+ overflow: hidden;
75
+
76
+ .start-part,
77
+ .end-part {
78
+ display: inline-block;
79
+ vertical-align: bottom;
80
+ white-space: nowrap;
81
+ overflow: hidden;
82
+ }
83
+ .start-part {
84
+ max-width: calc(100% - ${props => props.endwidth});
85
+ min-width: ${props => props.startwidth};
86
+ text-overflow: ellipsis;
87
+ }
88
+ .end-part {
89
+ max-width: calc(100% - ${props => props.startwidth});
90
+ direction: rtl;
91
+ }
92
+ `;
@@ -0,0 +1,184 @@
1
+ // https://app.zeplin.io/styleguide/5d1436f1e97c2156f49c0725/colors
2
+ import { createTheme } from '@material-ui/core/styles';
3
+ import '@fontsource/lato/400.css';
4
+ import '@fontsource/lato/700.css';
5
+ import responsiveFontSizes from './responsiveFontSizes';
6
+ import colors from '../Colors';
7
+
8
+ // https://material-ui.com/customization/default-theme/
9
+ // eslint-disable-next-line import/prefer-default-export
10
+ export const create = ({
11
+ mode = 'light',
12
+ pageWidth = 'md',
13
+ palette,
14
+ typography,
15
+ overrides,
16
+ ...rest
17
+ } = {}) => {
18
+ const theme = createTheme({
19
+ themeName: 'ArcBlock',
20
+ palette: Object.assign(
21
+ {
22
+ ...colors,
23
+ background: {
24
+ paper: mode === 'light' ? colors.common.white : colors.grey[900],
25
+ default: mode === 'light' ? colors.background.default : colors.grey[900],
26
+ },
27
+ type: mode,
28
+ },
29
+ palette || {}
30
+ ),
31
+ typography: Object.assign(
32
+ {
33
+ useNextVariants: true,
34
+ color: {
35
+ // 此处 #222222 必须硬编码, layout/sidebar.js -> Icon/image 加载图片时 color 会影响加载路径
36
+ // TODO: 此处硬编码的色值后面需要改为 colors.grey[900],
37
+ // 或者如果可以的话直接删掉 typography#color, 文本颜色建议使用 theme.palette.text 中的色值?
38
+ // layout 组件建议重构, sidebar 中建议使用 icon 替换 img (#366)
39
+ main: mode === 'light' ? '#222222' : colors.common.white,
40
+ gray: mode === 'light' ? colors.grey[500] : colors.grey[300],
41
+ },
42
+ fontFamily: [
43
+ 'Lato',
44
+ 'Avenir',
45
+ '-apple-system',
46
+ 'BlinkMacSystemFont',
47
+ '"Segoe UI"',
48
+ 'Roboto',
49
+ '"Helvetica Neue"',
50
+ 'Arial',
51
+ 'sans-serif',
52
+ '"Apple Color Emoji"',
53
+ '"Segoe UI Emoji"',
54
+ '"Segoe UI Symbol"',
55
+ ].join(','),
56
+ // 按最新设计规范, 只使用 400/700
57
+ fontWeightLight: 400,
58
+ fontWeightRegular: 400,
59
+ fontWeightMedium: 700,
60
+ fontWeightBold: 700,
61
+ // button 默认使用粗体
62
+ button: {
63
+ fontWeight: 700,
64
+ },
65
+ },
66
+ typography || {}
67
+ ),
68
+ overrides: Object.assign(
69
+ {
70
+ MuiButton: {
71
+ root: {
72
+ boxShadow: 'none',
73
+ },
74
+ },
75
+ MuiButtonGroup: {
76
+ contained: {
77
+ boxShadow: 'none',
78
+ },
79
+ },
80
+ MuiAppBar: {
81
+ root: {
82
+ height: 80,
83
+ },
84
+ },
85
+ MuiToolbar: {
86
+ root: {
87
+ background: mode === 'light' ? colors.background.default : colors.grey[900],
88
+ },
89
+ },
90
+ MuiTableCell: {
91
+ root: {
92
+ borderBottomWidth: '0',
93
+ paddingTop: '14px',
94
+ paddingBottom: '14px',
95
+ paddingLeft: 0,
96
+ paddingRight: '30px',
97
+ },
98
+ head: {
99
+ textTransform: 'uppercase',
100
+ color: mode === 'light' ? colors.grey[900] : colors.grey[300],
101
+ },
102
+ body: {
103
+ color: mode === 'light' ? colors.grey[900] : colors.grey[300],
104
+ },
105
+ },
106
+ MuiChip: {
107
+ root: {
108
+ padding: '3px',
109
+ height: '24px',
110
+ fontSize: '12px',
111
+ marginRight: '10px',
112
+ },
113
+ label: {
114
+ paddingLeft: '5px',
115
+ paddingRight: '5px',
116
+ marginRight: '5px',
117
+ },
118
+ },
119
+ MuiTooltip: {
120
+ tooltip: {
121
+ fontSize: '14px',
122
+ },
123
+ },
124
+ MuiTypography: {
125
+ body1: {
126
+ color: mode === 'light' ? colors.grey[900] : colors.grey[300],
127
+ },
128
+ body2: {
129
+ color: mode === 'light' ? colors.grey[900] : colors.grey[300],
130
+ },
131
+ },
132
+ },
133
+ overrides || {}
134
+ ),
135
+ pageWidth,
136
+ // TODO: 过时的 colors, 需要各项目负责人检查项目中是否使用 "theme.colors", 如果有需要清除,
137
+ // 可以从 Colors 模块/theme.palette/mui colors 中取值
138
+ colors: {
139
+ white: '#FFFFFF',
140
+ dark: '#4A707C',
141
+ gray: '#222222',
142
+ minor: '#9B9B9B',
143
+ darkText: '#DCDCDC',
144
+ background: '#F7F8F8',
145
+ yellow: '#FFCF71',
146
+ green: '#44cdc6',
147
+ red: '#D0021B',
148
+ blue: '#4E6AF6',
149
+ primary: '#222222',
150
+ black: '#222222',
151
+ secondary: '#44cdc6',
152
+ mint: '#44cdc6',
153
+ textSecondary: '#4A4A4A',
154
+ active: '#5b9025',
155
+ danger: '#D0021B',
156
+ lightGrey: '#BCBCBC',
157
+ },
158
+ mode,
159
+ ...rest,
160
+ });
161
+
162
+ const enhanced = responsiveFontSizes(theme, {
163
+ breakpoints: ['xs', 'sm', 'md', 'lg'],
164
+ disableAlign: false,
165
+ factor: 3,
166
+ variants: [
167
+ 'h1',
168
+ 'h2',
169
+ 'h3',
170
+ 'h4',
171
+ 'h5',
172
+ 'h6',
173
+ 'subtitle1',
174
+ 'subtitle2',
175
+ 'body1',
176
+ 'body2',
177
+ 'caption',
178
+ 'button',
179
+ 'overline',
180
+ ],
181
+ });
182
+
183
+ return enhanced;
184
+ };
@@ -0,0 +1,94 @@
1
+ // https://github.com/mui-org/material-ui/blob/f2d74e9144ffec1ba6a098528573c7dfb3957b48/packages/material-ui/src/styles/responsiveFontSizes.js
2
+ import {
3
+ isUnitless,
4
+ convertLength,
5
+ responsiveProperty,
6
+ alignProperty,
7
+ fontGrid,
8
+ } from '@material-ui/core/styles/cssUtils';
9
+
10
+ export default function responsiveFontSizes(themeInput, options = {}) {
11
+ const {
12
+ breakpoints = ['sm', 'md', 'lg'],
13
+ disableAlign = false,
14
+ factor = 3,
15
+ maxSize = 2.5,
16
+ // minSize = 0.8,
17
+ variants = [
18
+ 'h1',
19
+ 'h2',
20
+ 'h3',
21
+ 'h4',
22
+ 'h5',
23
+ 'h6',
24
+ 'subtitle1',
25
+ 'subtitle2',
26
+ 'body1',
27
+ 'body2',
28
+ 'caption',
29
+ 'button',
30
+ 'overline',
31
+ ],
32
+ } = options;
33
+
34
+ const theme = { ...themeInput };
35
+ theme.typography = { ...theme.typography };
36
+ const { typography } = theme;
37
+
38
+ // Convert between css lengths e.g. em->px or px->rem
39
+ // Set the baseFontSize for your project. Defaults to 16px (also the browser default).
40
+ const convert = convertLength(typography.htmlFontSize);
41
+ const breakpointValues = breakpoints.map(x => theme.breakpoints.values[x]);
42
+
43
+ variants.forEach(variant => {
44
+ const style = typography[variant];
45
+ const remFontSize = parseFloat(convert(style.fontSize, 'rem'));
46
+
47
+ if (remFontSize <= 1) {
48
+ return;
49
+ }
50
+
51
+ const maxFontSize = Math.min(remFontSize, maxSize);
52
+ const minFontSize = 1 + (maxFontSize - 1) / factor;
53
+
54
+ let { lineHeight } = style;
55
+
56
+ if (!isUnitless(lineHeight) && !disableAlign) {
57
+ throw new Error(
58
+ [
59
+ 'Material-UI: unsupported non-unitless line height with grid alignment.',
60
+ 'Use unitless line heights instead.',
61
+ ].join('\n')
62
+ );
63
+ }
64
+
65
+ if (!isUnitless(lineHeight)) {
66
+ // make it unitless
67
+ lineHeight = parseFloat(convert(lineHeight, 'rem')) / parseFloat(remFontSize);
68
+ }
69
+
70
+ let transform = null;
71
+
72
+ if (!disableAlign) {
73
+ transform = value =>
74
+ alignProperty({
75
+ size: value,
76
+ grid: fontGrid({ pixels: 4, lineHeight, htmlFontSize: typography.htmlFontSize }),
77
+ });
78
+ }
79
+
80
+ typography[variant] = {
81
+ ...style,
82
+ ...responsiveProperty({
83
+ cssProperty: 'fontSize',
84
+ min: minFontSize,
85
+ max: maxFontSize,
86
+ unit: 'rem',
87
+ breakpoints: breakpointValues,
88
+ transform,
89
+ }),
90
+ };
91
+ });
92
+
93
+ return theme;
94
+ }
@@ -0,0 +1,118 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import CheckCircleIcon from '@material-ui/icons/CheckCircle';
5
+ import ErrorIcon from '@material-ui/icons/Error';
6
+ import InfoIcon from '@material-ui/icons/Info';
7
+ import CloseIcon from '@material-ui/icons/Close';
8
+ import WarningIcon from '@material-ui/icons/Warning';
9
+ import IconButton from '@material-ui/core/IconButton';
10
+ import Snackbar from '@material-ui/core/Snackbar';
11
+ import SnackbarContent from '@material-ui/core/SnackbarContent';
12
+ import { amber, green } from '@material-ui/core/colors';
13
+ import { makeStyles } from '@material-ui/core/styles';
14
+
15
+ const variantIcon = {
16
+ success: CheckCircleIcon,
17
+ warning: WarningIcon,
18
+ error: ErrorIcon,
19
+ info: InfoIcon,
20
+ };
21
+
22
+ const useStyles1 = makeStyles(theme => ({
23
+ success: {
24
+ backgroundColor: green[600],
25
+ },
26
+ error: {
27
+ backgroundColor: theme.palette.error.dark,
28
+ },
29
+ info: {
30
+ backgroundColor: theme.palette.primary.main,
31
+ },
32
+ warning: {
33
+ backgroundColor: amber[700],
34
+ },
35
+ icon: {
36
+ fontSize: 20,
37
+ },
38
+ iconVariant: {
39
+ opacity: 0.9,
40
+ marginRight: theme.spacing(1),
41
+ },
42
+ message: {
43
+ display: 'flex',
44
+ alignItems: 'center',
45
+ },
46
+ }));
47
+
48
+ function SnackbarContentWrapper(props) {
49
+ const classes = useStyles1();
50
+ const { className, message, onClose, variant, ...rest } = props;
51
+ const Icon = variantIcon[variant];
52
+
53
+ return (
54
+ <SnackbarContent
55
+ className={[classes[variant], className].join(' ').trim()}
56
+ message={
57
+ <span id="client-snackbar" className={classes.message}>
58
+ <Icon className={[classes.icon, classes.iconVariant].join(' ').trim()} />
59
+ {message}
60
+ </span>
61
+ }
62
+ action={[
63
+ <IconButton key="close" aria-label="close" color="inherit" onClick={onClose}>
64
+ <CloseIcon className={classes.icon} />
65
+ </IconButton>,
66
+ ]}
67
+ {...rest}
68
+ />
69
+ );
70
+ }
71
+
72
+ SnackbarContentWrapper.propTypes = {
73
+ message: PropTypes.string.isRequired,
74
+ onClose: PropTypes.func.isRequired,
75
+ className: PropTypes.string,
76
+ variant: PropTypes.oneOf(['error', 'info', 'success', 'warning']),
77
+ };
78
+
79
+ SnackbarContentWrapper.defaultProps = {
80
+ className: '',
81
+ variant: 'success',
82
+ };
83
+
84
+ export default function Toast({ onClose, variant, duration, message }) {
85
+ const [open, setOpen] = React.useState(true);
86
+
87
+ const handleClose = (e, reason) => {
88
+ if (reason === 'clickaway') {
89
+ return;
90
+ }
91
+
92
+ setOpen(false);
93
+ onClose();
94
+ };
95
+
96
+ return (
97
+ <Snackbar
98
+ open={open}
99
+ anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
100
+ autoHideDuration={duration}
101
+ onClose={handleClose}>
102
+ <SnackbarContentWrapper onClose={handleClose} variant={variant} message={message} />
103
+ </Snackbar>
104
+ );
105
+ }
106
+
107
+ Toast.propTypes = {
108
+ message: PropTypes.string.isRequired,
109
+ variant: PropTypes.string,
110
+ duration: PropTypes.number,
111
+ onClose: PropTypes.func,
112
+ };
113
+
114
+ Toast.defaultProps = {
115
+ variant: 'success',
116
+ duration: 3000,
117
+ onClose: () => {},
118
+ };