@materializecss/materialize 2.0.3-alpha → 2.0.3

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 (71) hide show
  1. package/README.md +1 -1
  2. package/dist/css/materialize.css +345 -236
  3. package/dist/css/materialize.min.css +2 -2
  4. package/dist/js/materialize.js +518 -1979
  5. package/dist/js/materialize.min.js +2 -2
  6. package/dist/js/materialize.min.js.map +1 -1
  7. package/dist/src/buttons.d.ts.map +1 -1
  8. package/dist/src/cards.d.ts.map +1 -1
  9. package/dist/src/collapsible.d.ts +1 -0
  10. package/dist/src/collapsible.d.ts.map +1 -1
  11. package/dist/src/dropdown.d.ts.map +1 -1
  12. package/dist/src/global.d.ts.map +1 -1
  13. package/dist/src/materialbox.d.ts +14 -10
  14. package/dist/src/materialbox.d.ts.map +1 -1
  15. package/dist/src/modal.d.ts.map +1 -1
  16. package/dist/src/range.d.ts.map +1 -1
  17. package/dist/src/scrollspy.d.ts.map +1 -1
  18. package/dist/src/sidenav.d.ts +25 -25
  19. package/dist/src/sidenav.d.ts.map +1 -1
  20. package/dist/src/slider.d.ts +12 -12
  21. package/dist/src/slider.d.ts.map +1 -1
  22. package/dist/src/tabs.d.ts +1 -1
  23. package/dist/src/tabs.d.ts.map +1 -1
  24. package/dist/src/toasts.d.ts +7 -2
  25. package/dist/src/toasts.d.ts.map +1 -1
  26. package/dist/src/tooltip.d.ts +8 -2
  27. package/dist/src/tooltip.d.ts.map +1 -1
  28. package/package.json +14 -13
  29. package/sass/components/_buttons.scss +158 -73
  30. package/sass/components/_chips.scss +75 -28
  31. package/sass/components/_collapsible.scss +14 -2
  32. package/sass/components/_global.scss +6 -94
  33. package/sass/components/_materialbox.scss +2 -2
  34. package/sass/components/_modal.scss +0 -1
  35. package/sass/components/_preloader.scss +85 -0
  36. package/sass/components/_tooltip.scss +18 -8
  37. package/sass/components/_variables.scss +5 -4
  38. package/sass/components/forms/_range.scss +1 -1
  39. package/sass/components/forms/_switches.scss +44 -14
  40. package/Gruntfile.js +0 -480
  41. package/src/autocomplete.ts +0 -553
  42. package/src/bounding.ts +0 -6
  43. package/src/buttons.ts +0 -260
  44. package/src/cards.ts +0 -53
  45. package/src/carousel.ts +0 -676
  46. package/src/characterCounter.ts +0 -117
  47. package/src/chips.ts +0 -439
  48. package/src/collapsible.ts +0 -249
  49. package/src/component.ts +0 -120
  50. package/src/datepicker.ts +0 -1076
  51. package/src/dropdown.ts +0 -644
  52. package/src/edges.ts +0 -6
  53. package/src/forms.ts +0 -132
  54. package/src/global.ts +0 -114
  55. package/src/index.ts +0 -26
  56. package/src/materialbox.ts +0 -404
  57. package/src/modal.ts +0 -341
  58. package/src/parallax.ts +0 -149
  59. package/src/pushpin.ts +0 -165
  60. package/src/range.ts +0 -198
  61. package/src/scrollspy.ts +0 -263
  62. package/src/select.ts +0 -484
  63. package/src/sidenav.ts +0 -543
  64. package/src/slider.ts +0 -474
  65. package/src/tabs.ts +0 -347
  66. package/src/tapTarget.ts +0 -273
  67. package/src/timepicker.ts +0 -832
  68. package/src/toasts.ts +0 -290
  69. package/src/tooltip.ts +0 -346
  70. package/src/utils.ts +0 -271
  71. package/src/waves.ts +0 -70
