@materializecss/materialize 2.0.3-beta → 2.0.3

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 (64) hide show
  1. package/README.md +1 -1
  2. package/dist/css/materialize.css +37 -15
  3. package/dist/css/materialize.min.css +2 -2
  4. package/dist/js/materialize.js +503 -1974
  5. package/dist/js/materialize.min.js +2 -2
  6. package/dist/js/materialize.min.js.map +1 -1
  7. package/dist/src/buttons.d.ts.map +1 -1
  8. package/dist/src/cards.d.ts.map +1 -1
  9. package/dist/src/collapsible.d.ts +1 -0
  10. package/dist/src/collapsible.d.ts.map +1 -1
  11. package/dist/src/dropdown.d.ts.map +1 -1
  12. package/dist/src/global.d.ts.map +1 -1
  13. package/dist/src/materialbox.d.ts +14 -10
  14. package/dist/src/materialbox.d.ts.map +1 -1
  15. package/dist/src/modal.d.ts.map +1 -1
  16. package/dist/src/range.d.ts.map +1 -1
  17. package/dist/src/scrollspy.d.ts.map +1 -1
  18. package/dist/src/sidenav.d.ts +25 -25
  19. package/dist/src/sidenav.d.ts.map +1 -1
  20. package/dist/src/slider.d.ts +12 -12
  21. package/dist/src/slider.d.ts.map +1 -1
  22. package/dist/src/tabs.d.ts +1 -1
  23. package/dist/src/tabs.d.ts.map +1 -1
  24. package/dist/src/toasts.d.ts +7 -2
  25. package/dist/src/toasts.d.ts.map +1 -1
  26. package/dist/src/tooltip.d.ts.map +1 -1
  27. package/package.json +14 -10
  28. package/sass/components/_collapsible.scss +14 -2
  29. package/sass/components/_materialbox.scss +2 -2
  30. package/sass/components/_modal.scss +0 -1
  31. package/sass/components/_tooltip.scss +18 -8
  32. package/sass/components/_variables.scss +2 -2
  33. package/Gruntfile.js +0 -385
  34. package/src/autocomplete.ts +0 -553
  35. package/src/bounding.ts +0 -6
  36. package/src/buttons.ts +0 -260
  37. package/src/cards.ts +0 -53
  38. package/src/carousel.ts +0 -676
  39. package/src/characterCounter.ts +0 -117
  40. package/src/chips.ts +0 -439
  41. package/src/collapsible.ts +0 -249
  42. package/src/component.ts +0 -120
  43. package/src/datepicker.ts +0 -1076
  44. package/src/dropdown.ts +0 -644
  45. package/src/edges.ts +0 -6
  46. package/src/forms.ts +0 -132
  47. package/src/global.ts +0 -114
  48. package/src/index.ts +0 -26
  49. package/src/materialbox.ts +0 -404
  50. package/src/modal.ts +0 -341
  51. package/src/parallax.ts +0 -149
  52. package/src/pushpin.ts +0 -165
  53. package/src/range.ts +0 -198
  54. package/src/scrollspy.ts +0 -263
  55. package/src/select.ts +0 -484
  56. package/src/sidenav.ts +0 -543
  57. package/src/slider.ts +0 -474
  58. package/src/tabs.ts +0 -347
  59. package/src/tapTarget.ts +0 -273
  60. package/src/timepicker.ts +0 -832
  61. package/src/toasts.ts +0 -290
  62. package/src/tooltip.ts +0 -366
  63. package/src/utils.ts +0 -271
  64. package/src/waves.ts +0 -70
