@ons/design-system 46.0.0 → 46.1.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 ONS Digital
3
+ Copyright (c) 2018 Crown Copyright (Office for National Statistics)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -12,7 +12,7 @@
12
12
  }
13
13
 
14
14
  &__subject {
15
- margin: 0;
15
+ margin: 0 0 0.2rem;
16
16
  }
17
17
 
18
18
  &__metadata {
@@ -1,4 +1,4 @@
1
- {% macro onsModal(params) %}
1
+ {% macro onsModal(params) %}
2
2
  {% set modalID = params.id | default('dialog') %}
3
3
  <dialog class="ons-modal ons-js-modal {{ params.classes }}"
4
4
  id="{{ modalID }}"
@@ -29,6 +29,8 @@
29
29
  {% if params is defined and params and params.type == "warn-branded" or params.type == "announcement" %}
30
30
  <div class="{{containerClass}}">
31
31
  <div class="ons-container">
32
+ {% elif params.type is defined and params.type == "warn" %}
33
+ <div class="ons-container">
32
34
  {% endif %}
33
35
 
34
36
  <div {% if params is defined and params and params.type == 'error' and params.title is defined and params.title %}aria-labelledby="error-summary-title" role="alert" tabindex="-1" {% if params.dsExample != true %}autofocus="autofocus" {% endif %}{% endif %}class="ons-panel{{ typeClass }}{{ iconClass }}{{ noTitleClass }}{{ spaciousClass }}{{ classes }}"{% if params is defined and params and params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params is defined and params and params.attributes is mapping and params.attributes.items is defined and params.attributes.items else params.attributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}{% if params is defined and params and params.id is defined and params.id %} id="{{params.id}}"{% endif %}>
@@ -86,7 +88,7 @@
86
88
  {% endif %}
87
89
  {% endif %}
88
90
 
89
- <div class="ons-panel__body{% if params is defined and params and params.iconSize is defined and params.iconSize %} ons-svg-icon-margin--{{ params.iconSize }}{% endif %}" {% if params is defined and params and params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params is defined and params and params.attributes is mapping and params.attributes.items is defined and params.attributes.items else params.attributes) %}{{attribute}}="{{value}}" {% endfor %}{% endif %}>{{ (params.body if params else "") | safe }}
91
+ <div class="ons-panel__body{% if params is defined and params and params.iconSize is defined and params.iconSize %} ons-svg-icon-margin--{{ params.iconSize }}{% endif %}">{{ (params.body if params else "") | safe }}
90
92
  {{ caller() if caller }}
91
93
  </div>
92
94
 
@@ -95,6 +97,8 @@
95
97
  {% if params is defined and params and params.type == "warn-branded" or params.type == "announcement" %}
96
98
  </div>
97
99
  </div>
100
+ {% elif params.type is defined and params.type == "warn" %}
101
+ </div>
98
102
  {% endif %}
99
103
 
100
104
  {% endmacro %}
@@ -47,6 +47,10 @@
47
47
  padding: 0.75rem 1rem;
48
48
  }
49
49
 
50
+ &__timer {
51
+ white-space: nowrap;
52
+ }
53
+
50
54
  &__title {
51
55
  margin: 0;
52
56
  }
@@ -33,9 +33,10 @@
33
33
  color: $color-text;
34
34
  display: inline-block;
35
35
  height: 2.5rem;
36
+ line-height: 2.3rem;
36
37
  margin: 0 0.1rem 0 0;
37
38
  overflow: visible;
38
- padding: 0.5rem 1rem;
39
+ padding: 0 1rem;
39
40
  position: relative;
40
41
  text-decoration: underline;
41
42
 
@@ -1,5 +1,5 @@
1
1
  {% from "components/modal/_macro.njk" import onsModal %}
2
- {% macro onsTimeoutModal(params) %}
2
+ {% macro onsTimeoutModal(params) %}
3
3
  {% call onsModal({
4
4
  "title": params.title,
5
5
  "btnText": params.btnText,
@@ -10,11 +10,12 @@
10
10
  "data-show-modal-time": params.showModalTimeInSeconds,
11
11
  "data-server-session-expiry-endpoint": params.serverSessionExpiryEndpoint,
12
12
  "data-countdown-text": params.countdownText,
13
- "data-redirecting-text": params.redirectingText,
13
+ "data-countdown-expired-text": params.countdownExpiredText,
14
14
  "data-minutes-text-singular": params.minutesTextSingular,
15
15
  "data-minutes-text-plural": params.minutesTextPlural,
16
16
  "data-seconds-text-singular": params.secondsTextSingular,
17
17
  "data-seconds-text-plural": params.secondsTextPlural,
18
+ "data-full-stop": params.endWithFullStop,
18
19
  "aria-describedby": "timeout-time-remaining"
19
20
  }
20
21
  })