@@ -1,249 +0,0 @@
1
- import anim from "animejs";
2
-
3
- import { Utils } from "./utils";
4
- import { Component, BaseOptions, InitElements, MElement } from "./component";
5
-
6
- export interface CollapsibleOptions extends BaseOptions {
7
- /**
8
- * If accordion versus collapsible.
9
- * @default true
10
- */
11
- accordion: boolean;
12
- /**
13
- * Transition in duration in milliseconds.
14
- * @default 300
15
- */
16
- inDuration: number;
17
- /**
18
- * Transition out duration in milliseconds.
19
- * @default 300
20
- */
21
- outDuration: number;
22
- /**
23
- * Callback function called before collapsible is opened.
24
- * @default null
25
- */
26
- onOpenStart: (el: Element) => void;
27
- /**
28
- * Callback function called after collapsible is opened.
29
- * @default null
30
- */
31
- onOpenEnd: (el: Element) => void;
32
- /**
33
- * Callback function called before collapsible is closed.
34
- * @default null
35
- */
36
- onCloseStart: (el: Element) => void;
37
- /**
38
- * Callback function called after collapsible is closed.
39
- * @default null
40
- */
41
- onCloseEnd: (el: Element) => void;
42
- }
43
-
44
- const _defaults: CollapsibleOptions = {
45
- accordion: true,
46
- onOpenStart: null,
47
- onOpenEnd: null,
48
- onCloseStart: null,
49
- onCloseEnd: null,
50
- inDuration: 300,
51
- outDuration: 300
52
- };
53
-
54
- export class Collapsible extends Component<CollapsibleOptions> {
55
- private _headers: HTMLElement[];
56
-
57
- constructor(el: HTMLElement, options: Partial<CollapsibleOptions>) {
58
- super(el, options, Collapsible);
59
- (this.el as any).M_Collapsible = this;
60
-
61
- this.options = {
62
- ...Collapsible.defaults,
63
- ...options
64
- };
65
-
66
- // Setup tab indices
67
- this._headers = Array.from(this.el.querySelectorAll('li > .collapsible-header'));
68
- this._headers.forEach(el => el.tabIndex = 0);
69
- this._setupEventHandlers();
70
- // Open first active
71
- const activeBodies: HTMLElement[] = Array.from(this.el.querySelectorAll('li.active > .collapsible-body'));
72
- if (this.options.accordion)
73
- if (activeBodies.length > 0)
74
- activeBodies[0].style.display = 'block'; // Accordion
75
- else
76
- activeBodies.forEach(el => el.style.display = 'block'); // Expandables
77
- }
78
-
79
- static get defaults(): CollapsibleOptions {
80
- return _defaults;
81
- }
82
-
83
- /**
84
- * Initializes instance of Collapsible.
85
- * @param el HTML element.
86
- * @param options Component options.
87
- */
88
- static init(el: HTMLElement, options?: Partial<CollapsibleOptions>): Collapsible;
89
- /**
90
- * Initializes instances of Collapsible.
91
- * @param els HTML elements.
92
- * @param options Component options.
93
- */
94
- static init(els: InitElements<MElement>, options?: Partial<CollapsibleOptions>): Collapsible[];
95
- /**
96
- * Initializes instances of Collapsible.
97
- * @param els HTML elements.
98
- * @param options Component options.
99
- */
100
- static init(els: HTMLElement | InitElements<MElement>, options: Partial<CollapsibleOptions> = {}): Collapsible | Collapsible[] {
101
- return super.init(els, options, Collapsible);
102
- }
103
-
104
- static getInstance(el: HTMLElement): Collapsible {
105
- return (el as any).M_Collapsible;
106
- }
107
-
108
- destroy() {
109
- this._removeEventHandlers();
110
- (this.el as any).M_Collapsible = undefined;
111
- }
112
-
113
- _setupEventHandlers() {
114
- this.el.addEventListener('click', this._handleCollapsibleClick);
115
- this._headers.forEach(header => header.addEventListener('keydown', this._handleCollapsibleKeydown));
116
- }
117
-
118
- _removeEventHandlers() {
119
- this.el.removeEventListener('click', this._handleCollapsibleClick);
120
- this._headers.forEach(header => header.removeEventListener('keydown', this._handleCollapsibleKeydown));
121
- }
122
-
123
- _handleCollapsibleClick = (e: MouseEvent | KeyboardEvent) => {
124
- const header = (e.target as HTMLElement).closest('.collapsible-header');
125
- if (e.target && header) {
126
- const collapsible = header.closest('.collapsible');
127
- if (collapsible !== this.el) return;
128
-
129
- const li = header.closest('li');
130
- const isActive = li.classList.contains('active');
131
- const index = [...li.parentNode.children].indexOf(li);
132
-
133
- if (isActive)
134
- this.close(index);
135
- else
136
- this.open(index);
137
- }
138
- }
139
-
140
- _handleCollapsibleKeydown = (e: KeyboardEvent) => {
141
- if (Utils.keys.ENTER.includes(e.key)) {
142
- this._handleCollapsibleClick(e);
143
- }
144
- }
145
-
146
- _animateIn(index: number) {
147
- const li = this.el.children[index];
148
- if (!li) return;
149
- const body: HTMLElement = li.querySelector('.collapsible-body');
150
- anim.remove(body);
151
- body.style.display = 'block';
152
- body.style.overflow = 'hidden';
153
- body.style.height = '0';
154
- body.style.paddingTop = '';
155
- body.style.paddingBottom = '';
156
- const pTop = getComputedStyle(body).paddingTop; // . css('padding-top');
157
- const pBottom = getComputedStyle(body).paddingBottom; //body.css('padding-bottom');
158
- const finalHeight = body.scrollHeight;
159
- body.style.paddingTop = '0';
160
- body.style.paddingBottom = '0';
161
- anim({
162
- targets: body,
163
- height: finalHeight,
164
- paddingTop: pTop,
165
- paddingBottom: pBottom,
166
- duration: this.options.inDuration,
167
- easing: 'easeInOutCubic',
168
- complete: (anim) => {
169
- body.style.overflow = '';
170
- body.style.height = '';
171
- body.style.paddingTop = '';
172
- body.style.paddingBottom = '';
173
- // onOpenEnd callback
174
- if (typeof this.options.onOpenEnd === 'function') {
175
- this.options.onOpenEnd.call(this, li);
176
- }
177
- }
178
- });
179
- }
180
-
181
- _animateOut(index: number) {
182
- const li = this.el.children[index];
183
- if (!li) return;
184
- const body: HTMLElement = li.querySelector('.collapsible-body');
185
- anim.remove(body);
186
- body.style.overflow = 'hidden';
187
- anim({
188
- targets: body,
189
- height: 0,
190
- paddingTop: 0,
191
- paddingBottom: 0,
192
- duration: this.options.outDuration,
193
- easing: 'easeInOutCubic',
194
- complete: () => {
195
- body.style.overflow = '';
196
- body.style.height = '';
197
- body.style.padding = '';
198
- body.style.display = '';
199
- // onCloseEnd callback
200
- if (typeof this.options.onCloseEnd === 'function') {
201
- this.options.onCloseEnd.call(this, li);
202
- }
203
- }
204
- });
205
- }
206
-
207
- /**
208
- * Open collapsible section.
209
- * @param n Nth section to open.
210
- */
211
- open = (index: number) => {
212
- const listItems = Array.from(this.el.children).filter(c => c.tagName === 'LI');
213
- const li = listItems[index];
214
- if (li && !li.classList.contains('active')) {
215
- // onOpenStart callback
216
- if (typeof this.options.onOpenStart === 'function') {
217
- this.options.onOpenStart.call(this, li);
218
- }
219
- // Handle accordion behavior
220
- if (this.options.accordion) {
221
- const activeLis = listItems.filter(li => li.classList.contains('active'));
222
- activeLis.forEach(activeLi => {
223
- const index = listItems.indexOf(activeLi);
224
- this.close(index);
225
- });
226
- }
227
- // Animate in
228
- li.classList.add('active');
229
- this._animateIn(index);
230
- }
231
- }
232
-
233
- /**
234
- * Close collapsible section.
235
- * @param n Nth section to close.
236
- */
237
- close = (index: number) => {
238
- const li = Array.from(this.el.children).filter(c => c.tagName === 'LI')[index];
239
- if (li && li.classList.contains('active')) {
240
- // onCloseStart callback
241
- if (typeof this.options.onCloseStart === 'function') {
242
- this.options.onCloseStart.call(this, li);
243
- }
244
- // Animate out
245
- li.classList.remove('active');
246
- this._animateOut(index);
247
- }
248
- }
249
- }
package/src/component.ts DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * Base options for component initialization.
3
- */
4
- export interface BaseOptions {};
5
-
6
- export type MElement = HTMLElement | Element;
7
- export type InitElements<T extends MElement> = NodeListOf<T> | HTMLCollectionOf<T>;
8
- type ComponentConstructor<T extends Component<O>, O extends BaseOptions> = {
9
- new (el: HTMLElement, options: Partial<O>): T
10
- };
11
- type ComponentType<C extends Component<O>, O extends BaseOptions> = ComponentConstructor<C, O> & typeof Component<O>;
12
-
13
- export interface I18nOptions {
14
- cancel: string;
15
- clear: string;
16
- done: string;
17
- }
18
-
19
- export interface Openable {
20
- isOpen: boolean;
21
- open(): void;
22
- close(): void;
23
- };
24
-
25
- /**
26
- * Base class implementation for Materialize components.
27
- */
28
- export class Component<O extends BaseOptions>{
29
- /**
30
- * The DOM element the plugin was initialized with.
31
- */
32
- el: HTMLElement;
33
- /**
34
- * The options the instance was initialized with.
35
- */
36
- options: O;
37
-
38
- /**
39
- * Constructs component instance and set everything up.
40
- */
41
- constructor(el: HTMLElement, options: Partial<O>, classDef: ComponentType<Component<O>, O>){
42
- // Display error if el is not a valid HTML Element
43
- if (!(el instanceof HTMLElement)) {
44
- console.error(Error(el + ' is not an HTML Element'));
45
- }
46
- // If exists, destroy and reinitialize in child
47
- let ins = classDef.getInstance(el);
48
- if (!!ins) {
49
- ins.destroy();
50
- }
51
- this.el = el;
52
- }
53
-
54
- /**
55
- * Initializes component instance.
56
- * @param el HTML element.
57
- * @param options Component options.
58
- * @param classDef Class definition.
59
- */
60
- protected static init<
61
- I extends HTMLElement, O extends BaseOptions, C extends Component<O>
62
- >(el: I, options: O, classDef: ComponentType<C, O>): C;
63
- /**
64
- * Initializes component instances.
65
- * @param els HTML elements.
66
- * @param options Component options.
67
- * @param classDef Class definition.
68
- */
69
- protected static init<
70
- I extends MElement, O extends BaseOptions, C extends Component<O>
71
- >(els: InitElements<I>, options: Partial<O>, classDef: ComponentType<C, O>): C[];
72
- /**
73
- * Initializes component instances.
74
- * @param els HTML elements.
75
- * @param options Component options.
76
- * @param classDef Class definition.
77
- */
78
- protected static init<
79
- I extends MElement, O extends BaseOptions, C extends Component<O>
80
- >(els: I | InitElements<I>, options: Partial<O>, classDef: ComponentType<C, O>): C | C[];
81
- /**
82
- * Initializes component instances.
83
- * @param els HTML elements.
84
- * @param options Component options.
85
- * @param classDef Class definition.
86
- */
87
- protected static init<
88
- I extends MElement, O extends BaseOptions, C extends Component<O>
89
- >(els: I | InitElements<I>, options: Partial<O>, classDef: ComponentType<C, O>): C | C[] {
90
- let instances = null;
91
- if (els instanceof Element) {
92
- instances = new classDef(<HTMLElement>els, options);
93
- }
94
- else if (!!els && els.length) {
95
- instances = [];
96
- for (let i = 0; i < els.length; i++) {
97
- instances.push(new classDef(<HTMLElement>els[i], options));
98
- }
99
- }
100
- return instances;
101
- }
102
-
103
- /**
104
- * @returns default options for component instance.
105
- */
106
- static get defaults(): BaseOptions{ return {}; }
107
-
108
- /**
109
- * Retrieves component instance for the given element.
110
- * @param el Associated HTML Element.
111
- */
112
- static getInstance(el: HTMLElement): Component<BaseOptions> {
113
- throw new Error("This method must be implemented.");
114
- }
115
-
116
- /**
117
- * Destroy plugin instance and teardown.
118
- */
119
- destroy(): void { throw new Error("This method must be implemented."); }
120
- }