@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/scrollspy.ts CHANGED
@@ -1,223 +1,263 @@
1
- import { Component } from "./component";
2
- import { M } from "./global";
3
1
  import anim from "animejs";
4
2
 
5
- let _defaults = {
3
+ import { Utils } from "./utils";
4
+ import { Component, BaseOptions, InitElements, MElement } from "./component";
5
+
6
+ export interface ScrollSpyOptions extends BaseOptions {
7
+ /**
8
+ * Throttle of scroll handler.
9
+ * @default 100
10
+ */
11
+ throttle: number;
12
+ /**
13
+ * Offset for centering element when scrolled to.
14
+ * @default 200
15
+ */
16
+ scrollOffset: number;
17
+ /**
18
+ * Class applied to active elements.
19
+ * @default 'active'
20
+ */
21
+ activeClass: string;
22
+ /**
23
+ * Used to find active element.
24
+ * @default id => 'a[href="#' + id + '"]'
25
+ */
26
+ getActiveElement: (id: string) => string;
27
+ };
28
+
29
+ let _defaults: ScrollSpyOptions = {
6
30
  throttle: 100,
7
31
  scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
8
32
  activeClass: 'active',
9
33
  getActiveElement: (id: string): string => { return 'a[href="#'+id+'"]'; }
10
34
  };
11
35
 
12
- export class ScrollSpy extends Component {
13
- el: HTMLElement;
14
- static _elements: ScrollSpy[];
15
- static _count: number;
16
- static _increment: number;
17
- tickId: number;
18
- id: any;
19
- static _elementsInView: ScrollSpy[];
20
- static _visibleElements: any[];
21
- private _handleThrottledResizeBound: any;
22
- private _handleWindowScrollBound: any;
23
- static _ticks: number;
24
-
25
- constructor(el, options) {
26
- super(ScrollSpy, el, options);
27
- (this.el as any).M_ScrollSpy = this;
28
- this.options = {...ScrollSpy.defaults, ...options};
29
- ScrollSpy._elements.push(this);
30
- ScrollSpy._count++;
31
- ScrollSpy._increment++;
32
- this.tickId = -1;
33
- this.id = ScrollSpy._increment;
34
- this._setupEventHandlers();
35
- this._handleWindowScroll();
36
- }
36
+ export class ScrollSpy extends Component<ScrollSpyOptions> {
37
+ static _elements: ScrollSpy[];
38
+ static _count: number;
39
+ static _increment: number;
40
+ tickId: number;
41
+ id: any;
42
+ static _elementsInView: ScrollSpy[];
43
+ static _visibleElements: any[];
44
+ static _ticks: number;
37
45
 
38
- static get defaults() {
39
- return _defaults;
40
- }
46
+ constructor(el: HTMLElement, options: Partial<ScrollSpyOptions>) {
47
+ super(el, options, ScrollSpy);
48
+ (this.el as any).M_ScrollSpy = this;
41
49
 
42
- static init(els, options) {
43
- return super.init(this, els, options);
44
- }
50
+ this.options = {
51
+ ...ScrollSpy.defaults,
52
+ ...options
53
+ };
45
54
 
46
- static getInstance(el) {
47
- let domElem = !!el.jquery ? el[0] : el;
48
- return domElem.M_ScrollSpy;
49
- }
55
+ ScrollSpy._elements.push(this);
56
+ ScrollSpy._count++;
57
+ ScrollSpy._increment++;
58
+ this.tickId = -1;
59
+ this.id = ScrollSpy._increment;
60
+ this._setupEventHandlers();
61
+ this._handleWindowScroll();
62
+ }
50
63
 
51
- destroy() {
52
- ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
53
- ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
54
- ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.el), 1);
55
- ScrollSpy._count--;
56
- this._removeEventHandlers();
57
- const actElem = document.querySelector(this.options.getActiveElement(this.el.id));
58
- actElem.classList.remove(this.options.activeClass);
59
- (this.el as any).M_ScrollSpy = undefined;
60
- }
64
+ static get defaults(): ScrollSpyOptions {
65
+ return _defaults;
66
+ }
61
67
 
62
- _setupEventHandlers() {
63
- let throttledResize = M.throttle(this._handleWindowScroll, 200);
64
- this._handleThrottledResizeBound = throttledResize.bind(this);
65
- this._handleWindowScrollBound = this._handleWindowScroll.bind(this);
66
- if (ScrollSpy._count === 1) {
67
- window.addEventListener('scroll', this._handleWindowScrollBound);
68
- window.addEventListener('resize', this._handleThrottledResizeBound);
69
- document.body.addEventListener('click', this._handleTriggerClick);
70
- }
68
+ /**
69
+ * Initializes instance of ScrollSpy.
70
+ * @param el HTML element.
71
+ * @param options Component options.
72
+ */
73
+ static init(el: HTMLElement, options?: Partial<ScrollSpyOptions>): ScrollSpy;
74
+ /**
75
+ * Initializes instances of ScrollSpy.
76
+ * @param els HTML elements.
77
+ * @param options Component options.
78
+ */
79
+ static init(els: InitElements<MElement>, options?: Partial<ScrollSpyOptions>): ScrollSpy[];
80
+ /**
81
+ * Initializes instances of ScrollSpy.
82
+ * @param els HTML elements.
83
+ * @param options Component options.
84
+ */
85
+ static init(els: HTMLElement | InitElements<MElement>, options: Partial<ScrollSpyOptions> = {}): ScrollSpy | ScrollSpy[] {
86
+ return super.init(els, options, ScrollSpy);
87
+ }
88
+
89
+ static getInstance(el: HTMLElement): ScrollSpy {
90
+ return (el as any).M_ScrollSpy;
91
+ }
92
+
93
+ destroy() {
94
+ ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
95
+ ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
96
+ ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.el), 1);
97
+ ScrollSpy._count--;
98
+ this._removeEventHandlers();
99
+ const actElem = document.querySelector(this.options.getActiveElement(this.el.id));
100
+ actElem.classList.remove(this.options.activeClass);
101
+ (this.el as any).M_ScrollSpy = undefined;
102
+ }
103
+
104
+ _setupEventHandlers() {
105
+ if (ScrollSpy._count === 1) {
106
+ window.addEventListener('scroll', this._handleWindowScroll);
107
+ window.addEventListener('resize', this._handleThrottledResize);
108
+ document.body.addEventListener('click', this._handleTriggerClick);
71
109
  }
110
+ }
72
111
 
