uniform-ui 3.0.0.beta2 → 3.0.0.beta10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascripts/uniform/checkbox.js +15 -15
  3. data/lib/assets/javascripts/uniform/component.js +23 -12
  4. data/lib/assets/javascripts/uniform/dropdown.js +54 -54
  5. data/lib/assets/javascripts/uniform/dropzone.js +107 -0
  6. data/lib/assets/javascripts/uniform/floating-label-input.js +14 -12
  7. data/lib/assets/javascripts/uniform/modal.js +31 -33
  8. data/lib/assets/javascripts/uniform/popover.js +59 -40
  9. data/lib/assets/javascripts/uniform/resizer.js +21 -21
  10. data/lib/assets/javascripts/uniform/select.js +187 -163
  11. data/lib/assets/javascripts/uniform/sticker.js +26 -0
  12. data/lib/assets/javascripts/uniform/tooltip.js +29 -16
  13. data/lib/assets/javascripts/uniform.js +23 -8
  14. data/lib/assets/stylesheets/uniform/base.scss +24 -9
  15. data/lib/assets/stylesheets/uniform/components/buttons.scss +4 -5
  16. data/lib/assets/stylesheets/uniform/components/checkbox.scss +2 -0
  17. data/lib/assets/stylesheets/uniform/components/container.scss +8 -7
  18. data/lib/assets/stylesheets/uniform/components/dropzone.scss +40 -0
  19. data/lib/assets/stylesheets/uniform/components/input-group.scss +9 -0
  20. data/lib/assets/stylesheets/uniform/components/loaders.scss +0 -3
  21. data/lib/assets/stylesheets/uniform/components/modal.scss +21 -36
  22. data/lib/assets/stylesheets/uniform/components/pointer.scss +4 -4
  23. data/lib/assets/stylesheets/uniform/components/select.scss +7 -2
  24. data/lib/assets/stylesheets/uniform/components/thumb.scss +0 -1
  25. data/lib/assets/stylesheets/uniform/components/z-input.scss +6 -0
  26. data/lib/assets/stylesheets/uniform/config.scss +156 -0
  27. data/lib/assets/stylesheets/uniform/defaults.scss +2 -26
  28. data/lib/assets/stylesheets/uniform/functions/icons.scss +29 -0
  29. data/lib/assets/stylesheets/uniform/functions/map.scss +95 -0
  30. data/lib/assets/stylesheets/uniform/functions/string.scss +15 -0
  31. data/lib/assets/stylesheets/uniform/functions.scss +4 -79
  32. data/lib/assets/stylesheets/uniform/mixins.scss +34 -26
  33. data/lib/assets/stylesheets/uniform/utilities/borders.scss +12 -13
  34. data/lib/assets/stylesheets/uniform/utilities/effects.scss +31 -0
  35. data/lib/assets/stylesheets/uniform/utilities/layout.scss +22 -22
  36. data/lib/assets/stylesheets/uniform/utilities/position.scss +4 -0
  37. data/lib/assets/stylesheets/uniform/utilities/sizing.scss +14 -8
  38. data/lib/assets/stylesheets/uniform/utilities/spacing.scss +20 -14
  39. data/lib/assets/stylesheets/uniform/utilities/svg.scss +5 -0
  40. data/lib/assets/stylesheets/uniform/utilities/text.scss +1 -0
  41. data/lib/assets/stylesheets/uniform/utilities.scss +8 -0
  42. data/lib/uniform/version.rb +1 -1
  43. metadata +11 -4
  44. data/lib/assets/stylesheets/uniform/variables.scss +0 -134
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbdcb9dbd05373a00cbd0d38122c4022daefafb4b11cbd25977e57f7367ab38c
4
- data.tar.gz: 074e042a4176f0e1f7e61107b67dcfdbf54c24a3cc937925fa0e8f2b17f1735b
3
+ metadata.gz: b7bdc92171e497d800d00558b6fa1bc980d2664aea204a005379b3bf13a17156
4
+ data.tar.gz: 607b3652e660dbf9ee784fa1faaa0702dd35786c910dac92747d720a3bae5024
5
5
  SHA512:
