@justeattakeaway/pie-css 0.29.0 → 0.31.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/README.md CHANGED
@@ -207,7 +207,9 @@ The starting position of the slide animation can be customised by overriding the
207
207
 
208
208
  ## Typography Utility Classes
209
209
 
210
- `pie-css` includes a comprehensive set of typography utility classes that provide consistent typography styles across your application. These utility classes are built on top of PIE design tokens and automatically apply the correct font family, weight, size, line height, and spacing.
210
+ `pie-css` includes a comprehensive set of typography utility classes that provide consistent typography styles across your application. These utility classes are built on top of PIE design tokens and automatically apply the correct font family, weight, size, and line height.
211
+
212
+ Paragraph spacing is now opt-in via the `.u-typographySpacing` utility class, used alongside a typography class on the same element (for example, `<p class="u-font-body-l u-typographySpacing">...</p>`).
211
213
 
212
214
  The utility classes follow a simple naming convention: `u-font-{token-name}`, where the token name matches the design token used in Figma. For example, the `body-l-link` token becomes the `.u-font-body-l-link` utility class.
213
215
 
@@ -10,7 +10,6 @@
10
10
  line-height: calc(var(--dt-font-heading-xs-line-height--wide) * 1px);
11
11
  }
12
12
  }
13
-
14
13
  .u-font-heading-s {
15
14
  font-family: var(--dt-font-heading-s-family);
16
15
  font-weight: var(--dt-font-heading-s-weight);
@@ -23,7 +22,6 @@
23
22
  line-height: calc(var(--dt-font-heading-s-line-height--wide) * 1px);
24
23
  }
25
24
  }
26
-
27
25
  .u-font-heading-m {
28
26
  font-family: var(--dt-font-heading-m-family);
29
27
  font-weight: var(--dt-font-heading-m-weight);
@@ -36,7 +34,6 @@
36
34
  line-height: calc(var(--dt-font-heading-m-line-height--wide) * 1px);
37
35
  }
38
36
  }
39
-
40
37
  .u-font-heading-l {
41
38
  font-family: var(--dt-font-heading-l-family);
42
39
  font-weight: var(--dt-font-heading-l-weight);
@@ -49,7 +46,6 @@
49
46
  line-height: calc(var(--dt-font-heading-l-line-height--wide) * 1px);
50
47
  }
51
48
  }
52
-
53
49
  .u-font-heading-xl {
54
50
  font-family: var(--dt-font-heading-xl-family);
55
51
  font-weight: var(--dt-font-heading-xl-weight);
@@ -62,7 +58,6 @@
62
58
  line-height: calc(var(--dt-font-heading-xl-line-height--wide) * 1px);
63
59
  }
64
60
  }
65
-
66
61
  .u-font-heading-xxl {
67
62
  font-family: var(--dt-font-heading-xxl-family);
68
63
  font-weight: var(--dt-font-heading-xxl-weight);
@@ -75,7 +70,6 @@
75
70
  line-height: calc(var(--dt-font-heading-xxl-line-height--wide) * 1px);
76
71
  }
77
72
  }
78
-
79
73
  .u-font-heading-xs-italic {
80
74
  font-family: var(--dt-font-heading-xs-italic-family);
81
75
  font-weight: var(--dt-font-heading-xs-italic-weight);
@@ -90,7 +84,6 @@
90
84
  line-height: calc(var(--dt-font-heading-xs-italic-line-height--wide) * 1px);
91
85
  }
92
86
  }
93
-
94
87
  .u-font-heading-s-italic {
95
88
  font-family: var(--dt-font-heading-s-italic-family);
96
89
  font-weight: var(--dt-font-heading-s-italic-weight);
@@ -105,7 +98,6 @@
105
98
  line-height: calc(var(--dt-font-heading-s-italic-line-height--wide) * 1px);
106
99
  }
107
100
  }
