@bonniernews/dn-design-system-web 7.0.1 → 7.1.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 CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 7.1.0 (2023-10-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **web:** refactored spacing ([#1062](https://github.com/BonnierNews/dn-design-system/issues/1062)) ([6d76bc0](https://github.com/BonnierNews/dn-design-system/commit/6d76bc07dfb193333ebf841962e9a42560e77a74))
12
+
13
+
14
+
6
15
  ## 7.0.1 (2023-10-20)
7
16
 
8
17
 
@@ -5,18 +5,18 @@ $ds-disclaimer__icon-size: 20px;
5
5
  $ds-btn-outlined__border-width: ds-metrics-border-width(x1);
6
6
 
7
7
  .ds-disclaimer {
8
- @include ds-spacing-layout($ds-sl-gap-vertical-static-medium, padding-bottom);
8
+ padding-bottom: ds-spacing($ds-s-gap-vertical-static-medium);
9
9
  box-sizing: border-box;
10
10
 
11
11
  .ds-disclaimer__body-html,
12
12
  .ds-disclaimer__icon-wrapper {
13
13
  background-color: $ds-color-surface-raised;
14
- padding: ds-spacing-component($ds-sc-x3 $ds-sc-x4);
14
+ padding: ds-spacing($ds-s-075 $ds-s-100);
15
15
  }
16
16
 
17
17
  .ds-disclaimer__icon-wrapper {
18
18
  // instead of margin to keep background color
19
- padding-right: ds-spacing-component($ds-sc-x2);
19
+ padding-right: ds-spacing($ds-s-050);
20
20
  }
21
21
 
22
22
  .ds-disclaimer__body-html {
@@ -2,8 +2,8 @@
2
2
  @use "../../assets/teaser/teaser.scss" as *;
3
3
 
4
4
  .ds-split-container {
5
- @include ds-spacing-layout(
6
- $ds-sl-teaser-vertical-small $ds-sl-teaser-horizontal
5
+ padding: ds-spacing(
6
+ $ds-s-teaser-vertical-small $ds-s-teaser-horizontal
7
7
  $ds-sl-teaser-vertical-medium
8
8
  );
9
9
  display: flex;
@@ -21,7 +21,7 @@
21
21
  right: 0;
22
22
  top: 0;
23
23
  position: absolute;
24
- @include ds-spacing-layout(0 $ds-sl-teaser-horizontal, margin);
24
+ margin: ds-spacing(0 $ds-s-teaser-horizontal);
25
25
  }
26
26
  }
27
27
 
@@ -30,7 +30,7 @@
30
30
  display: block;
31
31
  position: relative;
32
32
  flex: 1;
33
- margin-right: ds-spacing-component($ds-sc-x4);
33
+ margin-right: ds-spacing($ds-s-100);
34
34
  &:last-child {
35
35
  margin-right: 0;
36
36
  }
@@ -38,7 +38,7 @@
38
38
  @include ds-teaser-focus(4px);
39
39
 
40
40
  @include ds-mq-largest-breakpoint(mobile) {
41
- width: calc(50% - ds-spacing-component($ds-sc-x4) / 2);
41
+ width: calc(50% - ds-spacing($ds-s-100) / 2);
42
42
  flex: auto;
43
43
  // if a teaser is both third and last child it has the row by itself and should be full width
44
44
  &:nth-child(3):last-child {
@@ -53,8 +53,8 @@
53
53
  &:nth-child(4)::before {
54
54
  display: block;
55
55
  content: "";
56
- @include ds-spacing-layout($ds-sl-teaser-vertical-medium, margin-top);
57
- @include ds-spacing-layout($ds-sl-teaser-vertical-small, padding-top);
56
+ margin-top: ds-spacing($ds-s-teaser-vertical-medium);
57
+ padding-top: ds-spacing($ds-s-teaser-vertical-small);
58
58
  border-top: ds-metrics-border-width(x1) solid $ds-color-border-primary;
59
59
 
60
60
  @include ds-mq-smallest-breakpoint(tablet) {
@@ -65,7 +65,7 @@
65
65
  }
66
66
 
67
67
  &:nth-child(3):not(:last-child)::before {
68
- margin-right: ds-spacing-component($ds-sc-x4, "px", true);
68
+ margin-right: ds-spacing($ds-s-100, "px", true);
69
69
  }
70
70
 
71
71
  .ds-teaser__title {
@@ -74,7 +74,7 @@
74
74
 
75
75
  .ds-teaser__media {
76
76
  @include ds-mq-largest-breakpoint(mobile) {
77
- margin-bottom: ds-spacing-component($ds-sc-x2);
77
+ margin-bottom: ds-spacing($ds-s-050);
78
78
 
79
79
  .ds-teaser-image__byline {
80
80
  display: none;
@@ -82,7 +82,7 @@
82
82
  }
83
83
 
84
84
  @include ds-mq-smallest-breakpoint(tablet) {
85
- margin-bottom: ds-spacing-component($ds-sc-x3);
85
+ margin-bottom: ds-spacing($ds-s-075);
86
86
  }
87
87
  }
88
88
  }
@@ -1,3 +1,4 @@
1
1
  @use "./colors.scss";
2
2
  @use "./fontFamily.scss";
3
3
  @use "./shadows.scss";
4
+ @use "./spacing.scss";
@@ -1,6 +1,6 @@
1
1
  - GitHub: [BonnierNews/dn-design-system/../web/src/foundations/helpers/spacing.scss](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/foundations/helpers/spacing.scss)
2
- - Storybook: [Spacing > Component](https://designsystem.dn.se/?path=/story/foundations-spacing--component)
3
- - Storybook: [Spacing > Layout](https://designsystem.dn.se/?path=/story/foundations-spacing--layout)
2
+ - Storybook: [Spacing > Base](https://designsystem.dn.se/?path=/story/foundations-spacing--base)
3
+ - Storybook: [Spacing > Detail](https://designsystem.dn.se/?path=/story/foundations-spacing--detail)
4
4
 
5
5
  ----
6
6
 
@@ -9,102 +9,50 @@
9
9
  ## use sass variable
10
10
  To avoid silent breaking changes use sass variable instead of raw token name.
11
11
 
12
- Ex: `margin: ds-spacing-component($ds-sc-x1 0 $ds-sc-x4)`
13
-
14
- Ex: `@include ds-spacing-layout($ds-sl-page-horizontal auto, padding-top)`
12
+ Ex: `margin: ds-spacing($ds-s-050 0 $ds-s-page-horizontal)`
15
13
 
16
14
  By using sass variables (instead of token name directly), if a spacing token used in scss is removed sass will not compile - which is a good thing!
17
15
 
18
16
  By using sass variables for spacing tokens you will see which tokens are available through auto complete.
19
17
 
20
- Variables with `$ds-sc-` prefix are available for `ds-spacing-component()`
21
-
22
- Variables with `$ds-sl-` prefix are available for `ds-spacing-layout()`
23
-
24
- ## ds-spacing-component | function
25
-
26
- Use for space _inside_ a component (or atom).
27
-
28
- Dynamic spacings are static and are _not_ wrapped in any media query, the function only return values.
18
+ ## ds-spacing | function
29
19
 
30
20
  ### Parameters
31
21
 
32
22
  |parameter | type | required | options | default | description |
33
23
  |:--- | :--- | :--- | :--- | :--- | :--- |
34
- |units | String | yes | one or more spacing tokens or `auto` or `0` | | Ex. x2 0 x4 |
35
- |sizeUnit | String | no | px, rem, em | px | |
24
+ |units | String | yes | one or more spacing tokens or `auto` or `0` or numeric value `14`| | $ds-s-050 0 $ds-s-page-horizontal 14 |
25
+ |sizeUnit | String | no | px, rem | px | |
36
26
  |negative | bool | no | true, false | false | Applies to all units except for `auto` and `0` |
37
27
 
38
28
  ```scss
39
29
  @use "@bonniernews/dn-design-system-web/foundations/helpers/forward.helpers.scss" as *;
40
30
 
41
31
  .test-1 {
42
- margin: ds-spacing-component($ds-sc-x1 $ds-sc-x2 0);
32
+ margin: ds-spacing($ds-s-050 0 $ds-s-page-horizontal auto);
33
+ padding: ds-spacing($ds-s-125 14);
43
34
  }
44
35
 
45
36
  // Outputs:
46
- 4px 8px 0
47
-
48
- .test-2 {
49
- margin: ds-spacing-component($ds-sc-x1 $ds-sc-x2 0, px, true);
50
- }
51
-
52
- // Outputs:
53
- -4px -8px 0
54
- ```
55
-
56
- ## ds-spacing-layout | mixin
57
-
58
- Use for space _between_ components.
59
-
60
- This mixin returns `property: value` wrapped in media query.
61
-
62
- ### Parameters
63
-
64
- |parameter | type | required | options | default | description |
65
- |:--- | :--- | :--- | :--- | :--- | :--- |
66
- |units | String | yes | one or more spacing tokens or `auto` or `0` | | Ex. 0 page-horizontal |
67
- |property | String | no | padding, margin | padding | Use padding for layout spacing to avoid collapsing margins|
68
- |sizeUnit | String | no | px, rem, em | px | |
69
- |negative | bool | no | true, false | false | Applies to all units except for `auto` and `0` |
70
-
71
- ```scss
72
- @use "@bonniernews/dn-design-system-web/foundations/helpers/forward.helpers.scss" as *;
73
-
74
37
  .test-1 {
75
- @include ds-spacing-layout($ds-sl-page-top-small, padding-top);
76
- }
77
-
78
- // Outputs:
79
- @media (max-width: 1024px) {
80
- .test-1 {
81
- padding-top: 16px;
82
- }
83
- }
84
- @media (min-width: 1025px) {
85
- .test-1 {
86
- padding-top: 32px;
87
- }
38
+ margin: 8px 0 var(--ds-spacing-px-page-horizontal) auto;
39
+ padding: 20px 14px;
88
40
  }
89
41
 
90
42
  .test-2 {
91
- @include ds-spacing-layout(
92
- 0 $ds-sl-page-horizontal,
93
- margin,
94
- px,
95
- true
96
- );
43
+ margin: ds-spacing($ds-s-050 0 $ds-s-page-horizontal auto, rem, true);
44
+ padding: ds-spacing($ds-s-125 14, rem);
97
45
  }
98
46
 
99
47
  // Outputs:
100
- @media (max-width: 1024px) {
101
- .test-2 {
102
- margin: 0 -16px;
103
- }
104
- }
105
- @media (min-width: 1025px) {
106
- .test-2 {
107
- margin: 0 -32px;
108
- }
48
+ .test-2 {
49
+ margin: -0.5rem 0 var(--ds-spacing-negative-rem-page-horizontal) auto;
50
+ padding: 1.25rem 0.875rem;
109
51
  }
110
52
  ```
53
+
54
+ ## ⚠️ Deprecated functions and mixins
55
+
56
+ The function `ds-spacing-component()` is deprecated.
57
+
58
+ The mixin `@include ds-spacing-layout()` is deprecated.
@@ -0,0 +1,77 @@
1
+ @use "sass:list";
2
+ @use "sass:math";
3
+ @use "sass:map";
4
+ @use "mediaQueries.scss" as *;
5
+ @use "../variables/deprecated/spacingComponent.scss" as *;
6
+ @use "../variables/deprecated/spacingLayout.scss" as *;
7
+ @use "../variables/deprecated/spacingLayoutLargeScreen.scss" as *;
8
+ @forward "../variables/deprecated/spacingComponentList.scss";
9
+ @forward "../variables/deprecated/spacingLayoutList.scss";
10
+
11
+ @function ds-spacing-component(
12
+ $units: null,
13
+ $sizeUnit: "px",
14
+ $negative: false
15
+ ) {
16
+ @if $units {
17
+ @return _ds-get-spacings-deprecated($spacingComponent, $units, $sizeUnit, $negative);
18
+ }
19
+
20
+ @return null;
21
+ }
22
+
23
+ @mixin ds-spacing-layout(
24
+ $units: null,
25
+ $property: padding,
26
+ $sizeUnit: "px",
27
+ $negative: false
28
+ ) {
29
+ @if $units {
30
+ $values: _ds-get-spacings-deprecated($spacingLayout, $units, $sizeUnit, $negative);
31
+ @include ds-mq-largest-breakpoint(mobile) {
32
+ #{$property}: $values;
33
+ }
34
+ $valuesLargeScreen: _ds-get-spacings-deprecated(
35
+ $spacingLayoutLargeScreen,
36
+ $units,
37
+ $sizeUnit,
38
+ $negative
39
+ );
40
+ @include ds-mq-smallest-breakpoint(tablet) {
41
+ #{$property}: $valuesLargeScreen;
42
+ }
43
+ }
44
+ }
45
+
46
+ @function _ds-get-spacings-deprecated($map, $units, $sizeUnit: "px", $negative: false) {
47
+ $values: ();
48
+
49
+ @each $unit in $units {
50
+ $value: map.get($map, $unit);
51
+ @if ($unit == "auto") {
52
+ $value: auto;
53
+ } @else if ($unit == 0) {
54
+ $value: 0 * 1;
55
+ } @else if ($value and type-of($value) == "number") {
56
+ @if ($sizeUnit == "rem") {
57
+ $value: (math.div($value, 16)) * 1rem;
58
+ } @else if ($sizeUnit == "em") {
59
+ $value: (math.div($value, 16)) * 1em;
60
+ } @else {
61
+ $value: $value * 1px;
62
+ }
63
+ @if $negative {
64
+ $value: $value * -1;
65
+ }
66
+ }
67
+ @if (type-of($value) == "number" or $value == "auto") {
68
+ $values: list.append($values, $value);
69
+ }
70
+ }
71
+
72
+ @if length($values) == 1 {
73
+ @return list.nth($values, 1);
74
+ }
75
+
76
+ @return $values;
77
+ }
@@ -2,76 +2,60 @@
2
2
  @use "sass:math";
3
3
  @use "sass:map";
4
4
  @use "mediaQueries.scss" as *;
5
- @use "../variables/spacingComponent.scss" as *;
6
- @use "../variables/spacingLayout.scss" as *;
7
- @use "../variables/spacingLayoutLargeScreen.scss" as *;
8
- @forward "../variables/spacingComponentList.scss";
9
- @forward "../variables/spacingLayoutList.scss";
5
+ @use "../variables/spacingBase.scss" as *;
6
+ @forward "../variables/spacingBaseList.scss";
7
+ @use "../variables/spacingDetail.scss" as *;
8
+ @use "../variables/spacingDetailScreenLarge.scss" as *;
9
+ @forward "../variables/spacingDetailList.scss";
10
10
 
11
- @function ds-spacing-component(
12
- $units: null,
13
- $sizeUnit: "px",
14
- $negative: false
15
- ) {
16
- @if $units {
17
- @return _ds-get-spacings($spacingComponent, $units, $sizeUnit, $negative);
18
- }
11
+ // @todo remove when possible
12
+ @forward "spacing-deprecated.scss";
19
13
 
20
- @return null;
21
- }
22
-
23
- @mixin ds-spacing-layout(
14
+ @function ds-spacing(
24
15
  $units: null,
25
- $property: padding,
26
16
  $sizeUnit: "px",
27
17
  $negative: false
28
18
  ) {
29
19
  @if $units {
30
- $values: _ds-get-spacings($spacingLayout, $units, $sizeUnit, $negative);
31
- @include ds-mq-largest-breakpoint(mobile) {
32
- #{$property}: $values;
33
- }
34
- $valuesLargeScreen: _ds-get-spacings(
35
- $spacingLayoutLargeScreen,
36
- $units,
37
- $sizeUnit,
38
- $negative
39
- );
40
- @include ds-mq-smallest-breakpoint(tablet) {
41
- #{$property}: $valuesLargeScreen;
42
- }
43
- }
44
- }
20
+ $values: ();
45
21
 
46
- @function _ds-get-spacings($map, $units, $sizeUnit: "px", $negative: false) {
47
- $values: ();
48
-
49
- @each $unit in $units {
50
- $value: map.get($map, $unit);
51
- @if ($unit == "auto") {
52
- $value: auto;
53
- } @else if ($unit == 0) {
54
- $value: 0 * 1;
55
- } @else if ($value and type-of($value) == "number") {
56
- @if ($sizeUnit == "rem") {
57
- $value: (math.div($value, 16)) * 1rem;
58
- } @else if ($sizeUnit == "em") {
59
- $value: (math.div($value, 16)) * 1em;
22
+ @each $unit in $units {
23
+ @if map.has-key($spacingDetail, $unit) {
24
+ $value: var(--ds-spacing-#{$sizeUnit}-#{$unit});
25
+ @if ($negative) {
26
+ $value: calc(var(--ds-spacing-#{$sizeUnit}-#{$unit}) * -1);
27
+ }
28
+ $values: list.append($values, $value);
60
29
  } @else {
61
- $value: $value * 1px;
62
- }
63
- @if $negative {
64
- $value: $value * -1;
30
+ $value: $unit;
31
+ @if map.has-key($spacingBase, $unit) {
32
+ $value: map.get($spacingBase, $unit);
33
+ }
34
+
35
+ @if ($value == 0) {
36
+ $value: 0 * 1;
37
+ } @else if ($value and type-of($value) == "number") {
38
+ @if ($sizeUnit == "rem") {
39
+ $value: (math.div($value, 16)) * 1rem;
40
+ } @else {
41
+ $value: $value * 1px;
42
+ }
43
+ @if $negative {
44
+ $value: $value * -1;
45
+ }
46
+ }
47
+ @if (type-of($value) == "number" or $value == "auto") {
48
+ $values: list.append($values, $value);
49
+ }
65
50
  }
66
51
  }
67
- @if (type-of($value) == "number" or $value == "auto") {
68
- $values: list.append($values, $value);
52
+
53
+ @if length($values) == 1 {
54
+ @return list.nth($values, 1);
69
55
  }
70
- }
71
56
 
72
- @if length($values) == 1 {
73
- @return list.nth($values, 1);
57
+ @return $values;
74
58
  }
75
59
 
76
- @return $values;
60
+ @return null;
77
61
  }
@@ -0,0 +1,24 @@
1
+ @use "sass:map";
2
+ @use "sass:meta";
3
+ @use "./variables/spacingDetail";
4
+ @use "./variables/spacingDetailScreenLarge";
5
+ @use "./helpers/mediaQueries.scss" as *;
6
+ @use "./helpers/utilities.scss" as *;
7
+
8
+ :root {
9
+ @each $name, $map in meta.module-variables("spacingDetail") {
10
+ @each $key in map-keys($map) {
11
+ --ds-spacing-px-#{$key}: #{map.get($map, $key) * 1px};
12
+ --ds-spacing-rem-#{$key}: #{ds-px-to-rem(map.get($map, $key))};
13
+ }
14
+ }
15
+
16
+ @include ds-mq-smallest-breakpoint(tablet) {
17
+ @each $name, $map in meta.module-variables("spacingDetailScreenLarge") {
18
+ @each $key in map-keys($map) {
19
+ --ds-spacing-px-#{$key}: #{map.get($map, $key) * 1px};
20
+ --ds-spacing-rem-#{$key}: #{ds-px-to-rem(map.get($map, $key))};
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,14 @@
1
+ $spacingBase: (
2
+ 100: 16,
3
+ 125: 20,
4
+ 150: 24,
5
+ 200: 32,
6
+ 250: 40,
7
+ 300: 48,
8
+ 350: 56,
9
+ 400: 64,
10
+ 500: 80,
11
+ 025: 4,
12
+ 050: 8,
13
+ 075: 12
14
+ );
@@ -0,0 +1,12 @@
1
+ $ds-s-100: 100;
2
+ $ds-s-125: 125;
3
+ $ds-s-150: 150;
4
+ $ds-s-200: 200;
5
+ $ds-s-250: 250;
6
+ $ds-s-300: 300;
7
+ $ds-s-350: 350;
8
+ $ds-s-400: 400;
9
+ $ds-s-500: 500;
10
+ $ds-s-025: 025;
11
+ $ds-s-050: 050;
12
+ $ds-s-075: 075;
@@ -0,0 +1,15 @@
1
+ $spacingDetail: (
2
+ outer: 16,
3
+ outer-negative: -16,
4
+ page-horizontal: 16,
5
+ page-top-small: 16,
6
+ gap-vertical-static-medium: 16,
7
+ gap-vertical-medium: 16,
8
+ gap-vertical-static-large: 32,
9
+ gap-vertical-static-small: 8,
10
+ page-top-xsmall: 4,
11
+ teaser-vertical-small: 8,
12
+ teaser-horizontal: 16,
13
+ teaser-vertical-medium: 12,
14
+ direkt-header-bottom: 48
15
+ );
@@ -0,0 +1,13 @@
1
+ $ds-s-outer: outer;
2
+ $ds-s-outer-negative: outer-negative;
3
+ $ds-s-page-horizontal: page-horizontal;
4
+ $ds-s-page-top-small: page-top-small;
5
+ $ds-s-gap-vertical-static-medium: gap-vertical-static-medium;
6
+ $ds-s-gap-vertical-medium: gap-vertical-medium;
7
+ $ds-s-gap-vertical-static-large: gap-vertical-static-large;
8
+ $ds-s-gap-vertical-static-small: gap-vertical-static-small;
9
+ $ds-s-page-top-xsmall: page-top-xsmall;
10
+ $ds-s-teaser-vertical-small: teaser-vertical-small;
11
+ $ds-s-teaser-horizontal: teaser-horizontal;
12
+ $ds-s-teaser-vertical-medium: teaser-vertical-medium;
13
+ $ds-s-direkt-header-bottom: direkt-header-bottom;
@@ -0,0 +1,15 @@
1
+ $spacingDetailScreenLarge: (
2
+ page-top-small: 32,
3
+ page-horizontal: 32,
4
+ gap-vertical-medium: 32,
5
+ teaser-vertical-small: 12,
6
+ teaser-horizontal: 16,
7
+ teaser-vertical-medium: 16,
8
+ direkt-header-bottom: 64,
9
+ outer: 16,
10
+ outer-negative: -16,
11
+ gap-vertical-static-medium: 16,
12
+ gap-vertical-static-large: 32,
13
+ gap-vertical-static-small: 8,
14
+ page-top-xsmall: 4
15
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonniernews/dn-design-system-web",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "DN design system for web.",
5
5
  "main": "index.js",
6
6
  "homepage": "https://github.com/BonnierNews/dn-design-system/tree/main/web/src#readme",
@@ -0,0 +1,14 @@
1
+ {
2
+ "100": "100",
3
+ "125": "125",
4
+ "150": "150",
5
+ "200": "200",
6
+ "250": "250",
7
+ "300": "300",
8
+ "350": "350",
9
+ "400": "400",
10
+ "500": "500",
11
+ "025": "025",
12
+ "050": "050",
13
+ "075": "075"
14
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "outer": "outer",
3
+ "outer-negative": "outer-negative",
4
+ "page-horizontal": "page-horizontal",
5
+ "page-top-small": "page-top-small",
6
+ "gap-vertical-static-medium": "gap-vertical-static-medium",
7
+ "gap-vertical-medium": "gap-vertical-medium",
8
+ "gap-vertical-static-large": "gap-vertical-static-large",
9
+ "gap-vertical-static-small": "gap-vertical-static-small",
10
+ "page-top-xsmall": "page-top-xsmall",
11
+ "teaser-vertical-small": "teaser-vertical-small",
12
+ "teaser-horizontal": "teaser-horizontal",
13
+ "teaser-vertical-medium": "teaser-vertical-medium",
14
+ "direkt-header-bottom": "direkt-header-bottom"
15
+ }