@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.
Files changed (46) hide show
  1. package/Gruntfile.js +7 -4
  2. package/README.md +24 -12
  3. package/dist/css/materialize.css +90 -86
  4. package/dist/css/materialize.min.css +2 -2
  5. package/dist/js/materialize.js +2869 -2764
  6. package/dist/js/materialize.min.js +2 -2
  7. package/dist/js/materialize.min.js.map +1 -1
  8. package/package.json +1 -1
  9. package/sass/components/_collapsible.scss +0 -41
  10. package/sass/components/_global.scss +3 -2
  11. package/sass/components/_icons-material-design.scss +2 -1
  12. package/sass/components/_navbar.scss +6 -3
  13. package/sass/components/_sidenav.scss +66 -37
  14. package/sass/components/_theme_variables.scss +98 -0
  15. package/sass/components/_typography.scss +2 -2
  16. package/sass/components/forms/_input-fields.scss +4 -10
  17. package/sass/materialize.scss +0 -4
  18. package/src/autocomplete.ts +188 -94
  19. package/src/buttons.ts +225 -260
  20. package/src/cards.ts +5 -6
  21. package/src/carousel.ts +611 -542
  22. package/src/characterCounter.ts +50 -21
  23. package/src/chips.ts +152 -63
  24. package/src/collapsible.ts +97 -32
  25. package/src/component.ts +99 -10
  26. package/src/datepicker.ts +905 -726
  27. package/src/dropdown.ts +576 -484
  28. package/src/edges.ts +4 -4
  29. package/src/forms.ts +17 -14
  30. package/src/global.ts +56 -325
  31. package/src/materialbox.ts +354 -298
  32. package/src/modal.ts +296 -211
  33. package/src/parallax.ts +129 -105
  34. package/src/pushpin.ts +148 -103
  35. package/src/range.ts +166 -150
  36. package/src/scrollspy.ts +214 -174
  37. package/src/select.ts +434 -398
  38. package/src/sidenav.ts +447 -381
  39. package/src/slider.ts +421 -362
  40. package/src/tabs.ts +284 -227
  41. package/src/tapTarget.ts +246 -213
  42. package/src/timepicker.ts +738 -614
  43. package/src/toasts.ts +254 -230
  44. package/src/tooltip.ts +315 -252
  45. package/src/utils.ts +271 -0
  46. package/src/waves.ts +10 -10
package/src/toasts.ts CHANGED
@@ -1,266 +1,290 @@
1
1
  import anim from "animejs";
2
2
 
