kmaterialize 2.0.0 → 2.3.3-1.0.1

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 (156) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +55 -91
  3. package/components/appbar/_navbar.old.scss +223 -0
  4. package/components/appbar/appbar.css +235 -0
  5. package/components/appbar/appbar.mjs +54 -0
  6. package/components/appbar/appbar.test.mjs +9 -0
  7. package/components/atomic/atomic.mjs +19 -0
  8. package/components/atomic/component.mjs +67 -0
  9. package/components/badge/_badges.scss +75 -0
  10. package/components/badge/badge.mjs +11 -0
  11. package/components/breadcrumb/_breadcrumb.scss +27 -0
  12. package/components/button/_buttons.scss +352 -0
  13. package/components/button/button.mjs +11 -0
  14. package/components/button/buttons.stories.ts +150 -0
  15. package/components/button/buttons.ts +282 -0
  16. package/components/button/examples.iso.js +18 -0
  17. package/components/button/fabSpec.js +65 -0
  18. package/components/button/test-button.mjs +16 -0
  19. package/components/card/_cards.scss +229 -0
  20. package/components/card/card.mjs +10 -0
  21. package/components/card/cards.ts +185 -0
  22. package/components/card/cardsSpec.js +269 -0
  23. package/components/carousel/_carousel.scss +93 -0
  24. package/components/carousel/_slider.scss +119 -0
  25. package/components/carousel/carousel.ts +693 -0
  26. package/components/carousel/carouselSpec.js +61 -0
  27. package/components/carousel/slider.ts +431 -0
  28. package/components/carousel/sliderSpec.js +99 -0
  29. package/components/checkbox/_checkboxes.scss +281 -0
  30. package/components/checkbox/checkbox.mdx +24 -0
  31. package/components/checkbox/checkbox.stories.ts +120 -0
  32. package/components/chip/chip.mjs +37 -0
  33. package/components/chip/chip.test.mjs +10 -0
  34. package/components/chip/chips.css +126 -0
  35. package/components/chip/chips.mdx +33 -0
  36. package/components/chip/chips.ts +440 -0
  37. package/components/chip/chipsSpec.js +165 -0
  38. package/components/chip/readme.md +323 -0
  39. package/components/collapsible/_collapsible.scss +82 -0
  40. package/components/collapsible/collapsible.ts +230 -0
  41. package/components/collapsible/collapsibleSpec.js +240 -0
  42. package/components/datepicker/_datepicker.scss +268 -0
  43. package/components/datepicker/datepicker.ts +1450 -0
  44. package/components/datepicker/datepickerSpec.js +162 -0
  45. package/components/dialog/_materialbox.scss +42 -0
  46. package/components/dialog/_modal.scss +79 -0
  47. package/components/dialog/materialbox.ts +446 -0
  48. package/components/dialog/materialboxSpec.js +37 -0
  49. package/components/dialog/modal.ts +111 -0
  50. package/components/dialog/modalSpec.js +83 -0
  51. package/components/dialog/readme.md +5 -0
  52. package/components/divider/readme.md +15 -0
  53. package/components/dropdown/_dropdown.scss +83 -0
  54. package/components/dropdown/dropdown.ts +653 -0
  55. package/components/dropdown/dropdownSpec.js +108 -0
  56. package/components/list/_collection.scss +114 -0
  57. package/components/list/_list.scss +6 -0
  58. package/components/list/list.mjs +58 -0
  59. package/components/list/list.test.mjs +16 -0
  60. package/components/loading/loading.mjs +26 -0
  61. package/components/loading/loading.test.mjs +10 -0
  62. package/components/navigation-bar/_old +582 -0
  63. package/components/navigation-bar/navigation-bar.mdx +20 -0
  64. package/components/navigation-bar/navigation-bar.stories.ts +39 -0
  65. package/components/navigation-drawer/_sidenav.scss +247 -0
  66. package/components/navigation-drawer/sidenav.ts +546 -0
  67. package/components/navigation-drawer/sidenavSpec.js +124 -0
  68. package/components/pagination/_pagination.scss +47 -0
  69. package/components/progress/_preloader.scss +416 -0
  70. package/components/radio-button/_radio-buttons.scss +112 -0
  71. package/components/radio-button/radio-buttons.mdx +28 -0
  72. package/components/radio-button/radio-buttons.stories.ts +51 -0
  73. package/components/search/autocomplete.ts +620 -0
  74. package/components/search/autocompleteSpec.js +321 -0
  75. package/components/slider/_range.scss +157 -0
  76. package/components/slider/range.ts +216 -0
  77. package/components/snackbar/_toast.scss +68 -0
  78. package/components/snackbar/toastSpec.js +132 -0
  79. package/components/snackbar/toasts.ts +312 -0
  80. package/components/switch/_switches.scss +121 -0
  81. package/components/tabs/_tabs.scss +171 -0
  82. package/components/tabs/tabs.mjs +31 -0
  83. package/components/tabs/tabs.ts +358 -0
  84. package/components/tabs/tabsSpec.js +180 -0
  85. package/components/textfield/_file-input.scss +41 -0
  86. package/components/textfield/_input-fields.scss +368 -0
  87. package/components/textfield/_select.scss +104 -0
  88. package/components/textfield/formfields.css +311 -0
  89. package/components/textfield/forms.ts +182 -0
  90. package/components/textfield/formsSpec.js +142 -0
  91. package/components/textfield/select.ts +472 -0
  92. package/components/textfield/selectSpec.js +390 -0
  93. package/components/textfield/textfield.mjs +29 -0
  94. package/components/textfield/textfield.test.mjs +10 -0
  95. package/components/timepicker/_timepicker.scss +362 -0
  96. package/components/timepicker/timepicker.ts +905 -0
  97. package/components/tooltip/_tooltip.scss +40 -0
  98. package/components/tooltip/tooltip.ts +380 -0
  99. package/components/tooltip/tooltipSpec.js +145 -0
  100. package/dist/css/materialize.colors.min.css +6 -0
  101. package/dist/css/materialize.css +7578 -6326
  102. package/dist/css/materialize.min.css +6 -13
  103. package/dist/css/materialize.min.css.map +1 -0
  104. package/dist/js/materialize.cjs.js +8410 -0
  105. package/dist/js/materialize.d.ts +2625 -0
  106. package/dist/js/materialize.js +8415 -12374
  107. package/dist/js/materialize.min.js +6 -6
  108. package/dist/js/materialize.mjs +8382 -0
  109. package/package.json +82 -47
  110. package/sass/_colors.scss +417 -0
  111. package/sass/_global.scss +490 -0
  112. package/sass/_grid.scss +172 -0
  113. package/sass/_table_of_contents.scss +28 -0
  114. package/sass/_tapTarget.scss +102 -0
  115. package/sass/_typography.scss +58 -0
  116. package/sass/_variables.scss +56 -0
  117. package/sass/colors.module.css +74 -0
  118. package/sass/materialize.scss +51 -0
  119. package/sass/mixins.module.scss +168 -0
  120. package/sass/pulse.css +35 -0
  121. package/sass/theme.module.css +140 -0
  122. package/sass/tokens.module.css +272 -0
  123. package/sass/transitions.css +10 -0
  124. package/sass/typography.module.css +150 -0
  125. package/extras/noUiSlider/nouislider.css +0 -406
  126. package/extras/noUiSlider/nouislider.js +0 -2147
  127. package/extras/noUiSlider/nouislider.min.js +0 -1
  128. package/js/anime.min.js +0 -34
  129. package/js/autocomplete.js +0 -448
  130. package/js/buttons.js +0 -354
  131. package/js/cards.js +0 -40
  132. package/js/carousel.js +0 -717
  133. package/js/cash.js +0 -960
  134. package/js/characterCounter.js +0 -136
  135. package/js/chips.js +0 -481
  136. package/js/collapsible.js +0 -275
  137. package/js/component.js +0 -44
  138. package/js/datepicker.js +0 -975
  139. package/js/dropdown.js +0 -635
  140. package/js/forms.js +0 -275
  141. package/js/global.js +0 -444
  142. package/js/materialbox.js +0 -453
  143. package/js/modal.js +0 -382
  144. package/js/parallax.js +0 -138
  145. package/js/pushpin.js +0 -148
  146. package/js/range.js +0 -263
  147. package/js/scrollspy.js +0 -295
  148. package/js/select.js +0 -450
  149. package/js/sidenav.js +0 -580
  150. package/js/slider.js +0 -359
  151. package/js/tabs.js +0 -402
  152. package/js/tapTarget.js +0 -314
  153. package/js/timepicker.js +0 -647
  154. package/js/toasts.js +0 -310
  155. package/js/tooltip.js +0 -303
  156. package/js/waves.js +0 -335
