forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_aspect-ratio.scss
72 lines (65 loc) · 1.78 KB
/
_aspect-ratio.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Copyright IBM Corp. 2018, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
@use 'sass:list';
@use 'sass:math';
@use 'sass:meta';
@use '../../config' as *;
/// The aspect ratios that are used to generate corresponding aspect ratio
/// classes in code
/// @type List
/// @access public
/// @group @carbon/grid
$aspect-ratios: (
(16, 9),
(9, 16),
(2, 1),
(1, 2),
(4, 3),
(3, 4),
(3, 2),
(2, 3),
(1, 1)
);
/// Generates the CSS classname utilities for the aspect ratios
///
/// CSS Tricks article on aspect ratios and all the different ways it can be done.
/// https://css-tricks.com/aspect-ratio-boxes/#article-header-id-6
///
/// That article references an earlier article on the topic.
/// https://keithjgrant.com/posts/2017/03/aspect-ratios/
///
/// @param {Number} $width width from an aspect ratio
/// @param {Number} $height height from an aspect ratio
/// @access private
/// @group @carbon/grid
@mixin aspect-ratio($aspect-ratios: $aspect-ratios) {
.#{$prefix}--aspect-ratio {
position: relative;
}
.#{$prefix}--aspect-ratio::before {
block-size: 0;
content: '';
// float: inline-start is not supported yet
// https://caniuse.com/mdn-css_properties_float_flow_relative_values
// stylelint-disable-next-line csstools/use-logical
float: left;
inline-size: 1px;
margin-inline-start: -1px;
}
.#{$prefix}--aspect-ratio::after {
display: table;
clear: both;
content: '';
}
@each $aspect-ratio in $aspect-ratios {
$width: list.nth($aspect-ratio, 1);
$height: list.nth($aspect-ratio, 2);
.#{$prefix}--aspect-ratio--#{$width}x#{$height}::before {
padding-block-start: math.percentage(math.div($height, $width));
}
}
}