material 0.6.2 → 0.7.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 (98) hide show
  1. package/form.js +27 -0
  2. package/index.js +61 -51
  3. package/list.js +35 -0
  4. package/package.json +5 -1
  5. package/src/appbar.js +7 -204
  6. package/src/badge.js +27 -0
  7. package/src/button.js +160 -161
  8. package/src/calendar.js +8 -10
  9. package/src/card.js +4 -6
  10. package/src/checkbox.js +8 -10
  11. package/src/component.js +4 -6
  12. package/src/container.js +4 -6
  13. package/src/datehour.js +38 -0
  14. package/src/dialog.js +106 -153
  15. package/src/divider.js +4 -6
  16. package/src/drawer.js +11 -13
  17. package/src/field/email.js +5 -5
  18. package/src/field/image.js +4 -4
  19. package/src/{control/file.js → file.js} +18 -48
  20. package/src/form/build.js +7 -7
  21. package/src/form/verify.js +2 -2
  22. package/src/form.js +6 -8
  23. package/src/icon.js +8 -10
  24. package/src/image.js +39 -106
  25. package/src/item.js +7 -9
  26. package/src/layout.js +10 -10
  27. package/src/link.js +50 -0
  28. package/src/list/add.js +1 -1
  29. package/src/list/build.js +9 -9
  30. package/src/list/collection.js +1 -1
  31. package/src/list/display.js +10 -10
  32. package/src/list/filter.js +2 -2
  33. package/src/list/request.js +1 -1
  34. package/src/list/search.js +7 -7
  35. package/src/list.js +29 -217
  36. package/src/loading.js +73 -0
  37. package/src/map/build.js +6 -6
  38. package/src/map/display.js +8 -8
  39. package/src/menu.js +60 -116
  40. package/src/{component → mixin}/control.js +10 -10
  41. package/src/{component → mixin}/create.js +1 -1
  42. package/src/{module → mixin}/display.js +9 -22
  43. package/src/{component → mixin}/events.js +2 -2
  44. package/src/{component → mixin}/focus.js +2 -3
  45. package/src/{component → mixin}/insert.js +3 -25
  46. package/src/{control/module → module}/attributes.js +2 -2
  47. package/src/module/build.js +11 -7
  48. package/src/{component → module}/classify.js +0 -13
  49. package/src/module/dom.js +1 -57
  50. package/src/module/events.js +4 -2
  51. package/src/{component → module}/ripple.js +15 -42
  52. package/src/navigation.js +19 -0
  53. package/src/progress.js +7 -9
  54. package/src/search.js +71 -0
  55. package/src/select.js +58 -273
  56. package/src/{control/selecter.js → selecter.js} +20 -20
  57. package/src/selector.js +32 -32
  58. package/src/skin/material/component/navigation.sass +1 -0
  59. package/src/skin/material/control/button.sass +10 -0
  60. package/src/slider.js +32 -34
  61. package/src/snackbar.js +72 -51
  62. package/src/switch.js +115 -107
  63. package/src/{control/switcher.js → switcher.js} +33 -36
  64. package/src/tabs.js +8 -8
  65. package/src/tabview.js +8 -8
  66. package/src/text.js +25 -74
  67. package/src/textfield.js +97 -234
  68. package/src/toolbar.js +28 -28
  69. package/src/tooltip.js +11 -11
  70. package/src/tree.js +12 -16
  71. package/src/view/build.js +6 -6
  72. package/src/view/display.js +16 -16
  73. package/src/view.js +5 -5
  74. package/src/banner.js +0 -231
  75. package/src/component/click.js +0 -17
  76. package/src/control/button.js +0 -267
  77. package/src/control/button.new.js +0 -190
  78. package/src/control/datehour.js +0 -65
  79. package/src/control/dialog.js +0 -175
  80. package/src/control/image.js +0 -92
  81. package/src/control/link.js +0 -69
  82. package/src/control/list.js +0 -67
  83. package/src/control/loading.js +0 -128
  84. package/src/control/menu.js +0 -85
  85. package/src/control/search.js +0 -98
  86. package/src/control/select.js +0 -130
  87. package/src/control/snackbar.js +0 -89
  88. package/src/control/switch.js +0 -272
  89. package/src/control/text.js +0 -70
  90. package/src/control/textfield.js +0 -177
  91. /package/src/{component → mixin}/controller.js +0 -0
  92. /package/src/{component → mixin}/emitter.js +0 -0
  93. /package/src/{component → mixin}/icon.js +0 -0
  94. /package/src/{component → mixin}/init.js +0 -0
  95. /package/src/{component → mixin}/label.js +0 -0
  96. /package/src/{component → mixin}/settings.js +0 -0
  97. /package/src/{control/module → module}/addclass.js +0 -0
  98. /package/src/{tabs/setup.js → module/last.js} +0 -0
