nsw-design-system 3.3.0 → 3.5.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/CHANGELOG.md +19 -0
- package/dist/css/core.css +1 -1
- package/dist/css/main.css +1 -1
- package/dist/js/main.js +512 -0
- package/package.json +1 -1
- package/src/components/_all.scss +4 -0
- package/src/components/file-upload/_file-upload.scss +56 -0
- package/src/components/file-upload/file-upload.js +87 -0
- package/src/components/form/_form.scss +1 -32
- package/src/components/loader/_loader.scss +62 -0
- package/src/components/select/_select.scss +121 -0
- package/src/components/select/select.js +390 -0
- package/src/components/status-labels/_status-labels.scss +19 -0
- package/src/global/scss/settings/_palette.scss +4 -4
- package/src/main.js +17 -1
- package/src/main.scss +4 -0
package/dist/js/main.js
CHANGED
|
@@ -1270,6 +1270,102 @@
|
|
|
1270
1270
|
return Filters;
|
|
1271
1271
|
}();
|
|
1272
1272
|
|
|
1273
|
+
/* eslint-disable max-len */
|
|
1274
|
+
var FileUpload = /*#__PURE__*/function () {
|
|
1275
|
+
function FileUpload(element) {
|
|
1276
|
+
_classCallCheck(this, FileUpload);
|
|
1277
|
+
|
|
1278
|
+
this.element = element;
|
|
1279
|
+
this.input = this.element.querySelector('.nsw-file-upload__input');
|
|
1280
|
+
this.label = this.element.querySelector('.nsw-file-upload__label');
|
|
1281
|
+
this.multipleUpload = this.input.hasAttribute('multiple');
|
|
1282
|
+
this.replaceFiles = this.element.hasAttribute('data-replace-files');
|
|
1283
|
+
this.filesList = false;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
_createClass(FileUpload, [{
|
|
1287
|
+
key: "init",
|
|
1288
|
+
value: function init() {
|
|
1289
|
+
var _this = this;
|
|
1290
|
+
|
|
1291
|
+
if (!this.input) return;
|
|
1292
|
+
this.input.addEventListener('change', function () {
|
|
1293
|
+
if (_this.input.value === '') return;
|
|
1294
|
+
|
|
1295
|
+
_this.updateFileList();
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
}, {
|
|
1299
|
+
key: "createFileList",
|
|
1300
|
+
value: function createFileList() {
|
|
1301
|
+
var ul = document.createElement('ul');
|
|
1302
|
+
ul.classList.add('nsw-file-upload__list');
|
|
1303
|
+
this.label.insertAdjacentElement('afterend', ul);
|
|
1304
|
+
this.filesList = this.element.querySelector('.nsw-file-upload__list');
|
|
1305
|
+
}
|
|
1306
|
+
}, {
|
|
1307
|
+
key: "createFileItem",
|
|
1308
|
+
value: function createFileItem(file) {
|
|
1309
|
+
var li = document.createElement('li');
|
|
1310
|
+
li.classList.add('nsw-file-upload__item');
|
|
1311
|
+
var html = "\n <span class=\"nsw-file-upload__item-filename\"></span>\n <button type=\"button\" class=\"nsw-icon-button\">\n <span class=\"sr-only\">Remove file</span>\n <span class=\"material-icons nsw-material-icons\" focusable=\"false\" aria-hidden=\"true\">cancel</span>\n </button>";
|
|
1312
|
+
li.insertAdjacentHTML('afterbegin', html);
|
|
1313
|
+
li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50);
|
|
1314
|
+
return li.outerHTML;
|
|
1315
|
+
}
|
|
1316
|
+
}, {
|
|
1317
|
+
key: "updateFileList",
|
|
1318
|
+
value: function updateFileList() {
|
|
1319
|
+
if (!this.filesList) {
|
|
1320
|
+
this.createFileList();
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
this.filesList.classList.add('active');
|
|
1324
|
+
var string = '';
|
|
1325
|
+
|
|
1326
|
+
for (var i = 0; i < this.input.files.length; i += 1) {
|
|
1327
|
+
var file = this.input.files[i];
|
|
1328
|
+
string = this.createFileItem(file) + string;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
if (this.replaceFiles) {
|
|
1332
|
+
this.filesList.innerHTML = string;
|
|
1333
|
+
} else {
|
|
1334
|
+
this.filesList.insertAdjacentHTML('beforeend', string);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
this.removeFile();
|
|
1338
|
+
}
|
|
1339
|
+
}, {
|
|
1340
|
+
key: "removeFile",
|
|
1341
|
+
value: function removeFile() {
|
|
1342
|
+
var _this2 = this;
|
|
1343
|
+
|
|
1344
|
+
this.filesList.addEventListener('click', function (event) {
|
|
1345
|
+
if (!event.target.closest('.nsw-icon-button')) return;
|
|
1346
|
+
event.preventDefault();
|
|
1347
|
+
var item = event.target.closest('.nsw-file-upload__item');
|
|
1348
|
+
item.remove();
|
|
1349
|
+
|
|
1350
|
+
if (event.currentTarget.children.length === 0) {
|
|
1351
|
+
_this2.filesList.classList.remove('active');
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
}], [{
|
|
1356
|
+
key: "truncateString",
|
|
1357
|
+
value: function truncateString(str, num) {
|
|
1358
|
+
if (str.length <= num) {
|
|
1359
|
+
return str;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
return "".concat(str.slice(0, num), "...");
|
|
1363
|
+
}
|
|
1364
|
+
}]);
|
|
1365
|
+
|
|
1366
|
+
return FileUpload;
|
|
1367
|
+
}();
|
|
1368
|
+
|
|
1273
1369
|
var Tabs = /*#__PURE__*/function () {
|
|
1274
1370
|
function Tabs(element, showTab) {
|
|
1275
1371
|
var _this = this;
|
|
@@ -1485,6 +1581,404 @@
|
|
|
1485
1581
|
return GlobalAlert;
|
|
1486
1582
|
}();
|
|
1487
1583
|
|
|
1584
|
+
/* eslint-disable max-len */
|
|
1585
|
+
var Select = /*#__PURE__*/function () {
|
|
1586
|
+
function Select(element) {
|
|
1587
|
+
_classCallCheck(this, Select);
|
|
1588
|
+
|
|
1589
|
+
this.element = element;
|
|
1590
|
+
this.select = this.element.querySelector('select');
|
|
1591
|
+
this.options = this.select.querySelectorAll('option');
|
|
1592
|
+
this.optGroups = this.select.querySelectorAll('optgroup');
|
|
1593
|
+
this.selectId = this.select.getAttribute('id');
|
|
1594
|
+
this.trigger = false;
|
|
1595
|
+
this.dropdown = false;
|
|
1596
|
+
this.customOptions = false;
|
|
1597
|
+
this.optionIndex = 0;
|
|
1598
|
+
this.textSelected = this.element.getAttribute('data-selection-text') || 'selected';
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
_createClass(Select, [{
|
|
1602
|
+
key: "init",
|
|
1603
|
+
value: function init() {
|
|
1604
|
+
this.initCustomSelect();
|
|
1605
|
+
this.initCustomSelectEvents();
|
|
1606
|
+
}
|
|
1607
|
+
}, {
|
|
1608
|
+
key: "initCustomSelect",
|
|
1609
|
+
value: function initCustomSelect() {
|
|
1610
|
+
this.element.insertAdjacentHTML('beforeend', this.initButtonSelect() + this.initListSelect());
|
|
1611
|
+
this.dropdown = this.element.querySelector('.nsw-multi-select__dropdown');
|
|
1612
|
+
this.trigger = this.element.querySelector('.nsw-multi-select__button');
|
|
1613
|
+
this.multiSelectList = this.dropdown.querySelector('.nsw-multi-select__list');
|
|
1614
|
+
this.customOptions = this.multiSelectList.querySelectorAll('.nsw-multi-select__option');
|
|
1615
|
+
this.multiSelectList.insertAdjacentHTML('afterbegin', this.initAllButton());
|
|
1616
|
+
this.allButton = this.multiSelectList.querySelector('.js-multi-select-all');
|
|
1617
|
+
this.allButtonInput = this.allButton.querySelector('.nsw-form__checkbox-input');
|
|
1618
|
+
}
|
|
1619
|
+
}, {
|
|
1620
|
+
key: "initCustomSelectEvents",
|
|
1621
|
+
value: function initCustomSelectEvents() {
|
|
1622
|
+
var _this = this;
|
|
1623
|
+
|
|
1624
|
+
this.initSelection();
|
|
1625
|
+
this.trigger.addEventListener('click', function (event) {
|
|
1626
|
+
event.preventDefault();
|
|
1627
|
+
|
|
1628
|
+
_this.toggleCustomSelect(false);
|
|
1629
|
+
});
|
|
1630
|
+
this.trigger.addEventListener('keydown', function (event) {
|
|
1631
|
+
if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup' || event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
|
|
1632
|
+
event.preventDefault();
|
|
1633
|
+
|
|
1634
|
+
_this.toggleCustomSelect(false);
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
this.dropdown.addEventListener('keydown', function (event) {
|
|
1638
|
+
if (event.code && event.code === 38 || event.key && event.key.toLowerCase() === 'arrowup') {
|
|
1639
|
+
_this.keyboardCustomSelect('prev', event);
|
|
1640
|
+
} else if (event.code && event.code === 40 || event.key && event.key.toLowerCase() === 'arrowdown') {
|
|
1641
|
+
_this.keyboardCustomSelect('next', event);
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
window.addEventListener('keyup', function (event) {
|
|
1645
|
+
if (event.key && event.key.toLowerCase() === 'escape') {
|
|
1646
|
+
_this.constructor.moveFocusToSelectTrigger(event.target);
|
|
1647
|
+
|
|
1648
|
+
_this.toggleCustomSelect('false');
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
window.addEventListener('click', function (event) {
|
|
1652
|
+
_this.checkCustomSelectClick(event.target);
|
|
1653
|
+
});
|
|
1654
|
+
window.addEventListener('resize', this.placeDropdown);
|
|
1655
|
+
this.allButton.addEventListener('change', function () {
|
|
1656
|
+
_this.toggleAllOptions();
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
}, {
|
|
1660
|
+
key: "toggleCustomSelect",
|
|
1661
|
+
value: function toggleCustomSelect(bool) {
|
|
1662
|
+
var ariaExpanded;
|
|
1663
|
+
|
|
1664
|
+
if (bool) {
|
|
1665
|
+
ariaExpanded = bool;
|
|
1666
|
+
} else {
|
|
1667
|
+
ariaExpanded = this.trigger.getAttribute('aria-expanded') === 'true' ? 'false' : 'true';
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
this.trigger.setAttribute('aria-expanded', ariaExpanded);
|
|
1671
|
+
|
|
1672
|
+
if (ariaExpanded === 'true') {
|
|
1673
|
+
var selectedOption = this.getSelectedOption();
|
|
1674
|
+
this.constructor.moveFocus(selectedOption);
|
|
1675
|
+
this.dropdown.addEventListener('transitionend', function cb() {
|
|
1676
|
+
this.constructor.moveFocus(selectedOption);
|
|
1677
|
+
this.dropdown.removeEventListener('transitionend', cb);
|
|
1678
|
+
});
|
|
1679
|
+
this.constructor.trapFocus(this.dropdown);
|
|
1680
|
+
this.placeDropdown();
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
}, {
|
|
1684
|
+
key: "placeDropdown",
|
|
1685
|
+
value: function placeDropdown() {
|
|
1686
|
+
var _this$trigger$getBoun = this.trigger.getBoundingClientRect(),
|
|
1687
|
+
top = _this$trigger$getBoun.top,
|
|
1688
|
+
bottom = _this$trigger$getBoun.bottom;
|
|
1689
|
+
|
|
1690
|
+
var moveUp = window.innerHeight - bottom < top;
|
|
1691
|
+
var maxHeight = moveUp ? top - 20 : window.innerHeight - bottom - 20;
|
|
1692
|
+
var vhCalc = Math.ceil(100 * maxHeight / window.innerHeight);
|
|
1693
|
+
this.dropdown.setAttribute('style', "max-height: ".concat(vhCalc, "vh;"));
|
|
1694
|
+
}
|
|
1695
|
+
}, {
|
|
1696
|
+
key: "keyboardCustomSelect",
|
|
1697
|
+
value: function keyboardCustomSelect(direction, event) {
|
|
1698
|
+
event.preventDefault();
|
|
1699
|
+
var allOptions = [].concat(_toConsumableArray(this.customOptions), [this.allButton]);
|
|
1700
|
+
var index = Array.prototype.indexOf.call(allOptions, document.activeElement.closest('.nsw-multi-select__option'));
|
|
1701
|
+
index = direction === 'next' ? index + 1 : index - 1;
|
|
1702
|
+
if (index < 0) index = allOptions.length - 1;
|
|
1703
|
+
if (index >= allOptions.length) index = 0;
|
|
1704
|
+
this.constructor.moveFocus(allOptions[index].querySelector('.nsw-form__checkbox-input'));
|
|
1705
|
+
}
|
|
1706
|
+
}, {
|
|
1707
|
+
key: "initSelection",
|
|
1708
|
+
value: function initSelection() {
|
|
1709
|
+
var _this2 = this;
|
|
1710
|
+
|
|
1711
|
+
if (!this.dropdown) return;
|
|
1712
|
+
this.customOptions.forEach(function (opt) {
|
|
1713
|
+
opt.addEventListener('change', function (event) {
|
|
1714
|
+
var option = event.currentTarget.closest('.nsw-multi-select__option');
|
|
1715
|
+
if (!option) return;
|
|
1716
|
+
|
|
1717
|
+
_this2.selectOption(option);
|
|
1718
|
+
});
|
|
1719
|
+
opt.addEventListener('click', function (event) {
|
|
1720
|
+
var option = event.currentTarget.closest('.nsw-multi-select__option');
|
|
1721
|
+
if (!option || !event.target.classList.contains('nsw-multi-select__option')) return;
|
|
1722
|
+
|
|
1723
|
+
_this2.selectOption(option);
|
|
1724
|
+
});
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
}, {
|
|
1728
|
+
key: "getSelectedOptionCount",
|
|
1729
|
+
value: function getSelectedOptionCount() {
|
|
1730
|
+
var selectedOptCounter = 0;
|
|
1731
|
+
|
|
1732
|
+
for (var i = 0; i < this.options.length; i += 1) {
|
|
1733
|
+
if (this.options[i].selected) {
|
|
1734
|
+
selectedOptCounter += 1;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
return selectedOptCounter;
|
|
1739
|
+
}
|
|
1740
|
+
}, {
|
|
1741
|
+
key: "toggleAllOptions",
|
|
1742
|
+
value: function toggleAllOptions() {
|
|
1743
|
+
var _this3 = this;
|
|
1744
|
+
|
|
1745
|
+
var count = this.getSelectedOptionCount();
|
|
1746
|
+
this.customOptions.forEach(function (check) {
|
|
1747
|
+
var input = check.querySelector('.nsw-form__checkbox-input');
|
|
1748
|
+
|
|
1749
|
+
if (count === _this3.options.length) {
|
|
1750
|
+
input.checked = false;
|
|
1751
|
+
input.removeAttribute('checked');
|
|
1752
|
+
check.setAttribute('aria-selected', 'false');
|
|
1753
|
+
|
|
1754
|
+
_this3.updateNativeSelect(check.getAttribute('data-index'), false);
|
|
1755
|
+
} else {
|
|
1756
|
+
input.checked = true;
|
|
1757
|
+
input.setAttribute('checked', '');
|
|
1758
|
+
check.setAttribute('aria-selected', 'true');
|
|
1759
|
+
|
|
1760
|
+
_this3.updateNativeSelect(check.getAttribute('data-index'), true);
|
|
1761
|
+
} //
|
|
1762
|
+
|
|
1763
|
+
});
|
|
1764
|
+
|
|
1765
|
+
var _this$getSelectedOpti = this.getSelectedOptionText(),
|
|
1766
|
+
_this$getSelectedOpti2 = _slicedToArray(_this$getSelectedOpti, 2),
|
|
1767
|
+
label = _this$getSelectedOpti2[0],
|
|
1768
|
+
ariaLabel = _this$getSelectedOpti2[1];
|
|
1769
|
+
|
|
1770
|
+
this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
|
|
1771
|
+
this.constructor.toggleClass(this.trigger, 'active', count > 0);
|
|
1772
|
+
this.updateTriggerAria(ariaLabel);
|
|
1773
|
+
}
|
|
1774
|
+
}, {
|
|
1775
|
+
key: "selectOption",
|
|
1776
|
+
value: function selectOption(option) {
|
|
1777
|
+
var input = option.querySelector('.nsw-form__checkbox-input');
|
|
1778
|
+
|
|
1779
|
+
if (option.hasAttribute('aria-selected') && option.getAttribute('aria-selected') === 'true') {
|
|
1780
|
+
input.checked = false;
|
|
1781
|
+
input.removeAttribute('checked');
|
|
1782
|
+
option.setAttribute('aria-selected', 'false');
|
|
1783
|
+
this.updateNativeSelect(option.getAttribute('data-index'), false);
|
|
1784
|
+
} else {
|
|
1785
|
+
input.checked = true;
|
|
1786
|
+
input.value = true;
|
|
1787
|
+
input.setAttribute('checked', '');
|
|
1788
|
+
option.setAttribute('aria-selected', 'true');
|
|
1789
|
+
this.updateNativeSelect(option.getAttribute('data-index'), true);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
var _this$getSelectedOpti3 = this.getSelectedOptionText(),
|
|
1793
|
+
_this$getSelectedOpti4 = _slicedToArray(_this$getSelectedOpti3, 2),
|
|
1794
|
+
label = _this$getSelectedOpti4[0],
|
|
1795
|
+
ariaLabel = _this$getSelectedOpti4[1];
|
|
1796
|
+
|
|
1797
|
+
var count = this.getSelectedOptionCount();
|
|
1798
|
+
|
|
1799
|
+
if (count === this.options.length) {
|
|
1800
|
+
this.allButtonInput.checked = true;
|
|
1801
|
+
this.allButtonInput.setAttribute('checked', '');
|
|
1802
|
+
this.allButton.setAttribute('aria-selected', 'true');
|
|
1803
|
+
} else {
|
|
1804
|
+
this.allButtonInput.checked = false;
|
|
1805
|
+
this.allButtonInput.removeAttribute('checked');
|
|
1806
|
+
this.allButton.setAttribute('aria-selected', 'false');
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
this.trigger.querySelector('.nsw-multi-select__label').innerHTML = label;
|
|
1810
|
+
this.constructor.toggleClass(this.trigger, 'active', count > 0);
|
|
1811
|
+
this.updateTriggerAria(ariaLabel);
|
|
1812
|
+
}
|
|
1813
|
+
}, {
|
|
1814
|
+
key: "initButtonSelect",
|
|
1815
|
+
value: function initButtonSelect() {
|
|
1816
|
+
var triggerLabel = this.getSelectedOptionText(this.element);
|
|
1817
|
+
var button = "<button class=\"nsw-button nsw-multi-select__button\" aria-label=\"".concat(triggerLabel[1], "\" aria-expanded=\"false\" aria-controls=\"").concat(this.selectId, "-dropdown\">\n <span aria-hidden=\"true\" class=\"nsw-multi-select__label\">").concat(triggerLabel[0], "</span>\n <span class=\"material-icons nsw-material-icons\" focusable=\"false\" aria-hidden=\"true\">keyboard_arrow_down</span>\n </button>");
|
|
1818
|
+
return button;
|
|
1819
|
+
}
|
|
1820
|
+
}, {
|
|
1821
|
+
key: "initAllButton",
|
|
1822
|
+
value: function initAllButton() {
|
|
1823
|
+
var all = this.getSelectedOptionCount() === this.options.length;
|
|
1824
|
+
var selected = all ? ' aria-selected="true"' : ' aria-selected="false"';
|
|
1825
|
+
var checked = all ? 'checked' : '';
|
|
1826
|
+
var allButton = "\n <li class=\"js-multi-select-all nsw-multi-select__option\" role=\"option\" data-value=\"Select all\" aria-selected=\"false\" ".concat(selected, " data-label=\"Select all\">\n <input aria-hidden=\"true\" class=\"nsw-form__checkbox-input\" type=\"checkbox\" id=\"").concat(this.selectId, "-all\" ").concat(checked, ">\n <label class=\"nsw-form__checkbox-label\" aria-hidden=\"true\" for=\"").concat(this.selectId, "-all\">\n <span>Select all</span>\n </label>\n </li>");
|
|
1827
|
+
return allButton;
|
|
1828
|
+
}
|
|
1829
|
+
}, {
|
|
1830
|
+
key: "getSelectedOptionText",
|
|
1831
|
+
value: function getSelectedOptionText() {
|
|
1832
|
+
var noSelectionText = '<span class="multi-select__term">Please select</span>';
|
|
1833
|
+
var label = '';
|
|
1834
|
+
var ariaLabel = '';
|
|
1835
|
+
var count = this.getSelectedOptionCount();
|
|
1836
|
+
|
|
1837
|
+
if (count === this.options.length) {
|
|
1838
|
+
label = "All ".concat(this.textSelected);
|
|
1839
|
+
ariaLabel = "All ".concat(this.textSelected);
|
|
1840
|
+
} else if (count > 1) {
|
|
1841
|
+
label = "".concat(count, " ").concat(this.textSelected);
|
|
1842
|
+
ariaLabel = "".concat(count, " ").concat(this.textSelected, ", Please select");
|
|
1843
|
+
} else if (count > 0) {
|
|
1844
|
+
ariaLabel += "".concat(this.options[0].text, ", Please select");
|
|
1845
|
+
label = this.options[0].text;
|
|
1846
|
+
} else {
|
|
1847
|
+
label = noSelectionText;
|
|
1848
|
+
ariaLabel = 'Please select';
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
return [label, ariaLabel];
|
|
1852
|
+
}
|
|
1853
|
+
}, {
|
|
1854
|
+
key: "initListSelect",
|
|
1855
|
+
value: function initListSelect() {
|
|
1856
|
+
var _this4 = this;
|
|
1857
|
+
|
|
1858
|
+
var list = "<div class=\"nsw-multi-select__dropdown\" aria-describedby=".concat(this.selectId, "-description\" id=\"").concat(this.selectId, "-dropdown\">");
|
|
1859
|
+
|
|
1860
|
+
if (this.optGroups.length > 0) {
|
|
1861
|
+
this.optGroups.forEach(function (optionGroup) {
|
|
1862
|
+
var optGroupList = optionGroup.querySelectorAll('option');
|
|
1863
|
+
var optGroupLabel = "<li><span>".concat(optionGroup.getAttribute('label'), "</span></li>");
|
|
1864
|
+
list += "<ul class=\"nsw-multi-select__list\" role=\"listbox\" aria-multiselectable=\"true\">\n ".concat(optGroupLabel + _this4.getOptionsList(optGroupList), "\n </ul>");
|
|
1865
|
+
});
|
|
1866
|
+
} else {
|
|
1867
|
+
list += "<ul class=\"nsw-multi-select__list\" role=\"listbox\" aria-multiselectable=\"true\">".concat(this.getOptionsList(this.options), "</ul>");
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
return list;
|
|
1871
|
+
}
|
|
1872
|
+
}, {
|
|
1873
|
+
key: "getOptionsList",
|
|
1874
|
+
value: function getOptionsList(options) {
|
|
1875
|
+
var _this5 = this;
|
|
1876
|
+
|
|
1877
|
+
var list = '';
|
|
1878
|
+
options.forEach(function (option) {
|
|
1879
|
+
var selected = option.hasAttribute('selected') ? ' aria-selected="true"' : ' aria-selected="false"';
|
|
1880
|
+
var checked = option.hasAttribute('selected') ? 'checked' : '';
|
|
1881
|
+
|
|
1882
|
+
var uniqueName = _this5.constructor.createSafeCssClassname("".concat(_this5.selectId, "-").concat(option.value, "-").concat(_this5.optionIndex.toString()));
|
|
1883
|
+
|
|
1884
|
+
list += "\n <li class=\"nsw-multi-select__option\" role=\"option\" data-value=\"".concat(option.value, "\" ").concat(selected, " data-label=\"").concat(option.text, "\" data-index=\"").concat(_this5.optionIndex, "\">\n <input aria-hidden=\"true\" class=\"nsw-form__checkbox-input\" type=\"checkbox\" id=\"").concat(uniqueName, "\" ").concat(checked, ">\n <label class=\"nsw-form__checkbox-label\" aria-hidden=\"true\" for=\"").concat(uniqueName, "\">\n <span>").concat(option.text, "</span>\n </label>\n </li>");
|
|
1885
|
+
_this5.optionIndex += 1;
|
|
1886
|
+
});
|
|
1887
|
+
return list;
|
|
1888
|
+
}
|
|
1889
|
+
}, {
|
|
1890
|
+
key: "getSelectedOption",
|
|
1891
|
+
value: function getSelectedOption() {
|
|
1892
|
+
var option = this.dropdown.querySelector('[aria-selected="true"]');
|
|
1893
|
+
|
|
1894
|
+
if (option) {
|
|
1895
|
+
return option.querySelector('.nsw-form__checkbox-input');
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
return this.dropdown.querySelector('.nsw-multi-select__option').querySelector('.nsw-form__checkbox-input');
|
|
1899
|
+
}
|
|
1900
|
+
}, {
|
|
1901
|
+
key: "checkCustomSelectClick",
|
|
1902
|
+
value: function checkCustomSelectClick(target) {
|
|
1903
|
+
if (!this.element.contains(target)) this.toggleCustomSelect('false');
|
|
1904
|
+
}
|
|
1905
|
+
}, {
|
|
1906
|
+
key: "updateNativeSelect",
|
|
1907
|
+
value: function updateNativeSelect(index, bool) {
|
|
1908
|
+
this.options[index].selected = bool;
|
|
1909
|
+
this.select.dispatchEvent(new CustomEvent('update', {
|
|
1910
|
+
bubbles: true
|
|
1911
|
+
}));
|
|
1912
|
+
}
|
|
1913
|
+
}, {
|
|
1914
|
+
key: "updateTriggerAria",
|
|
1915
|
+
value: function updateTriggerAria(ariaLabel) {
|
|
1916
|
+
this.trigger.setAttribute('aria-label', ariaLabel);
|
|
1917
|
+
}
|
|
1918
|
+
}], [{
|
|
1919
|
+
key: "createSafeCssClassname",
|
|
1920
|
+
value: function createSafeCssClassname(str) {
|
|
1921
|
+
var invalidBeginningOfClassname = /^([0-9]|--|-[0-9])/;
|
|
1922
|
+
|
|
1923
|
+
if (typeof str !== 'string') {
|
|
1924
|
+
return '';
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
var strippedClassname = str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g).map(function (x) {
|
|
1928
|
+
return x.toLowerCase();
|
|
1929
|
+
}).join('-');
|
|
1930
|
+
return invalidBeginningOfClassname.test(strippedClassname) ? "_".concat(strippedClassname) : strippedClassname;
|
|
1931
|
+
}
|
|
1932
|
+
}, {
|
|
1933
|
+
key: "moveFocusToSelectTrigger",
|
|
1934
|
+
value: function moveFocusToSelectTrigger(target) {
|
|
1935
|
+
var multiSelect = target.closest('.js-multi-select');
|
|
1936
|
+
if (!multiSelect) return;
|
|
1937
|
+
multiSelect.querySelector('.nsw-multi-select__button').focus();
|
|
1938
|
+
}
|
|
1939
|
+
}, {
|
|
1940
|
+
key: "trapFocus",
|
|
1941
|
+
value: function trapFocus(element) {
|
|
1942
|
+
var focusableElements = '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])';
|
|
1943
|
+
var firstFocusableElement = element.querySelectorAll(focusableElements)[0];
|
|
1944
|
+
var focusableContent = element.querySelectorAll(focusableElements);
|
|
1945
|
+
var lastFocusableElement = focusableContent[focusableContent.length - 1];
|
|
1946
|
+
document.addEventListener('keydown', function (event) {
|
|
1947
|
+
var isTabPressed = event.key === 'Tab' || event.code === 9;
|
|
1948
|
+
|
|
1949
|
+
if (!isTabPressed) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
if (event.shiftKey) {
|
|
1954
|
+
if (document.activeElement === firstFocusableElement) {
|
|
1955
|
+
lastFocusableElement.focus();
|
|
1956
|
+
event.preventDefault();
|
|
1957
|
+
}
|
|
1958
|
+
} else if (document.activeElement === lastFocusableElement) {
|
|
1959
|
+
firstFocusableElement.focus();
|
|
1960
|
+
event.preventDefault();
|
|
1961
|
+
}
|
|
1962
|
+
});
|
|
1963
|
+
firstFocusableElement.focus();
|
|
1964
|
+
}
|
|
1965
|
+
}, {
|
|
1966
|
+
key: "moveFocus",
|
|
1967
|
+
value: function moveFocus(element) {
|
|
1968
|
+
if (document.activeElement !== element) {
|
|
1969
|
+
element.focus();
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}, {
|
|
1973
|
+
key: "toggleClass",
|
|
1974
|
+
value: function toggleClass(el, className, bool) {
|
|
1975
|
+
if (bool) el.classList.add(className);else el.classList.remove(className);
|
|
1976
|
+
}
|
|
1977
|
+
}]);
|
|
1978
|
+
|
|
1979
|
+
return Select;
|
|
1980
|
+
}();
|
|
1981
|
+
|
|
1488
1982
|
if (window.NodeList && !NodeList.prototype.forEach) {
|
|
1489
1983
|
NodeList.prototype.forEach = Array.prototype.forEach;
|
|
1490
1984
|
}
|
|
@@ -1514,9 +2008,11 @@
|
|
|
1514
2008
|
var closeSearchButton = document.querySelectorAll('.js-close-search');
|
|
1515
2009
|
var accordions = document.querySelectorAll('.js-accordion');
|
|
1516
2010
|
var dialogs = document.querySelectorAll('.js-dialog');
|
|
2011
|
+
var fileUpload = document.querySelectorAll('.js-file-upload');
|
|
1517
2012
|
var filters = document.querySelectorAll('.js-filters');
|
|
1518
2013
|
var tabs = document.querySelectorAll('.js-tabs');
|
|
1519
2014
|
var globalAlert = document.querySelectorAll('.js-global-alert');
|
|
2015
|
+
var multiSelect = document.querySelectorAll('.js-multi-select');
|
|
1520
2016
|
openSearchButton.forEach(function (element) {
|
|
1521
2017
|
new SiteSearch(element).init();
|
|
1522
2018
|
});
|
|
@@ -1532,6 +2028,12 @@
|
|
|
1532
2028
|
new Dialog(element).init();
|
|
1533
2029
|
});
|
|
1534
2030
|
|
|
2031
|
+
if (fileUpload) {
|
|
2032
|
+
fileUpload.forEach(function (element) {
|
|
2033
|
+
new FileUpload(element).init();
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
|
|
1535
2037
|
if (filters) {
|
|
1536
2038
|
filters.forEach(function (element) {
|
|
1537
2039
|
new Filters(element).init();
|
|
@@ -1549,11 +2051,21 @@
|
|
|
1549
2051
|
new GlobalAlert(element).init();
|
|
1550
2052
|
});
|
|
1551
2053
|
}
|
|
2054
|
+
|
|
2055
|
+
if (multiSelect) {
|
|
2056
|
+
multiSelect.forEach(function (element) {
|
|
2057
|
+
new Select(element).init();
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
1552
2060
|
}
|
|
1553
2061
|
|
|
1554
2062
|
exports.Accordion = Accordion;
|
|
2063
|
+
exports.Dialog = Dialog;
|
|
2064
|
+
exports.FileUpload = FileUpload;
|
|
2065
|
+
exports.Filters = Filters;
|
|
1555
2066
|
exports.GlobalAlert = GlobalAlert;
|
|
1556
2067
|
exports.Navigation = Navigation;
|
|
2068
|
+
exports.Select = Select;
|
|
1557
2069
|
exports.SiteSearch = SiteSearch;
|
|
1558
2070
|
exports.Tabs = Tabs;
|
|
1559
2071
|
exports.initSite = initSite;
|
package/package.json
CHANGED
package/src/components/_all.scss
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
@import 'callout/callout';
|
|
6
6
|
@import 'card/card';
|
|
7
7
|
@import 'content-block/content-block';
|
|
8
|
+
@import 'file-upload/file-upload';
|
|
8
9
|
@import 'filters/filters';
|
|
9
10
|
@import 'footer/footer';
|
|
10
11
|
@import 'form/form';
|
|
@@ -16,13 +17,16 @@
|
|
|
16
17
|
@import 'in-page-nav/in-page-nav';
|
|
17
18
|
@import 'link-list/link-list';
|
|
18
19
|
@import 'list-item/list-item';
|
|
20
|
+
@import 'loader/loader';
|
|
19
21
|
@import 'main-nav/main-nav';
|
|
20
22
|
@import 'masthead/masthead';
|
|
21
23
|
@import 'media/media';
|
|
22
24
|
@import 'pagination/pagination';
|
|
23
25
|
@import 'progress-indicator/progress-indicator';
|
|
24
26
|
@import 'results-bar/results-bar';
|
|
27
|
+
@import 'select/select';
|
|
25
28
|
@import 'side-nav/side-nav';
|
|
29
|
+
@import 'status-labels/status-labels';
|
|
26
30
|
@import 'steps/steps';
|
|
27
31
|
@import 'table/table';
|
|
28
32
|
@import 'tabs/tabs';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.nsw-file-upload {
|
|
2
|
+
margin-top: rem(8px);
|
|
3
|
+
display: block;
|
|
4
|
+
|
|
5
|
+
&__label {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
&__input {
|
|
10
|
+
position: absolute;
|
|
11
|
+
opacity: 0;
|
|
12
|
+
|
|
13
|
+
&:disabled {
|
|
14
|
+
+ .nsw-file-upload__label {
|
|
15
|
+
opacity: 0.4;
|
|
16
|
+
cursor: not-allowed;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&:focus + .nsw-file-upload__label {
|
|
21
|
+
@include nsw-focus;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__list {
|
|
26
|
+
display: none;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
border: 0;
|
|
30
|
+
|
|
31
|
+
&.active {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&__item {
|
|
37
|
+
display: flex;
|
|
38
|
+
max-width: rem(500px);
|
|
39
|
+
align-items: center;
|
|
40
|
+
justify-content: space-between;
|
|
41
|
+
background-color: var(--nsw-off-white);
|
|
42
|
+
border-radius: var(--nsw-border-radius);
|
|
43
|
+
padding: rem(8px);
|
|
44
|
+
|
|
45
|
+
&:not(:last-child) {
|
|
46
|
+
margin-bottom: rem(8px);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&__item-filename {
|
|
51
|
+
margin-left: rem(8px);
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
text-overflow: ellipsis;
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
}
|
|
56
|
+
}
|