material 0.7.1 → 0.7.4

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 (155) hide show
  1. package/LICENSE +9 -18
  2. package/README.md +1 -5
  3. package/index.js +25 -48
  4. package/package.json +3 -24
  5. package/src/badge.js +1 -1
  6. package/src/button.js +50 -100
  7. package/src/calendar.js +53 -53
  8. package/src/card.js +1 -1
  9. package/src/checkbox.js +52 -104
  10. package/src/datehour.js +7 -7
  11. package/src/dialog.js +5 -5
  12. package/src/divider.js +1 -1
  13. package/src/drawer.js +1 -17
  14. package/src/element/attribute.js +7 -10
  15. package/src/element/build.js +6 -7
  16. package/src/element/create.js +3 -6
  17. package/src/element/event.js +2 -2
  18. package/src/element/insert.js +9 -20
  19. package/src/element/observer.js +22 -0
  20. package/src/element/offset.js +2 -2
  21. package/src/element/style.js +12 -12
  22. package/src/element.js +2 -2
  23. package/src/file.js +1 -1
  24. package/src/form/build.js +7 -7
  25. package/src/form/controller.js +8 -8
  26. package/src/form/create.js +1 -1
  27. package/src/form/data.js +9 -9
  28. package/src/form/delete.js +1 -1
  29. package/src/form/render.js +9 -9
  30. package/src/form/set.js +1 -1
  31. package/src/form/submit.js +6 -6
  32. package/src/form/update.js +3 -3
  33. package/src/form/verify.js +4 -4
  34. package/src/form.js +9 -9
  35. package/src/icon.js +4 -4
  36. package/src/image.js +7 -7
  37. package/src/item.js +1 -1
  38. package/src/layout.js +14 -14
  39. package/src/link.js +1 -1
  40. package/src/list/build.js +8 -8
  41. package/src/list/click.js +3 -3
  42. package/src/list/filter.js +11 -11
  43. package/src/list/image.js +3 -3
  44. package/src/list/render.js +15 -15
  45. package/src/list/request.js +7 -7
  46. package/src/list/search.js +9 -9
  47. package/src/list/select.js +18 -18
  48. package/src/list/status.js +1 -1
  49. package/src/list/update.js +6 -6
  50. package/src/list/virtual.js +20 -20
  51. package/src/list/virtual.new.js +5 -5
  52. package/src/list.js +8 -10
  53. package/src/map/build.js +2 -2
  54. package/src/map/countries.js +8 -8
  55. package/src/map/display.js +13 -13
  56. package/src/map/focus.js +7 -7
  57. package/src/map/select.js +2 -2
  58. package/src/map/set.js +3 -3
  59. package/src/map/viewport.js +11 -11
  60. package/src/menu.js +12 -12
  61. package/src/mixin/control.js +3 -3
  62. package/src/mixin/controller.js +5 -5
  63. package/src/mixin/create.js +1 -1
  64. package/src/mixin/display.js +1 -1
  65. package/src/mixin/events.js +4 -16
  66. package/src/mixin/focus.js +1 -1
  67. package/src/mixin/icon.js +2 -2
  68. package/src/mixin/init.js +2 -2
  69. package/src/mixin/insert.js +5 -5
  70. package/src/mixin/label.js +2 -2
  71. package/src/mixin/settings.js +5 -5
  72. package/src/module/attach.js +35 -49
  73. package/src/module/attributes.js +2 -2
  74. package/src/module/build.js +6 -11
  75. package/src/module/classify.js +4 -4
  76. package/src/module/controller.js +5 -32
  77. package/src/module/css.js +12 -84
  78. package/src/module/dataset.js +1 -1
  79. package/src/module/dom.js +9 -3
  80. package/src/module/dot.js +4 -4
  81. package/src/module/emitter.js +1 -1
  82. package/src/module/event.js +2 -2
  83. package/src/module/events.js +29 -35
  84. package/src/module/extract.js +10 -10
  85. package/src/module/last.js +18 -0
  86. package/src/module/mediator.js +1 -13
  87. package/src/module/object.js +4 -4
  88. package/src/module/observer.js +43 -16
  89. package/src/module/remove.js +10 -10
  90. package/src/module/request.js +33 -0
  91. package/src/module/ripple.js +19 -24
  92. package/src/module/scrollbar.js +10 -14
  93. package/src/module/smoothscroll.js +5 -9
  94. package/src/module/utils.js +14 -23
  95. package/src/module/viewport.js +5 -5
  96. package/src/navigation.js +7 -1
  97. package/src/progress.js +1 -9
  98. package/src/search.js +24 -29
  99. package/src/select.js +6 -6
  100. package/src/selecter.js +39 -39
  101. package/src/selector.js +3 -3
  102. package/src/skin/material/button/action.sass +6 -6
  103. package/src/skin/material/button/button.sass +6 -6
  104. package/src/skin/material/button/file.sass +1 -1
  105. package/src/skin/material/button/floating.sass +5 -5
  106. package/src/skin/material/button/raised.sass +5 -5
  107. package/src/skin/material/button/stroked.sass +5 -5
  108. package/src/skin/material/component/navigation.sass +13 -1
  109. package/src/skin/material/control/checkbox.sass +21 -21
  110. package/src/skin/material/module/ripple.sass +1 -1
  111. package/src/slider.js +1 -1
  112. package/src/snackbar.js +12 -9
  113. package/src/styles/M3/abstracts/variables.sass +44 -0
  114. package/src/styles/M3/components/button.sass +26 -0
  115. package/src/styles/M3/modules/ripple.sass +9 -0
  116. package/src/styles/M3/themes/classic.sass +2 -0
  117. package/src/switch.js +1 -1
  118. package/src/switcher.js +15 -15
  119. package/src/tabs.js +6 -8
  120. package/src/tabview.js +26 -46
  121. package/src/text.js +1 -1
  122. package/src/textfield.js +1 -1
  123. package/src/toolbar.js +12 -12
  124. package/src/tooltip.js +7 -7
  125. package/src/tree.js +10 -66
  126. package/src/view/build.js +2 -2
  127. package/src/view/dataset.js +1 -1
  128. package/src/view.js +9 -74
  129. package/dist/demo-bundle.js +0 -2
  130. package/dist/demo-bundle.js.map +0 -1
  131. package/dist/demo.css +0 -93
  132. package/dist/demo.css.map +0 -7
  133. package/dist/demo.html +0 -24
  134. package/dist/demo.js +0 -159
  135. package/dist/icon/accessibility.svg +0 -5
  136. package/dist/icon/apps.svg +0 -5
  137. package/dist/icon/happy.svg +0 -6
  138. package/dist/icon/link.svg +0 -5
  139. package/dist/icon/more.svg +0 -5
  140. package/dist/icon/navi.svg +0 -5
  141. package/dist/icon/phone.svg +0 -6
  142. package/dist/icon/share.svg +0 -6
  143. package/dist/icon/side.svg +0 -5
  144. package/dist/icon/star.svg +0 -7
  145. package/dist/icon/star_border.svg +0 -6
  146. package/dist/material.css +0 -2429
  147. package/dist/material.css.map +0 -7
  148. package/dist/styles/demo.sass +0 -110
  149. package/dist/styles.css +0 -23
  150. package/rollup.config.js +0 -34
  151. package/src/container.js +0 -66
  152. package/src/element/ripple.js +0 -90
  153. package/src/field/email.js +0 -59
  154. package/src/field/image.js +0 -93
  155. package/src/module/addclass.js +0 -16