package/src/button.js CHANGED
@@ -1,235 +1,234 @@
1
- 'use strict'
2
-
3
- import create from './component/create'
4
- import control from './component/control'
5
- import ripple from './component/ripple'
6
-
7
- import insert from './element/insert'
8
-
9
- import emitter from './module/emitter'
10
- import attach from './module/attach'
11
-
12
- const defaults = {
13
- prefix: 'material',
14
- class: 'button',
15
- tag: 'button',
16
- ripple: false,
17
- events: [
18
- ['root.click', 'handleClick'],
19
- ['root.mouseover', 'handleMouseOver']
20
- ]
21
- }
1
+ import EventEmitter from './mixin/emitter'
2
+
3
+ import build from './module/build'
4
+ import display from './mixin/display'
5
+ import bindEvents from './module/events'
6
+
7
+ import dataset from './module/dataset'
8
+ import ripple from './module/ripple'
9
+
10
+ class Button extends EventEmitter{
11
+ static isComponent () {
12
+ return true
13
+ }
14
+
15
+ static defaults = {
16
+ class: 'button',
17
+ tag: 'button',
18
+ modules: [build, bindEvents],
19
+ styles: ['style', 'color'],
20
+ ripple: true,
21
+ stopPropagation: false,
22
+ events: [
23
+ ['element.click', 'click'],
24
+ ['element.mousedown', 'mousedown'],
25
+ ['element.mouseup', 'mouseup'],
26
+ ['element.mouseleave', 'mouseup'],
27
+ ['element.touchstart', 'mousedown'],
28
+ ['element.touchend', 'mouseup']
29
+ ]
30
+ }
22
31
 
23
- /**
24
- * Class that represents a button
25
- * @class
26
- * @since 0.0.1
27
- * @example
28
- * var button = new Button({
29
- * label: 'Button raised',
30
- * type: 'raised',
31
- * color: 'primary'
32
- * }).on('click', function(e) {
33
- * console.log('button click', e);
34
- * }).insert(document.body);
35
- */
36
- class Button {
37
32
  /**
38
- * The init method of the Button class
39
- * @param {Object} options [description]
40
- * @private
41
- * @return {Object} The class instance
33
+ * Constructor
34
+ * @param {Object} options - Component options
35
+ * @return {Object} Class instance
42
36
  */
43
37
  constructor (options) {
38
+ super()
39
+
44
40
  this.init(options)
45
41
  this.build()
46
42
  this.setup()
47
- this.attach()
43
+ this.bindEvents()
48
44
 
49
- this.emit('ready')
45
+ if (this.options.container) {
46
+ this.append(this.options.container)
47
+ }
50
48
 
51
49
  return this
52
50
  }
53
51
 
54
- /**
55
- * [init description]
56
- * @param {?} options [description]
57
- * @return {?} [description]
58
- */
59
52
  init (options) {
60
- this.options = Object.assign({}, defaults, options || {})
61
- Object.assign(this, control, emitter, attach)
53
+ this.options = Object.assign({}, Button.defaults, options || {})
54
+ Object.assign(this, build, display, bindEvents)
62
55
 
63
- this.element = this.element || {}
56
+ }
64
57
 
65
- // init module$
66
- if (this.options.ripple) {
67
- ripple(this)
68
- }
58
+ setup () {
59
+ this.styleAttributes()
69
60
 
70
- this.emit('init')
71
- }
61
+ this.buildIcon()
62
+ this.buildLabel()
72
63
 
73
- /**
74
- * Build button's method
75
- * @override
76
- * @return {void}
77
- */
78
- build () {
79
- this.element = {}
64
+ if (this.options.text) {
65
+ this.element.innerHTML = this.element.innerHTML + this.options.text
66
+ }
67
+
68
+ if (this.options.data) {
69
+ dataset(this.element, this.options.data)
70
+ }
80
71
 
81
- this.root = create(this.options)
72
+ if (this.options.type) {
73
+ this.element.setAttribute('type', this.options.type)
74
+ } else {
75
+ this.element.setAttribute('type', 'button')
76
+ }
82
77
 
83
- this.options.label = this.options.label || this.options.text
78
+ if (this.options.name) {
79
+ this.element.setAttribute('name', this.options.name)
80
+ }
84
81
 
85
- this.root.setAttribute('aria-label', this.options.label || this.options.name)
82
+ if (this.options.value) {
83
+ this.element.setAttribute('value', this.options.value)
84
+ }
86
85
 
87
86
  if (this.options.title) {
88
- this.root.setAttribute('title', this.options.title)
87
+ this.element.setAttribute('title', this.options.title)
89
88
  }
90
89
 
91
- this.label(this.options.label)
92
- this.icon(this.options.icon)
90
+ this.element.setAttribute('aria-label', this.options.text || this.options.label || this.options.class)
93
91
 
94
92
  if (this.options.tooltip) {
95
- this.root.dataset.tooltip = this.options.tooltip
93
+ this.element.setAttribute('data-tooltip', this.options.tooltip)
96
94
  }
97
95
 
98
- if (this.options.container) {
99
- if (this.options.container.root) {
100
- this.container = this.options.container.root
101
- } else {
102
- this.container = this.options.container
103
- }
104
- insert(this.root, this.options.container)
96
+ if (this.options.case) {
97
+ this.element.classList.add(this.options.case + '-case')
105
98
  }
106
99
 
107
- this.emit('built', this.root)
100
+ if (this.options.ripple) ripple(this.element)
101
+ }
108
102
 
109
- return this
103
+ append (container) {
104
+ container = container || this.options.container
105
+ if (this.options.container) {
106
+ container.appendChild(this.element)
107
+ }
110
108
  }
111
109
 
112
- /**
113
- * insert method
114
- * @param {?} container [description]
115
- * @param {?} context [description]
116
- * @return {?} [description]
117
- */
118
- insert (container, context) {
119
- insert(this.root, container, context)
110
+ buildLabel () {
111
+ if (!this.options.label) return
120
112
 
121
- return this
113
+ if (this.options.label) {
114
+ this.label = document.createElement('label')
115
+ this.label.classList.add('label')
116
+ this.label.innerHTML = this.options.label
117
+
118
+ this.element.appendChild(this.label)
119
+ }
122
120
  }
123
121
 
124
- /**
125
- * Setup method
126
- * @return {?} [description]
127
- */
128
- setup () {
129
- this.element.input = this.root
122
+ buildIcon () {
123
+ if (!this.options.icon) return
130
124
 
131
- if (this.options.name) {
132
- this.root.dataset.name = this.options.name
125
+ if (this.options.icon) {
126
+ this.icon = document.createElement('i')
127
+ this.icon.classList.add('icon')
128
+ this.icon.innerHTML = this.options.icon
129
+
130
+ this.element.appendChild(this.icon)
131
+ }
132
+ }
133
+
134
+ styleAttributes () {
135
+ if (this.options.style) {
136
+ this.element.classList.add('style-' + this.options.style)
133
137
  }
134
138
 
135
- // if (this.options.label) {
136
- // this.root.title = this.options.label
137
- // }
139
+ if (this.options.size) {
140
+ this.element.classList.add(this.options.size + '-size')
141
+ }
138
142
 
139
- if (this.options.content) {
140
- this.root.innerHTML = this.options.content
143
+ if (this.options.color) {
144
+ this.element.classList.add('color-' + this.options.color)
141
145
  }
142
146
 
143
- if (this.options.disabled === true) {
144
- this.disable()
147
+ if (this.options.bold) {
148
+ this.element.classList.add('bold')
145
149
  }
146
150
  }
147
151
 
148
- /**
149
- * Setter
150
- * @param {string} prop
151
- * @param {string} value
152
- * @return {Object} The class instance
153
- */
154
152
  set (prop, value) {
153
+ // console.log('set', this.element, prop, value)
155
154
  switch (prop) {
156
- case 'disabled':
157
- this.disable(value)
158
- break
159
155
  case 'value':
160
- this.setValue(value)
156
+ this.element.value = value
161
157
  break
162
158
  case 'label':
163
- this.setLabel(value)
159
+ if (this.label) {
160
+ this.label.innerHTML = value
161
+ }
162
+ break
163
+ case 'text':
164
+ this.element.innerHTML = value
165
+ break
166
+ case 'icon':
167
+ if (this.icon) {
168
+ this.icon.innerHTML = value
169
+ }
164
170
  break
165
171
  default:
166
- this.setValue(prop)
172
+ // console.log('prop', prop)
173
+ this.element.innerHTML = prop
167
174
  }
168
175
 
169
176
  return this
170
177
  }
171
178
 
172
- /**
173
- * [buildLabel description]
174
- * @return {Object} The class instance
175
- */
176
- setLabel (label) {
177
- label = label || this.options.label
178
- var text = label
179
-
180
- if (label === null || label === false) {
181
- text = ''
182
- } else if (label) {
183
- text = label
184
- } else if (this.options.label) {
185
- text = label
186
- } else {
187
- text = this.options.name
188
- }
179
+ setLabel (value) {
180
+ // console.log('setLabel', value)
181
+ this.label.innerHTML = value
182
+ }
189
183
 
190
- if (!this.element.label) {
191
- this.label(text)
184
+ setText (value) {
185
+ // console.log('setText', value)
186
+ if (this.label) {
187
+ this.setLabel(value)
192
188
  } else {
193
- this.element.label.textContent = text
189
+ this.element.innerHTML = value
194
190
  }
195
191
  }
196
192
 
197
- destroy () {
198
- this.container.removeChild(this.root)
199
- }
200
-
201
193
  /**
202
- * method handleClick
203
- * @param {event} e
204
- * @return {void}
194
+ * Setter
195
+ * @param {string} prop
196
+ * @param {string} value
197
+ * @return {Object} The class instance
205
198
  */
206
- handleClick (e) {
207
- e.preventDefault()
208
-
209
- if (this.disabled === true) return
210
- if (this.options.upload) return
199
+ get (prop, value) {
200
+ switch (prop) {
201
+ case 'value':
202
+ return this.element.value
203
+ case 'label':
204
+ return this.label.innerHTML
205
+ default:
206
+ return this.element.value
207
+ }
208
+ }
211
209
 
212
- // this.publish('click');
213
- this.emit('click', e)
210
+ disable () {
211
+ this.element.disabled = true
212
+ }
214
213
 
215
- return this
214
+ enable () {
215
+ this.element.disabled = false
216
216
  }
217
217
 
218
- /**
219
- * method handleClick
220
- * @param {event} e
221
- * @return {void}
222
- */
223
- handleMouseOver (e) {
224
- e.preventDefault()
218
+ click (ev) {
219
+ if (this.options.stopPropagation === true) {
220
+ ev.stopPropagation()
221
+ }
225
222
 
226
- // console.log('mouse over', e.target)
223
+ this.emit('click', ev)
224
+ }
227
225
 
228
- if (e.target.dataset.tooltip) {
229
- // console.log(e.target.dataset.tooltip)
230
- }
226
+ mousedown (ev) {
227
+ this.element.classList.add('pushed')
228
+ }
231
229
 
232
- return this
230
+ mouseup (ev) {
231
+ this.element.classList.remove('pushed')
233
232
  }
234
233
  }
235
234
 
package/src/calendar.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import create from './element/create'
4
2
  import insert from './element/insert'
5
3
  import css from './module/css'
@@ -112,12 +110,12 @@ class Calendar {
112
110
  // define main tag
113
111
  var tag = this.options.tag || 'div'
114
112
 
115
- this.root = create(tag, this.options.prefix + '-' + this.options.class)
113
+ this.element = create(tag, this.options.prefix + '-' + this.options.class)
116
114
 
117
115
  this.buildWeek()
118
116
 
119
117
  if (this.options.container) {
120
- insert(this.root, this.options.container)
118
+ insert(this.element, this.options.container)
121
119
  }
122
120
 
123
121
  return this
@@ -143,7 +141,7 @@ class Calendar {
143
141
  */
144
142
  buildHeader () {
145
143
  this.header = create('header')
146
- insert(this.header, this.root)
144
+ insert(this.header, this.element)
147
145
 
148
146
  this.buildHeadline()
149
147
 
@@ -266,7 +264,7 @@ class Calendar {
266
264
 
267
265
  this.body = create('div')
268
266
  css.add(this.body, this.options.class + '-body')
269
- insert(this.body, this.root)
267
+ insert(this.body, this.element)
270
268
 
271
269
  var hours = create('div')
272
270
  css.add(hours, 'hours')
@@ -422,7 +420,7 @@ class Calendar {
422
420
  next () {
423
421
  this.firstDay.setDate(this.firstDay.getDate() + this.options.rangedays)
424
422
 
425
- this.root.innerHTML = ''
423
+ this.element.innerHTML = ''
426
424
 
427
425
  this.buildWeek()
428
426
  }
@@ -434,7 +432,7 @@ class Calendar {
434
432
  back () {
435
433
  this.firstDay.setDate(this.firstDay.getDate() - this.options.rangedays)
436
434
 
437
- this.root.innerHTML = ''
435
+ this.element.innerHTML = ''
438
436
 
439
437
  this.buildWeek()
440
438
  }
@@ -448,7 +446,7 @@ class Calendar {
448
446
  date = date || new Date()
449
447
 
450
448
  this.firstDay = this.getFirstDayOfWeek(this.date)
451
- this.root.innerHTML = ''
449
+ this.element.innerHTML = ''
452
450
 
453
451
  this.buildWeek()
454
452
  }
@@ -459,7 +457,7 @@ class Calendar {
459
457
 
460
458
  empty () {
461
459
  console.log('empty')
462
- this.root.innerHTML = ''
460
+ this.element.innerHTML = ''
463
461
  }
464
462
  }
465
463
 
package/src/card.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
1
  // import modules
4
- import create from './component/create'
5
- import insert from './component/insert'
2
+ import create from './mixin/create'
3
+ import insert from './mixin/insert'
6
4
  // import components
7
5
  import Layout from './layout'
8
6
 
@@ -33,10 +31,10 @@ class Card {
33
31
  * @return {Object} The class instance
34
32
  */
35
33
  build () {
36
- this.root = create(this.options)
34
+ this.element = create(this.options)
37
35
 
38
36
  if (this.options.layout) {
39
- this.layout = new Layout(this.options.layout, this.root)
37
+ this.layout = new Layout(this.options.layout, this.element)
40
38
  }
41
39
  }
42
40
  }
package/src/checkbox.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
- import events from './component/events'
4
- import control from './component/control'
5
- import label from './component/label'
1
+ import events from './mixin/events'
2
+ import control from './mixin/control'
3
+ import label from './mixin/label'
6
4
 
7
5
  import insert from './element/insert'
8
6
  import build from './element/build'
@@ -79,13 +77,13 @@ class Checkbox {
79
77
  */
80
78
  build () {
81
79
  this.element = build(this.options.build)
82
- this.root = this.element.root
80
+ this.element = this.element.root
83
81
 
84
82
  this.element.control.innerHTML = icon
85
83
 
86
84
  var text = this.options.text || this.options.label
87
85
 
88
- this.element.label = label(this.root, text, this.options)
86
+ this.element.label = label(this.element, text, this.options)
89
87
 
90
88
  this.element.input.setAttribute('type', 'checkbox')
91
89
  this.element.input.setAttribute('name', this.options.name)
@@ -98,7 +96,7 @@ class Checkbox {
98
96
  if (this.options.disabled) {
99
97
  this.disabled = this.options.disabled
100
98
  this.element.input.setAttribute('disabled', 'disabled')
101
- css.add(this.root, 'is-disabled')
99
+ css.add(this.element, 'is-disabled')
102
100
  }
103
101
 
104
102
  if (this.options.checked) {
@@ -111,7 +109,7 @@ class Checkbox {
111
109
 
112
110
  // insert if container options is given
113
111
  if (this.options.container) {
114
- insert(this.root, this.options.container)
112
+ insert(this.element, this.options.container)
115
113
  }
116
114
 
117
115
  return this
@@ -148,7 +146,7 @@ class Checkbox {
148
146
  * @return {?} [description]
149
147
  */
150
148
  insert (container, context) {
151
- insert(this.root, container, context)
149
+ insert(this.element, container, context)
152
150
 
153
151
  return this
154
152
  }
package/src/component.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
- import create from './component/create'
4
- import events from './component/events'
5
- import insert from './component/insert'
1
+ import create from './mixin/create'
2
+ import events from './mixin/events'
3
+ import insert from './mixin/insert'
6
4
 
7
5
  import emitter from './module/emitter'
8
6
 
@@ -59,7 +57,7 @@ class Component {
59
57
  * @return {Object} This class instance
60
58
  */
61
59
  build () {
62
- this.root = create(this.options)
60
+ this.element = create(this.options)
63
61
 
64
62
  if (this.options.container) {
65
63
  this.insert(this.options.container)
package/src/container.js CHANGED
@@ -1,6 +1,4 @@
1
- 'use strict'
2
-
3
- import create from './component/create'
1
+ import create from './mixin/create'
4
2
  import insert from './element/insert'
5
3
  import emitter from './module/emitter'
6
4
 
@@ -50,17 +48,17 @@ class Container {
50
48
  * @return {Object} This class instance
51
49
  */
52
50
  build () {
53
- this.root = create(this.options)
51
+ this.element = create(this.options)
54
52
 
55
53
  if (this.options.container) {
56
- insert(this.root, this.options.container)
54
+ insert(this.element, this.options.container)
57
55
  }
58
56
 
59
57
  return this
60
58
  }
61
59
 
62
60
  insert (container, context) {
63
- insert(this.root, container, context)
61
+ insert(this.element, container, context)
64
62
  return this
65
63
  }
66
64
  }
@@ -0,0 +1,38 @@
1
+ import build from './module/build'
2
+
3
+ class DateHour {
4
+ static defaults = {
5
+ class: 'date',
6
+ tag: 'span'
7
+ }
8
+
9
+ constructor (options) {
10
+ this.init(options)
11
+ this.build()
12
+ }
13
+
14
+ init(options) {
15
+ this.options = Object.assign({}, DateHour.defaults, options || {})
16
+ Object.assign(this, build)
17
+ }
18
+
19
+ set (date) {
20
+ // console.log('set', src)
21
+ var d = new Date(date)
22
+ var formatted = this.format(d)
23
+ this.element.innerHTML = formatted
24
+ }
25
+
26
+ format (date) {
27
+ var hours = date.getHours()
28
+ var minutes = date.getMinutes()
29
+ var ampm = hours >= 12 ? 'pm' : 'am'
30
+ hours = hours % 12
31
+ hours = hours || 12 // the hour '0' should be '12'
32
+ minutes = minutes < 10 ? '0' + minutes : minutes
33
+ var strTime = hours + ':' + minutes + ' ' + ampm
34
+ return date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear() + ' ' + strTime
35
+ }
36
+ }
37
+
38
+ export default DateHour