nsw-design-system 3.2.4 → 3.3.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
@@ -30,10 +30,22 @@
30
30
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
31
31
  }
32
32
 
33
+ function _toConsumableArray(arr) {
34
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
35
+ }
36
+
37
+ function _arrayWithoutHoles(arr) {
38
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
39
+ }
40
+
33
41
  function _arrayWithHoles(arr) {
34
42
  if (Array.isArray(arr)) return arr;
35
43
  }
36
44
 
45
+ function _iterableToArray(iter) {
46
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
47
+ }
48
+
37
49
  function _iterableToArrayLimit(arr, i) {
38
50
  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
39
51
  var _arr = [];
@@ -78,6 +90,10 @@
78
90
  return arr2;
79
91
  }
80
92
 
93
+ function _nonIterableSpread() {
94
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
95
+ }
96
+
81
97
  function _nonIterableRest() {
82
98
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83
99
  }
@@ -787,11 +803,26 @@
787
803
  _classCallCheck(this, Filters);
788
804
 
789
805
  this.filters = element;
806
+ this.filtersWrapper = element.querySelector('.nsw-filters__wrapper');
790
807
  this.openButton = element.querySelector('.nsw-filters__controls button');
791
- this.closeButtons = element.querySelectorAll('.nsw-filters__back button');
792
- this.all = element.querySelectorAll('.nsw-filters__all');
793
- this.allBlocks = Array.prototype.slice.call(this.all);
808
+ this.openButtonIcons = this.openButton ? this.openButton.querySelectorAll('span') : null;
809
+ this.selectedCount = element.querySelector('.js-filters--count');
810
+ this.openButtonText = this.selectedCount ? this.selectedCount.querySelector('span:not(.nsw-material-icons)') : null;
811
+ this.buttonLabel = this.openButtonText ? this.openButtonText.innerText : null;
812
+ this.closeButton = element.querySelector('.nsw-filters__back button');
813
+ this.acceptButton = element.querySelector('.nsw-filters__accept button');
814
+ this.clearButton = element.querySelector('.nsw-filters__cancel button');
794
815
  this.showMoreButtons = Array.prototype.slice.call(element.querySelectorAll('.nsw-filters__more'));
816
+ this.accordionButtons = element.querySelectorAll('.nsw-filters__item-button');
817
+ this.showAll = element.querySelectorAll('.nsw-filters__all');
818
+ this.showAllBlocks = Array.prototype.slice.call(this.showAll);
819
+ this.filtersItems = element.querySelectorAll('.nsw-filters__item');
820
+ /* eslint-disable max-len */
821
+
822
+ this.focusableEls = this.filtersWrapper.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])');
823
+ this.checkIcon = '<span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">check_circle</span>';
824
+ this.arrowIcon = '<span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">keyboard_arrow_right</span>';
825
+ /* eslint-ensable max-len */
795
826
 
796
827
  this.showEvent = function (e) {
797
828
  return _this.showFilters(e);
@@ -805,34 +836,99 @@
805
836
  return _this.showMore(e);
806
837
  };
807
838
 
839
+ this.toggleEvent = function (e) {
840
+ return _this.toggleAccordion(e);
841
+ };
842
+
843
+ this.resetEvent = function (e) {
844
+ return _this.clearAllFilters(e);
845
+ };
846
+
808
847
  this.body = document.body;
848
+ this.buttons = [];
849
+ this.content = [];
850
+ this.selected = [];
809
851
  }
810
852
 
