@materializecss/materialize 1.2.2 → 2.0.1-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 (90) hide show
  1. package/Gruntfile.js +68 -313
  2. package/README.md +26 -14
  3. package/dist/css/materialize.css +1009 -1822
  4. package/dist/css/materialize.min.css +2 -8
  5. package/dist/js/materialize.js +8414 -12299
  6. package/dist/js/materialize.min.js +8968 -2
  7. package/dist/js/materialize.min.js.map +1 -0
  8. package/package.json +13 -9
  9. package/sass/components/_badges.scss +12 -2
  10. package/sass/components/_buttons.scss +16 -11
  11. package/sass/components/_cards.scss +14 -9
  12. package/sass/components/_carousel.scss +5 -2
  13. package/sass/components/_chips.scss +3 -3
  14. package/sass/components/_collapsible.scss +22 -8
  15. package/sass/components/_collection.scss +14 -6
  16. package/sass/components/_datepicker.scss +30 -11
  17. package/sass/components/_dropdown.scss +6 -4
  18. package/sass/components/_global.scss +132 -111
  19. package/sass/components/_grid.scss +119 -98
  20. package/sass/components/_modal.scss +3 -3
  21. package/sass/components/_navbar.scss +31 -17
  22. package/sass/components/_normalize.scss +26 -124
  23. package/sass/components/_sidenav.scss +21 -20
  24. package/sass/components/_slider.scss +27 -7
  25. package/sass/components/_table_of_contents.scss +12 -12
  26. package/sass/components/_tabs.scss +47 -16
  27. package/sass/components/_tapTarget.scss +6 -6
  28. package/sass/components/_theme_variables.scss +98 -0
  29. package/sass/components/_timepicker.scss +54 -46
  30. package/sass/components/_toast.scss +3 -3
  31. package/sass/components/_tooltip.scss +4 -5
  32. package/sass/components/_typography.scss +1 -1
  33. package/sass/components/_variables.scss +185 -120
  34. package/sass/components/forms/_checkboxes.scss +9 -9
  35. package/sass/components/forms/_file-input.scss +9 -7
  36. package/sass/components/forms/_input-fields.scss +173 -234
  37. package/sass/components/forms/_radio-buttons.scss +1 -1
  38. package/sass/components/forms/_range.scss +11 -11
  39. package/sass/components/forms/_select.scss +29 -19
  40. package/sass/components/forms/_switches.scss +22 -18
  41. package/sass/materialize.scss +1 -1
  42. package/src/autocomplete.ts +459 -0
  43. package/src/bounding.ts +6 -0
  44. package/{js/buttons.js → src/buttons.ts} +103 -162
  45. package/src/cards.ts +54 -0
  46. package/{js/carousel.js → src/carousel.ts} +137 -262
  47. package/src/characterCounter.ts +88 -0
  48. package/src/chips.ts +350 -0
  49. package/src/collapsible.ts +184 -0
  50. package/{js/component.js → src/component.ts} +6 -19
  51. package/{js/datepicker.js → src/datepicker.ts} +213 -299
  52. package/{js/dropdown.js → src/dropdown.ts} +140 -254
  53. package/src/edges.ts +6 -0
  54. package/src/forms.ts +120 -0
  55. package/src/global.ts +385 -0
  56. package/src/materialbox.ts +348 -0
  57. package/src/modal.ts +256 -0
  58. package/{js/parallax.js → src/parallax.ts} +47 -60
  59. package/{js/pushpin.js → src/pushpin.ts} +19 -47
  60. package/{js/range.js → src/range.ts} +58 -139
  61. package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
  62. package/src/select.ts +448 -0
  63. package/{js/sidenav.js → src/sidenav.ts} +96 -202
  64. package/src/slider.ts +415 -0
  65. package/src/tabs.ts +293 -0
  66. package/src/tapTarget.ts +240 -0
  67. package/{js/timepicker.js → src/timepicker.ts} +268 -272
  68. package/{js/toasts.js → src/toasts.ts} +75 -134
  69. package/{js/tooltip.js → src/tooltip.ts} +59 -96
  70. package/src/waves.ts +70 -0
  71. package/extras/noUiSlider/nouislider.css +0 -404
  72. package/extras/noUiSlider/nouislider.js +0 -2147
  73. package/extras/noUiSlider/nouislider.min.js +0 -1
  74. package/js/anime.min.js +0 -34
  75. package/js/autocomplete.js +0 -479
  76. package/js/cards.js +0 -40
  77. package/js/cash.js +0 -960
  78. package/js/characterCounter.js +0 -136
  79. package/js/chips.js +0 -486
  80. package/js/collapsible.js +0 -275
  81. package/js/forms.js +0 -285
  82. package/js/global.js +0 -428
  83. package/js/materialbox.js +0 -453
  84. package/js/modal.js +0 -382
  85. package/js/select.js +0 -391
  86. package/js/slider.js +0 -497
  87. package/js/tabs.js +0 -402
  88. package/js/tapTarget.js +0 -315
  89. package/js/waves.js +0 -615
  90. package/sass/components/_waves.scss +0 -187
