@internetstiftelsen/styleguide 3.0.11 → 3.0.13

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.
@@ -1,13 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var ranges = document.querySelectorAll('.js-range-wrapper');
4
- function setValue(range, rangeValue) {
4
+ function setValue(range, rangeValue, rangeInput) {
5
5
  var val = range.value;
6
6
  var min = range.min ? range.min : 0;
7
7
  var max = range.max ? range.max : 100;
8
8
  var newVal = Number((val - min) * 100 / (max - min));
9
9
  rangeValue.innerHTML = val;
10
10
 
11
+ if (rangeInput) {
12
+ rangeInput.value = val;
13
+ }
14
+
11
15
  // Sorta magic numbers based on size of the native UI thumb
12
16
  rangeValue.style.left = 'calc(' + newVal + '% + (' + (8 - newVal * 0.15) + 'px))';
13
17
  }
@@ -15,11 +19,23 @@ function setValue(range, rangeValue) {
15
19
  ranges.forEach(function (wrap) {
16
20
  var range = wrap.querySelector('.js-range');
17
21
  var rangeValue = wrap.querySelector('.js-range-value');
22
+ var rangeInput = wrap.querySelector('.js-range-input');
18
23
 
19
24
  range.addEventListener('input', function () {
20
- setValue(range, rangeValue);
25
+ setValue(range, rangeValue, rangeInput);
21
26
  range.focus();
22
27
  });
23
28
 
24
- setValue(range, rangeValue);
29
+ if (rangeInput) {
30
+ rangeInput.addEventListener('input', function () {
31
+ if (rangeInput.value !== '') {
32
+ range.value = rangeInput.value;
33
+ rangeValue.innerHTML = rangeInput.value;
34
+ setValue(range, rangeValue, rangeInput);
35
+ }
36
+ rangeInput.focus();
37
+ });
38
+ }
39
+
40
+ setValue(range, rangeValue, rangeInput);
25
41
  });
@@ -2,6 +2,13 @@
2
2
 
3
3
  window.a11yTabs = function tabsComponentIIFE(global, document) {
4
4
  var tabInstances = new WeakMap();
5
+ var className = 'o-tab-list';
6
+ var tablistElement = document.querySelector('.js-' + className);
7
+ var updateURLFromHash = void 0;
8
+
9
+ if (tablistElement) {
10
+ updateURLFromHash = tablistElement.getAttribute('data-update-url');
11
+ }
5
12
 
6
13
  /**
7
14
  * Instantiates the component
@@ -13,8 +20,6 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
13
20
  return;
14
21
  }
15
22
 
16
- var className = 'o-tab-list';
17
- var tablistElement = document.querySelector('.js-' + className);
18
23
  var namespace = getComputedStyle(tablistElement, ':before').content.replace(/["']/g, '');
19
24
 
20
25
  var defaults = {
@@ -46,7 +51,6 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
46
51
 
47
52
  this.tabLinks.forEach(function (item, index) {
48
53
  item.setAttribute('role', 'tab');
49
- // item.setAttribute('id', `tab${index}`);
50
54
 
51
55
  if (index > 0) {
52
56
  item.setAttribute('tabindex', '-1');
@@ -71,14 +75,10 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
71
75
 
72
76
  tabInstances.set(this.element, this);
73
77
 
74
- this.eventCallback = handleEvents.bind(this); // eslint-disable-line
75
- this.tabList.addEventListener('click', this.eventCallback, false);
76
- this.tabList.addEventListener('keydown', this.eventCallback, false);
77
-
78
- tabInstances.set(this.element, this);
79
-
80
- // New line to select the correct tab based on URL hash
81
- this.selectTabFromHash(); // Call the new method after setup
78
+ // Select the correct tab based on URL hash
79
+ if (updateURLFromHash) {
80
+ this.selectTabFromHash();
81
+ }
82
82
  };
83
83
 
84
84
  TabComponent.prototype = {
@@ -116,16 +116,18 @@ window.a11yTabs = function tabsComponentIIFE(global, document) {
116
116
  this.tabLinks[newIndex].setAttribute('aria-selected', 'true');
117
117
  this.tabItems[newIndex].setAttribute('data-tab-active', '');
118
118
  this.tabLinks[newIndex].removeAttribute('tabindex');
119
- this.tabLinks[newIndex].focus();
119
+ this.tabLinks[newIndex].focus(); // Focus the newly selected tab
120
120
 
121
121
  // update tab panels
122
122
  this.tabPanels[currentIndex].setAttribute('hidden', '');
123
123
  this.tabPanels[newIndex].removeAttribute('hidden');
124
124
 
125
- // After updating tabs and tab panels, add the URL update feature
126
125
  // Update the browser's URL hash to reflect the current tab's ID
127
126
  var selectedTabId = this.tabLinks[newIndex].id;
128
- global.history.pushState(null, '', '#' + selectedTabId);
127
+
128
+ if (updateURLFromHash) {
129
+ window.history.pushState(null, '', '#' + selectedTabId);
130
+ }
129
131
 
130
132
  this.currentIndex = newIndex;
131
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetstiftelsen/styleguide",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "main": "dist/components.js",
5
5
  "ports": {
6
6
  "fractal": "3000"
@@ -18,6 +18,10 @@
18
18
  @include m(discreet) {
19
19
  @extend %discreet;
20
20
  }
21
+ @include m(small) {
22
+ font-size: $size-medium;
23
+ padding: rhythm(0.5);
24
+ }
21
25
  }
22
26
 
23
27
  @include b(input-icon) {
@@ -6,6 +6,7 @@
6
6
  background: transparent;
7
7
  cursor: pointer;
8
8
  width: 100%;
9
+ position: relative;
9
10
 
10
11
  &::-webkit-slider-runnable-track {
11
12
  background-color: $color-concrete;
@@ -76,6 +77,12 @@
76
77
  box-shadow: 0 0 0 inset rgba($color-cyberspace, 0.2), 0 1px 2px rgba($color-cyberspace, 0.2), 0 0 0 3px $color-ocean-light;
77
78
  }
78
79
 
80
+ @include m(no-preview) {
81
+ & + output {
82
+ display: none;
83
+ }
84
+ }
85
+
79
86
  @include e(value){
80
87
  background-color: $color-concrete;
81
88
  padding: rhythm(0.5) rhythm(1);
@@ -102,3 +109,11 @@
102
109
  }
103
110
  }
104
111
 
112
+ @include atom(range-input) {
113
+ position: absolute;
114
+ top: 0;
115
+ right: 0;
116
+ z-index: 0;
117
+ width: rhythm(5);
118
+ }
119
+
@@ -41,5 +41,26 @@ module.exports = {
41
41
  step: '1',
42
42
  }
43
43
  },
44
+ {
45
+ name: 'Text input',
46
+ context: {
47
+ input: true,
48
+ value: '0',
49
+ min: '0',
50
+ max: '100',
51
+ step: '1',
52
+ }
53
+ },
54
+ {
55
+ name: 'No preview',
56
+ context: {
57
+ no_preview: true,
58
+ input: true,
59
+ value: '0',
60
+ min: '0',
61
+ max: '100',
62
+ step: '1',
63
+ }
64
+ }
44
65
  ]
45
66
  }
@@ -1,11 +1,15 @@
1
1
  const ranges = document.querySelectorAll('.js-range-wrapper');
2
- function setValue(range, rangeValue) {
2
+ function setValue(range, rangeValue, rangeInput) {
3
3
  const val = range.value;
4
4
  const min = range.min ? range.min : 0;
5
5
  const max = range.max ? range.max : 100;
6
6
  const newVal = Number(((val - min) * 100) / (max - min));
7
7
  rangeValue.innerHTML = val;
8
8
 
9
+ if (rangeInput) {
10
+ rangeInput.value = val;
11
+ }
12
+
9
13
  // Sorta magic numbers based on size of the native UI thumb
10
14
  rangeValue.style.left = `calc(${newVal}% + (${8 - newVal * 0.15}px))`;
11
15
  }
@@ -13,11 +17,23 @@ function setValue(range, rangeValue) {
13
17
  ranges.forEach((wrap) => {
14
18
  const range = wrap.querySelector('.js-range');
15
19
  const rangeValue = wrap.querySelector('.js-range-value');
20
+ const rangeInput = wrap.querySelector('.js-range-input');
16
21
 
17
22
  range.addEventListener('input', () => {
18
- setValue(range, rangeValue);
23
+ setValue(range, rangeValue, rangeInput);
19
24
  range.focus();
20
25
  });
21
26
 
22
- setValue(range, rangeValue);
27
+ if (rangeInput) {
28
+ rangeInput.addEventListener('input', () => {
29
+ if (rangeInput.value !== '') {
30
+ range.value = rangeInput.value;
31
+ rangeValue.innerHTML = rangeInput.value;
32
+ setValue(range, rangeValue, rangeInput);
33
+ }
34
+ rangeInput.focus();
35
+ });
36
+ }
37
+
38
+ setValue(range, rangeValue, rangeInput);
23
39
  });
@@ -2,7 +2,11 @@ window.a11yTabs = (function tabsComponentIIFE(global, document) {
2
2
  const tabInstances = new WeakMap();
3
3
  const className = 'o-tab-list';
4
4
  const tablistElement = document.querySelector(`.js-${className}`);
5
- const updateURLFromHash = tablistElement.getAttribute('data-update-url');
5
+ let updateURLFromHash;
6
+
7
+ if (tablistElement) {
8
+ updateURLFromHash = tablistElement.getAttribute('data-update-url');
9
+ }
6
10
 
7
11
  /**
8
12
  * Instantiates the component