811
853
  _createClass(Filters, [{
812
854
  key: "init",
813
855
  value: function init() {
856
+ this.setUpDom();
814
857
  this.controls();
858
+ this.selectedItems();
815
859
  }
816
860
  }, {
817
- key: "controls",
818
- value: function controls() {
861
+ key: "setUpDom",
862
+ value: function setUpDom() {
819
863
  var _this2 = this;
820
864
 
821
- this.openButton.addEventListener('click', this.showEvent, false);
822
- this.closeButtons.forEach(function (element) {
823
- element.addEventListener('click', _this2.hideEvent, false);
865
+ this.filters.classList.add('ready');
866
+
867
+ if (this.openButton) {
868
+ if (this.openButtonIcons.length < 3) {
869
+ this.openButton.insertAdjacentHTML('beforeend', this.arrowIcon);
870
+ }
871
+ }
872
+
873
+ this.accordionButtons.forEach(function (button) {
874
+ var buttonElem = button;
875
+ var uID = uniqueId('collapsed');
876
+ buttonElem.setAttribute('type', 'button');
877
+ buttonElem.setAttribute('aria-expanded', 'false');
878
+ buttonElem.setAttribute('aria-controls', uID);
879
+ var contentElem = buttonElem.nextElementSibling;
880
+ contentElem.id = buttonElem.getAttribute('aria-controls');
881
+ contentElem.hidden = true;
882
+
883
+ _this2.content.push(contentElem);
884
+
885
+ _this2.buttons.push(buttonElem);
824
886
  });
825
- this.all.forEach(function (element) {
887
+ }
888
+ }, {
889
+ key: "controls",
890
+ value: function controls() {
891
+ var _this3 = this;
892
+
893
+ if (this.openButton) {
894
+ this.openButton.addEventListener('click', this.showEvent, false);
895
+ }
896
+
897
+ if (this.acceptButton) {
898
+ this.acceptButton.disabled = true;
899
+ }
900
+
901
+ if (this.closeButton) {
902
+ this.closeButton.addEventListener('click', this.hideEvent, false);
903
+ }
904
+
905
+ this.showAll.forEach(function (element) {
826
906
  var showMoreButton = element.nextElementSibling;
827
- showMoreButton.addEventListener('click', _this2.showMoreEvent, false);
907
+ showMoreButton.addEventListener('click', _this3.showMoreEvent, false);
828
908
  });
909
+
910
+ if (this.buttons) {
911
+ this.buttons.forEach(function (element) {
912
+ element.addEventListener('click', _this3.toggleEvent, false);
913
+ });
914
+ }
915
+
916
+ if (this.clearButton) {
917
+ this.clearButton.addEventListener('click', this.resetEvent, false);
918
+ }
829
919
  }
830
920
  }, {
831
921
  key: "showFilters",
832
922
  value: function showFilters(e) {
833
923
  e.preventDefault();
834
- this.filters.classList.add('active');
835
- this.body.classList.add('filters-open');
924
+
925
+ if (this.filters.classList.contains('nsw-filters--down')) {
926
+ this.filters.classList.toggle('active');
927
+ } else {
928
+ this.trapFocus(this.filtersWrapper);
929
+ this.filters.classList.add('active');
930
+ this.body.classList.add('filters-open');
931
+ }
836
932
  }
837
933
  }, {
838
934
  key: "hideFilters",
@@ -847,10 +943,328 @@
847
943
  e.preventDefault();
848
944
  var currentShowMore = e.target;
849
945
  var currentIndex = this.showMoreButtons.indexOf(currentShowMore);
850
- var currentAll = this.allBlocks[currentIndex];
946
+ var currentAll = this.showAllBlocks[currentIndex];
851
947
  currentAll.classList.remove('hidden');
852
948
  currentShowMore.classList.add('hidden');
853
949
  }
950
+ }, {
951
+ key: "getTargetContent",
952
+ value: function getTargetContent(element) {
953
+ var currentIndex = this.buttons.indexOf(element);
954
+ return this.content[currentIndex];
955
+ }
956
+ }, {
957
+ key: "setAccordionState",
958
+ value: function setAccordionState(element, state) {
959
+ var targetContent = this.getTargetContent(element);
960
+
961
+ if (state === 'open') {
962
+ element.classList.add('active');
963
+ element.setAttribute('aria-expanded', 'true');
964
+ targetContent.hidden = false;
965
+ } else if (state === 'close') {
966
+ element.classList.remove('active');
967
+ element.setAttribute('aria-expanded', 'false');
968
+ targetContent.hidden = true;
969
+ }
970
+ }
971
+ }, {
972
+ key: "toggleAccordion",
973
+ value: function toggleAccordion(e) {
974
+ var currentTarget = e.currentTarget;
975
+ var targetContent = this.getTargetContent(currentTarget);
976
+ var isHidden = targetContent.hidden;
977
+
978
+ if (isHidden) {
979
+ this.setAccordionState(currentTarget, 'open');
980
+ } else {
981
+ this.setAccordionState(currentTarget, 'close');
982
+ }
983
+ }
984
+ }, {
985
+ key: "trapFocus",
986
+ value: function trapFocus(element) {
987
+ var firstFocusableEl = this.focusableEls[0];
988
+ var lastFocusableEl = this.focusableEls[this.focusableEls.length - 1];
989
+ var KEYCODE_TAB = 9;
990
+ element.addEventListener('keydown', function (e) {
991
+ var isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
992
+
993
+ if (!isTabPressed) {
994
+ return;
995
+ }
996
+
997
+ if (e.shiftKey) {
998
+ if (document.activeElement === firstFocusableEl) {
999
+ e.preventDefault();
1000
+ lastFocusableEl.focus();
1001
+ }
1002
+ } else if (document.activeElement === lastFocusableEl) {
1003
+ e.preventDefault();
1004
+ firstFocusableEl.focus();
1005
+ }
1006
+ });
1007
+ }
1008
+ }, {
1009
+ key: "toggleAccept",
1010
+ value: function toggleAccept(array) {
1011
+ if (this.acceptButton) {
1012
+ if (array.length > 0) {
1013
+ this.acceptButton.disabled = false;
1014
+ } else {
1015
+ this.acceptButton.disabled = true;
1016
+ }
1017
+ }
1018
+ }
1019
+ }, {
1020
+ key: "toggleSelectedState",
1021
+ value: function toggleSelectedState(array) {
1022
+ if (array.length > 0) {
1023
+ this.openButton.parentElement.classList.add('active');
1024
+ } else {
1025
+ this.openButton.parentElement.classList.remove('active');
1026
+ }
1027
+ }
1028
+ }, {
1029
+ key: "resultsCount",
1030
+ value: function resultsCount(array, buttonText) {
1031
+ if (this.openButtonText) {
1032
+ if (array.length > 0) {
1033
+ this.openButtonText.innerText = "".concat(buttonText, " (").concat(array.length, ")");
1034
+ } else {
1035
+ this.openButtonText.innerText = "".concat(buttonText);
1036
+ }
1037
+ }
1038
+ }
1039
+ }, {
1040
+ key: "updateDom",
1041
+ value: function updateDom() {
1042
+ this.resultsCount(this.selected, this.buttonLabel);
1043
+ this.toggleAccept(this.selected);
1044
+ this.toggleSelectedState(this.selected);
1045
+ }
1046
+ }, {
1047
+ key: "updateCount",
1048
+ value: function updateCount(options) {
1049
+ var _this4 = this;
1050
+
1051
+ var id = uniqueId();
1052
+ var GroupArray = [];
1053
+
1054
+ if (options.array.length > 0) {
1055
+ options.array.forEach(function (element, index) {
1056
+ var getEventType = _this4.constructor.getEventType(element.type);
1057
+
1058
+ var _this4$constructor$si = _this4.constructor.singleCount(element, index, id),
1059
+ uniqueID = _this4$constructor$si.uniqueID,
1060
+ singleID = _this4$constructor$si.singleID,
1061
+ isSingleCount = _this4$constructor$si.isSingleCount;
1062
+
1063
+ if (_this4.constructor.getCondition(element)) {
1064
+ _this4.selected.push(uniqueID);
1065
+
1066
+ if (isSingleCount) {
1067
+ GroupArray.push(singleID);
1068
+ }
1069
+
1070
+ _this4.updateDom();
1071
+ }
1072
+
1073
+ element.addEventListener(getEventType, function () {
1074
+ var selectedIndex = _this4.selected.indexOf(uniqueID);
1075
+
1076
+ var singleSelectedIndex = GroupArray.indexOf(singleID);
1077
+
1078
+ if (_this4.constructor.getCondition(element)) {
1079
+ if (!_this4.selected.includes(uniqueID)) {
1080
+ _this4.selected.push(uniqueID);
1081
+ }
1082
+
1083
+ if (isSingleCount && !GroupArray.includes(singleID)) {
1084
+ GroupArray.push(singleID);
1085
+ }
1086
+
1087
+ _this4.updateDom();
1088
+ } else {
1089
+ if (isSingleCount && singleSelectedIndex !== -1) {
1090
+ GroupArray.splice(singleSelectedIndex, 1);
1091
+ }
1092
+
1093
+ if (!isSingleCount && selectedIndex !== -1) {
1094
+ _this4.selected.splice(selectedIndex, 1);
1095
+ } else if (GroupArray.length <= 0) {
1096
+ _this4.selected.splice(selectedIndex, 1);
1097
+ }
1098
+
1099
+ _this4.updateDom();
1100
+ }
1101
+ });
1102
+ });
1103
+ }
1104
+ }
1105
+ }, {
1106
+ key: "updateStatus",
1107
+ value: function updateStatus(options) {
1108
+ var _this5 = this;
1109
+
1110
+ var id = uniqueId();
1111
+ var text = options.title;
1112
+ var GroupArray = [];
1113
+
1114
+ if (options.array.length > 0) {
1115
+ var labelText = text ? text.textContent : null;
1116
+ options.array.forEach(function (element, index) {
1117
+ var getEventType = _this5.constructor.getEventType(element.type);
1118
+
1119
+ var _this5$constructor$si = _this5.constructor.singleCount(element, index, id),
1120
+ singleID = _this5$constructor$si.singleID;
1121
+
1122
+ if (_this5.constructor.getCondition(element)) {
1123
+ if (text) {
1124
+ text.textContent = labelText;
1125
+ text.innerHTML = "".concat(text.textContent, " ").concat(_this5.checkIcon);
1126
+ }
1127
+ }
1128
+
1129
+ element.addEventListener(getEventType, function () {
1130
+ if (_this5.constructor.getCondition(element)) {
1131
+ if (!GroupArray.includes(singleID)) {
1132
+ GroupArray.push(singleID);
1133
+ }
1134
+ } else if (GroupArray.indexOf(singleID) !== -1) {
1135
+ GroupArray.splice(GroupArray.indexOf(singleID), 1);
1136
+ }
1137
+
1138
+ if (text) {
1139
+ if (GroupArray.length > 0) {
1140
+ text.textContent = labelText;
1141
+ text.innerHTML = "".concat(text.textContent, " ").concat(_this5.checkIcon);
1142
+ } else {
1143
+ text.textContent = labelText;
1144
+ }
1145
+ }
1146
+ });
1147
+ });
1148
+ }
1149
+ }
1150
+ }, {
1151
+ key: "selectedItems",
1152
+ value: function selectedItems() {
1153
+ var _this6 = this;
1154
+
1155
+ this.filtersItems.forEach(function (filter) {
1156
+ var button = filter.querySelector('.nsw-filters__item-name');
1157
+ var content = filter.querySelector('.nsw-filters__item-content');
1158
+ var text = content ? content.querySelectorAll('input[type="text"]') : null;
1159
+ var selects = content ? content.querySelectorAll('select') : null;
1160
+ var checkboxes = content ? content.querySelectorAll('input[type="checkbox"]') : null;
1161
+ if (!content) return;
1162
+
1163
+ _this6.updateCount({
1164
+ array: text,
1165
+ title: button
1166
+ });
1167
+
1168
+ _this6.updateCount({
1169
+ array: selects,
1170
+ title: button
1171
+ });
1172
+
1173
+ _this6.updateCount({
1174
+ array: checkboxes,
1175
+ title: button
1176
+ });
1177
+
1178
+ _this6.updateStatus({
1179
+ array: text,
1180
+ title: button
1181
+ });
1182
+
1183
+ _this6.updateStatus({
1184
+ array: selects,
1185
+ title: button
1186
+ });
1187
+
1188
+ _this6.updateStatus({
1189
+ array: checkboxes,
1190
+ title: button
1191
+ });
1192
+ });
1193
+ }
1194
+ }, {
1195
+ key: "clearAllFilters",
1196
+ value: function clearAllFilters(e) {
1197
+ var _this7 = this;
1198
+
1199
+ e.preventDefault();
1200
+ this.filtersItems.forEach(function (filter) {
1201
+ var button = filter.querySelector('.nsw-filters__item-name');
1202
+ var buttonCheck = button ? button.querySelector('span.nsw-material-icons') : null;
1203
+ var content = filter.querySelector('.nsw-filters__item-content');
1204
+ var text = content.querySelectorAll('input[type="text"]');
1205
+ var selects = content.querySelectorAll('select');
1206
+ var checkboxes = content.querySelectorAll('input[type="checkbox"]');
1207
+ var allFields = [].concat(_toConsumableArray(text), _toConsumableArray(selects), _toConsumableArray(checkboxes));
1208
+ if (!content) return;
1209
+
1210
+ if (allFields.length > 0) {
1211
+ allFields.forEach(function (input) {
1212
+ var field = input;
1213
+
1214
+ if (_this7.constructor.getCondition(field) && (field.type === 'text' || field.type === 'select-one')) {
1215
+ field.value = '';
1216
+ } else {
1217
+ field.checked = false;
1218
+ }
1219
+ });
1220
+ }
1221
+
1222
+ if (buttonCheck) {
1223
+ buttonCheck.remove();
1224
+ }
1225
+
1226
+ _this7.selected = [];
1227
+
1228
+ _this7.updateDom();
1229
+ });
1230
+ }
1231
+ }], [{
1232
+ key: "getEventType",
1233
+ value: function getEventType(type) {
1234
+ if (type === 'text') {
1235
+ return 'input';
1236
+ }
1237
+
1238
+ return 'change';
1239
+ }
1240
+ }, {
1241
+ key: "getCondition",
1242
+ value: function getCondition(element) {
1243
+ if (element.type === 'text' || element.type === 'select-one') {
1244
+ return element.value !== '';
1245
+ }
1246
+
1247
+ return element.checked;
1248
+ }
1249
+ }, {
1250
+ key: "singleCount",
1251
+ value: function singleCount(element, index, id) {
1252
+ var isSingleCount = element.closest('.js-filters--single-count');
1253
+
1254
+ if (!isSingleCount) {
1255
+ return {
1256
+ uniqueID: "".concat(id, "-").concat(index),
1257
+ singleID: "".concat(id, "-").concat(index),
1258
+ isSingleCount: isSingleCount
1259
+ };
1260
+ }
1261
+
1262
+ return {
1263
+ uniqueID: "".concat(id),
1264
+ singleID: "".concat(id, "-").concat(index),
1265
+ isSingleCount: isSingleCount
1266
+ };
1267
+ }
854
1268
  }]);
855
1269
 
856
1270
  return Filters;
@@ -974,7 +1388,11 @@
974
1388
  this.selectedTab = clickedTab;
975
1389
 
976
1390
  if (!clickedTab.classList.contains('js-tabs-fixed')) {
977
- this.selectedTab.scrollIntoView();
1391
+ clickedTab.scrollIntoView({
1392
+ behavior: 'smooth',
1393
+ block: 'nearest',
1394
+ inline: 'nearest'
1395
+ });
978
1396
  }
979
1397
  }
980
1398
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsw-design-system",
3
- "version": "3.2.4",
3
+ "version": "3.3.0",
4
4
  "description": "Design system for Digital NSW",
5
5
  "main": "dist/main.js",
6
6
  "style": "dist/main.css",
@@ -41,7 +41,7 @@
41
41
 
42
42
  button {
43
43
  @include font-size('sm');
44
- color: var(--nsw-brand-dark);
44
+ color: var(--nsw-text-link);
45
45
  text-decoration: underline;
46
46
  text-decoration-skip-ink: auto;
47
47
  font-weight: var(--nsw-font-bold);
@@ -50,8 +50,8 @@
50
50
  background: none;
51
51
 
52
52
  &:hover:enabled {
53
- @include nsw-hover;
54
- outline: 2px solid var(--nsw-text-hover);
53
+ @include nsw-link-hover;
54
+ outline: 2px solid var(--nsw-text-link-hover);
55
55
 
56
56
  .nsw-section--invert & {
57
57
  background-color: var(--nsw-text-hover-light);