@carbon/grid 10.34.0 → 10.37.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/grid",
3
3
  "description": "Grid for digital and software products using the Carbon Design System",
4
- "version": "10.34.0",
4
+ "version": "10.37.0",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -33,10 +33,10 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@carbon/import-once": "^10.6.0",
36
- "@carbon/layout": "^10.30.0"
36
+ "@carbon/layout": "^10.33.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@carbon/cli": "^10.28.0",
39
+ "@carbon/cli": "^10.30.0",
40
40
  "rimraf": "^3.0.0"
41
41
  },
42
42
  "eyeglass": {
@@ -45,5 +45,5 @@
45
45
  "sassDir": "scss",
46
46
  "needs": "^1.3.0"
47
47
  },
48
- "gitHead": "1b4811e1ef0be1d058e63a90242d9d48f0bff445"
48
+ "gitHead": "90b2b8c089af8fc2f9db25255d4b27d5b16ca5fe"
49
49
  }
@@ -0,0 +1,416 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+ //-------------------------------------------
8
+ // Compatibility notes (*.import.scss)
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with dart-sass.
12
+ // It is incompatible with node-sass/libsass as it contains sass language features
13
+ // or functions that are unavailable in node-sass/libsass, such as `math.div`.
14
+ //
15
+ // The non-`.import` suffixed version of this file eg. `_filename.scss`
16
+ // is intended to be compatible with node-sass/libsass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
21
+
22
+ // Helpers for defining columns, rows, and containers are heavily inspired by,
23
+ // and often derived from, bootstrap:
24
+ // https://github.com/twbs/bootstrap/blob/v4-dev/scss/mixins/_grid.scss
25
+
26
+ @use 'sass:math';
27
+ @import '../vendor/@carbon/layout/breakpoint'; /* stylelint-disable-line no-invalid-position-at-import-rule */
28
+ @import 'prefix'; /* stylelint-disable-line no-invalid-position-at-import-rule */
29
+
30
+ // -----------------------------------------------------------------------------
31
+ // Columns
32
+ // -----------------------------------------------------------------------------
33
+
34
+ /// Used to initialize the default properties for a column class, most notably
35
+ /// for setting width and default gutters when a column's breakpoint has not been
36
+ /// hit yet.
37
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter for the grid system
38
+ /// @param {Number} $collapsed-gutter [$carbon--grid-gutter--condensed] - The condensed mode gutter
39
+ /// @access private
40
+ /// @group @carbon/grid
41
+ @mixin carbon--make-col-ready(
42
+ $gutter: $carbon--grid-gutter,
43
+ $condensed-gutter: $carbon--grid-gutter--condensed
44
+ ) {
45
+ // Prevent columns from becoming too narrow when at smaller grid tiers by
46
+ // always setting `width: 100%;`. This works because we use `flex` values
47
+ // later on to override this initial width.
48
+ width: 100%;
49
+ padding-right: math.div($gutter, 2);
50
+ padding-left: math.div($gutter, 2);
51
+
52
+ // For our condensed use-case, our gutters collapse to 2px solid, 1px on each
53
+ // side.
54
+ .#{$prefix}--row--condensed &,
55
+ .#{$prefix}--grid--condensed & {
56
+ padding-right: math.div($condensed-gutter, 2);
57
+ padding-left: math.div($condensed-gutter, 2);
58
+ }
59
+
60
+ // For our narrow use-case, our container hangs 16px into the gutter
61
+ .#{$prefix}--row--narrow &,
62
+ .#{$prefix}--grid--narrow & {
63
+ padding-right: math.div($gutter, 2);
64
+ padding-left: 0;
65
+ }
66
+ }
67
+
68
+ /// Define the width of the column for a given span and column count.
69
+ /// A width of 0 will hide the column entirely.
70
+ /// @param {Number} $span - The number of columns covered
71
+ /// @param {Number} $columns - The total number of columns available
72
+ /// @access private
73
+ /// @group @carbon/grid
74
+ @mixin carbon--make-col($span, $columns) {
75
+ @if $span == 0 {
76
+ display: none;
77
+ } @else {
78
+ // Explicitly include `display: block` to override
79
+ display: block;
80
+ // Add a `max-width` to ensure content within each column does not blow out
81
+ // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
82
+ // do not appear to require this.
83
+ max-width: percentage(math.div($span, $columns));
84
+ flex: 0 0 percentage(math.div($span, $columns));
85
+ }
86
+ }
87
+
88
+ /// Create a column offset for a given span and column count.
89
+ /// @param {Number} $span - The number of columns the offset should cover
90
+ /// @param {Number} $columns - The total number of columns available
91
+ /// @access private
92
+ /// @group @carbon/grid
93
+ @mixin carbon--make-col-offset($span, $columns) {
94
+ $offset: math.div($span, $columns);
95
+ @if $offset == 0 {
96
+ margin-left: 0;
97
+ } @else {
98
+ margin-left: percentage($offset);
99
+ }
100
+ }
101
+
102
+ /// Output the CSS required for all the columns in a given grid system.
103
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - The breakpoints in the grid system
104
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter for the grid system
105
+ /// @access private
106
+ /// @group @carbon/grid
107
+ @mixin carbon--make-grid-columns(
108
+ $breakpoints: $carbon--grid-breakpoints,
109
+ $gutter: $carbon--grid-gutter
110
+ ) {
111
+ .#{$prefix}--col {
112
+ @include carbon--make-col-ready($gutter);
113
+ }
114
+
115
+ @each $breakpoint in map-keys($breakpoints) {
116
+ $infix: carbon--breakpoint-infix($breakpoint);
117
+ $columns: map-get(map-get($breakpoints, $breakpoint), columns);
118
+
119
+ // Allow columns to stretch full width below their breakpoints
120
+ @for $i from 0 through $columns {
121
+ .#{$prefix}--col#{$infix}-#{$i} {
122
+ @include carbon--make-col-ready($gutter);
123
+ }
124
+ }
125
+
126
+ .#{$prefix}--col#{$infix},
127
+ .#{$prefix}--col#{$infix}--auto {
128
+ @include carbon--make-col-ready($gutter);
129
+ }
130
+
131
+ @include carbon--breakpoint($breakpoint, $breakpoints) {
132
+ // Provide basic `.col-{bp}` classes for equal-width flexbox columns
133
+ .#{$prefix}--col,
134
+ .#{$prefix}--col#{$infix} {
135
+ max-width: 100%;
136
+ flex-basis: 0;
137
+ flex-grow: 1;
138
+ }
139
+
140
+ .#{$prefix}--col--auto,
141
+ .#{$prefix}--col#{$infix}--auto {
142
+ width: auto;
143
+ // Reset earlier grid tiers
144
+ max-width: 100%;
145
+ flex: 1 0 0%;
146
+ }
147
+
148
+ @for $i from 0 through $columns {
149
+ .#{$prefix}--col#{$infix}-#{$i} {
150
+ @include carbon--make-col($i, $columns);
151
+ }
152
+ }
153
+
154
+ @for $i from 0 through ($columns - 1) {
155
+ @if not($infix == '') {
156
+ .#{$prefix}--offset#{$infix}-#{$i} {
157
+ @include carbon--make-col-offset($i, $columns);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ // -----------------------------------------------------------------------------
166
+ // Rows
167
+ // -----------------------------------------------------------------------------
168
+
169
+ /// Define the properties for a selector assigned to a row in the grid system.
170
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter in the grid system
171
+ /// @access private
172
+ /// @group @carbon/grid
173
+ @mixin carbon--make-row($gutter: $carbon--grid-gutter) {
174
+ display: flex;
175
+ flex-wrap: wrap;
176
+ margin-right: -1 * math.div($gutter, 2);
177
+ margin-left: -1 * math.div($gutter, 2);
178
+ }
179
+
180
+ // -----------------------------------------------------------------------------
181
+ // No gutter
182
+ // -----------------------------------------------------------------------------
183
+
184
+ /// Add `no-gutter` and `no-gutter--{start,end}` classes to the output CSS. These
185
+ /// classes are useful for dropping the gutter in fluid situations.
186
+ /// @access private
187
+ /// @group @carbon/grid
188
+ @mixin carbon--no-gutter {
189
+ .#{$prefix}--no-gutter,
190
+ .#{$prefix}--row.#{$prefix}--no-gutter [class*='#{$prefix}--col'] {
191
+ padding-right: 0;
192
+ padding-left: 0;
193
+ }
194
+
195
+ .#{$prefix}--no-gutter--start,
196
+ .#{$prefix}--row.#{$prefix}--no-gutter--start [class*='#{$prefix}--col'] {
197
+ padding-left: 0;
198
+ }
199
+
200
+ .#{$prefix}--no-gutter--end,
201
+ .#{$prefix}--row.#{$prefix}--no-gutter--end [class*='#{$prefix}--col'] {
202
+ padding-right: 0;
203
+ }
204
+
205
+ // Deprecated ☠️
206
+ .#{$prefix}--no-gutter--left,
207
+ .#{$prefix}--row.#{$prefix}--no-gutter--left [class*='#{$prefix}--col'] {
208
+ padding-left: 0;
209
+ }
210
+
211
+ .#{$prefix}--no-gutter--right,
212
+ .#{$prefix}--row.#{$prefix}--no-gutter--right [class*='#{$prefix}--col'] {
213
+ padding-right: 0;
214
+ }
215
+ }
216
+
217
+ // -----------------------------------------------------------------------------
218
+ // Hang
219
+ // -----------------------------------------------------------------------------
220
+
221
+ /// Add `hang--start` and `hang--end` classes for a given gutter. These classes are
222
+ /// used alongside `no-gutter--start` and `no-gutter--end` to "hang" type.
223
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter in the grid system
224
+ /// @access private
225
+ /// @group @carbon/grid
226
+ @mixin carbon--hang($gutter: $carbon--grid-gutter) {
227
+ .#{$prefix}--hang--start {
228
+ padding-left: math.div($gutter, 2);
229
+ }
230
+
231
+ .#{$prefix}--hang--end {
232
+ padding-right: math.div($gutter, 2);
233
+ }
234
+
235
+ // Deprecated ☠️
236
+ .#{$prefix}--hang--left {
237
+ padding-left: math.div($gutter, 2);
238
+ }
239
+
240
+ .#{$prefix}--hang--right {
241
+ padding-right: math.div($gutter, 2);
242
+ }
243
+ }
244
+
245
+ // -----------------------------------------------------------------------------
246
+ // Aspect ratio
247
+ // -----------------------------------------------------------------------------
248
+
249
+ /// The aspect ratios that are used to generate corresponding aspect ratio
250
+ /// classes in code
251
+ /// @type List
252
+ /// @access public
253
+ /// @group @carbon/grid
254
+ $carbon--aspect-ratios: (
255
+ (16, 9),
256
+ (9, 16),
257
+ (2, 1),
258
+ (1, 2),
259
+ (4, 3),
260
+ (3, 4),
261
+ (3, 2),
262
+ (2, 3),
263
+ (1, 1)
264
+ );
265
+
266
+ /// Generates the CSS classname utilities for the aspect ratios
267
+ ///
268
+ /// CSS Tricks article on aspect ratios and all the different ways it can be done.
269
+ /// https://css-tricks.com/aspect-ratio-boxes/#article-header-id-6
270
+ ///
271
+ /// That article references an earlier article on the topic.
272
+ /// https://keithjgrant.com/posts/2017/03/aspect-ratios/
273
+ ///
274
+ /// @param {Number} $width width from an aspect ratio
275
+ /// @param {Number} $height height from an aspect ratio
276
+ /// @access private
277
+ /// @group @carbon/grid
278
+ @mixin carbon--aspect-ratio($aspect-ratios: $carbon--aspect-ratios) {
279
+ .#{$prefix}--aspect-ratio {
280
+ position: relative;
281
+ }
282
+
283
+ .#{$prefix}--aspect-ratio::before {
284
+ width: 1px;
285
+ height: 0;
286
+ margin-left: -1px;
287
+ content: '';
288
+ float: left;
289
+ }
290
+
291
+ .#{$prefix}--aspect-ratio::after {
292
+ display: table;
293
+ clear: both;
294
+ content: '';
295
+ }
296
+
297
+ @each $aspect-ratio in $aspect-ratios {
298
+ $width: nth($aspect-ratio, 1);
299
+ $height: nth($aspect-ratio, 2);
300
+
301
+ .#{$prefix}--aspect-ratio--#{$width}x#{$height}::before {
302
+ padding-top: percentage(math.div($height, $width));
303
+ }
304
+ }
305
+
306
+ // leaving here for legacy support
307
+ .#{$prefix}--aspect-ratio--object {
308
+ position: absolute;
309
+ top: 0;
310
+ left: 0;
311
+ width: 100%;
312
+ height: 100%;
313
+ }
314
+ }
315
+
316
+ // -----------------------------------------------------------------------------
317
+ // Grid
318
+ // -----------------------------------------------------------------------------
319
+
320
+ /// Create the container for a grid. Will cause full-bleed for the grid unless
321
+ /// max-width properties are added with `make-container-max-widths`
322
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
323
+ /// @access private
324
+ /// @group @carbon/grid
325
+ @mixin carbon--make-container($breakpoints: $carbon--grid-breakpoints) {
326
+ margin-right: auto;
327
+ margin-left: auto;
328
+
329
+ @include carbon--set-largest-breakpoint();
330
+
331
+ @each $name, $value in $breakpoints {
332
+ $prev-breakpoint: map-get($breakpoints, carbon--breakpoint-prev($name));
333
+ $margin: map-get($value, margin);
334
+
335
+ @if $prev-breakpoint {
336
+ $prev-margin: map-get($prev-breakpoint, margin);
337
+ @if $prev-margin != $margin {
338
+ @include carbon--breakpoint($name) {
339
+ padding-right: #{math.div($carbon--grid-gutter, 2) + $margin};
340
+ padding-left: #{math.div($carbon--grid-gutter, 2) + $margin};
341
+ }
342
+ }
343
+ } @else {
344
+ @include carbon--breakpoint($name) {
345
+ padding-right: #{math.div($carbon--grid-gutter, 2) + $margin};
346
+ padding-left: #{math.div($carbon--grid-gutter, 2) + $margin};
347
+ }
348
+ }
349
+ }
350
+ }
351
+
352
+ /// Get the last breakpoint width and set max-width to its value
353
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
354
+ /// @access private
355
+ /// @group @carbon/grid
356
+ @mixin carbon--set-largest-breakpoint($breakpoints: $carbon--grid-breakpoints) {
357
+ $largest-breakpoint: last-map-item($breakpoints);
358
+
359
+ max-width: map-get($largest-breakpoint, 'width');
360
+ }
361
+
362
+ /// Add in the max-widths for each breakpoint to the container
363
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
364
+ /// @access private
365
+ /// @group @carbon/grid
366
+ @mixin carbon--make-container-max-widths(
367
+ $breakpoints: $carbon--grid-breakpoints
368
+ ) {
369
+ @each $name, $value in $breakpoints {
370
+ @include carbon--breakpoint($name) {
371
+ max-width: map-get($value, width);
372
+ }
373
+ }
374
+ }
375
+
376
+ /// Generate the CSS for a grid for the given breakpoints and gutters
377
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - The default breakpoints
378
+ /// @param {Number} $grid-gutter [$carbon--grid-gutter] - The default gutters
379
+ /// @param {Number} $condensed-gutter [$carbon--grid-gutter--condensed] - The condensed mode gutter
380
+ /// @access public
381
+ /// @group @carbon/grid
382
+ @mixin carbon--grid(
383
+ $breakpoints: $carbon--grid-breakpoints,
384
+ $grid-gutter: $carbon--grid-gutter,
385
+ $condensed-gutter: $carbon--grid-gutter--condensed
386
+ ) {
387
+ .#{$prefix}--grid {
388
+ @include carbon--make-container($breakpoints);
389
+ }
390
+
391
+ @include carbon--largest-breakpoint($breakpoints) {
392
+ .#{$prefix}--grid--full-width {
393
+ max-width: 100%;
394
+ }
395
+ }
396
+
397
+ .#{$prefix}--row {
398
+ @include carbon--make-row();
399
+ }
400
+
401
+ .#{$prefix}--row-padding [class*='#{$prefix}--col'],
402
+ .#{$prefix}--col-padding {
403
+ padding-top: math.div($grid-gutter, 2);
404
+ padding-bottom: math.div($grid-gutter, 2);
405
+ }
406
+
407
+ .#{$prefix}--grid--condensed [class*='#{$prefix}--col'] {
408
+ padding-top: math.div($condensed-gutter, 2);
409
+ padding-bottom: math.div($condensed-gutter, 2);
410
+ }
411
+
412
+ @include carbon--make-grid-columns($breakpoints, $grid-gutter);
413
+ @include carbon--no-gutter();
414
+ @include carbon--hang($grid-gutter);
415
+ @include carbon--aspect-ratio();
416
+ }
@@ -4,6 +4,20 @@
4
4
  // This source code is licensed under the Apache-2.0 license found in the
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
+ //-------------------------------------------
8
+ // Compatibility notes
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with node-sass/libsass.
12
+ // Sass language features only available in dart-sass, such as `math.div`,
13
+ // should not be used.
14
+ //
15
+ // The `.import` suffixed version of this file eg. `_filename.import.scss`
16
+ // is intended to be compatible with dart-sass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
7
21
 