108
-
109
101
  .u-font-heading-m-italic {
110
102
  font-family: var(--dt-font-heading-m-italic-family);
111
103
  font-weight: var(--dt-font-heading-m-italic-weight);
@@ -120,7 +112,6 @@
120
112
  line-height: calc(var(--dt-font-heading-m-italic-line-height--wide) * 1px);
121
113
  }
122
114
  }
123
-
124
115
  .u-font-heading-l-italic {
125
116
  font-family: var(--dt-font-heading-l-italic-family);
126
117
  font-weight: var(--dt-font-heading-l-italic-weight);
@@ -135,7 +126,6 @@
135
126
  line-height: calc(var(--dt-font-heading-l-italic-line-height--wide) * 1px);
136
127
  }
137
128
  }
138
-
139
129
  .u-font-heading-xl-italic {
140
130
  font-family: var(--dt-font-heading-xl-italic-family);
141
131
  font-weight: var(--dt-font-heading-xl-italic-weight);
@@ -150,7 +140,6 @@
150
140
  line-height: calc(var(--dt-font-heading-xl-italic-line-height--wide) * 1px);
151
141
  }
152
142
  }
153
-
154
143
  .u-font-heading-xxl-italic {
155
144
  font-family: var(--dt-font-heading-xxl-italic-family);
156
145
  font-weight: var(--dt-font-heading-xxl-italic-weight);
@@ -165,7 +154,6 @@
165
154
  line-height: calc(var(--dt-font-heading-xxl-italic-line-height--wide) * 1px);
166
155
  }
167
156
  }
168
-
169
157
  .u-font-subheading-s {
170
158
  font-family: var(--dt-font-subheading-s-family);
171
159
  font-weight: var(--dt-font-subheading-s-weight);
@@ -178,7 +166,6 @@
178
166
  line-height: calc(var(--dt-font-subheading-s-line-height--wide) * 1px);
179
167
  }
180
168
  }
181
-
182
169
  .u-font-subheading-l {
183
170
  font-family: var(--dt-font-subheading-l-family);
184
171
  font-weight: var(--dt-font-subheading-l-weight);
@@ -191,136 +178,158 @@
191
178
  line-height: calc(var(--dt-font-subheading-l-line-height--wide) * 1px);
192
179
  }
193
180
  }
194
-
195
181
  .u-font-interactive-xs {
196
182
  font-family: var(--dt-font-interactive-xs-family);
197
183
  font-weight: var(--dt-font-interactive-xs-weight);
198
184
  font-size: calc(var(--dt-font-interactive-xs-size) * 1px);
199
185
  line-height: calc(var(--dt-font-interactive-xs-line-height) * 1px);
200
186
  }
201
-
202
187
  .u-font-interactive-s {
203
188
  font-family: var(--dt-font-interactive-s-family);
204
189
  font-weight: var(--dt-font-interactive-s-weight);
205
190
  font-size: calc(var(--dt-font-interactive-s-size) * 1px);
206
191
  line-height: calc(var(--dt-font-interactive-s-line-height) * 1px);
207
192
  }
208
-
209
193
  .u-font-interactive-l {
210
194
  font-family: var(--dt-font-interactive-l-family);
211
195
  font-weight: var(--dt-font-interactive-l-weight);
212
196
  font-size: calc(var(--dt-font-interactive-l-size) * 1px);
213
197
  line-height: calc(var(--dt-font-interactive-l-line-height) * 1px);
214
198
  }
215
-
216
199
  .u-font-body-s {
217
200
  font-family: var(--dt-font-body-s-family);
218
201
  font-weight: var(--dt-font-body-s-weight);
219
- margin-block-end: calc(var(--dt-font-body-s-paragraph) * 1px);
220
202
  font-size: calc(var(--dt-font-body-s-size) * 1px);
221
203
  line-height: calc(var(--dt-font-body-s-line-height) * 1px);
222
204
  }
205
+ .u-font-body-s.u-typographySpacing {
206
+ margin-block-end: calc(var(--dt-font-body-s-paragraph) * 1px);
207
+ }
223
208
 
