nsw-design-system 3.3.0 → 3.4.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
@@ -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;
@@ -1514,6 +1610,7 @@
1514
1610
  var closeSearchButton = document.querySelectorAll('.js-close-search');
1515
1611
  var accordions = document.querySelectorAll('.js-accordion');
1516
1612
  var dialogs = document.querySelectorAll('.js-dialog');
1613
+ var fileUpload = document.querySelectorAll('.js-file-upload');
1517
1614
  var filters = document.querySelectorAll('.js-filters');
1518
1615
  var tabs = document.querySelectorAll('.js-tabs');
1519
1616
  var globalAlert = document.querySelectorAll('.js-global-alert');
@@ -1532,6 +1629,12 @@
1532
1629
  new Dialog(element).init();
1533
1630
  });
1534
1631
 
1632
+ if (fileUpload) {
1633
+ fileUpload.forEach(function (element) {
1634
+ new FileUpload(element).init();
1635
+ });
1636
+ }
1637
+
1535
1638
  if (filters) {
1536
1639
  filters.forEach(function (element) {
1537
1640
  new Filters(element).init();
@@ -1552,6 +1655,9 @@
1552
1655
  }
1553
1656
 
1554
1657
  exports.Accordion = Accordion;
1658
+ exports.Dialog = Dialog;
1659
+ exports.FileUpload = FileUpload;
1660
+ exports.Filters = Filters;
1555
1661
  exports.GlobalAlert = GlobalAlert;
1556
1662
  exports.Navigation = Navigation;
1557
1663
  exports.SiteSearch = SiteSearch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsw-design-system",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Design system for Digital NSW",
5
5
  "main": "dist/main.js",
6
6
  "style": "dist/main.css",
@@ -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,6 +17,7 @@
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';
@@ -23,6 +25,7 @@
23
25
  @import 'progress-indicator/progress-indicator';
24
26
  @import 'results-bar/results-bar';
25
27
  @import 'side-nav/side-nav';
28
+ @import 'status-labels/status-labels';
26
29
  @import 'steps/steps';
27
30
  @import 'table/table';
28
31
  @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
+ }
@@ -0,0 +1,87 @@
1
+ /* eslint-disable max-len */
2
+ class FileUpload {
3
+ constructor(element) {
4
+ this.element = element
5
+ this.input = this.element.querySelector('.nsw-file-upload__input')
6
+ this.label = this.element.querySelector('.nsw-file-upload__label')
7
+ this.multipleUpload = this.input.hasAttribute('multiple')
8
+ this.replaceFiles = this.element.hasAttribute('data-replace-files')
9
+ this.filesList = false
10
+ }
11
+
12
+ init() {
13
+ if (!this.input) return
14
+
15
+ this.input.addEventListener('change', () => {
16
+ if (this.input.value === '') return
17
+ this.updateFileList()
18
+ })
19
+ }
20
+
21
+ createFileList() {
22
+ const ul = document.createElement('ul')
23
+ ul.classList.add('nsw-file-upload__list')
24
+ this.label.insertAdjacentElement('afterend', ul)
25
+ this.filesList = this.element.querySelector('.nsw-file-upload__list')
26
+ }
27
+
28
+ createFileItem(file) {
29
+ const li = document.createElement('li')
30
+ li.classList.add('nsw-file-upload__item')
31
+ const html = `
32
+ <span class="nsw-file-upload__item-filename"></span>
33
+ <button type="button" class="nsw-icon-button">
34
+ <span class="sr-only">Remove file</span>
35
+ <span class="material-icons nsw-material-icons" focusable="false" aria-hidden="true">cancel</span>
36
+ </button>`
37
+
38
+ li.insertAdjacentHTML('afterbegin', html)
39
+ li.querySelector('.nsw-file-upload__item-filename').textContent = this.constructor.truncateString(file.name, 50)
40
+ return li.outerHTML
41
+ }
42
+
43
+ updateFileList() {
44
+ if (!this.filesList) {
45
+ this.createFileList()
46
+ }
47
+
48
+ this.filesList.classList.add('active')
49
+
50
+ let string = ''
51
+ for (let i = 0; i < this.input.files.length; i += 1) {
52
+ const file = this.input.files[i]
53
+ string = this.createFileItem(file) + string
54
+ }
55
+
56
+ if (this.replaceFiles) {
57
+ this.filesList.innerHTML = string
58
+ } else {
59
+ this.filesList.insertAdjacentHTML('beforeend', string)
60
+ }
61
+
62
+ this.removeFile()
63
+ }
64
+
65
+ removeFile() {
66
+ this.filesList.addEventListener('click', (event) => {
67
+ if (!event.target.closest('.nsw-icon-button')) return
68
+ event.preventDefault()
69
+ const item = event.target.closest('.nsw-file-upload__item')
70
+
71
+ item.remove()
72
+
73
+ if (event.currentTarget.children.length === 0) {
74
+ this.filesList.classList.remove('active')
75
+ }
76
+ })
77
+ }
78
+
79
+ static truncateString(str, num) {
80
+ if (str.length <= num) {
81
+ return str
82
+ }
83
+ return `${str.slice(0, num)}...`
84
+ }
85
+ }
86
+
87
+ export default FileUpload
@@ -0,0 +1,62 @@
1
+ //Variations
2
+ $nsw-loaders: (
3
+ sm: (
4
+ size: rem(24px),
5
+ border: 3px,
6
+ ),
7
+ md: (
8
+ size: rem(32px),
9
+ border: 3px,
10
+ ),
11
+ lg: (
12
+ size: rem(48px),
13
+ border: 4px,
14
+ )
15
+ );
16
+
17
+ .nsw-loader {
18
+ text-align: center;
19
+ width: fit-content;
20
+
21
+ &__circle {
22
+ position: relative;
23
+ display: inline-flex;
24
+ border-radius: 50%;
25
+ border-style: solid;
26
+ animation-name: nsw-loader-animation-rotate;
27
+ animation-duration: 1.4s;
28
+ animation-timing-function: linear;
29
+ animation-iteration-count: infinite;
30
+ width: rem(64px);
31
+ height: rem(64px);
32
+ border-width: 4px;
33
+ transform-origin: 50% 50% calc((4rem / 2) + 4px);
34
+ border-color: var(--nsw-grey-03);
35
+ border-top-color: var(--nsw-brand-accent);
36
+
37
+ @each $size, $variant in $nsw-loaders {
38
+ &--#{"" + $size} {
39
+ width: map-get($variant, size);
40
+ height: map-get($variant, size);
41
+ transform-origin: 50% 50% calc((#{map-get($variant, size)} / 2) + #{map-get($variant, border)});
42
+ @if map-get($variant, border) == 3px {
43
+ border-width: map-get($variant, border);
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ &__label {
50
+ display: block;
51
+ }
52
+ }
53
+
54
+ @keyframes nsw-loader-animation-rotate {
55
+ 0% {
56
+ transform: rotate(0deg);
57
+ }
58
+
59
+ 100% {
60
+ transform: rotate(360deg);
61
+ }
62
+ }
@@ -0,0 +1,19 @@
1
+ $nsw-status-labels: ( info, success, warning, error );
2
+
3
+ .nsw-status-label {
4
+ @include font-size('xs');
5
+ padding: rem(2px) rem(16px);
6
+ border: solid 1px var(--nsw-off-white);
7
+ background-color: var(--nsw-off-white);
8
+ border-radius: rem(24px);
9
+ color: var(--nsw-text-dark);
10
+ display: inline-block;
11
+
12
+ @each $color, $variant in $nsw-status-labels {
13
+ &--#{"" + $color} {
14
+ border-color: var(--nsw-status-#{$color});
15
+ background-color: var(--nsw-status-#{$color});
16
+ color: var(--nsw-white);
17
+ }
18
+ }
19
+ }
@@ -118,18 +118,18 @@
118
118
 
119
119
  --nsw-palette-info-blue: #2e5299;
120
120
  --nsw-palette-info-blue-bg: #eaedf4;
121
- --nsw-palette-success-green: #00a908;
121
+ --nsw-palette-success-green: #008a07;
122
122
  --nsw-palette-success-green-bg: #e5f6e6;
123
- --nsw-palette-warning-orange: #dc5800;
123
+ --nsw-palette-warning-orange: #c95000;
124
124
  --nsw-palette-warning-orange-bg: #fbeee5;
125
125
  --nsw-palette-error-red: #b81237;
126
126
  --nsw-palette-error-red-bg: #f7e7eb;
127
127
 
128
128
  --nsw-palette-info-blue-rgb: 46, 82, 153;
129
129
  --nsw-palette-info-blue-bg-rgb: 234, 237, 244;
130
- --nsw-palette-success-green-rgb: 0, 169, 8;
130
+ --nsw-palette-success-green-rgb: 0, 138, 7;
131
131
  --nsw-palette-success-green-bg-rgb: 229, 246, 230;
132
- --nsw-palette-warning-orange-rgb: 220, 88, 0;
132
+ --nsw-palette-warning-orange-rgb: 201, 80, 0;
133
133
  --nsw-palette-warning-orange-bg-rgb: 251, 238, 229;
134
134
  --nsw-palette-error-red-rgb: 184, 18, 55;
135
135
  --nsw-palette-error-red-bg-rgb: 247, 231, 235;
package/src/main.js CHANGED
@@ -3,6 +3,7 @@ import Navigation from './components/main-nav/main-nav'
3
3
  import Accordion from './components/accordion/accordion'
4
4
  import Dialog from './components/dialog/dialog'
5
5
  import Filters from './components/filters/filters'
6
+ import FileUpload from './components/file-upload/file-upload'
6
7
  import Tabs from './components/tabs/tabs'
7
8
  import GlobalAlert from './components/global-alert/global-alert'
8
9
 
@@ -32,6 +33,7 @@ function initSite() {
32
33
  const closeSearchButton = document.querySelectorAll('.js-close-search')
33
34
  const accordions = document.querySelectorAll('.js-accordion')
34
35
  const dialogs = document.querySelectorAll('.js-dialog')
36
+ const fileUpload = document.querySelectorAll('.js-file-upload')
35
37
  const filters = document.querySelectorAll('.js-filters')
36
38
  const tabs = document.querySelectorAll('.js-tabs')
37
39
  const globalAlert = document.querySelectorAll('.js-global-alert')
@@ -55,6 +57,12 @@ function initSite() {
55
57
  new Dialog(element).init()
56
58
  })
57
59
 
60
+ if (fileUpload) {
61
+ fileUpload.forEach((element) => {
62
+ new FileUpload(element).init()
63
+ })
64
+ }
65
+
58
66
  if (filters) {
59
67
  filters.forEach((element) => {
60
68
  new Filters(element).init()
@@ -75,5 +83,5 @@ function initSite() {
75
83
  }
76
84
 
77
85
  export {
78
- initSite, SiteSearch, Navigation, Accordion, Tabs, GlobalAlert,
86
+ initSite, SiteSearch, Navigation, Accordion, Tabs, GlobalAlert, Dialog, Filters, FileUpload,
79
87
  }
package/src/main.scss CHANGED
@@ -14,6 +14,7 @@
14
14
  @import 'components/callout/callout';
15
15
  @import 'components/card/card';
16
16
  @import 'components/content-block/content-block';
17
+ @import 'components/file-upload/file-upload';
17
18
  @import 'components/filters/filters';
18
19
  @import 'components/footer/footer';
19
20
  @import 'components/form/form';
@@ -25,6 +26,7 @@
25
26
  @import 'components/in-page-nav/in-page-nav';
26
27
  @import 'components/link-list/link-list';
27
28
  @import 'components/list-item/list-item';
29
+ @import 'components/loader/loader';
28
30
  @import 'components/main-nav/main-nav';
29
31
  @import 'components/masthead/masthead';
30
32
  @import 'components/media/media';
@@ -32,6 +34,7 @@
32
34
  @import 'components/progress-indicator/progress-indicator';
33
35
  @import 'components/results-bar/results-bar';
34
36
  @import 'components/side-nav/side-nav';
37
+ @import 'components/status-labels/status-labels';
35
38
  @import 'components/steps/steps';
36
39
  @import 'components/table/table';
37
40
  @import 'components/tabs/tabs';