73
- _removeEventHandlers() {
74
- if (ScrollSpy._count === 0) {
75
- window.removeEventListener('scroll', this._handleWindowScrollBound);
76
- window.removeEventListener('resize', this._handleThrottledResizeBound);
77
- document.body.removeEventListener('click', this._handleTriggerClick);
78
- }
112
+ _removeEventHandlers() {
113
+ if (ScrollSpy._count === 0) {
114
+ window.removeEventListener('scroll', this._handleWindowScroll);
115
+ window.removeEventListener('resize', this._handleThrottledResize);
116
+ document.body.removeEventListener('click', this._handleTriggerClick);
79
117
  }
118
+ }
80
119
 
81
- _handleTriggerClick(e) {
82
- const trigger = e.target;
83
- for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
84
- const scrollspy = ScrollSpy._elements[i];
120
+ _handleThrottledResize: () => void = Utils.throttle(function(){ this._handleWindowScroll(); }, 200).bind(this);
85
121
 
86
- const x = document.querySelector('a[href="#'+scrollspy.el.id+'"]');
87
- if (trigger === x) {
88
- e.preventDefault();
89
- const offset = ScrollSpy._offset(scrollspy.el).top + 1;
122
+ _handleTriggerClick = (e: MouseEvent) => {
123
+ const trigger = e.target;
124
+ for (let i = ScrollSpy._elements.length - 1; i >= 0; i--) {
125
+ const scrollspy = ScrollSpy._elements[i];
90
126
 
91
- anim({
92
- targets: [document.documentElement, document.body],
93
- scrollTop: offset - scrollspy.options.scrollOffset,
94
- duration: 400,
95
- easing: 'easeOutCubic'
96
- });
127
+ const x = document.querySelector('a[href="#'+scrollspy.el.id+'"]');
128
+ if (trigger === x) {
129
+ e.preventDefault();
130
+ const offset = ScrollSpy._offset(scrollspy.el).top + 1;
97
131
 
98
- break;
99
- }
132
+ anim({
133
+ targets: [document.documentElement, document.body],
134
+ scrollTop: offset - scrollspy.options.scrollOffset,
135
+ duration: 400,
136
+ easing: 'easeOutCubic'
137
+ });
138
+
139
+ break;
100
140
  }
101
141
  }
142
+ }
102
143
 
103
- _handleWindowScroll() {
104
- // unique tick id
105
- ScrollSpy._ticks++;
106
-
107
- // viewport rectangle
108
- let top = M.getDocumentScrollTop(),
109
- left = M.getDocumentScrollLeft(),
110
- right = left + window.innerWidth,
111
- bottom = top + window.innerHeight;
112
-
113
- // determine which elements are in view
114
- let intersections = ScrollSpy._findElements(top, right, bottom, left);
115
- for (let i = 0; i < intersections.length; i++) {
116
- let scrollspy = intersections[i];
117
- let lastTick = scrollspy.tickId;
118
- if (lastTick < 0) {
119
- // entered into view
120
- scrollspy._enter();
121
- }
144
+ _handleWindowScroll = () => {
145
+ // unique tick id
146
+ ScrollSpy._ticks++;
122
147
 
123
- // update tick id
124
- scrollspy.tickId = ScrollSpy._ticks;
125
- }
148
+ // viewport rectangle
149
+ let top = Utils.getDocumentScrollTop(),
150
+ left = Utils.getDocumentScrollLeft(),
151
+ right = left + window.innerWidth,
152
+ bottom = top + window.innerHeight;
126
153
 
127
- for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {
128
- let scrollspy = ScrollSpy._elementsInView[i];
129
- let lastTick = scrollspy.tickId;
130
- if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {
131
- // exited from view
132
- scrollspy._exit();
133
- scrollspy.tickId = -1;
134
- }
154
+ // determine which elements are in view
155
+ let intersections = ScrollSpy._findElements(top, right, bottom, left);
156
+ for (let i = 0; i < intersections.length; i++) {
157
+ let scrollspy = intersections[i];
158
+ let lastTick = scrollspy.tickId;
159
+ if (lastTick < 0) {
160
+ // entered into view
161
+ scrollspy._enter();
135
162
  }
136
- // remember elements in view for next tick
137
- ScrollSpy._elementsInView = intersections;
163
+
164
+ // update tick id
165
+ scrollspy.tickId = ScrollSpy._ticks;
138
166
  }
139
167
 
140
- static _offset(el) {
141
- const box = el.getBoundingClientRect();
142
- const docElem = document.documentElement;
143
- return {
144
- top: box.top + window.pageYOffset - docElem.clientTop,
145
- left: box.left + window.pageXOffset - docElem.clientLeft
146
- };
168
+ for (let i = 0; i < ScrollSpy._elementsInView.length; i++) {
169
+ let scrollspy = ScrollSpy._elementsInView[i];
170
+ let lastTick = scrollspy.tickId;
171
+ if (lastTick >= 0 && lastTick !== ScrollSpy._ticks) {
172
+ // exited from view
173
+ scrollspy._exit();
174
+ scrollspy.tickId = -1;
175
+ }
147
176
  }
177
+ // remember elements in view for next tick
178
+ ScrollSpy._elementsInView = intersections;
179
+ }
180
+
181
+ static _offset(el) {
182
+ const box = el.getBoundingClientRect();
183
+ const docElem = document.documentElement;
184
+ return {
185
+ top: box.top + window.pageYOffset - docElem.clientTop,
186
+ left: box.left + window.pageXOffset - docElem.clientLeft
187
+ };
188
+ }
189
+
190
+ static _findElements(top: number, right: number, bottom: number, left: number): ScrollSpy[] {
191
+ let hits = [];
192
+ for (let i = 0; i < ScrollSpy._elements.length; i++) {
193
+ let scrollspy = ScrollSpy._elements[i];
194
+ let currTop = top + scrollspy.options.scrollOffset || 200;
195
+
196
+ if (scrollspy.el.getBoundingClientRect().height > 0) {
197
+ let elTop = ScrollSpy._offset(scrollspy.el).top,
198
+ elLeft = ScrollSpy._offset(scrollspy.el).left,
199
+ elRight = elLeft + scrollspy.el.getBoundingClientRect().width,
200
+ elBottom = elTop + scrollspy.el.getBoundingClientRect().height;
201
+
202
+ let isIntersect = !(
203
+ elLeft > right ||
204
+ elRight < left ||
205
+ elTop > bottom ||
206
+ elBottom < currTop
207
+ );
148
208
 
149
- static _findElements(top: number, right: number, bottom: number, left: number): ScrollSpy[] {
150
- let hits = [];
151
- for (let i = 0; i < ScrollSpy._elements.length; i++) {
152
- let scrollspy = ScrollSpy._elements[i];
153
- let currTop = top + scrollspy.options.scrollOffset || 200;
154
-
155
- if (scrollspy.el.getBoundingClientRect().height > 0) {
156
- let elTop = ScrollSpy._offset(scrollspy.el).top,
157
- elLeft = ScrollSpy._offset(scrollspy.el).left,
158
- elRight = elLeft + scrollspy.el.getBoundingClientRect().width,
159
- elBottom = elTop + scrollspy.el.getBoundingClientRect().height;
160
-
161
- let isIntersect = !(
162
- elLeft > right ||
163
- elRight < left ||
164
- elTop > bottom ||
165
- elBottom < currTop
166
- );
167
-
168
- if (isIntersect) {
169
- hits.push(scrollspy);
170
- }
209
+ if (isIntersect) {
210
+ hits.push(scrollspy);
171
211
  }
172
212
  }
173
- return hits;
174
213
  }
214
+ return hits;
215
+ }
175
216
 
176
- _enter() {
177
- ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
217
+ _enter() {
218
+ ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
178
219
 
179
- if (ScrollSpy._visibleElements[0]) {
180
- const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
181
- actElem?.classList.remove(this.options.activeClass);
220
+ if (ScrollSpy._visibleElements[0]) {
221
+ const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
222
+ actElem?.classList.remove(this.options.activeClass);
182
223
 
183
- if (ScrollSpy._visibleElements[0].M_ScrollSpy && this.id < ScrollSpy._visibleElements[0].M_ScrollSpy.id) {
184
- ScrollSpy._visibleElements.unshift(this.el);
185
- }
186
- else {
187
- ScrollSpy._visibleElements.push(this.el);
188
- }
224
+ if (ScrollSpy._visibleElements[0].M_ScrollSpy && this.id < ScrollSpy._visibleElements[0].M_ScrollSpy.id) {
225
+ ScrollSpy._visibleElements.unshift(this.el);
189
226
  }
190
227
  else {
191
228
  ScrollSpy._visibleElements.push(this.el);
192
229
  }
193
- const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
194
- document.querySelector(selector)?.classList.add(this.options.activeClass);
195
230
  }
231
+ else {
232
+ ScrollSpy._visibleElements.push(this.el);
233
+ }
234
+ const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
235
+ document.querySelector(selector)?.classList.add(this.options.activeClass);
236
+ }
196
237
 
197
- _exit() {
198
- ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
238
+ _exit() {
239
+ ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(value => value.getBoundingClientRect().height !== 0);
199
240
 
200
- if (ScrollSpy._visibleElements[0]) {
201
- const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
202
- actElem?.classList.remove(this.options.activeClass);
241
+ if (ScrollSpy._visibleElements[0]) {
242
+ const actElem = document.querySelector(this.options.getActiveElement(ScrollSpy._visibleElements[0].id));
243
+ actElem?.classList.remove(this.options.activeClass);
203
244
 
204
- ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((x) => x.id != this.el.id);
245
+ ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((x) => x.id != this.el.id);
205
246
 
206
- if (ScrollSpy._visibleElements[0]) {
207
- // Check if empty
208
- const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
209
- document.querySelector(selector)?.classList.add(this.options.activeClass);
210
- }
247
+ if (ScrollSpy._visibleElements[0]) {
248
+ // Check if empty
249
+ const selector = this.options.getActiveElement(ScrollSpy._visibleElements[0].id);
250
+ document.querySelector(selector)?.classList.add(this.options.activeClass);
211
251
  }
212
252
  }
253
+ }
213
254
 
214
- static {
215
- ScrollSpy._elements = [];
216
- ScrollSpy._elementsInView = [];
217
- ScrollSpy._visibleElements = []; // Array.<cash>
218
- ScrollSpy._count = 0;
219
- ScrollSpy._increment = 0;
220
- ScrollSpy._ticks = 0;
221
- }
255
+ static {
256
+ ScrollSpy._elements = [];
257
+ ScrollSpy._elementsInView = [];
258
+ ScrollSpy._visibleElements = []; // Array.<cash>
259
+ ScrollSpy._count = 0;
260
+ ScrollSpy._increment = 0;
261
+ ScrollSpy._ticks = 0;
222
262
  }
223
-
263
+ }