6
- metadata.gz: daa319ca0955e68bf4f3180066b12a8a0dc58208e26b3176b86a4c9449a645c74c396b967bd9b76c732758637623c9b2e9ede3979522e649687be7106ba396cd
7
- data.tar.gz: 4d200fdbe66802694345f57d44c5b82cd0a94e149cf7c4c9cac7726f7423116cdb509bbd24adc946a2c8c834012f70153fddb89dc7f4f0e1d45fa1b37263bfa9
6
+ metadata.gz: 1e92685de1a592984b81e8b619364f5fd61be992af20d616bf84001b7ef6edc9f534699e6c26a1bf3a5e4bb484e15cbcd1aa57f4cbd9048b154872a2569460af
7
+ data.tar.gz: d72fcaaa3702f68f0558f57b876def3e96cd670e1f0c04c5c1c81af88da31be9e4b9be5e0e1a015aa9ff58a7a9efa84353bc0b6a658bd4c60ca56d222fe68dd7
@@ -1,5 +1,5 @@
1
1
  import Component from './component';
2
- import {addClass, toggleClass, trigger, createElement} from 'dolla';
2
+ import { trigger, createElement} from 'dolla';
3
3
 
4
4
  export class Checkbox extends Component {
5
5
  static CSSClass = "uniformCheckbox";
@@ -7,15 +7,15 @@ export class Checkbox extends Component {
7
7
 
8
8
  initialize (options) {
9
9
  if(options.input instanceof Element) {
10
- this.input = options.input
10
+ this.input = options.input
11
11
  } else {
12
- this.input = createElement('input', Object.assign({}, {
13
- type: this.constructor.type
14
- }, options.input)) // TODO filter options to dolla.HTML_ATTRIBUTES
12
+ this.input = createElement('input', Object.assign({}, {
13
+ type: this.constructor.type
14
+ }, options.input)) // TODO filter options to dolla.HTML_ATTRIBUTES
15
15
  }
16
16
 
17
17
  if(!options.tabindex) this.el.tabIndex = 0;
18
- addClass(this.el, this.constructor.CSSClass);
18
+ this.el.classList.add(this.constructor.CSSClass);
19
19
 
20
20
  this.listenTo(this.el, 'click', this.click);
21
21
  this.listenTo(this.input, 'change', this.change);
@@ -27,9 +27,9 @@ export class Checkbox extends Component {
27
27
  this.input.style.display = "none";
28
28
 
29
29
  if(this.input.parentNode){
30
- this.input.parentNode.insertBefore(this.el, this.input.nextSibling);
30
+ this.input.parentNode.insertBefore(this.el, this.input.nextSibling);
31
31
  } else {
32
- this.el.append(this.input);
32
+ this.el.append(this.input);
33
33
  }
34
34
 
35
35
  this.change()
@@ -38,7 +38,7 @@ export class Checkbox extends Component {
38
38
  }
39
39
 
40
40
  change () {
41
- toggleClass(this.el, 'checked', this.input.checked);
41
+ this.el.classList.toggle('checked', this.input.checked);
42
42
  }
43
43
 
44
44
  click (e) {
@@ -58,17 +58,17 @@ export class Checkbox extends Component {
58
58
  }
59
59
 
60
60
  keydown(e) {
61
- if(e.keyCode == 32 && document.activeElement == this.el) {
62
- // Prevent Page Scroll
63
- e.preventDefault();
64
- }
61
+ if(e.keyCode == 32 && document.activeElement == this.el) {
62
+ // Prevent Page Scroll
63
+ e.preventDefault();
64
+ }
65
65
  }
66
66
  }
67
67
 
68
68
  export class Radio extends Checkbox {
69
- static CSSClass = "uniformRadio";
69
+ static CSSClass = "uniformRadio";
70
70
  }
71
71
 
72
72
  export class Toggle extends Checkbox {
73
- static CSSClass = "uniformToggle";
73
+ static CSSClass = "uniformToggle";
74
74
  }
@@ -1,4 +1,4 @@
1
- import {hasClass, HTML_ATTRIBUTES, createElement, closest} from 'dolla';
1
+ import { HTML_ATTRIBUTES, createElement} from 'dolla';
2
2
 
3
3
  function uniqueId(prefix){
4
4
  window.idCounter || (window.idCounter = 0);
@@ -12,7 +12,14 @@ export default class Component {
12
12
  options = options || {};
13
13
  this.eventListens = new Array();
14
14
  this.eventListeners = new Array();
15
- this.el = options.el || createElement('div', options); //TODO filter options to HTML_ATTRIBUTES
15
+ const htmlAttributes = {}
16
+ Object.keys(options).forEach(key => {
17
+ if (HTML_ATTRIBUTES.includes(key)) {
18
+ htmlAttributes[key] = options[key]
19
+ }
20
+ })
21
+ delete htmlAttributes.content;
22
+ this.el = options.el || createElement('div', htmlAttributes);
16
23
  this.cid = uniqueId('c');
17
24
 
18
25
  this.on = function (type, handler) {
@@ -29,11 +36,15 @@ export default class Component {
29
36
  });
30
37
  }.bind(this);
31
38
 
32
- this.trigger = function (event_key) {
39
+ this.trigger = function (event_key, ...args) {
33
40
  if(!this.eventListeners) return;
34
- this.eventListeners.forEach(function(listener){
35
- if(listener.type == "*" || listener.type == "all" || event_key == listener.type){
36
- listener.handler(event_key, this);
41
+ this.eventListeners.forEach(listener => {
42
+ if (listener.type == "*" || listener.type == "all" || event_key == listener.type){
43
+ args.push(this);
44
+ if (event_key != listener.type) {
45
+ args.unshift(event_key)
46
+ }
47
+ listener.handler(...args);
37
48
  }
38
49
  })
39
50
  };
@@ -42,11 +53,11 @@ export default class Component {
42
53
  }
43
54
 
44
55
  addEventListener () {
45
- this.on.apply(this, arguments);
56
+ this.on.apply(this, arguments);
46
57
  }
47
58
 
48
59
  removeEventListener () {
49
- this.off.apply(this, arguments);
60
+ this.off.apply(this, arguments);
50
61
  }
51
62
 
52
63
  pick (object, keys) {
@@ -59,8 +70,8 @@ export default class Component {
59
70
  }
60
71
 
61
72
  /*
62
- listenTo(el, 'click', '.inner_class', f(), this)
63
- listenTo(el, 'click', f(), this)
73
+ listenTo(el, 'click', '.inner_class', f(), this)
74
+ listenTo(el, 'click', f(), this)
64
75
  */
65
76
  listenTo(node, event, scope, callback, context){
66
77
  // scope is optional param
@@ -74,8 +85,8 @@ export default class Component {
74
85
  node,
75
86
  event,
76
87
  function(e){
77
- if(!scope || (e.target.matches(scope) || closest(e.target, scope))) {
78
- return callback.bind(context)(...arguments);
88
+ if(!scope || (e.target.matches(scope) || e.target.closest(scope))) {
89
+ return callback.bind(context)(...arguments);
79
90
  }
80
91
  }.bind(context)
81
92
  ]
@@ -18,69 +18,69 @@ import {createElement} from 'dolla';
18
18
  */
19
19
  export default class Dropdown extends Component {
20
20
 
21
- initialize (options) {
22
- this.el = options.anchor;
23
- options = options || {}
24
- this.options = {
25
- align: 'center bottom',
26
- container: document.body
27
- };
28
- Object.assign(this.options, this.pick(options, Object.keys(this.options)));
21
+ initialize (options) {
22
+ this.el = options.anchor;
23
+ options = options || {}
24
+ this.options = {
25
+ align: 'center bottom',
26
+ container: document.body
27
+ };
28
+ Object.assign(this.options, this.pick(options, Object.keys(this.options)));
29
29
 
30
- this.enabled = true;
31
- this.active = false;
32
- this.content = options.content;
33
- this.el.dropdown = this;
30
+ this.enabled = true;
31
+ this.active = false;
32
+ this.content = options.content;
33
+ this.el.dropdown = this;
34
34
 
35
- this.listenTo(this.el, 'click', this.toggle);
36
- }
35
+ this.listenTo(this.el, 'click', this.toggle);
36
+ }
37
37
 
38
- render () {
39
- return this;
40
- }
38
+ render () {
39
+ return this;
40
+ }
41
41
 
42
- toggle () {
43
- this.active = !this.active
44
- if(this.active) {
45
- this.show()
46
- } else {
47
- this.hide()
42
+ toggle () {
43
+ this.active = !this.active
44
+ if(this.active) {
45
+ this.show()
46
+ } else {
47
+ this.hide()
48
+ }
48
49
  }
49
- }
50
50
 
51
- show () {
52
- if(!this.enabled) return;
53
- this.active = true;
54
- this.el.classList.add('-active');
55
- if (this.popup) {
56
- this.popup.show()
57
- } else {
58
- this.popup = new Popover({
59
- content: this.content,
60
- anchor: this.el,
61
- align: this.options.align,
62
- container: this.options.container
63
- }).render();
64
- this.listenToOnce(this.popup, 'hidden', this.hidden)
51
+ show () {
52
+ if(!this.enabled) return;
53
+ this.active = true;
54
+ this.el.classList.add('-active');
55
+ if (this.popup) {
56
+ this.popup.show()
57
+ } else {
58
+ this.popup = new Popover({
59
+ content: this.content,
60
+ anchor: this.el,
61
+ align: this.options.align,
62
+ container: this.options.container
63
+ }).render();
64
+ this.listenToOnce(this.popup, 'hidden', this.hidden)
65
+ }
65
66
  }
66
- }
67
67
 
68
- hide () {
69
- this.popup.remove();
70
- delete this.popup;
71
- this.hidden();
72
- }
68
+ hide () {
69
+ this.popup.remove();
70
+ delete this.popup;
71
+ this.hidden();
72
+ }
73
73
 
74
- hidden () {
75
- this.active = false;
76
- this.el.classList.remove('-active');
77
- }
74
+ hidden () {
75
+ this.active = false;
76
+ this.el.classList.remove('-active');
77
+ }
78
78
 
79
- disable () {
80
- this.enabled = false;
81
- }
79
+ disable () {
80
+ this.enabled = false;
81
+ }
82
82
 
83
- enabled () {
84
- this.enabled = true;
85
- }
83
+ enabled () {
84
+ this.enabled = true;
85
+ }
86
86
  }
@@ -0,0 +1,107 @@
1
+ import Component from './component';
2
+ import { remove, append } from 'dolla';
3
+
4
+ /*
5
+ Options
6
+ ===
7
+ content: string|$el|function
8
+ el: element
9
+
10
+ */
11
+ export default class Dropzone extends Component {
12
+
13
+ enabled = true;
14
+
15
+ initialize (options) {
16
+ this.el.classList.add('uniformDropzone');
17
+ if (getComputedStyle(this.el)['position'] == "static") {
18
+ this.el.classList.add('relative');
19
+ }
20
+ if (typeof options.enabled == "boolean") {
21
+ this.enabled = options.enabled
22
+ }
23
+
24
+ this.windowDragEnter = this.windowDragEnter.bind(this)
25
+ this.windowDragLeave = this.windowDragLeave.bind(this)
26
+ this.windowDrop = this.windowDrop.bind(this)
27
+ this.el.addEventListener('drop', this.drop.bind(this))
28
+ this.el.addEventListener('dragover', this.dragOver.bind(this))
29
+ this.el.addEventListener('dragenter', this.dragEnter.bind(this))
30
+ this.el.addEventListener('dragleave', this.dragLeave.bind(this))
31
+ window.addEventListener('dragenter', this.windowDragEnter);
32
+ window.addEventListener('dragleave', this.windowDragLeave);
33
+ window.addEventListener('drop', this.windowDrop);
34
+
35
+ }
36
+
37
+ remove () {
38
+ window.removeEventListener('dragenter', this.windowDragEnter);
39
+ window.removeEventListener('dragleave', this.windowDragLeave);
40
+ window.removeEventListener('drop', this.windowDrop);
41
+ super.remove()
42
+ }
43
+
44
+ /*--------------------
45
+ This Events
46
+ --------------------*/
47
+ dragEnter (e) {
48
+ if (!this.enabled) return;
49
+ e.preventDefault();
50
+
51
+ this.el.classList.add('-active');
52
+ }
53
+
54
+ dragLeave (e) {
55
+ if (!this.enabled) return;
56
+ e.preventDefault();
57
+
58
+ // relatedTarget is what drag is going to, deals with dragging inside dropzone
59
+ if (!this.el.contains(e.relatedTarget)) {
60
+ this.el.classList.remove('-active');
61
+ }
62
+ }
63
+
64
+ drop (e) {
65
+ if (!this.enabled) return;
66
+ e.preventDefault();
67
+ ([...e.dataTransfer.files]).forEach(file => {
68
+ this.trigger('drop', file)
69
+ });
70
+ }
71
+
72
+ // Enables Dropzone
73
+ dragOver (e) {
74
+ if (!this.enabled) return;
75
+ e.preventDefault();
76
+ }
77
+
78
+
79
+ /*--------------------
80
+ Window Events
81
+ --------------------*/
82
+ windowDragEnter (e) {
83
+ if (!this.enabled) return;
84
+ e.preventDefault();
85
+
86
+ // Meaning it came from not in window
87
+ if (!e.relatedTarget) {
88
+ this.el.classList.add('-show')
89
+ }
90
+ }
91
+
92
+ windowDragLeave (e) {
93
+ if (!this.enabled) return;
94
+ e.preventDefault();
95
+
96
+ // Meaning it came from not in window
97
+ if (!e.relatedTarget) {
98
+ this.el.classList.remove('-show')
99
+ }
100
+ }
101
+
102
+ windowDrop (e) {
103
+ if (!this.enabled) return;
104
+ e.preventDefault();
105
+ this.el.classList.remove('-show')
106
+ }
107
+ }
@@ -1,23 +1,23 @@
1
1
  import Component from './component';
2
- import { isVisible, isFocus, hasClass, addClass, removeClass, css, createElement } from 'dolla';
2
+ import { isVisible, isFocus, css, createElement } from 'dolla';
3
3
 
4
4
  export default class FloatingLabel extends Component {
5
5
 
6
6
  initialize(options){
7
7
  if(options.input instanceof Element) {
8
- this.input = options.input
8
+ this.input = options.input
9
9
  } else {
10
- this.input = createElement('input', Object.assign({}, {
11
- type: this.constructor.type
12
- }, options.input)) // TODO filter options to dolla.HTML_ATTRIBUTES
10
+ this.input = createElement('input', Object.assign({}, {
11
+ type: this.constructor.type
12
+ }, options.input)) // TODO filter options to dolla.HTML_ATTRIBUTES
13
13
  }
14
14
  this.label = createElement('label', {
15
- for: this.input.id,
16
- children: [options.label]
15
+ for: this.input.id,
16
+ children: [options.label]
17
17
  });
18
18
  this.input.setAttribute('aria-label', options.label);
19
19
 
20
- addClass(this.el, 'uniformFloatingLabelInput');
20
+ this.el.classList.add('uniformFloatingLabelInput');
21
21
 
22
22
  this.listenTo(this.input, 'focus', this.focus);
23
23
  this.listenTo(this.input, 'blur', this.blur);
@@ -25,7 +25,7 @@ export default class FloatingLabel extends Component {
25
25
  }
26
26
 
27
27
  render () {
28
- if(!isVisible(this.input)) return;
28
+ if(!isVisible(this.input)) return this;
29
29
 
30
30
  let internalHeight = parseInt(css(this.input, 'height')) - parseInt(css(this.input, 'borderTopWidth')) - parseInt(css(this.input, 'borderBottomWidth'));
31
31
  this.input.style.lineHeight = 1;
@@ -47,17 +47,19 @@ export default class FloatingLabel extends Component {
47
47
  this.el.append(this.label);
48
48
 
49
49
  if(this.input.value != ""){
50
- this.focus()
50
+ this.focus()
51
51
  }
52
+
53
+ return this;
52
54
  }
53
55
 
54
56
  focus (e) {
55
- addClass(this.el, 'present');
57
+ this.el.classList.add('present');
56
58
  }
57
59
 
58
60
  blur (e) {
59
61
  if(this.input.value == ""){
60
- removeClass(this.el, 'present');
62
+ this.el.classList.remove('present');
61
63
  }
62
64
  }
63
65
  }
@@ -1,5 +1,5 @@
1
1
  import Component from './component';
2
- import {addClass, hasClass, removeClass, css, trigger} from 'dolla';
2
+ import {css, trigger, append, createElement} from 'dolla';
3
3
 
4
4
  /* UniformModal.initialize
5
5
  Options
@@ -16,7 +16,7 @@ export default class Modal extends Component {
16
16
  this.content = options.content;
17
17
  this.el.removeAttribute('content');
18
18
 
19
- addClass(this.el, 'uniformModal');
19
+ this.el.classList.add('uniformModal');
20
20
  this.listenTo(document, 'keyup', this.keyup);
21
21
  this.listenTo(this.el, 'click', this.checkCloseButton);
22
22
  }
@@ -28,14 +28,10 @@ export default class Modal extends Component {
28
28
 
29
29
  render () {
30
30
  var that = this;
31
- var content = typeof this.content == 'function' ? this.content() : this.content;
32
31
 
33
32
  this.highest_z_index = 0;
34
- this.overlay = document.createElement('div');
35
- addClass(this.overlay, 'uniformModal-overlay');
36
-
37
- this.blur = document.createElement('div');
38
- addClass(this.blur, 'uniformModal-blur');
33
+ this.overlay = createElement('div', {class: 'uniformModal-overlay'});
34
+ this.blur = createElement('div', {class: 'uniformModal-blur'});
39
35
 
40
36
  this.original_scroll = window.scrollY;
41
37
  this.blur.style.top = 0 - this.original_scroll + "px";
@@ -47,51 +43,53 @@ export default class Modal extends Component {
47
43
  this.el.style.zIndex = this.highest_z_index + 2;
48
44
  }
49
45
 
50
- this.el.appendChild(this.overlay);
51
-
52
46
  let next_element = document.body.children[0]
53
47
  while(next_element){
54
- const element = next_element;
55
- next_element = element.nextElementSibling;
56
- if(!element.matches('[blurrable="false"]')) {
57
- this.blur.appendChild(element)
58
- }
48
+ const element = next_element;
49
+ next_element = element.nextElementSibling;
50
+ if(!element.matches('[blurrable="false"]')) {
51
+ this.blur.appendChild(element)
52
+ }
59
53
  }
60
54
 
61
- addClass(document.body, 'uniformModal-active');
55
+ document.body.classList.add('uniformModal-active');
62
56
  document.body.appendChild(this.blur);
63
57
  document.body.appendChild(this.el);
64
58
 
65
- var container = document.createElement('div');
66
- addClass(container, 'uniformModal-container');
67
- if (content instanceof Node) {
68
- container.appendChild(content);
69
- } else {
70
- container.innerHTML = content;
71
- }
72
-
73
- var closeButton = document.createElement('div');
74
- addClass(closeButton, 'uniformModal-close');
75
- this.el.appendChild(closeButton);
76
-
77
59
  this.el.style.top = window.scrollY;
78
60
  this.listenTo(this.overlay, 'click', this.close);
79
- this.el.appendChild(container);
61
+
62
+ const container = createElement('div', {
63
+ class: 'uniformModal-container',
64
+ children: this.content
65
+ });
66
+
67
+ const closeButton = createElement('div', {
68
+ class: 'uniformModal-close-container',
69
+ children: {
70
+ class: 'uniformModal-close'
71
+ }
72
+ });
73
+
74
+ this.el.append(this.overlay);
75
+ this.el.append(container);
76
+ this.el.append(closeButton);
80
77
 
81
- if (this.options.klass) addClass(container, this.options.klass);
82
- if (content.innerHTML) trigger(content, 'rendered');
78
+ if (this.options.klass) container.classList.add(this.options.klass);
79
+ if (this.content.innerHTML) trigger(this.content, 'rendered');
83
80
  this.trigger('rendered');
84
81
 
85
82
  return this;
86
83
  }
87
84
 
88
85
  checkCloseButton (e) {
89
- if(hasClass(e.target, 'uniformModal-close'))
86
+ if(e.target.classList.contains('uniformModal-close')){
90
87
  this.close();
88
+ }
91
89
  }
92
90
 
93
91
  close () {
94
- removeClass(document.querySelectorAll('uniformModal-active'), 'uniformModal-active');
92
+ document.querySelectorAll('uniformModal-active').forEach(el => el.classList.remove('uniformModal-active'));
95
93
  var elements = this.blur.children;
96
94
  var elementCount = elements.length
97
95
  for(var i=0; i < elementCount; i++){