224
209
  .u-font-body-s-link {
225
210
  font-family: var(--dt-font-body-s-link-family);
226
211
  font-weight: var(--dt-font-body-s-link-weight);
227
212
  text-decoration: var(--dt-font-body-s-link-text-decoration);
228
- margin-block-end: calc(var(--dt-font-body-s-link-paragraph) * 1px);
229
213
  font-size: calc(var(--dt-font-body-s-link-size) * 1px);
230
214
  line-height: calc(var(--dt-font-body-s-link-line-height) * 1px);
231
215
  }
216
+ .u-font-body-s-link.u-typographySpacing {
217
+ margin-block-end: calc(var(--dt-font-body-s-link-paragraph) * 1px);
218
+ }
232
219
 
233
220
  .u-font-body-l {
234
221
  font-family: var(--dt-font-body-l-family);
235
222
  font-weight: var(--dt-font-body-l-weight);
236
- margin-block-end: calc(var(--dt-font-body-l-paragraph) * 1px);
237
223
  font-size: calc(var(--dt-font-body-l-size) * 1px);
238
224
  line-height: calc(var(--dt-font-body-l-line-height) * 1px);
239
225
  }
226
+ .u-font-body-l.u-typographySpacing {
227
+ margin-block-end: calc(var(--dt-font-body-l-paragraph) * 1px);
228
+ }
240
229
 
241
230
  .u-font-body-l-link {
242
231
  font-family: var(--dt-font-body-l-link-family);
243
232
  font-weight: var(--dt-font-body-l-link-weight);
244
233
  text-decoration: var(--dt-font-body-l-link-text-decoration);
245
- margin-block-end: calc(var(--dt-font-body-l-link-paragraph) * 1px);
246
234
  font-size: calc(var(--dt-font-body-l-link-size) * 1px);
247
235
  line-height: calc(var(--dt-font-body-l-link-line-height) * 1px);
248
236
  }
237
+ .u-font-body-l-link.u-typographySpacing {
238
+ margin-block-end: calc(var(--dt-font-body-l-link-paragraph) * 1px);
239
+ }
249
240
 
250
241
  .u-font-body-strong-s {
251
242
  font-family: var(--dt-font-body-strong-s-family);
252
243
  font-weight: var(--dt-font-body-strong-s-weight);
253
- margin-block-end: calc(var(--dt-font-body-strong-s-paragraph) * 1px);
254
244
  font-size: calc(var(--dt-font-body-strong-s-size) * 1px);
255
245
  line-height: calc(var(--dt-font-body-strong-s-line-height) * 1px);
256
246
  }
247
+ .u-font-body-strong-s.u-typographySpacing {
248
+ margin-block-end: calc(var(--dt-font-body-strong-s-paragraph) * 1px);
249
+ }
257
250
 
258
251
  .u-font-body-strong-s-link {
259
252
  font-family: var(--dt-font-body-strong-s-link-family);
260
253
  font-weight: var(--dt-font-body-strong-s-link-weight);
261
254
  text-decoration: var(--dt-font-body-strong-s-link-text-decoration);
262
- margin-block-end: calc(var(--dt-font-body-strong-s-link-paragraph) * 1px);
263
255
  font-size: calc(var(--dt-font-body-strong-s-link-size) * 1px);
264
256
  line-height: calc(var(--dt-font-body-strong-s-link-line-height) * 1px);
265
257
  }
258
+ .u-font-body-strong-s-link.u-typographySpacing {
259
+ margin-block-end: calc(var(--dt-font-body-strong-s-link-paragraph) * 1px);
260
+ }
266
261
 
267
262
  .u-font-body-strong-l {
268
263
  font-family: var(--dt-font-body-strong-l-family);
269
264
  font-weight: var(--dt-font-body-strong-l-weight);
270
- margin-block-end: calc(var(--dt-font-body-strong-l-paragraph) * 1px);
271
265
  font-size: calc(var(--dt-font-body-strong-l-size) * 1px);
272
266
  line-height: calc(var(--dt-font-body-strong-l-line-height) * 1px);
273
267
  }
