Rewrite the carousel without Tailwind
Plan step 36 (containment group): <x-carousel>'s and <x-carousel-item>'s class lists move into resources/css/components/carousel.css and carousel-item.css, keyed on data-md-carousel (its value is the layout) and the parts' data-md-carousel-* hooks (-probe, -scroller, -controls with "auto"/"always", -previous/-next, -item, -surface, -content, -label/-label-text). Every selector uses a `>` combinator rather than a bare descendant one, because a carousel item can itself hold a nested carousel whose own root would otherwise match its parent's layout rules too (list.css already solves the same problem for segmented list rows). Behaviour is unchanged: resources/js/carousel.js (the keyline maths, C-05's reduced-motion fix, C-11's vertical full-screen layout, C-12's padding, C-18's item-as-tab-stop, the multi-aspect layout) is touched only where it reads or writes the renamed hooks and dataset properties; every inline custom property it writes (--material-carousel-*) is untouched. The item renders the shared md-focus-ring class (foundation/interaction.css) instead of a hand-rolled ring, refined to an inset offset since an outward one would draw under the neighbouring item. The previous/next buttons mirror whole in RTL from carousel.css rather than through <x-icon mirror-rtl>, which <x-button icon> has no prop to reach (a component outside this batch); the technique matches how the Tailwind-era markup already mirrored the whole button. The overlay label's literal white ink over the scrim (C-25) is kept, with the same reasoning as before. Hooks renamed data-material-carousel(-item/-surface/-content/-label) -> data-md-carousel(-item/-surface/-content/-label), data-padding(-end) -> data-md-padding(-end), data-centered -> data-md-centered, updated in the same commit: resources/js/carousel.js, tests/Feature/Components/ CarouselTest.php (rewritten on data-md-* and ComponentStylesheet) and tests/Browser/CarouselTest.php. Browser tests owed by docs/plans/material-3-browser-tests.md, added but not run: the multi-aspect carousel's previous/next, arrow keys, Home and End (scoped by data-md-carousel="multi-aspect" rather than a position in the showcase, so reordering its examples cannot silently mis-target the wrong carousel); a reduced-motion click on an item cut off only by the row's own edge, which documents rather than fixes a real gap — isMasked()'s inset check is always false once C-05 zeroes every item's inset, so the click-to-reveal affordance does not fire there (found by the Chromium baseline, step 32; fixing it is outside a hook rename). Imported from the Containment block of components.css. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
287340b066
commit
a149970dd0
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* <x-carousel-item>: one slide of an <x-carousel>, masked and shifted by the keyline maths
|
||||
* carousel.css's header describes, unless the row is full-screen or multi-aspect, where nothing
|
||||
* masks it at all (docs/reference/m3/components-actions-communication-containment.md § Carousel;
|
||||
* docs/audits/m3-alignment/containment.md, C-11, C-12, C-25).
|
||||
*
|
||||
* [data-md-carousel-item] the tab stop (C-18), a focusable `group`, `md-focus-ring`
|
||||
* [data-md-carousel-surface] the masked, shifted, extra-large-corner (28px) box
|
||||
* [data-md-carousel-content] the slot (an <img>, cropped)
|
||||
* [data-md-carousel-label] the "n of m"-named overlay on the scrim
|
||||
* [data-md-carousel-label-text]
|
||||
*
|
||||
* The item renders the shared `md-focus-ring` class (foundation/interaction.css) rather than a
|
||||
* hand-rolled ring — the box the class draws *is* the item's own whole hit area — refined here to
|
||||
* an inset ring: an item sits edge to edge with its neighbours in the row, so the class's own 2px
|
||||
* *outward* offset would draw under the next item instead of around this one.
|
||||
*
|
||||
* Full-screen: edge to edge, no corner, no mask — `--material-carousel-shift`/`-inset` go unread.
|
||||
* Multi-aspect: the view writes the item's own `aspect-ratio` inline (`aspect`, a prop, held
|
||||
* inside M3's 9:16–16:9 range); the extra-large corner still applies but nothing masks it, since
|
||||
* an Arrangement describes items of one size and a multi-aspect row has none. Selectors use `>`
|
||||
* throughout, matching carousel.css, so a carousel nested inside an item never inherits its
|
||||
* parent's layout rules.
|
||||
*
|
||||
* The label's ink is a literal `white`, not a role: it sits over `--md-sys-color-scrim`, which is
|
||||
* black in every scheme, theme and contrast level, so white is the one ink that always has the
|
||||
* scrim's contrast — a role (`inverse-on-surface`) is dark ink in a dark scheme and fails there
|
||||
* (C-25, deliberately kept, as the component's original header explained).
|
||||
*/
|
||||
|
||||
@layer material.reset, material.tokens, material.base, material.layout, material.components, material.text, material.visibility;
|
||||
|
||||
@layer material.components {
|
||||
[data-md-carousel-item] {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
flex-shrink: 0;
|
||||
scroll-snap-align: start;
|
||||
scroll-snap-stop: always;
|
||||
}
|
||||
|
||||
[data-md-carousel-item]:focus-visible {
|
||||
outline-offset: -12px;
|
||||
}
|
||||
|
||||
[data-md-carousel='full-screen'] > [data-md-carousel-scroller] > [data-md-carousel-item] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
[data-md-carousel='multi-aspect'] > [data-md-carousel-scroller] > [data-md-carousel-item] {
|
||||
width: auto;
|
||||
border-radius: var(--md-sys-shape-corner-xl);
|
||||
}
|
||||
|
||||
[data-md-carousel]:not([data-md-carousel='full-screen']):not([data-md-carousel='multi-aspect']) > [data-md-carousel-scroller] > [data-md-carousel-item] {
|
||||
width: var(--material-carousel-slot);
|
||||
max-width: 100%;
|
||||
border-radius: var(--md-sys-shape-corner-xl);
|
||||
}
|
||||
|
||||
[data-md-carousel-item] > [data-md-carousel-surface] {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background-color: var(--md-sys-color-surface-container-highest);
|
||||
color: var(--md-sys-color-on-surface);
|
||||
}
|
||||
|
||||
[data-md-carousel='multi-aspect'] > [data-md-carousel-scroller] > [data-md-carousel-item] > [data-md-carousel-surface] {
|
||||
border-radius: var(--md-sys-shape-corner-xl);
|
||||
}
|
||||
|
||||
[data-md-carousel]:not([data-md-carousel='full-screen']):not([data-md-carousel='multi-aspect']) > [data-md-carousel-scroller] > [data-md-carousel-item] > [data-md-carousel-surface] {
|
||||
border-radius: var(--md-sys-shape-corner-xl);
|
||||
translate: var(--material-carousel-shift) 0;
|
||||
clip-path: inset(0 var(--material-carousel-inset, 0px) round var(--md-sys-shape-corner-xl));
|
||||
}
|
||||
|
||||
[data-md-carousel-surface] > [data-md-carousel-content] {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
& > img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
[data-md-carousel-surface] > [data-md-carousel-label] {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
padding: var(--md-sys-measurement-space500) var(--md-sys-measurement-space200) var(--md-sys-measurement-space200);
|
||||
background: linear-gradient(to top, color-mix(in srgb, var(--md-sys-color-scrim) 60%, transparent), transparent);
|
||||
opacity: var(--material-carousel-label);
|
||||
}
|
||||
|
||||
[data-md-carousel-label] > [data-md-carousel-label-text] {
|
||||
overflow: hidden;
|
||||
color: white;
|
||||
font: var(--md-sys-typescale-title-md);
|
||||
letter-spacing: var(--md-sys-typescale-title-md-tracking);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
translate: var(--material-carousel-label-shift) 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* <x-carousel>: M3 Expressive's carousel — multi-browse, hero, uncontained, the uncontained
|
||||
* multi-aspect-ratio layout (added November 2025) and full-screen, on a native scroll container
|
||||
* with CSS scroll snap. resources/js/carousel.js ports Compose's keyline maths (Arrangement.kt,
|
||||
* Keylines.kt, KeylineList.kt, Strategy.kt, KeylineSnapPosition.kt, Carousel.kt, androidx Compose
|
||||
* Material 3 @ commit 7ac433e44e797de53af85226797862687f37735f, Apache-2.0) and writes the masks
|
||||
* and sizes as inline custom properties every scroll frame; this file draws everything the script
|
||||
* does not — the row's layout per layout, and the controls — and carousel-item.css draws the
|
||||
* item and its mask (docs/reference/m3/components-actions-communication-containment.md
|
||||
* § Carousel; docs/audits/m3-alignment/containment.md).
|
||||
*
|
||||
* [data-md-carousel] the row wrapper; its value is the layout
|
||||
* [data-md-carousel-probe] hidden, measures the preferred item width for the script
|
||||
* [data-md-carousel-scroller] the scroll container (role="region")
|
||||
* [data-md-carousel-item] one slide — carousel-item.css
|
||||
* [data-md-carousel-controls] previous/next, "auto" (pointer: fine only) or "always"
|
||||
* [data-md-carousel-previous], [data-md-carousel-next]
|
||||
*
|
||||
* Specs table: 16dp leading/trailing padding, 8dp top/bottom and between items, for every layout
|
||||
* but uncontained (leading only) and full-screen (0, edge to edge — C-12); a `>` combinator
|
||||
* throughout, never a bare descendant one, because a carousel item can itself hold a nested
|
||||
* carousel (a `multi-aspect` gallery inside a `hero` slide) whose own root would otherwise match
|
||||
* its parent's rules too. Full-screen scrolls vertically, one edge-to-edge item at a time, capped
|
||||
* at the 840px medium window it is meant for (C-11); reduced motion needs no rule here at all —
|
||||
* the script writes zero inset, shift and full opacity itself for every layout (C-05).
|
||||
*
|
||||
* The previous/next icons mirror in RTL by scaling the whole button, as the row's arrow keys and
|
||||
* scroll direction already do (`resources/js/carousel.js`'s own `state.rtl`), rather than through
|
||||
* `<x-icon mirror-rtl>`: `<x-button icon>` has no prop to reach it, and flipping a round icon
|
||||
* button whole reads the same as flipping only its glyph.
|
||||
*/
|
||||
|
||||
@layer material.reset, material.tokens, material.base, material.layout, material.components, material.text, material.visibility;
|
||||
|
||||
@import './button.css';
|
||||
@import './carousel-item.css';
|
||||
|
||||
@layer material.components {
|
||||
[data-md-carousel] {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
[data-md-carousel] > [data-md-carousel-probe] {
|
||||
position: absolute;
|
||||
inset-inline-start: 0;
|
||||
top: 0;
|
||||
height: 0;
|
||||
width: var(--material-carousel-item-width);
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
[data-md-carousel] > [data-md-carousel-scroller] {
|
||||
display: flex;
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
[data-md-carousel='full-screen'] > [data-md-carousel-scroller] {
|
||||
margin-inline: auto;
|
||||
height: var(--material-carousel-height);
|
||||
max-width: 840px;
|
||||
flex-direction: column;
|
||||
gap: var(--md-sys-measurement-space200);
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior-y: contain;
|
||||
scroll-snap-type: y mandatory;
|
||||
}
|
||||
|
||||
[data-md-carousel]:not([data-md-carousel='full-screen']) > [data-md-carousel-scroller] {
|
||||
height: calc(var(--material-carousel-height) + 16px);
|
||||
gap: var(--md-sys-measurement-space100);
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
overscroll-behavior-x: contain;
|
||||
padding-block: var(--md-sys-measurement-space100);
|
||||
}
|
||||
|
||||
[data-md-carousel='multi-aspect'] > [data-md-carousel-scroller] {
|
||||
padding-inline-start: var(--material-carousel-pad);
|
||||
}
|
||||
|
||||
[data-md-carousel='multi-browse'] > [data-md-carousel-scroller],
|
||||
[data-md-carousel='hero'] > [data-md-carousel-scroller] {
|
||||
scroll-snap-type: x mandatory;
|
||||
}
|
||||
|
||||
[data-md-carousel] > [data-md-carousel-controls] {
|
||||
display: none;
|
||||
margin-top: 12px;
|
||||
justify-content: flex-end;
|
||||
gap: var(--md-sys-measurement-space100);
|
||||
}
|
||||
|
||||
[data-md-carousel] > [data-md-carousel-controls='always'] {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@media (pointer: fine) {
|
||||
[data-md-carousel] > [data-md-carousel-controls='auto'] {
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
[data-md-carousel]:not([data-md-carousel='full-screen']) > [data-md-carousel-controls] > [data-md-carousel-previous]:dir(rtl),
|
||||
[data-md-carousel]:not([data-md-carousel='full-screen']) > [data-md-carousel-controls] > [data-md-carousel-next]:dir(rtl) {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user