nsw-design-system 3.1.0 → 3.2.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/dist/js/main.js CHANGED
@@ -383,9 +383,13 @@
383
383
  }, {
384
384
  key: "buttonClickDesktop",
385
385
  value: function buttonClickDesktop(e) {
386
- this.saveElements(e);
387
- this.toggleSubNavDesktop();
388
- e.preventDefault();
386
+ var isDesktop = this.breakpoint.matches;
387
+
388
+ if (!isDesktop || !e.target.closest('.nsw-main-nav__sub-nav')) {
389
+ this.saveElements(e);
390
+ this.toggleSubNavDesktop();
391
+ e.preventDefault();
392
+ }
389
393
  }
390
394
  }, {
391
395
  key: "buttonKeydownDesktop",
@@ -686,6 +690,93 @@
686
690
  return Accordion;
687
691
  }();
688
692
 
693
+ var Dialog = /*#__PURE__*/function () {
694
+ function Dialog(element) {
695
+ var _this = this;
696
+
697
+ _classCallCheck(this, Dialog);
698
+
699
+ this.dialog = element;
700
+ this.dialogWrapper = element.querySelector('.nsw-dialog__wrapper');
701
+ this.openBtn = document.querySelectorAll('.js-open-dialog-'.concat(element.getAttribute('id')));
702
+ this.closeBtn = element.querySelectorAll('.js-close-dialog'); // eslint-disable-next-line max-len
703
+
704
+ this.focusableEls = element.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])');
705
+ this.body = document.body;
706
+
707
+ this.openEvent = function (e) {
708
+ return _this.openDialog(e);
709
+ };
710
+
711
+ this.closeEvent = function (e) {
712
+ return _this.closeDialog(e);
713
+ };
714
+
715
+ this.clickEvent = function (e) {
716
+ return _this.clickDialog(e);
717
+ };
718
+
719
+ this.trapEvent = function (e) {
720
+ return _this.trapFocus(e);
721
+ };
722
+ }
723
+
724
+ _createClass(Dialog, [{
725
+ key: "init",
726
+ value: function init() {
727
+ this.controls();
728
+ }
729
+ }, {
730
+ key: "controls",
731
+ value: function controls() {
732
+ var _this2 = this;
733
+
734
+ this.openBtn.forEach(function (btn) {
735
+ btn.addEventListener('click', _this2.openEvent, false);
736
+ });
737
+ this.closeBtn.forEach(function (btn) {
738
+ btn.addEventListener('click', _this2.closeEvent, false);
739
+ });
740
+
741
+ if (this.dialog.classList.contains('js-dialog-dismiss')) {
742
+ this.dialog.addEventListener('click', this.clickEvent, false);
743
+ }
744
+
745
+ this.focusableEls[this.focusableEls.length - 1].addEventListener('blur', this.trapEvent, false);
746
+ }
747
+ }, {
748
+ key: "openDialog",
749
+ value: function openDialog() {
750
+ this.dialog.setAttribute('aria-expanded', 'true');
751
+ this.dialog.classList.add('active');
752
+ this.body.classList.add('dialog-active');
753
+ this.focusableEls[0].focus();
754
+ }
755
+ }, {
756
+ key: "closeDialog",
757
+ value: function closeDialog() {
758
+ this.dialog.setAttribute('aria-expanded', 'false');
759
+ this.dialog.classList.remove('active');
760
+ this.body.classList.remove('dialog-active');
761
+ }
762
+ }, {
763
+ key: "clickDialog",
764
+ value: function clickDialog(e) {
765
+ if (!this.dialogWrapper.contains(e.target)) {
766
+ this.closeDialog();
767
+ }
768
+ }
769
+ }, {
770
+ key: "trapFocus",
771
+ value: function trapFocus(e) {
772
+ e.preventDefault();
773
+ this.focusableEls[0].focus();
774
+ }
775
+ }]);
776
+
777
+ return Dialog;
778
+ }();
779
+
689
780
  var Filters = /*#__PURE__*/function () {
690
781
  function Filters(element) {
691
782
  var _this = this;
@@ -1001,6 +1092,7 @@
1001
1092
  var openSearchButton = document.querySelectorAll('.js-open-search');
1002
1093
  var closeSearchButton = document.querySelectorAll('.js-close-search');
1003
1094
  var accordions = document.querySelectorAll('.js-accordion');
1095
+ var dialogs = document.querySelectorAll('.js-dialog');
1004
1096
  var filters = document.querySelectorAll('.js-filters');
1005
1097
  var tabs = document.querySelectorAll('.js-tabs');
1006
1098
  var globalAlert = document.querySelectorAll('.js-global-alert');
@@ -1015,6 +1107,9 @@
1015
1107
  accordions.forEach(function (element) {
1016
1108
  new Accordion(element).init();
1017
1109
  });
1110
+ dialogs.forEach(function (element) {
1111
+ new Dialog(element).init();
1112
+ });
1018
1113
 
1019
1114
  if (filters) {
1020
1115
  filters.forEach(function (element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsw-design-system",
3
- "version": "3.1.0",
3
+ "version": "3.2.2",
4
4
  "description": "Design system for Digital NSW",
5
5
  "main": "dist/main.js",
6
6
  "style": "dist/main.css",
@@ -1,4 +1,5 @@
1
1
  @import 'accordion/accordion';
2
+ @import 'dialog/dialog';
2
3
  @import 'breadcrumbs/breadcrumbs';
3
4
  @import 'button/button';
4
5
  @import 'callout/callout';
@@ -0,0 +1,156 @@
1
+ .dialog-active {
2
+ overflow: hidden;
3
+ }
4
+
5
+ .nsw-dialog {
6
+ @include z-index('upper');
7
+ display: none;
8
+ position: fixed;
9
+ left: 0;
10
+ right: 0;
11
+ top: 0;
12
+ bottom: 0;
13
+ background-color: rgba(var(--nsw-black-rgb), 0.7);
14
+ justify-content: center;
15
+ align-items: flex-end;
16
+
17
+ @include breakpoint('sm') {
18
+ align-items: center;
19
+ padding: 0 rem(16px);
20
+ }
21
+
22
+ &.active {
23
+ display: flex;
24
+ }
25
+
26
+ &__wrapper {
27
+ background-color: var(--nsw-white);
28
+ width: 100%;
29
+ max-width: rem(736px);
30
+ position: relative;
31
+ padding-bottom: rem(145px);
32
+
33
+ @include breakpoint('sm') {
34
+ border-radius: var(--nsw-border-radius);
35
+ align-items: center;
36
+ max-height: 90%;
37
+ }
38
+
39
+ @include breakpoint('md') {
40
+ padding-bottom: rem(81px);
41
+ }
42
+
43
+ @include breakpoint('lg') {
44
+ padding-bottom: rem(113px);
45
+ }
46
+
47
+ .nsw-dialog--single-action & {
48
+ padding-bottom: rem(81px);
49
+
50
+ @include breakpoint('lg') {
51
+ padding-bottom: rem(113px);
52
+ }
53
+ }
54
+ }
55
+
56
+ &__container {
57
+ height: 100%;
58
+ max-height: calc(100vh - #{rem(145px)});
59
+ overflow-y: auto;
60
+
61
+ @include breakpoint('sm') {
62
+ max-height: calc(90vh - #{rem(145px)});
63
+ }
64
+
65
+ @include breakpoint('md') {
66
+ max-height: calc(90vh - #{rem(81px)});
67
+ }
68
+
69
+ @include breakpoint('lg') {
70
+ max-height: calc(90vh - #{rem(113px)});
71
+ }
72
+
73
+ .nsw-dialog--single-action & {
74
+ max-height: calc(100vh - #{rem(81px)});
75
+
76
+ @include breakpoint('sm') {
77
+ max-height: calc(90vh - #{rem(81px)});
78
+ }
79
+
80
+ @include breakpoint('lg') {
81
+ max-height: calc(90vh - #{rem(113px)});
82
+ }
83
+ }
84
+ }
85
+
86
+ &__top {
87
+ border-bottom: 1px solid var(--nsw-grey-04);
88
+ display: flex;
89
+ }
90
+
91
+ &__title {
92
+ padding: rem(16px);
93
+ width: 100%;
94
+
95
+ @include breakpoint('lg') {
96
+ padding: rem(32px);
97
+ }
98
+ }
99
+
100
+ &__close {
101
+ min-width: rem(48px);
102
+ max-width: rem(48px);
103
+ padding: rem(8px) rem(8px) rem(8px) 0;
104
+
105
+ @include breakpoint('lg') {
106
+ min-width: rem(64px);
107
+ max-width: rem(64px);
108
+ padding: rem(24px) rem(24px) rem(24px) 0;
109
+ }
110
+ }
111
+
112
+ &__content {
113
+ padding: rem(16px);
114
+
115
+ @include breakpoint('lg') {
116
+ padding: rem(32px);
117
+ }
118
+ }
119
+
120
+ &__bottom {
121
+ border-top: 1px solid var(--nsw-grey-04);
122
+ position: absolute;
123
+ bottom: 0;
124
+ left: 0;
125
+ right: 0;
126
+ display: flex;
127
+ flex-direction: column;
128
+ padding: rem(16px);
129
+
130
+ @include breakpoint('md') {
131
+ flex-direction: row-reverse;
132
+ justify-content: flex-start;
133
+ }
134
+
135
+ @include breakpoint('lg') {
136
+ padding: rem(32px);
137
+ }
138
+
139
+ button {
140
+ margin-bottom: rem(16px);
141
+
142
+ @include breakpoint('md') {
143
+ margin-left: rem(16px);
144
+ margin-bottom: 0;
145
+ }
146
+
147
+ &:last-child {
148
+ margin-bottom: 0;
149
+
150
+ @include breakpoint('md') {
151
+ margin-left: 0;
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,60 @@
1
+ class Dialog {
2
+ constructor(element) {
3
+ this.dialog = element
4
+ this.dialogWrapper = element.querySelector('.nsw-dialog__wrapper')
5
+ this.openBtn = document.querySelectorAll('.js-open-dialog-'.concat(element.getAttribute('id')))
6
+ this.closeBtn = element.querySelectorAll('.js-close-dialog')
7
+ // eslint-disable-next-line max-len
8
+ this.focusableEls = element.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])')
9
+ this.body = document.body
10
+ this.openEvent = (e) => this.openDialog(e)
11
+ this.closeEvent = (e) => this.closeDialog(e)
12
+ this.clickEvent = (e) => this.clickDialog(e)
13
+ this.trapEvent = (e) => this.trapFocus(e)
14
+ }
15
+
16
+ init() {
17
+ this.controls()
18
+ }
19
+
20
+ controls() {
21
+ this.openBtn.forEach((btn) => {
22
+ btn.addEventListener('click', this.openEvent, false)
23
+ })
24
+ this.closeBtn.forEach((btn) => {
25
+ btn.addEventListener('click', this.closeEvent, false)
26
+ })
27
+
28
+ if (this.dialog.classList.contains('js-dialog-dismiss')) {
29
+ this.dialog.addEventListener('click', this.clickEvent, false)
30
+ }
31
+
32
+ this.focusableEls[this.focusableEls.length - 1].addEventListener('blur', this.trapEvent, false)
33
+ }
34
+
35
+ openDialog() {
36
+ this.dialog.setAttribute('aria-expanded', 'true')
37
+ this.dialog.classList.add('active')
38
+ this.body.classList.add('dialog-active')
39
+ this.focusableEls[0].focus()
40
+ }
41
+
42
+ closeDialog() {
43
+ this.dialog.setAttribute('aria-expanded', 'false')
44
+ this.dialog.classList.remove('active')
45
+ this.body.classList.remove('dialog-active')
46
+ }
47
+
48
+ clickDialog(e) {
49
+ if (!this.dialogWrapper.contains(e.target)) {
50
+ this.closeDialog()
51
+ }
52
+ }
53
+
54
+ trapFocus(e) {
55
+ e.preventDefault()
56
+ this.focusableEls[0].focus()
57
+ }
58
+ }
59
+
60
+ export default Dialog
@@ -104,6 +104,30 @@
104
104
  }
105
105
  }
106
106
 
107
+ &__links {
108
+ @include breakpoint('md') {
109
+ display: flex;
110
+ justify-content: space-between;
111
+ margin-top: rem(-16px);
112
+ }
113
+ }
114
+
115
+ &__social {
116
+ display: flex;
117
+ flex-wrap: wrap;
118
+ align-items: center;
119
+ margin: 0 rem(-12px);
120
+ padding: rem(8px) 0 rem(12px) 0;
121
+
122
+ @include breakpoint('md') {
123
+ padding-bottom: rem(8px);
124
+ }
125
+
126
+ a {
127
+ margin: 0 rem(4px);
128
+ }
129
+ }
130
+
107
131
  &__info {
108
132
  @include breakpoint('md') {
109
133
  display: flex;
@@ -124,4 +148,25 @@
124
148
  text-align: right;
125
149
  }
126
150
  }
151
+
152
+ &--dark {
153
+ .nsw-footer__lower {
154
+ background-color: var(--nsw-brand-dark);
155
+ }
156
+ }
157
+
158
+ &--light {
159
+ hr {
160
+ background-color: var(--nsw-grey-02);
161
+ }
162
+
163
+ .nsw-footer__lower {
164
+ background-color: var(--nsw-brand-light);
165
+ color: var(--nsw-text-dark);
166
+
167
+ a {
168
+ @include link-dark;
169
+ }
170
+ }
171
+ }
127
172
  }
@@ -134,7 +134,7 @@
134
134
 
135
135
  @include breakpoint('xl') {
136
136
  width: 50%;
137
- padding-left: calc(var(--nsw-container-width)/12+#{rem($grid-gutters)}*2);
137
+ padding-left: calc(var(--nsw-container-width)/12 + #{rem($grid-gutters)}*2);
138
138
  }
139
139
  }
140
140
 
@@ -174,6 +174,10 @@
174
174
  }
175
175
  }
176
176
 
177
+ &--off-white {
178
+ background-color: var(--nsw-off-white);
179
+ }
180
+
177
181
  &--dark {
178
182
  background-color: var(--nsw-brand-dark);
179
183
 
@@ -226,7 +230,7 @@
226
230
 
227
231
  @include breakpoint('xl') {
228
232
  width: 50%;
229
- padding-left: calc(var(--nsw-container-width)/4+#{rem($grid-gutters)}*2);
233
+ padding-left: calc(var(--nsw-container-width)/4 + #{rem($grid-gutters)}*2);
230
234
  }
231
235
  }
232
236
  }
@@ -139,9 +139,12 @@ class Navigation {
139
139
  }
140
140
 
141
141
  buttonClickDesktop(e) {
142
- this.saveElements(e)
143
- this.toggleSubNavDesktop()
144
- e.preventDefault()
142
+ const isDesktop = this.breakpoint.matches
143
+ if (!isDesktop || !e.target.closest('.nsw-main-nav__sub-nav')) {
144
+ this.saveElements(e)
145
+ this.toggleSubNavDesktop()
146
+ e.preventDefault()
147
+ }
145
148
  }
146
149
 
147
150
  buttonKeydownDesktop(e) {
package/src/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import SiteSearch from './components/header/header'
2
2
  import Navigation from './components/main-nav/main-nav'
3
3
  import Accordion from './components/accordion/accordion'
4
+ import Dialog from './components/dialog/dialog'
4
5
  import Filters from './components/filters/filters'
5
6
  import Tabs from './components/tabs/tabs'
6
7
  import GlobalAlert from './components/global-alert/global-alert'
@@ -30,6 +31,7 @@ function initSite() {
30
31
  const openSearchButton = document.querySelectorAll('.js-open-search')
31
32
  const closeSearchButton = document.querySelectorAll('.js-close-search')
32
33
  const accordions = document.querySelectorAll('.js-accordion')
34
+ const dialogs = document.querySelectorAll('.js-dialog')
33
35
  const filters = document.querySelectorAll('.js-filters')
34
36
  const tabs = document.querySelectorAll('.js-tabs')
35
37
  const globalAlert = document.querySelectorAll('.js-global-alert')
@@ -49,6 +51,10 @@ function initSite() {
49
51
  new Accordion(element).init()
50
52
  })
51
53
 
54
+ dialogs.forEach((element) => {
55
+ new Dialog(element).init()
56
+ })
57
+
52
58
  if (filters) {
53
59
  filters.forEach((element) => {
54
60
  new Filters(element).init()
package/src/main.scss CHANGED
@@ -8,6 +8,7 @@
8
8
  @import 'core/all';
9
9
 
10
10
  @import 'components/accordion/accordion';
11
+ @import 'components/dialog/dialog';
11
12
  @import 'components/breadcrumbs/breadcrumbs';
12
13
  @import 'components/button/button';
13
14
  @import 'components/callout/callout';