kmaterialize 2.3.3-1.0.21 → 2.3.3-1.0.23

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 (47) hide show
  1. package/components/air-datepicker/air-datepicker.js +152 -0
  2. package/components/alert/alert.js +54 -0
  3. package/components/button/buttons.js +220 -0
  4. package/components/card/cards.js +149 -0
  5. package/components/carousel/carousel.js +574 -0
  6. package/components/carousel/slider.js +340 -0
  7. package/components/chip/chips.js +341 -0
  8. package/components/collapsible/collapsible.js +156 -0
  9. package/components/color-input/color-input.js +166 -0
  10. package/components/datepicker/datepicker.js +1035 -0
  11. package/components/dialog/materialbox.js +377 -0
  12. package/components/dialog/modal.js +72 -0
  13. package/components/dropdown/dropdown.js +505 -0
  14. package/components/file-input/file-input.js +169 -0
  15. package/components/kanban/_kanban.scss +69 -0
  16. package/components/kanban/kanban.js +168 -0
  17. package/components/kanban/kanban.ts +57 -8
  18. package/components/loading/_loading.scss +68 -0
  19. package/components/loading/loading.ts +104 -0
  20. package/components/loading/loadingSpec.js +102 -0
  21. package/components/navigation-drawer/sidenav.js +454 -0
  22. package/components/number-input/number-input.js +68 -0
  23. package/components/password-input/password-input.js +49 -0
  24. package/components/popup/_popup.scss +106 -0
  25. package/components/popup/popup.ts +113 -0
  26. package/components/popup/popupSpec.js +140 -0
  27. package/components/search/autocomplete.js +470 -0
  28. package/components/slider/range.js +169 -0
  29. package/components/snackbar/toasts.js +244 -0
  30. package/components/tabs/tabs.js +289 -0
  31. package/components/textfield/forms.js +172 -0
  32. package/components/textfield/select.js +385 -0
  33. package/components/timepicker/timepicker.js +698 -0
  34. package/components/tom-select/tom-select-field.js +130 -0
  35. package/components/toolbar/toolbar.js +134 -0
  36. package/components/tooltip/tooltip.js +270 -0
  37. package/dist/css/materialize.colors.min.css +1 -1
  38. package/dist/css/materialize.css +322 -1
  39. package/dist/css/materialize.min.css +2 -2
  40. package/dist/css/materialize.min.css.map +1 -1
  41. package/dist/js/materialize.cjs.js +258 -42
  42. package/dist/js/materialize.d.ts +50 -3
  43. package/dist/js/materialize.js +258 -42
  44. package/dist/js/materialize.min.js +2 -2
  45. package/dist/js/materialize.mjs +257 -43
  46. package/package.json +6 -1
  47. package/sass/materialize.scss +2 -0