@@ -13,14 +13,14 @@ function e (instance, ev) {
13
13
  }
14
14
  }
15
15
 
16
- var iteration
17
- var obj = {}
18
- var element
16
+ let iteration
17
+ const obj = {}
18
+ let element
19
19
 
20
- var keys = ev.split('.')
20
+ const keys = ev.split('.')
21
21
 
22
- for (var i = 0, l = keys.length; i <= l; i++) {
23
- var key = keys[i]
22
+ for (let i = 0, l = keys.length; i <= l; i++) {
23
+ const key = keys[i]
24
24
  iteration = iteration || instance
25
25
  iteration = iteration[key]
26
26
 
@@ -45,11 +45,11 @@ function f (instance, func) {
45
45
  if (typeof func === 'function') {
46
46
  return func
47
47
  } else if (!func.match(/\./)) return instance[func]
48
- var iteration
48
+ let iteration
49
49
 
50
- var keys = func.split('.')
51
- for (var i = 0, l = keys.length; i < l; i++) {
52
- var key = keys[i]
50
+ const keys = func.split('.')
51
+ for (let i = 0, l = keys.length; i < l; i++) {
52
+ const key = keys[i]
53
53
 
54
54
  iteration = iteration || instance
55
55
  iteration = iteration[key]
@@ -0,0 +1,18 @@
1
+ export default {
2
+ (str) => {
3
+ // console.log('_path', str)
4
+ if (!str) return this
5
+ else if (!str.match(/\./)) return this[str]
6
+ var last
7
+
8
+ var keys = str.split('.')
9
+ for (var i = 0, l = keys.length; i < l; i++) {
10
+ var key = keys[i]
11
+
12
+ last = last || this
13
+ last = last[key]
14
+ }
15
+
16
+ return last
17
+ }
18
+ }
@@ -1,10 +1,4 @@
1
1
  const mediator = ((() => {
2
- /**
3
- * @description Subscribe to an event, supply a callback to be executed when that event is broadcast
4
- * @param store {string}
5
- * @param fn {function}
6
- * @returns {subscribe} {object}
7
- */
8
2
  const subscribe = function (store, fn) {
9
3
  if (!mediator.stores[store]) {
10
4
  mediator.stores[store] = []
@@ -18,19 +12,13 @@ const mediator = ((() => {
18
12
  return this
19
13
  }
20
14
 
21
- /**
22
- * @description Publish/broadcast an event to the rest of the application
23
- * @param store {string}
24
- * @param args {object}
25
- * @returns {*||boolean}
26
- */
27
15
  const publish = function (store, ...args) {
28
16
  // console.log('publish', store, args)
29
17
  if (!mediator.stores[store]) {
30
18
  return false
31
19
  }
32
20
 
33
- for (let value of mediator.stores[store]) {
21
+ for (const value of mediator.stores[store]) {
34
22
  const subscription = value
35
23
  subscription.callback.apply(subscription.context, args)
36
24
  }
@@ -7,10 +7,10 @@ function is (object) {
7
7
 
8
8
  function byString (o, s) {
9
9
  s = s.replace(/\[(\w+)\]/g, '.$1') // convert indexes to properties
10
- s = s.replace(/^\./, '') // strip a leading dot
11
- var a = s.split('.')
12
- for (var i = 0, n = a.length; i < n; ++i) {
13
- var k = a[i]
10
+ s = s.replace(/^\./, '') // strip a leading dot
11
+ const a = s.split('.')
12
+ for (let i = 0, n = a.length; i < n; ++i) {
13
+ const k = a[i]
14
14
  if (k in o) {
15
15
  o = o[k]
16
16
  } else {
@@ -1,23 +1,50 @@
1
+ const observer = (() => {
2
+ const watch = function (event, fn, context = this) {
3
+ if (typeof event !== 'string' || typeof fn !== 'function') {
4
+ throw new Error('Invalid arguments. Event must be a string and callback must be a function.')
5
+ }
1
6
 
2
- const observer = {
3
- insert: (element, cb) => {
4
- var observer = new MutationObserver((mutations) => {
5
- if (document.contains(element)) {
6
- if (typeof cb === 'function' && !element.classList.contains('inserted')) {
7
- cb()
8
- }
7
+ if (!observer.events[event]) {
8
+ observer.events[event] = []
9
+ }
9
10
 
10
- observer.disconnect()
11
- }
11
+ observer.events[event].push({
12
+ context,
13
+ callback: fn
12
14
  })
13
15
 
14
- observer.observe(document, {
15
- attributes: false,
16
- childList: true,
17
- characterData: false,
18
- subtree: true
19
- })
16
+ return this
17
+ }
18
+
19
+ const unwatch = function (event, fn) {
20
+ if (!observer.events[event]) return this
21
+
22
+ observer.events[event] = observer.events[event].filter(subscriber => subscriber.callback !== fn)
23
+
24
+ return this
25
+ }
26
+
27
+ const notify = function (event, ...args) {
28
+ if (!observer.events[event]) return this
29
+
30
+ for (const { context, callback } of observer.events[event]) {
31
+ callback.apply(context, args)
32
+ }
33
+
34
+ return this
35
+ }
36
+
37
+ return {
38
+ events: {},
39
+ watch,
40
+ unwatch,
41
+ notify,
42
+ init: function (obj) {
43
+ obj.watch = watch
44
+ obj.unwatch = unwatch
45
+ obj.notify = notify
46
+ }
20
47
  }
21
- }
48
+ })()
22
49
 
23
50
  export default observer
@@ -19,16 +19,16 @@ export default {
19
19
  if (!events) return
20
20
 
21
21
  // console.log('attach', events, this)
22
- var instance = this
22
+ const instance = this
23
23
  events.map((def) => {
24
- var e = extract.e(instance, def[0])
25
- var f = extract.f(instance, def[1])
26
- var option = def[2]
24
+ const e = extract.e(instance, def[0])
25
+ const f = extract.f(instance, def[1])
26
+ const option = def[2]
27
27
 
28
- var keys = def[1].split('.')
28
+ const keys = def[1].split('.')
29
29
 
30
30
  keys.pop()
31
- var bound = this.last(keys.join('.'))
31
+ const bound = this.last(keys.join('.'))
32
32
 
33
33
  if (f && bound && e && e.element && e.element.addEventListener) {
34
34
  if (!f) { console.log('error') }
@@ -59,11 +59,11 @@ export default {
59
59
  // console.log('_path', str)
60
60
  if (!str) return this
61
61
  else if (!str.match(/\./)) return this[str]
62
- var last
62
+ let last
63
63
 
64
- var keys = str.split('.')
65
- for (var i = 0, l = keys.length; i < l; i++) {
66
- var key = keys[i]
64
+ const keys = str.split('.')
65
+ for (let i = 0, l = keys.length; i < l; i++) {
66
+ const key = keys[i]
67
67
 
68
68
  last = last || this
69
69
  last = last[key]
@@ -0,0 +1,33 @@
1
+ // request.js
2
+ const request = async (url, method = 'GET', body = null, headers = {}, signal = null) => {
3
+ const defaultHeaders = {
4
+ Accept: 'application/json',
5
+ 'Content-Type': 'application/json'
6
+ }
7
+
8
+ const options = {
9
+ method,
10
+ headers: { ...defaultHeaders, ...headers },
11
+ signal
12
+ }
13
+
14
+ if (body) {
15
+ options.body = JSON.stringify(body)
16
+ }
17
+
18
+ try {
19
+ const response = await fetch(url, options)
20
+ if (!response.ok) {
21
+ throw new Error(`HTTP error! status: ${response.status}`)
22
+ }
23
+ const data = await response.json()
24
+
25
+ return data
26
+ } catch (error) {
27
+ // Handle fetch or data processing errors
28
+ // console.log('error', error)
29
+ return { error }
30
+ }
31
+ }
32
+
33
+ export default request
@@ -6,41 +6,36 @@ const defaults = {
6
6
  opacity: ['1', '.3']
7
7
  }
8
8
 
9
- function init (container) {
10
- console.log('set', container)
9
+ const init = (container) => {
11
10
  container.addEventListener('mousedown', (e) => {
12
- console.log('mousedown')
13
11
  show(e)
14
12
  })
15
13
  }
16
14
 
17
- function show (e) {
18
- console.log('show', e)
19
- var container = e.target
20
- var offs = offset(container)
15
+ const show = (e) => {
16
+ const container = e.target
17
+ const offs = offset(container)
21
18
 
22
- let ripple = document.createElement('div')
19
+ const ripple = document.createElement('div')
23
20
  ripple.classList.add('ripple')
24
- let end = coordinate(offs)
25
- let initial = {
26
- left: (e.offsetX || offs.width / 2) + 'px',
27
- top: (e.offsetY || offs.height / 2) + 'px'
21
+
22
+ const end = coordinate(offs)
23
+ const initial = {
24
+ left: `${e.offsetX || offs.width / 2}px`,
25
+ top: `${e.offsetY || offs.height / 2}px`
28
26
  }
29
27
 
30
28
  ripple.style.left = initial.left
31
29
  ripple.style.top = initial.top
32
- // ripple.style.opacity = defaults.opacity[1]
33
30
  ripple.style.transition = defaults.transition
34
31
 
35
32
  insert(ripple, container, 'top')
36
33
 
37
34
  setTimeout(() => {
38
- // console.log('style coord', end);
39
35
  ripple.style.left = end.left
40
36
  ripple.style.top = end.top
41
37
  ripple.style.width = end.size
42
38
  ripple.style.height = end.size
43
- // ripple.style.opacity = defaults.opacity[1]
44
39
  }, 1)
45
40
 
46
41
  document.body.onmouseup = () => {
@@ -48,9 +43,9 @@ function show (e) {
48
43
  }
49
44
  }
50
45
 
51
- function coordinate (o) {
52
- var size = o.height
53
- var top = -o.height / 2
46
+ const coordinate = (o) => {
47
+ let size = o.height
48
+ let top = -o.height / 2
54
49
 
55
50
  if (o.width > o.height) {
56
51
  top = -(o.width - o.height / 2)
@@ -58,19 +53,19 @@ function coordinate (o) {
58
53
  }
59
54
 
60
55
  return {
61
- size: (size * 2) + 'px',
62
- top: top + 'px',
63
- left: (size / -2) + 'px'
56
+ size: `${size * 2}px`,
57
+ top: `${top}px`,
58
+ left: `${size / -2}px`
64
59
  }
65
60
  }
66
61
 
67
- function destroy (ripple) {
68
- if (ripple.parentNode) { ripple.style.opacity = '0' }
62
+ const destroy = (ripple) => {
63
+ if (ripple.parentNode) ripple.style.opacity = '0'
69
64
 
70
65
  document.body.onmouseup = null
71
66
 
72
67
  setTimeout(() => {
73
- if (ripple.parentNode) { ripple.parentNode.removeChild(ripple) }
68
+ if (ripple.parentNode) ripple.parentNode.removeChild(ripple)
74
69
  }, 1000)
75
70
  }
76
71
 
@@ -1,42 +1,38 @@
1
-
2
1
  window._scrollbar = {}
3
2
 
4
- function scrollbar () {
3
+ const scrollbar = () => {
5
4
  // if (window._scrollbar.checked) return
6
5
 
7
- var list = document.createElement('div')
6
+ const list = document.createElement('div')
8
7
  list.classList.add('list')
9
- list.style['z-index'] = '1000'
8
+ list.style.zIndex = '1000'
10
9
  list.style.display = 'block'
11
10
  list.style.width = '300px'
12
- list.style['minWidth'] = '300px'
11
+ list.style.minWidth = '300px'
13
12
  list.style.height = '20px'
14
13
  list.style.position = 'absolute'
15
14
  list.style.top = '-200px'
16
15
  list.style.right = 'initial'
17
16
  list.style.bottom = 'initial'
18
17
  list.style.left = '200px'
19
- list.style['overflowY'] = 'hidden'
18
+ list.style.overflowY = 'hidden'
20
19
  document.body.appendChild(list)
21
20
 
22
- var body = document.createElement('div')
21
+ const body = document.createElement('div')
23
22
  body.classList.add('body')
24
- body.style['overflowY'] = 'scroll'
23
+ body.style.overflowY = 'scroll'
25
24
  list.appendChild(body)
26
25
 
27
- var item = document.createElement('div')
26
+ const item = document.createElement('div')
28
27
  item.classList.add('item')
29
28
  item.style.height = '40px'
30
29
  item.style.margin = '0'
31
30
  item.style.padding = '0'
32
31
  item.style.border = '0'
33
- item.style['backgroundColor'] = 'green'
32
+ item.style.backgroundColor = 'green'
34
33
  body.appendChild(item)
35
34
 
36
- var info = item.getBoundingClientRect()
37
- // console.log('width', 300 - info.width)
38
-
39
- // console.log('list', list)
35
+ const info = item.getBoundingClientRect()
40
36
 
41
37
  document.body.removeChild(list)
42
38
 
@@ -1,19 +1,15 @@
1
- function smoothscroll (e, top, time) {
2
- // console.log('smoothscroll', top, e.scrollTop)
1
+ const smoothscroll = (e, top, time = 275) => {
2
+ const start = top - e.scrollTop
3
+ const step = start / 100
4
+ let current = 0
3
5
 
4
- var start = top - e.scrollTop
5
-
6
- time = time || 275
7
- var step = start / 100
8
- var current = 0
9
6
  while (current <= time) {
10
7
  window.setTimeout(scrolling, current, e, step)
11
8
  current += time / 100
12
9
  }
13
10
  }
14
11
 
15
- function scrolling (e, step) {
16
- // console.log('scrolling', step, e.scrollTop)
12
+ const scrolling = (e, step) => {
17
13
  e.scrollBy(0, step)
18
14
  }
19
15
 
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  /**
4
2
  * Utility functions
5
3
  * @module module/utils
@@ -9,19 +7,17 @@
9
7
  * Checks if given value is an array
10
8
  * @param {*} object
11
9
  * @returns {boolean}
12
- * @private
13
10
  */
14
- function _isArray (object) {
11
+ const isArray = (object) => {
15
12
  return Object.prototype.toString.call(object) === '[object Array]'
16
13
  }
17
14
 
18
15
  /**
19
- * Checks if javascript object is plain object
16
+ * Checks if JavaScript object is a plain object
20
17
  * @param {Object} object
21
18
  * @returns {*|boolean}
22
- * @private
23
19
  */
24
- function _isLiteralObject (object) {
20
+ const isLiteralObject = (object) => {
25
21
  return object && typeof object === 'object' && Object.getPrototypeOf(object) === Object.getPrototypeOf({})
26
22
  }
27
23
 
@@ -29,34 +25,30 @@ function _isLiteralObject (object) {
29
25
  * Checks if object is iterable
30
26
  * @param {Object} object
31
27
  * @returns {boolean}
32
- * @private
33
28
  */
34
- function _isIterable (object) {
35
- var r = _isLiteralObject(object) ||
36
- _isArray(object) ||
29
+ const isIterable = (object) => {
30
+ return isLiteralObject(object) ||
31
+ isArray(object) ||
37
32
  (typeof object === 'object' &&
38
33
  object !== null &&
39
34
  object.length !== undefined)
40
-
41
- return r
42
35
  }
43
36
 
44
37
  /**
45
38
  *
46
39
  * @param {Object} object
47
40
  * @param {Function} callback
48
- * @private
49
41
  */
50
- function _each (object, callback) {
51
- if (_isArray(object) || (typeof object === 'object' && object.length !== undefined)) {
52
- for (var i = 0, l = object.length; i < l; i++) {
42
+ const each = (object, callback) => {
43
+ if (isArray(object) || (typeof object === 'object' && object.length !== undefined)) {
44
+ for (let i = 0, l = object.length; i < l; i++) {
53
45
  callback.apply(object[i], [object[i], i])
54
46
  }
55
47
  return
56
48
  }
57
49
 
58
- if (_isLiteralObject(object)) {
59
- for (var key in object) {
50
+ if (isLiteralObject(object)) {
51
+ for (const key in object) {
60
52
  callback.apply(object[key], [object[key], key])
61
53
  }
62
54
  }
@@ -67,13 +59,12 @@ function _each (object, callback) {
67
59
  * @param {Array} array
68
60
  * @param {*} obj
69
61
  * @returns {number}
70
- * @private
71
62
  */
72
- function _indexOf (array, obj) {
63
+ const indexOf = (array, obj) => {
73
64
  if (Array.prototype.indexOf) {
74
65
  return Array.prototype.indexOf.call(array, obj)
75
66
  }
76
- for (var i = 0, j = array.length; i < j; i++) {
67
+ for (let i = 0, j = array.length; i < j; i++) {
77
68
  if (array[i] === obj) {
78
69
  return i
79
70
  }
@@ -81,4 +72,4 @@ function _indexOf (array, obj) {
81
72
  return -1
82
73
  }
83
74
 
84
- export { _isArray, _isIterable, _isLiteralObject, _each, _indexOf }
75
+ export { isArray, isIterable, isLiteralObject, each, indexOf }
@@ -2,12 +2,12 @@
2
2
  function viewport (el) {
3
3
  if (!el) return
4
4
 
5
- var rect = el.getBoundingClientRect()
5
+ const rect = el.getBoundingClientRect()
6
6
 
7
- var top = rect.top
8
- var left = rect.left
9
- var width = rect.width
10
- var height = rect.height
7
+ const top = rect.top
8
+ const left = rect.left
9
+ const width = rect.width
10
+ const height = rect.height
11
11
 
12
12
  return (
13
13
  top >= window.pageYOffset &&
package/src/navigation.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as css from './module/css'
1
2
  import build from './module/build'
2
3
 
3
4
  class Navigation {
@@ -8,12 +9,17 @@ class Navigation {
8
9
  constructor (options) {
9
10
  this.init(options)
10
11
  this.build()
12
+ this.setup()
11
13
  }
12
14
 
13
15
  init (options) {
14
- this.options = Object.assign({}, Navigation.defaults, options || {})
16
+ this.options = { ...Navigation.defaults, ...options }
15
17
  Object.assign(this, build)
16
18
  }
19
+
20
+ setup() {
21
+ if (this.options.type) css.add(this.element, 'type-', this.options.type)
22
+ }
17
23
  }
18
24
 
19
25
  export default Navigation
package/src/progress.js CHANGED
@@ -1,10 +1,9 @@
1
1
  // import Component from './component';
2
2
  import create from './element/create'
3
3
  import classify from './module/classify'
4
- import css from './module/css'
5
4
  import insert from './element/insert'
6
5
 
7
- var defaults = {
6
+ const defaults = {
8
7
  prefix: 'material',
9
8
  class: 'progress',
10
9
  tag: 'div',
@@ -14,13 +13,6 @@ var defaults = {
14
13
  </svg>`
15
14
  }
16
15
 
17
- /**
18
- * The class represents an item ie for list
19
- *
20
- * @class
21
- * @return {Object} The class instance
22
- * @example new Item(object);
23
- */
24
16
  class Spinner {
25
17
  /**
26
18
  * init
package/src/search.js CHANGED
@@ -1,20 +1,24 @@
1
1
  import EventEmitter from './mixin/emitter'
2
2
 
3
3
  import build from './module/build'
4
+ import display from './mixin/display'
4
5
  import bindEvents from './module/events'
5
6
 
7
+ import Element from './element'
6
8
  import Button from './button'
7
- import cancel from './skin/material/icon/cancel.svg'
8
9
 
9
10
  class Search extends EventEmitter {
10
11
  static defaults = {
11
12
  class: 'search-input',
12
13
  minChar: 4,
13
- iconCancel: cancel,
14
14
  timeout: 200,
15
+ layout: [
16
+ [Element, 'input', { tag: 'input', class: 'input'} ],
17
+ [Button, 'clear', { class: 'clear'} ]
18
+ ],
15
19
  events: [
16
- ['input.input', 'onInput'],
17
- ['input.cancel', 'onCancel']
20
+ ['ui.input.input', 'onInput'],
21
+ ['ui.clear.click', 'onClear']
18
22
  ]
19
23
  }
20
24
 
@@ -23,47 +27,38 @@ class Search extends EventEmitter {
23
27
 
24
28
  this.init(options)
25
29
  this.build()
26
- this.buildSearch()
27
30
  this.bindEvents()
28
- }
29
31
 
30
- init(options) {
31
- this.options = Object.assign({}, Search.defaults, options || {})
32
- Object.assign(this, build, bindEvents)
32
+ this.input = this.ui.input
33
33
  }
34
34
 
35
- buildSearch () {
36
- if (this.options.icon) {
37
- this.icon = document.createElement('i')
38
- this.icon.classList.add('icon')
39
- this.icon.innerHTML = this.options.icon
40
- this.element.appendChild(this.icon)
41
- }
35
+ init (options) {
36
+ this.options = { ...Search.defaults, ...options }
37
+ Object.assign(this, build, display, bindEvents)
38
+ }
42
39
 
43
- this.input = document.createElement('input')
44
- this.input.classList.add('input')
45
- this.element.appendChild(this.input)
40
+ set (value) {
41
+ if (value) this.input.value = value
42
+ else this.input.value = ''
43
+ }
46
44
 
47
- this.cancel = new Button({
48
- container: this.element,
49
- class: 'clear',
50
- icon: this.options.iconCancel
51
- })
45
+ focus () {
46
+ this.ui.input.focus()
52
47
  }
53
48
 
54
49
  onInput () {
55
- if (this.input.value.length < this.options.minChar) return
50
+ if (this.ui.input.value.length < this.options.minChar) return
56
51
 
57
52
  clearTimeout(this.timeout)
58
53
 
59
54
  this.timeout = setTimeout(() => {
60
- this.emit('change', this.input.value)
55
+ this.emit('change', this.ui.input.value)
61
56
  }, this.options.timeout)
62
57
  }
63
58
 
64
- onCancel () {
65
- this.input.value = ''
66
- this.input.focus()
59
+ onClear () {
60
+ this.set(null)
61
+ this.focus()
67
62
  this.emit('cancel')
68
63
  }
69
64
  }