268
+ .u-font-body-strong-l.u-typographySpacing {
269
+ margin-block-end: calc(var(--dt-font-body-strong-l-paragraph) * 1px);
270
+ }
274
271
 
275
272
  .u-font-body-strong-l-link {
276
273
  font-family: var(--dt-font-body-strong-l-link-family);
277
274
  font-weight: var(--dt-font-body-strong-l-link-weight);
278
275
  text-decoration: var(--dt-font-body-strong-l-link-text-decoration);
279
- margin-block-end: calc(var(--dt-font-body-strong-l-link-paragraph) * 1px);
280
276
  font-size: calc(var(--dt-font-body-strong-l-link-size) * 1px);
281
277
  line-height: calc(var(--dt-font-body-strong-l-link-line-height) * 1px);
282
278
  }
279
+ .u-font-body-strong-l-link.u-typographySpacing {
280
+ margin-block-end: calc(var(--dt-font-body-strong-l-link-paragraph) * 1px);
281
+ }
283
282
 
284
283
  .u-font-caption {
285
284
  font-family: var(--dt-font-caption-family);
286
285
  font-weight: var(--dt-font-caption-weight);
287
- margin-block-end: calc(var(--dt-font-caption-paragraph) * 1px);
288
286
  font-size: calc(var(--dt-font-caption-size) * 1px);
289
287
  line-height: calc(var(--dt-font-caption-line-height) * 1px);
290
288
  }
289
+ .u-font-caption.u-typographySpacing {
290
+ margin-block-end: calc(var(--dt-font-caption-paragraph) * 1px);
291
+ }
291
292
 
292
293
  .u-font-caption-link {
293
294
  font-family: var(--dt-font-caption-link-family);
294
295
  font-weight: var(--dt-font-caption-link-weight);
295
296
  text-decoration: var(--dt-font-caption-link-text-decoration);
296
- margin-block-end: calc(var(--dt-font-caption-link-paragraph) * 1px);
297
297
  font-size: calc(var(--dt-font-caption-link-size) * 1px);
298
298
  line-height: calc(var(--dt-font-caption-link-line-height) * 1px);
299
299
  }
300
+ .u-font-caption-link.u-typographySpacing {
301
+ margin-block-end: calc(var(--dt-font-caption-link-paragraph) * 1px);
302
+ }
300
303
 
301
304
  .u-font-caption-strong {
302
305
  font-family: var(--dt-font-caption-strong-family);
303
306
  font-weight: var(--dt-font-caption-strong-weight);
304
- margin-block-end: calc(var(--dt-font-caption-strong-paragraph) * 1px);
305
307
  font-size: calc(var(--dt-font-caption-strong-size) * 1px);
306
308
  line-height: calc(var(--dt-font-caption-strong-line-height) * 1px);
307
309
  }
310
+ .u-font-caption-strong.u-typographySpacing {
311
+ margin-block-end: calc(var(--dt-font-caption-strong-paragraph) * 1px);
312
+ }
308
313
 
309
314
  .u-font-caption-strong-italic {
310
315
  font-family: var(--dt-font-caption-strong-italic-family);
311
316
  font-weight: var(--dt-font-caption-strong-italic-weight);
312
- margin-block-end: calc(var(--dt-font-caption-strong-italic-paragraph) * 1px);
313
317
  font-style: var(--dt-font-caption-strong-italic-font-style);
314
318
  font-variation-settings: "slnt" -20;
315
319
  font-size: calc(var(--dt-font-caption-strong-italic-size) * 1px);
316
320
  line-height: calc(var(--dt-font-caption-strong-italic-line-height) * 1px);
317
321
  }
322
+ .u-font-caption-strong-italic.u-typographySpacing {
323
+ margin-block-end: calc(var(--dt-font-caption-strong-italic-paragraph) * 1px);
324
+ }
318
325
 
