energy-foundations 2.4.0 → 2.5.0-beta.1

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.
@@ -1,31 +1,194 @@
1
+ @use 'sass:list';
1
2
  @use 'sass:map';
3
+ @use 'sass:selector';
4
+ @use 'sass:string';
5
+ @use '../variables/grid' as *;
2
6
  @use '../variables/layout' as *;
7
+ @use 'breakpoint-fixed' as *;
3
8
 
4
- // Responsive media queries
9
+ $_layout-b-keys: (
10
+ mobile: mobile-v2,
11
+ tablet: tablet-v2,
12
+ desktop: desktop-v2,
13
+ desktop-large: desktop-large-v2,
14
+ ultrawide: ultrawide-v2
15
+ );
16
+
17
+ $_layout-conditions: (
18
+ a: ":not([data-rds-layout='b'])",
19
+ b: "[data-rds-layout='b']"
20
+ );
21
+
22
+ // Layout resolved by an enclosing breakpoint; nested calls reuse it instead of adding a second body context.
23
+ $_active-layout: null;
24
+
25
+ // Responsive media queries that follow the layout declared on body[data-rds-layout].
26
+ // Semantic keys use Layout A by default and their *-v2 values with body[data-rds-layout='b'].
27
+ // Explicit *-v2 and custom keys are fixed media queries.
5
28
  // use:
6
29
  // .element {
7
- // @include breakpoint(mobile|tablet|desktop|desktop-large|ultrawide){
30
+ // @include breakpoint(mobile|tablet|desktop|desktop-large|ultrawide) {
31
+ // ...
32
+ // }
33
+ // }
34
+ // or at the root:
35
+ // @include breakpoint(tablet) {
36
+ // .element {
8
37
  // ...
9
38
  // }
