@internetstiftelsen/styleguide 2.21.0 → 2.21.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.
@@ -48,4 +48,6 @@ require('./molecules/glider/glider-single');
48
48
 
49
49
  require('./atoms/timeline/anchorScroll');
50
50
 
51
- require('./molecules/timeline-navigation/timeline-navigation');
51
+ require('./molecules/timeline-navigation/timeline-navigation');
52
+
53
+ require('./molecules/context-menu/context-menu');
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var elements = document.querySelectorAll('[data-close-on-outside-click]');
4
+
5
+ function closeElement(element) {
6
+ document.addEventListener('mouseup', function (e) {
7
+ var childElement = element.nextElementSibling;
8
+
9
+ /* Close menu on all clicks except the trigger button,
10
+ the menu and it's child elements and if the menu is actually open. */
11
+ if (!element.contains(e.target) && !childElement.contains(e.target) && element.getAttribute('aria-expanded') === 'true') {
12
+ element.click();
13
+ }
14
+ });
15
+ }
16
+
17
+ if (elements) {
18
+ [].forEach.call(elements, closeElement);
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetstiftelsen/styleguide",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
4
4
  "main": "dist/components.js",
5
5
  "ports": {
6
6
  "fractal": "3000"
package/src/.DS_Store ADDED
Binary file
Binary file
Binary file
package/src/components.js CHANGED
@@ -23,3 +23,4 @@ import './molecules/glider/glider';
23
23
  import './molecules/glider/glider-single';
24
24
  import './atoms/timeline/anchorScroll';
25
25
  import './molecules/timeline-navigation/timeline-navigation';
26
+ import './molecules/context-menu/context-menu';
Binary file
@@ -4,14 +4,24 @@ module.exports = {
4
4
  context: {
5
5
  name: 'Context menu',
6
6
  controls: 'contextMenu',
7
- focusTrap: true
7
+ focusTrap: true,
8
+ outsideClick: false
8
9
  },
9
10
  variants: [
10
11
  {
11
12
  name: 'No focus trap',
12
13
  context: {
13
14
  controls: 'contextMenu2',
14
- focusTrap: false
15
+ focusTrap: false,
16
+ outsideClick: false
17
+ }
18
+ },
19
+ {
20
+ name: 'Close on outside click',
21
+ context: {
22
+ controls: 'contextMenu3',
23
+ focusTrap: false,
24
+ outsideClick: true
15
25
  }
16
26
  }
17
27
  ]
@@ -1,5 +1,5 @@
1
1
  <nav class="m-context-menu js-context-menu">
2
- <button type="button" class="a-button a-button--icon a-button--transparent a-button--icon js-context-menu-btn" aria-expanded="false" data-a11y-toggle="{{controls}}" aria-controls="{{controls}}">
2
+ <button type="button" class="a-button a-button--icon a-button--transparent a-button--icon js-context-menu-btn" aria-expanded="false" data-a11y-toggle="{{controls}}" aria-controls="{{controls}}" {{#if outsideClick}}data-close-on-outside-click="true"{{/if}}>
3
3
  <span class="a-button__text">Exportera</span>
4
4
  <svg class="icon a-button__icon">
5
5
  <use xlink:href="#icon-download"></use>
@@ -0,0 +1,17 @@
1
+ const elements = document.querySelectorAll('[data-close-on-outside-click]');
2
+
3
+ function closeElement(element) {
4
+ document.addEventListener('mouseup', (e) => {
5
+ const childElement = element.nextElementSibling;
6
+
7
+ /* Close menu on all clicks except the trigger button,
8
+ the menu and it's child elements and if the menu is actually open. */
9
+ if (!element.contains(e.target) && !childElement.contains(e.target) && element.getAttribute('aria-expanded') === 'true') {
10
+ element.click();
11
+ }
12
+ });
13
+ }
14
+
15
+ if (elements) {
16
+ [].forEach.call(elements, closeElement);
17
+ }
@@ -11,6 +11,11 @@ $fill-color: $color-black;
11
11
  background-position: center center !important;
12
12
 
13
13
  // Sizes
14
+ @include m(smallest) {
15
+ width: $icon-size-smallest !important;
16
+ height: $icon-size-smallest !important;
17
+ }
18
+
14
19
  @include m(small) {
15
20
  width: $icon-size-small !important;
16
21
  height: $icon-size-small !important;