material 0.7.4 → 0.7.6

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.
package/index.js CHANGED
@@ -29,6 +29,7 @@ import Text from './src/text'
29
29
  import Textfield from './src/textfield'
30
30
  import Toolbar from './src/toolbar'
31
31
  import Tooltip from './src/tooltip'
32
+ import View from './src/view'
32
33
  import attach from './src/module/attach'
33
34
  import attributes from './src/module/attributes'
34
35
  import build from './src/module/build'
@@ -45,6 +46,6 @@ export {
45
46
  AppBar, Button, Card, Checkbox, Component, DateHour, Dialog, Drawer, Element,
46
47
  File, Form, Image, Layout, List, Loading, Menu, Navigation, Progress, Select,
47
48
  Selecter, Slider, Snackbar, Switch, Switcher, Tabs, TabView, Text, Textfield, Toolbar, Tooltip,
48
- attach, attributes, build, dataset, display, events, emitter, jsonToHTML, mediator,
49
+ View, attach, attributes, build, dataset, display, events, emitter, jsonToHTML, mediator,
49
50
  observer, smoothscroll
50
51
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.7.4",
4
- "description": "A lightweight implementation of Material Design Components - ES6",
3
+ "version": "0.7.6",
4
+ "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "repository": {
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "homepage": "https://gitlab.com/alkaloid/material",
17
17
  "keywords": [
18
- "lightweight material design ui component es6 vanilla javascript"
18
+ "lightweight material design ui component web es6 vanilla javascript"
19
19
  ],
20
20
  "devDependencies": {
21
21
  "standard": "^10.0.3"
package/src/button.js CHANGED
@@ -46,18 +46,12 @@ class Button extends EventEmitter {
46
46
  setup () {
47
47
  this.setAttributes()
48
48
  this.styleAttributes()
49
- this.buildElements()
50
49
 
51
50
  if (this.options.text) {
52
51
  this.element.innerHTML = this.element.innerHTML + this.options.text
53
52
  }
54
53
  }
55
54
 
56
- buildElements () {
57
- this.buildIcon()
58
- this.buildLabel()
59
- }
60
-
61
55
  setAttributes () {
62
56
  const { type, name, value, title, text, label, tooltip, data, case: caseOption } = this.options
63
57
 
@@ -80,26 +74,6 @@ class Button extends EventEmitter {
80
74
  if (bold) this.element.classList.add('bold')
81
75
  }
82
76
 
83
- buildLabel () {
84
- if (!this.options.label) return
85
-
86
- this.label = document.createElement('label')
87
- this.label.classList.add('label')
88
- this.label.innerHTML = this.options.label
89
-
90
- this.element.appendChild(this.label)
91
- }
92
-
93
- buildIcon () {
94
- if (!this.options.icon) return
95
-
96
- this.icon = document.createElement('i')
97
- this.icon.classList.add('icon')
98
- this.icon.innerHTML = this.options.icon
99
-
100
- this.element.appendChild(this.icon)
101
- }
102
-
103
77
  set (prop, value) {
104
78
  // console.log('set', this.element, prop, value)
105
79
  switch (prop) {
@@ -107,15 +81,15 @@ class Button extends EventEmitter {
107
81
  this.element.value = value
108
82
  break
109
83
  case 'label':
110
- if (!this.label) this.buildLabel()
111
- this.label.innerHTML = value
84
+ if (!this.ui.label) this.buildLabel()
85
+ this.ui.label.innerHTML = value
112
86
  break
113
87
  case 'text':
114
88
  this.element.innerHTML = value
115
89
  break
116
90
  case 'icon':
117
- if (this.icon) {
118
- this.icon.innerHTML = value
91
+ if (this.ui.icon) {
92
+ this.ui.icon.innerHTML = value
119
93
  }
120
94
  break
121
95
  case 'enable':
@@ -133,13 +107,13 @@ class Button extends EventEmitter {
133
107
  }
134
108
 
135
109
  setLabel (value) {
136
- if (this.label) {
137
- this.label.innerHTML = value
110
+ if (this.ui.label) {
111
+ this.ui.label.innerHTML = value
138
112
  }
139
113
  }
140
114
 
141
115
  setText (value) {
142
- if (this.label) {
116
+ if (this.ui.label) {
143
117
  this.setLabel(value)
144
118
  } else {
145
119
  this.element.innerHTML = value
package/src/card.js CHANGED
@@ -11,11 +11,6 @@ const defaults = {
11
11
  }
12
12
 
13
13
  class Card {
14
- /**
15
- * Constructor
16
- * @param {Object} options - Component options
17
- * @return {Object} Class instance
18
- */
19
14
  constructor (options) {
20
15
  this.init(options)
21
16
  this.build()
@@ -1,9 +1,11 @@
1
1
  import dom from '../module/dom'
2
2
 
3
3
  const insert = (component, container, context = 'bottom') => {
4
+ // console.log('insert', component, container, context)
5
+
4
6
  if (!component || !container) return
5
7
 
6
- element = component.element || component
8
+ const element = component.element || component
7
9
  container = container.element || container
8
10
 
9
11
  const contexts = ['top', 'bottom', 'after', 'before']
package/src/file.js CHANGED
@@ -13,7 +13,6 @@ class File {
13
13
  constructor (options) {
14
14
  this.init(options)
15
15
  this.build()
16
- this.buildLabel()
17
16
  this.buildInput()
18
17
  this.attach()
19
18
  }
@@ -23,15 +22,6 @@ class File {
23
22
  Object.assign(this, build)
24
23
  }
25
24
 
26
- buildLabel () {
27
- if (this.options.label) {
28
- this.label = document.createElement('label')
29
- this.label.classList.add('label')
30
- this.label.innerHTML = this.options.label
31
- this.element.appendChild(this.label)
32
- }
33
- }
34
-
35
25
  buildInput () {
36
26
  this.field = document.createElement('div')
37
27
  this.field.classList.add('field')
package/src/item.js CHANGED
@@ -1,93 +1,45 @@
1
- import Layout from './layout'
1
+ import build from './module/build'
2
2
 
3
- import create from './mixin/create'
4
- import insert from './mixin/insert'
5
-
6
- const defaults = {
7
- prefix: 'material',
8
- class: 'item',
9
- type: 'default',
10
- tag: 'li',
11
- types: {
12
- default: 'span',
13
- display4: 'h1',
14
- display3: 'h1',
15
- display2: 'h1',
16
- display1: 'h1',
17
- headline: 'h1',
18
- title: 'h2',
19
- subheading2: 'h3',
20
- subheading1: 'h4',
21
- body: 'p',
22
- body2: 'aside',
23
- caption: 'span'
3
+ class Item {
4
+ static defaults = {
5
+ prefix: 'material',
6
+ class: 'item',
7
+ type: 'default',
8
+ tag: 'span',
9
+ types: {
10
+ default: 'span',
11
+ display4: 'h1',
12
+ display3: 'h1',
13
+ display2: 'h1',
14
+ display1: 'h1',
15
+ headline: 'h1',
16
+ title: 'h2',
17
+ subheading2: 'h3',
18
+ subheading1: 'h4',
19
+ body: 'p',
20
+ body2: 'aside',
21
+ caption: 'span'
22
+ }
24
23
  }
25
- }
26
24
 
27
- /**
28
- * The class represents an item ie for list
29
- *
30
- * @class
31
- * @return {Object} The class instance
32
- * @example new Item(object);
33
- */
34
- class Item {
35
- /**
36
- * init
37
- * @return {Object} The class options
38
- */
39
25
  constructor (options) {
40
26
  this.init(options)
41
27
  this.build()
28
+ this.setup()
29
+ }
42
30
 
43
- return this
31
+ setup () {
32
+ if (this.options.text) this.set(this.options.text)
33
+ if (this.options.name) this.element.setAttribute('name', this.options.name)
44
34
  }
45
35
 
46
- /**
47
- * [init description]
48
- * @param {?} options [description]
49
- * @return {?} [description]
50
- */
51
36
  init (options) {
52
- // merge options
53
- this.options = Object.assign({}, defaults, options || {})
54
-
55
- // define class
56
-
57
- // assign modules
58
- Object.assign(this, insert)
59
- }
37
+ this.options = Object.assign({}, Item.defaults, options || {})
38
+ Object.assign(this, build)
60
39
 
61
- /**
62
- * Build function for item
63
- * @return {Object} This class instance
64
- */
65
- build () {
66
- // define main tag
67
40
  this.options.tag = this.options.tag || this.options.types[this.options.type]
68
-
69
- this.options.tag = this.options.tag
70
-
71
- this.element = create(this.options)
72
-
73
- if (this.options.text) {
74
- this.set(this.options.text)
75
- }
76
-
77
- if (this.options.layout) {
78
- this.layout = new Layout(this.options.layout, this.element)
79
- } else {
80
- if (this.options.container) {
81
- this.insert(this.options.container)
82
- }
83
- }
84
41
  }
85
42
 
86
- /**
87
- * Get or set text value of the element
88
- * @param {string} value The text to set
89
- * @returns {*}
90
- */
91
43
  set (value) {
92
44
  if (value) {
93
45
  if (this.element.innerText) {
@@ -95,8 +47,6 @@ class Item {
95
47
  } else {
96
48
  this.element.textContent = value
97
49
  }
98
-
99
- return this
100
50
  }
101
51
 
102
52
  return this
package/src/loader.js ADDED
@@ -0,0 +1,88 @@
1
+ class Loader {
2
+ static defaults = {
3
+ class: 'loader'
4
+ }
5
+
6
+ constructor (options) {
7
+ this.options = Object.assign({}, Loader.defaults, options || {})
8
+
9
+ // Object.assign(this, attach, mediator, build)
10
+
11
+ this.build()
12
+
13
+ return this
14
+ }
15
+
16
+ build () {
17
+ this.element = document.createElement(this.options.tag || 'div')
18
+ this.element.classList.add(this.options.class || 'loader')
19
+
20
+ this.container = document.createElement('div')
21
+ this.container.classList.add('container')
22
+ this.element.appendChild(this.container)
23
+
24
+ const svg = `
25
+ <svg
26
+ version="1.1"
27
+ id="dc-spinner"
28
+ xmlns="http://www.w3.org/2000/svg"
29
+ x="0px" y="0px"
30
+ width:"38"
31
+ height:"38"
32
+ viewBox="0 0 38 38"
33
+ preserveAspectRatio="xMinYMin meet"
34
+ >
35
+ <path class="circles" d="M20,35c-8.271,0-15-6.729-15-15S11.729,5,20,5s15,6.729,15,15S28.271,35,20,35z M20,5.203
36
+ C11.841,5.203,5.203,11.841,5.203,20c0,8.159,6.638,14.797,14.797,14.797S34.797,28.159,34.797,20
37
+ C34.797,11.841,28.159,5.203,20,5.203z">
38
+ </path>
39
+
40
+ <path class="circles" d="M20,33.125c-7.237,0-13.125-5.888-13.125-13.125S12.763,6.875,20,6.875S33.125,12.763,33.125,20
41
+ S27.237,33.125,20,33.125z M20,7.078C12.875,7.078,7.078,12.875,7.078,20c0,7.125,5.797,12.922,12.922,12.922
42
+ S32.922,27.125,32.922,20C32.922,12.875,27.125,7.078,20,7.078z">
43
+ </path>
44
+
45
+ <path class="circletwo" stroke-width="0.6027" stroke-miterlimit="10" d="M5.203,20
46
+ c0-8.159,6.638-14.797,14.797-14.797V5C11.729,5,5,11.729,5,20s6.729,15,15,15v-0.203C11.841,34.797,5.203,28.159,5.203,20z">
47
+ <animateTransform
48
+ attributeName="transform"
49
+ type="rotate"
50
+ from="0 20 20"
51
+ to="360 20 20"
52
+ calcMode="spline"
53
+ keySplines="0.4, 0, 0.2, 1"
54
+ keyTimes="0;1"
55
+ dur="2s"
56
+ repeatCount="indefinite" />
57
+ </path>
58
+
59
+ <path class="circleone" stroke-width="0.2027" stroke-miterlimit="10" d="M7.078,20
60
+ c0-7.125,5.797-12.922,12.922-12.922V6.875C12.763,6.875,6.875,12.763,6.875,20S12.763,33.125,20,33.125v-0.203
61
+ C12.875,32.922,7.078,27.125,7.078,20z">
62
+ <animateTransform
63
+ attributeName="transform"
64
+ type="rotate"
65
+ from="0 20 20"
66
+ to="360 20 20"
67
+ dur="1.8s"
68
+ repeatCount="indefinite" />
69
+ </path>
70
+ </svg>`
71
+
72
+ this.container.innerHTML = svg
73
+ this.text = document.createElement(this.options.tag || 'span')
74
+ this.text.classList.add('text')
75
+ this.text.innerHTML = this.options.text
76
+ this.container.appendChild(this.text)
77
+ }
78
+
79
+ show () {
80
+ this.element.classList.add('show')
81
+ }
82
+
83
+ hide () {
84
+ this.element.classList.remove('show')
85
+ }
86
+ }
87
+
88
+ export default Loader
@@ -8,10 +8,6 @@ const KEYCODE = {
8
8
  }
9
9
 
10
10
  const control = {
11
- /**
12
- * [toggle description]
13
- * @return {Object} The class instance
14
- */
15
11
  toggle () {
16
12
  if (this.disabled) return
17
13
 
@@ -26,10 +22,6 @@ const control = {
26
22
  return this
27
23
  },
28
24
 
29
- /**
30
- * Set checkbox value
31
- * @param {boolean} value [description]
32
- */
33
25
  check (checked) {
34
26
  if (checked === true) {
35
27
  css.add(this.element, 'is-checked')
@@ -45,10 +37,6 @@ const control = {
45
37
  return this
46
38
  },
47
39
 
48
- /**
49
- * [initLabel description]
50
- * @return {?} [description]
51
- */
52
40
  label (label, container) {
53
41
  if (!label) return
54
42
 
@@ -65,11 +53,6 @@ const control = {
65
53
  insert(this.element.label, container)
66
54
  },
67
55
 
68
- /**
69
- * [_initIcon description]
70
- * @param {string} type
71
- * @return {string}
72
- */
73
56
  icon (icon, container, position) {
74
57
  if (!icon) return
75
58
 
@@ -88,10 +71,6 @@ const control = {
88
71
  this.element.icon.innerHTML = icon
89
72
  },
90
73
 
91
- /**
92
- * [initLabel description]
93
- * @return {?} [description]
94
- */
95
74
  error (error) {
96
75
  error = error || this.options.error
97
76
  if (this.options.error === null) return
@@ -137,12 +116,6 @@ const control = {
137
116
  }
138
117
  },
139
118
 
140
- /**
141
- * Setter
142
- * @param {string} prop
143
- * @param {string} value
144
- * @return {Object} The class instance
145
- */
146
119
  get (prop) {
147
120
  switch (prop) {
148
121
  case 'name':
@@ -165,10 +138,6 @@ const control = {
165
138
  return this.element.dataset.name
166
139
  },
167
140
 
168
- /**
169
- * [_onInputFocus description]
170
- * @return {?} [description]
171
- */
172
141
  focus () {
173
142
  if (this.disabled === true) return this
174
143
 
@@ -177,10 +146,6 @@ const control = {
177
146
  return this
178
147
  },
179
148
 
180
- /**
181
- * [_onInputBlur description]
182
- * @return {?} [description]
183
- */
184
149
  blur () {
185
150
  css.remove(this.element, 'is-focused')
186
151
  return this
@@ -10,10 +10,7 @@ export default {
10
10
 
11
11
  show () {
12
12
  // console.log('show', this.visible)
13
-
14
- // if (this.options.transition) {
15
- // this.element.style.display = 'initial'
16
- // }
13
+ if (!this.element) return
17
14
 
18
15
  this.element.getBoundingClientRect()
19
16
 
@@ -29,11 +26,6 @@ export default {
29
26
  },
30
27
 
31
28
  hide () {
32
- // console.log('hide')
33
- // if (this.element.style.display === 'none') return
34
- // clearTimeout(this.displayTimeout)
35
- // this._display = getComputedStyle(this.element).display
36
-
37
29
  if (!this.element) return
38
30
 
39
31
  this.element.classList.remove('show')
@@ -43,13 +35,6 @@ export default {
43
35
  this.underlay.classList.remove('show')
44
36
  }
45
37
 
46
- // if (this.options.transition) {
47
- // this.displayTimeout = setTimeout(() => {
48
- // console.log('display: none', this._display)
49
- // this.element.style.display = 'none'
50
- // }, this.options.transition)
51
- // }
52
-
53
38
  this.emit?.('hide')
54
39
  return this
55
40
  },
@@ -3,10 +3,6 @@ import insert from '../element/insert'
3
3
 
4
4
  const prefix = 'material'
5
5
 
6
- /**
7
- * [initLabel description]
8
- * @return {?} [description]
9
- */
10
6
  function label (root, text, options) {
11
7
  text = text || null
12
8
 
@@ -1,5 +1,5 @@
1
- // Assuming extract is imported or defined elsewhere
2
1
  import extract from './extract'
2
+ import last from './last'
3
3
 
4
4
  const attachModule = {
5
5
  attach (events) {
@@ -18,7 +18,7 @@ const attachModule = {
18
18
  keys.pop()
19
19
  }
20
20
 
21
- const bound = this.last(keys.join('.'))
21
+ const bound = last(keys.join('.'), this)
22
22
 
23
23
  let handler = null
24
24
 
@@ -45,14 +45,8 @@ const attachModule = {
45
45
  })
46
46
 
47
47
  return this
48
- },
49
-
50
- last (str) {
51
- if (!str) return this
52
- if (!str.includes('.')) return this[str]
53
-
54
- return str.split('.').reduce((acc, key) => acc[key], this)
55
48
  }
49
+
56
50
  }
57
51
 
58
52
  export default attachModule
@@ -1,21 +1,14 @@
1
1
  const special = ['required', 'disabled', 'multiple', 'checked']
2
2
 
3
- function attributes (element, o) {
4
- // console.log('attributes', o.attributes, element)
3
+ const attributes = (element, options) => {
4
+ if (!element || !options.attributes) return
5
5
 
6
- if (!element) return
7
-
8
- for (let i = 0; i < o.attributes.length; i++) {
9
- const attribute = o.attributes[i]
10
-
11
- if (o[attribute] && o[attribute] !== 'undefined') {
12
- if (special.indexOf(attribute) > -1) {
13
- element.setAttribute(attribute, attribute)
14
- } else {
15
- element.setAttribute(attribute, o[attribute])
16
- }
6
+ options.attributes.forEach(attribute => {
7
+ if (options[attribute] && String(options[attribute]) !== 'undefined') {
8
+ const value = special.includes(attribute) ? attribute : options[attribute]
9
+ element.setAttribute(attribute, value)
17
10
  }
18
- }
11
+ })
19
12
  }
20
13
 
21
14
  export default attributes
@@ -33,9 +33,34 @@ export default {
33
33
  this.ui = this.layout.component
34
34
  }
35
35
 
36
+ this.ui = this.ui || {}
37
+
38
+ if (this.options.label) this.buildLabel()
39
+ if (this.options.icon) this.buildIcon()
40
+
36
41
  if (this.options.show === true && this.show) this.show()
37
42
  },
38
43
 
44
+ buildLabel () {
45
+ if (!this.options.label) return
46
+
47
+ this.ui.label = document.createElement('label')
48
+ this.ui.label.classList.add('label')
49
+ this.ui.label.innerHTML = this.options.label
50
+
51
+ this.element.appendChild(this.ui.label)
52
+ },
53
+
54
+ buildIcon () {
55
+ if (!this.options.icon) return
56
+
57
+ this.ui.icon = document.createElement('i')
58
+ this.ui.icon.classList.add('icon')
59
+ this.ui.icon.innerHTML = this.options.icon
60
+
61
+ this.element.appendChild(this.ui.icon)
62
+ },
63
+
39
64
  appendTo (container) {
40
65
  container.appendChild(this.element)
41
66
  }
@@ -0,0 +1,24 @@
1
+ const cookie = {
2
+ set: (name, value, expire = 365) => {
3
+ const d = new Date()
4
+ d.setTime(d.getTime() + (expire * 24 * 60 * 60 * 1000))
5
+ const expires = `expires=${d.toUTCString()}`
6
+ document.cookie = `${name}=${value};${expires};path=/`
7
+ },
8
+ get: name => {
9
+ const nameEQ = `${name}=`
10
+ const ca = decodeURIComponent(document.cookie).split(';')
11
+
12
+ for (let c of ca) {
13
+ while (c.charAt(0) === ' ') c = c.substring(1)
14
+ if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length)
15
+ }
16
+
17
+ return ''
18
+ },
19
+ del: name => {
20
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`
21
+ }
22
+ }
23
+
24
+ export default cookie
@@ -1,18 +1,8 @@
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
1
+ const last = (str, that) => {
2
+ if (!str) return that
3
+ if (!str.includes('.')) return that[str]
7
4
 
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
- }
5
+ return str.split('.').reduce((acc, key) => acc[key], that)
18
6
  }
7
+
8
+ export default last