material 0.7.0 → 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 (65) hide show
  1. package/form.js +27 -0
  2. package/index.js +59 -58
  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 +155 -155
  8. package/src/calendar.js +0 -2
  9. package/src/card.js +0 -2
  10. package/src/checkbox.js +0 -2
  11. package/src/component.js +0 -2
  12. package/src/container.js +0 -2
  13. package/src/datehour.js +38 -0
  14. package/src/dialog.js +105 -152
  15. package/src/divider.js +0 -2
  16. package/src/drawer.js +0 -2
  17. package/src/{control/file.js → file.js} +15 -45
  18. package/src/form/verify.js +2 -2
  19. package/src/form.js +0 -2
  20. package/src/icon.js +0 -2
  21. package/src/image.js +39 -106
  22. package/src/item.js +0 -2
  23. package/src/{control/link.js → link.js} +13 -32
  24. package/src/list/build.js +2 -2
  25. package/src/list/collection.js +1 -1
  26. package/src/list/filter.js +2 -2
  27. package/src/list/request.js +1 -1
  28. package/src/list/search.js +5 -5
  29. package/src/list.js +29 -217
  30. package/src/loading.js +73 -0
  31. package/src/menu.js +60 -116
  32. package/src/mixin/display.js +0 -1
  33. package/src/mixin/insert.js +2 -24
  34. package/src/{control/module → module}/attributes.js +2 -2
  35. package/src/module/build.js +8 -5
  36. package/src/navigation.js +19 -0
  37. package/src/progress.js +0 -2
  38. package/src/search.js +71 -0
  39. package/src/select.js +57 -272
  40. package/src/{control/selecter.js → selecter.js} +5 -5
  41. package/src/skin/material/component/navigation.sass +1 -0
  42. package/src/skin/material/control/button.sass +10 -0
  43. package/src/slider.js +0 -2
  44. package/src/snackbar.js +72 -51
  45. package/src/switch.js +111 -103
  46. package/src/{control/switcher.js → switcher.js} +17 -20
  47. package/src/text.js +25 -74
  48. package/src/textfield.js +96 -233
  49. package/src/banner.js +0 -231
  50. package/src/control/button.js +0 -239
  51. package/src/control/button.new.js +0 -190
  52. package/src/control/datehour.js +0 -65
  53. package/src/control/dialog.js +0 -175
  54. package/src/control/image.js +0 -92
  55. package/src/control/list.js +0 -67
  56. package/src/control/loading.js +0 -128
  57. package/src/control/menu.js +0 -85
  58. package/src/control/search.js +0 -98
  59. package/src/control/select.js +0 -130
  60. package/src/control/snackbar.js +0 -91
  61. package/src/control/switch.js +0 -272
  62. package/src/control/text.js +0 -70
  63. package/src/control/textfield.js +0 -177
  64. package/src/tabs/setup.js +0 -0
  65. /package/src/{control/module → module}/addclass.js +0 -0
package/src/button.js CHANGED
@@ -1,234 +1,234 @@
1
- 'use strict'
1
+ import EventEmitter from './mixin/emitter'
2
2
 
3
- import create from './mixin/create'
4
- import control from './mixin/control'
5
- import ripple from './module/ripple'
3
+ import build from './module/build'
4
+ import display from './mixin/display'
5
+ import bindEvents from './module/events'
6
6
 
7
- import insert from './element/insert'
7
+ import dataset from './module/dataset'
8
+ import ripple from './module/ripple'
8
9
 