@@ -0,0 +1,321 @@
1
+ describe('Autocomplete Plugin', () => {
2
+ const fixture = `<div class="row">
3
+ <div class="col s12">
4
+ <div class="row">
5
+ <div class="input-field col s12">
6
+ <input type="text" id="normal-autocomplete" class="autocomplete">
7
+ <label for="normal-autocomplete">Autocomplete</label>
8
+ </div>
9
+ </div>
10
+ </div>
11
+ <div class="col s12">
12
+ <div class="row">
13
+ <div class="input-field col s12">
14
+ <input type="text" id="limited-autocomplete" class="autocomplete">
15
+ <label for="limited-autocomplete">Autocomplete</label>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>`;
20
+
21
+ beforeEach(() => {
22
+ XloadHtml(fixture);
23
+ M.Autocomplete.init(document.querySelectorAll('input.autocomplete'), {
24
+ dropdownOptions: {
25
+ inDuration: 0,
26
+ outDuration: 0
27
+ },
28
+ data: [
29
+ { id: 12, text: 'Apple' },
30
+ { id: 13, text: 'Microsoft' },
31
+ {
32
+ id: 42,
33
+ text: 'Google',
34
+ image:
35
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
36
+ }
37
+ ]
38
+ });
39
+ });
40
+ afterEach(() => XunloadFixtures());
41
+
42
+ describe('Autocomplete', () => {
43
+ function resetAutocomplete(autocompleteElement, data) {
44
+ M.Autocomplete.getInstance(autocompleteElement).destroy();
45
+ return M.Autocomplete.init(autocompleteElement, {
46
+ data: data,
47
+ minLength: 0,
48
+ dropdownOptions: {
49
+ inDuration: 0,
50
+ outDuration: 0
51
+ }
52
+ });
53
+ }
54
+
55
+ function openDropdownAndSelectFirstOption(autocomplete, onFinish) {
56
+ click(autocomplete);
57
+ keyup(autocomplete, 9); // works
58
+ setTimeout(() => {
59
+ const firstOption = autocomplete.parentNode.querySelector('.autocomplete-content li');
60
+ click(firstOption);
61
+ setTimeout(() => onFinish(), 10);
62
+ }, 10); // error caused by setTimeout in autocomplete component
63
+ }
64
+
65
+ it('should work with multiple initializations', (done) => {
66
+ const normal = document.querySelector('#normal-autocomplete');
67
+ M.Autocomplete.init(normal, { hi: null });
68
+ M.Autocomplete.init(normal, { hi: null });
69
+ M.Autocomplete.init(normal, { hi: null });
70
+ M.Autocomplete.init(normal, {
71
+ data: [
72
+ { id: 12, text: 'Apple' },
73
+ { id: 13, text: 'Microsoft' },
74
+ {
75
+ id: 42,
76
+ text: 'Google',
77
+ image:
78
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
79
+ }
80
+ ]
81
+ });
82
+ const autocompleteEl = normal.parentNode.querySelectorAll('.autocomplete-content');
83
+ expect(autocompleteEl.length).toEqual(
84
+ 1,
85
+ 'Should dynamically generate autocomplete structure.'
86
+ );
87
+ done();
88
+ });
89
+
90
+ it('should limit results in search function', (done) => {
91
+ const limited = document.querySelector('#limited-autocomplete');
92
+ const data = [];
93
+ for (let i = 100; i >= 0; i--) {
94
+ const randString = 'a' + Math.random().toString(36).substring(2);
95
+ data.push({ id: randString });
96
+ }
97
+ const limitedInstance = M.Autocomplete.getInstance(limited);
98
+ const limit = 20;
99
+ limitedInstance.options.onSearch = () => {
100
+ const filteredItems = data.slice(0, limit);
101
+ limitedInstance.setMenuItems(filteredItems);
102
+ };
103
+ focus(limited);
104
+ limited.value = 'a';
105
+ keyup(limited, 65);
106
+ setTimeout(() => {
107
+ const autocompleteEl = limitedInstance.container;
108
+ expect(autocompleteEl.children.length).toEqual(
109
+ 20,
110
+ 'Results should be at max the set limit'
111
+ );
112
+ done();
113
+ }, 10);
114
+ });
115
+
116
+ it('should open correctly from typing', (done) => {
117
+ const normal = document.querySelector('#normal-autocomplete');
118
+ const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
119
+ focus(normal);
120
+ normal.value = 'e';
121
+ keyup(normal, 69);
122
+ setTimeout(() => {
123
+ expect(autocompleteEl.children.length).toEqual(
124
+ 2,
125
+ 'Results should show dropdown on text input'
126
+ );
127
+ done();
128
+ }, 10);
129
+ });
130
+
131
+ it('should open correctly from keyboard focus', (done) => {
132
+ const normal = document.querySelector('#normal-autocomplete');
133
+ const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
134
+ normal.value = 'e';
135
+ keyup(normal, 9);
136
+ focus(normal);
137
+ setTimeout(() => {
138
+ expect(autocompleteEl.children.length).toEqual(
139
+ 2,
140
+ 'Results should show dropdown on text input'
141
+ );
142
+ done();
143
+ }, 10);
144
+ });
145
+
146
+ it('should select option on click', (done) => {
147
+ const normal = document.querySelector('#normal-autocomplete');
148
+ M.Autocomplete.init(normal, {
149
+ data: [{ id: 'Value A' }],
150
+ minLength: 0,
151
+ dropdownOptions: {
152
+ inDuration: 0,
153
+ outDuration: 0
154
+ }
155
+ });
156
+ openDropdownAndSelectFirstOption(normal, () => {
157
+ expect(normal.value).toEqual('Value A', 'Value should equal chosen option.');
158
+ done();
159
+ });
160
+ });
161
+
162
+ it('should select proper options on both autocompletes', (done) => {
163
+ const normal = document.querySelector('#normal-autocomplete');
164
+ const limited = document.querySelector('#limited-autocomplete');
165
+ M.Autocomplete.init(normal, {
166
+ data: [{ id: 'Value A' }],
167
+ minLength: 0,
168
+ dropdownOptions: {
169
+ inDuration: 0,
170
+ outDuration: 0
171
+ }
172
+ });
173
+ M.Autocomplete.init(limited, {
174
+ data: [{ id: 'Value B' }],
175
+ minLength: 0,
176
+ dropdownOptions: {
177
+ inDuration: 0,
178
+ outDuration: 0
179
+ }
180
+ });
181
+ openDropdownAndSelectFirstOption(normal, () => {
182
+ openDropdownAndSelectFirstOption(limited, () => {
183
+ expect(normal.value).toEqual('Value A', 'Value should equal chosen option.');
184
+ expect(limited.value).toEqual('Value B', 'Value should equal chosen option.');
185
+ done();
186
+ });
187
+ });
188
+ });
189
+
190
+ it('destroy method should properly dispose autocomplete component', () => {
191
+ const normal = document.querySelector('#normal-autocomplete');
192
+ const limited = document.querySelector('#limited-autocomplete');
193
+ expect(normal.parentNode.querySelector('.autocomplete-content')).not.toBeNull();
194
+ expect(limited.parentNode.querySelector('.autocomplete-content')).not.toBeNull();
195
+ const normalInstance = M.Autocomplete.getInstance(normal);
196
+ const limitedInstance = M.Autocomplete.getInstance(limited);
197
+ normalInstance.destroy();
198
+ limitedInstance.destroy();
199
+ expect(normal.parentNode.querySelector('.autocomplete-content')).toBeNull();
200
+ expect(limited.parentNode.querySelector('.autocomplete-content')).toBeNull();
201
+ });
202
+
203
+ it('selectOption method should chose only from showed dropdown', (done) => {
204
+ const normal = document.querySelector('#normal-autocomplete');
205
+ const autocompleteInstance = resetAutocomplete(normal, [
206
+ { id: 'Value Q1' },
207
+ { id: 'Value Q' },
208
+ { id: 'Value R' }
209
+ ]);
210
+ const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
211
+
212
+ focus(normal);
213
+ normal.value = 'Q';
214
+ keyup(normal, 81);
215
+
216
+ setTimeout(() => {
217
+ expect(autocompleteEl.children.length).toBe(2);
218
+ const dropdownAutocompleteIds = Array.from(autocompleteEl.querySelectorAll('li')).map(
219
+ (liElement) => liElement.getAttribute('data-id')
220
+ );
221
+ expect(dropdownAutocompleteIds).toEqual(['Value Q1', 'Value Q']);
222
+
223
+ autocompleteInstance.selectOption('Value R');
224
+ expect(normal.value)
225
+ .withContext('Only options from dropdown can be selected through selectOption')
226
+ .toBe('Q');
227
+ autocompleteInstance.selectOption('Value Q');
228
+ expect(normal.value)
229
+ .withContext('Only options from dropdown can be selected through selectOption')
230
+ .toBe('Value Q');
231
+ done();
232
+ }, 10);
233
+ });
234
+
235
+ it('setValues method should chose from any init data entry', (done) => {
236
+ const normal = document.querySelector('#normal-autocomplete');
237
+ const autocompleteInstance = resetAutocomplete(normal, [
238
+ { id: 'Value Q1' },
239
+ { id: 'Value Q' },
240
+ { id: 'Value R' }
241
+ ]);
242
+ const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
243
+
244
+ focus(normal);
245
+ normal.value = 'Q';
246
+ keyup(normal, 81);
247
+
248
+ setTimeout(function () {
249
+ expect(autocompleteEl.children.length).toBe(2);
250
+ const dropdownAutocompleteIds = Array.from(autocompleteEl.querySelectorAll('li')).map(
251
+ (liElement) => liElement.getAttribute('data-id')
252
+ );
253
+ expect(dropdownAutocompleteIds).toEqual(['Value Q1', 'Value Q']);
254
+
255
+ autocompleteInstance.setValues([{ id: 'Value R' }]);
256
+ expect(normal.value)
257
+ .withContext('Any option from init data can be selected through setValues')
258
+ .toBe('Value R');
259
+ autocompleteInstance.setValues([{ id: 'Value Q' }]);
260
+ expect(normal.value)
261
+ .withContext('Any option from init data can be selected through setValues')
262
+ .toBe('Value Q');
263
+ done();
264
+ }, 10);
265
+ });
266
+
267
+ it('selected options should preselect option in single select', (done) => {
268
+ const normal = document.querySelector('#normal-autocomplete');
269
+ M.Autocomplete.getInstance(normal).destroy();
270
+ M.Autocomplete.init(normal, {
271
+ data: [{ id: 'Value A', text: 'Text 1' }, { id: 'Value B', text: 'Text 2' }],
272
+ selected: ['Value B'],
273
+ });
274
+
275
+ setTimeout(() => {
276
+ expect(normal.value)
277
+ .withContext('Value should equal chosen option.')
278
+ .toBe('Text 2');
279
+ done();
280
+ }, 10);
281
+ });
282
+
283
+ it('selected options should preselect options in multi select', (done) => {
284
+ const normal = document.querySelector('#normal-autocomplete');
285
+ M.Autocomplete.getInstance(normal).destroy();
286
+ M.Autocomplete.init(normal, {
287
+ data: [{ id: 'Value A', text: 'Text 1' }, { id: 'Value B', text: 'Text 2' }, { id: 'Value C', text: 'Text 3' }],
288
+ selected: ['Value A', 'Value B']
289
+ });
290
+ const instance = M.Autocomplete.getInstance(normal);
291
+
292
+ setTimeout(() => {
293
+ const dropdownAutocompleteIds = Array.from(instance.selectedValues).map(
294
+ (selectedValue) => selectedValue.id
295
+ );
296
+ expect(dropdownAutocompleteIds)
297
+ .withContext('Value should equal chosen option.')
298
+ .toEqual(['Value A', 'Value B']);
299
+ done();
300
+ }, 10);
301
+ });
302
+
303
+ it('selectOptions should select multiple options', (done) => {
304
+ const normal = document.querySelector('#normal-autocomplete');
305
+ resetAutocomplete(normal, [
306
+ { id: 1, text: 'Value A' },
307
+ { id: 2, text: 'Value B' },
308
+ { id: 3, text: 'Value C' }
309
+ ]);
310
+ const selectOptions = [2, 3];
311
+ const autocomplete = M.Autocomplete.getInstance(normal)
312
+ autocomplete.selectOptions(selectOptions);
313
+ setTimeout(() => {
314
+ expect(autocomplete.selectedValues.filter((value) => !(selectOptions.indexOf(value.id) === -1)).length === selectOptions.length)
315
+ .withContext('filtered selectValues based on selectOptions should match')
316
+ .toBe(true);
317
+ done();
318
+ }, 10)
319
+ });
320
+ });
321
+ });
@@ -0,0 +1,157 @@
1
+ @use '../../sass/global' as *;
2
+
3
+ .range-field {
4
+ position: relative;
5
+ }
6
+
7
+ input[type=range],
8
+ input[type=range] + .thumb {
9
+ @extend .no-select;
10
+ cursor: pointer;
11
+ }
12
+
13
+ input[type=range] {
14
+ position: relative;
15
+ background: linear-gradient(var(--md-sys-color-outline-variant), var(--md-sys-color-outline-variant));
16
+ border: none;
17
+ outline: none;
18
+ width: 100%;
19
+ margin: 15px 0;
20
+ padding: 0;
21
+ height: 3px;
22
+
23
+ &:focus {
24
+ outline: none;
25
+ }
26
+ }
27
+
28
+ input[type=range] + .thumb {
29
+ position: absolute;
30
+ top: 10px;
31
+ left: 0;
32
+ border: none;
33
+ height: 0;
34
+ width: 0;
35
+ border-radius: 50%;
36
+ background-color: var(--md-sys-color-primary);
37
+ margin-left: 7px;
38
+
39
+ transform-origin: 50% 50%;
40
+ transform: rotate(-45deg);
41
+
42
+ .value {
43
+ display: block;
44
+ width: 30px;
45
+ text-align: center;
46
+ color: var(--md-sys-color-primary);
47
+ font-size: 0;
48
+ transform: rotate(45deg);
49
+ }
50
+
51
+ &.active {
52
+ border-radius: 50% 50% 50% 0;
53
+
54
+ .value {
55
+ color: var(--md-sys-color-on-primary);
56
+ margin-left: -1px;
57
+ margin-top: 8px;
58
+ font-size: 10px;
59
+ }
60
+ }
61
+ }
62
+
63
+ // Shared
64
+ @mixin range-track {
65
+ height: 3px;
66
+ background-color: var(--md-sys-color-surface-variant);
67
+ border: none;
68
+ }
69
+
70
+ @mixin range-thumb {
71
+ border: none;
72
+ height: 14px;
73
+ width: 14px;
74
+ border-radius: 50%;
75
+ background: var(--md-sys-color-primary);
76
+ transition: box-shadow .3s;
77
+ }
78
+
79
+ // WebKit
80
+ input[type=range] {
81
+ appearance: none;
82
+ -webkit-appearance: none;
83
+ }
84
+
85
+ input[type=range]::-webkit-slider-runnable-track {
86
+ @include range-track;
87
+ }
88
+
89
+ input[type=range]::-webkit-slider-thumb {
90
+ @include range-thumb;
91
+ -webkit-appearance: none;
92
+ background-color: var(--md-sys-color-primary);
93
+ transform-origin: 50% 50%;
94
+ margin: -5px 0 0 0;
95
+
96
+ }
97
+
98
+ .keyboard-focused input[type=range]:focus:not(.active)::-webkit-slider-thumb {
99
+ box-shadow: 0 0 0 10px color-mix(in srgb, transparent, var(--md-sys-color-primary) 18%);
100
+ }
101
+
102
+ // FireFox
103
+ input[type=range] {
104
+ /*required for proper track sizing in FF*/
105
+ }
106
+
107
+ input[type=range]::-moz-range-track {
108
+ @include range-track;
109
+ }
110
+
111
+ input[type=range]::-moz-focus-inner {
112
+ border: 0;
113
+ }
114
+
115
+ input[type=range]::-moz-range-thumb {
116
+ @include range-thumb;
117
+ margin-top: -5px;
118
+ }
119
+
120
+ // hide the outline behind the border
121
+ input[type=range]:-moz-focusring {
122
+ outline: 1px solid #fff;
123
+ outline-offset: -1px;
124
+ }
125
+
126
+ .keyboard-focused input[type=range]:focus:not(.active)::-moz-range-thumb {
127
+ box-shadow: 0 0 0 10px color-mix(in srgb, transparent, var(--md-sys-color-primary) 18%);
128
+ }
129
+
130
+ //------------------------------- Remove this?
131
+ // IE 10+
132
+ input[type=range]::-ms-track {
133
+ height: 3px;
134
+ // remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead
135
+ background: transparent;
136
+ // leave room for the larger thumb to overflow with a transparent border */
137
+ border-color: transparent;
138
+ border-width: 6px 0;
139
+ /*remove default tick marks*/
140
+ color: transparent;
141
+ }
142
+ input[type=range]::-ms-fill-lower,
143
+ input[type=range]::-moz-range-progress {
144
+ background: var(--md-sys-color-primary);
145
+ }
146
+ input[type=range]::-ms-fill-upper,
147
+ input[type=range]::-moz-range-track {
148
+ background: var(--md-sys-color-shadow-light);
149
+ }
150
+ input[type=range]::-ms-thumb {
151
+ @include range-thumb;
152
+ }
153
+ //--------------------------------
154
+
155
+ .keyboard-focused input[type=range]:focus:not(.active)::-ms-thumb {
156
+ box-shadow: 0 0 0 10px color-mix(in srgb, transparent, var(--md-sys-color-primary) 18%);
157
+ }
@@ -0,0 +1,216 @@
1
+ import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4
+ export interface RangeOptions extends BaseOptions {}
5
+
6
+ const _defaults: RangeOptions = {};
7
+
8
+ // TODO: !!!!!
9
+
10
+ export class Range extends Component<RangeOptions> {
11
+ declare el: HTMLInputElement;
12
+ private _mousedown: boolean;
13
+ value: HTMLElement;
14
+ thumb: HTMLElement;
15
+
16
+ constructor(el: HTMLInputElement, options: Partial<RangeOptions>) {
17
+ super(el, options, Range);
18
+ this.el['M_Range'] = this;
19
+
20
+ this.options = {
21
+ ...Range.defaults,
22
+ ...options
23
+ };
24
+
25
+ this._mousedown = false;
26
+ this._setupThumb();
27
+ this._setupEventHandlers();
28
+ }
29
+
30
+ static get defaults(): RangeOptions {
31
+ return _defaults;
32
+ }
33
+
34
+ /**
35
+ * Initializes instance of Range.
36
+ * @param el HTML element.
37
+ * @param options Component options.
38
+ */
39
+ static init(el: HTMLInputElement, options?: Partial<RangeOptions>): Range;
40
+ /**
41
+ * Initializes instances of Range.
42
+ * @param els HTML elements.
43
+ * @param options Component options.
44
+ */
45
+ static init(
46
+ els: InitElements<HTMLInputElement | MElement>,
47
+ options?: Partial<RangeOptions>
48
+ ): Range[];
49
+ /**
50
+ * Initializes instances of Range.
51
+ * @param els HTML elements.
52
+ * @param options Component options.
53
+ */
54
+ static init(
55
+ els: HTMLInputElement | InitElements<HTMLInputElement | MElement>,
56
+ options: Partial<RangeOptions> = {}
57
+ ): Range | Range[] {
58
+ return super.init(els, options, Range);
59
+ }
60
+
61
+ static getInstance(el: HTMLInputElement): Range {
62
+ return el['M_Range'];
63
+ }
64
+
65
+ destroy() {
66
+ this._removeEventHandlers();
67
+ this._removeThumb();
68
+ this.el['M_Range'] = undefined;
69
+ }
70
+
71
+ _setupEventHandlers() {
72
+ this.el.addEventListener('change', this._handleRangeChange);
73
+ this.el.addEventListener('mousedown', this._handleRangeMousedownTouchstart);
74
+ this.el.addEventListener('touchstart', this._handleRangeMousedownTouchstart);
75
+ this.el.addEventListener('input', this._handleRangeInputMousemoveTouchmove);
76
+ this.el.addEventListener('mousemove', this._handleRangeInputMousemoveTouchmove);
77
+ this.el.addEventListener('touchmove', this._handleRangeInputMousemoveTouchmove);
78
+ this.el.addEventListener('mouseup', this._handleRangeMouseupTouchend);
79
+ this.el.addEventListener('touchend', this._handleRangeMouseupTouchend);
80
+ this.el.addEventListener('blur', this._handleRangeBlurMouseoutTouchleave);
81
+ this.el.addEventListener('mouseout', this._handleRangeBlurMouseoutTouchleave);
82
+ this.el.addEventListener('touchleave', this._handleRangeBlurMouseoutTouchleave);
83
+ }
84
+
85
+ _removeEventHandlers() {
86
+ this.el.removeEventListener('change', this._handleRangeChange);
87
+ this.el.removeEventListener('mousedown', this._handleRangeMousedownTouchstart);
88
+ this.el.removeEventListener('touchstart', this._handleRangeMousedownTouchstart);
89
+ this.el.removeEventListener('input', this._handleRangeInputMousemoveTouchmove);
90
+ this.el.removeEventListener('mousemove', this._handleRangeInputMousemoveTouchmove);
91
+ this.el.removeEventListener('touchmove', this._handleRangeInputMousemoveTouchmove);
92
+ this.el.removeEventListener('mouseup', this._handleRangeMouseupTouchend);
93
+ this.el.removeEventListener('touchend', this._handleRangeMouseupTouchend);
94
+ this.el.removeEventListener('blur', this._handleRangeBlurMouseoutTouchleave);
95
+ this.el.removeEventListener('mouseout', this._handleRangeBlurMouseoutTouchleave);
96
+ this.el.removeEventListener('touchleave', this._handleRangeBlurMouseoutTouchleave);
97
+ }
98
+
99
+ _handleRangeChange = () => {
100
+ this.value.innerHTML = this.el.value;
101
+ if (!this.thumb.classList.contains('active')) {
102
+ this._showRangeBubble();
103
+ }
104
+ const offsetLeft = this._calcRangeOffset();
105
+ this.thumb.classList.add('active');
106
+ this.thumb.style.left = offsetLeft + 'px';
107
+ };
108
+
109
+ _handleRangeMousedownTouchstart = (e: MouseEvent | TouchEvent) => {
110
+ // Set indicator value
111
+ this.value.innerHTML = this.el.value;
112
+ this._mousedown = true;
113
+ this.el.classList.add('active');
114
+ if (!this.thumb.classList.contains('active')) {
115
+ this._showRangeBubble();
116
+ }
117
+ if (e.type !== 'input') {
118
+ const offsetLeft = this._calcRangeOffset();
119
+ this.thumb.classList.add('active');
120
+ this.thumb.style.left = offsetLeft + 'px';
121
+ }
122
+ };
123
+
124
+ _handleRangeInputMousemoveTouchmove = () => {
125
+ if (this._mousedown) {
126
+ if (!this.thumb.classList.contains('active')) {
127
+ this._showRangeBubble();
128
+ }
129
+ const offsetLeft = this._calcRangeOffset();
130
+ this.thumb.classList.add('active');
131
+ this.thumb.style.left = offsetLeft + 'px';
132
+ this.value.innerHTML = this.el.value;
133
+ }
134
+ };
135
+
136
+ _handleRangeMouseupTouchend = () => {
137
+ this._mousedown = false;
138
+ this.el.classList.remove('active');
139
+ };
140
+
141
+ _handleRangeBlurMouseoutTouchleave = () => {
142
+ if (!this._mousedown) {
143
+ const paddingLeft = parseInt(getComputedStyle(this.el).paddingLeft);
144
+ const marginLeftText = 7 + paddingLeft + 'px';
145
+ if (this.thumb.classList.contains('active')) {
146
+ const duration = 100;
147
+ // from
148
+ this.thumb.style.transition = 'none';
149
+ setTimeout(() => {
150
+ this.thumb.style.transition = `
151
+ height ${duration}ms ease,
152
+ width ${duration}ms ease,
153
+ top ${duration}ms ease,
154
+ margin ${duration}ms ease
155
+ `;
156
+ // to
157
+ this.thumb.style.height = '0';
158
+ this.thumb.style.width = '0';
159
+ this.thumb.style.top = '0';
160
+ this.thumb.style.marginLeft = marginLeftText;
161
+ }, 1);
162
+ }
163
+ this.thumb.classList.remove('active');
164
+ }
165
+ };
166
+
167
+ _setupThumb() {
168
+ this.thumb = document.createElement('span');
169
+ this.value = document.createElement('span');
170
+ this.thumb.classList.add('thumb');
171
+ this.value.classList.add('value');
172
+ this.thumb.append(this.value);
173
+ this.el.after(this.thumb);
174
+ }
175
+
176
+ _removeThumb() {
177
+ this.thumb.remove();
178
+ }
179
+
180
+ _showRangeBubble() {
181
+ const paddingLeft = parseInt(getComputedStyle(this.thumb.parentElement).paddingLeft);
182
+ const marginLeftText = -7 + paddingLeft + 'px'; // TODO: fix magic number?
183
+ const duration = 300;
184
+ // easeOutQuint
185
+ this.thumb.style.transition = `
186
+ height ${duration}ms ease,
187
+ width ${duration}ms ease,
188
+ top ${duration}ms ease,
189
+ margin ${duration}ms ease
190
+ `;
191
+ // to
192
+ this.thumb.style.height = '30px';
193
+ this.thumb.style.width = '30px';
194
+ this.thumb.style.top = '-30px';
195
+ this.thumb.style.marginLeft = marginLeftText;
196
+ }
197
+
198
+ _calcRangeOffset(): number {
199
+ const width = this.el.getBoundingClientRect().width - 15;
200
+ const max = parseFloat(this.el.getAttribute('max')) || 100; // Range default max
201
+ const min = parseFloat(this.el.getAttribute('min')) || 0; // Range default min
202
+ const percent = (parseFloat(this.el.value) - min) / (max - min);
203
+ return percent * width;
204
+ }
205
+
206
+ /**
207
+ * Initializes every range input in the current document.
208
+ */
209
+ static Init() {
210
+ if (typeof document !== 'undefined')
211
+ Range.init(
212
+ document?.querySelectorAll('input[type=range]') as NodeListOf<HTMLInputElement>,
213
+ {}
214
+ );
215
+ }
216
+ }