@@ -0,0 +1,377 @@
1
+ import { Utils } from '../../src/utils';
2
+ import { Component } from '../../src/component';
3
+ const _defaults = {
4
+ inDuration: 275,
5
+ outDuration: 200,
6
+ onOpenStart: null,
7
+ onOpenEnd: null,
8
+ onCloseStart: null,
9
+ onCloseEnd: null
10
+ };
11
+ export class Materialbox extends Component {
12
+ /** If the materialbox overlay is showing. */
13
+ overlayActive;
14
+ /** If the materialbox is no longer being animated. */
15
+ doneAnimating;
16
+ /** Caption, if specified. */
17
+ caption;
18
+ /** Original width of image. */
19
+ originalWidth;
20
+ /** Original height of image. */
21
+ originalHeight;
22
+ originInlineStyles;
23
+ placeholder;
24
+ _changedAncestorList;
25
+ newHeight;
26
+ newWidth;
27
+ windowWidth;
28
+ windowHeight;
29
+ attrWidth;
30
+ attrHeight;
31
+ _overlay;
32
+ _photoCaption;
33
+ constructor(el, options) {
34
+ super(el, options, Materialbox);
35
+ this.el['M_Materialbox'] = this;
36
+ this.options = {
37
+ ...Materialbox.defaults,
38
+ ...options
39
+ };
40
+ this.overlayActive = false;
41
+ this.doneAnimating = true;
42
+ this.placeholder = document.createElement('div');
43
+ this.placeholder.classList.add('material-placeholder');
44
+ this.originalWidth = 0;
45
+ this.originalHeight = 0;
46
+ this.originInlineStyles = this.el.getAttribute('style');
47
+ this.caption = this.el.getAttribute('data-caption') || '';
48
+ this.el.tabIndex = 0;
49
+ // Wrap
50
+ this.el.before(this.placeholder);
51
+ this.placeholder.append(this.el);
52
+ this._setupEventHandlers();
53
+ }
54
+ static get defaults() {
55
+ return _defaults;
56
+ }
57
+ /**
58
+ * Initializes instances of MaterialBox.
59
+ * @param els HTML elements.
60
+ * @param options Component options.
61
+ */
62
+ static init(els, options = {}) {
63
+ return super.init(els, options, Materialbox);
64
+ }
65
+ static getInstance(el) {
66
+ return el['M_Materialbox'];
67
+ }
68
+ destroy() {
69
+ this._removeEventHandlers();
70
+ this.el['M_Materialbox'] = undefined;
71
+ // Unwrap image
72
+ //this.placeholder.after(this.el).remove();
73
+ this.placeholder.remove();
74
+ this.el.removeAttribute('style');
75
+ }
76
+ _setupEventHandlers() {
77
+ this.el.addEventListener('click', this._handleMaterialboxClick);
78
+ this.el.addEventListener('keypress', this._handleMaterialboxKeypress);
79
+ }
80
+ _removeEventHandlers() {
81
+ this.el.removeEventListener('click', this._handleMaterialboxClick);
82
+ this.el.removeEventListener('keypress', this._handleMaterialboxKeypress);
83
+ }
84
+ _handleMaterialboxClick = () => {
85
+ this._handleMaterialboxToggle();
86
+ };
87
+ _handleMaterialboxKeypress = (e) => {
88
+ if (Utils.keys.ENTER.includes(e.key)) {
89
+ this._handleMaterialboxToggle();
90
+ }
91
+ };
92
+ _handleMaterialboxToggle = () => {
93
+ // If already modal, return to original
94
+ if (this.doneAnimating === false || (this.overlayActive && this.doneAnimating))
95
+ this.close();
96
+ else
97
+ this.open();
98
+ };
99
+ _handleWindowScroll = () => {
100
+ if (this.overlayActive)
101
+ this.close();
102
+ };
103
+ _handleWindowResize = () => {
104
+ if (this.overlayActive)
105
+ this.close();
106
+ };
107
+ _handleWindowEscape = (e) => {
108
+ if (Utils.keys.ESC.includes(e.key) && this.doneAnimating && this.overlayActive)
109
+ this.close();
110
+ };
111
+ _makeAncestorsOverflowVisible() {
112
+ this._changedAncestorList = [];
113
+ let ancestor = this.placeholder.parentNode;
114
+ while (ancestor !== null && ancestor !== document) {
115
+ const curr = ancestor;
116
+ if (curr.style.overflow !== 'visible') {
117
+ curr.style.overflow = 'visible';
118
+ this._changedAncestorList.push(curr);
119
+ }
120
+ ancestor = ancestor.parentNode;
121
+ }
122
+ }
123
+ _offset(el) {
124
+ const box = el.getBoundingClientRect();
125
+ const docElem = document.documentElement;
126
+ return {
127
+ top: box.top + window.scrollY - docElem.clientTop,
128
+ left: box.left + window.scrollX - docElem.clientLeft
129
+ };
130
+ }
131
+ _updateVars() {
132
+ this.windowWidth = window.innerWidth;
133
+ this.windowHeight = window.innerHeight;
134
+ this.caption = this.el.getAttribute('data-caption') || '';
135
+ }
136
+ // Image
137
+ _animateImageIn() {
138
+ this.el.style.maxHeight = this.newHeight.toString() + 'px';
139
+ this.el.style.maxWidth = this.newWidth.toString() + 'px';
140
+ const duration = this.options.inDuration;
141
+ // from
142
+ this.el.style.transition = 'none';
143
+ this.el.style.height = this.originalHeight + 'px';
144
+ this.el.style.width = this.originalWidth + 'px';
145
+ setTimeout(() => {
146
+ // easeOutQuad
147
+ this.el.style.transition = `height ${duration}ms ease,
148
+ width ${duration}ms ease,
149
+ left ${duration}ms ease,
150
+ top ${duration}ms ease
151
+ `;
152
+ // to
153
+ this.el.style.height = this.newHeight + 'px';
154
+ this.el.style.width = this.newWidth + 'px';
155
+ this.el.style.left =
156
+ Utils.getDocumentScrollLeft() +
157
+ this.windowWidth / 2 -
158
+ this._offset(this.placeholder).left -
159
+ this.newWidth / 2 +
160
+ 'px';
161
+ this.el.style.top =
162
+ Utils.getDocumentScrollTop() +
163
+ this.windowHeight / 2 -
164
+ this._offset(this.placeholder).top -
165
+ this.newHeight / 2 +
166
+ 'px';
167
+ }, 1);
168
+ setTimeout(() => {
169
+ this.doneAnimating = true;
170
+ if (typeof this.options.onOpenEnd === 'function')
171
+ this.options.onOpenEnd.call(this, this.el);
172
+ }, duration);
173
+ /*
174
+ anim({
175
+ targets: this.el, // image
176
+ height: [this.originalHeight, this.newHeight],
177
+ width: [this.originalWidth, this.newWidth],
178
+ left:
179
+ Utils.getDocumentScrollLeft() +
180
+ this.windowWidth / 2 -
181
+ this._offset(this.placeholder).left -
182
+ this.newWidth / 2,
183
+ top:
184
+ Utils.getDocumentScrollTop() +
185
+ this.windowHeight / 2 -
186
+ this._offset(this.placeholder).top -
187
+ this.newHeight / 2,
188
+
189
+ duration: this.options.inDuration,
190
+ easing: 'easeOutQuad',
191
+ complete: () => {
192
+ this.doneAnimating = true;
193
+ if (typeof this.options.onOpenEnd === 'function') this.options.onOpenEnd.call(this, this.el);
194
+ }
195
+ });
196
+ */
197
+ }
198
+ _animateImageOut() {
199
+ const duration = this.options.outDuration;
200
+ // easeOutQuad
201
+ this.el.style.transition = `height ${duration}ms ease,
202
+ width ${duration}ms ease,
203
+ left ${duration}ms ease,
204
+ top ${duration}ms ease
205
+ `;
206
+ // to
207
+ this.el.style.height = this.originalWidth + 'px';
208
+ this.el.style.width = this.originalWidth + 'px';
209
+ this.el.style.left = '0';
210
+ this.el.style.top = '0';
211
+ setTimeout(() => {
212
+ this.placeholder.style.height = '';
213
+ this.placeholder.style.width = '';
214
+ this.placeholder.style.position = '';
215
+ this.placeholder.style.top = '';
216
+ this.placeholder.style.left = '';
217
+ // Revert to width or height attribute
218
+ if (this.attrWidth)
219
+ this.el.setAttribute('width', this.attrWidth.toString());
220
+ if (this.attrHeight)
221
+ this.el.setAttribute('height', this.attrHeight.toString());
222
+ this.el.removeAttribute('style');
223
+ if (this.originInlineStyles)
224
+ this.el.setAttribute('style', this.originInlineStyles);
225
+ // Remove class
226
+ this.el.classList.remove('active');
227
+ this.doneAnimating = true;
228
+ // Remove overflow overrides on ancestors
229
+ this._changedAncestorList.forEach((anchestor) => (anchestor.style.overflow = ''));
230
+ // onCloseEnd callback
231
+ if (typeof this.options.onCloseEnd === 'function')
232
+ this.options.onCloseEnd.call(this, this.el);
233
+ }, duration);
234
+ }
235
+ // Caption
236
+ _addCaption() {
237
+ this._photoCaption = document.createElement('div');
238
+ this._photoCaption.classList.add('materialbox-caption');
239
+ this._photoCaption.innerText = this.caption;
240
+ document.body.append(this._photoCaption);
241
+ this._photoCaption.style.display = 'inline';
242
+ // Animate
243
+ this._photoCaption.style.transition = 'none';
244
+ this._photoCaption.style.opacity = '0';
245
+ const duration = this.options.inDuration;
246
+ setTimeout(() => {
247
+ this._photoCaption.style.transition = `opacity ${duration}ms ease`;
248
+ this._photoCaption.style.opacity = '1';
249
+ }, 1);
250
+ }
251
+ _removeCaption() {
252
+ const duration = this.options.outDuration;
253
+ this._photoCaption.style.transition = `opacity ${duration}ms ease`;
254
+ this._photoCaption.style.opacity = '0';
255
+ setTimeout(() => {
256
+ this._photoCaption.remove();
257
+ }, duration);
258
+ }
259
+ // Overlay
260
+ _addOverlay() {
261
+ this._overlay = document.createElement('div');
262
+ this._overlay.id = 'materialbox-overlay';
263
+ this._overlay.addEventListener('click', () => {
264
+ if (this.doneAnimating)
265
+ this.close();
266
+ }, { once: true });
267
+ // Put before in origin image to preserve z-index layering.
268
+ this.el.before(this._overlay);
269
+ // Set dimensions if needed
270
+ const overlayOffset = this._overlay.getBoundingClientRect();
271
+ this._overlay.style.width = this.windowWidth + 'px';
272
+ this._overlay.style.height = this.windowHeight + 'px';
273
+ this._overlay.style.left = -1 * overlayOffset.left + 'px';
274
+ this._overlay.style.top = -1 * overlayOffset.top + 'px';
275
+ // Animate
276
+ this._overlay.style.transition = 'none';
277
+ this._overlay.style.opacity = '0';
278
+ const duration = this.options.inDuration;
279
+ setTimeout(() => {
280
+ this._overlay.style.transition = `opacity ${duration}ms ease`;
281
+ this._overlay.style.opacity = '1';
282
+ }, 1);
283
+ }
284
+ _removeOverlay() {
285
+ const duration = this.options.outDuration;
286
+ this._overlay.style.transition = `opacity ${duration}ms ease`;
287
+ this._overlay.style.opacity = '0';
288
+ setTimeout(() => {
289
+ this.overlayActive = false;
290
+ this._overlay.remove();
291
+ }, duration);
292
+ }
293
+ /**
294
+ * Open materialbox.
295
+ */
296
+ open = () => {
297
+ this._updateVars();
298
+ this.originalWidth = this.el.getBoundingClientRect().width;
299
+ this.originalHeight = this.el.getBoundingClientRect().height;
300
+ // Set states
301
+ this.doneAnimating = false;
302
+ this.el.classList.add('active');
303
+ this.overlayActive = true;
304
+ // onOpenStart callback
305
+ if (typeof this.options.onOpenStart === 'function')
306
+ this.options.onOpenStart.call(this, this.el);
307
+ // Set positioning for placeholder
308
+ this.placeholder.style.width = this.placeholder.getBoundingClientRect().width + 'px';
309
+ this.placeholder.style.height = this.placeholder.getBoundingClientRect().height + 'px';
310
+ this.placeholder.style.position = 'relative';
311
+ this.placeholder.style.top = '0';
312
+ this.placeholder.style.left = '0';
313
+ this._makeAncestorsOverflowVisible();
314
+ // Set css on origin
315
+ this.el.style.position = 'absolute';
316
+ this.el.style.zIndex = '1000';
317
+ this.el.style.willChange = 'left, top, width, height';
318
+ // Change from width or height attribute to css
319
+ this.attrWidth = this.el.getAttribute('width');
320
+ this.attrHeight = this.el.getAttribute('height');
321
+ if (this.attrWidth) {
322
+ this.el.style.width = this.attrWidth + 'px';
323
+ this.el.removeAttribute('width');
324
+ }
325
+ if (this.attrHeight) {
326
+ this.el.style.width = this.attrHeight + 'px';
327
+ this.el.removeAttribute('height');
328
+ }
329
+ this._addOverlay();
330
+ // Add and animate caption if it exists
331
+ if (this.caption !== '')
332
+ this._addCaption();
333
+ // Resize Image
334
+ const widthPercent = this.originalWidth / this.windowWidth;
335
+ const heightPercent = this.originalHeight / this.windowHeight;
336
+ this.newWidth = 0;
337
+ this.newHeight = 0;
338
+ if (widthPercent > heightPercent) {
339
+ // Width first
340
+ const ratio = this.originalHeight / this.originalWidth;
341
+ this.newWidth = this.windowWidth * 0.9;
342
+ this.newHeight = this.windowWidth * 0.9 * ratio;
343
+ }
344
+ else {
345
+ // Height first
346
+ const ratio = this.originalWidth / this.originalHeight;
347
+ this.newWidth = this.windowHeight * 0.9 * ratio;
348
+ this.newHeight = this.windowHeight * 0.9;
349
+ }
350
+ this._animateImageIn();
351
+ // Handle Exit triggers
352
+ window.addEventListener('scroll', this._handleWindowScroll);
353
+ window.addEventListener('resize', this._handleWindowResize);
354
+ window.addEventListener('keyup', this._handleWindowEscape);
355
+ };
356
+ /**
357
+ * Close materialbox.
358
+ */
359
+ close = () => {
360
+ this._updateVars();
361
+ this.doneAnimating = false;
362
+ // onCloseStart callback
363
+ if (typeof this.options.onCloseStart === 'function')
364
+ this.options.onCloseStart.call(this, this.el);
365
+ //anim.remove(this.el);
366
+ //anim.remove(this._overlay);
367
+ //if (this.caption !== '') anim.remove(this._photoCaption);
368
+ // disable exit handlers
369
+ window.removeEventListener('scroll', this._handleWindowScroll);
370
+ window.removeEventListener('resize', this._handleWindowResize);
371
+ window.removeEventListener('keyup', this._handleWindowEscape);
372
+ this._removeOverlay();
373
+ this._animateImageOut();
374
+ if (this.caption !== '')
375
+ this._removeCaption();
376
+ };
377
+ }
@@ -0,0 +1,72 @@
1
+ import { Component } from '../../src/component';
2
+ const _defaults = {
3
+ opacity: 0.5,
4
+ inDuration: 250,
5
+ outDuration: 250,
6
+ onOpenStart: null,
7
+ onOpenEnd: null,
8
+ onCloseStart: null,
9
+ onCloseEnd: null,
10
+ preventScrolling: true,
11
+ dismissible: true,
12
+ startingTop: '4%',
13
+ endingTop: '10%'
14
+ };
15
+ class Modal extends Component {
16
+ constructor(el, options) {
17
+ super(el, options, Modal);
18
+ this.el['M_Modal'] = this;
19
+ this.options = {
20
+ ...Modal.defaults,
21
+ ...options
22
+ };
23
+ this.el.tabIndex = 0;
24
+ this._setupEventHandlers();
25
+ }
26
+ static get defaults() {
27
+ return _defaults;
28
+ }
29
+ static init(els, options = {}) {
30
+ return super.init(els, options, Modal);
31
+ }
32
+ static getInstance(el) {
33
+ return el['M_Modal'];
34
+ }
35
+ destroy() { }
36
+ _setupEventHandlers() { }
37
+ _removeEventHandlers() { }
38
+ _handleTriggerClick() { }
39
+ _handleOverlayClick() { }
40
+ _handleModalCloseClick() { }
41
+ _handleKeydown() { }
42
+ _handleFocus() { }
43
+ open() {
44
+ return this;
45
+ }
46
+ close() {
47
+ return this;
48
+ }
49
+ // Experimental!
50
+ static #createHtml(config) {
51
+ return `<dialog id="modal1" class="modal">
52
+ ${config.header ? '<div class="modal-header">' + config.header + '</div>' : ''}
53
+ <div class="modal-content">
54
+ ${config.content}
55
+ </div>
56
+ ${config.header ? '<div class="modal-footer">' + config.footer + '</div>' : ''}
57
+ </dialog>`;
58
+ }
59
+ static #createHtmlElement(config) {
60
+ const dialog = document.createElement('dialog');
61
+ dialog.id = config.id;
62
+ return dialog;
63
+ }
64
+ static create(config) {
65
+ const isServer = false;
66
+ if (isServer)
67
+ return this.#createHtml(config);
68
+ return this.#createHtmlElement(config);
69
+ }
70
+ static { }
71
+ }
72
+ export { Modal };