@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/parallax.ts CHANGED
@@ -1,125 +1,149 @@
1
- import { Component } from "./component";
2
- import { M } from "./global";
3
-
4
- let _defaults = {
5
- responsiveThreshold: 0 // breakpoint for swipeable
6
- };
7
-
8
- export class Parallax extends Component {
9
- private _enabled: boolean;
10
- private _img: HTMLImageElement;
11
- private _handleImageLoadBound: any;
12
- static _parallaxes: any;
13
- static _handleScrollThrottled: any;
14
- static _handleWindowResizeThrottled: () => any;
15
-
16
- constructor(el, options) {
17
- super(Parallax, el, options);
18
- (this.el as any).M_Parallax = this;
19
- this.options = {...Parallax.defaults, ...options};
20
- this._enabled = window.innerWidth > this.options.responsiveThreshold;
21
- this._img = this.el.querySelector('img');
22
- this._updateParallax();
23
- this._setupEventHandlers();
24
- this._setupStyles();
25
- Parallax._parallaxes.push(this);
26
- }
1
+ import { Utils } from "./utils";
2
+ import { Component, BaseOptions, InitElements, MElement } from "./component";
3
+
4
+ export interface ParallaxOptions extends BaseOptions {
5
+ /**
6
+ * The minimum width of the screen, in pixels, where the parallax functionality starts working.
7
+ * @default 0
8
+ */
9
+ responsiveThreshold: number;
10
+ }
11
+
12
+ let _defaults: ParallaxOptions = {
13
+ responsiveThreshold: 0 // breakpoint for swipeable
14
+ };
15
+
16
+ export class Parallax extends Component<ParallaxOptions> {
17
+ private _enabled: boolean;
18
+ private _img: HTMLImageElement;
19
+ static _parallaxes: Parallax[] = [];
20
+ static _handleScrollThrottled: () => any;
21
+ static _handleWindowResizeThrottled: () => any;
22
+
23
+ constructor(el: HTMLElement, options: Partial<ParallaxOptions>) {
24
+ super(el, options, Parallax);
25
+ (this.el as any).M_Parallax = this;
26
+
27
+ this.options = {
28
+ ...Parallax.defaults,
29
+ ...options
30
+ };
31
+
32
+ this._enabled = window.innerWidth > this.options.responsiveThreshold;
33
+ this._img = this.el.querySelector('img');
34
+ this._updateParallax();
35
+ this._setupEventHandlers();
36
+ this._setupStyles();
37
+ Parallax._parallaxes.push(this);
38
+ }
27
39
 
28
- static get defaults() {
29
- return _defaults;
30
- }
40
+ static get defaults(): ParallaxOptions {
41
+ return _defaults;
42
+ }
31
43
 
32
- static init(els, options) {
33
- return super.init(this, els, options);
34
- }
44
+ /**
45
+ * Initializes instance of Parallax.
46
+ * @param el HTML element.
47
+ * @param options Component options.
48
+ */
49
+ static init(el: HTMLElement, options?: Partial<ParallaxOptions>): Parallax;
50
+ /**
51
+ * Initializes instances of Parallax.
52
+ * @param els HTML elements.
53
+ * @param options Component options.
54
+ */
55
+ static init(els: InitElements<MElement>, options?: Partial<ParallaxOptions>): Parallax[];
56
+ /**
57
+ * Initializes instances of Parallax.
58
+ * @param els HTML elements.
59
+ * @param options Component options.
60
+ */
61
+ static init(els: HTMLElement | InitElements<MElement>, options: Partial<ParallaxOptions> = {}): Parallax | Parallax[] {
62
+ return super.init(els, options, Parallax);
63
+ }
35
64
 
36
- static getInstance(el) {
37
- let domElem = !!el.jquery ? el[0] : el;
38
- return domElem.M_Parallax;
39
- }
65
+ static getInstance(el: HTMLElement): Parallax {
66
+ return (el as any).M_Parallax;
67
+ }
40
68
 
41
- destroy() {
42
- Parallax._parallaxes.splice(Parallax._parallaxes.indexOf(this), 1);
43
- this._img.style.transform = '';
44
- this._removeEventHandlers();
45
- (this.el as any).M_Parallax = undefined;
46
- }
69
+ destroy() {
70
+ Parallax._parallaxes.splice(Parallax._parallaxes.indexOf(this), 1);
71
+ this._img.style.transform = '';
72
+ this._removeEventHandlers();
73
+ (this.el as any).M_Parallax = undefined;
74
+ }
47
75
 
48
- static _handleScroll() {
49
- for (let i = 0; i < Parallax._parallaxes.length; i++) {
50
- let parallaxInstance = Parallax._parallaxes[i];
51
- parallaxInstance._updateParallax.call(parallaxInstance);
52
- }
76
+ static _handleScroll() {
77
+ for (let i = 0; i < Parallax._parallaxes.length; i++) {
78
+ let parallaxInstance = Parallax._parallaxes[i];
79
+ parallaxInstance._updateParallax.call(parallaxInstance);
53
80
  }
81
+ }
54
82
 
55
- static _handleWindowResize() {
56
- for (let i = 0; i < Parallax._parallaxes.length; i++) {
57
- let parallaxInstance = Parallax._parallaxes[i];
58
- parallaxInstance._enabled =
59
- window.innerWidth > parallaxInstance.options.responsiveThreshold;
60
- }
83
+ static _handleWindowResize() {
84
+ for (let i = 0; i < Parallax._parallaxes.length; i++) {
85
+ let parallaxInstance = Parallax._parallaxes[i];
86
+ parallaxInstance._enabled =
87
+ window.innerWidth > parallaxInstance.options.responsiveThreshold;
61
88
  }
89
+ }
62
90
 
63
- _setupEventHandlers() {
64
- this._handleImageLoadBound = this._handleImageLoad.bind(this);
65
- this._img.addEventListener('load', this._handleImageLoadBound);
66
- if (Parallax._parallaxes.length === 0) {
67
- Parallax._handleScrollThrottled = M.throttle(Parallax._handleScroll, 5);
68
- window.addEventListener('scroll', Parallax._handleScrollThrottled);
69
- Parallax._handleWindowResizeThrottled = M.throttle(Parallax._handleWindowResize, 5);
70
- window.addEventListener('resize', Parallax._handleWindowResizeThrottled);
91
+ _setupEventHandlers() {
92
+ this._img.addEventListener('load', this._handleImageLoad);
93
+ if (Parallax._parallaxes.length === 0) {
94
+ if (!Parallax._handleScrollThrottled){
95
+ Parallax._handleScrollThrottled = Utils.throttle(Parallax._handleScroll, 5);
71
96
  }
72
- }
73
-
74
- _removeEventHandlers() {
75
- this._img.removeEventListener('load', this._handleImageLoadBound);
76
- if (Parallax._parallaxes.length === 0) {
77
- window.removeEventListener('scroll', Parallax._handleScrollThrottled);
78
- window.removeEventListener('resize', Parallax._handleWindowResizeThrottled);
97
+ if (!Parallax._handleWindowResizeThrottled){
98
+ Parallax._handleWindowResizeThrottled = Utils.throttle(Parallax._handleWindowResize, 5);
79
99
  }
100
+ window.addEventListener('scroll', Parallax._handleScrollThrottled);
101
+ window.addEventListener('resize', Parallax._handleWindowResizeThrottled);
80
102
  }
103
+ }
81
104
 
82
- _setupStyles() {
83
- this._img.style.opacity = '1';
105
+ _removeEventHandlers() {
106
+ this._img.removeEventListener('load', this._handleImageLoad);
107
+ if (Parallax._parallaxes.length === 0) {
108
+ window.removeEventListener('scroll', Parallax._handleScrollThrottled);
109
+ window.removeEventListener('resize', Parallax._handleWindowResizeThrottled);
84
110
  }
111
+ }
85
112
 
86
- _handleImageLoad() {
87
- this._updateParallax();
88
- }
113
+ _setupStyles() {
114
+ this._img.style.opacity = '1';
115
+ }
89
116
 
90
- private _offset(el: Element) {
91
- const box = el.getBoundingClientRect();
92
- const docElem = document.documentElement;
93
- return {
94
- top: box.top + window.pageYOffset - docElem.clientTop,
95
- left: box.left + window.pageXOffset - docElem.clientLeft
96
- };
97
- }
117
+ _handleImageLoad = () => {
118
+ this._updateParallax();
119
+ }
98
120
 
99
- _updateParallax() {
100
- const containerHeight = this.el.getBoundingClientRect().height > 0 ? (this.el.parentNode as any).offsetHeight : 500;
101
- const imgHeight = this._img.offsetHeight;
102
- const parallaxDist = imgHeight - containerHeight;
103
- const bottom = this._offset(this.el).top + containerHeight;
104
- const top = this._offset(this.el).top;
105
- const scrollTop = M.getDocumentScrollTop();
106
- const windowHeight = window.innerHeight;
107
- const windowBottom = scrollTop + windowHeight;
108
- const percentScrolled = (windowBottom - top) / (containerHeight + windowHeight);
109
- const parallax = parallaxDist * percentScrolled;
110
-
111
- if (!this._enabled) {
112
- this._img.style.transform = '';
113
- }
114
- else if (bottom > scrollTop && top < scrollTop + windowHeight) {
115
- this._img.style.transform = `translate3D(-50%, ${parallax}px, 0)`;
116
- }
117
- }
121
+ private _offset(el: Element) {
122
+ const box = el.getBoundingClientRect();
123
+ const docElem = document.documentElement;
124
+ return {
125
+ top: box.top + window.pageYOffset - docElem.clientTop,
126
+ left: box.left + window.pageXOffset - docElem.clientLeft
127
+ };
128
+ }
118
129
 
119
- static {
120
- Parallax._parallaxes = [];
130
+ _updateParallax() {
131
+ const containerHeight = this.el.getBoundingClientRect().height > 0 ? (this.el.parentNode as any).offsetHeight : 500;
132
+ const imgHeight = this._img.offsetHeight;
133
+ const parallaxDist = imgHeight - containerHeight;
134
+ const bottom = this._offset(this.el).top + containerHeight;
135
+ const top = this._offset(this.el).top;
136
+ const scrollTop = Utils.getDocumentScrollTop();
137
+ const windowHeight = window.innerHeight;
138
+ const windowBottom = scrollTop + windowHeight;
139
+ const percentScrolled = (windowBottom - top) / (containerHeight + windowHeight);
140
+ const parallax = parallaxDist * percentScrolled;
141
+
142
+ if (!this._enabled) {
143
+ this._img.style.transform = '';
144
+ }
145
+ else if (bottom > scrollTop && top < scrollTop + windowHeight) {
146
+ this._img.style.transform = `translate3D(-50%, ${parallax}px, 0)`;
121
147
  }
122
148
  }
123
-
124
-
125
-
149
+ }
package/src/pushpin.ts CHANGED
@@ -1,120 +1,165 @@
1
- import { Component } from "./component";
2
- import { M } from "./global";
3
-
4
- let _defaults = {
5
- top: 0,
6
- bottom: Infinity,
7
- offset: 0,
8
- onPositionChange: null
9
- };
10
-
11
- export class Pushpin extends Component {
12
- static _pushpins: any[];
13
- originalOffset: any;
14
-
15
- constructor(el, options) {
16
- super(Pushpin, el, options);
17
- (this.el as any).M_Pushpin = this;
18
- this.options = {...Pushpin.defaults, ...options};
19
- this.originalOffset = (this.el as HTMLElement).offsetTop;
20
- Pushpin._pushpins.push(this);
21
- this._setupEventHandlers();
22
- this._updatePosition();
1
+ import { Utils } from "./utils";
2
+ import { Component, BaseOptions, InitElements, MElement } from "./component";
3
+
4
+ export interface PushpinOptions extends BaseOptions {
5
+ /**
6
+ * The distance in pixels from the top of the page where
7
+ * the element becomes fixed.
8
+ * @default 0
9
+ */
10
+ top: number;
11
+ /**
12
+ * The distance in pixels from the top of the page where
13
+ * the elements stops being fixed.
14
+ * @default Infinity
15
+ */
16
+ bottom: number;
17
+ /**
18
+ * The offset from the top the element will be fixed at.
19
+ * @default 0
20
+ */
21
+ offset: number;
22
+ /**
23
+ * Callback function called when pushpin position changes.
24
+ * You are provided with a position string.
25
+ * @default null
26
+ */
27
+ onPositionChange: (position: "pinned" | "pin-top" | "pin-bottom") => void;
28
+ }
29
+
30
+ let _defaults = {
31
+ top: 0,
32
+ bottom: Infinity,
33
+ offset: 0,
34
+ onPositionChange: null
35
+ };
36
+
37
+ export class Pushpin extends Component<PushpinOptions> {
38
+ static _pushpins: any[];
39
+ originalOffset: any;
40
+
41
+ constructor(el: HTMLElement, options: Partial<PushpinOptions>) {
42
+ super(el, options, Pushpin);
43
+ (this.el as any).M_Pushpin = this;
44
+
45
+ this.options = {
46
+ ...Pushpin.defaults,
47
+ ...options
48
+ };
49
+
50
+ this.originalOffset = (this.el as HTMLElement).offsetTop;
51
+ Pushpin._pushpins.push(this);
52
+ this._setupEventHandlers();
53
+ this._updatePosition();
54
+ }
55
+
56
+ static get defaults(): PushpinOptions {
57
+ return _defaults;
58
+ }
59
+
60
+ /**
61
+ * Initializes instance of Pushpin.
62
+ * @param el HTML element.
63
+ * @param options Component options.
64
+ */
65
+ static init(el: HTMLElement, options?: Partial<PushpinOptions>): Pushpin;
66
+ /**
67
+ * Initializes instances of Pushpin.
68
+ * @param els HTML elements.
69
+ * @param options Component options.
70
+ */
71
+ static init(els: InitElements<MElement>, options?: Partial<PushpinOptions>): Pushpin[];
72
+ /**
73
+ * Initializes instances of Pushpin.
74
+ * @param els HTML elements.
75
+ * @param options Component options.
76
+ */
77
+ static init(els: HTMLElement | InitElements<MElement>, options: Partial<PushpinOptions> = {}): Pushpin | Pushpin[] {
78
+ return super.init(els, options, Pushpin);
79
+ }
80
+
81
+ static getInstance(el: HTMLElement): Pushpin {
82
+ return (el as any).M_Pushpin;
83
+ }
84
+
85
+ destroy() {
86
+ (this.el as HTMLElement).style.top = null;
87
+ this._removePinClasses();
88
+ // Remove pushpin Inst
89
+ let index = Pushpin._pushpins.indexOf(this);
90
+ Pushpin._pushpins.splice(index, 1);
91
+ if (Pushpin._pushpins.length === 0) {
92
+ this._removeEventHandlers();
23
93
  }
94
+ (this.el as any).M_Pushpin = undefined;
95
+ }
24
96
 
25
- static get defaults() {
26
- return _defaults;
97
+ static _updateElements() {
98
+ for (let elIndex in Pushpin._pushpins) {
99
+ let pInstance = Pushpin._pushpins[elIndex];
100
+ pInstance._updatePosition();
27
101
  }
102
+ }
28
103
 
29
- static init(els, options) {
30
- return super.init(this, els, options);
31
- }
104
+ _setupEventHandlers() {
105
+ document.addEventListener('scroll', Pushpin._updateElements);
106
+ }
32
107
 
33
- static getInstance(el) {
34
- let domElem = !!el.jquery ? el[0] : el;
35
- return domElem.M_Pushpin;
36
- }
108
+ _removeEventHandlers() {
109
+ document.removeEventListener('scroll', Pushpin._updateElements);
110
+ }
111
+
112
+ _updatePosition() {
113
+ let scrolled = Utils.getDocumentScrollTop() + this.options.offset;
37
114
 
38
- destroy() {
39
- (this.el as HTMLElement).style.top = null;
115
+ if (
116
+ this.options.top <= scrolled &&
117
+ this.options.bottom >= scrolled &&
118
+ !this.el.classList.contains('pinned')
119
+ ) {
40
120
  this._removePinClasses();
41
- // Remove pushpin Inst
42
- let index = Pushpin._pushpins.indexOf(this);
43
- Pushpin._pushpins.splice(index, 1);
44
- if (Pushpin._pushpins.length === 0) {
45
- this._removeEventHandlers();
46
- }
47
- (this.el as any).M_Pushpin = undefined;
48
- }
121
+ (this.el as HTMLElement).style.top = `${this.options.offset}px`;
122
+ this.el.classList.add('pinned');
49
123
 
50
- static _updateElements() {
51
- for (let elIndex in Pushpin._pushpins) {
52
- let pInstance = Pushpin._pushpins[elIndex];
53
- pInstance._updatePosition();
124
+ // onPositionChange callback
125
+ if (typeof this.options.onPositionChange === 'function') {
126
+ this.options.onPositionChange.call(this, 'pinned');
54
127
  }
55
128
  }
56
129
 
57
- _setupEventHandlers() {
58
- document.addEventListener('scroll', Pushpin._updateElements);
59
- }
60
-
61
- _removeEventHandlers() {
62
- document.removeEventListener('scroll', Pushpin._updateElements);
63
- }
64
-
65
- _updatePosition() {
66
- let scrolled = M.getDocumentScrollTop() + this.options.offset;
67
-
68
- if (
69
- this.options.top <= scrolled &&
70
- this.options.bottom >= scrolled &&
71
- !this.el.classList.contains('pinned')
72
- ) {
73
- this._removePinClasses();
74
- (this.el as HTMLElement).style.top = `${this.options.offset}px`;
75
- this.el.classList.add('pinned');
76
-
77
- // onPositionChange callback
78
- if (typeof this.options.onPositionChange === 'function') {
79
- this.options.onPositionChange.call(this, 'pinned');
80
- }
81
- }
82
-
83
- // Add pin-top (when scrolled position is above top)
84
- if (scrolled < this.options.top && !this.el.classList.contains('pin-top')) {
85
- this._removePinClasses();
86
- (this.el as HTMLElement).style.top = '0';
87
- this.el.classList.add('pin-top');
88
-
89
- // onPositionChange callback
90
- if (typeof this.options.onPositionChange === 'function') {
91
- this.options.onPositionChange.call(this, 'pin-top');
92
- }
93
- }
94
-
95
- // Add pin-bottom (when scrolled position is below bottom)
96
- if (scrolled > this.options.bottom && !this.el.classList.contains('pin-bottom')) {
97
- this._removePinClasses();
98
- this.el.classList.add('pin-bottom');
99
- (this.el as HTMLElement).style.top = `${this.options.bottom - this.originalOffset}px`;
130
+ // Add pin-top (when scrolled position is above top)
131
+ if (scrolled < this.options.top && !this.el.classList.contains('pin-top')) {
132
+ this._removePinClasses();
133
+ (this.el as HTMLElement).style.top = '0';
134
+ this.el.classList.add('pin-top');
100
135
 
101
- // onPositionChange callback
102
- if (typeof this.options.onPositionChange === 'function') {
103
- this.options.onPositionChange.call(this, 'pin-bottom');
104
- }
136
+ // onPositionChange callback
137
+ if (typeof this.options.onPositionChange === 'function') {
138
+ this.options.onPositionChange.call(this, 'pin-top');
105
139
  }
106
140
  }
107
141
 
108
- _removePinClasses() {
109
- // IE 11 bug (can't remove multiple classes in one line)
110
- this.el.classList.remove('pin-top');
111
- this.el.classList.remove('pinned');
112
- this.el.classList.remove('pin-bottom');
113
- }
142
+ // Add pin-bottom (when scrolled position is below bottom)
143
+ if (scrolled > this.options.bottom && !this.el.classList.contains('pin-bottom')) {
144
+ this._removePinClasses();
145
+ this.el.classList.add('pin-bottom');
146
+ (this.el as HTMLElement).style.top = `${this.options.bottom - this.originalOffset}px`;
114
147
 
115
- static {
116
- Pushpin._pushpins = [];
148
+ // onPositionChange callback
149
+ if (typeof this.options.onPositionChange === 'function') {
150
+ this.options.onPositionChange.call(this, 'pin-bottom');
151
+ }
117
152
  }
118
- }
119
-
120
-
153
+ }
154
+
155
+ _removePinClasses() {
156
+ // IE 11 bug (can't remove multiple classes in one line)
157
+ this.el.classList.remove('pin-top');
158
+ this.el.classList.remove('pinned');
159
+ this.el.classList.remove('pin-bottom');
160
+ }
161
+
162
+ static {
163
+ Pushpin._pushpins = [];
164
+ }
165
+ }