10
- // }
39
+ // }
11
40
  @mixin breakpoint($breakpoint) {
12
- $value: map.get($breakpoints, $breakpoint);
41
+ @if map.has-key($_layout-b-keys, $breakpoint) {
42
+ $layout-b-key: map.get($_layout-b-keys, $breakpoint);
43
+
44
+ @if not map.get($breakpoints, $breakpoint) or not map.get($breakpoints, $layout-b-key) {
45
+ @error 'Missing layout A/B values for breakpoint: #{$breakpoint}.';
46
+ }
13
47
 
14
- // If the key exists in the map
15
- @if $value {
16
- @if $breakpoint == mobile or $breakpoint == mobile-v2 {
17
- @media (max-width: $value) {
48
+ @if $_active-layout == a {
49
+ @include fixed-breakpoint($breakpoint) {
18
50
  @content;
19
51
  }
20
- } @else {
21
- @media (min-width: $value) {
52
+ } @else if $_active-layout == b {
53
+ @include fixed-breakpoint($layout-b-key) {
22
54
  @content;
23
55
  }
56
+ } @else {
57
+ @include _layout-context(a) {
58
+ @include fixed-breakpoint($breakpoint) {
59
+ @content;
60
+ }
61
+ }
62
+
63
+ @include _layout-context(b) {
64
+ @include fixed-breakpoint($layout-b-key) {
65
+ @content;
66
+ }
67
+ }
68
+ }
69
+ } @else {
70
+ @include fixed-breakpoint($breakpoint) {
71
+ @content;
72
+ }
73
+ }
74
+ }
75
+
76
+ @mixin _layout-context($layout) {
77
+ $previous-layout: $_active-layout;
78
+ $condition: map.get($_layout-conditions, $layout);
79
+
80
+ @if $previous-layout == $layout {
81
+ // Already resolved by an enclosing breakpoint: do not add a second body condition.
82
+ @content;
83
+ } @else if $previous-layout {
84
+ // Nested inside the other layout: these rules can never match.
85
+ } @else if & {
86
+ $_active-layout: $layout !global;
87
+
88
+ @at-root #{_contextualize(&, $condition)} {
89
+ @content;
90
+ }
91
+ } @else {
92
+ $_active-layout: $layout !global;
93
+
94
+ // At the root the context prefixes the selectors written inside the content.
95
+ :where(body#{$condition}) {
96
+ @content;
24
97
  }
25
98
  }
26
99
 
27
- // If the key doesn't exist in the map
28
- @else {
29
- @warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. " + "Please make sure it is defined in `$breakpoints` map.";
100
+ $_active-layout: $previous-layout !global;
101
+ }
102
+
103
+ // Page container that follows the layout declared on body[data-rds-layout].
104
+ // Layout A: 16/24/32px gutters and 1600px max width. Layout B: up to 72px gutters and 1584px max width.
105
+ // use:
106
+ // .portal-main {
107
+ // @include layout-max;
108
+ // }
109
+ @mixin layout-max {
110
+ @if not & {
111
+ @error 'layout-max must be included inside a selector, e.g. `.portal-main { @include layout-max; }`.';
112
+ }
113
+
114
+ padding: 0 $g-padding-mobile;
115
+
116
+ @include breakpoint(tablet) {
117
+ padding: 0 $g-padding-tablet;
30
118
  }
119
+
120
+ @include breakpoint(desktop) {
121
+ padding: 0 $g-padding-desktop;
122
+ }
123
+
124
+ @include _layout-context(a) {
125
+ @include fixed-breakpoint(ultrawide) {
126
+ margin: 0 auto;
127
+ max-width: 1600px;
128
+ padding: 0 $g-padding-ultrawide;
129
+ }
130
+ }
131
+
132
+ @include _layout-context(b) {
133
+ @include fixed-breakpoint(desktop-large-v2) {
134
+ padding: 0 72px;
135
+ }
136
+
137
+ @include fixed-breakpoint(ultrawide-v2) {
138
+ margin: 0 auto;
139
+ max-width: 1584px;
140
+ padding: 0 72px;
141
+ }
142
+ }
143
+ }
144
+
145
+ // The condition is checked on the selected element itself, so other conditions such as `.dark` or `[dir='rtl']`
146
+ // keep working when they live on body or html. It is inserted at the start of the last compound (after a type
147
+ // selector), so `&--modifier`, `&__element` and pseudo-elements can still be appended by the content.
148
+ @function _contextualize($selector, $condition) {
149
+ $result: ();
150
+
151
+ @each $complex in selector.parse($selector) {
152
+ $subject: list.nth($complex, -1);
153
+ $check: ':where(body#{$condition}, body#{$condition} *)';
154
+
155
+ @if _starts-with-type($subject, 'html') or _starts-with-type($subject, ':root') {
156
+ // html and :root are never inside body: they check their child body, which requires :has().
157
+ $check: ':where(:has(> body#{$condition}))';
158
+ }
159
+
160
+ $result: list.append($result, list.set-nth($complex, -1, _insert-after-type($subject, $check)), $separator: comma);
161
+ }
162
+
163
+ @return $result;
164
+ }
165
+
166
+ // A type or universal selector must stay first in a compound selector.
167
+ @function _insert-after-type($compound, $check) {
168
+ $compound: '#{$compound}';
169
+ $position: 1;
170
+
171
+ @if not string.index('.#[:', string.slice($compound, 1, 1)) {
172
+ @while $position <= string.length($compound) and not string.index('.#[:', string.slice($compound, $position, $position)) {
173
+ $position: $position + 1;
174
+ }
175
+ }
176
+
177
+ @return string.unquote(string.insert($compound, $check, $position));
178
+ }
179
+
180
+ @function _starts-with-type($compound, $type) {
181
+ $compound: string.to-lower-case('#{$compound}');
182
+
183
+ @if string.index($compound, $type) != 1 {
184
+ @return false;
185
+ }
186
+
187
+ @if string.length($compound) == string.length($type) {
188
+ @return true;
189
+ }
190
+
191
+ $next: string.slice($compound, string.length($type) + 1, string.length($type) + 1);
192
+
193
+ @return not string.index('abcdefghijklmnopqrstuvwxyz0123456789-_', $next);
31
194
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  @use '../variables/typography' as *;
5
5
  @use '../mixins/utils' as *;
6
- @use '../mixins/layout' as *;
6
+ @use '../mixins/breakpoint-fixed' as *;
7
7
 
8
8
  @mixin numeric-typography($name) {
9
9
  @if string.index($name, 'numbers') {
@@ -34,7 +34,7 @@
34
34
  }
35
35
  }
36
36
 
37
- // Include font styles. Three versions: ld, sd or fluid
37
+ // Include font styles. Mobile, Desktop or responsive.
38
38
  // use:
39
39
  // .element {
40
40
  // @include rds-font-style(rds-typography-headline-1);
@@ -70,22 +70,37 @@
70
70
 
71
71
  @mixin rds-font-style($name) {
72
72
  @if map.has-key($rds-types-fluid, $name) {
73
-
74
73
  @include rds-font-style-sd($name);
75
74
 
76
-
77
- @include breakpoint(tablet) {
75
+ @include fixed-breakpoint(tablet) {
78
76
  @include rds-font-style-md($name);
79
77
  }
80
78
 
81
- @include breakpoint(desktop) {
79
+ @include fixed-breakpoint(desktop) {
82
80
  @include rds-font-style-ld($name);
83
81
  }
84
82
 
85
- @include breakpoint(ultrawide) {
83
+ @include fixed-breakpoint(ultrawide) {
86
84
  @include rds-font-style-xd($name);
87
85
  }
88
-
86
+
87
+ :where(body[data-rds-layout='b']) & {
88
+ @include fixed-breakpoint(tablet) {
89
+ @include rds-font-style-sd($name);
90
+ }
91
+
92
+ @include fixed-breakpoint(tablet-v2) {
93
+ @include rds-font-style-md($name);
94
+ }
95
+
96
+ @include fixed-breakpoint(desktop-v2) {
97
+ @include rds-font-style-ld($name);
98
+ }
99
+
100
+ @include fixed-breakpoint(ultrawide-v2) {
101
+ @include rds-font-style-xd($name);
102
+ }
103
+ }
89
104
  } @else {
90
105
  @include rds-font-style-sd($name);
91
106
  }