neo.mjs 4.6.3 → 4.6.4
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/examples/toast/MainContainer.mjs +2 -2
- package/examples/toast/MainContainerController.mjs +1 -1
- package/package.json +1 -1
- package/resources/scss/src/component/Toast.scss +191 -0
- package/resources/scss/theme-dark/component/Toast.scss +21 -0
- package/resources/scss/theme-light/component/Toast.scss +21 -0
- package/src/{dialog → component}/Toast.mjs +61 -63
- package/src/manager/Toast.mjs +119 -74
- package/resources/scss/src/dialog/Toast.scss +0 -190
- package/resources/scss/theme-dark/dialog/Toast.scss +0 -13
- package/resources/scss/theme-light/dialog/Toast.scss +0 -25
@@ -44,7 +44,7 @@ class MainContainer extends Viewport {
|
|
44
44
|
style : {paddingBottom: '40px', marginLeft: '10px'}
|
45
45
|
}, {
|
46
46
|
module : TextField,
|
47
|
-
labelText: '
|
47
|
+
labelText: 'title',
|
48
48
|
name : 'title'
|
49
49
|
}, {
|
50
50
|
module : TextField,
|
@@ -57,7 +57,7 @@ class MainContainer extends Viewport {
|
|
57
57
|
store : {data: [{name: 'tl'}, {name: 'tc'}, {name: 'tr'}, {name: 'bl'}, {name: 'bc'}, {name: 'br'}]}
|
58
58
|
}, {
|
59
59
|
module : SelectField,
|
60
|
-
labelText: 'slideDirection =
|
60
|
+
labelText: 'slideDirection = right',
|
61
61
|
name : 'slideDirection',
|
62
62
|
store : {data: [{name: 'down'}, {name: 'up'}, {name: 'left'}, {name: 'right'}]}
|
63
63
|
}, {
|
package/package.json
CHANGED
@@ -0,0 +1,191 @@
|
|
1
|
+
.neo-toast {
|
2
|
+
z-index : 20; // ensure to be on top of table headers
|
3
|
+
align-items : center;
|
4
|
+
background-color: v(toast-background-color);
|
5
|
+
border-radius : 0.5rem;
|
6
|
+
box-shadow : 0 0.25rem 0.5rem v(toast-shadow-color);
|
7
|
+
color : v(toast-color);
|
8
|
+
display : flex;
|
9
|
+
position : fixed;
|
10
|
+
transition : bottom .3s ease-out, top .3s ease-out;
|
11
|
+
|
12
|
+
.neo-toast-inner {
|
13
|
+
align-items: center;
|
14
|
+
display : flex;
|
15
|
+
|
16
|
+
&.neo-toast-has-title {
|
17
|
+
.neo-toast-text {
|
18
|
+
text-align: left;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
& > div {
|
23
|
+
padding: 0.25em 0.5em;
|
24
|
+
}
|
25
|
+
|
26
|
+
.neo-toast-icon {
|
27
|
+
border-right: 2px solid v(toast-color);
|
28
|
+
flex : 1;
|
29
|
+
font-size : 1.5em;
|
30
|
+
}
|
31
|
+
|
32
|
+
.neo-toast-text {
|
33
|
+
padding : 0.25em 1em;
|
34
|
+
text-align: center;
|
35
|
+
|
36
|
+
.neo-toast-msg {
|
37
|
+
font-size: 0.8em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.neo-toast-title {
|
41
|
+
padding-bottom: 0.2em;
|
42
|
+
text-transform: uppercase;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
.neo-toast-close {
|
47
|
+
background : transparent;
|
48
|
+
border : 0;
|
49
|
+
color : inherit;
|
50
|
+
cursor : pointer;
|
51
|
+
font-size : 1.5rem;
|
52
|
+
line-height: 1.5;
|
53
|
+
margin-left: auto;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
// ui: danger
|
59
|
+
.neo-toast-danger {
|
60
|
+
background-color: v(toast-danger-background-color);
|
61
|
+
color: v(toast-danger-color);
|
62
|
+
|
63
|
+
& > div {
|
64
|
+
|
65
|
+
.neo-toast-inner {
|
66
|
+
|
67
|
+
.neo-toast-icon {
|
68
|
+
border-right: 2px solid v(toast-danger-color);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
// ui: success
|
75
|
+
.neo-toast-success {
|
76
|
+
background-color: v(toast-success-background-color);
|
77
|
+
color: v(toast-success-color);
|
78
|
+
|
79
|
+
& > div {
|
80
|
+
|
81
|
+
.neo-toast-inner {
|
82
|
+
|
83
|
+
.neo-toast-icon {
|
84
|
+
border-right: 2px solid v(toast-success-color);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
/* Toast positions */
|
91
|
+
.neo-toast-tr {
|
92
|
+
right: 1rem;
|
93
|
+
top : 1rem;
|
94
|
+
}
|
95
|
+
|
96
|
+
.neo-toast-tc {
|
97
|
+
left : 50%;
|
98
|
+
top : 1rem;
|
99
|
+
transform: translateX(-50%);
|
100
|
+
}
|
101
|
+
|
102
|
+
.neo-toast-tl {
|
103
|
+
left: 1rem;
|
104
|
+
top : 1rem;
|
105
|
+
}
|
106
|
+
|
107
|
+
.neo-toast-br {
|
108
|
+
bottom: 1rem;
|
109
|
+
right : 1rem;
|
110
|
+
}
|
111
|
+
|
112
|
+
.neo-toast-bc {
|
113
|
+
bottom : 1rem;
|
114
|
+
left : 50%;
|
115
|
+
transform: translateX(-50%);
|
116
|
+
}
|
117
|
+
|
118
|
+
.neo-toast-bl {
|
119
|
+
bottom: 1rem;
|
120
|
+
left : 1rem;
|
121
|
+
}
|
122
|
+
|
123
|
+
/* Toast slide-in animation */
|
124
|
+
@keyframes neo-toast-slide-down-in {
|
125
|
+
from {
|
126
|
+
transform: translateY(-150%);
|
127
|
+
}
|
128
|
+
to {
|
129
|
+
transform: translateY(0);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
@keyframes neo-toast-slide-up-in {
|
134
|
+
from {
|
135
|
+
transform: translateY(150%);
|
136
|
+
}
|
137
|
+
to {
|
138
|
+
transform: translateY(0);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
@keyframes neo-toast-slide-left-in {
|
143
|
+
from {
|
144
|
+
transform: translateX(-150%);
|
145
|
+
}
|
146
|
+
to {
|
147
|
+
transform: translateX(0);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
@keyframes neo-toast-slide-right-in {
|
152
|
+
from {
|
153
|
+
transform: translateX(150%);
|
154
|
+
}
|
155
|
+
to {
|
156
|
+
transform: translateX(0);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
/* Add the slide-in animation to the toast when the slide-in class is added */
|
161
|
+
.neo-toast-slide-down-in {
|
162
|
+
animation: neo-toast-slide-down-in 0.25s ease-out;
|
163
|
+
}
|
164
|
+
|
165
|
+
.neo-toast-slide-up-in {
|
166
|
+
animation: neo-toast-slide-up-in 0.25s ease-out;
|
167
|
+
}
|
168
|
+
|
169
|
+
.neo-toast-slide-left-in {
|
170
|
+
animation: neo-toast-slide-left-in 0.25s ease-out;
|
171
|
+
}
|
172
|
+
|
173
|
+
.neo-toast-slide-right-in {
|
174
|
+
animation: neo-toast-slide-right-in 0.25s ease-out;
|
175
|
+
}
|
176
|
+
|
177
|
+
/* Toast fade-out animation */
|
178
|
+
@keyframes neo-toast-fade-out {
|
179
|
+
from {
|
180
|
+
opacity: 1;
|
181
|
+
}
|
182
|
+
to {
|
183
|
+
opacity: 0;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
/* Add the fade-out animation to the toast when the fade-out class is added */
|
188
|
+
.neo-toast-fade-out {
|
189
|
+
animation : neo-toast-fade-out 0.25s ease-out;
|
190
|
+
animation-fill-mode: forwards;
|
191
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$neoMap: map-merge($neoMap, (
|
2
|
+
'toast-background-color' : lightblue,
|
3
|
+
'toast-color' : #083741,
|
4
|
+
'toast-danger-background-color' : #e6adad,
|
5
|
+
'toast-danger-color' : #410808,
|
6
|
+
'toast-shadow-color' : rgba(255, 255, 255, 0.15),
|
7
|
+
'toast-success-background-color': #b7e6ad,
|
8
|
+
'toast-success-color' : #124108
|
9
|
+
));
|
10
|
+
|
11
|
+
@if $useCssVars == true {
|
12
|
+
:root .neo-theme-dark { // .neo-toast
|
13
|
+
--toast-background-color : #{neo(toast-background-color)};
|
14
|
+
--toast-color : #{neo(toast-color)};
|
15
|
+
--toast-shadow-color : #{neo(toast-shadow-color)};
|
16
|
+
--toast-danger-background-color : #{neo(toast-danger-background-color)};
|
17
|
+
--toast-danger-color : #{neo(toast-danger-color)};
|
18
|
+
--toast-success-background-color: #{neo(toast-success-background-color)};
|
19
|
+
--toast-success-color : #{neo(toast-success-color)};
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$neoMap: map-merge($neoMap, (
|
2
|
+
'toast-background-color' : lightblue,
|
3
|
+
'toast-color' : #083741,
|
4
|
+
'toast-danger-background-color' : #e6adad,
|
5
|
+
'toast-danger-color' : #410808,
|
6
|
+
'toast-shadow-color' : rgba(0, 0, 0, 0.15),
|
7
|
+
'toast-success-background-color': #b7e6ad,
|
8
|
+
'toast-success-color' : #124108
|
9
|
+
));
|
10
|
+
|
11
|
+
@if $useCssVars == true {
|
12
|
+
:root .neo-theme-light { // .neo-toast
|
13
|
+
--toast-background-color : #{neo(toast-background-color)};
|
14
|
+
--toast-color : #{neo(toast-color)};
|
15
|
+
--toast-shadow-color : #{neo(toast-shadow-color)};
|
16
|
+
--toast-danger-background-color : #{neo(toast-danger-background-color)};
|
17
|
+
--toast-danger-color : #{neo(toast-danger-color)};
|
18
|
+
--toast-success-background-color: #{neo(toast-success-background-color)};
|
19
|
+
--toast-success-color : #{neo(toast-success-color)};
|
20
|
+
}
|
21
|
+
}
|
@@ -3,7 +3,7 @@ import ToastManager from '../manager/Toast.mjs';
|
|
3
3
|
import NeoArray from "../util/Array.mjs";
|
4
4
|
|
5
5
|
/**
|
6
|
-
* @class Neo.
|
6
|
+
* @class Neo.component.Toast
|
7
7
|
* @extends Neo.component.Base
|
8
8
|
*
|
9
9
|
* @example
|
@@ -16,7 +16,7 @@ import NeoArray from "../util/Array.mjs";
|
|
16
16
|
iconCls : 'fa fa-bell', // null
|
17
17
|
maxWidth : 300, // 250
|
18
18
|
position : 'br', // 'tr'
|
19
|
-
slideDirection : 'right', // '
|
19
|
+
slideDirection : 'right', // 'right'
|
20
20
|
title : 'Alarm Clock' // null
|
21
21
|
})
|
22
22
|
*/
|
@@ -28,11 +28,10 @@ class Toast extends Base {
|
|
28
28
|
*/
|
29
29
|
running = false
|
30
30
|
/**
|
31
|
-
*
|
32
|
-
* @member {
|
33
|
-
* @private
|
31
|
+
* Timeout in ms after which the toast is removed
|
32
|
+
* @member {Number} timeout=3000
|
34
33
|
*/
|
35
|
-
|
34
|
+
timeout = 3000
|
36
35
|
|
37
36
|
static getStaticConfig() {return {
|
38
37
|
/**
|
@@ -52,24 +51,15 @@ class Toast extends Base {
|
|
52
51
|
|
53
52
|
static getConfig() {return {
|
54
53
|
/**
|
55
|
-
* @member {String} className='Neo.
|
54
|
+
* @member {String} className='Neo.component.Toast'
|
56
55
|
* @protected
|
57
56
|
*/
|
58
|
-
className: 'Neo.
|
57
|
+
className: 'Neo.component.Toast',
|
59
58
|
/**
|
60
59
|
* @member {String} ntype='toast'
|
61
60
|
* @protected
|
62
61
|
*/
|
63
62
|
ntype: 'toast',
|
64
|
-
|
65
|
-
/**
|
66
|
-
* @member {Boolean} autoMount=true
|
67
|
-
*/
|
68
|
-
autoMount: true,
|
69
|
-
/**
|
70
|
-
* @member {Boolean} autoRender=true
|
71
|
-
*/
|
72
|
-
autoRender: true,
|
73
63
|
/**
|
74
64
|
* @member {String[]} baseCls=['neo-toast']
|
75
65
|
* @protected
|
@@ -110,14 +100,9 @@ class Toast extends Base {
|
|
110
100
|
/**
|
111
101
|
* Describes which direction from which side the toasts slides-in
|
112
102
|
* This creates a cls `neo-toast-slide-${direction}-in`
|
113
|
-
* @member {'down'|'up'|'left'|'right'} slideDirection_=
|
114
|
-
*/
|
115
|
-
slideDirection_: 'down',
|
116
|
-
/**
|
117
|
-
* Timeout in ms after which the toast is removed
|
118
|
-
* @member {Number} timeout_=3000
|
103
|
+
* @member {'down'|'up'|'left'|'right'} slideDirection_='right'
|
119
104
|
*/
|
120
|
-
|
105
|
+
slideDirection_: 'right',
|
121
106
|
/**
|
122
107
|
* Adds a title to the toast
|
123
108
|
* @member {Number} title_=null
|
@@ -138,6 +123,9 @@ class Toast extends Base {
|
|
138
123
|
}]}
|
139
124
|
}}
|
140
125
|
|
126
|
+
/**
|
127
|
+
* @param {Object} config
|
128
|
+
*/
|
141
129
|
construct(config) {
|
142
130
|
super.construct(config);
|
143
131
|
|
@@ -146,7 +134,9 @@ class Toast extends Base {
|
|
146
134
|
// click listener for close
|
147
135
|
me.addDomListeners([
|
148
136
|
{click: {fn: me.unregister, delegate: '.neo-toast-close', scope: me}}
|
149
|
-
])
|
137
|
+
]);
|
138
|
+
|
139
|
+
ToastManager.register(me);
|
150
140
|
}
|
151
141
|
|
152
142
|
/**
|
@@ -176,7 +166,6 @@ class Toast extends Base {
|
|
176
166
|
* Using the afterSetMsg to trigger the setup of the dom
|
177
167
|
* A new container is added as an item.
|
178
168
|
* We cannot use the vdom here.
|
179
|
-
*
|
180
169
|
* @param {String|null} value
|
181
170
|
* @param {String|null} oldValue
|
182
171
|
*/
|
@@ -186,19 +175,6 @@ class Toast extends Base {
|
|
186
175
|
vdom.innerHTML = value;
|
187
176
|
}
|
188
177
|
|
189
|
-
/**
|
190
|
-
* @param {String|null} value
|
191
|
-
* @param {String|null} oldValue
|
192
|
-
*/
|
193
|
-
afterSetTitle(value, oldValue) {
|
194
|
-
let vdom = this.getTextRootVdom().cn[0],
|
195
|
-
clsFn = !!value ? 'add' : 'remove';
|
196
|
-
|
197
|
-
vdom.removeDom = Neo.isEmpty(value);
|
198
|
-
vdom.innerHTML = value;
|
199
|
-
NeoArray[clsFn](vdom.cls, 'neo-toast-has-title');
|
200
|
-
}
|
201
|
-
|
202
178
|
/**
|
203
179
|
* Apply a cls, based on the position
|
204
180
|
* @param {String} value
|
@@ -218,17 +194,35 @@ class Toast extends Base {
|
|
218
194
|
}
|
219
195
|
|
220
196
|
/**
|
221
|
-
* Close the toast after the
|
222
|
-
* @param {
|
223
|
-
* @param {
|
197
|
+
* Close the toast after the mounted if not closable
|
198
|
+
* @param {Boolean} value
|
199
|
+
* @param {Boolean} oldValue
|
224
200
|
*/
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
201
|
+
afterSetMounted(value, oldValue) {
|
202
|
+
super.afterSetMounted(value, oldValue);
|
203
|
+
|
204
|
+
let me = this;
|
205
|
+
|
206
|
+
if (!me.closable && value) {
|
207
|
+
setTimeout(() => {
|
208
|
+
this.destroy(true);
|
209
|
+
}, me.timeout)
|
229
210
|
}
|
230
211
|
}
|
231
212
|
|
213
|
+
/**
|
214
|
+
* @param {String|null} value
|
215
|
+
* @param {String|null} oldValue
|
216
|
+
*/
|
217
|
+
afterSetTitle(value, oldValue) {
|
218
|
+
let vdom = this.getTextRootVdom().cn[0],
|
219
|
+
clsFn = !!value ? 'add' : 'remove';
|
220
|
+
|
221
|
+
vdom.removeDom = Neo.isEmpty(value);
|
222
|
+
vdom.innerHTML = value;
|
223
|
+
NeoArray[clsFn](vdom.cls, 'neo-toast-has-title');
|
224
|
+
}
|
225
|
+
|
232
226
|
/**
|
233
227
|
* Triggered before the position config gets changed
|
234
228
|
* @param {String} value
|
@@ -250,32 +244,36 @@ class Toast extends Base {
|
|
250
244
|
}
|
251
245
|
|
252
246
|
/**
|
253
|
-
*
|
254
|
-
* @returns {vdom}
|
247
|
+
*
|
255
248
|
*/
|
256
|
-
|
257
|
-
|
249
|
+
async destroy(...args) {
|
250
|
+
let me = this;
|
251
|
+
|
252
|
+
me.addDomListeners({
|
253
|
+
animationend: function () {
|
254
|
+
ToastManager.removeToast(me.id);
|
255
|
+
ToastManager.unregister(me);
|
256
|
+
me.destroy(true);
|
257
|
+
}
|
258
|
+
});
|
259
|
+
|
260
|
+
me.addCls('neo-toast-fade-out')
|
258
261
|
}
|
259
262
|
|
263
|
+
/**
|
264
|
+
* This is a dialog, so we have to add an item to be able to
|
265
|
+
* @returns {Object} vdom
|
266
|
+
*/
|
260
267
|
getTextRootVdom() {
|
261
268
|
return this.getVdomInner().cn[1];
|
262
269
|
}
|
263
270
|
|
264
271
|
/**
|
265
|
-
*
|
266
|
-
*
|
272
|
+
* This is a dialog, so we have to add an item to be able to
|
273
|
+
* @returns {Object} vdom
|
267
274
|
*/
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
me.addDomListeners({
|
272
|
-
animationend: function () {
|
273
|
-
ToastManager.removeToast(me.toastManagerId);
|
274
|
-
me.destroy(true);
|
275
|
-
}
|
276
|
-
})
|
277
|
-
|
278
|
-
me.addCls('neo-toast-fade-out');
|
275
|
+
getVdomInner() {
|
276
|
+
return this.vdom.cn[0];
|
279
277
|
}
|
280
278
|
}
|
281
279
|
|
package/src/manager/Toast.mjs
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import Base
|
1
|
+
import Base from './Base.mjs';
|
2
|
+
import NeoArray from "../util/Array.mjs";
|
2
3
|
|
3
4
|
/**
|
4
5
|
* See Neo.dialog.Toast for examples
|
@@ -8,37 +9,29 @@ import Base from './Base.mjs';
|
|
8
9
|
*/
|
9
10
|
class Toast extends Base {
|
10
11
|
/**
|
11
|
-
*
|
12
|
-
*
|
12
|
+
* Using a default margin between the item
|
13
|
+
* If you switch the distance to the top or bottom you have to change this value accordingly
|
14
|
+
* @member {Number} defaultMargin=16
|
13
15
|
*/
|
14
|
-
|
15
|
-
closable : false,
|
16
|
-
cls : ['neo-toast'],
|
17
|
-
maxWidth : 250,
|
18
|
-
position : 'tr',
|
19
|
-
running : false,
|
20
|
-
slideDirection: 'down',
|
21
|
-
timeout : 3000,
|
22
|
-
title : null
|
23
|
-
}
|
16
|
+
defaultMargin = 16
|
24
17
|
/**
|
25
18
|
* Currently only 1 is supported, because they would overlap
|
26
|
-
* @member {
|
19
|
+
* @member {Number} maxToasts=3
|
27
20
|
*/
|
28
|
-
maxToasts =
|
21
|
+
maxToasts = 3
|
29
22
|
/**
|
30
23
|
* Counts the currently running Toasts per area
|
31
24
|
* @member {Object} running
|
32
25
|
*/
|
33
26
|
running = {
|
34
|
-
bc:
|
35
|
-
tc:
|
27
|
+
bc: [], bl: [], br: [],
|
28
|
+
tc: [], tl: [], tr: []
|
36
29
|
}
|
37
30
|
/**
|
38
31
|
* If you prefer your own class to open, override here
|
39
|
-
* @member {String} toastClass='Neo.
|
32
|
+
* @member {String} toastClass='Neo.component.Toast'
|
40
33
|
*/
|
41
|
-
toastClass = 'Neo.
|
34
|
+
toastClass = 'Neo.component.Toast'
|
42
35
|
|
43
36
|
static getConfig() {return {
|
44
37
|
/**
|
@@ -53,37 +46,26 @@ class Toast extends Base {
|
|
53
46
|
singleton: true
|
54
47
|
}}
|
55
48
|
|
49
|
+
/**
|
50
|
+
* @param {Object} config
|
51
|
+
*/
|
56
52
|
construct(config) {
|
57
53
|
super.construct(config);
|
58
54
|
Neo.toast = this.createToast.bind(this);
|
59
55
|
}
|
60
56
|
|
61
|
-
/**
|
62
|
-
* @param {Object} item
|
63
|
-
*/
|
64
|
-
register(item) {
|
65
|
-
super.register(item);
|
66
|
-
this.runQueue();
|
67
|
-
}
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Removes a collection item passed by reference or key
|
71
|
-
* @param {Object|String} item
|
72
|
-
*/
|
73
|
-
unregister(item) {
|
74
|
-
super.unregister(item);
|
75
|
-
this.runQueue();
|
76
|
-
}
|
77
|
-
|
78
57
|
/**
|
79
58
|
* Create the Toast definition and pass it to the Collection
|
80
|
-
*
|
81
59
|
* @param {Object} toast
|
82
|
-
* @returns {
|
60
|
+
* @returns {String|null}
|
83
61
|
*/
|
84
62
|
createToast(toast) {
|
85
|
-
let me = this
|
86
|
-
|
63
|
+
let me = this;
|
64
|
+
|
65
|
+
if (toast.position && !me.running[toast.position]) {
|
66
|
+
Neo.logError('[Neo.manager.Toast] Supported values for slideDirection are: tl, tc, tr, bl, bc, br');
|
67
|
+
return null;
|
68
|
+
}
|
87
69
|
|
88
70
|
if (!toast.msg || !toast.appName) {
|
89
71
|
!toast.msg && Neo.logError('[Neo.manager.Toast] Toast has to define a msg');
|
@@ -91,18 +73,49 @@ class Toast extends Base {
|
|
91
73
|
return null;
|
92
74
|
}
|
93
75
|
|
94
|
-
|
95
|
-
|
96
|
-
toast = {
|
97
|
-
id,
|
98
|
-
toastManagerId: id,
|
99
|
-
...me.defaultToastConfig,
|
76
|
+
toast = Neo.create({
|
77
|
+
className: this.toastClass,
|
100
78
|
...toast
|
101
|
-
};
|
79
|
+
});
|
102
80
|
|
103
|
-
|
81
|
+
toast.on({
|
82
|
+
mounted: me.updateItemsInPosition,
|
83
|
+
scope : me
|
84
|
+
})
|
104
85
|
|
105
|
-
return toast.
|
86
|
+
return toast.id;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Find the first toast based on the maximum allowed toasts
|
91
|
+
* @returns {*}
|
92
|
+
* @private
|
93
|
+
*/
|
94
|
+
findFirstToast() {
|
95
|
+
let me = this,
|
96
|
+
firstToast, item;
|
97
|
+
|
98
|
+
me.filters = [{property: 'running', value: false}];
|
99
|
+
|
100
|
+
for (item of me.map.values()) {
|
101
|
+
if (me.running[item.position].length < me.maxToasts) {
|
102
|
+
firstToast = item;
|
103
|
+
firstToast.running = true;
|
104
|
+
break;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
me.clearFilters();
|
109
|
+
|
110
|
+
return firstToast;
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* @param {Object} item
|
115
|
+
*/
|
116
|
+
register(item) {
|
117
|
+
super.register(item);
|
118
|
+
this.runQueue();
|
106
119
|
}
|
107
120
|
|
108
121
|
/**
|
@@ -110,11 +123,20 @@ class Toast extends Base {
|
|
110
123
|
* @param {String} toastId
|
111
124
|
*/
|
112
125
|
removeToast(toastId) {
|
113
|
-
let me
|
126
|
+
let me = this,
|
127
|
+
toast = me.get(toastId),
|
128
|
+
position;
|
129
|
+
|
130
|
+
if (!toast) {
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
|
134
|
+
position = toast.position;
|
114
135
|
|
115
136
|
// decrease total of displayed toasts for a position
|
116
|
-
me.running[
|
117
|
-
|
137
|
+
NeoArray.remove(me.running[position], toastId);
|
138
|
+
|
139
|
+
me.updateItemsInPosition(toastId);
|
118
140
|
}
|
119
141
|
|
120
142
|
/**
|
@@ -131,36 +153,59 @@ class Toast extends Base {
|
|
131
153
|
}
|
132
154
|
}
|
133
155
|
|
156
|
+
/**
|
157
|
+
* @param {Neo.component.Toast} toast
|
158
|
+
*/
|
134
159
|
showToast(toast) {
|
135
|
-
|
160
|
+
toast.render(true);
|
161
|
+
|
136
162
|
// increase total of displayed toasts for a position
|
137
|
-
this.running[
|
138
|
-
|
139
|
-
|
140
|
-
|
163
|
+
this.running[toast.position].unshift(toast.id);
|
164
|
+
|
165
|
+
// todo: we could use a mounted listener
|
166
|
+
setTimeout(() => {
|
167
|
+
this.updateItemsInPosition(toast.id);
|
168
|
+
}, 50);
|
141
169
|
}
|
142
170
|
|
143
171
|
/**
|
144
|
-
*
|
145
|
-
* @
|
172
|
+
* Removes a collection item passed by reference or key
|
173
|
+
* @param {Object|String} item
|
146
174
|
*/
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
me.filters = [{property: 'running', value: false}];
|
152
|
-
me.filter();
|
175
|
+
unregister(item) {
|
176
|
+
super.unregister(item);
|
177
|
+
this.runQueue();
|
178
|
+
}
|
153
179
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
180
|
+
/**
|
181
|
+
* To handle multiple toasts we handle the exact position
|
182
|
+
* from the top or bottom
|
183
|
+
* @param {String} id
|
184
|
+
* @returns {Promise<void>}
|
185
|
+
*/
|
186
|
+
async updateItemsInPosition(id) {
|
187
|
+
let me = this,
|
188
|
+
toast = me.get(id),
|
189
|
+
position = toast.position,
|
190
|
+
positionArray = me.running[position],
|
191
|
+
acc = 0,
|
192
|
+
margin = me.defaultMargin,
|
193
|
+
moveTo = position.substring(0, 1) === 't' ? 'top' : 'bottom',
|
194
|
+
component, componentId, index, moveObj, rects;
|
195
|
+
|
196
|
+
rects = await toast.getDomRect(positionArray);
|
197
|
+
|
198
|
+
for ([index, componentId] of positionArray.entries()) {
|
199
|
+
component = Neo.getComponent(componentId);
|
200
|
+
moveObj = {};
|
201
|
+
|
202
|
+
acc = acc + margin;
|
203
|
+
moveObj[moveTo] = acc + 'px';
|
204
|
+
component.style = moveObj;
|
205
|
+
component.update();
|
206
|
+
|
207
|
+
acc = acc + rects[index].height;
|
159
208
|
}
|
160
|
-
|
161
|
-
me.clearFilters();
|
162
|
-
|
163
|
-
return firstToast;
|
164
209
|
}
|
165
210
|
}
|
166
211
|
|
@@ -1,190 +0,0 @@
|
|
1
|
-
.neo-toast {
|
2
|
-
z-index: 20; // ensure to be on top of table headers
|
3
|
-
align-items: center;
|
4
|
-
background-color: v(toast-background-color);
|
5
|
-
border-radius: 0.5rem;
|
6
|
-
box-shadow: 0 0.25rem 0.5rem v(toast-shadow-color);
|
7
|
-
color: v(toast-color);
|
8
|
-
display: flex;
|
9
|
-
position: fixed;
|
10
|
-
|
11
|
-
.neo-toast-inner {
|
12
|
-
align-items: center;
|
13
|
-
display: flex;
|
14
|
-
|
15
|
-
&.neo-toast-has-title {
|
16
|
-
.neo-toast-text {
|
17
|
-
text-align: left;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
& > div {
|
22
|
-
padding: 0.25em 0.5em;
|
23
|
-
}
|
24
|
-
|
25
|
-
.neo-toast-icon {
|
26
|
-
border-right: 2px solid v(toast-color);
|
27
|
-
flex: 1;
|
28
|
-
font-size: 1.5em;
|
29
|
-
}
|
30
|
-
|
31
|
-
.neo-toast-text {
|
32
|
-
padding: 0.25em 1em;
|
33
|
-
text-align: center;
|
34
|
-
|
35
|
-
.neo-toast-msg {
|
36
|
-
font-size: 0.8em;
|
37
|
-
}
|
38
|
-
|
39
|
-
.neo-toast-title {
|
40
|
-
padding-bottom: 0.2em;
|
41
|
-
text-transform: uppercase;
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
.neo-toast-close {
|
46
|
-
background: transparent;
|
47
|
-
border: 0;
|
48
|
-
color: inherit;
|
49
|
-
cursor: pointer;
|
50
|
-
font-size: 1.5rem;
|
51
|
-
line-height: 1.5;
|
52
|
-
margin-left: auto;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
// ui: danger
|
58
|
-
.neo-toast-danger {
|
59
|
-
background-color: v(toast-danger-background-color);
|
60
|
-
color: v(toast-danger-color);
|
61
|
-
|
62
|
-
& > div {
|
63
|
-
|
64
|
-
.neo-toast-inner {
|
65
|
-
|
66
|
-
.neo-toast-icon {
|
67
|
-
border-right: 2px solid v(toast-danger-color);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
// ui: success
|
74
|
-
.neo-toast-success {
|
75
|
-
background-color: v(toast-success-background-color);
|
76
|
-
color: v(toast-success-color);
|
77
|
-
|
78
|
-
& > div {
|
79
|
-
|
80
|
-
.neo-toast-inner {
|
81
|
-
|
82
|
-
.neo-toast-icon {
|
83
|
-
border-right: 2px solid v(toast-success-color);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
/* Toast positions */
|
90
|
-
.neo-toast-tr {
|
91
|
-
right: 1rem;
|
92
|
-
top: 1rem;
|
93
|
-
}
|
94
|
-
|
95
|
-
.neo-toast-tc {
|
96
|
-
left: 50%;
|
97
|
-
top: 1rem;
|
98
|
-
transform: translateX(-50%);
|
99
|
-
}
|
100
|
-
|
101
|
-
.neo-toast-tl {
|
102
|
-
left: 1rem;
|
103
|
-
top: 1rem;
|
104
|
-
}
|
105
|
-
|
106
|
-
.neo-toast-br {
|
107
|
-
bottom: 1rem;
|
108
|
-
right: 1rem;
|
109
|
-
}
|
110
|
-
|
111
|
-
.neo-toast-bc {
|
112
|
-
bottom: 1rem;
|
113
|
-
left: 50%;
|
114
|
-
transform: translateX(-50%);
|
115
|
-
}
|
116
|
-
|
117
|
-
.neo-toast-bl {
|
118
|
-
bottom: 1rem;
|
119
|
-
left: 1rem;
|
120
|
-
}
|
121
|
-
|
122
|
-
/* Toast slide-in animation */
|
123
|
-
@keyframes neo-toast-slide-down-in {
|
124
|
-
from {
|
125
|
-
transform: translateY(-150%);
|
126
|
-
}
|
127
|
-
to {
|
128
|
-
transform: translateY(0);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
@keyframes neo-toast-slide-up-in {
|
133
|
-
from {
|
134
|
-
transform: translateY(150%);
|
135
|
-
}
|
136
|
-
to {
|
137
|
-
transform: translateY(0);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
@keyframes neo-toast-slide-left-in {
|
142
|
-
from {
|
143
|
-
transform: translateX(-150%);
|
144
|
-
}
|
145
|
-
to {
|
146
|
-
transform: translateX(0);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
@keyframes neo-toast-slide-right-in {
|
151
|
-
from {
|
152
|
-
transform: translateX(150%);
|
153
|
-
}
|
154
|
-
to {
|
155
|
-
transform: translateX(0);
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
/* Add the slide-in animation to the toast when the slide-in class is added */
|
160
|
-
.neo-toast-slide-down-in {
|
161
|
-
animation: neo-toast-slide-down-in 0.25s ease-out;
|
162
|
-
}
|
163
|
-
|
164
|
-
.neo-toast-slide-up-in {
|
165
|
-
animation: neo-toast-slide-up-in 0.25s ease-out;
|
166
|
-
}
|
167
|
-
|
168
|
-
.neo-toast-slide-left-in {
|
169
|
-
animation: neo-toast-slide-left-in 0.25s ease-out;
|
170
|
-
}
|
171
|
-
|
172
|
-
.neo-toast-slide-right-in {
|
173
|
-
animation: neo-toast-slide-right-in 0.25s ease-out;
|
174
|
-
}
|
175
|
-
|
176
|
-
/* Toast fade-out animation */
|
177
|
-
@keyframes neo-toast-fade-out {
|
178
|
-
from {
|
179
|
-
opacity: 1;
|
180
|
-
}
|
181
|
-
to {
|
182
|
-
opacity: 0;
|
183
|
-
}
|
184
|
-
}
|
185
|
-
|
186
|
-
/* Add the fade-out animation to the toast when the fade-out class is added */
|
187
|
-
.neo-toast-fade-out {
|
188
|
-
animation: neo-toast-fade-out 0.25s ease-out;
|
189
|
-
animation-fill-mode: forwards;
|
190
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
$neoMap: map-merge($neoMap, (
|
2
|
-
'toast-background-color' : #083741,
|
3
|
-
'toast-color' : lightblue,
|
4
|
-
'toast-shadow-color' : rgba(255, 255, 255, 0.15)
|
5
|
-
));
|
6
|
-
|
7
|
-
@if $useCssVars == true {
|
8
|
-
:root .neo-theme-dark { // .neo-button
|
9
|
-
--toast-background-color : #{neo(toast-background-color)};
|
10
|
-
--toast-color : #{neo(toast-color)};
|
11
|
-
--toast-shadow-color : #{neo(toast-shadow-color)};
|
12
|
-
}
|
13
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
$neoMap: map-merge($neoMap, (
|
2
|
-
'toast-background-color' : lightblue,
|
3
|
-
'toast-color' : #083741,
|
4
|
-
'toast-shadow-color' : rgba(0, 0, 0, 0.15),
|
5
|
-
// ui: danger
|
6
|
-
'toast-danger-background-color' : #e6adad,
|
7
|
-
'toast-danger-color' : #410808,
|
8
|
-
// ui: success
|
9
|
-
'toast-success-background-color' : #b7e6ad,
|
10
|
-
'toast-success-color' : #124108,
|
11
|
-
));
|
12
|
-
|
13
|
-
@if $useCssVars == true {
|
14
|
-
:root .neo-theme-light { // .neo-button
|
15
|
-
--toast-background-color : #{neo(toast-background-color)};
|
16
|
-
--toast-color : #{neo(toast-color)};
|
17
|
-
--toast-shadow-color : #{neo(toast-shadow-color)};
|
18
|
-
// ui: danger
|
19
|
-
--toast-danger-background-color : #{neo(toast-danger-background-color)};
|
20
|
-
--toast-danger-color : #{neo(toast-danger-color)};
|
21
|
-
// ui: success
|
22
|
-
--toast-success-background-color : #{neo(toast-success-background-color)};
|
23
|
-
--toast-success-color : #{neo(toast-success-color)};
|
24
|
-
}
|
25
|
-
}
|