8
22
  // Helpers for defining columns, rows, and containers are heavily inspired by,
9
23
  // and often derived from, bootstrap:
@@ -0,0 +1,416 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+ //-------------------------------------------
8
+ // Compatibility notes (*.import.scss)
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with dart-sass.
12
+ // It is incompatible with node-sass/libsass as it contains sass language features
13
+ // or functions that are unavailable in node-sass/libsass, such as `math.div`.
14
+ //
15
+ // The non-`.import` suffixed version of this file eg. `_filename.scss`
16
+ // is intended to be compatible with node-sass/libsass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
21
+
22
+ // Helpers for defining columns, rows, and containers are heavily inspired by,
23
+ // and often derived from, bootstrap:
24
+ // https://github.com/twbs/bootstrap/blob/v4-dev/scss/mixins/_grid.scss
25
+
26
+ @use 'sass:math';
27
+ @import '@carbon/layout/scss/breakpoint'; /* stylelint-disable-line no-invalid-position-at-import-rule */
28
+ @import 'prefix'; /* stylelint-disable-line no-invalid-position-at-import-rule */
29
+
30
+ // -----------------------------------------------------------------------------
31
+ // Columns
32
+ // -----------------------------------------------------------------------------
33
+
34
+ /// Used to initialize the default properties for a column class, most notably
35
+ /// for setting width and default gutters when a column's breakpoint has not been
36
+ /// hit yet.
37
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter for the grid system
38
+ /// @param {Number} $collapsed-gutter [$carbon--grid-gutter--condensed] - The condensed mode gutter
39
+ /// @access private
40
+ /// @group @carbon/grid
41
+ @mixin carbon--make-col-ready(
42
+ $gutter: $carbon--grid-gutter,
43
+ $condensed-gutter: $carbon--grid-gutter--condensed
44
+ ) {
45
+ // Prevent columns from becoming too narrow when at smaller grid tiers by
46
+ // always setting `width: 100%;`. This works because we use `flex` values
47
+ // later on to override this initial width.
48
+ width: 100%;
49
+ padding-right: math.div($gutter, 2);
50
+ padding-left: math.div($gutter, 2);
51
+
52
+ // For our condensed use-case, our gutters collapse to 2px solid, 1px on each
53
+ // side.
54
+ .#{$prefix}--row--condensed &,
55
+ .#{$prefix}--grid--condensed & {
56
+ padding-right: math.div($condensed-gutter, 2);
57
+ padding-left: math.div($condensed-gutter, 2);
58
+ }
59
+
60
+ // For our narrow use-case, our container hangs 16px into the gutter
61
+ .#{$prefix}--row--narrow &,
62
+ .#{$prefix}--grid--narrow & {
63
+ padding-right: math.div($gutter, 2);
64
+ padding-left: 0;
65
+ }
66
+ }
67
+
68
+ /// Define the width of the column for a given span and column count.
69
+ /// A width of 0 will hide the column entirely.
70
+ /// @param {Number} $span - The number of columns covered
71
+ /// @param {Number} $columns - The total number of columns available
72
+ /// @access private
73
+ /// @group @carbon/grid
74
+ @mixin carbon--make-col($span, $columns) {
75
+ @if $span == 0 {
76
+ display: none;
77
+ } @else {
78
+ // Explicitly include `display: block` to override
79
+ display: block;
80
+ // Add a `max-width` to ensure content within each column does not blow out
81
+ // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
82
+ // do not appear to require this.
83
+ max-width: percentage(math.div($span, $columns));
84
+ flex: 0 0 percentage(math.div($span, $columns));
85
+ }
86
+ }
87
+
88
+ /// Create a column offset for a given span and column count.
89
+ /// @param {Number} $span - The number of columns the offset should cover
90
+ /// @param {Number} $columns - The total number of columns available
91
+ /// @access private
92
+ /// @group @carbon/grid
93
+ @mixin carbon--make-col-offset($span, $columns) {
94
+ $offset: math.div($span, $columns);
95
+ @if $offset == 0 {
96
+ margin-left: 0;
97
+ } @else {
98
+ margin-left: percentage($offset);
99
+ }
100
+ }
101
+
102
+ /// Output the CSS required for all the columns in a given grid system.
103
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - The breakpoints in the grid system
104
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter for the grid system
105
+ /// @access private
106
+ /// @group @carbon/grid
107
+ @mixin carbon--make-grid-columns(
108
+ $breakpoints: $carbon--grid-breakpoints,
109
+ $gutter: $carbon--grid-gutter
110
+ ) {
111
+ .#{$prefix}--col {
112
+ @include carbon--make-col-ready($gutter);
113
+ }
114
+
115
+ @each $breakpoint in map-keys($breakpoints) {
116
+ $infix: carbon--breakpoint-infix($breakpoint);
117
+ $columns: map-get(map-get($breakpoints, $breakpoint), columns);
118
+
119
+ // Allow columns to stretch full width below their breakpoints
120
+ @for $i from 0 through $columns {
121
+ .#{$prefix}--col#{$infix}-#{$i} {
122
+ @include carbon--make-col-ready($gutter);
123
+ }
124
+ }
125
+
126
+ .#{$prefix}--col#{$infix},
127
+ .#{$prefix}--col#{$infix}--auto {
128
+ @include carbon--make-col-ready($gutter);
129
+ }
130
+
131
+ @include carbon--breakpoint($breakpoint, $breakpoints) {
132
+ // Provide basic `.col-{bp}` classes for equal-width flexbox columns
133
+ .#{$prefix}--col,
134
+ .#{$prefix}--col#{$infix} {
135
+ max-width: 100%;
136
+ flex-basis: 0;
137
+ flex-grow: 1;
138
+ }
139
+
140
+ .#{$prefix}--col--auto,
141
+ .#{$prefix}--col#{$infix}--auto {
142
+ width: auto;
143
+ // Reset earlier grid tiers
144
+ max-width: 100%;
145
+ flex: 1 0 0%;
146
+ }
147
+
148
+ @for $i from 0 through $columns {
149
+ .#{$prefix}--col#{$infix}-#{$i} {
150
+ @include carbon--make-col($i, $columns);
151
+ }
152
+ }
153
+
154
+ @for $i from 0 through ($columns - 1) {
155
+ @if not($infix == '') {
156
+ .#{$prefix}--offset#{$infix}-#{$i} {
157
+ @include carbon--make-col-offset($i, $columns);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ // -----------------------------------------------------------------------------
166
+ // Rows
167
+ // -----------------------------------------------------------------------------
168
+
169
+ /// Define the properties for a selector assigned to a row in the grid system.
170
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter in the grid system
171
+ /// @access private
172
+ /// @group @carbon/grid
173
+ @mixin carbon--make-row($gutter: $carbon--grid-gutter) {
174
+ display: flex;
175
+ flex-wrap: wrap;
176
+ margin-right: -1 * math.div($gutter, 2);
177
+ margin-left: -1 * math.div($gutter, 2);
178
+ }
179
+
180
+ // -----------------------------------------------------------------------------
181
+ // No gutter
182
+ // -----------------------------------------------------------------------------
183
+
184
+ /// Add `no-gutter` and `no-gutter--{start,end}` classes to the output CSS. These
185
+ /// classes are useful for dropping the gutter in fluid situations.
186
+ /// @access private
187
+ /// @group @carbon/grid
188
+ @mixin carbon--no-gutter {
189
+ .#{$prefix}--no-gutter,
190
+ .#{$prefix}--row.#{$prefix}--no-gutter [class*='#{$prefix}--col'] {
191
+ padding-right: 0;
192
+ padding-left: 0;
193
+ }
194
+
195
+ .#{$prefix}--no-gutter--start,
196
+ .#{$prefix}--row.#{$prefix}--no-gutter--start [class*='#{$prefix}--col'] {
197
+ padding-left: 0;
198
+ }
199
+
200
+ .#{$prefix}--no-gutter--end,
201
+ .#{$prefix}--row.#{$prefix}--no-gutter--end [class*='#{$prefix}--col'] {
202
+ padding-right: 0;
203
+ }
204
+
205
+ // Deprecated ☠️
206
+ .#{$prefix}--no-gutter--left,
207
+ .#{$prefix}--row.#{$prefix}--no-gutter--left [class*='#{$prefix}--col'] {
208
+ padding-left: 0;
209
+ }
210
+
211
+ .#{$prefix}--no-gutter--right,
212
+ .#{$prefix}--row.#{$prefix}--no-gutter--right [class*='#{$prefix}--col'] {
213
+ padding-right: 0;
214
+ }
215
+ }
216
+
217
+ // -----------------------------------------------------------------------------
218
+ // Hang
219
+ // -----------------------------------------------------------------------------
220
+
221
+ /// Add `hang--start` and `hang--end` classes for a given gutter. These classes are
222
+ /// used alongside `no-gutter--start` and `no-gutter--end` to "hang" type.
223
+ /// @param {Number} $gutter [$carbon--grid-gutter] - The gutter in the grid system
224
+ /// @access private
225
+ /// @group @carbon/grid
226
+ @mixin carbon--hang($gutter: $carbon--grid-gutter) {
227
+ .#{$prefix}--hang--start {
228
+ padding-left: math.div($gutter, 2);
229
+ }
230
+
231
+ .#{$prefix}--hang--end {
232
+ padding-right: math.div($gutter, 2);
233
+ }
234
+
235
+ // Deprecated ☠️
236
+ .#{$prefix}--hang--left {
237
+ padding-left: math.div($gutter, 2);
238
+ }
239
+
240
+ .#{$prefix}--hang--right {
241
+ padding-right: math.div($gutter, 2);
242
+ }
243
+ }
244
+
245
+ // -----------------------------------------------------------------------------
246
+ // Aspect ratio
247
+ // -----------------------------------------------------------------------------
248
+
249
+ /// The aspect ratios that are used to generate corresponding aspect ratio
250
+ /// classes in code
251
+ /// @type List
252
+ /// @access public
253
+ /// @group @carbon/grid
254
+ $carbon--aspect-ratios: (
255
+ (16, 9),
256
+ (9, 16),
257
+ (2, 1),
258
+ (1, 2),
259
+ (4, 3),
260
+ (3, 4),
261
+ (3, 2),
262
+ (2, 3),
263
+ (1, 1)
264
+ );
265
+
266
+ /// Generates the CSS classname utilities for the aspect ratios
267
+ ///
268
+ /// CSS Tricks article on aspect ratios and all the different ways it can be done.
269
+ /// https://css-tricks.com/aspect-ratio-boxes/#article-header-id-6
270
+ ///
271
+ /// That article references an earlier article on the topic.
272
+ /// https://keithjgrant.com/posts/2017/03/aspect-ratios/
273
+ ///
274
+ /// @param {Number} $width width from an aspect ratio
275
+ /// @param {Number} $height height from an aspect ratio
276
+ /// @access private
277
+ /// @group @carbon/grid
278
+ @mixin carbon--aspect-ratio($aspect-ratios: $carbon--aspect-ratios) {
279
+ .#{$prefix}--aspect-ratio {
280
+ position: relative;
281
+ }
282
+
283
+ .#{$prefix}--aspect-ratio::before {
284
+ width: 1px;
285
+ height: 0;
286
+ margin-left: -1px;
287
+ content: '';
288
+ float: left;
289
+ }
290
+
291
+ .#{$prefix}--aspect-ratio::after {
292
+ display: table;
293
+ clear: both;
294
+ content: '';
295
+ }
296
+
297
+ @each $aspect-ratio in $aspect-ratios {
298
+ $width: nth($aspect-ratio, 1);
299
+ $height: nth($aspect-ratio, 2);
300
+
301
+ .#{$prefix}--aspect-ratio--#{$width}x#{$height}::before {
302
+ padding-top: percentage(math.div($height, $width));
303
+ }
304
+ }
305
+
306
+ // leaving here for legacy support
307
+ .#{$prefix}--aspect-ratio--object {
308
+ position: absolute;
309
+ top: 0;
310
+ left: 0;
311
+ width: 100%;
312
+ height: 100%;
313
+ }
314
+ }
315
+
316
+ // -----------------------------------------------------------------------------
317
+ // Grid
318
+ // -----------------------------------------------------------------------------
319
+
320
+ /// Create the container for a grid. Will cause full-bleed for the grid unless
321
+ /// max-width properties are added with `make-container-max-widths`
322
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
323
+ /// @access private
324
+ /// @group @carbon/grid
325
+ @mixin carbon--make-container($breakpoints: $carbon--grid-breakpoints) {
326
+ margin-right: auto;
327
+ margin-left: auto;
328
+
329
+ @include carbon--set-largest-breakpoint();
330
+
331
+ @each $name, $value in $breakpoints {
332
+ $prev-breakpoint: map-get($breakpoints, carbon--breakpoint-prev($name));
333
+ $margin: map-get($value, margin);
334
+
335
+ @if $prev-breakpoint {
336
+ $prev-margin: map-get($prev-breakpoint, margin);
337
+ @if $prev-margin != $margin {
338
+ @include carbon--breakpoint($name) {
339
+ padding-right: #{math.div($carbon--grid-gutter, 2) + $margin};
340
+ padding-left: #{math.div($carbon--grid-gutter, 2) + $margin};
341
+ }
342
+ }
343
+ } @else {
344
+ @include carbon--breakpoint($name) {
345
+ padding-right: #{math.div($carbon--grid-gutter, 2) + $margin};
346
+ padding-left: #{math.div($carbon--grid-gutter, 2) + $margin};
347
+ }
348
+ }
349
+ }
350
+ }
351
+
352
+ /// Get the last breakpoint width and set max-width to its value
353
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
354
+ /// @access private
355
+ /// @group @carbon/grid
356
+ @mixin carbon--set-largest-breakpoint($breakpoints: $carbon--grid-breakpoints) {
357
+ $largest-breakpoint: last-map-item($breakpoints);
358
+
359
+ max-width: map-get($largest-breakpoint, 'width');
360
+ }
361
+
362
+ /// Add in the max-widths for each breakpoint to the container
363
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - A map of breakpoints where the key is the name
364
+ /// @access private
365
+ /// @group @carbon/grid
366
+ @mixin carbon--make-container-max-widths(
367
+ $breakpoints: $carbon--grid-breakpoints
368
+ ) {
369
+ @each $name, $value in $breakpoints {
370
+ @include carbon--breakpoint($name) {
371
+ max-width: map-get($value, width);
372
+ }
373
+ }
374
+ }
375
+
376
+ /// Generate the CSS for a grid for the given breakpoints and gutters
377
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - The default breakpoints
378
+ /// @param {Number} $grid-gutter [$carbon--grid-gutter] - The default gutters
379
+ /// @param {Number} $condensed-gutter [$carbon--grid-gutter--condensed] - The condensed mode gutter
380
+ /// @access public
381
+ /// @group @carbon/grid
382
+ @mixin carbon--grid(
383
+ $breakpoints: $carbon--grid-breakpoints,
384
+ $grid-gutter: $carbon--grid-gutter,
385
+ $condensed-gutter: $carbon--grid-gutter--condensed
386
+ ) {
387
+ .#{$prefix}--grid {
388
+ @include carbon--make-container($breakpoints);
389
+ }
390
+
391
+ @include carbon--largest-breakpoint($breakpoints) {
392
+ .#{$prefix}--grid--full-width {
393
+ max-width: 100%;
394
+ }
395
+ }
396
+
397
+ .#{$prefix}--row {
398
+ @include carbon--make-row();
399
+ }
400
+
401
+ .#{$prefix}--row-padding [class*='#{$prefix}--col'],
402
+ .#{$prefix}--col-padding {
403
+ padding-top: math.div($grid-gutter, 2);
404
+ padding-bottom: math.div($grid-gutter, 2);
405
+ }
406
+
407
+ .#{$prefix}--grid--condensed [class*='#{$prefix}--col'] {
408
+ padding-top: math.div($condensed-gutter, 2);
409
+ padding-bottom: math.div($condensed-gutter, 2);
410
+ }
411
+
412
+ @include carbon--make-grid-columns($breakpoints, $grid-gutter);
413
+ @include carbon--no-gutter();
414
+ @include carbon--hang($grid-gutter);
415
+ @include carbon--aspect-ratio();
416
+ }
package/scss/_mixins.scss CHANGED
@@ -4,6 +4,20 @@
4
4
  // This source code is licensed under the Apache-2.0 license found in the
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
+ //-------------------------------------------
8
+ // Compatibility notes
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with node-sass/libsass.
12
+ // Sass language features only available in dart-sass, such as `math.div`,
13
+ // should not be used.
14
+ //
15
+ // The `.import` suffixed version of this file eg. `_filename.import.scss`
16
+ // is intended to be compatible with dart-sass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
7
21
 
