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
@@ -150,7 +150,7 @@ class Collection {
150
150
  route = this.addParams(route, this.params())
151
151
  }
152
152
 
153
- if (this.ui.filter && this.ui.filter.root.classList.contains('selected')) {
153
+ if (this.ui.filter && this.ui.filter.element.classList.contains('selected')) {
154
154
  route = this.addParams(route, this.getFilter())
155
155
  }
156
156
 
@@ -61,7 +61,7 @@ export default {
61
61
  }
62
62
 
63
63
  // console.log('showSearch')
64
- this.ui['filter'].root.classList.add('selected')
64
+ this.ui['filter'].element.classList.add('selected')
65
65
  this.ui['filter-input'].classList.add('show')
66
66
 
67
67
  // this.ui['search-list'].classList.add('show')
@@ -74,7 +74,7 @@ export default {
74
74
  */
75
75
  hideFilter () {
76
76
  // console.log('hideSearch')
77
- this.ui['filter'].root.classList.remove('selected')
77
+ this.ui['filter'].element.classList.remove('selected')
78
78
  this.ui['filter-input'].classList.remove('show')
79
79
  // this.ui['search-list'].classList.remove('show')
80
80
  // this.ui.body.classList.remove('hide')
@@ -154,7 +154,7 @@ export default {
154
154
 
155
155
  }
156
156
 
157
- if (this.ui.filter && this.ui.filter.root.classList.contains('selected')) {
157
+ if (this.ui.filter && this.ui.filter.element.classList.contains('selected')) {
158
158
  route = this.addParams(route, this.getFilter())
159
159
  }
160
160
 
@@ -93,7 +93,7 @@ export default {
93
93
  toggleSearch (e) {
94
94
  e.stopPropagation()
95
95
  // console.log('toggle search', this.ui.body)
96
- if (!this.ui['search-input'].root.classList.contains('show')) {
96
+ if (!this.ui['search-input'].element.classList.contains('show')) {
97
97
  this.showSearch()
98
98
  } else {
99
99
  this.hideSearch()
@@ -114,12 +114,12 @@ export default {
114
114
  this.element.classList.add('search-mode')
115
115
 
116
116
  if (this.ui.search) {
117
- this.ui.search.root.classList.add('selected')
117
+ this.ui.search.element.classList.add('selected')
118
118
  }
119
119
 
120
120
  if (this.ui['search-input']) {
121
121
  this.ui['search-input'].input.value = ''
122
- this.ui['search-input'].root.classList.add('show')
122
+ this.ui['search-input'].element.classList.add('show')
123
123
  this.ui['search-input'].input.focus()
124
124
  }
125
125
 
@@ -139,10 +139,10 @@ export default {
139
139
  this.element.classList.remove('search-mode')
140
140
 
141
141
  if (this.ui.search) {
142
- this.ui.search.root.classList.remove('selected')
142
+ this.ui.search.element.classList.remove('selected')
143
143
  }
144
144
  if (this.ui['search-input']) {
145
- this.ui['search-input'].root.classList.remove('show')
145
+ this.ui['search-input'].element.classList.remove('show')
146
146
  this.ui['search-input'].input.value = ''
147
147
  }
148
148
  // this.ui['search-list'].classList.remove('show')
package/src/list.js CHANGED
@@ -1,255 +1,67 @@
1
- 'use strict'
2
-
3
- import Item from './item'
4
- import Divider from './divider'
5
-
6
- // import init from './mixin/init'
7
- import emitter from './module/emitter'
8
- import insert from './element/insert'
9
- import css from './module/css'
10
- import attach from './module/attach'
1
+ import addClass from './module/addclass'
11
2
 
12
3
  const defaults = {
13
- prefix: 'material',
14
- class: 'list',
15
- tag: 'ul',
16
- functions: ['render', 'select'],
17
- target: 'LI',
18
- events: [
19
- ['root.click', 'handleSelect']
20
- ]
4
+ className: 'text',
5
+ tag: 'span',
6
+ seprator: ' | '
21
7
  }
22
8
 
23
- /**
24
- * List view class
25
- * @class
26
- * @param {Object} options Default options for view
27
- * @extends {View}
28
- * @since 0.0.4
29
- * @author Jerome Vial
30
- *
31
- * @type {prime}
32
- */
33
9
  class List {
34
- /**
35
- * init
36
- * @return {Object} The class options
37
- */
38
10
  constructor (options) {
39
11
  this.options = Object.assign({}, defaults, options || {})
40
12
 
41
- this.init(this.options)
42
- this.build(this.options)
43
- this.attach(this.options.events)
44
-
45
- return this
46
- }
47
-
48
- /**
49
- * [_initView description]
50
- * @return Class instance
51
- */
52
- init () {
53
- this.filters = []
54
- this.data = []
55
- this.items = []
56
-
57
- // assign modules
58
- Object.assign(this, emitter, attach)
13
+ // console.log('options', this.options)
59
14
 
60
- // init function
61
- this._initFunction(this.options.functions)
15
+ this.build()
62
16
 
63
17
  return this
64
18
  }
65
19
 
66
- /**
67
- * [_initFunction description]
68
- * @param {?} functions [description]
69
- * @return {?} [description]
70
- */
71
- _initFunction (functions) {
72
- for (var i = 0; i < functions.length; i++) {
73
- var name = functions[i]
74
- if (this.options[name]) {
75
- this[name] = this.options[name]
76
- }
77
- }
78
- }
20
+ build () {
21
+ this.root = document.createElement(this.options.tag)
22
+ addClass(this.root, this.options.class)
79
23
 
80
- /**
81
- * [_initList description]
82
- * @param {Object} options this class options
83
- * @return {Object} The class instance
84
- */
85
- build (options) {
86
- // define main tag
87
- var tag = this.options.tag || 'ul'
88
-
89
- this.element = document.createElement(tag)
90
- css.add(this.element, 'material-' + this.options.class)
91
-
92
- if (options.name) {
93
- css.add(this.element, options.class + '-' + options.name)
94
- }
95
-
96
- if (options.type) {
97
- css.add(this.element, 'type-' + options.type)
98
- }
99
-
100
- if (options.layout) {
101
- css.add(this.element, 'layout-' + options.layout)
24
+ if (this.options.class !== 'text') {
25
+ this.root.classList.add('text')
102
26
  }
103
27
 
104
28
  if (this.options.list) {
105
- this.set('list', this.options.list)
29
+ this.set(this.options.list)
106
30
  }
107
31
 
108
32
  if (this.options.container) {
109
- insert(this.element, this.options.container)
33
+ this.options.container.appendChild(this.root)
110
34
  }
111
35
 
112
- // this.element.addEventListener("click", function(e) {
113
- // // console.log("list", this, e);
114
- // // e.target was the clicked element
115
- // });
116
-
117
36
  return this
118
37
  }
119
38
 
120
- /**
121
- * [onSelect description]
122
- * @param {?} e [description]
123
- * @return {?} [description]
124
- */
125
- handleSelect (e) {
126
- // console.log('handleSelect-', e.currentTarget, this.options.target)
127
- e.stopPropagation()
128
-
129
- if (e.target === e.currentTarget) {
130
- return
131
- }
132
-
133
- if (e && e.target) {
134
- var el = e.target
135
- // console.log('el', el, el.matches(this.options.target))
136
- while (el && !el.matches(this.options.target)) {
137
- el = el.parentNode
138
- }
139
-
140
- css.remove(this.item, 'is-selected')
141
- css.add(el, 'is-selected')
142
-
143
- this.select(el, e, this.item)
144
- this.item = el
145
- }
146
- }
147
-
148
- /**
149
- * select
150
- * @param {Element} item [description]
151
- * @param {event} event The caller event
152
- * @return [description]
153
- */
154
- select (item, e, selected) {
155
- this.emit('select', item)
156
- }
157
-
158
- /**
159
- * [render description]
160
- * @param {?} info [description]
161
- * @return {?} [description]
162
- */
163
- render (info) {
164
- var item
165
-
166
- if (info.type === 'divider') {
167
- item = new Divider()
168
- } else {
169
- item = new Item({
170
- name: info.name,
171
- text: info.text || info.name
172
- })
173
- }
174
-
175
- return item
176
- }
39
+ set (list) {
40
+ var text = ''
177
41
 
178
- /**
179
- * Setter
180
- * @param {string} prop
181
- * @param {string} value
182
- */
183
- set (prop, value, options) {
184
- // console.log('set', prop, value)
185
- switch (prop) {
186
- case 'list':
187
- this.setList(value, options)
188
- break
189
- default:
190
- this.setList(prop, options)
191
- }
192
-
193
- return this
194
- }
195
-
196
- /**
197
- * Set list
198
- * @param {Array} list List of info object
199
- * @return {Object} The class instance
200
- */
201
- setList (list) {
202
42
  for (var i = 0; i < list.length; i++) {
203
- this.addItem(this.render(list[i]), i)
43
+ if (i < list.length - 1) {
44
+ text = text + list[i] + this.options.seprator
45
+ } else {
46
+ text = text + list[i]
47
+ }
204
48
  }
205
49
 
206
- return this
207
- }
50
+ // console.log('set', text)
51
+ if (text === undefined) return
208
52
 
209
- scrollToBottom () {
210
- this.element.scrollTop = this.element.scrollHeight - this.element.getBoundingClientRect().height
211
- }
53
+ var label = this.options.label || ''
212
54
 
213
- /**
214
- * [add description]
215
- * @param {Object} item [description]
216
- */
217
- addItem (item /*, index */) {
218
- if (!item) {
219
- return
220
- }
55
+ this.root.innerHTML = label + text
221
56
 
222
- var where = 'bottom'
223
- if (item.root) {
224
- insert(item.root, this.element, where)
225
- } else {
226
- insert(item, this.element, where)
57
+ if (this.options.spaceAfter) {
58
+ this.root.innerHTML = this.root.innerHTML + ' '
227
59
  }
228
-
229
- this.items.push(item)
230
-
231
- return item
232
60
  }
233
61
 
234
- insert (container, context) {
235
- insert(this.element, container, context)
236
- }
237
-
238
- empty () {
239
- this.element.innerHTML = ''
240
- this.items = []
241
- this.item = null
242
- }
243
-
244
- /**
245
- * Reverse the list order
246
- * @return {Object} The class instance
247
- */
248
- reverse () {
249
- this.list.reverse()
250
- this.update(this.list)
251
-
252
- return this
62
+ setText (text) {
63
+ // console.log('setText', text)
64
+ this.root.innerHTML = text
253
65
  }
254
66
  }
255
67
 
package/src/loading.js ADDED
@@ -0,0 +1,73 @@
1
+ import build from './module/build'
2
+
3
+ class Loading {
4
+ static isComponent () {
5
+ return true
6
+ }
7
+
8
+ static defaults = {
9
+ class: 'loading',
10
+ tag: 'div',
11
+ delay: 1000,
12
+ type: 'indeterminate',
13
+ circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
14
+ <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
15
+ </svg>`
16
+ }
17
+
18
+ constructor (options) {
19
+ this.init(options)
20
+ this.build()
21
+ this.buildLoading()
22
+ }
23
+
24
+ init (options) {
25
+ this.options = Object.assign({}, Loading.defaults, options || {})
26
+ Object.assign(this, build)
27
+ }
28
+
29
+ buildLoading (options) {
30
+ if (this.options.type === 'circular') {
31
+ this.element.innerHTML = this.options.circular
32
+ } if (this.options.type === 'indeterminate') {
33
+ this.bar = document.createElement(this.options.tag)
34
+ this.bar.classList.add('bar')
35
+ this.element.classList.add('type-indeterminate')
36
+ this.element.appendChild(this.bar)
37
+ }
38
+ }
39
+
40
+ set (progress) {
41
+ this.bar.setAttribute('style', 'width: ' + progress)
42
+ }
43
+
44
+ show (delay) {
45
+ delay = delay || this.options.delay
46
+
47
+ clearTimeout(this.showTimeout)
48
+ this.showTimeout = setTimeout(() => {
49
+ this.element.classList.add('show')
50
+ }, this.options.delay)
51
+
52
+ this.visible = true
53
+
54
+ return this
55
+ }
56
+
57
+ showNow () {
58
+ this.element.classList.add('show')
59
+
60
+ this.visible
61
+
62
+ return this
63
+ }
64
+
65
+ hide () {
66
+ clearTimeout(this.showTimeout)
67
+ this.element.classList.remove('show')
68
+ this.visible = false
69
+ return this
70
+ }
71
+ }
72
+
73
+ export default Loading
package/src/menu.js CHANGED
@@ -1,140 +1,84 @@
1
- 'use strict'
1
+ import EventEmitter from './mixin/emitter'
2
+ // menu related modules
3
+ import build from './module/build'
4
+ import bindEvents from './module/events'
5
+ import display from './mixin/display'
6
+
7
+ import Element from './element'
8
+ import Button from './button'
9
+
10
+ class Menu extends EventEmitter {
11
+ static defaults = {
12
+ class: 'menu',
13
+ transition: 200,
14
+ modal: false,
15
+ layout: [
16
+ [Element, 'surface', { class: 'surface' },
17
+ [Element, 'list', { tag: 'ul', class: 'items' }]
18
+ ]
19
+ ],
20
+ events: [
21
+ ['element.click', 'close']
22
+ ]
23
+ };
2
24
 
3
- import classify from './module/classify'
4
- import css from './module/css'
5
- import events from './mixin/events'
6
- import insert from './element/insert'
7
- import offset from './element/offset'
8
-
9
- import create from './element/create'
10
-
11
- import attach from './module/attach'
12
- import emitter from './module/emitter'
13
-
14
- import List from './list'
15
- import Item from './item'
16
- import Divider from './divider'
17
-
18
- const defaults = {
19
- prefix: 'material',
20
- class: 'menu',
21
- tag: 'div',
22
- events: [
23
- ['root.click', 'hide'],
24
- ['mask.click', 'hide']
25
- ]
26
- }
27
-
28
- /**
29
- * This Class represents a menu.
30
- *
31
- * @return {parent} The class instance
32
- * @example new Container({
33
- * container: document.body
34
- * });
35
- */
36
- class Menu {
37
- /**
38
- * Constructor
39
- * @param {Object} options - Component options
40
- * @return {Object} Class instance
41
- */
42
25
  constructor (options) {
26
+ super()
27
+
43
28
  this.init(options)
44
- this.build()
45
- this.setup()
29
+ this.build(this.constructor)
30
+ this.bindEvents()
46
31
 
47
- this.attach()
48
-
49
- this.emit('ready')
50
-
51
- return this
32
+ this.render(this.options.items)
52
33
  }
53
34
 
54
- /**
55
- * [init description]
56
- * @return {[type]} [description]
57
- */
58
- init (options) {
59
- this.options = Object.assign({}, defaults, options || {})
60
-
61
- Object.assign(this, emitter, events, attach, insert)
35
+ init(options) {
36
+ this.options = Object.assign({}, Menu.defaults, options || {})
37
+ Object.assign(this, build, bindEvents, display)
62
38
  }
63
39
 
64
- /**
65
- * Build Method
66
- * @return {Object} This class instance
67
- */
68
- build () {
69
- this.element = create(this.options.tag, this.options.css)
70
- this.mask = create(this.options.tag, this.options.class + '-mask')
71
-
72
- if (this.options.position) {
73
- this.element.style.position = this.options.position
40
+ render (items) {
41
+ if (items && Array.isArray(items)) {
42
+ for (var i = 0; i < items.length; i++) {
43
+ this.add(items[i])
44
+ }
74
45
  }
75
46
 
76
- classify(this.element, this.options)
77
-
78
- if (this.options.list) {
79
- this.list = new List({
80
- // root: this.element,
81
- list: this.options.list,
82
- target: '.material-item',
83
- height: 600,
84
- label: 'Flat',
85
- select: (item) => {
86
- this.selected = item
87
- this.hide()
88
- }
89
- }).insert(this.element)
90
- }
91
-
92
- this.emit('built', this.element)
93
-
94
47
  return this
95
48
  }
96
49
 
97
- insert () {
98
- insert(this.mask, document.body)
99
- insert(this.element, document.body)
100
- }
101
-
102
- setup () {
103
- // this.subscribe('click', () => {
104
- // console.log('click');
105
- // this.close();
106
- // });
107
- //
108
- window.addEventListener('resize', () => this.position())
109
- }
110
-
111
- show (e) {
112
- css.add(this.mask, 'mask-show')
113
-
114
- if (e) this.caller = e.target
50
+ add (obj) {
51
+ if (typeof obj !== 'object') return this;
52
+ let item;
53
+ if (obj.type === 'divider') {
54
+ item = new Element({ tag: 'li', class: 'divider' })
55
+ } else {
56
+ obj.container = this.ui.list
57
+ obj.class = 'item'
58
+ item = new Button(obj).on('click', (ev) => {
59
+ // console.log('select', ev.target.name)
60
+ this.emit('select', ev.target.name)
61
+ })
62
+ }
115
63
 
116
- css.add(this.element, this.options.class + '-show')
117
- this.position(this.caller)
64
+ return this
118
65
  }
119
66
 
120
- position () {
121
- if (!this.caller) return
122
- var offs = offset(this.caller)
67
+ position(target) {
68
+ if (!target) return
69
+ var offs = target.getBoundingClientRect()
123
70
 
124
- var offsw = this.offset = offset(this.element)
71
+ var offsw = this.offset = this.ui.surface.getBoundingClientRect()
125
72
 
126
- // console.log('offset')
127
- // console.log('caller', this.caller, offs, screen.width)
73
+ this.ui.surface.style.top = (offs.top - 4) + 'px'
74
+ this.ui.surface.style.left = offs.left - offsw.width + offs.width + 'px'
128
75
 
129
- this.element.style.top = offs.top + 'px'
130
- this.element.style.left = offs.left - offsw.width + offs.width + 'px'
131
- // this.element.style.right = offs.right + offs.width + offsw.width + 'px'
76
+ return this
132
77
  }
133
78
 
134
- hide () {
135
- // console.log('hide')
136
- css.remove(this.element, this.options.class + '-show')
137
- css.remove(this.mask, 'mask-show')
79
+ close() {
80
+ // console.log('close')
81
+ this.destroy()
138
82
  }
139
83
  }
140
84
 
@@ -70,7 +70,6 @@ export default {
70
70
  dom.destroy(this.element)
71
71
  }
72
72
 
73
-
74
73
  this.emit?.('destroy')
75
74
  }
76
75
  }
@@ -2,21 +2,8 @@
2
2
 
3
3
  import dom from '../module/dom'
4
4
 
5
- /**
6
- * Inject method insert element to the domtree using Dom methods
7
- * @param {HTMLElement} container [description]
8
- * @param {string} context - Injection context
9
- * @return {Object} This class intance
10
- */
11
5
  export default {
12
6
 
13
- /**
14
- * [insert description]
15
- * @param {?} container [description]
16
- * @param {?} context [description]
17
- * @param {?} debug [description]
18
- * @return {?} [description]
19
- */
20
7
  insert (container, context) {
21
8
  var element = this.element
22
9
 
@@ -25,18 +12,9 @@ export default {
25
12
  return this
26
13
  },
27
14
 
28
- /**
29
- * [insertElement description]
30
-
31
- * @param {?} element [description]
32
- * @param {?} container [description]
33
- * @param {?} context [description]
34
- * @param {?} debug [description]
35
- * @return {?} [description]
36
- */
37
15
  insertElement (element, container, context) {
38
- if (container && container.root) {
39
- container = container.root
16
+ if (container && container.element) {
17
+ container = container.element
40
18
  }
41
19
 
42
20
  this.container = container