@@ -4,12 +4,12 @@ async function modals() {
4
4
  const timeouts = [...document.querySelectorAll('.ons-js-timeout-modal')];
5
5
 
6
6
  if (timeouts.length) {
7
- const Timeout = (await import('./timeout')).default;
7
+ const TimeoutModal = (await import('./timeout-modal')).default;
8
8
 
9
9
  timeouts.forEach(context => {
10
10
  let url = context.getAttribute('data-server-session-expiry-endpoint');
11
11
  let time = context.getAttribute('data-server-session-expires-at');
12
- new Timeout(context, url, time);
12
+ new TimeoutModal(context, url, time);
13
13
  });
14
14
  }
15
15
  }
@@ -0,0 +1,62 @@
1
+ import Modal from '../modal/modal';
2
+ import Timeout from '../../js/timeout';
3
+
4
+ export default class TimeoutModal {
5
+ constructor(context, sessionExpiryEndpoint, initialExpiryTime) {
6
+ this.context = context;
7
+ this.sessionExpiryEndpoint = sessionExpiryEndpoint;
8
+ this.initialExpiryTime = initialExpiryTime;
9
+ this.continueButton = context.querySelector('.ons-js-modal-btn');
10
+ this.modalVisibleInMilliseconds = context.getAttribute('data-show-modal-time') * 1000;
11
+
12
+ // Create modal instance
13
+ this.modal = new Modal(this.context);
14
+
15
+ // Create timeout instance
16
+ this.timeout = new Timeout(this.context, this.sessionExpiryEndpoint, this.initialExpiryTime, true);
17
+
18
+ this.bindEventListeners();
19
+ }
20
+
21
+ bindEventListeners() {
22
+ window.onload = this.startTimeout();
23
+ window.addEventListener('keydown', this.escToClose.bind(this));
24
+ this.continueButton.addEventListener('click', this.closeModalAndRestartTimeout.bind(this));
25
+ }
26
+
27
+ startTimeout() {
28
+ clearTimeout(this.showModalTimeout);
29
+ if (this.initialExpiryTime) {
30
+ this.totalMilliseconds = this.timeout.expiryTimeInMilliseconds;
31
+ } else {
32
+ // For demo purposes
33
+ this.totalMilliseconds = 60000;
34
+ }
35
+ this.showModalTimeout = setTimeout(
36
+ this.openModalAndStartCountdown.bind(this),
37
+ this.totalMilliseconds - this.modalVisibleInMilliseconds,
38
+ );
39
+ }
40
+
41
+ async openModalAndStartCountdown() {
42
+ const modalWillOpen = await this.timeout.hasExpiryTimeResetInAnotherTab();
43
+ if (modalWillOpen && !this.modal.isDialogOpen()) {
44
+ this.modal.openDialog();
45
+ this.timeout.startUiCountdown();
46
+ }
47
+ }
48
+
49
+ closeModalAndRestartTimeout() {
50
+ if (this.modal.isDialogOpen()) {
51
+ this.modal.closeDialog();
52
+ }
53
+ this.timeout.restartTimeout();
54
+ this.startTimeout();
55
+ }
56
+
57
+ escToClose(event) {
58
+ if (this.modal.isDialogOpen() && event.keyCode === 27) {
59
+ this.closeModalAndRestartTimeout();
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,26 @@
1
+ {% from "components/panel/_macro.njk" import onsPanel %}
2
+ {% macro onsTimeoutPanel(params) %}
3
+ {% call onsPanel({
4
+ "id": params.id,
5
+ "classes": "ons-js-panel-with-countdown",
6
+ "type": "warn",
7
+ "attributes": {
8
+ "data-redirect-url": params.redirectUrl,
9
+ "data-server-session-expires-at": params.sessionExpiresAt,
10
+ "data-server-session-expiry-endpoint": params.serverSessionExpiryEndpoint,
11
+ "data-countdown-text": params.countdownText,
12
+ "data-countdown-expired-text": params.countdownExpiredText,
13
+ "data-minutes-text-singular": params.minutesTextSingular,
14
+ "data-minutes-text-plural": params.minutesTextPlural,
15
+ "data-seconds-text-singular": params.secondsTextSingular,
16
+ "data-seconds-text-plural": params.secondsTextPlural,
17
+ "data-full-stop": params.endWithFullStop,
18
+ "aria-describedby": "timeout-time-remaining"
19
+ }
20
+ })
21
+ %}
22
+ <noscript><p class="ons-js-nojs-text">{{ params.nojsText }}</p></noscript>
23
+ <p class="ons-js-timeout-timer" aria-hidden="true" aria-relevant="additions"></p>
24
+ <p class="ons-js-timeout-timer-acc ons-u-vh" role="status" id="timeout-time-remaining"></p>
25
+ {% endcall %}
26
+ {% endmacro %}
@@ -0,0 +1,17 @@
1
+ import domready from '../../js/domready';
2
+
3
+ async function timeoutPanels() {
4
+ const panels = [...document.querySelectorAll('.ons-js-panel-with-countdown')];
5
+
6
+ if (panels.length) {
7
+ const Timeout = (await import('../../js/timeout')).default;
8
+
9
+ panels.forEach(context => {
10
+ let url = context.getAttribute('data-server-session-expiry-endpoint');
11
+ let time = context.getAttribute('data-server-session-expires-at');
12
+ new Timeout(context, url, time, false, true);
13
+ });
14
+ }
15
+ }
16
+
17
+ domready(timeoutPanels);