@materializecss/materialize 2.0.0-alpha → 2.0.2-alpha
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/Gruntfile.js +7 -4
- package/README.md +24 -12
- package/dist/css/materialize.css +90 -86
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +2869 -2764
- package/dist/js/materialize.min.js +2 -2
- package/dist/js/materialize.min.js.map +1 -1
- package/package.json +1 -1
- package/sass/components/_collapsible.scss +0 -41
- package/sass/components/_global.scss +3 -2
- package/sass/components/_icons-material-design.scss +2 -1
- package/sass/components/_navbar.scss +6 -3
- package/sass/components/_sidenav.scss +66 -37
- package/sass/components/_theme_variables.scss +98 -0
- package/sass/components/_typography.scss +2 -2
- package/sass/components/forms/_input-fields.scss +4 -10
- package/sass/materialize.scss +0 -4
- package/src/autocomplete.ts +188 -94
- package/src/buttons.ts +225 -260
- package/src/cards.ts +5 -6
- package/src/carousel.ts +611 -542
- package/src/characterCounter.ts +50 -21
- package/src/chips.ts +152 -63
- package/src/collapsible.ts +97 -32
- package/src/component.ts +99 -10
- package/src/datepicker.ts +905 -726
- package/src/dropdown.ts +576 -484
- package/src/edges.ts +4 -4
- package/src/forms.ts +17 -14
- package/src/global.ts +56 -325
- package/src/materialbox.ts +354 -298
- package/src/modal.ts +296 -211
- package/src/parallax.ts +129 -105
- package/src/pushpin.ts +148 -103
- package/src/range.ts +166 -150
- package/src/scrollspy.ts +214 -174
- package/src/select.ts +434 -398
- package/src/sidenav.ts +447 -381
- package/src/slider.ts +421 -362
- package/src/tabs.ts +284 -227
- package/src/tapTarget.ts +246 -213
- package/src/timepicker.ts +738 -614
- package/src/toasts.ts +254 -230
- package/src/tooltip.ts +315 -252
- package/src/utils.ts +271 -0
- package/src/waves.ts +10 -10
package/src/toasts.ts
CHANGED
|
@@ -1,266 +1,290 @@
|
|
|
1
1
|
import anim from "animejs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
text: '',
|
|
5
|
-
displayLength: 4000,
|
|
6
|
-
inDuration: 300,
|
|
7
|
-
outDuration: 375,
|
|
8
|
-
classes: '',
|
|
9
|
-
completeCallback: null,
|
|
10
|
-
activationPercent: 0.8
|
|
11
|
-
};
|
|
3
|
+
import { BaseOptions } from "./component";
|
|
12
4
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
export interface ToastOptions extends BaseOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The content of the Toast.
|
|
8
|
+
* @default ""
|
|
9
|
+
*/
|
|
10
|
+
text: string;
|
|
11
|
+
/**
|
|
12
|
+
* Length in ms the Toast stays before dismissal.
|
|
13
|
+
* @default 4000
|
|
14
|
+
*/
|
|
15
|
+
displayLength: number;
|
|
16
|
+
/**
|
|
17
|
+
* Transition in duration in milliseconds.
|
|
18
|
+
* @default 300
|
|
19
|
+
*/
|
|
20
|
+
inDuration: number;
|
|
21
|
+
/**
|
|
22
|
+
* Transition out duration in milliseconds.
|
|
23
|
+
* @default 375
|
|
24
|
+
*/
|
|
25
|
+
outDuration: number;
|
|
26
|
+
/**
|
|
27
|
+
* Classes to be added to the toast element.
|
|
28
|
+
* @default ""
|
|
29
|
+
*/
|
|
30
|
+
classes: string;
|
|
31
|
+
/**
|
|
32
|
+
* Callback function called when toast is dismissed.
|
|
33
|
+
* @default null
|
|
34
|
+
*/
|
|
35
|
+
completeCallback: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* The percentage of the toast's width it takes fora drag
|
|
38
|
+
* to dismiss a Toast.
|
|
39
|
+
* @default 0.8
|
|
40
|
+
*/
|
|
41
|
+
activationPercent: number;
|
|
42
|
+
}
|
|
29
43
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// if (!!this.options.unsafeHTML) {
|
|
40
|
-
// this.htmlMessage = this.options.unsafeHTML;
|
|
41
|
-
// }
|
|
42
|
-
this.message = this.options.text;
|
|
43
|
-
this.panning = false;
|
|
44
|
-
this.timeRemaining = this.options.displayLength;
|
|
45
|
-
if (Toast._toasts.length === 0) {
|
|
46
|
-
Toast._createContainer();
|
|
47
|
-
}
|
|
48
|
-
// Create new toast
|
|
49
|
-
Toast._toasts.push(this);
|
|
50
|
-
let toastElement = this._createToast();
|
|
51
|
-
(toastElement as any).M_Toast = this;
|
|
52
|
-
this.el = toastElement;
|
|
53
|
-
this._animateIn();
|
|
54
|
-
this._setTimer();
|
|
55
|
-
}
|
|
44
|
+
let _defaults: ToastOptions = {
|
|
45
|
+
text: '',
|
|
46
|
+
displayLength: 4000,
|
|
47
|
+
inDuration: 300,
|
|
48
|
+
outDuration: 375,
|
|
49
|
+
classes: '',
|
|
50
|
+
completeCallback: null,
|
|
51
|
+
activationPercent: 0.8
|
|
52
|
+
};
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
export class Toast {
|
|
55
|
+
/** The toast element. */
|
|
56
|
+
el: HTMLDivElement;
|
|
57
|
+
/**
|
|
58
|
+
* The remaining amount of time in ms that the toast
|
|
59
|
+
* will stay before dismissal.
|
|
60
|
+
*/
|
|
61
|
+
timeRemaining: number;
|
|
62
|
+
/**
|
|
63
|
+
* Describes the current pan state of the Toast.
|
|
64
|
+
*/
|
|
65
|
+
panning: boolean;
|
|
66
|
+
options: ToastOptions;
|
|
67
|
+
message: string;
|
|
68
|
+
counterInterval: NodeJS.Timeout;
|
|
69
|
+
wasSwiped: boolean;
|
|
70
|
+
startingXPos: number;
|
|
71
|
+
xPos: number;
|
|
72
|
+
time: number;
|
|
73
|
+
deltaX: number;
|
|
74
|
+
velocityX: number;
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
76
|
+
static _toasts: Toast[];
|
|
77
|
+
static _container: any;
|
|
78
|
+
static _draggedToast: Toast;
|
|
65
79
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
document.body.appendChild(container);
|
|
77
|
-
Toast._container = container;
|
|
80
|
+
constructor(options: Partial<ToastOptions>) {
|
|
81
|
+
this.options = {
|
|
82
|
+
...Toast.defaults,
|
|
83
|
+
...options
|
|
84
|
+
};
|
|
85
|
+
this.message = this.options.text;
|
|
86
|
+
this.panning = false;
|
|
87
|
+
this.timeRemaining = this.options.displayLength;
|
|
88
|
+
if (Toast._toasts.length === 0) {
|
|
89
|
+
Toast._createContainer();
|
|
78
90
|
}
|
|
91
|
+
// Create new toast
|
|
92
|
+
Toast._toasts.push(this);
|
|
93
|
+
let toastElement = this._createToast();
|
|
94
|
+
(toastElement as any).M_Toast = this;
|
|
95
|
+
this.el = toastElement;
|
|
96
|
+
this._animateIn();
|
|
97
|
+
this._setTimer();
|
|
98
|
+
}
|
|
79
99
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Toast._container.remove();
|
|
84
|
-
Toast._container = null;
|
|
85
|
-
}
|
|
100
|
+
static get defaults(): ToastOptions {
|
|
101
|
+
return _defaults;
|
|
102
|
+
}
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
static getInstance(el: HTMLElement): Toast {
|
|
105
|
+
return (el as any).M_Toast;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static _createContainer() {
|
|
109
|
+
const container = document.createElement('div');
|
|
110
|
+
container.setAttribute('id', 'toast-container');
|
|
111
|
+
// Add event handler
|
|
112
|
+
container.addEventListener('touchstart', Toast._onDragStart);
|
|
113
|
+
container.addEventListener('touchmove', Toast._onDragMove);
|
|
114
|
+
container.addEventListener('touchend', Toast._onDragEnd);
|
|
115
|
+
container.addEventListener('mousedown', Toast._onDragStart);
|
|
116
|
+
document.addEventListener('mousemove', Toast._onDragMove);
|
|
117
|
+
document.addEventListener('mouseup', Toast._onDragEnd);
|
|
118
|
+
document.body.appendChild(container);
|
|
119
|
+
Toast._container = container;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static _removeContainer() {
|
|
123
|
+
document.removeEventListener('mousemove', Toast._onDragMove);
|
|
124
|
+
document.removeEventListener('mouseup', Toast._onDragEnd);
|
|
125
|
+
Toast._container.remove();
|
|
126
|
+
Toast._container = null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static _onDragStart(e: TouchEvent | MouseEvent) {
|
|
130
|
+
if (e.target && (<HTMLElement>e.target).closest('.toast')) {
|
|
131
|
+
const toastElem = (<HTMLElement>e.target).closest('.toast');
|
|
132
|
+
const toast: Toast = (toastElem as any).M_Toast;
|
|
133
|
+
toast.panning = true;
|
|
134
|
+
Toast._draggedToast = toast;
|
|
135
|
+
toast.el.classList.add('panning');
|
|
136
|
+
toast.el.style.transition = '';
|
|
137
|
+
toast.startingXPos = Toast._xPos(e);
|
|
138
|
+
toast.time = Date.now();
|
|
139
|
+
toast.xPos = Toast._xPos(e);
|
|
99
140
|
}
|
|
141
|
+
}
|
|
100
142
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
143
|
+
static _onDragMove(e: TouchEvent | MouseEvent) {
|
|
144
|
+
if (!!Toast._draggedToast) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
const toast = Toast._draggedToast;
|
|
147
|
+
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
|
148
|
+
toast.xPos = Toast._xPos(e);
|
|
149
|
+
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
|
150
|
+
toast.time = Date.now();
|
|
109
151
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
152
|
+
const totalDeltaX = toast.xPos - toast.startingXPos;
|
|
153
|
+
const activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
154
|
+
toast.el.style.transform = `translateX(${totalDeltaX}px)`;
|
|
155
|
+
toast.el.style.opacity = (1 - Math.abs(totalDeltaX / activationDistance)).toString();
|
|
115
156
|
}
|
|
157
|
+
}
|
|
116
158
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
159
|
+
static _onDragEnd() {
|
|
160
|
+
if (!!Toast._draggedToast) {
|
|
161
|
+
let toast = Toast._draggedToast;
|
|
162
|
+
toast.panning = false;
|
|
163
|
+
toast.el.classList.remove('panning');
|
|
122
164
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
165
|
+
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
166
|
+
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
167
|
+
let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
|
126
168
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
135
|
-
toast.el.style.transform = '';
|
|
136
|
-
toast.el.style.opacity = '';
|
|
137
|
-
}
|
|
138
|
-
Toast._draggedToast = null;
|
|
169
|
+
// Remove toast
|
|
170
|
+
if (shouldBeDismissed) {
|
|
171
|
+
toast.wasSwiped = true;
|
|
172
|
+
toast.dismiss();
|
|
173
|
+
// Animate toast back to original position
|
|
139
174
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return e.targetTouches[0].clientX;
|
|
175
|
+
else {
|
|
176
|
+
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
177
|
+
toast.el.style.transform = '';
|
|
178
|
+
toast.el.style.opacity = '';
|
|
145
179
|
}
|
|
146
|
-
|
|
147
|
-
return e.clientX;
|
|
180
|
+
Toast._draggedToast = null;
|
|
148
181
|
}
|
|
182
|
+
}
|
|
149
183
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
184
|
+
static _xPos(e: TouchEvent | MouseEvent) {
|
|
185
|
+
if (e.type.startsWith("touch") && (e as TouchEvent).targetTouches.length >= 1) {
|
|
186
|
+
return (e as TouchEvent).targetTouches[0].clientX;
|
|
154
187
|
}
|
|
188
|
+
// mouse event
|
|
189
|
+
return (e as MouseEvent).clientX;
|
|
190
|
+
}
|
|
155
191
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
192
|
+
/**
|
|
193
|
+
* dismiss all toasts.
|
|
194
|
+
*/
|
|
195
|
+
static dismissAll() {
|
|
196
|
+
for (let toastIndex in Toast._toasts) {
|
|
197
|
+
Toast._toasts[toastIndex].dismiss();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
162
200
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
_createToast() {
|
|
202
|
+
const toast = document.createElement('div');
|
|
203
|
+
toast.classList.add('toast');
|
|
204
|
+
toast.setAttribute('role', 'alert');
|
|
205
|
+
toast.setAttribute('aria-live', 'assertive');
|
|
206
|
+
toast.setAttribute('aria-atomic', 'true');
|
|
167
207
|
|
|
168
|
-
|
|
169
|
-
|
|
208
|
+
// Add custom classes onto toast
|
|
209
|
+
if (this.options.classes.length > 0) {
|
|
210
|
+
toast.classList.add(...this.options.classes.split(' '));
|
|
211
|
+
}
|
|
170
212
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// ? this.htmlMessage instanceof HTMLElement
|
|
174
|
-
// : this.htmlMessage &&
|
|
175
|
-
// typeof this.htmlMessage === 'object' &&
|
|
176
|
-
// this.htmlMessage !== null &&
|
|
177
|
-
// this.htmlMessage.nodeType === 1 &&
|
|
178
|
-
// typeof this.htmlMessage.nodeName === 'string'
|
|
179
|
-
// ) {
|
|
180
|
-
// //if the htmlMessage is an HTML node, append it directly
|
|
181
|
-
// toast.appendChild(this.htmlMessage);
|
|
182
|
-
// }
|
|
183
|
-
// else if (!!this.htmlMessage.jquery) {
|
|
184
|
-
// // Check if it is jQuery object, append the node
|
|
185
|
-
// $(toast).append(this.htmlMessage[0]);
|
|
186
|
-
// }
|
|
187
|
-
// else {
|
|
188
|
-
// // Append as unsanitized html;
|
|
189
|
-
// $(toast).append(this.htmlMessage);
|
|
190
|
-
// }
|
|
213
|
+
// Set text content
|
|
214
|
+
else toast.innerText = this.message;
|
|
191
215
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
216
|
+
// Append toast
|
|
217
|
+
Toast._container.appendChild(toast);
|
|
218
|
+
return toast;
|
|
219
|
+
}
|
|
196
220
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
221
|
+
_animateIn() {
|
|
222
|
+
// Animate toast in
|
|
223
|
+
anim({
|
|
224
|
+
targets: this.el,
|
|
225
|
+
top: 0,
|
|
226
|
+
opacity: 1,
|
|
227
|
+
duration: this.options.inDuration,
|
|
228
|
+
easing: 'easeOutCubic'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
207
231
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
232
|
+
/**
|
|
233
|
+
* Create setInterval which automatically removes toast when timeRemaining >= 0
|
|
234
|
+
* has been reached.
|
|
235
|
+
*/
|
|
236
|
+
_setTimer() {
|
|
237
|
+
if (this.timeRemaining !== Infinity) {
|
|
238
|
+
this.counterInterval = setInterval(() => {
|
|
239
|
+
// If toast is not being dragged, decrease its time remaining
|
|
240
|
+
if (!this.panning) {
|
|
241
|
+
this.timeRemaining -= 20;
|
|
242
|
+
}
|
|
243
|
+
// Animate toast out
|
|
244
|
+
if (this.timeRemaining <= 0) {
|
|
245
|
+
this.dismiss();
|
|
246
|
+
}
|
|
247
|
+
}, 20);
|
|
225
248
|
}
|
|
249
|
+
}
|
|
226
250
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Dismiss toast with animation.
|
|
253
|
+
*/
|
|
254
|
+
dismiss() {
|
|
255
|
+
window.clearInterval(this.counterInterval);
|
|
256
|
+
let activationDistance = this.el.offsetWidth * this.options.activationPercent;
|
|
233
257
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
258
|
+
if (this.wasSwiped) {
|
|
259
|
+
this.el.style.transition = 'transform .05s, opacity .05s';
|
|
260
|
+
this.el.style.transform = `translateX(${activationDistance}px)`;
|
|
261
|
+
this.el.style.opacity = '0';
|
|
262
|
+
}
|
|
239
263
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
// Remove toast from DOM
|
|
252
|
-
this.el.remove();
|
|
253
|
-
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
|
|
254
|
-
if (Toast._toasts.length === 0) {
|
|
255
|
-
Toast._removeContainer();
|
|
256
|
-
}
|
|
264
|
+
anim({
|
|
265
|
+
targets: this.el,
|
|
266
|
+
opacity: 0,
|
|
267
|
+
marginTop: -40,
|
|
268
|
+
duration: this.options.outDuration,
|
|
269
|
+
easing: 'easeOutExpo',
|
|
270
|
+
complete: () => {
|
|
271
|
+
// Call the optional callback
|
|
272
|
+
if (typeof this.options.completeCallback === 'function') {
|
|
273
|
+
this.options.completeCallback();
|
|
257
274
|
}
|
|
258
|
-
|
|
259
|
-
|
|
275
|
+
// Remove toast from DOM
|
|
276
|
+
this.el.remove();
|
|
277
|
+
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
|
|
278
|
+
if (Toast._toasts.length === 0) {
|
|
279
|
+
Toast._removeContainer();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
260
284
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
285
|
+
static {
|
|
286
|
+
Toast._toasts = [];
|
|
287
|
+
Toast._container = null;
|
|
288
|
+
Toast._draggedToast = null;
|
|
266
289
|
}
|
|
290
|
+
}
|