@@ -0,0 +1,240 @@
1
+ import { Component } from "./component";
2
+ import { M } from "./global";
3
+
4
+ let _defaults = {
5
+ onOpen: undefined,
6
+ onClose: undefined
7
+ };
8
+
9
+ export class TapTarget extends Component {
10
+ el: HTMLElement
11
+ isOpen: boolean;
12
+ private wrapper: HTMLElement;
13
+ private _handleDocumentClickBound: (this: HTMLElement, ev: MouseEvent) => any;
14
+ private _origin: HTMLElement;
15
+ private _handleTargetClickBound: EventListenerOrEventListenerObject;
16
+ private originEl: HTMLElement;
17
+ private _handleOriginClickBound: any;
18
+ private _handleThrottledResizeBound: any;
19
+ private waveEl: HTMLElement & Element & Node;
20
+ private contentEl: HTMLElement;
21
+
22
+ constructor(el, options) {
23
+ super(TapTarget, el, options);
24
+ (this.el as any).M_TapTarget = this;
25
+ this.options = {...TapTarget.defaults, ...options};
26
+ this.isOpen = false;
27
+ // setup
28
+ this._origin = document.querySelector('#'+this.el.getAttribute('data-target'));
29
+ this._setup();
30
+ this._calculatePositioning();
31
+ this._setupEventHandlers();
32
+ }
33
+
34
+ static get defaults() {
35
+ return _defaults;
36
+ }
37
+
38
+ static init(els, options) {
39
+ return super.init(this, els, options);
40
+ }
41
+
42
+ static getInstance(el) {
43
+ let domElem = !!el.jquery ? el[0] : el;
44
+ return domElem.M_TapTarget;
45
+ }
46
+
47
+ destroy() {
48
+ this._removeEventHandlers();
49
+ (this.el as any).TapTarget = undefined;
50
+ }
51
+
52
+ _setupEventHandlers() {
53
+ this._handleDocumentClickBound = this._handleDocumentClick.bind(this);
54
+ this._handleTargetClickBound = this._handleTargetClick.bind(this);
55
+ this._handleOriginClickBound = this._handleOriginClick.bind(this);
56
+ this.el.addEventListener('click', this._handleTargetClickBound);
57
+ this.originEl.addEventListener('click', this._handleOriginClickBound);
58
+ // Resize
59
+ let throttledResize = M.throttle(this._handleResize, 200);
60
+ this._handleThrottledResizeBound = throttledResize.bind(this);
61
+ window.addEventListener('resize', this._handleThrottledResizeBound);
62
+ }
63
+
64
+ _removeEventHandlers() {
65
+ this.el.removeEventListener('click', this._handleTargetClickBound);
66
+ this.originEl.removeEventListener('click', this._handleOriginClickBound);
67
+ window.removeEventListener('resize', this._handleThrottledResizeBound);
68
+ }
69
+
70
+ _handleTargetClick(e) {
71
+ this.open();
72
+ }
73
+
74
+ _handleOriginClick(e) {
75
+ this.close();
76
+ }
77
+
78
+ _handleResize(e) {
79
+ this._calculatePositioning();
80
+ }
81
+
82
+ _handleDocumentClick(e) {
83
+ if (!e.target.closest('.tap-target-wrapper')) {
84
+ this.close();
85
+ e.preventDefault();
86
+ e.stopPropagation();
87
+ }
88
+ }
89
+
90
+ _setup() {
91
+ // Creating tap target
92
+ this.wrapper = this.el.parentElement;
93
+ this.waveEl = this.wrapper.querySelector('.tap-target-wave');
94
+ this.originEl = this.wrapper.querySelector('.tap-target-origin');
95
+ this.contentEl = this.el.querySelector('.tap-target-content');
96
+ // Creating wrapper
97
+ if (!this.wrapper.classList.contains('.tap-target-wrapper')) {
98
+ this.wrapper = document.createElement('div');
99
+ this.wrapper.classList.add('tap-target-wrapper');
100
+ this.el.before(this.wrapper);
101
+ this.wrapper.append(this.el);
102
+ }
103
+ // Creating content
104
+ if (!this.contentEl) {
105
+ this.contentEl = document.createElement('div');
106
+ this.contentEl.classList.add('tap-target-content');
107
+ this.el.append(this.contentEl);
108
+ }
109
+ // Creating foreground wave
110
+ if (!this.waveEl) {
111
+ this.waveEl = document.createElement('div');
112
+ this.waveEl.classList.add('tap-target-wave');
113
+ // Creating origin
114
+ if (!this.originEl) {
115
+ this.originEl = <HTMLElement>this._origin.cloneNode(true); // .clone(true, true);
116
+ this.originEl.classList.add('tap-target-origin');
117
+ this.originEl.removeAttribute('id');
118
+ this.originEl.removeAttribute('style');
119
+ this.waveEl.append(this.originEl);
120
+ }
121
+ this.wrapper.append(this.waveEl);
122
+ }
123
+ }
124
+
125
+ private _offset(el) {
126
+ const box = el.getBoundingClientRect();
127
+ const docElem = document.documentElement;
128
+ return {
129
+ top: box.top + window.pageYOffset - docElem.clientTop,
130
+ left: box.left + window.pageXOffset - docElem.clientLeft
131
+ };
132
+ }
133
+
134
+ _calculatePositioning() {
135
+ // Element or parent is fixed position?
136
+ let isFixed = getComputedStyle(this._origin).position === 'fixed';
137
+ if (!isFixed) {
138
+
139
+ let currentElem: any = this._origin;
140
+ const parents = [];
141
+ while ((currentElem = currentElem.parentNode) && currentElem !== document)
142
+ parents.push(currentElem);
143
+
144
+ for (let i = 0; i < parents.length; i++) {
145
+ isFixed = getComputedStyle(parents[i]).position === 'fixed';
146
+ if (isFixed) break;
147
+ }
148
+ }
149
+ // Calculating origin
150
+ const originWidth = this._origin.offsetWidth;
151
+ const originHeight = this._origin.offsetHeight;
152
+ const originTop = isFixed ? this._offset(this._origin).top - M.getDocumentScrollTop() : this._offset(this._origin).top;
153
+ const originLeft = isFixed ? this._offset(this._origin).left - M.getDocumentScrollLeft() : this._offset(this._origin).left;
154
+
155
+ // Calculating screen
156
+ const windowWidth = window.innerWidth;
157
+ const windowHeight = window.innerHeight;
158
+ const scrollBarWidth = windowWidth - document.documentElement.clientWidth;
159
+ const centerX = windowWidth / 2;
160
+ const centerY = windowHeight / 2;
161
+ const isLeft = originLeft <= centerX;
162
+ const isRight = originLeft > centerX;
163
+ const isTop = originTop <= centerY;
164
+ const isBottom = originTop > centerY;
165
+ const isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75;
166
+
167
+ // Calculating tap target
168
+ const tapTargetWidth = this.el.offsetWidth;
169
+ const tapTargetHeight = this.el.offsetHeight;
170
+ const tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2;
171
+ const tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2;
172
+ const tapTargetPosition = isFixed ? 'fixed' : 'absolute';
173
+
174
+ // Calculating content
175
+ const tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth;
176
+ const tapTargetTextHeight = tapTargetHeight / 2;
177
+ const tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0;
178
+ const tapTargetTextBottom = 0;
179
+ const tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0;
180
+ const tapTargetTextRight = 0;
181
+ const tapTargetTextPadding = originWidth;
182
+ const tapTargetTextAlign = isBottom ? 'bottom' : 'top';
183
+
184
+ // Calculating wave
185
+ const tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2;
186
+ const tapTargetWaveHeight = tapTargetWaveWidth;
187
+ const tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2;
188
+ const tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2;
189
+
190
+ // Setting tap target
191
+ this.wrapper.style.top = isTop ? tapTargetTop + 'px' : '';
192
+ this.wrapper.style.right = isRight ? windowWidth - tapTargetLeft - tapTargetWidth - scrollBarWidth + 'px' : '';
193
+ this.wrapper.style.bottom = isBottom ? windowHeight - tapTargetTop - tapTargetHeight + 'px' : '';
194
+ this.wrapper.style.left = isLeft ? tapTargetLeft + 'px' : '';
195
+ this.wrapper.style.position = tapTargetPosition;
196
+
197
+ // Setting content
198
+ this.contentEl.style.width = tapTargetTextWidth + 'px';
199
+ this.contentEl.style.height = tapTargetTextHeight + 'px';
200
+ this.contentEl.style.top = tapTargetTextTop + 'px';
201
+ this.contentEl.style.right = tapTargetTextRight + 'px';
202
+ this.contentEl.style.bottom = tapTargetTextBottom + 'px';
203
+ this.contentEl.style.left = tapTargetTextLeft + 'px';
204
+ this.contentEl.style.padding = tapTargetTextPadding + 'px';
205
+ this.contentEl.style.verticalAlign = tapTargetTextAlign;
206
+
207
+ // Setting wave
208
+ this.waveEl.style.top = tapTargetWaveTop+'px';
209
+ this.waveEl.style.left = tapTargetWaveLeft+'px';
210
+ this.waveEl.style.width = tapTargetWaveWidth+'px';
211
+ this.waveEl.style.height = tapTargetWaveHeight+'px';
212
+ }
213
+
214
+ open() {
215
+ if (this.isOpen) return;
216
+ // onOpen callback
217
+ if (typeof this.options.onOpen === 'function') {
218
+ this.options.onOpen.call(this, this._origin);
219
+ }
220
+ this.isOpen = true;
221
+ this.wrapper.classList.add('open');
222
+ document.body.addEventListener('click', this._handleDocumentClickBound, true);
223
+ document.body.addEventListener('touchend', this._handleDocumentClickBound);
224
+ }
225
+
226
+ close() {
227
+ if (!this.isOpen) return;
228
+ // onClose callback
229
+ if (typeof this.options.onClose === 'function') {
230
+ this.options.onClose.call(this, this._origin);
231
+ }
232
+ this.isOpen = false;
233
+ this.wrapper.classList.remove('open');
234
+ document.body.removeEventListener('click', this._handleDocumentClickBound, true);
235
+ document.body.removeEventListener('touchend', this._handleDocumentClickBound);
236
+ }
237
+ }
238
+
239
+
240
+