|
1 | 1 | @use 'sass:math'; |
2 | 2 | @use '../compiled/tokens/scss/color'; |
| 3 | +@use '../compiled/tokens/scss/ease'; |
| 4 | +@use '../compiled/tokens/scss/font-weight'; |
| 5 | +@use '../compiled/tokens/scss/line-height'; |
3 | 6 | @use '../compiled/tokens/scss/size'; |
| 7 | +@use '../compiled/tokens/scss/transition'; |
4 | 8 | @use '../mixins/border-radius'; |
5 | 9 | @use '../mixins/emdash'; |
6 | 10 | @use '../mixins/ms'; |
@@ -258,6 +262,80 @@ blockquote > footer > cite { |
258 | 262 | } |
259 | 263 | } |
260 | 264 |
|
| 265 | +/// Details/Summary |
| 266 | +/// |
| 267 | +/// 1. Apply vertical rhythm between child elements, similar to `blockquote` |
| 268 | + |
| 269 | +details { |
| 270 | + @include spacing.vertical-rhythm; // 1 |
| 271 | + |
| 272 | + /// 1. Offset the summary text a bit from its contents |
| 273 | + /// 2. Use the same interaction affordance as buttons |
| 274 | + /// 3. Set up our custom marker. Because Safari for `::marker` is poor, we |
| 275 | + /// have to use some hackery instead. |
| 276 | + /// 4. Apply padding that is consistent with lists. |
| 277 | + /// |
| 278 | + > summary { |
| 279 | + color: var(--theme-color-text-emphasis); // 1 |
| 280 | + cursor: pointer; // 2 |
| 281 | + font-weight: font-weight.$medium; |
| 282 | + list-style: none; // 3 |
| 283 | + padding-inline-start: size.$spacing-type-block-indent; // 4 |
| 284 | + position: relative; // 3 |
| 285 | + |
| 286 | + /// Safari 16.6 demands more than `list-style: none` |
| 287 | + &::-webkit-details-marker { |
| 288 | + display: none; |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + /// Icon affordance for summary. We use a pseudo element so we can rotate it |
| 293 | + /// without an additional asset. |
| 294 | + /// |
| 295 | + /// 1. Align nicely with adjacent text, using the default `line-height` as a |
| 296 | + /// fallback when line-height units aren't supported. |
| 297 | + /// 2. Offset just a bit visually so the pointer aligns nicely with the |
| 298 | + /// content below. We use `translate` instead of `transform` so we can |
| 299 | + /// modify the rotation without repeating this style. |
| 300 | + > summary::before { |
| 301 | + background-position: center; |
| 302 | + background-repeat: no-repeat; |
| 303 | + background-size: contain; |
| 304 | + block-size: line-height.$loose * 1em; // 1 |
| 305 | + block-size: 1lh; // 1 |
| 306 | + content: ''; |
| 307 | + inline-size: 1em; |
| 308 | + inset-inline-start: 0; |
| 309 | + position: absolute; |
| 310 | + translate: -33% 0; // 2 |
| 311 | + |
| 312 | + // Vary the icon color based on the theme. |
| 313 | + @include theme.styles { |
| 314 | + background-image: svg-load( |
| 315 | + 'icons/caret-right.svg', |
| 316 | + fill=color.$text-dark |
| 317 | + ); |
| 318 | + } |
| 319 | + |
| 320 | + @include theme.styles(dark) { |
| 321 | + background-image: svg-load( |
| 322 | + 'icons/caret-right.svg', |
| 323 | + fill=color.$text-light-emphasis |
| 324 | + ); |
| 325 | + } |
| 326 | + |
| 327 | + // Animate the icon rotation if the user has no reduced motion preference. |
| 328 | + @media (prefers-reduced-motion: no-preference) { |
| 329 | + transition: rotate transition.$immediate ease.$out; |
| 330 | + } |
| 331 | + } |
| 332 | + |
| 333 | + // Rotate the icon when the details element is open. |
| 334 | + &[open] > summary::before { |
| 335 | + rotate: 90deg; |
| 336 | + } |
| 337 | +} |
| 338 | + |
261 | 339 | /** |
262 | 340 | * Apply some sensible defaults to tables |
263 | 341 | */ |
|
0 commit comments