nsw-design-system 3.1.0 → 3.2.0

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
@@ -686,6 +686,93 @@
686
686
  return Accordion;
687
687
  }();
688
688
 
689
+ var Dialog = /*#__PURE__*/function () {
690
+ function Dialog(element) {
691
+ var _this = this;
692
+
693
+ _classCallCheck(this, Dialog);
694
+
695
+ this.dialog = element;
696
+ this.dialogWrapper = element.querySelector('.nsw-dialog__wrapper');
697
+ this.openBtn = document.querySelectorAll('.js-open-dialog-'.concat(element.getAttribute('id')));
698
+ this.closeBtn = element.querySelectorAll('.js-close-dialog'); // eslint-disable-next-line max-len
699
+
700
+ 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])');
701
+ this.body = document.body;
702
+
703
+ this.openEvent = function (e) {
704
+ return _this.openDialog(e);
705
+ };
706
+
707
+ this.closeEvent = function (e) {
708
+ return _this.closeDialog(e);
709
+ };
710
+
711
+ this.clickEvent = function (e) {
712
+ return _this.clickDialog(e);
713
+ };
714
+
715
+ this.trapEvent = function (e) {
716
+ return _this.trapFocus(e);
717
+ };
718
+ }
719
+
720
+ _createClass(Dialog, [{
721
+ key: "init",
722
+ value: function init() {
723
+ this.controls();
724
+ }
725
+ }, {
726
+ key: "controls",
727
+ value: function controls() {
728
+ var _this2 = this;
729
+
730
+ this.openBtn.forEach(function (btn) {
731
+ btn.addEventListener('click', _this2.openEvent, false);
732
+ });
733
+ this.closeBtn.forEach(function (btn) {
734
+ btn.addEventListener('click', _this2.closeEvent, false);
735
+ });
736
+
737
+ if (this.dialog.classList.contains('js-dialog-dismiss')) {
738
+ this.dialog.addEventListener('click', this.clickEvent, false);
739
+ }
740
+
741
+ this.focusableEls[this.focusableEls.length - 1].addEventListener('blur', this.trapEvent, false);
742
+ }
743
+ }, {
744
+ key: "openDialog",
745
+ value: function openDialog() {
746
+ this.dialog.setAttribute('aria-expanded', 'true');
747
+ this.dialog.classList.add('active');
748
+ this.body.classList.add('dialog-active');
749
+ this.focusableEls[0].focus();
750
+ }
751
+ }, {
752
+ key: "closeDialog",
753
+ value: function closeDialog() {
754
+ this.dialog.setAttribute('aria-expanded', 'false');
755
+ this.dialog.classList.remove('active');
756
+ this.body.classList.remove('dialog-active');
757
+ }
758
+ }, {
759
+ key: "clickDialog",
760
+ value: function clickDialog(e) {
761
+ if (!this.dialogWrapper.contains(e.target)) {
762
+ this.closeDialog();
763
+ }
764
+ }
765
+ }, {
766
+ key: "trapFocus",
767
+ value: function trapFocus(e) {
768
+ e.preventDefault();
769
+ this.focusableEls[0].focus();
770
+ }
771
+ }]);
772
+
773
+ return Dialog;
774
+ }();
775
+
689
776
  var Filters = /*#__PURE__*/function () {
690
777
  function Filters(element) {
691
778
  var _this = this;
@@ -1001,6 +1088,7 @@
1001
1088
  var openSearchButton = document.querySelectorAll('.js-open-search');
1002
1089
  var closeSearchButton = document.querySelectorAll('.js-close-search');
1003
1090
  var accordions = document.querySelectorAll('.js-accordion');
1091
+ var dialogs = document.querySelectorAll('.js-dialog');
1004
1092
  var filters = document.querySelectorAll('.js-filters');
1005
1093
  var tabs = document.querySelectorAll('.js-tabs');
1006
1094
  var globalAlert = document.querySelectorAll('.js-global-alert');
@@ -1015,6 +1103,9 @@
1015
1103
  accordions.forEach(function (element) {
1016
1104
  new Accordion(element).init();
1017
1105
  });
1106
+ dialogs.forEach(function (element) {
1107
+ new Dialog(element).init();
1108
+ });
1018
1109
 
1019
1110
  if (filters) {
1020
1111
  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.0",
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
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';