@materializecss/materialize 2.0.3-beta → 2.0.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.
Files changed (66) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -18
  3. package/dist/css/materialize.css +73 -26
  4. package/dist/css/materialize.min.css +3 -3
  5. package/dist/js/materialize.js +560 -2015
  6. package/dist/js/materialize.min.js +3 -3
  7. package/dist/js/materialize.min.js.map +1 -1
  8. package/dist/src/buttons.d.ts.map +1 -1
  9. package/dist/src/cards.d.ts.map +1 -1
  10. package/dist/src/collapsible.d.ts +1 -0
  11. package/dist/src/collapsible.d.ts.map +1 -1
  12. package/dist/src/dropdown.d.ts +1 -0
  13. package/dist/src/dropdown.d.ts.map +1 -1
  14. package/dist/src/global.d.ts.map +1 -1
  15. package/dist/src/materialbox.d.ts +14 -10
  16. package/dist/src/materialbox.d.ts.map +1 -1
  17. package/dist/src/modal.d.ts.map +1 -1
  18. package/dist/src/range.d.ts.map +1 -1
  19. package/dist/src/scrollspy.d.ts.map +1 -1
  20. package/dist/src/sidenav.d.ts +25 -25
  21. package/dist/src/sidenav.d.ts.map +1 -1
  22. package/dist/src/slider.d.ts +12 -12
  23. package/dist/src/slider.d.ts.map +1 -1
  24. package/dist/src/tabs.d.ts +1 -1
  25. package/dist/src/tabs.d.ts.map +1 -1
  26. package/dist/src/toasts.d.ts +7 -2
  27. package/dist/src/toasts.d.ts.map +1 -1
  28. package/dist/src/tooltip.d.ts.map +1 -1
  29. package/package.json +29 -44
  30. package/sass/components/_collapsible.scss +14 -2
  31. package/sass/components/_materialbox.scss +2 -2
  32. package/sass/components/_modal.scss +0 -1
  33. package/sass/components/_tooltip.scss +18 -8
  34. package/sass/components/_variables.scss +2 -2
  35. package/Gruntfile.js +0 -385
  36. package/src/autocomplete.ts +0 -553
  37. package/src/bounding.ts +0 -6
  38. package/src/buttons.ts +0 -260
  39. package/src/cards.ts +0 -53
  40. package/src/carousel.ts +0 -676
  41. package/src/characterCounter.ts +0 -117
  42. package/src/chips.ts +0 -439
  43. package/src/collapsible.ts +0 -249
  44. package/src/component.ts +0 -120
  45. package/src/datepicker.ts +0 -1076
  46. package/src/dropdown.ts +0 -644
  47. package/src/edges.ts +0 -6
  48. package/src/forms.ts +0 -132
  49. package/src/global.ts +0 -114
  50. package/src/index.ts +0 -26
  51. package/src/materialbox.ts +0 -404
  52. package/src/modal.ts +0 -341
  53. package/src/parallax.ts +0 -149
  54. package/src/pushpin.ts +0 -165
  55. package/src/range.ts +0 -198
  56. package/src/scrollspy.ts +0 -263
  57. package/src/select.ts +0 -484
  58. package/src/sidenav.ts +0 -543
  59. package/src/slider.ts +0 -474
  60. package/src/tabs.ts +0 -347
  61. package/src/tapTarget.ts +0 -273
  62. package/src/timepicker.ts +0 -832
  63. package/src/toasts.ts +0 -290
  64. package/src/tooltip.ts +0 -366
  65. package/src/utils.ts +0 -271
  66. package/src/waves.ts +0 -70
