neo.mjs 4.6.3 → 4.6.5
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/button/base/MainContainer.mjs +18 -1
- package/examples/toast/MainContainer.mjs +2 -2
- package/examples/toast/MainContainerController.mjs +1 -1
- package/package.json +1 -1
- package/resources/scss/src/button/Base.scss +60 -23
- package/resources/scss/src/component/Toast.scss +191 -0
- package/resources/scss/theme-dark/button/Base.scss +16 -2
- package/resources/scss/theme-dark/component/Toast.scss +21 -0
- package/resources/scss/theme-light/button/Base.scss +16 -2
- package/resources/scss/theme-light/component/Toast.scss +21 -0
- package/src/component/Base.mjs +10 -1
- package/src/{dialog → component}/Toast.mjs +67 -70
- package/src/form/field/Select.mjs +77 -81
- 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
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
|
-
}
|