8
22
  // Helpers for defining columns, rows, and containers are heavily inspired by,
9
23
  // and often derived from, bootstrap:
@@ -0,0 +1,56 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+ //-------------------------------------------
8
+ // Compatibility notes (*.import.scss)
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with dart-sass.
12
+ // It is incompatible with node-sass/libsass as it contains sass language features
13
+ // or functions that are unavailable in node-sass/libsass, such as `math.div`.
14
+ //
15
+ // The non-`.import` suffixed version of this file eg. `_filename.scss`
16
+ // is intended to be compatible with node-sass/libsass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
21
+
22
+ @use 'sass:math';
23
+
24
+ /// Default font size
25
+ /// @type Number
26
+ /// @access public
27
+ /// @group @carbon/layout
28
+ $carbon--base-font-size: 16px !default;
29
+
30
+ /// Convert a given px unit to a rem unit
31
+ /// @param {Number} $px - Number with px unit
32
+ /// @return {Number} Number with rem unit
33
+ /// @access public
34
+ /// @group @carbon/layout
35
+ @function carbon--rem($px) {
36
+ @if unit($px) != 'px' {
37
+ // TODO: update to @error in v11
38
+ @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
39
+ }
40
+
41
+ @return math.div($px, $carbon--base-font-size) * 1rem;
42
+ }
43
+
44
+ /// Convert a given px unit to a em unit
45
+ /// @param {Number} $px - Number with px unit
46
+ /// @return {Number} Number with em unit
47
+ /// @access public
48
+ /// @group @carbon/layout
49
+ @function carbon--em($px) {
50
+ @if unit($px) != 'px' {
51
+ // TODO: update to @error in v11
52
+ @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
53
+ }
54
+
55
+ @return math.div($px, $carbon--base-font-size) * 1em;
56
+ }
@@ -4,6 +4,20 @@
4
4
  // This source code is licensed under the Apache-2.0 license found in the
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
+ //-------------------------------------------
8
+ // Compatibility notes
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with node-sass/libsass.
12
+ // Sass language features only available in dart-sass, such as `math.div`,
13
+ // should not be used.
14
+ //
15
+ // The `.import` suffixed version of this file eg. `_filename.import.scss`
16
+ // is intended to be compatible with dart-sass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
7
21
 
