@cloudflare/component-notifications 10.0.18 → 10.1.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.
- package/CHANGELOG.md +8 -0
- package/dist/Notification.d.ts +30 -0
- package/dist/NotificationGlobalContainer.d.ts +7 -0
- package/dist/NotificationItem.d.ts +10 -0
- package/dist/NotificationList.d.ts +82 -0
- package/dist/index.d.ts +4 -0
- package/dist/utils.d.ts +4 -0
- package/es/Notification.js +18 -161
- package/es/NotificationGlobalContainer.js +5 -12
- package/es/NotificationItem.js +101 -0
- package/es/NotificationList.js +2 -8
- package/es/utils.js +33 -0
- package/lib/Notification.js +19 -164
- package/lib/NotificationGlobalContainer.js +4 -13
- package/lib/NotificationItem.js +115 -0
- package/lib/NotificationList.js +1 -9
- package/lib/utils.js +46 -0
- package/package.json +5 -3
- package/src/Notification.tsx +171 -0
- package/src/NotificationGlobalContainer.tsx +33 -0
- package/src/NotificationItem.tsx +120 -0
- package/src/NotificationList.tsx +18 -0
- package/src/utils.ts +37 -0
- package/src/Notification.js +0 -291
- package/src/NotificationGlobalContainer.js +0 -26
- package/src/NotificationList.js +0 -20
- /package/src/{index.js → index.ts} +0 -0
package/lib/Notification.js
CHANGED
|
@@ -9,15 +9,13 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
|
-
var _styleConst = require("@cloudflare/style-const");
|
|
15
|
-
|
|
16
12
|
var _raf = _interopRequireDefault(require("raf"));
|
|
17
13
|
|
|
18
14
|
var _styleContainer = require("@cloudflare/style-container");
|
|
19
15
|
|
|
20
|
-
var
|
|
16
|
+
var _NotificationItem = _interopRequireDefault(require("./NotificationItem"));
|
|
17
|
+
|
|
18
|
+
var _utils = require("./utils");
|
|
21
19
|
|
|
22
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
21
|
|
|
@@ -41,75 +39,11 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
41
39
|
|
|
42
40
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
switch (type) {
|
|
46
|
-
case 'success':
|
|
47
|
-
return theme.colors.green[5];
|
|
48
|
-
|
|
49
|
-
case 'warning':
|
|
50
|
-
return theme.colors.orange[5];
|
|
51
|
-
|
|
52
|
-
case 'error':
|
|
53
|
-
return theme.colors.red[2];
|
|
54
|
-
|
|
55
|
-
case 'info':
|
|
56
|
-
default:
|
|
57
|
-
return theme.colors.blue[3];
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var getBackgroundColor = function getBackgroundColor(type, theme) {
|
|
62
|
-
switch (type) {
|
|
63
|
-
case 'success':
|
|
64
|
-
return theme.colors.green[(0, _styleConst.isDarkMode)() ? 3 : 6];
|
|
65
|
-
|
|
66
|
-
case 'warning':
|
|
67
|
-
return theme.colors.orange[(0, _styleConst.isDarkMode)() ? 3 : 6];
|
|
68
|
-
|
|
69
|
-
case 'error':
|
|
70
|
-
return theme.colors.red[3];
|
|
42
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
71
43
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
var NotificationMessage = (0, _styleContainer.createComponent)(function (_ref) {
|
|
79
|
-
var theme = _ref.theme;
|
|
80
|
-
return {
|
|
81
|
-
position: 'relative',
|
|
82
|
-
zIndex: 2,
|
|
83
|
-
color: theme.colors.white,
|
|
84
|
-
display: 'flex',
|
|
85
|
-
alignItems: 'center'
|
|
86
|
-
};
|
|
87
|
-
}, 'span');
|
|
88
|
-
var NotificationClose = (0, _styleContainer.createComponent)(function (_ref2) {
|
|
89
|
-
var theme = _ref2.theme,
|
|
90
|
-
type = _ref2.type;
|
|
91
|
-
return {
|
|
92
|
-
position: 'absolute',
|
|
93
|
-
zIndex: 3,
|
|
94
|
-
top: 0,
|
|
95
|
-
right: 0,
|
|
96
|
-
bottom: 0,
|
|
97
|
-
width: '2.5em',
|
|
98
|
-
cursor: 'pointer',
|
|
99
|
-
'&:hover': {
|
|
100
|
-
backgroundColor: getBorderColor(type, theme)
|
|
101
|
-
},
|
|
102
|
-
'&::before': {
|
|
103
|
-
position: 'absolute',
|
|
104
|
-
top: '50%',
|
|
105
|
-
left: '50%',
|
|
106
|
-
transform: 'translate(-50%, -50%)'
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}, 'span');
|
|
110
|
-
var NotificationContainer = (0, _styleContainer.createComponent)(function (_ref3) {
|
|
111
|
-
var theme = _ref3.theme,
|
|
112
|
-
type = _ref3.type;
|
|
44
|
+
var NotificationContainer = (0, _styleContainer.createStyledComponent)(function (_ref) {
|
|
45
|
+
var theme = _ref.theme,
|
|
46
|
+
type = _ref.type;
|
|
113
47
|
return {
|
|
114
48
|
position: 'relative',
|
|
115
49
|
padding: theme.space[2],
|
|
@@ -118,16 +52,16 @@ var NotificationContainer = (0, _styleContainer.createComponent)(function (_ref3
|
|
|
118
52
|
'-webkit-font-smoothing': 'antialiased',
|
|
119
53
|
cursor: 'pointer',
|
|
120
54
|
transformOrigin: 'bottom left',
|
|
121
|
-
borderTopColor: getBorderColor(
|
|
122
|
-
borderBottomColor: getBorderColor(
|
|
123
|
-
borderLeftColor: getBorderColor(
|
|
124
|
-
borderRightColor: getBorderColor(
|
|
55
|
+
borderTopColor: (0, _utils.getBorderColor)(theme, type),
|
|
56
|
+
borderBottomColor: (0, _utils.getBorderColor)(theme, type),
|
|
57
|
+
borderLeftColor: (0, _utils.getBorderColor)(theme, type),
|
|
58
|
+
borderRightColor: (0, _utils.getBorderColor)(theme, type),
|
|
125
59
|
borderTopWidth: 1,
|
|
126
60
|
borderRightWidth: 1,
|
|
127
61
|
borderBottomWidth: 0,
|
|
128
62
|
borderLeftWidth: 1,
|
|
129
63
|
borderStyle: 'solid',
|
|
130
|
-
backgroundColor: getBackgroundColor(
|
|
64
|
+
backgroundColor: (0, _utils.getBackgroundColor)(theme, type),
|
|
131
65
|
animationName: {
|
|
132
66
|
'0%': {
|
|
133
67
|
transform: 'scaleY(0)'
|
|
@@ -151,78 +85,6 @@ var NotificationContainer = (0, _styleContainer.createComponent)(function (_ref3
|
|
|
151
85
|
}
|
|
152
86
|
};
|
|
153
87
|
}, 'div');
|
|
154
|
-
var IconWrapper = (0, _styleContainer.createComponent)(function () {
|
|
155
|
-
return {
|
|
156
|
-
paddingRight: 6,
|
|
157
|
-
display: 'flex'
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
var NotificationWrapper = (0, _styleContainer.createComponent)(function () {
|
|
161
|
-
return {
|
|
162
|
-
display: 'flex'
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
var CloseWrapper = (0, _styleContainer.createComponent)(function () {
|
|
166
|
-
return {
|
|
167
|
-
position: 'absolute',
|
|
168
|
-
top: '50%',
|
|
169
|
-
left: '50%',
|
|
170
|
-
transform: 'translate(-50%,-50%)'
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
var NotificationItem = (0, _styleContainer.createComponent)(function () {
|
|
174
|
-
return {};
|
|
175
|
-
}, function (_ref4) {
|
|
176
|
-
var children = _ref4.children,
|
|
177
|
-
closable = _ref4.closable,
|
|
178
|
-
handleClickClose = _ref4.handleClickClose,
|
|
179
|
-
type = _ref4.type;
|
|
180
|
-
var iconType;
|
|
181
|
-
|
|
182
|
-
switch (type) {
|
|
183
|
-
case 'success':
|
|
184
|
-
iconType = 'ok-sign';
|
|
185
|
-
break;
|
|
186
|
-
|
|
187
|
-
case 'info':
|
|
188
|
-
iconType = 'info-sign';
|
|
189
|
-
break;
|
|
190
|
-
|
|
191
|
-
case 'warning':
|
|
192
|
-
iconType = 'exclamation-sign';
|
|
193
|
-
break;
|
|
194
|
-
|
|
195
|
-
case 'error':
|
|
196
|
-
iconType = 'exclamation-sign';
|
|
197
|
-
break;
|
|
198
|
-
|
|
199
|
-
default:
|
|
200
|
-
iconType = 'info-sign';
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return /*#__PURE__*/_react.default.createElement(NotificationWrapper, null, /*#__PURE__*/_react.default.createElement(NotificationMessage, null, /*#__PURE__*/_react.default.createElement(IconWrapper, null, /*#__PURE__*/_react.default.createElement(_componentIcon.Icon, {
|
|
205
|
-
type: iconType,
|
|
206
|
-
label: type ? type : 'info-sign',
|
|
207
|
-
color: "white",
|
|
208
|
-
size: 24
|
|
209
|
-
})), children), closable && /*#__PURE__*/_react.default.createElement(NotificationClose, {
|
|
210
|
-
onClick: handleClickClose,
|
|
211
|
-
type: type
|
|
212
|
-
}, /*#__PURE__*/_react.default.createElement(CloseWrapper, null, /*#__PURE__*/_react.default.createElement(_componentIcon.Icon, {
|
|
213
|
-
type: "remove",
|
|
214
|
-
label: "close",
|
|
215
|
-
color: "white"
|
|
216
|
-
}))));
|
|
217
|
-
});
|
|
218
|
-
NotificationItem.propTypes = {
|
|
219
|
-
children: _propTypes.default.string,
|
|
220
|
-
closable: _propTypes.default.bool,
|
|
221
|
-
persist: _propTypes.default.bool,
|
|
222
|
-
duration: _propTypes.default.number,
|
|
223
|
-
active: _propTypes.default.bool,
|
|
224
|
-
handleClickClose: _propTypes.default.func
|
|
225
|
-
};
|
|
226
88
|
|
|
227
89
|
var Notification = /*#__PURE__*/function (_React$Component) {
|
|
228
90
|
_inherits(Notification, _React$Component);
|
|
@@ -235,6 +97,9 @@ var Notification = /*#__PURE__*/function (_React$Component) {
|
|
|
235
97
|
_classCallCheck(this, Notification);
|
|
236
98
|
|
|
237
99
|
_this = _super.call(this, props);
|
|
100
|
+
|
|
101
|
+
_defineProperty(_assertThisInitialized(_this), "_raf", null);
|
|
102
|
+
|
|
238
103
|
_this.state = {
|
|
239
104
|
persist: _this.props.persist,
|
|
240
105
|
timeoutId: null
|
|
@@ -328,12 +193,9 @@ var Notification = /*#__PURE__*/function (_React$Component) {
|
|
|
328
193
|
onMouseEnter: this.handleMouseEnter.bind(this),
|
|
329
194
|
onMouseLeave: this.handleMouseLeave.bind(this),
|
|
330
195
|
type: this.props.type
|
|
331
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
196
|
+
}, /*#__PURE__*/_react.default.createElement(_NotificationItem.default, {
|
|
332
197
|
closable: this.props.closable,
|
|
333
198
|
handleClickClose: this.handleClickClose.bind(this),
|
|
334
|
-
duration: this.props.delay,
|
|
335
|
-
persist: this.state.persist,
|
|
336
|
-
active: !!this.state.timeoutId,
|
|
337
199
|
type: this.props.type
|
|
338
200
|
}, this.props.message));
|
|
339
201
|
}
|
|
@@ -342,19 +204,12 @@ var Notification = /*#__PURE__*/function (_React$Component) {
|
|
|
342
204
|
return Notification;
|
|
343
205
|
}(_react.default.Component);
|
|
344
206
|
|
|
345
|
-
Notification
|
|
346
|
-
type: _propTypes.default.oneOf(['success', 'error', 'info', 'warning']),
|
|
347
|
-
message: _propTypes.default.string.isRequired,
|
|
348
|
-
closable: _propTypes.default.bool,
|
|
349
|
-
delay: _propTypes.default.number,
|
|
350
|
-
persist: _propTypes.default.bool,
|
|
351
|
-
onClose: _propTypes.default.func.isRequired
|
|
352
|
-
};
|
|
353
|
-
Notification.defaultProps = {
|
|
207
|
+
_defineProperty(Notification, "defaultProps", {
|
|
354
208
|
closable: true,
|
|
355
209
|
delay: 4000,
|
|
356
210
|
persist: false,
|
|
357
211
|
type: 'info'
|
|
358
|
-
};
|
|
212
|
+
});
|
|
213
|
+
|
|
359
214
|
var _default = Notification;
|
|
360
215
|
exports.default = _default;
|
|
@@ -7,13 +7,11 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
10
|
var _styleContainer = require("@cloudflare/style-container");
|
|
13
11
|
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var StyledContainer = (0, _styleContainer.createStyledComponent)(function (_ref) {
|
|
17
15
|
var theme = _ref.theme;
|
|
18
16
|
return {
|
|
19
17
|
position: 'fixed',
|
|
@@ -25,22 +23,15 @@ var styles = function styles(_ref) {
|
|
|
25
23
|
zIndex: 1600,
|
|
26
24
|
fontSize: theme.fontSizes[3]
|
|
27
25
|
};
|
|
28
|
-
};
|
|
26
|
+
}, 'div');
|
|
29
27
|
|
|
30
28
|
var NotificationGlobalContainer = function NotificationGlobalContainer(_ref2) {
|
|
31
29
|
var className = _ref2.className,
|
|
32
30
|
children = _ref2.children;
|
|
33
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement(StyledContainer, {
|
|
34
32
|
className: className
|
|
35
33
|
}, children);
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
children: _propTypes.default.node,
|
|
40
|
-
className: _propTypes.default.string
|
|
41
|
-
};
|
|
42
|
-
NotificationGlobalContainer.displayName = 'NotificationGlobalContainer';
|
|
43
|
-
|
|
44
|
-
var _default = (0, _styleContainer.createComponent)(styles, NotificationGlobalContainer);
|
|
45
|
-
|
|
36
|
+
var _default = NotificationGlobalContainer;
|
|
46
37
|
exports.default = _default;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _componentIcon = require("@cloudflare/component-icon");
|
|
11
|
+
|
|
12
|
+
var _styleContainer = require("@cloudflare/style-container");
|
|
13
|
+
|
|
14
|
+
var _utils = require("./utils");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
var IconWrapper = (0, _styleContainer.createStyledComponent)(function () {
|
|
19
|
+
return {
|
|
20
|
+
paddingRight: '6px',
|
|
21
|
+
display: 'flex'
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
var NotificationWrapper = (0, _styleContainer.createStyledComponent)(function () {
|
|
25
|
+
return {
|
|
26
|
+
display: 'flex'
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
var CloseWrapper = (0, _styleContainer.createStyledComponent)(function () {
|
|
30
|
+
return {
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
top: '50%',
|
|
33
|
+
left: '50%',
|
|
34
|
+
transform: 'translate(-50%,-50%)'
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
var NotificationMessage = (0, _styleContainer.createStyledComponent)(function (_ref) {
|
|
38
|
+
var theme = _ref.theme;
|
|
39
|
+
return {
|
|
40
|
+
position: 'relative',
|
|
41
|
+
zIndex: 2,
|
|
42
|
+
color: theme.colors.white,
|
|
43
|
+
display: 'flex',
|
|
44
|
+
alignItems: 'center'
|
|
45
|
+
};
|
|
46
|
+
}, 'span');
|
|
47
|
+
var NotificationClose = (0, _styleContainer.createStyledComponent)(function (_ref2) {
|
|
48
|
+
var theme = _ref2.theme,
|
|
49
|
+
type = _ref2.type;
|
|
50
|
+
return {
|
|
51
|
+
position: 'absolute',
|
|
52
|
+
zIndex: 3,
|
|
53
|
+
top: 0,
|
|
54
|
+
right: 0,
|
|
55
|
+
bottom: 0,
|
|
56
|
+
width: '2.5em',
|
|
57
|
+
cursor: 'pointer',
|
|
58
|
+
'&:hover': {
|
|
59
|
+
backgroundColor: (0, _utils.getBorderColor)(theme, type)
|
|
60
|
+
},
|
|
61
|
+
'&::before': {
|
|
62
|
+
position: 'absolute',
|
|
63
|
+
top: '50%',
|
|
64
|
+
left: '50%',
|
|
65
|
+
transform: 'translate(-50%, -50%)'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, 'span');
|
|
69
|
+
|
|
70
|
+
var NotificationItem = function NotificationItem(_ref3) {
|
|
71
|
+
var children = _ref3.children,
|
|
72
|
+
closable = _ref3.closable,
|
|
73
|
+
handleClickClose = _ref3.handleClickClose,
|
|
74
|
+
type = _ref3.type;
|
|
75
|
+
var iconType;
|
|
76
|
+
|
|
77
|
+
switch (type) {
|
|
78
|
+
case 'success':
|
|
79
|
+
iconType = 'ok-sign';
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
case 'info':
|
|
83
|
+
iconType = 'info-sign';
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 'warning':
|
|
87
|
+
iconType = 'exclamation-sign';
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case 'error':
|
|
91
|
+
iconType = 'exclamation-sign';
|
|
92
|
+
break;
|
|
93
|
+
|
|
94
|
+
default:
|
|
95
|
+
iconType = 'info-sign';
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return /*#__PURE__*/_react.default.createElement(NotificationWrapper, null, /*#__PURE__*/_react.default.createElement(NotificationMessage, null, /*#__PURE__*/_react.default.createElement(IconWrapper, null, /*#__PURE__*/_react.default.createElement(_componentIcon.Icon, {
|
|
100
|
+
type: iconType,
|
|
101
|
+
label: type ? type : 'info-sign',
|
|
102
|
+
color: "white",
|
|
103
|
+
size: 24
|
|
104
|
+
})), children), closable && /*#__PURE__*/_react.default.createElement(NotificationClose, {
|
|
105
|
+
onClick: handleClickClose,
|
|
106
|
+
type: type
|
|
107
|
+
}, /*#__PURE__*/_react.default.createElement(CloseWrapper, null, /*#__PURE__*/_react.default.createElement(_componentIcon.Icon, {
|
|
108
|
+
type: "remove",
|
|
109
|
+
label: "close",
|
|
110
|
+
color: "white"
|
|
111
|
+
}))));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var _default = NotificationItem;
|
|
115
|
+
exports.default = _default;
|
package/lib/NotificationList.js
CHANGED
|
@@ -7,8 +7,6 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
10
|
var _styleContainer = require("@cloudflare/style-container");
|
|
13
11
|
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -28,12 +26,6 @@ var NotificationList = function NotificationList(_ref) {
|
|
|
28
26
|
}, children);
|
|
29
27
|
};
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
children: _propTypes.default.node,
|
|
33
|
-
className: _propTypes.default.string
|
|
34
|
-
};
|
|
35
|
-
NotificationList.displayName = 'NotificationList';
|
|
36
|
-
|
|
37
|
-
var _default = (0, _styleContainer.createComponent)(styles, NotificationList);
|
|
29
|
+
var _default = (0, _styleContainer.createStyledComponent)(styles, NotificationList);
|
|
38
30
|
|
|
39
31
|
exports.default = _default;
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBorderColor = exports.getBackgroundColor = void 0;
|
|
7
|
+
|
|
8
|
+
var _styleConst = require("@cloudflare/style-const");
|
|
9
|
+
|
|
10
|
+
var getBorderColor = function getBorderColor(theme, type) {
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'success':
|
|
13
|
+
return theme.colors.green[5];
|
|
14
|
+
|
|
15
|
+
case 'warning':
|
|
16
|
+
return theme.colors.orange[5];
|
|
17
|
+
|
|
18
|
+
case 'error':
|
|
19
|
+
return theme.colors.red[2];
|
|
20
|
+
|
|
21
|
+
case 'info':
|
|
22
|
+
default:
|
|
23
|
+
return theme.colors.blue[3];
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.getBorderColor = getBorderColor;
|
|
28
|
+
|
|
29
|
+
var getBackgroundColor = function getBackgroundColor(theme, type) {
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 'success':
|
|
32
|
+
return theme.colors.green[(0, _styleConst.isDarkMode)() ? 3 : 6];
|
|
33
|
+
|
|
34
|
+
case 'warning':
|
|
35
|
+
return theme.colors.orange[(0, _styleConst.isDarkMode)() ? 3 : 6];
|
|
36
|
+
|
|
37
|
+
case 'error':
|
|
38
|
+
return theme.colors.red[3];
|
|
39
|
+
|
|
40
|
+
case 'info':
|
|
41
|
+
default:
|
|
42
|
+
return theme.colors.blue[(0, _styleConst.isDarkMode)() ? 3 : 6];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.getBackgroundColor = getBackgroundColor;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/component-notifications",
|
|
3
3
|
"description": "Cloudflare Notifications Component",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.1.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"author": "James Kyle <jkyle@cloudflare.com>",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public",
|
|
11
11
|
"main": "lib/index.js",
|
|
12
|
-
"module": "es/index.js"
|
|
12
|
+
"module": "es/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
16
|
"raf": "^3.3.2"
|
|
@@ -31,5 +32,6 @@
|
|
|
31
32
|
"test": "stratus test",
|
|
32
33
|
"test-coverage": "stratus test --coverage --muteErrorsFixWeNeedToSolveThis",
|
|
33
34
|
"test-watch": "stratus test --watch"
|
|
34
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"types": "./dist/index.d.ts"
|
|
35
37
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import raf from 'raf';
|
|
3
|
+
import {
|
|
4
|
+
createStyledComponent,
|
|
5
|
+
type ThemeProp
|
|
6
|
+
} from '@cloudflare/style-container';
|
|
7
|
+
import NotificationItem from './NotificationItem';
|
|
8
|
+
import { getBackgroundColor, getBorderColor } from './utils';
|
|
9
|
+
|
|
10
|
+
type TNotificationContainerProps = ThemeProp & {
|
|
11
|
+
type?: TNotificationType;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const NotificationContainer = createStyledComponent(
|
|
15
|
+
({ theme, type }: TNotificationContainerProps) => ({
|
|
16
|
+
position: 'relative',
|
|
17
|
+
padding: theme.space[2],
|
|
18
|
+
verticalAlign: 'middle',
|
|
19
|
+
'-webkit-text-stroke': '0',
|
|
20
|
+
'-webkit-font-smoothing': 'antialiased',
|
|
21
|
+
cursor: 'pointer',
|
|
22
|
+
transformOrigin: 'bottom left',
|
|
23
|
+
borderTopColor: getBorderColor(theme, type),
|
|
24
|
+
borderBottomColor: getBorderColor(theme, type),
|
|
25
|
+
borderLeftColor: getBorderColor(theme, type),
|
|
26
|
+
borderRightColor: getBorderColor(theme, type),
|
|
27
|
+
borderTopWidth: 1,
|
|
28
|
+
borderRightWidth: 1,
|
|
29
|
+
borderBottomWidth: 0,
|
|
30
|
+
borderLeftWidth: 1,
|
|
31
|
+
borderStyle: 'solid',
|
|
32
|
+
backgroundColor: getBackgroundColor(theme, type),
|
|
33
|
+
animationName: {
|
|
34
|
+
'0%': {
|
|
35
|
+
transform: 'scaleY(0)'
|
|
36
|
+
},
|
|
37
|
+
'100%': {
|
|
38
|
+
transform: 'scaleY(1)'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
animationDuration: '200ms',
|
|
42
|
+
animationTimingFunction: 'ease-in-out',
|
|
43
|
+
'&::before': {
|
|
44
|
+
position: 'absolute',
|
|
45
|
+
top: '50%',
|
|
46
|
+
left: '0.75rem',
|
|
47
|
+
transform: 'translate(0, -50%)',
|
|
48
|
+
lineHeight: '1',
|
|
49
|
+
verticalAlign: 'middle'
|
|
50
|
+
},
|
|
51
|
+
'&:first-child': {
|
|
52
|
+
borderTopWidth: 1
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
'div'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
type TNotificationProps = {
|
|
59
|
+
type?: TNotificationType;
|
|
60
|
+
message: string;
|
|
61
|
+
closable?: boolean;
|
|
62
|
+
delay?: number;
|
|
63
|
+
persist?: boolean;
|
|
64
|
+
onClose: () => void;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type TNotificationState = {
|
|
68
|
+
persist?: boolean;
|
|
69
|
+
timeoutId: NodeJS.Timeout | null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type TNotificationType = 'success' | 'error' | 'info' | 'warning';
|
|
73
|
+
|
|
74
|
+
class Notification extends React.Component<
|
|
75
|
+
TNotificationProps,
|
|
76
|
+
TNotificationState
|
|
77
|
+
> {
|
|
78
|
+
private _raf: number | null = null;
|
|
79
|
+
|
|
80
|
+
static defaultProps: Partial<TNotificationProps> = {
|
|
81
|
+
closable: true,
|
|
82
|
+
delay: 4000,
|
|
83
|
+
persist: false,
|
|
84
|
+
type: 'info'
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
constructor(props) {
|
|
88
|
+
super(props);
|
|
89
|
+
this.state = {
|
|
90
|
+
persist: this.props.persist,
|
|
91
|
+
timeoutId: null
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
componentDidMount() {
|
|
96
|
+
// Read this https://stanko.github.io/react-rerender-in-component-did-mount/
|
|
97
|
+
this._raf = raf(() => {
|
|
98
|
+
this._raf = raf(() => {
|
|
99
|
+
this._raf = null;
|
|
100
|
+
this.startTimeout();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
componentWillUnmount() {
|
|
106
|
+
this.stopTimeout();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
startTimeout() {
|
|
110
|
+
// Don't dismiss errors if they're configured to be persisted,
|
|
111
|
+
// or if we're in a testing environment
|
|
112
|
+
if (this.state.persist || process.env.TESTING) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.stopTimeout();
|
|
116
|
+
const timeoutId = setTimeout(() => this.props.onClose(), this.props.delay);
|
|
117
|
+
this.setState({ timeoutId });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
stopTimeout() {
|
|
121
|
+
if (this._raf) {
|
|
122
|
+
raf.cancel(this._raf);
|
|
123
|
+
this._raf = null;
|
|
124
|
+
}
|
|
125
|
+
if (this.state.timeoutId) {
|
|
126
|
+
clearTimeout(this.state.timeoutId);
|
|
127
|
+
this.setState({ timeoutId: null });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
handleMouseEnter() {
|
|
132
|
+
this.stopTimeout();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
handleMouseLeave() {
|
|
136
|
+
this.startTimeout();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
handleClickClose() {
|
|
140
|
+
this.props.onClose();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
handleClick() {
|
|
144
|
+
this.stopTimeout();
|
|
145
|
+
this.setState({
|
|
146
|
+
persist: true
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
render() {
|
|
151
|
+
return (
|
|
152
|
+
<NotificationContainer
|
|
153
|
+
role="alert"
|
|
154
|
+
onClick={this.handleClick.bind(this)}
|
|
155
|
+
onMouseEnter={this.handleMouseEnter.bind(this)}
|
|
156
|
+
onMouseLeave={this.handleMouseLeave.bind(this)}
|
|
157
|
+
type={this.props.type}
|
|
158
|
+
>
|
|
159
|
+
<NotificationItem
|
|
160
|
+
closable={this.props.closable}
|
|
161
|
+
handleClickClose={this.handleClickClose.bind(this)}
|
|
162
|
+
type={this.props.type}
|
|
163
|
+
>
|
|
164
|
+
{this.props.message}
|
|
165
|
+
</NotificationItem>
|
|
166
|
+
</NotificationContainer>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default Notification;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
createStyledComponent,
|
|
4
|
+
type ThemeProp
|
|
5
|
+
} from '@cloudflare/style-container';
|
|
6
|
+
|
|
7
|
+
const StyledContainer = createStyledComponent(
|
|
8
|
+
({ theme }: ThemeProp) => ({
|
|
9
|
+
position: 'fixed',
|
|
10
|
+
bottom: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
right: 0,
|
|
13
|
+
maxHeight: '25%',
|
|
14
|
+
overflow: 'auto',
|
|
15
|
+
zIndex: 1600,
|
|
16
|
+
fontSize: theme.fontSizes[3]
|
|
17
|
+
}),
|
|
18
|
+
'div'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
type TNotificationGlobalContainerProps = {
|
|
22
|
+
className?: string;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const NotificationGlobalContainer = ({
|
|
27
|
+
className,
|
|
28
|
+
children
|
|
29
|
+
}: TNotificationGlobalContainerProps) => {
|
|
30
|
+
return <StyledContainer className={className}>{children}</StyledContainer>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default NotificationGlobalContainer;
|