-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy path_patterns_image.scss
128 lines (115 loc) · 3.66 KB
/
_patterns_image.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
@classreference
image-container:
Image container:
.p-image-container:
Main element of the image component.
"&.is-cover":
Cover variant, to be used to set the `.p-image-container__image` within to cover the container.
"&.is-highlighted":
Highlighted variant, to be used to highlight contents.
.p-image-container--16-9:
Wraps contents in a container with an aspect ratio of 16:9.
.p-image-container--3-2:
Wraps contents in a container with an aspect ratio of 3:2.
.p-image-container--2-3:
Wraps contents in a container with an aspect ratio of 2:3.
.p-image-container--cinematic:
Wraps contents in a container with an aspect ratio of 2.4:1.
.p-image-container--square:
Wraps contents in a container with an aspect ratio of 1:1.
.p-image-container--(16-9|3-2|2-3|cinematic|square)-on-(small|medium|large):
Wraps contents in a container with the specified aspect ratio on the specified breakpoint.
Image:
.p-image-container__image:
Image element within an image container.
*/
@use 'sass:color';
@import 'settings';
// Mapping of aspect ratio class names to their `aspect-ratio` values (width / height).
$aspect-ratios: (
'16-9': calc(16 / 9),
'3-2': calc(3 / 2),
'2-3': calc(2 / 3),
'cinematic': 2.4,
'square': 1,
);
@mixin aspect-ratio-classes {
@each $aspect-ratio, $aspect-ratio-value in $aspect-ratios {
.p-image-container--#{$aspect-ratio} {
aspect-ratio: $aspect-ratio-value;
}
}
@each $breakpoint-name, $breakpoint-bounds-pair in $breakpoint-bounds {
$min-width: map-get($breakpoint-bounds-pair, min);
$max-width: map-get($breakpoint-bounds-pair, max);
@if $min-width and $max-width {
@media ($min-width <= width < $max-width) {
@each $aspect-ratio, $aspect-ratio-value in $aspect-ratios {
.p-image-container--#{$aspect-ratio}-on-#{$breakpoint-name} {
aspect-ratio: $aspect-ratio-value;
}
}
}
} @else if $min-width {
@media (width >= $min-width) {
@each $aspect-ratio, $aspect-ratio-value in $aspect-ratios {
.p-image-container--#{$aspect-ratio}-on-#{$breakpoint-name} {
aspect-ratio: $aspect-ratio-value;
}
}
}
} @else if $max-width {
@media (width < $max-width) {
@each $aspect-ratio, $aspect-ratio-value in $aspect-ratios {
.p-image-container--#{$aspect-ratio}-on-#{$breakpoint-name} {
aspect-ratio: $aspect-ratio-value;
}
}
}
}
}
}
@mixin vf-p-image {
.p-image-container,
[class^='p-image-container--'] {
align-items: center;
display: flex;
justify-content: center;
text-align: center;
// If there is a child lazyloaded image, don't let it affect the layout
& > .lazyloaded {
display: contents;
}
&.is-highlighted {
background: $colors--theme--background-alt;
}
.p-image-container__image {
// max height prevents the image from stretching the container
// when the aspect ratio is set, and object-fit ensures the aspect ratio
// of the image content is maintained
max-height: 100%;
object-fit: contain;
}
&.is-cover {
.p-image-container__image {
height: 100%;
object-fit: cover;
width: 100%;
}
}
}
@include aspect-ratio-classes;
// Deprecated; will be removed in v5
.p-image--bordered {
border: {
color: $colors--theme--border-low-contrast;
style: solid;
width: 1px;
}
}
// Deprecated; will be removed in v5
.p-image--shadowed {
box-shadow: $box-shadow;
}
}