319
326
  .u-font-caption-strong-link {
320
327
  font-family: var(--dt-font-caption-strong-link-family);
321
328
  font-weight: var(--dt-font-caption-strong-link-weight);
322
329
  text-decoration: var(--dt-font-caption-strong-link-text-decoration);
323
- margin-block-end: calc(var(--dt-font-caption-strong-link-paragraph) * 1px);
324
330
  font-size: calc(var(--dt-font-caption-strong-link-size) * 1px);
325
331
  line-height: calc(var(--dt-font-caption-strong-link-line-height) * 1px);
326
332
  }
333
+ .u-font-caption-strong-link.u-typographySpacing {
334
+ margin-block-end: calc(var(--dt-font-caption-strong-link-paragraph) * 1px);
335
+ }
@@ -15,6 +15,7 @@ The PIE CSS Typography Utilities provide a comprehensive set of utility classes
15
15
  - [If You Have Designs](#if-you-have-designs)
16
16
  - [If You Don't Have Designs](#if-you-dont-have-designs)
17
17
  - [Available Classes](#available-classes)
18
+ - [Typography Spacing Utility](#typography-spacing-utility)
18
19
  - [the `font-theme` mixin](#the-font-theme-mixin)
19
20
  - [Usage Examples](#usage-examples)
20
21
  - [What Each Utility Class Applies](#what-each-utility-class-applies)
@@ -162,9 +163,17 @@ Interactive text utilities are optimized for buttons, links, and other interacti
162
163
  | `.u-font-interactive-s` | Small interactive text |
163
164
  | `.u-font-interactive-xs` | Extra small interactive text |
164
165
 
166
+ ### Typography Spacing Utility
167
+
168
+ Use `.u-typographySpacing` alongside a typography utility class on the same element to apply paragraph spacing for typography tokens that define a `paragraph` token.
169
+
170
+ | Class | Use Case |
171
+ | --- | --- |
172
+ | `.u-typographySpacing` | Opt-in paragraph spacing for typography classes that support paragraph tokens |
173
+
165
174
  ### Body Text
166
175
 
167
- Body text utilities are for paragraphs and general content. These utilities include automatic paragraph spacing via `margin-block-end`.
176
+ Body text utilities are for paragraphs and general content.
168
177
 
169
178
  | Class | Use Case |
170
179
  | --- | --- |
@@ -240,6 +249,7 @@ Simply add the utility class to your HTML element:
240
249
  ```html
241
250
  <h1 class="u-font-heading-xl">Page Title</h1>
242
251
  <p class="u-font-body-l">This is a paragraph of body text.</p>
252
+ <p class="u-font-body-l u-typographySpacing">This is body text with opt-in paragraph spacing.</p>
243
253
  ```
244
254
 
245
255
  ### React Example
@@ -253,6 +263,9 @@ function MyComponent() {
253
263
  <p className="u-font-body-l">
254
264
  This is a paragraph using the body large utility class.
255
265
  </p>
266
+ <p className="u-font-body-l u-typographySpacing">
267
+ This paragraph uses the same typography class with opt-in spacing.
268
+ </p>
256
269
  <a href="#" className="u-font-body-l-link">Learn more</a>
257
270
  </div>
258
271
  );
@@ -269,6 +282,9 @@ function MyComponent() {
269
282
  <p class="u-font-body-l">
270
283
  This is a paragraph using the body large utility class.
271
284
  </p>
285
+ <p class="u-font-body-l u-typographySpacing">
286
+ This paragraph uses the same typography class with opt-in spacing.
287
+ </p>
272
288
  <a href="#" class="u-font-body-l-link">Learn more</a>
273
289
  </div>
274
290
  </template>
@@ -306,7 +322,8 @@ Each typography utility class applies a complete set of typography properties:
306
322
  - **`line-height`**: Applies the appropriate line height for readability ([MDN reference](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height))
307
323
  - **`font-style`**: Applied for italic variants ([MDN reference](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style))
308
324
  - **`text-decoration`**: Applied for link variants ([MDN reference](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration))
309
- - **`margin-block-end`**: Applied for body and caption variants to provide paragraph spacing ([MDN reference](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block-end))
325
+
326
+ Use `.u-typographySpacing` for opt-in paragraph spacing via `margin-block-end` on supported typography tokens ([MDN reference](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block-end)).
310
327
 
311
328
  ## Troubleshooting
312
329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-css",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "A styling library that provides both a shared collection of ready to use CSS styles to be used across JET web front-ends, and SCSS-based style helpers for our PIE Web Component library.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,5 +12,9 @@ $typography-names: font-heading-xs font-heading-s font-heading-m font-heading-l
12
12
  @each $name in $typography-names {
13
13
  .u-#{$name} {
14
14
  @include font-theme($name);
15
+
16
+ &.u-typographySpacing {
17
+ @include typography-spacing($name);
18
+ }
15
19
  }
16
20
  }
@@ -24,22 +24,19 @@
24
24
  'family': 'font-family',
25
25
  'weight': 'font-weight',
26
26
  'text-decoration': 'text-decoration',
27
- 'paragraph': 'margin-block-end',
28
27
  'font-style': 'font-style',
29
28
  );
30
29
 
31
30
  // --- Mobile-First (Narrow) and Static Properties ---
32
31
 
33
- // Apply Static Properties (font-family, font-weight, text-decoration, paragraph and font-style)
32
+ // Apply Static Properties (font-family, font-weight, text-decoration and font-style)
34
33
  @each $suffix, $css-prop in $static-properties {
35
34
  // Example variable structure (assuming $token-name is 'font-heading-l'): --dt-font-heading-l-family
36
35
  $scss-name: '#{$token-name}-#{$suffix}';
37
36
  $var-name: '--dt-#{$token-name}-#{$suffix}';
38
37
 
39
38
  @if meta.variable-exists($scss-name) {
40
- @if $suffix == 'paragraph' {
41
- #{$css-prop}: calc(var(#{$var-name}) * 1px);
42
- } @else if $suffix == 'font-style' {
39
+ @if $suffix == 'font-style' {
43
40
  // if we're setting font-style: italic, we need to add the font-variation-settings for slant
44
41
  #{$css-prop}: var(#{$var-name});
45
42
  font-variation-settings: 'slnt' -20;
@@ -84,3 +81,12 @@
84
81
  }
85
82
  }
86
83
  }
84
+
85
+ @mixin typography-spacing($token-name) {
86
+ $paragraph-scss-name: '#{$token-name}-paragraph';
87
+ $paragraph-var-name: '--dt-#{$token-name}-paragraph';
88
+
89
+ @if meta.variable-exists($paragraph-scss-name) {
90
+ margin-block-end: calc(var(#{$paragraph-var-name}) * 1px);
91
+ }
92
+ }
@@ -1,7 +1,6 @@
1
1
  //
2
2
  // !IMPORTANT: This file is a copy of the original include-media SCSS library
3
3
  // !DO NOT directly edit this file/
4
- //
5
4
  // _ _ _ _ _
6
5
  // (_) | | | | | (_)
7
6
  // _ _ __ ___| |_ _ __| | ___ _ __ ___ ___ __| |_ __ _
@@ -178,50 +177,10 @@ $im-no-media-breakpoint: 'desktop' !default;
178
177
  $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
179
178
 
180
179
  ////
181
- /// Cross-engine logging engine
182
- /// @author Kitty Giraudel
180
+ /// Determines whether a list of conditions is intercepted by the static breakpoint.
183
181
  /// @access private
184
182
  ////
185
183
 
186
- ///
187
- /// Log a message either with `@error` if supported
188
- /// else with `@warn`, using `feature-exists('at-error')`
189
- /// to detect support.
190
- ///
191
- /// @param {String} $message - Message to log
192
- ///
193
- @function im-log($message) {
194
- @if meta.feature-exists('at-error') {
195
- @error $message;
196
- } @else {
197
- @warn $message;
198
-
199
- $_: noop();
200
- }
201
-
202
- @return $message;
203
- }
204
-
205
- ///
206
- /// Wrapper mixin for the log function so it can be used with a more friendly
207
- /// API than `@if im-log('..') {}` or `$_: im-log('..')`. Basically, use the function
208
- /// within functions because it is not possible to include a mixin in a function
209
- /// and use the mixin everywhere else because it's much more elegant.
210
- ///
211
- /// @param {String} $message - Message to log
212
- ///
213
- @mixin log($message) {
214
- @if im-log($message) {
215
- }
216
- }
217
-
218
- ///
219
- /// Function with no `@return` called next to `@warn` in Sass 3.3
220
- /// to trigger a compiling error and stop the process.
221
- ///
222
- @function noop() {
223
- }
224
-
225
184
  ///
226
185
  /// Determines whether a list of conditions is intercepted by the static breakpoint.
227
186
  ///
@@ -233,8 +192,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
233
192
  $no-media-breakpoint-value: map.get($breakpoints, $im-no-media-breakpoint);
234
193
 
235
194
  @if not $no-media-breakpoint-value {
236
- @if im-log('`#{$im-no-media-breakpoint}` is not a valid breakpoint.') {
237
- }
195
+ @error '#{$im-no-media-breakpoint}` is not a valid breakpoint.';
238
196
  }
239
197
 
240
198
  @each $condition in $conditions {
@@ -276,12 +234,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
276
234
  }
277
235
  }
278
236
 
279
- // It is not possible to include a mixin inside a function, so we have to
280
- // rely on the `im-log(..)` function rather than the `log(..)` mixin. Because
281
- // functions cannot be called anywhere in Sass, we need to hack the call in
282
- // a dummy variable, such as `$_`. If anybody ever raise a scoping issue with
283
- // Sass 3.3, change this line in `@if im-log(..) {}` instead.
284
- $_: im-log('No operator found in `#{$expression}`.');
237
+ @error 'No operator found in `#{$expression}`.';
285
238
  }
286
239
 
287
240
  ///
@@ -295,6 +248,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
295
248
  @function get-expression-dimension($expression, $operator) {
296
249
  $operator-index: string.index($expression, $operator);
297
250
  $parsed-dimension: string.slice($expression, 0, $operator-index - 1);
251
+ $parsed-dimension: str-trim($parsed-dimension);
298
252
  $dimension: 'width';
299
253
 
300
254
  @if string.length($parsed-dimension) > 0 {
@@ -312,7 +266,11 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
312
266
  /// @return {String} - `min` or `max`
313
267
  ///
314
268
  @function get-expression-prefix($operator) {
315
- @return if(list.index(('<', '<=', '≤'), $operator), 'max', 'min');
269
+ @if list.index(('<', '<=', '≤'), $operator) {
270
+ @return 'max';
271
+ } @else {
272
+ @return 'min';
273
+ }
316
274
  }
317
275
 
318
276
  ///
@@ -326,22 +284,18 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
326
284
  @function get-expression-value($expression, $operator) {
327
285
  $operator-index: string.index($expression, $operator);
328
286
  $value: string.slice($expression, $operator-index + string.length($operator));
287
+ $trimmedValue: str-trim($value);
329
288
 
330
- @if map.has-key($breakpoints, $value) {
331
- $value: map.get($breakpoints, $value);
289
+ @if map.has-key($breakpoints, $trimmedValue) {
290
+ $value: map.get($breakpoints, $trimmedValue);
332
291
  } @else {
333
- $value: to-number($value);
292
+ $value: to-number($trimmedValue);
334
293
  }
335
294
 
336
295
  $interval: map.get($unit-intervals, math.unit($value));
337
296
 
338
297
  @if not $interval {
339
- // It is not possible to include a mixin inside a function, so we have to
340
- // rely on the `im-log(..)` function rather than the `log(..)` mixin. Because
341
- // functions cannot be called anywhere in Sass, we need to hack the call in
342
- // a dummy variable, such as `$_`. If anybody ever raise a scoping issue with
343
- // Sass 3.3, change this line in `@if im-log(..) {}` instead.
344
- $_: im-log('Unknown unit `#{math.unit($value)}`.');
298
+ @error 'Unknown unit `#{math.unit($value)}`.';
345
299
  }
346
300
 
347
301
  @if $operator == '>' {
@@ -418,7 +372,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
418
372
  @if meta.type-of($value) == 'number' {
419
373
  @return $value;
420
374
  } @else if meta.type-of($value) != 'string' {
421
- $_: im-log('Value for `to-number` should be a number or a string.');
375
+ @error 'Value for `to-number` should be a number or a string.';
422
376
  }
423
377
 
424
378
  $first-character: string.slice($value, 1, 1);
@@ -439,15 +393,20 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
439
393
  );
440
394
 
441
395
  // Remove +/- sign if present at first character
442
- @if $first-character == '+' or $first-character == '-' {
396
+ @if ($first-character == '+' or $first-character == '-') {
443
397
  $value: string.slice($value, 2);
444
398
  }
445
399
 
400
+ $sign: 1;
401
+ @if $minus {
402
+ $sign: -1;
403
+ }
404
+
446
405
  @for $i from 1 through string.length($value) {
447
406
  $character: string.slice($value, $i, $i);
448
407
 
449
408
  @if not(list.index(map.keys($numbers), $character) or $character == '.') {
450
- @return to-length(if($minus, -$result, $result), string.slice($value, $i));
409
+ @return to-length($sign * $result, string.slice($value, $i));
451
410
  }
452
411
 
453
412
  @if $character == '.' {
@@ -460,7 +419,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
460
419
  }
461
420
  }
462
421
 
463
- @return if($minus, -$result, $result);
422
+ @return $sign * $result;
464
423
  }
465
424
 
466
425
  ///
@@ -491,12 +450,36 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
491
450
  );
492
451
 
493
452
  @if not list.index(map.keys($units), $unit) {
494
- $_: im-log('Invalid unit `#{$unit}`.');
453
+ @error 'Invalid unit `#{$unit}`.';
495
454
  }
496
455
 
497
456
  @return $value * map.get($units, $unit);
498
457
  }
499
458
 
459
+ ////
460
+ /// String trim
461
+ /// @author Jack McNicol
462
+ /// @access private
463
+ ////
464
+
465
+ ///
466
+ /// Trims a string of leading and trailing spaces
467
+ ///
468
+ /// @param {String} $string - Value to be trimmed
469
+ ///
470
+ /// @return {String}
471
+ ///
472
+
473
+ @function str-trim($string) {
474
+ @if (string.slice($string, 1, 1) == ' ') {
475
+ @return str-trim(string.slice($string, 2));
476
+ } @else if (string.slice($string, string.length($string), -1) == ' ') {
477
+ @return str-trim(string.slice($string, 1, -2));
478
+ } @else {
479
+ @return $string;
480
+ }
481
+ }
482
+
500
483
  ///
501
484
  /// This mixin aims at redefining the configuration just for the scope of
502
485
  /// the call. It is helpful when having a component needing an extended
@@ -585,10 +568,11 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
585
568
  (not $im-media-support and im-intercepts-static-breakpoint($conditions...))
586
569
  {
587
570
  @content;
588
- } @else if $im-media-support and list.length($conditions) > 0 {
571
+ } @else if ($im-media-support and list.length($conditions) > 0) {
589
572
  @media #{string.unquote(parse-expression(list.nth($conditions, 1)))} {
590
573
  // Recursive call
591
- @include media(slice($conditions, 2)...) {
574
+ $sliced-conditions: slice($conditions, 2);
575
+ @include media($sliced-conditions...) {
592
576
  @content;
593
577
  }
594
578
  }