package/src/sidenav.ts DELETED
@@ -1,543 +0,0 @@
1
- import anim from "animejs";
2
-
3
- import { Utils } from "./utils";
4
- import { Component, BaseOptions, InitElements, MElement, Openable } from "./component";
5
-
6
- export interface SidenavOptions extends BaseOptions {
7
- /**
8
- * Side of screen on which Sidenav appears.
9
- * @default 'left'
10
- */
11
- edge: 'left' | 'right';
12
- /**
13
- * Allow swipe gestures to open/close Sidenav.
14
- * @default true
15
- */
16
- draggable: boolean;
17
- /**
18
- * Width of the area where you can start dragging.
19
- * @default '10px'
20
- */
21
- dragTargetWidth: string;
22
- /**
23
- * Length in ms of enter transition.
24
- * @default 250
25
- */
26
- inDuration: number;
27
- /**
28
- * Length in ms of exit transition.
29
- * @default 200
30
- */
31
- outDuration: number;
32
- /**
33
- * Prevent page from scrolling while sidenav is open.
34
- * @default true
35
- */
36
- preventScrolling: boolean;
37
- /**
38
- * Function called when sidenav starts entering.
39
- */
40
- onOpenStart: (elem: HTMLElement) => void;
41
- /**
42
- * Function called when sidenav finishes entering.
43
- */
44
- onOpenEnd: (elem: HTMLElement) => void;
45
- /**
46
- * Function called when sidenav starts exiting.
47
- */
48
- onCloseStart: (elem: HTMLElement) => void;
49
- /**
50
- * Function called when sidenav finishes exiting.
51
- */
52
- onCloseEnd: (elem: HTMLElement) => void;
53
- }
54
-
55
- const _defaults: SidenavOptions = {
56
- edge: 'left',
57
- draggable: true,
58
- dragTargetWidth: '10px',
59
- inDuration: 250,
60
- outDuration: 200,
61
- onOpenStart: null,
62
- onOpenEnd: null,
63
- onCloseStart: null,
64
- onCloseEnd: null,
65
- preventScrolling: true
66
- };
67
-
68
- export class Sidenav extends Component<SidenavOptions> implements Openable {
69
- id: string;
70
- /** Describes open/close state of Sidenav. */
71
- isOpen: boolean;
72
- /** Describes if sidenav is fixed. */
73
- isFixed: boolean;
74
- /** Describes if Sidenav is being dragged. */
75
- isDragged: boolean;
76
- lastWindowWidth: number;
77
- lastWindowHeight: number;
78
- static _sidenavs: Sidenav[];
79
- private _overlay: HTMLElement;
80
- dragTarget: Element;
81
- private _startingXpos: number;
82
- private _xPos: number;
83
- private _time: number;
84
- private _width: number;
85
- private _initialScrollTop: number;
86
- private _verticallyScrolling: boolean;
87
- private deltaX: number;
88
- private velocityX: number;
89
- private percentOpen: number;
90
-
91
- constructor(el: HTMLElement, options: Partial<SidenavOptions>) {
92
- super(el, options, Sidenav);
93
- (this.el as any).M_Sidenav = this;
94
-
95
- this.options = {
96
- ...Sidenav.defaults,
97
- ...options
98
- };
99
-
100
- this.id = this.el.id;
101
- this.isOpen = false;
102
- this.isFixed = this.el.classList.contains('sidenav-fixed');
103
- this.isDragged = false;
104
- // Window size variables for window resize checks
105
- this.lastWindowWidth = window.innerWidth;
106
- this.lastWindowHeight = window.innerHeight;
107
- this._createOverlay();
108
- this._createDragTarget();
109
- this._setupEventHandlers();
110
- this._setupClasses();
111
- this._setupFixed();
112
- Sidenav._sidenavs.push(this);
113
- }
114
-
115
- static get defaults(): SidenavOptions {
116
- return _defaults;
117
- }
118
-
119
- /**
120
- * Initializes instance of Sidenav.
121
- * @param el HTML element.
122
- * @param options Component options.
123
- */
124
- static init(el: HTMLElement, options?: Partial<SidenavOptions>): Sidenav;
125
- /**
126
- * Initializes instances of Sidenav.
127
- * @param els HTML elements.
128
- * @param options Component options.
129
- */
130
- static init(els: InitElements<MElement>, options?: Partial<SidenavOptions>): Sidenav[];
131
- /**
132
- * Initializes instances of Sidenav.
133
- * @param els HTML elements.
134
- * @param options Component options.
135
- */
136
- static init(els: HTMLElement | InitElements<MElement>, options: Partial<SidenavOptions> = {}): Sidenav | Sidenav[] {
137
- return super.init(els, options, Sidenav);
138
- }
139
-
140
- static getInstance(el: HTMLElement): Sidenav {
141
- return (el as any).M_Sidenav;
142
- }
143
-
144
- destroy() {
145
- this._removeEventHandlers();
146
- this._enableBodyScrolling();
147
- this._overlay.parentNode.removeChild(this._overlay);
148
- this.dragTarget.parentNode.removeChild(this.dragTarget);
149
- (this.el as any).M_Sidenav = undefined;
150
- (this.el as HTMLElement).style.transform = '';
151
- const index = Sidenav._sidenavs.indexOf(this);
152
- if (index >= 0) {
153
- Sidenav._sidenavs.splice(index, 1);
154
- }
155
- }
156
-
157
- _createOverlay() {
158
- this._overlay = document.createElement('div');
159
- this._overlay.classList.add('sidenav-overlay');
160
- this._overlay.addEventListener('click', this.close);
161
- document.body.appendChild(this._overlay);
162
- }
163
-
164
- _setupEventHandlers() {
165
- if (Sidenav._sidenavs.length === 0) {
166
- document.body.addEventListener('click', this._handleTriggerClick);
167
- }
168
- var passiveIfSupported: boolean = null;
169
- this.dragTarget.addEventListener('touchmove', this._handleDragTargetDrag, passiveIfSupported);
170
- this.dragTarget.addEventListener('touchend', this._handleDragTargetRelease);
171
- this._overlay.addEventListener('touchmove', this._handleCloseDrag, passiveIfSupported);
172
- this._overlay.addEventListener('touchend', this._handleCloseRelease);
173
- this.el.addEventListener('touchmove', this._handleCloseDrag, passiveIfSupported);
174
- this.el.addEventListener('touchend', this._handleCloseRelease);
175
- this.el.addEventListener('click', this._handleCloseTriggerClick);
176
- // Add resize for side nav fixed
177
- if (this.isFixed) {
178
- window.addEventListener('resize', this._handleWindowResize);
179
- }
180
- }
181
-
182
- _removeEventHandlers() {
183
- if (Sidenav._sidenavs.length === 1) {
184
- document.body.removeEventListener('click', this._handleTriggerClick);
185
- }
186
- this.dragTarget.removeEventListener('touchmove', this._handleDragTargetDrag);
187
- this.dragTarget.removeEventListener('touchend', this._handleDragTargetRelease);
188
- this._overlay.removeEventListener('touchmove', this._handleCloseDrag);
189
- this._overlay.removeEventListener('touchend', this._handleCloseRelease);
190
- this.el.removeEventListener('touchmove', this._handleCloseDrag);
191
- this.el.removeEventListener('touchend', this._handleCloseRelease);
192
- this.el.removeEventListener('click', this._handleCloseTriggerClick);
193
-
194
- // Remove resize for side nav fixed
195
- if (this.isFixed) {
196
- window.removeEventListener('resize', this._handleWindowResize);
197
- }
198
- }
199
-
200
- _handleTriggerClick(e) {
201
- const trigger = e.target.closest('.sidenav-trigger');
202
- if (e.target && trigger) {
203
- const sidenavId = Utils.getIdFromTrigger(trigger);
204
- const sidenavInstance = (document.getElementById(sidenavId) as any).M_Sidenav;
205
- if (sidenavInstance) {
206
- sidenavInstance.open(trigger);
207
- }
208
- e.preventDefault();
209
- }
210
- }
211
-
212
- // Set variables needed at the beginning of drag and stop any current transition.
213
- _startDrag(e) {
214
- const clientX = e.targetTouches[0].clientX;
215
- this.isDragged = true;
216
- this._startingXpos = clientX;
217
- this._xPos = this._startingXpos;
218
- this._time = Date.now();
219
- this._width = this.el.getBoundingClientRect().width;
220
- this._overlay.style.display = 'block';
221
- this._initialScrollTop = this.isOpen ? this.el.scrollTop : Utils.getDocumentScrollTop();
222
- this._verticallyScrolling = false;
223
- anim.remove(this.el);
224
- anim.remove(this._overlay);
225
- }
226
-
227
- //Set variables needed at each drag move update tick
228
- _dragMoveUpdate(e) {
229
- const clientX = e.targetTouches[0].clientX;
230
- const currentScrollTop = this.isOpen ? this.el.scrollTop : Utils.getDocumentScrollTop();
231
- this.deltaX = Math.abs(this._xPos - clientX);
232
- this._xPos = clientX;
233
- this.velocityX = this.deltaX / (Date.now() - this._time);
234
- this._time = Date.now();
235
- if (this._initialScrollTop !== currentScrollTop) {
236
- this._verticallyScrolling = true;
237
- }
238
- }
239
-
240
- _handleDragTargetDrag = (e) => {
241
- // Check if draggable
242
- if (!this.options.draggable || this._isCurrentlyFixed() || this._verticallyScrolling) {
243
- return;
244
- }
245
- // If not being dragged, set initial drag start variables
246
- if (!this.isDragged) {
247
- this._startDrag(e);
248
- }
249
- // Run touchmove updates
250
- this._dragMoveUpdate(e);
251
- // Calculate raw deltaX
252
- let totalDeltaX = this._xPos - this._startingXpos;
253
- // dragDirection is the attempted user drag direction
254
- const dragDirection = totalDeltaX > 0 ? 'right' : 'left';
255
- // Don't allow totalDeltaX to exceed Sidenav width or be dragged in the opposite direction
256
- totalDeltaX = Math.min(this._width, Math.abs(totalDeltaX));
257
- if (this.options.edge === dragDirection) {
258
- totalDeltaX = 0;
259
- }
260
- /**
261
- * transformX is the drag displacement
262
- * transformPrefix is the initial transform placement
263
- * Invert values if Sidenav is right edge
264
- */
265
- let transformX = totalDeltaX;
266
- let transformPrefix = 'translateX(-100%)';
267
- if (this.options.edge === 'right') {
268
- transformPrefix = 'translateX(100%)';
269
- transformX = -transformX;
270
- }
271
- // Calculate open/close percentage of sidenav, with open = 1 and close = 0
272
- this.percentOpen = Math.min(1, totalDeltaX / this._width);
273
- // Set transform and opacity styles
274
- (this.el as HTMLElement).style.transform = `${transformPrefix} translateX(${transformX}px)`;
275
- this._overlay.style.opacity = this.percentOpen.toString();
276
- }
277
-
278
- _handleDragTargetRelease = () => {
279
- if (this.isDragged) {
280
- if (this.percentOpen > 0.2) {
281
- this.open();
282
- } else {
283
- this._animateOut();
284
- }
285
- this.isDragged = false;
286
- this._verticallyScrolling = false;
287
- }
288
- }
289
-
290
- _handleCloseDrag = (e) => {
291
- if (this.isOpen) {
292
- // Check if draggable
293
- if (!this.options.draggable || this._isCurrentlyFixed() || this._verticallyScrolling) {
294
- return;
295
- }
296
- // If not being dragged, set initial drag start variables
297
- if (!this.isDragged) {
298
- this._startDrag(e);
299
- }
300
- // Run touchmove updates
301
- this._dragMoveUpdate(e);
302
- // Calculate raw deltaX
303
- let totalDeltaX = this._xPos - this._startingXpos;
304
- // dragDirection is the attempted user drag direction
305
- let dragDirection = totalDeltaX > 0 ? 'right' : 'left';
306
- // Don't allow totalDeltaX to exceed Sidenav width or be dragged in the opposite direction
307
- totalDeltaX = Math.min(this._width, Math.abs(totalDeltaX));
308
- if (this.options.edge !== dragDirection) {
309
- totalDeltaX = 0;
310
- }
311
- let transformX = -totalDeltaX;
312
- if (this.options.edge === 'right') {
313
- transformX = -transformX;
314
- }
315
- // Calculate open/close percentage of sidenav, with open = 1 and close = 0
316
- this.percentOpen = Math.min(1, 1 - totalDeltaX / this._width);
317
- // Set transform and opacity styles
318
- (this.el as HTMLElement).style.transform = `translateX(${transformX}px)`;
319
- this._overlay.style.opacity = this.percentOpen.toString();
320
- }
321
- }
322
-
323
- _handleCloseRelease = () => {
324
- if (this.isOpen && this.isDragged) {
325
- if (this.percentOpen > 0.8) {
326
- this._animateIn();
327
- } else {
328
- this.close();
329
- }
330
- this.isDragged = false;
331
- this._verticallyScrolling = false;
332
- }
333
- }
334
-
335
- // Handles closing of Sidenav when element with class .sidenav-close
336
- _handleCloseTriggerClick = (e) => {
337
- const closeTrigger = e.target.closest('.sidenav-close');
338
- if (closeTrigger && !this._isCurrentlyFixed()) {
339
- this.close();
340
- }
341
- }
342
-
343
- _handleWindowResize = () => {
344
- // Only handle horizontal resizes
345
- if (this.lastWindowWidth !== window.innerWidth) {
346
- if (window.innerWidth > 992) {
347
- this.open();
348
- } else {
349
- this.close();
350
- }
351
- }
352
- this.lastWindowWidth = window.innerWidth;
353
- this.lastWindowHeight = window.innerHeight;
354
- }
355
-
356
- _setupClasses() {
357
- if (this.options.edge === 'right') {
358
- this.el.classList.add('right-aligned');
359
- this.dragTarget.classList.add('right-aligned');
360
- }
361
- }
362
-
363
- _removeClasses() {
364
- this.el.classList.remove('right-aligned');
365
- this.dragTarget.classList.remove('right-aligned');
366
- }
367
-
368
- _setupFixed() {
369
- if (this._isCurrentlyFixed()) this.open();
370
- }
371
-
372
- _isCurrentlyFixed() {
373
- return this.isFixed && window.innerWidth > 992;
374
- }
375
-
376
- _createDragTarget() {
377
- const dragTarget = document.createElement('div');
378
- dragTarget.classList.add('drag-target');
379
- dragTarget.style.width = this.options.dragTargetWidth;
380
- document.body.appendChild(dragTarget);
381
- this.dragTarget = dragTarget;
382
- }
383
-
384
- _preventBodyScrolling() {
385
- document.body.style.overflow = 'hidden';
386
- }
387
-
388
- _enableBodyScrolling() {
389
- document.body.style.overflow = '';
390
- }
391
-
392
- /**
393
- * Opens Sidenav.
394
- */
395
- open = () => {
396
- if (this.isOpen === true) return;
397
- this.isOpen = true;
398
- // Run onOpenStart callback
399
- if (typeof this.options.onOpenStart === 'function') {
400
- this.options.onOpenStart.call(this, this.el);
401
- }
402
- // Handle fixed Sidenav
403
- if (this._isCurrentlyFixed()) {
404
- anim.remove(this.el);
405
- anim({
406
- targets: this.el,
407
- translateX: 0,
408
- duration: 0,
409
- easing: 'easeOutQuad'
410
- });
411
- this._enableBodyScrolling();
412
- this._overlay.style.display = 'none';
413
- }
414
- // Handle non-fixed Sidenav
415
- else {
416
- if (this.options.preventScrolling) {
417
- this._preventBodyScrolling();
418
- }
419
-
420
- if (!this.isDragged || this.percentOpen != 1) {
421
- this._animateIn();
422
- }
423
- }
424
- }
425
-
426
- /**
427
- * Closes Sidenav.
428
- */
429
- close = () => {
430
- if (this.isOpen === false) return;
431
- this.isOpen = false;
432
- // Run onCloseStart callback
433
- if (typeof this.options.onCloseStart === 'function') {
434
- this.options.onCloseStart.call(this, this.el);
435
- }
436
- // Handle fixed Sidenav
437
- if (this._isCurrentlyFixed()) {
438
- const transformX = this.options.edge === 'left' ? '-105%' : '105%';
439
- (this.el as HTMLElement).style.transform = `translateX(${transformX})`;
440
- }
441
- // Handle non-fixed Sidenav
442
- else {
443
- this._enableBodyScrolling();
444
- if (!this.isDragged || this.percentOpen != 0) {
445
- this._animateOut();
446
- } else {
447
- this._overlay.style.display = 'none';
448
- }
449
- }
450
- }
451
-
452
- _animateIn() {
453
- this._animateSidenavIn();
454
- this._animateOverlayIn();
455
- }
456
-
457
- _animateSidenavIn() {
458
- let slideOutPercent = this.options.edge === 'left' ? -1 : 1;
459
- if (this.isDragged) {
460
- slideOutPercent =
461
- this.options.edge === 'left'
462
- ? slideOutPercent + this.percentOpen
463
- : slideOutPercent - this.percentOpen;
464
- }
465
- anim.remove(this.el);
466
- anim({
467
- targets: this.el,
468
- translateX: [`${slideOutPercent * 100}%`, 0],
469
- duration: this.options.inDuration,
470
- easing: 'easeOutQuad',
471
- complete: () => {
472
- // Run onOpenEnd callback
473
- if (typeof this.options.onOpenEnd === 'function') {
474
- this.options.onOpenEnd.call(this, this.el);
475
- }
476
- }
477
- });
478
- }
479
-
480
- _animateOverlayIn() {
481
- let start = 0;
482
- if (this.isDragged) {
483
- start = this.percentOpen;
484
- }
485
- else {
486
- this._overlay.style.display = 'block';
487
- }
488
- anim.remove(this._overlay);
489
- anim({
490
- targets: this._overlay,
491
- opacity: [start, 1],
492
- duration: this.options.inDuration,
493
- easing: 'easeOutQuad'
494
- });
495
- }
496
-
497
- _animateOut() {
498
- this._animateSidenavOut();
499
- this._animateOverlayOut();
500
- }
501
-
502
- _animateSidenavOut() {
503
- const endPercent = this.options.edge === 'left' ? -1 : 1;
504
- let slideOutPercent = 0;
505
- if (this.isDragged) {
506
- slideOutPercent =
507
- this.options.edge === 'left'
508
- ? endPercent + this.percentOpen
509
- : endPercent - this.percentOpen;
510
- }
511
-
512
- anim.remove(this.el);
513
- anim({
514
- targets: this.el,
515
- translateX: [`${slideOutPercent * 100}%`, `${endPercent * 105}%`],
516
- duration: this.options.outDuration,
517
- easing: 'easeOutQuad',
518
- complete: () => {
519
- // Run onOpenEnd callback
520
- if (typeof this.options.onCloseEnd === 'function') {
521
- this.options.onCloseEnd.call(this, this.el);
522
- }
523
- }
524
- });
525
- }
526
-
527
- _animateOverlayOut() {
528
- anim.remove(this._overlay);
529
- anim({
530
- targets: this._overlay,
531
- opacity: 0,
532
- duration: this.options.outDuration,
533
- easing: 'easeOutQuad',
534
- complete: () => {
535
- this._overlay.style.display = 'none';
536
- }
537
- });
538
- }
539
-
540
- static {
541
- Sidenav._sidenavs = [];
542
- }
543
- }