|
| 1 | +@use '../../compiled/tokens/scss/breakpoint'; |
| 2 | +@use '../../compiled/tokens/scss/color'; |
| 3 | +@use '../../compiled/tokens/scss/size'; |
| 4 | +@use '../../mixins/spacing'; |
| 5 | +@use '../../mixins/theme'; |
| 6 | +@use 'sass:color' as sasscolor; |
| 7 | + |
| 8 | +/// Vary image outline colors based on theme. This is the only real style that |
| 9 | +/// IMO stretches the definition of "object" a bit, but it's a nice way to |
| 10 | +/// support different sorts of image content. |
| 11 | + |
| 12 | +@include theme.props { |
| 13 | + --theme-color-border-hype-group-object: #{sasscolor.change( |
| 14 | + color.$brand-primary-darker, |
| 15 | + $alpha: 0.1 |
| 16 | + )}; |
| 17 | +} |
| 18 | + |
| 19 | +@include theme.props(dark) { |
| 20 | + --theme-color-border-hype-group-object: #{sasscolor.change( |
| 21 | + color.$text-light-emphasis, |
| 22 | + $alpha: 0.1 |
| 23 | + )}; |
| 24 | +} |
| 25 | + |
| 26 | +/// Hype Group container. This assumes quite a bit of padding: For best results, |
| 27 | +/// include this within a padded Container object! |
| 28 | +/// |
| 29 | +/// 1. Clear any floats without hiding overflowing content (which we need for |
| 30 | +/// the image effect). |
| 31 | + |
| 32 | +.o-hype-group { |
| 33 | + contain: layout; // 1 |
| 34 | + |
| 35 | + /// Above a certain breakpoint, we switch to using Grid for layout. We can't |
| 36 | + /// do this from the beginning since the smallest layouts use floats. |
| 37 | + |
| 38 | + @media (width >= breakpoint.$m) { |
| 39 | + column-gap: spacing.$fluid-gap; |
| 40 | + display: grid; |
| 41 | + grid-template-areas: |
| 42 | + '. object' |
| 43 | + 'intro object' |
| 44 | + 'content object' |
| 45 | + '. object'; |
| 46 | + grid-template-columns: repeat(2, 1fr); |
| 47 | + grid-template-rows: minmax(0, 1fr) repeat(2, minmax(0, auto)) minmax(0, 1fr); |
| 48 | + } |
| 49 | + |
| 50 | + @media (width >= breakpoint.$l) { |
| 51 | + grid-template-areas: |
| 52 | + '. . object' |
| 53 | + 'intro intro object' |
| 54 | + 'content content object' |
| 55 | + '. . object'; |
| 56 | + grid-template-columns: repeat(3, 1fr); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +/// To display the visual object on the opposite side, we re-use the "reverse" |
| 61 | +/// term from the Media Object and derivative patterns. Though this is a bit of |
| 62 | +/// a misnomer since the change only applies to larger breakpoints: Floating |
| 63 | +/// the object left at smaller viewports would greatly disrupt the reading line. |
| 64 | + |
| 65 | +.o-hype-group--reverse { |
| 66 | + @media (width >= breakpoint.$m) { |
| 67 | + grid-template-areas: |
| 68 | + 'object .' |
| 69 | + 'object intro' |
| 70 | + 'object content' |
| 71 | + 'object .'; |
| 72 | + } |
| 73 | + |
| 74 | + @media (width >= breakpoint.$l) { |
| 75 | + grid-template-areas: |
| 76 | + 'object . .' |
| 77 | + 'object intro intro' |
| 78 | + 'object content content' |
| 79 | + 'object . .'; |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +/// Intro container (heading, etc.) |
| 84 | + |
| 85 | +.o-hype-group__intro { |
| 86 | + grid-area: intro; |
| 87 | +} |
| 88 | + |
| 89 | +/// The first of two containers for the visual object. The first reserves the |
| 90 | +/// space for the object within the container, the second allows the object to |
| 91 | +/// break out of that space for a more dynamic layout. |
| 92 | +/// |
| 93 | +/// 1. Where supported, we are going to use container query units for some |
| 94 | +/// sizing, so we need to set that up here. |
| 95 | +/// 2. We will need to use absolute positioning to control exactly how the |
| 96 | +/// inner element is positioned. This style makes sure that will be relative |
| 97 | +/// to this element. |
| 98 | + |
| 99 | +.o-hype-group__object { |
| 100 | + container-type: size; // 1 |
| 101 | + grid-area: object; |
| 102 | + position: relative; // 2 |
| 103 | + |
| 104 | + /// At smaller breakpoints, we float the object, which breaks out of its |
| 105 | + /// container off the right edge. |
| 106 | + /// |
| 107 | + /// 1. The aspect ratio defines how much taller this element is than its |
| 108 | + /// width. The taller the ratio, the more the inner object will break out |
| 109 | + /// of its container. |
| 110 | + /// 2. We subtract a bit of gap space so the visual object does not appear to |
| 111 | + /// be taking up _more_ space than the content (they should appear equal). |
| 112 | + |
| 113 | + @media (width < breakpoint.$m) { |
| 114 | + aspect-ratio: 2/3; // 1 |
| 115 | + float: right; |
| 116 | + inline-size: calc(50% - #{size.$spacing-gap-inline-small}); // 2 |
| 117 | + margin: size.$spacing-gap-inline-small; |
| 118 | + margin-inline-end: 0; |
| 119 | + |
| 120 | + /// Defining a circular shape allows content to flow around the circle |
| 121 | + /// instead of the outer box, which is more visually pleasing. We have to |
| 122 | + /// size and position the circle a little oddly since we're mapping it to |
| 123 | + /// the inner element, _not_ this container (which is narrower). |
| 124 | + |
| 125 | + .o-hype-group--circle-object & { |
| 126 | + shape-outside: circle(58% at 66% 50%); |
| 127 | + } |
| 128 | + |
| 129 | + @media (width >= breakpoint.$s) { |
| 130 | + aspect-ratio: 4/5; |
| 131 | + inline-size: calc(100% / 3 - #{size.$spacing-gap-inline-small}); |
| 132 | + |
| 133 | + .o-hype-group--circle-object & { |
| 134 | + shape-outside: circle(65% at 80% 50%); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + /// At larger breakpoints, we use negative margins to allow the object to |
| 140 | + /// break outside of the outer margins... first just a little bit, but |
| 141 | + /// eventually by quite a lot. |
| 142 | + |
| 143 | + @media (width >= breakpoint.$l) { |
| 144 | + margin-block: spacing.$fluid-spacing-block-negative-overlap-partial; |
| 145 | + } |
| 146 | + |
| 147 | + @media (width >= breakpoint.$xl) { |
| 148 | + margin-block: spacing.$fluid-spacing-block-negative-overlap; |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +/// This inner object defines the visual shape of the object. There's some |
| 153 | +/// overlap with our Embed object, but because there's so much to coordinate |
| 154 | +/// between this and other elements, it seemed cleaner to embrace a bit of |
| 155 | +/// repetition to avoid a lot of complex restrictions on the Embed object in |
| 156 | +/// this particular context. |
| 157 | +/// |
| 158 | +/// 1. Keeps the image a square, regardless of its container size. Really |
| 159 | +/// important for the effect! |
| 160 | +/// 2. By default, we fill the available height, which allows this element to |
| 161 | +/// fill its container and overflow the horizontal axis on small screens or |
| 162 | +/// the negative margin on large screens. |
| 163 | + |
| 164 | +.o-hype-group__object-inner { |
| 165 | + aspect-ratio: 1; // 1 |
| 166 | + block-size: 100%; // 2 |
| 167 | + border-radius: size.$border-radius-large; |
| 168 | + display: flex; |
| 169 | + inline-size: auto; |
| 170 | + overflow: hidden; |
| 171 | + position: relative; |
| 172 | + |
| 173 | + .o-hype-group--circle-object & { |
| 174 | + border-radius: size.$border-radius-full; |
| 175 | + } |
| 176 | + |
| 177 | + /// 1. If the container is very short, `100%` height will be too small. So |
| 178 | + /// where supported, we can use `cqmax` to size based on the largest |
| 179 | + /// container axis instead. |
| 180 | + /// 2. At larger breakpoints, we need to use absolute positioning to make sure |
| 181 | + /// the object is centered on both axes. Without this, it might overflow |
| 182 | + /// over the wrong edges depending on the `--reverse` modifier and the |
| 183 | + /// length of adjacent content. |
| 184 | + |
| 185 | + @media (width >= breakpoint.$m) { |
| 186 | + block-size: 100cqmax; // 1 |
| 187 | + inset-block-start: 50%; // 2 |
| 188 | + position: absolute; // 2 |
| 189 | + transform: translateY(-50%); // 2 |
| 190 | + |
| 191 | + .o-hype-group--reverse & { |
| 192 | + inset-inline-end: 0; |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + /// Here is where the optional object outline is applied, allowing this |
| 197 | + /// element to showcase content like interface screenshots where the |
| 198 | + /// background could unintentionally bleed into the background. (Again, this |
| 199 | + /// is the one touch that really stretches this being an "Object," but the |
| 200 | + /// fact that the pattern is, by default, devoid of any content, pushed me |
| 201 | + /// into categorizing it as such.) |
| 202 | + /// |
| 203 | + /// 1. Just in case the end user wants to copy the image URL or view the |
| 204 | + /// image properties or something, this prevents this overlay from |
| 205 | + /// interrupting that. |
| 206 | + |
| 207 | + .o-hype-group--outline-object &::after { |
| 208 | + border: size.$edge-medium solid var(--theme-color-border-hype-group-object); |
| 209 | + border-radius: inherit; |
| 210 | + content: ''; |
| 211 | + inset: 0; |
| 212 | + pointer-events: none; // 1 |
| 213 | + position: absolute; |
| 214 | + } |
| 215 | + |
| 216 | + /// Prevents non-square images from stretching to fit the square container. |
| 217 | + |
| 218 | + > img, |
| 219 | + > picture > img { |
| 220 | + object-fit: cover; |
| 221 | + } |
| 222 | +} |
| 223 | + |
| 224 | +/// We use margin instead of gap on the content container because we don't want |
| 225 | +/// extra space above and below the intro and content (where there are empty |
| 226 | +/// "fill" rows for the purposes of centering those elements at larger |
| 227 | +/// viewports). |
| 228 | + |
| 229 | +.o-hype-group__content { |
| 230 | + grid-area: content; |
| 231 | + margin-block-start: var(--rhythm, #{size.$rhythm-default}); |
| 232 | + max-inline-size: size.$max-width-prose; |
| 233 | +} |
0 commit comments