3
- let _defaults = {
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
- export class Toast {
14
- static _toasts: Toast[];
15
- static _container: any;
16
- static _draggedToast: Toast;
17
- options: any;
18
- message: string;
19
- panning: boolean;
20
- timeRemaining: number;
21
- el: HTMLDivElement;
22
- counterInterval: NodeJS.Timeout;
23
- wasSwiped: any;
24
- startingXPos: number;
25
- xPos: any;
26
- time: number;
27
- deltaX: number;
28
- velocityX: number;
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
- constructor(options: any) {
31
- this.options = {...Toast.defaults, ...options};
32
- //this.htmlMessage = this.options.html;
33
- // Warn when using html
34
- // if (!!this.options.html)
35
- // console.warn(
36
- // 'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
37
- // );
38
- // If the new unsafeHTML is used, prefer that
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
- static get defaults() {
58
- return _defaults;
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
- static getInstance(el) {
62
- let domElem = !!el.jquery ? el[0] : el;
63
- return domElem.M_Toast;
64
- }
76
+ static _toasts: Toast[];
77
+ static _container: any;
78
+ static _draggedToast: Toast;
65
79
 
66
- static _createContainer() {
67
- const container = document.createElement('div');
68
- container.setAttribute('id', 'toast-container');
69
- // Add event handler
70
- container.addEventListener('touchstart', Toast._onDragStart);
71
- container.addEventListener('touchmove', Toast._onDragMove);
72
- container.addEventListener('touchend', Toast._onDragEnd);
73
- container.addEventListener('mousedown', Toast._onDragStart);
74
- document.addEventListener('mousemove', Toast._onDragMove);
75
- document.addEventListener('mouseup', Toast._onDragEnd);
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
- static _removeContainer() {
81
- document.removeEventListener('mousemove', Toast._onDragMove);
82
- document.removeEventListener('mouseup', Toast._onDragEnd);
83
- Toast._container.remove();
84
- Toast._container = null;
85
- }
100
+ static get defaults(): ToastOptions {
101
+ return _defaults;
102
+ }
86
103
 
87
- static _onDragStart(e) {
88
- if (e.target && (<HTMLElement>e.target).closest('.toast')) {
89
- const toastElem = (<HTMLElement>e.target).closest('.toast');
90
- const toast: Toast = (toastElem as any).M_Toast;
91
- toast.panning = true;
92
- Toast._draggedToast = toast;
93
- toast.el.classList.add('panning');
94
- toast.el.style.transition = '';
95
- toast.startingXPos = Toast._xPos(e);
96
- toast.time = Date.now();
97
- toast.xPos = Toast._xPos(e);
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
- static _onDragMove(e) {
102
- if (!!Toast._draggedToast) {
103
- e.preventDefault();
104
- const toast = Toast._draggedToast;
105
- toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
106
- toast.xPos = Toast._xPos(e);
107
- toast.velocityX = toast.deltaX / (Date.now() - toast.time);
108
- toast.time = Date.now();
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
- const totalDeltaX = toast.xPos - toast.startingXPos;
111
- const activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
112
- toast.el.style.transform = `translateX(${totalDeltaX}px)`;
113
- toast.el.style.opacity = (1 - Math.abs(totalDeltaX / activationDistance)).toString();
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
- static _onDragEnd() {
118
- if (!!Toast._draggedToast) {
119
- let toast = Toast._draggedToast;
120
- toast.panning = false;
121
- toast.el.classList.remove('panning');
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
- let totalDeltaX = toast.xPos - toast.startingXPos;
124
- let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
125
- let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
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
- // Remove toast
128
- if (shouldBeDismissed) {
129
- toast.wasSwiped = true;
130
- toast.dismiss();
131
- // Animate toast back to original position
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
- static _xPos(e) {
143
- if (e.targetTouches && e.targetTouches.length >= 1) {
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
- // mouse event
147
- return e.clientX;
180
+ Toast._draggedToast = null;
148
181
  }
182
+ }
149
183
 
150
- static dismissAll() {
151
- for (let toastIndex in Toast._toasts) {
152
- Toast._toasts[toastIndex].dismiss();
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
- _createToast() {
157
- const toast = document.createElement('div');
158
- toast.classList.add('toast');
159
- toast.setAttribute('role', 'alert');
160
- toast.setAttribute('aria-live', 'assertive');
161
- toast.setAttribute('aria-atomic', 'true');
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
- // Add custom classes onto toast
164
- if (this.options.classes.length > 0) {
165
- toast.classList.add(...this.options.classes.split(' '));
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
- // Set safe text content
169
- toast.innerText = this.message;
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
- // if (
172
- // typeof HTMLElement === 'object'
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
- // Append toast
193
- Toast._container.appendChild(toast);
194
- return toast;
195
- }
216
+ // Append toast
217
+ Toast._container.appendChild(toast);
218
+ return toast;
219
+ }
196
220
 
197
- _animateIn() {
198
- // Animate toast in
199
- anim({
200
- targets: this.el,
201
- top: 0,
202
- opacity: 1,
203
- duration: this.options.inDuration,
204
- easing: 'easeOutCubic'
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
- * Create setInterval which automatically removes toast when timeRemaining >= 0
210
- * has been reached
211
- */
212
- _setTimer() {
213
- if (this.timeRemaining !== Infinity) {
214
- this.counterInterval = setInterval(() => {
215
- // If toast is not being dragged, decrease its time remaining
216
- if (!this.panning) {
217
- this.timeRemaining -= 20;
218
- }
219
- // Animate toast out
220
- if (this.timeRemaining <= 0) {
221
- this.dismiss();
222
- }
223
- }, 20);
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
- * Dismiss toast with animation
229
- */
230
- dismiss() {
231
- window.clearInterval(this.counterInterval);
232
- let activationDistance = this.el.offsetWidth * this.options.activationPercent;
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
- if (this.wasSwiped) {
235
- this.el.style.transition = 'transform .05s, opacity .05s';
236
- this.el.style.transform = `translateX(${activationDistance}px)`;
237
- this.el.style.opacity = '0';
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
- anim({
241
- targets: this.el,
242
- opacity: 0,
243
- marginTop: -40,
244
- duration: this.options.outDuration,
245
- easing: 'easeOutExpo',
246
- complete: () => {
247
- // Call the optional callback
248
- if (typeof this.options.completeCallback === 'function') {
249
- this.options.completeCallback();
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
- static {
262
- Toast._toasts = [];
263
- Toast._container = null;
264
- Toast._draggedToast = null;
265
- }
285
+ static {
286
+ Toast._toasts = [];
287
+ Toast._container = null;
288
+ Toast._draggedToast = null;
266
289
  }
290
+ }