package/src/slider.ts DELETED
@@ -1,474 +0,0 @@
1
- import anim from "animejs";
2
-
3
- import { Utils } from "./utils";
4
- import { Component, BaseOptions, InitElements, MElement } from "./component";
5
-
6
- export interface SliderOptions extends BaseOptions {
7
- /**
8
- * Set to false to hide slide indicators.
9
- * @default true
10
- */
11
- indicators: boolean;
12
- /**
13
- * Set height of slider.
14
- * @default 400
15
- */
16
- height: number;
17
- /**
18
- * Set the duration of the transition animation in ms.
19
- * @default 500
20
- */
21
- duration: number;
22
- /**
23
- * Set the duration between transitions in ms.
24
- * @default 6000
25
- */
26
- interval: number;
27
- /**
28
- * If slider should pause when keyboard focus is received.
29
- * @default true
30
- */
31
- pauseOnFocus: boolean;
32
- /**
33
- * If slider should pause when is hovered by a pointer.
34
- * @default true
35
- */
36
- pauseOnHover: boolean;
37
- /**
38
- * Optional function used to generate ARIA label to indicators (for accessibility purposes).
39
- * @param index Current index, starting from "1".
40
- * @param current A which indicates whether it is the current element or not
41
- * @returns a string to be used as label indicator.
42
- * @default null
43
- */
44
- indicatorLabelFunc: (index: number, current: boolean) => string
45
- }
46
-
47
- let _defaults: SliderOptions = {
48
- indicators: true,
49
- height: 400,
50
- duration: 500,
51
- interval: 6000,
52
- pauseOnFocus: true,
53
- pauseOnHover: true,
54
- indicatorLabelFunc: null // Function which will generate a label for the indicators (ARIA)
55
- };
56
-
57
- export class Slider extends Component<SliderOptions> {
58
- /** Index of current slide. */
59
- activeIndex: number;
60
- interval: string | number | NodeJS.Timeout;
61
- eventPause: any;
62
- _slider: HTMLUListElement;
63
- _slides: HTMLLIElement[];
64
- _activeSlide: HTMLLIElement;
65
- _indicators: HTMLLIElement[];
66
- _hovered: boolean;
67
- _focused: boolean;
68
- _focusCurrent: boolean;
69
- _sliderId: string;
70
-
71
- constructor(el: HTMLElement, options: Partial<SliderOptions>) {
72
- super(el, options, Slider);
73
- (this.el as any).M_Slider = this;
74
-
75
- this.options = {
76
- ...Slider.defaults,
77
- ...options
78
- };
79
-
80
- // init props
81
- this.interval = null;
82
- this.eventPause = false;
83
- this._hovered = false;
84
- this._focused = false;
85
- this._focusCurrent = false;
86
-
87
- // setup
88
- this._slider = this.el.querySelector('.slides');
89
- this._slides = Array.from(this._slider.querySelectorAll('li'));
90
- this.activeIndex = this._slides.findIndex(li => li.classList.contains('active'));
91
-
92
- if (this.activeIndex !== -1) {
93
- this._activeSlide = this._slides[this.activeIndex];
94
- }
95
-
96
- this._setSliderHeight();
97
-
98
- // Sets element id if it does not have one
99
- if (this._slider.hasAttribute('id'))
100
- this._sliderId = this._slider.getAttribute('id');
101
- else {
102
- this._sliderId = 'slider-' + Utils.guid();
103
- this._slider.setAttribute('id', this._sliderId);
104
- }
105
-
106
- const placeholderBase64 = 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
107
- // Set initial positions of captions
108
- this._slides.forEach(slide => {
109
- // Caption
110
- //const caption = <HTMLElement|null>slide.querySelector('.caption');
111
- //if (caption) this._animateCaptionIn(caption, 0);
112
- // Set Images as Background Images
113
- const img = slide.querySelector('img');
114
- if (img) {
115
- if (img.src !== placeholderBase64) {
116
- img.style.backgroundImage = 'url('+ img.src +')';
117
- img.src = placeholderBase64;
118
- }
119
- }
120
- // Sets slide as focusable by code
121
- if (!slide.hasAttribute('tabindex'))
122
- slide.setAttribute('tabindex', '-1');
123
- // Removes initial visibility from "inactive" slides
124
- slide.style.visibility = 'hidden';
125
- });
126
-
127
- this._setupIndicators();
128
-
129
- // Show active slide
130
- if (this._activeSlide) {
131
- this._activeSlide.style.display = 'block';
132
- this._activeSlide.style.visibility = 'visible';
133
- }
134
- else {
135
- this.activeIndex = 0;
136
- this._slides[0].classList.add('active');
137
- this._slides[0].style.visibility = 'visible';
138
- this._activeSlide = this._slides[0];
139
- this._animateSlide(this._slides[0], true);
140
- /*anim({
141
- targets: this._slides[0],
142
- opacity: 1,
143
- duration: this.options.duration,
144
- easing: 'easeOutQuad'
145
- });
146
- */
147
- // Update indicators
148
- if (this.options.indicators) {
149
- this._indicators[this.activeIndex].children[0].classList.add('active');
150
- }
151
- }
152
-
153
- // Adjust height to current slide
154
- // TODO: ??? Code does not do what it says in comment
155
- /*
156
- this._activeSlide.querySelectorAll('img').forEach(el => {
157
- anim({
158
- targets: this._activeSlide.querySelector('.caption'),
159
- opacity: 1,
160
- translateX: 0,
161
- translateY: 0,
162
- duration: this.options.duration,
163
- easing: 'easeOutQuad'
164
- });
165
- });
166
- */
167
-
168
- this._setupEventHandlers();
169
- // auto scroll
170
- this.start();
171
- }
172
-
173
- static get defaults() {
174
- return _defaults;
175
- }
176
-
177
- /**
178
- * Initializes instance of Slider.
179
- * @param el HTML element.
180
- * @param options Component options.
181
- */
182
- static init(el: HTMLElement, options?: Partial<SliderOptions>): Slider;
183
- /**
184
- * Initializes instances of Slider.
185
- * @param els HTML elements.
186
- * @param options Component options.
187
- */
188
- static init(els: InitElements<MElement>, options?: Partial<SliderOptions>): Slider[];
189
- /**
190
- * Initializes instances of Slider.
191
- * @param els HTML elements.
192
- * @param options Component options.
193
- */
194
- static init(els: HTMLElement | InitElements<MElement>, options: Partial<SliderOptions> = {}): Slider | Slider[] {
195
- return super.init(els, options, Slider);
196
- }
197
-
198
- static getInstance(el: HTMLElement): Slider {
199
- return (el as any).M_Slider;
200
- }
201
-
202
- destroy() {
203
- this.pause();
204
- this._removeIndicators();
205
- this._removeEventHandlers();
206
- (this.el as any).M_Slider = undefined;
207
- }
208
-
209
- _setupEventHandlers() {
210
- if (this.options.pauseOnFocus) {
211
- this.el.addEventListener('focusin', this._handleAutoPauseFocus);
212
- this.el.addEventListener('focusout', this._handleAutoStartFocus);
213
- }
214
- if (this.options.pauseOnHover) {
215
- this.el.addEventListener('mouseenter', this._handleAutoPauseHover);
216
- this.el.addEventListener('mouseleave', this._handleAutoStartHover);
217
- }
218
- if (this.options.indicators) {
219
- this._indicators.forEach((el) => {
220
- el.addEventListener('click', this._handleIndicatorClick);
221
- });
222
- }
223
- }
224
-
225
- _removeEventHandlers() {
226
- if (this.options.pauseOnFocus) {
227
- this.el.removeEventListener('focusin', this._handleAutoPauseFocus);
228
- this.el.removeEventListener('focusout', this._handleAutoStartFocus);
229
- }
230
- if (this.options.pauseOnHover) {
231
- this.el.removeEventListener('mouseenter', this._handleAutoPauseHover);
232
- this.el.removeEventListener('mouseleave', this._handleAutoStartHover);
233
- }
234
- if (this.options.indicators) {
235
- this._indicators.forEach((el) => {
236
- el.removeEventListener('click', this._handleIndicatorClick);
237
- });
238
- }
239
- }
240
-
241
- _handleIndicatorClick = (e: MouseEvent) => {
242
- const el = (<HTMLElement>e.target).parentElement;
243
- const currIndex = [...el.parentNode.children].indexOf(el);
244
- this._focusCurrent = true;
245
- this.set(currIndex);
246
- }
247
-
248
- _handleAutoPauseHover = () => {
249
- this._hovered = true;
250
- if (this.interval != null) {
251
- this._pause(true);
252
- }
253
- }
254
-
255
- _handleAutoPauseFocus = () => {
256
- this._focused = true;
257
- if (this.interval != null) {
258
- this._pause(true);
259
- }
260
- }
261
-
262
- _handleAutoStartHover = () => {
263
- this._hovered = false;
264
- if (!(this.options.pauseOnFocus && this._focused) && this.eventPause) {
265
- this.start();
266
- }
267
- }
268
-
269
- _handleAutoStartFocus = () => {
270
- this._focused = false;
271
- if (!(this.options.pauseOnHover && this._hovered) && this.eventPause) {
272
- this.start();
273
- }
274
- }
275
-
276
- _handleInterval = () => {
277
- const activeElem = this._slider.querySelector('.active');
278
- let newActiveIndex = [...activeElem.parentNode.children].indexOf(activeElem);
279
- if (this._slides.length === newActiveIndex + 1)
280
- newActiveIndex = 0; // loop to start
281
- else
282
- newActiveIndex += 1;
283
- this.set(newActiveIndex);
284
- }
285
-
286
- _animateSlide(slide: HTMLElement, isDirectionIn: boolean): void {
287
- let dx = 0, dy = 0;
288
- anim({
289
- targets: slide,
290
- opacity: isDirectionIn ? [0, 1] : [1, 0],
291
- duration: this.options.duration,
292
- easing: 'easeOutQuad'
293
- });
294
-
295
- const caption = slide.querySelector('.caption');
296
- if (!caption) return;
297
- if (caption.classList.contains('center-align')) dy = -100;
298
- else if (caption.classList.contains('right-align')) dx = 100;
299
- else if (caption.classList.contains('left-align')) dx = -100;
300
- anim({
301
- targets: caption,
302
- opacity: isDirectionIn ? [0, 1] : [1, 0],
303
- translateX: isDirectionIn ? [dx, 0] : [0, dx],
304
- translateY: isDirectionIn ? [dy, 0] : [0, dy],
305
- duration: this.options.duration,
306
- delay: this.options.duration,
307
- easing: 'easeOutQuad'
308
- });
309
- }
310
-
311
- _setSliderHeight() {
312
- // If fullscreen, do nothing
313
- if (!this.el.classList.contains('fullscreen')) {
314
- if (this.options.indicators) {
315
- // Add height if indicators are present
316
- this.el.style.height = (this.options.height + 40)+'px'; //.css('height', this.options.height + 40 + 'px');
317
- }
318
- else {
319
- this.el.style.height = this.options.height+'px';
320
- }
321
- this._slider.style.height = this.options.height+'px';
322
- }
323
- }
324
-
325
- _setupIndicators() {
326
- if (this.options.indicators) {
327
- const ul = document.createElement('ul');
328
- ul.classList.add('indicators');
329
-
330
- const arrLi = [];
331
- this._slides.forEach((el, i) => {
332
- const label = this.options.indicatorLabelFunc
333
- ? this.options.indicatorLabelFunc.call(this, i + 1, i === 0)
334
- : `${i + 1}`;
335
- const li = document.createElement('li');
336
- li.classList.add('indicator-item');
337
- li.innerHTML = `<button type="button" class="indicator-item-btn" aria-label="${label}" aria-controls="${this._sliderId}"></button>`;
338
- arrLi.push(li);
339
- ul.append(li);
340
- });
341
-
342
- this.el.append(ul);
343
- this._indicators = arrLi;
344
- }
345
- }
346
-
347
- _removeIndicators() {
348
- this.el.querySelector('ul.indicators').remove(); //find('ul.indicators').remove();
349
- }
350
-
351
- set(index: number) {
352
- // Wrap around indices.
353
- if (index >= this._slides.length) index = 0;
354
- else if (index < 0) index = this._slides.length - 1;
355
-
356
- // Only do if index changes
357
- if (this.activeIndex === index) return;
358
-
359
- this._activeSlide = this._slides[this.activeIndex];
360
- const _caption = <HTMLElement|null>this._activeSlide.querySelector('.caption');
361
-
362
- this._activeSlide.classList.remove('active');
363
- // Enables every slide
364
- this._slides.forEach(slide => slide.style.visibility = 'visible');
365
-
366
- //--- Hide active Slide + Caption
367
- // TODO: What does this do?
368
- anim({
369
- targets: this._activeSlide,
370
- opacity: 0,
371
- duration: this.options.duration,
372
- easing: 'easeOutQuad',
373
- complete: () => {
374
- this._slides.forEach(el => {
375
- if (el.classList.contains('active')) return;
376
- anim({
377
- targets: el,
378
- opacity: 0,
379
- translateX: 0,
380
- translateY: 0,
381
- duration: 0, // Animation with duration 0... why use anim at all then?
382
- easing: 'easeOutQuad'
383
- });
384
- // Disables invisible slides (for assistive technologies)
385
- el.style.visibility = 'hidden';
386
- });
387
- }
388
- });
389
-
390
- // Hide active Caption
391
- //this._animateCaptionIn(_caption, this.options.duration);
392
- _caption.style.opacity = '0';
393
-
394
- // Update indicators
395
- if (this.options.indicators) {
396
- const activeIndicator = this._indicators[this.activeIndex].children[0];
397
- const nextIndicator = this._indicators[index].children[0];
398
- activeIndicator.classList.remove('active');
399
- nextIndicator.classList.add('active');
400
- if (typeof this.options.indicatorLabelFunc === "function"){
401
- activeIndicator.ariaLabel = this.options.indicatorLabelFunc.call(this, this.activeIndex, false);
402
- nextIndicator.ariaLabel = this.options.indicatorLabelFunc.call(this, index, true);
403
- }
404
- }
405
-
406
- //--- Show new Slide + Caption
407
- this._animateSlide(this._slides[index], true);
408
-
409
- this._slides[index].classList.add('active');
410
-
411
- // TODO: Why focus? => causes uncontrollable page scroll
412
- /*
413
- if (this._focusCurrent) {
414
- this._slides[index].focus();
415
- this._focusCurrent = false;
416
- }
417
- */
418
-
419
- this.activeIndex = index;
420
-
421
- // Reset interval, if allowed. This check prevents autostart
422
- // when slider is paused, since it can be changed though indicators.
423
- if (this.interval != null) {
424
- this.start();
425
- }
426
- }
427
-
428
- _pause(fromEvent: boolean) {
429
- clearInterval(this.interval);
430
- this.eventPause = fromEvent;
431
- this.interval = null;
432
- }
433
-
434
- /**
435
- * Pause slider autoslide.
436
- */
437
- pause = () => {
438
- this._pause(false);
439
- }
440
-
441
- /**
442
- * Start slider autoslide.
443
- */
444
- start = () => {
445
- clearInterval(this.interval);
446
- this.interval = setInterval(
447
- this._handleInterval,
448
- this.options.duration + this.options.interval
449
- );
450
- this.eventPause = false;
451
- }
452
-
453
- /**
454
- * Move to next slider.
455
- */
456
- next = () => {
457
- let newIndex = this.activeIndex + 1;
458
- // Wrap around indices.
459
- if (newIndex >= this._slides.length) newIndex = 0;
460
- else if (newIndex < 0) newIndex = this._slides.length - 1;
461
- this.set(newIndex);
462
- }
463
-
464
- /**
465
- * Move to prev slider.
466
- */
467
- prev = () => {
468
- let newIndex = this.activeIndex - 1;
469
- // Wrap around indices.
470
- if (newIndex >= this._slides.length) newIndex = 0;
471
- else if (newIndex < 0) newIndex = this._slides.length - 1;
472
- this.set(newIndex);
473
- }
474
- }