9
- import emitter from './module/emitter'
10
- import attach from './module/attach'
10
+ class Button extends EventEmitter{
11
+ static isComponent () {
12
+ return true
13
+ }
11
14
 
12
- const defaults = {
13
- prefix: 'material',
14
- class: 'button',
15
- tag: 'button',
16
- ripple: true,
17
- events: [
18
- ['root.click', 'handleClick'],
19
- ['root.mouseover', 'handleMouseOver']
20
- ]
21
- }
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$
58
+ setup () {
59
+ this.styleAttributes()
66
60
 
67
- this.emit('init')
68
- }
61
+ this.buildIcon()
62
+ this.buildLabel()
69
63
 
70
- /**
71
- * Build button's method
72
- * @override
73
- * @return {void}
74
- */
75
- build () {
76
- this.element = {}
64
+ if (this.options.text) {
65
+ this.element.innerHTML = this.element.innerHTML + this.options.text
66
+ }
77
67
 
78
- this.element = create(this.options)
68
+ if (this.options.data) {
69
+ dataset(this.element, this.options.data)
70
+ }
79
71
 
80
- this.options.label = this.options.label || this.options.text
72
+ if (this.options.type) {
73
+ this.element.setAttribute('type', this.options.type)
74
+ } else {
75
+ this.element.setAttribute('type', 'button')
76
+ }
81
77
 
82
- this.element.setAttribute('aria-label', this.options.label || this.options.name)
78
+ if (this.options.name) {
79
+ this.element.setAttribute('name', this.options.name)
80
+ }
81
+
82
+ if (this.options.value) {
83
+ this.element.setAttribute('value', this.options.value)
84
+ }
83
85
 
84
86
  if (this.options.title) {
85
87
  this.element.setAttribute('title', this.options.title)
86
88
  }
87
89
 
88
- this.label(this.options.label)
89
- this.icon(this.options.icon)
90
+ this.element.setAttribute('aria-label', this.options.text || this.options.label || this.options.class)
90
91
 
91
92
  if (this.options.tooltip) {
92
- this.element.dataset.tooltip = this.options.tooltip
93
+ this.element.setAttribute('data-tooltip', this.options.tooltip)
93
94
  }
94
95
 
95
- if (this.options.container) {
96
- if (this.options.container.root) {
97
- this.container = this.options.container.root
98
- } else {
99
- this.container = this.options.container
100
- }
101
- insert(this.element, this.options.container)
96
+ if (this.options.case) {
97
+ this.element.classList.add(this.options.case + '-case')
102
98
  }
103
99
 
104
- if (this.options.ripple) {
105
- ripple(this.element)
106
- }
100
+ if (this.options.ripple) ripple(this.element)
101
+ }
107
102
 
108
- return this
103
+ append (container) {
104
+ container = container || this.options.container
105
+ if (this.options.container) {
106
+ container.appendChild(this.element)
107
+ }
109
108
  }
110
109
 
111
- /**
112
- * insert method
113
- * @param {?} container [description]
114
- * @param {?} context [description]
115
- * @return {?} [description]
116
- */
117
- insert (container, context) {
118
- insert(this.element, container, context)
110
+ buildLabel () {
111
+ if (!this.options.label) return
119
112
 
120
- 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
+ }
121
120
  }
122
121
 
123
- /**
124
- * Setup method
125
- * @return {?} [description]
126
- */
127
- setup () {
128
- this.element.input = this.element
122
+ buildIcon () {
123
+ if (!this.options.icon) return
129
124
 
130
- if (this.options.name) {
131
- this.element.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)
132
131
  }
132
+ }
133
133
 
134
- // if (this.options.label) {
135
- // this.element.title = this.options.label
136
- // }
134
+ styleAttributes () {
135
+ if (this.options.style) {
136
+ this.element.classList.add('style-' + this.options.style)
137
+ }
138
+
139
+ if (this.options.size) {
140
+ this.element.classList.add(this.options.size + '-size')
141
+ }
137
142
 
138
- if (this.options.content) {
139
- this.element.innerHTML = this.options.content
143
+ if (this.options.color) {
144
+ this.element.classList.add('color-' + this.options.color)
140
145
  }
141
146
 
142
- if (this.options.disabled === true) {
143
- this.disable()
147
+ if (this.options.bold) {
148
+ this.element.classList.add('bold')
144
149
  }
145
150
  }
146
151
 
147
- /**
148
- * Setter
149
- * @param {string} prop
150
- * @param {string} value
151
- * @return {Object} The class instance
152
- */
153
152
  set (prop, value) {
153
+ // console.log('set', this.element, prop, value)
154
154
  switch (prop) {
155
- case 'disabled':
156
- this.disable(value)
157
- break
158
155
  case 'value':
159
- this.setValue(value)
156
+ this.element.value = value
160
157
  break
161
158
  case 'label':
162
- 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
+ }
163
170
  break
164
171
  default:
165
- this.setValue(prop)
172
+ // console.log('prop', prop)
173
+ this.element.innerHTML = prop
166
174
  }
167
175
 
168
176
  return this
169
177
  }
170
178
 
171
- /**
172
- * [buildLabel description]
173
- * @return {Object} The class instance
174
- */
175
- setLabel (label) {
176
- label = label || this.options.label
177
- var text = label
178
-
179
- if (label === null || label === false) {
180
- text = ''
181
- } else if (label) {
182
- text = label
183
- } else if (this.options.label) {
184
- text = label
185
- } else {
186
- text = this.options.name
187
- }
179
+ setLabel (value) {
180
+ // console.log('setLabel', value)
181
+ this.label.innerHTML = value
182
+ }
188
183
 
189
- if (!this.element.label) {
190
- this.label(text)
184
+ setText (value) {
185
+ // console.log('setText', value)
186
+ if (this.label) {
187
+ this.setLabel(value)
191
188
  } else {
192
- this.element.label.textContent = text
189
+ this.element.innerHTML = value
193
190
  }
194
191
  }
195
192
 
196
- destroy () {
197
- this.container.removeChild(this.element)
198
- }
199
-
200
193
  /**
201
- * method handleClick
202
- * @param {event} e
203
- * @return {void}
194
+ * Setter
195
+ * @param {string} prop
196
+ * @param {string} value
197
+ * @return {Object} The class instance
204
198
  */
205
- handleClick (e) {
206
- e.preventDefault()
207
-
208
- if (this.disabled === true) return
209
- 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
+ }
210
209
 
211
- // this.publish('click');
212
- this.emit('click', e)
210
+ disable () {
211
+ this.element.disabled = true
212
+ }
213
213
 
214
- return this
214
+ enable () {
215
+ this.element.disabled = false
215
216
  }
216
217
 
217
- /**
218
- * method handleClick
219
- * @param {event} e
220
- * @return {void}
221
- */
222
- handleMouseOver (e) {
223
- e.preventDefault()
218
+ click (ev) {
219
+ if (this.options.stopPropagation === true) {
220
+ ev.stopPropagation()
221
+ }
224
222
 
225
- // console.log('mouse over', e.target)
223
+ this.emit('click', ev)
224
+ }
226
225
 
227
- if (e.target.dataset.tooltip) {
228
- // console.log(e.target.dataset.tooltip)
229
- }
226
+ mousedown (ev) {
227
+ this.element.classList.add('pushed')
228
+ }
230
229
 
231
- return this
230
+ mouseup (ev) {
231
+ this.element.classList.remove('pushed')
232
232
  }
233
233
  }
234
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'
package/src/card.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  // import modules
4
2
  import create from './mixin/create'
5
3
  import insert from './mixin/insert'
package/src/checkbox.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import events from './mixin/events'
4
2
  import control from './mixin/control'
5
3
  import label from './mixin/label'
package/src/component.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import create from './mixin/create'
4
2
  import events from './mixin/events'
5
3
  import insert from './mixin/insert'
package/src/container.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import create from './mixin/create'
4
2
  import insert from './element/insert'
5
3
  import emitter from './module/emitter'
@@ -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