8
22
  /// Default font size
9
23
  /// @type Number
@@ -0,0 +1,112 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+ //-------------------------------------------
8
+ // Compatibility notes (*.import.scss)
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with dart-sass.
12
+ // It is incompatible with node-sass/libsass as it contains sass language features
13
+ // or functions that are unavailable in node-sass/libsass, such as `math.div`.
14
+ //
15
+ // The non-`.import` suffixed version of this file eg. `_filename.scss`
16
+ // is intended to be compatible with node-sass/libsass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
21
+
22
+ @use "sass:math";
23
+ @import 'breakpoint'; /* stylelint-disable-line no-invalid-position-at-import-rule */
24
+ @import 'utilities'; /* stylelint-disable-line no-invalid-position-at-import-rule */
25
+
26
+ /// Get the column width for a given breakpoint
27
+ /// @param {String} $breakpoint
28
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints]
29
+ /// @return {Number} In rem
30
+ /// @access public
31
+ /// @group @carbon/layout
32
+ @function carbon--get-column-width(
33
+ $breakpoint,
34
+ $breakpoints: $carbon--grid-breakpoints
35
+ ) {
36
+ @if map-has-key($breakpoints, $breakpoint) {
37
+ $values: map-get($breakpoints, $breakpoint);
38
+ $width: map-get($values, width);
39
+ $margin: map-get($values, margin);
40
+ $columns: map-get($values, columns);
41
+
42
+ @return math.div($width - (2 * $margin), $columns);
43
+ } @else {
44
+ @warn 'Breakpoint: `#{$breakpoint}` is not a valid breakpoint.';
45
+ }
46
+ }
47
+
48
+ /// @type Map
49
+ /// @access public
50
+ /// @group @carbon/layout
51
+ $carbon--key-height-scales: (
52
+ sm: (
53
+ carbon--get-column-width(sm),
54
+ carbon--get-column-width(sm) * 2,
55
+ carbon--get-column-width(sm) * 3,
56
+ carbon--get-column-width(sm) * 4,
57
+ carbon--get-column-width(sm) * 5,
58
+ carbon--get-column-width(sm) * 6,
59
+ ),
60
+ md: (
61
+ carbon--get-column-width(md),
62
+ carbon--get-column-width(md) * 2,
63
+ carbon--get-column-width(md) * 3,
64
+ carbon--get-column-width(md) * 4,
65
+ carbon--get-column-width(md) * 5,
66
+ carbon--get-column-width(md) * 6,
67
+ ),
68
+ lg: (
69
+ carbon--get-column-width(lg),
70
+ carbon--get-column-width(lg) * 2,
71
+ carbon--get-column-width(lg) * 3,
72
+ carbon--get-column-width(lg) * 4,
73
+ carbon--get-column-width(lg) * 5,
74
+ carbon--get-column-width(lg) * 6,
75
+ carbon--get-column-width(lg) * 7,
76
+ carbon--get-column-width(lg) * 8,
77
+ ),
78
+ xlg: (
79
+ carbon--get-column-width(xlg),
80
+ carbon--get-column-width(xlg) * 2,
81
+ carbon--get-column-width(xlg) * 3,
82
+ carbon--get-column-width(xlg) * 4,
83
+ carbon--get-column-width(xlg) * 5,
84
+ carbon--get-column-width(xlg) * 6,
85
+ carbon--get-column-width(xlg) * 7,
86
+ carbon--get-column-width(xlg) * 8,
87
+ ),
88
+ max: (
89
+ carbon--get-column-width(max),
90
+ carbon--get-column-width(max) * 2,
91
+ carbon--get-column-width(max) * 3,
92
+ carbon--get-column-width(max) * 4,
93
+ carbon--get-column-width(max) * 5,
94
+ carbon--get-column-width(max) * 6,
95
+ carbon--get-column-width(max) * 7,
96
+ carbon--get-column-width(max) * 8,
97
+ ),
98
+ );
99
+
100
+ /// Get the value of a key height step at a given breakpoint
101
+ /// @param {String} $breakpoint
102
+ /// @param {Number} $step
103
+ /// @return {Number} In rem
104
+ /// @access public
105
+ /// @group @carbon/layout
106
+ @function carbon--key-height($breakpoint, $step) {
107
+ @if map-has-key($carbon--key-height-scales, $breakpoint) {
108
+ @return nth(map-get($carbon--key-height-scales, $breakpoint), $step);
109
+ } @else {
110
+ @warn 'Breakpoint: `#{$breakpoint}` is not a valid breakpoint.';
111
+ }
112
+ }
@@ -4,6 +4,20 @@
4
4
  // This source code is licensed under the Apache-2.0 license found in the
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
+ //-------------------------------------------
8
+ // Compatibility notes
9
+ // ------------------------------------------
10
+ //
11
+ // This file is intended to be consumed and processed with node-sass/libsass.
12
+ // Sass language features only available in dart-sass, such as `math.div`,
13
+ // should not be used.
14
+ //
15
+ // The `.import` suffixed version of this file eg. `_filename.import.scss`
16
+ // is intended to be compatible with dart-sass.
17
+ //
18
+ // Styles authored within this file must be duplicated to the corresponding
19
+ // compatibility file to ensure we continue to support node-sass and dart-sass
20
+ // in v10.
7
21
 
8
22
  @import 'breakpoint';
9
23
  @import 'utilities';
@@ -5,6 +5,8 @@
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  //
7
7
 
8
+ @use 'sass:math';
9
+
8
10
  /// Default font size
9
11
  /// @type Number
10
12
  /// @access public
@@ -22,7 +24,7 @@ $base-font-size: 16px !default;
22
24
  @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
23
25
  }
24
26
 
25
- @return ($px / $base-font-size) * 1rem;
27
+ @return math.div($px, $base-font-size) * 1rem;
26
28
  }
27
29
 
28
30
  /// Convert a given px unit to a em unit
@@ -36,5 +38,5 @@ $base-font-size: 16px !default;
36
38
  @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
37
39
  }
38
40
 
39
- @return ($px / $base-font-size) * 1em;
41
+ @return math.div($px, $base-font-size) * 1em;
40
42
  }