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/dialog.js CHANGED
@@ -1,213 +1,166 @@
1
- 'use strict'
2
-
3
1
  // dialog related modules
4
- import events from './mixin/events'
5
2
  import emitter from './module/emitter'
6
- import controller from './mixin/controller'
7
3
  import attach from './module/attach'
8
- import insert from './mixin/insert'
9
- import event from './element/event.js'
10
- import css from './module/css'
4
+ import display from './view/display'
11
5
 
6
+ import Element from './element'
12
7
  import Text from './text'
13
8
  import Button from './button'
14
- import Toolbar from './toolbar'
15
9
  import Layout from './layout'
16
10
 
17
- let defaults = {
18
- prefix: 'material',
19
- class: 'dialog',
20
- tag: 'div',
21
- events: [
22
- ['root.click', 'close']
23
- ]
24
- }
25
-
26
11
  class Dialog {
27
- /**
28
- * Constructor
29
- * @param {Object} options - Component options
30
- * @return {Object} Class instance
31
- */
12
+ static defaults = {
13
+ class: 'dialog',
14
+ close: true,
15
+ layout: [
16
+ [Element, 'head', { class: 'head' },
17
+ [Text, 'title', { class: 'title' }],
18
+ [Button, 'close', { class: 'close' }]
19
+ ],
20
+ [Element, 'body', { class: 'body' },
21
+ [Text, 'content', { class: 'content' }]
22
+ ],
23
+ [Element, 'foot', { class: 'foot' },
24
+ [Element, { class: 'divider' }],
25
+ [Button, 'ok', { class: 'ok', text: 'Ok', color: 'primary' }]
26
+ ]
27
+ ],
28
+ events: [
29
+ ['element.click', 'onClickRoot'],
30
+ ['surface.click', 'onClick'],
31
+ ['ui.ok.click', 'ok'],
32
+ ['ui.cancel.click', 'cancel'],
33
+ ['ui.close.click', 'close']
34
+ ]
35
+ }
36
+
32
37
  constructor (options) {
33
38
  this.init(options)
34
39
  this.build()
40
+ this.render()
35
41
  this.attach()
36
42
 
37
- this.element.style.display = 'none'
38
-
39
43
  return this
40
44
  }
41
45
 
42
- /**
43
- * Constructor
44
- * @param {Object} options The class options
45
- * @return {Object} This class instance
46
- */
47
- init (options) {
48
- // init options
49
- this.options = Object.assign({}, defaults, options || {})
50
-
51
- // implement modules
52
- Object.assign(this, events, emitter, attach, insert)
53
-
54
- this.layout = null
55
- this.content = null
56
- this.html = null
57
-
58
- this.controller = controller
59
-
60
- return this
46
+ init(options) {
47
+ this.options = Object.assign({}, Dialog.defaults, options || {})
48
+ Object.assign(this, emitter, attach, display)
61
49
  }
62
50
 
63
- /**
64
- * build the component using the super method
65
- * @return {Object} The class instance
66
- */
67
51
  build () {
68
52
  this.element = document.createElement('div')
53
+ this.element.classList.add('dialog')
69
54
 
70
- css.add(this.element, 'material-dialog')
55
+ this.element = this.element
71
56
 
72
- if (this.options.name) {
73
- css.add(this.element, 'dialog-' + this.options.name)
57
+ if (this.options.class !== 'dialog') {
58
+ this.element.classList.add(this.options.class)
74
59
  }
75
60
 
76
- if (this.options.css) {
77
- css.add(this.element, this.options.css)
78
- }
79
-
80
- if (this.options.theme) {
81
- css.add(this.element, this.options.theme + '-theme')
61
+ if (this.options.position) {
62
+ this.element.classList.add('position-' + this.options.position)
82
63
  }
83
64
 
84
65
  this.surface = document.createElement('div')
66
+ this.surface.classList.add('surface')
67
+ this.element.appendChild(this.surface)
85
68
 
86
- css.add(this.surface, 'dialog-surface')
87
-
88
- this.insertElement(this.surface, this.element)
69
+ this.layout = new Layout(this.options.layout, this.surface)
70
+ this.ui = this.layout.component
89
71
 
90
- if (this.options.title) {
91
- this.buildTitle()
72
+ if (this.options.container) {
73
+ this.options.container.appendChild(this.element)
92
74
  }
93
75
 
94
- if (this.options.content) {
95
- this.buildContent()
76
+ if (this.options.display === 'show') {
77
+ this.show()
96
78
  }
79
+ }
97
80
 
98
- if (this.options.layout) {
99
- this.buildLayout()
81
+ render () {
82
+ if (this.options.title && this.ui.title) {
83
+ this.ui.title.set(this.options.title)
100
84
  }
101
85
 
102
- if (this.options.html) {
103
- this.buildHTML()
86
+ if (this.options.content && this.ui.content) {
87
+ this.ui.content.set(this.options.content)
104
88
  }
105
89
 
106
- this.buildActions()
107
-
108
- event.add(this.surface, 'click', function (ev) {
109
- ev.stopPropagation()
110
- })
111
- }
112
-
113
- buildTitle () {
114
- this.title = new Text({
115
- type: 'title',
116
- css: 'dialog-title',
117
- text: this.options.title
118
- })
90
+ if (this.options.cancel && this.ui.cancel) {
91
+ this.ui.cancel.set('text', this.options.cancel)
92
+ }
119
93
 
120
- this.insertElement(this.title.root, this.surface)
94
+ if (this.options.ok && this.ui.ok) {
95
+ this.ui.ok.set('text', this.options.ok)
96
+ }
121
97
 
122
- // console.log('buildTitle', this.title)
98
+ if (this.options.target) {
99
+ this.setPosition()
100
+ }
123
101
  }
124
102
 
125
- buildLayout () {
126
- this.layout = new Layout(this.options.layout, this.surface)
127
- this.ui = this.layout.component
128
- }
103
+ setPosition () {
104
+ var coord = this.options.target.getBoundingClientRect()
105
+ var surface_coord = this.surface.getBoundingClientRect()
129
106
 
130
- buildHTML () {
131
- this.html = new Container({
132
- css: 'dialog-content'
133
- })
107
+ if (this.options.position === 'right') {
108
+ this.surface.style.top = coord.top + 'px'
109
+ this.surface.style.left = coord.left + coord.width // surface_coord.width + 'px'
110
+ } else {
111
+ this.surface.style.top = coord.top + 'px'
112
+ this.surface.style.left = coord.left - surface_coord.width + 'px'
113
+ }
134
114
  }
135
115
 
136
- buildContent () {
137
- // console.log('text content', this.options.content)
138
- this.content = new Text({
139
- type: 'content',
140
- css: 'dialog-content',
141
- text: this.options.content
142
- })
143
- this.insertElement(this.content.root, this.surface)
116
+ ok () {
117
+ this.emit('ok')
118
+ if (this.options.close) {
119
+ this.destroy()
120
+ }
144
121
  }
145
122
 
146
- buildActions () {
147
- if (this.options.actions) {
148
- this.actions = new Layout(this.options.actions, this.surface)
123
+ cancel () {
124
+ this.emit('cancel')
149
125
 
150
- css.add(this.actions.get('root'), 'dialog-actions')
151
- } else {
152
- var actions
153
- if (this.options.accept || this.options.cancel) {
154
- actions = new Toolbar({ css: 'dialog-actions' })
155
- this.insertElement(actions.root, this.surface)
156
- }
157
-
158
- if (this.options.cancel) {
159
- this.cancel = new Button(this.options.cancel)
160
- .on('click', () => {
161
- this.emit('canceled')
162
- this.close()
163
- })
164
- this.insertElement(this.cancel.root, actions.root)
165
- }
166
-
167
- if (this.options.accept) {
168
- this.accept = new Button(this.options.accept)
169
- .on('click', () => {
170
- this.emit('accepted')
171
- this.close()
172
- })
173
- this.insertElement(this.accept.root, actions.root)
174
- }
126
+ if (this.options.close) {
127
+ this.destroy()
175
128
  }
176
129
  }
177
130
 
178
131
  close () {
179
- css.add(this.element, 'dialog-closing')
180
-
181
- var delayMillis = 200 // 1 second
182
- setTimeout(() => {
183
- this.element.style.display = 'none'
184
- css.remove(this.element, 'dialog-closing')
185
- css.remove(this.element, 'dialog-show')
186
- }, delayMillis)
132
+ // this.hide()
187
133
 
188
- this.previousActive.focus()
189
-
190
- return this
134
+ if (this.options.close) {
135
+ this.destroy()
136
+ }
191
137
  }
192
138
 
193
- show () {
194
- this.previousActive = document.activeElement
195
-
196
- this.element.style.display = 'flex'
197
- // css.add(this.element, 'dialog-showing');
198
-
199
- var delayMillis = 100 // 1 second
200
-
201
- setTimeout(() => {
202
- css.add(this.element, 'dialog-show')
203
- // css.remove(this.element, 'dialog-showing');
204
- }, delayMillis)
139
+ onClick (e) {
140
+ e.stopPropagation()
141
+ }
205
142
 
206
- return this
143
+ onClickRoot (e) {
144
+ // console.log('onClickRoot')
145
+ e.stopPropagation()
146
+ if (!this.options.modal) {
147
+ this.destroy()
148
+ }
149
+ }
207
150
 
208
- // var button = this.element.querySelector('button')
151
+ emphase () {
152
+ this.element.classList.add('emphase')
153
+ var it
154
+ it = setTimeout(() => {
155
+ clearTimeout(it)
156
+ this.element.classList.remove('emphase')
157
+ }, 100)
158
+ }
209
159
 
210
- // if (button) button.focus()
160
+ set (prop, value) {
161
+ if (this.ui[prop]) {
162
+ this.ui[prop].set(value)
163
+ }
211
164
  }
212
165
  }
213
166
 
package/src/divider.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import create from './mixin/create'
4
2
  import insert from './mixin/insert'
5
3
 
package/src/drawer.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import init from './mixin/init'
4
2
  import insert from './element/insert'
5
3
  import classify from './module/classify'
@@ -1,56 +1,26 @@
1
- import emitter from '../module/emitter'
2
- import dataset from '../view/dataset'
3
- import attributes from './module/attributes'
1
+ import EventEmitter from './mixin/emitter'
4
2
 
5
- const defaults = {
6
- class: 'file',
7
- attributes: ['name', 'accept', 'required', 'disabled', 'multiple']
8
- }
3
+ import build from './module/build'
4
+ import dataset from './module/dataset'
5
+ import attributes from './module/attributes'
9
6
 
10
7
  class File {
11
- /**
12
- * Constructor
13
- * @param {Object} options - Component options
14
- * @return {Object} Class instance
15
- */
16
- constructor (options) {
17
- this.options = Object.assign({}, defaults, options || {})
18
- Object.assign(this, emitter)
19
-
20
- this.build()
21
- this.attach()
22
-
23
- return this
8
+ static defaults = {
9
+ class: 'file',
10
+ attributes: ['name', 'accept', 'required', 'disabled', 'multiple']
24
11
  }
25
12
 
26
- /**
27
- * Build Method
28
- * @return {Object} This class instance
29
- */
30
- build () {
31
- this.element = document.createElement('div')
32
- this.element.classList.add('file')
33
-
34
- if (this.options.class !== 'file') {
35
- this.element.classList.add(this.options.class)
36
- }
37
-
13
+ constructor (options) {
14
+ this.init(options)
15
+ this.build()
38
16
  this.buildLabel()
39
17
  this.buildInput()
18
+ this.attach()
19
+ }
40
20
 
41
- if (this.options.data) {
42
- dataset(this.element, this.options.data)
43
- }
44
-
45
- if (this.options.focus) {
46
- this.input.focus()
47
- }
48
-
49
- if (this.options.container) {
50
- this.options.container.appendChild(this.element)
51
- }
52
-
53
- return this
21
+ init (options) {
22
+ this.options = Object.assign({}, File.defaults, options || {})
23
+ Object.assign(this, build)
54
24
  }
55
25
 
56
26
  buildLabel () {
@@ -8,10 +8,10 @@ export default {
8
8
  var field = this.ui['info.' + list[i]]
9
9
 
10
10
  if (!this.layout.get(list[i]).get()) {
11
- field.root.classList.add('textfield-error')
11
+ field.element.classList.add('textfield-error')
12
12
  ok = false
13
13
  } else {
14
- field.root.classList.remove('textfield-error')
14
+ field.element.classList.remove('textfield-error')
15
15
  }
16
16
  }
17
17
 
package/src/form.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import insert from './element/insert'
4
2
  import css from './module/css'
5
3
  import emitter from './module/emitter'
package/src/icon.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import insert from './mixin/insert'
4
2
  import css from './module/css'
5
3
 
package/src/image.js CHANGED
@@ -1,124 +1,57 @@
1
- 'use strict'
1
+ import build from './module/build'
2
2
 
3
- // import insert from './mixin/insert'
4
- import css from './module/css'
5
- import insert from './element/insert'
6
- import control from './mixin/control'
7
-
8
- var defaults = {
9
- prefix: 'material',
10
- class: 'image',
11
- tag: 'div'
12
- }
13
-
14
- /**
15
- * The item class is used for example as item list
16
- *
17
- * @class
18
- * @extends {Component}
19
- * @return {Object} The class instance
20
- * @example new Item(object);
21
- */
22
3
  class Image {
23
- /**
24
- * init
25
- * @return {Object} The class options
26
- */
4
+ static defaults = {
5
+ class: 'image',
6
+ tag: 'div',
7
+ format: 'thumb'
8
+ }
9
+
27
10
  constructor (options) {
28
11
  this.init(options)
29
12
  this.build()
30
-
31
- return this
32
13
  }
33
14
 
34
- /**
35
- * [init description]
36
- * @param {?} options [description]
37
- * @return {?} [description]
38
- */
39
15
  init (options) {
40
- this.options = Object.assign({}, defaults, options || {})
41
- Object.assign(this, control)
16
+ this.options = Object.assign({}, Image.defaults, options || {})
17
+ Object.assign(this, build)
42
18
  }
43
19
 
44
- /**
45
- * Build function for item
46
- * @return {Object} This class instance
47
- */
48
- build (options) {
49
- options = options || this.options
50
-
51
- var tag = options.tag || 'div'
52
- var text = options.text || options.label
53
- this.element = document.createElement(tag)
54
-
55
- // if (options.src) {
56
- // this.element.setAttribute('style', 'background-image: url(' + options.src + ')')
57
-
58
- if (options.src) {
59
- this.image = document.createElement('img')
60
- this.image.setAttribute('src', options.src)
61
- css.add(this.image, this.options.class + '-image')
62
- insert(this.image, this.element)
63
- }
64
-
65
- this.info = document.createElement('span')
66
- css.add(this.info, this.options.class + '-info')
67
-
68
- insert(this.info, this.element)
69
-
70
- this.label(text, this.info)
71
-
72
- // this.label = this.element.label
73
-
74
- this.icon(this.options.icon, this.info, 'bottom')
75
-
76
- // if (text) {
77
- // this.label = document.createElement('span')
78
- // this.label.innerText = text
79
- // css.add(this.label, this.options.class + '-label')
80
- // insert(this.label, this.element)
81
- // }
82
-
83
- css.add(this.element, this.options.prefix + '-' + this.options.class)
84
-
85
- if (options.css) { css.add(this.element, options.css) }
86
- // css.add(this.element, this.options.class + '-adjust');
87
-
88
- if (this.options.container) {
89
- this.insert(this.options.container)
90
- }
91
- }
92
-
93
- /**
94
- * [insert description]
95
- * @param {?} container [description]
96
- * @param {?} context [description]
97
- * @return {?} [description]
98
- */
99
- insert (container, context) {
100
- insert(this.element, container, context)
101
-
102
- return this
103
- }
104
-
105
- /**
106
- * Get or set text value of the element
107
- * @param {string} value The text to set
108
- * @returns {*}
109
- */
110
- set (value) {
111
- if (value) {
112
- if (this.element.innerText) {
113
- this.element.innerText = value
20
+ set (src) {
21
+ // console.log('set', src)
22
+ if (!src) {
23
+ this.element.style.backgroundImage = ''
24
+ } else {
25
+ var url = null
26
+
27
+ if (src.format) {
28
+ var format = this.sanitize(src.format)
29
+
30
+ if (format.length > 0) {
31
+ var index = format.indexOf(this.options.format)
32
+ if (index === -1) {
33
+ format = src.format[0] + '/'
34
+ } else {
35
+ format = this.options.format + '/'
36
+ }
37
+ }
38
+
39
+ url = src.url + format
114
40
  } else {
115
- this.element.textContent = value
41
+ url = src.url
116
42
  }
117
43
 
118
- return this
44
+ this.element.style.backgroundImage = 'url(' + url + src.filename + ')'
119
45
  }
46
+ }
120
47
 
121
- return this
48
+ sanitize (formats) {
49
+ var a = []
50
+ for (var i = 0; i < formats.length; i++) {
51
+ var format = formats[i].replace(/\/$/, '')
52
+ a.push(format)
53
+ }
54
+ return a
122
55
  }
123
56
  }
124
57
 
package/src/item.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import Layout from './layout'
4
2
 
5
3
  import create from './mixin/create'
@@ -1,36 +1,23 @@
1
- 'use strict'
2
-
3
- const defaults = {
4
- class: 'link',
5
- tag: 'a'
6
- }
1
+ import build from './module/build'
7
2
 
8
3
  class Link {
9
- /**
10
- * Constructor
11
- * @param {Object} options - Component options
12
- * @return {Object} Class instance
13
- */
14
- constructor (options) {
15
- this.options = Object.assign({}, defaults, options || {})
4
+ static defaults = {
5
+ class: 'link',
6
+ tag: 'a'
7
+ }
16
8
 
9
+ constructor (options) {
10
+ this.init(options)
17
11
  this.build()
18
-
19
- return this
12
+ this.setup()
20
13
  }
21
14
 
22
- /**
23
- * Build Method
24
- * @return {Object} This class instance
25
- */
26
- build () {
27
- this.element = document.createElement(this.options.tag)
28
- this.element.classList.add(this.options.class)
29
-
30
- if (this.options.class !== 'link') {
31
- this.element.classList.add('link')
32
- }
15
+ init (options) {
16
+ this.options = Object.assign({}, Link.defaults, options || {})
17
+ Object.assign(this, build)
18
+ }
33
19
 
20
+ setup () {
34
21
  if (this.options.link) {
35
22
  this.set(this.options.link)
36
23
  }
@@ -39,15 +26,9 @@ class Link {
39
26
  this.element.target = this.options.target
40
27
  }
41
28
 
42
- if (this.options.container) {
43
- this.options.container.appendChild(this.element)
44
- }
45
-
46
29
  if (this.options.text) {
47
30
  this.element.innerHTML = this.options.text
48
31
  }
49
-
50
- return this
51
32
  }
52
33
 
53
34
  set (link) {
package/src/list/build.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import scrollbar from '../module/scrollbar'
2
- import dataset from '../view/dataset'
2
+ import dataset from '../module/dataset'
3
3
 
4
4
  import Layout from '../layout'
5
5
  import Virtual from './virtual'
6
- import Loading from '../control/loading'
6
+ import Loading from '../loading'
7
7
 
8
8
  export default {
9
9
  build (data) {