@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/range.ts CHANGED
@@ -1,182 +1,198 @@
1
- import { Component } from "./component";
2
1
  import anim from "animejs";
3
2
 
4
- const _defaults = {};
3
+ import { Component, BaseOptions, InitElements, MElement } from "./component";
4
+
5
+ export interface RangeOptions extends BaseOptions {};
6
+
7
+ const _defaults: RangeOptions = {};
5
8
 
6
9
  // TODO: !!!!!
7
10
 
8
- export class Range extends Component {
9
- el: HTMLInputElement;
10
- private _mousedown: boolean;
11
- private _handleRangeChangeBound: any;
12
- private _handleRangeMousedownTouchstartBound: any;
13
- private _handleRangeInputMousemoveTouchmoveBound: any;
14
- private _handleRangeMouseupTouchendBound: any;
15
- private _handleRangeBlurMouseoutTouchleaveBound: any;
16
- value: HTMLElement;
17
- thumb: HTMLElement;
18
-
19
- constructor(el, options) {
20
- super(Range, el, options);
21
- (this.el as any).M_Range = this;
22
- this.options = {...Range.defaults, ...options};
23
- this._mousedown = false;
24
- this._setupThumb();
25
- this._setupEventHandlers();
26
- }
11
+ export class Range extends Component<RangeOptions> {
12
+ declare el: HTMLInputElement;
13
+ private _mousedown: boolean;
14
+ value: HTMLElement;
15
+ thumb: HTMLElement;
27
16
 
28
- static get defaults() {
29
- return _defaults;
30
- }
17
+ constructor(el: HTMLInputElement, options: Partial<RangeOptions>) {
18
+ super(el, options, Range);
19
+ (this.el as any).M_Range = this;
31
20
 
32
- static init(els, options) {
33
- return super.init(this, els, options);
34
- }
21
+ this.options = {
22
+ ...Range.defaults,
23
+ ...options
24
+ };
35
25
 
36
- static getInstance(el) {
37
- const domElem = !!el.jquery ? el[0] : el;
38
- return domElem.M_Range;
39
- }
26
+ this._mousedown = false;
27
+ this._setupThumb();
28
+ this._setupEventHandlers();
29
+ }
40
30
 
41
- destroy() {
42
- this._removeEventHandlers();
43
- this._removeThumb();
44
- (this.el as any).M_Range = undefined;
45
- }
31
+ static get defaults(): RangeOptions {
32
+ return _defaults;
33
+ }
46
34
 
47
- _setupEventHandlers() {
48
- this._handleRangeChangeBound = this._handleRangeChange.bind(this);
49
- this._handleRangeMousedownTouchstartBound = this._handleRangeMousedownTouchstart.bind(this);
50
- this._handleRangeInputMousemoveTouchmoveBound = this._handleRangeInputMousemoveTouchmove.bind(this);
51
- this._handleRangeMouseupTouchendBound = this._handleRangeMouseupTouchend.bind(this);
52
- this._handleRangeBlurMouseoutTouchleaveBound = this._handleRangeBlurMouseoutTouchleave.bind(this);
53
- this.el.addEventListener('change', this._handleRangeChangeBound);
54
- this.el.addEventListener('mousedown', this._handleRangeMousedownTouchstartBound);
55
- this.el.addEventListener('touchstart', this._handleRangeMousedownTouchstartBound);
56
- this.el.addEventListener('input', this._handleRangeInputMousemoveTouchmoveBound);
57
- this.el.addEventListener('mousemove', this._handleRangeInputMousemoveTouchmoveBound);
58
- this.el.addEventListener('touchmove', this._handleRangeInputMousemoveTouchmoveBound);
59
- this.el.addEventListener('mouseup', this._handleRangeMouseupTouchendBound);
60
- this.el.addEventListener('touchend', this._handleRangeMouseupTouchendBound);
61
- this.el.addEventListener('blur', this._handleRangeBlurMouseoutTouchleaveBound);
62
- this.el.addEventListener('mouseout', this._handleRangeBlurMouseoutTouchleaveBound);
63
- this.el.addEventListener('touchleave', this._handleRangeBlurMouseoutTouchleaveBound);
64
- }
35
+ /**
36
+ * Initializes instance of Range.
37
+ * @param el HTML element.
38
+ * @param options Component options.
39
+ */
40
+ static init(el: HTMLInputElement, options?: Partial<RangeOptions>): Range;
41
+ /**
42
+ * Initializes instances of Range.
43
+ * @param els HTML elements.
44
+ * @param options Component options.
45
+ */
46
+ static init(els: InitElements<HTMLInputElement | MElement>, options?: Partial<RangeOptions>): Range[];
47
+ /**
48
+ * Initializes instances of Range.
49
+ * @param els HTML elements.
50
+ * @param options Component options.
51
+ */
52
+ static init(els: HTMLInputElement | InitElements<HTMLInputElement | MElement>, options: Partial<RangeOptions> = {}): Range | Range[] {
53
+ return super.init(els, options, Range);
54
+ }
55
+
56
+ static getInstance(el: HTMLInputElement): Range {
57
+ return (el as any).M_Range;
58
+ }
65
59
 
66
- _removeEventHandlers() {
67
- this.el.removeEventListener('change', this._handleRangeChangeBound);
68
- this.el.removeEventListener('mousedown', this._handleRangeMousedownTouchstartBound);
69
- this.el.removeEventListener('touchstart', this._handleRangeMousedownTouchstartBound);
70
- this.el.removeEventListener('input', this._handleRangeInputMousemoveTouchmoveBound);
71
- this.el.removeEventListener('mousemove', this._handleRangeInputMousemoveTouchmoveBound);
72
- this.el.removeEventListener('touchmove', this._handleRangeInputMousemoveTouchmoveBound);
73
- this.el.removeEventListener('mouseup', this._handleRangeMouseupTouchendBound);
74
- this.el.removeEventListener('touchend', this._handleRangeMouseupTouchendBound);
75
- this.el.removeEventListener('blur', this._handleRangeBlurMouseoutTouchleaveBound);
76
- this.el.removeEventListener('mouseout', this._handleRangeBlurMouseoutTouchleaveBound);
77
- this.el.removeEventListener('touchleave', this._handleRangeBlurMouseoutTouchleaveBound);
60
+ destroy() {
61
+ this._removeEventHandlers();
62
+ this._removeThumb();
63
+ (this.el as any).M_Range = undefined;
64
+ }
65
+
66
+ _setupEventHandlers() {
67
+ this.el.addEventListener('change', this._handleRangeChange);
68
+ this.el.addEventListener('mousedown', this._handleRangeMousedownTouchstart);
69
+ this.el.addEventListener('touchstart', this._handleRangeMousedownTouchstart);
70
+ this.el.addEventListener('input', this._handleRangeInputMousemoveTouchmove);
71
+ this.el.addEventListener('mousemove', this._handleRangeInputMousemoveTouchmove);
72
+ this.el.addEventListener('touchmove', this._handleRangeInputMousemoveTouchmove);
73
+ this.el.addEventListener('mouseup', this._handleRangeMouseupTouchend);
74
+ this.el.addEventListener('touchend', this._handleRangeMouseupTouchend);
75
+ this.el.addEventListener('blur', this._handleRangeBlurMouseoutTouchleave);
76
+ this.el.addEventListener('mouseout', this._handleRangeBlurMouseoutTouchleave);
77
+ this.el.addEventListener('touchleave', this._handleRangeBlurMouseoutTouchleave);
78
+ }
79
+
80
+ _removeEventHandlers() {
81
+ this.el.removeEventListener('change', this._handleRangeChange);
82
+ this.el.removeEventListener('mousedown', this._handleRangeMousedownTouchstart);
83
+ this.el.removeEventListener('touchstart', this._handleRangeMousedownTouchstart);
84
+ this.el.removeEventListener('input', this._handleRangeInputMousemoveTouchmove);
85
+ this.el.removeEventListener('mousemove', this._handleRangeInputMousemoveTouchmove);
86
+ this.el.removeEventListener('touchmove', this._handleRangeInputMousemoveTouchmove);
87
+ this.el.removeEventListener('mouseup', this._handleRangeMouseupTouchend);
88
+ this.el.removeEventListener('touchend', this._handleRangeMouseupTouchend);
89
+ this.el.removeEventListener('blur', this._handleRangeBlurMouseoutTouchleave);
90
+ this.el.removeEventListener('mouseout', this._handleRangeBlurMouseoutTouchleave);
91
+ this.el.removeEventListener('touchleave', this._handleRangeBlurMouseoutTouchleave);
92
+ }
93
+
94
+ _handleRangeChange = () => {
95
+ this.value.innerHTML = this.el.value;
96
+ if (!this.thumb.classList.contains('active')) {
97
+ this._showRangeBubble();
78
98
  }
99
+ const offsetLeft = this._calcRangeOffset();
100
+ this.thumb.classList.add('active');
101
+ this.thumb.style.left = offsetLeft+'px';
102
+ }
79
103
 
80
- _handleRangeChange() {
81
- this.value.innerHTML = this.el.value;
82
- if (!this.thumb.classList.contains('active')) {
83
- this._showRangeBubble();
84
- }
104
+ _handleRangeMousedownTouchstart = (e: MouseEvent | TouchEvent) => {
105
+ // Set indicator value
106
+ this.value.innerHTML = this.el.value;
107
+ this._mousedown = true;
108
+ this.el.classList.add('active');
109
+ if (!this.thumb.classList.contains('active')) {
110
+ this._showRangeBubble();
111
+ }
112
+ if (e.type !== 'input') {
85
113
  const offsetLeft = this._calcRangeOffset();
86
114
  this.thumb.classList.add('active');
87
115
  this.thumb.style.left = offsetLeft+'px';
88
116
  }
117
+ }
89
118
 
90
- _handleRangeMousedownTouchstart(e) {
91
- // Set indicator value
92
- this.value.innerHTML = this.el.value;
93
- this._mousedown = true;
94
- this.el.classList.add('active');
119
+ _handleRangeInputMousemoveTouchmove = () => {
120
+ if (this._mousedown) {
95
121
  if (!this.thumb.classList.contains('active')) {
96
122
  this._showRangeBubble();
97
123
  }
98
- if (e.type !== 'input') {
99
- const offsetLeft = this._calcRangeOffset();
100
- this.thumb.classList.add('active');
101
- this.thumb.style.left = offsetLeft+'px';
102
- }
103
- }
104
-
105
- _handleRangeInputMousemoveTouchmove() {
106
- if (this._mousedown) {
107
- if (!this.thumb.classList.contains('active')) {
108
- this._showRangeBubble();
109
- }
110
- const offsetLeft = this._calcRangeOffset();
111
- this.thumb.classList.add('active');
112
- this.thumb.style.left = offsetLeft+'px';
113
- this.value.innerHTML = this.el.value;
114
- }
124
+ const offsetLeft = this._calcRangeOffset();
125
+ this.thumb.classList.add('active');
126
+ this.thumb.style.left = offsetLeft+'px';
127
+ this.value.innerHTML = this.el.value;
115
128
  }
129
+ }
116
130
 
117
- _handleRangeMouseupTouchend() {
118
- this._mousedown = false;
119
- this.el.classList.remove('active');
120
- }
131
+ _handleRangeMouseupTouchend = () => {
132
+ this._mousedown = false;
133
+ this.el.classList.remove('active');
134
+ }
121
135
 
122
- _handleRangeBlurMouseoutTouchleave() {
123
- if (!this._mousedown) {
124
- const paddingLeft = parseInt(getComputedStyle(this.el).paddingLeft);
125
- const marginLeft = 7 + paddingLeft + 'px';
126
- if (this.thumb.classList.contains('active')) {
127
- anim.remove(this.thumb);
128
- anim({
129
- targets: this.thumb,
130
- height: 0,
131
- width: 0,
132
- top: 10,
133
- easing: 'easeOutQuad',
134
- marginLeft: marginLeft,
135
- duration: 100
136
- });
137
- }
138
- this.thumb.classList.remove('active');
136
+ _handleRangeBlurMouseoutTouchleave = () => {
137
+ if (!this._mousedown) {
138
+ const paddingLeft = parseInt(getComputedStyle(this.el).paddingLeft);
139
+ const marginLeft = 7 + paddingLeft + 'px';
140
+ if (this.thumb.classList.contains('active')) {
141
+ anim.remove(this.thumb);
142
+ anim({
143
+ targets: this.thumb,
144
+ height: 0,
145
+ width: 0,
146
+ top: 10,
147
+ easing: 'easeOutQuad',
148
+ marginLeft: marginLeft,
149
+ duration: 100
150
+ });
139
151
  }
152
+ this.thumb.classList.remove('active');
140
153
  }
154
+ }
141
155
 
142
- _setupThumb() {
143
- this.thumb = document.createElement('span');
144
- this.value = document.createElement('span');
145
- this.thumb.classList.add('thumb');
146
- this.value.classList.add('value');
147
- this.thumb.append(this.value);
148
- this.el.after(this.thumb);
149
- }
150
-
151
- _removeThumb() {
152
- this.thumb.remove();
153
- }
156
+ _setupThumb() {
157
+ this.thumb = document.createElement('span');
158
+ this.value = document.createElement('span');
159
+ this.thumb.classList.add('thumb');
160
+ this.value.classList.add('value');
161
+ this.thumb.append(this.value);
162
+ this.el.after(this.thumb);
163
+ }
154
164
 
155
- _showRangeBubble() {
156
- const paddingLeft = parseInt(getComputedStyle(this.thumb.parentElement).paddingLeft);
157
- const marginLeft = -7 + paddingLeft + 'px'; // TODO: fix magic number?
158
- anim.remove(this.thumb);
159
- anim({
160
- targets: this.thumb,
161
- height: 30,
162
- width: 30,
163
- top: -30,
164
- marginLeft: marginLeft,
165
- duration: 300,
166
- easing: 'easeOutQuint'
167
- });
168
- }
165
+ _removeThumb() {
166
+ this.thumb.remove();
167
+ }
169
168
 
170
- _calcRangeOffset(): number {
171
- const width = this.el.getBoundingClientRect().width - 15;
172
- const max = parseFloat(this.el.getAttribute('max')) || 100; // Range default max
173
- const min = parseFloat(this.el.getAttribute('min')) || 0; // Range default min
174
- const percent = (parseFloat(this.el.value) - min) / (max - min);
175
- return percent * width;
176
- }
169
+ _showRangeBubble() {
170
+ const paddingLeft = parseInt(getComputedStyle(this.thumb.parentElement).paddingLeft);
171
+ const marginLeft = -7 + paddingLeft + 'px'; // TODO: fix magic number?
172
+ anim.remove(this.thumb);
173
+ anim({
174
+ targets: this.thumb,
175
+ height: 30,
176
+ width: 30,
177
+ top: -30,
178
+ marginLeft: marginLeft,
179
+ duration: 300,
180
+ easing: 'easeOutQuint'
181
+ });
182
+ }
177
183
 
178
- static Init(){
179
- Range.init(document.querySelectorAll('input[type=range]'), {});
180
- }
184
+ _calcRangeOffset(): number {
185
+ const width = this.el.getBoundingClientRect().width - 15;
186
+ const max = parseFloat(this.el.getAttribute('max')) || 100; // Range default max
187
+ const min = parseFloat(this.el.getAttribute('min')) || 0; // Range default min
188
+ const percent = (parseFloat(this.el.value) - min) / (max - min);
189
+ return percent * width;
181
190
  }
182
191
 
192
+ /**
193
+ * Initializes every range input in the current document.
194
+ */
195
+ static Init(){
196
+ Range.init((document.querySelectorAll('input[type=range]')) as NodeListOf<HTMLInputElement>, {});
197
+ }
198
+ }