Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

refactor(templates): responsive, overlap-free mixed-gallery (grade 68→75) (#2608)

rubyycheunge9a6850df979
diff --git a/packages/cli/templates/pages/mixed-gallery/page.tsx b/packages/cli/templates/pages/mixed-gallery/page.tsx
index 209391518d..56c1db3c0c 100644
--- a/packages/cli/templates/pages/mixed-gallery/page.tsx
+++ b/packages/cli/templates/pages/mixed-gallery/page.tsx
@@ -3,36 +3,51 @@
'use client';
import {XDSVStack, XDSLayout, XDSLayoutContent} from '@xds/core/Layout';
-import {XDSCenter} from '@xds/core/Center';
import {XDSText, XDSHeading} from '@xds/core/Text';
-import {XDSSection} from '@xds/core/Section';
-import {XDSGrid, XDSGridSpan} from '@xds/core/Grid';
+import {XDSAspectRatio} from '@xds/core/AspectRatio';
import * as stylex from '@stylexjs/stylex';
// ─── Styles ────────────────────────────────────────────────────────────────
+// The masonry needs a responsive column count AND a hero that spans 2 columns
+// on desktop but goes full-width on mobile. XDSGrid forces grid-template-columns
+// inline, so a responsive span can't be expressed through its props — this is a
+// @container grid (the sanctioned XDS pattern for container-responsive layout).
+// Image fill + radius are also custom because XDS has no image primitive (#2582).
const styles = stylex.create({
- textCenter: {
- textAlign: 'center',
+ // Named inline-size container on the page column so the grid responds to the
+ // available content width (works inside the sandbox's resizable preview).
+ container: {
+ containerType: 'inline-size',
+ containerName: 'gallery',
},
- card: {
- position: 'relative',
- width: '100%',
- height: '100%',
- overflow: 'clip',
- borderRadius: 'var(--radius-element)',
+ // 3 columns on desktop, dropping straight to 1 column below 720px (no 2-col
+ // middle state). minmax(0, 1fr) (not 1fr) so tracks split evenly and ignore
+ // the images' intrinsic min-width.
+ grid: {
+ display: 'grid',
+ gap: 'var(--spacing-3)',
+ gridTemplateColumns: {
+ default: 'repeat(3, minmax(0, 1fr))',
+ '@container gallery (max-width: 720px)': 'minmax(0, 1fr)',
+ },
+ },
+ // Hero spans 2 columns on desktop, then fills the row once it's single-column.
+ hero: {
+ gridColumn: {
+ default: 'span 2',
+ '@container gallery (max-width: 720px)': '1 / -1',
+ },
},
+ // Fills the XDSAspectRatio box. No objectFit prop on XDSAspectRatio (#2582).
img: {
- position: 'absolute',
- inset: 0,
width: '100%',
height: '100%',
objectFit: 'cover',
- transition: 'transform 0.3s ease',
- transform: {
- default: 'scale(1)',
- ':hover': 'scale(1.05)',
- },
+ },
+ // Rounds the image corners. No radius prop on XDSAspectRatio (#2582).
+ clip: {
+ borderRadius: 'var(--radius-element)',
},
});
@@ -43,6 +58,7 @@ interface GalleryImage {
title: string;
}
+// All landscape photos so the uniform 3:2 / 3:1 tiles crop cleanly.
const IMAGES: GalleryImage[] = [
{
// illustrative-horizontal-1 from xds_oss asset set
@@ -54,45 +70,40 @@ const IMAGES: GalleryImage[] = [
src: '/template-assets/light-home-horizontal-1.png',
title: 'Making memories',
},
- {
- // light-lifestyle-vertical-3 from xds_oss asset set
- src: '/template-assets/light-lifestyle-vertical-3.png',
- title: 'Seeing things',
- },
- {
- // light-lifestyle-vertical-1 from xds_oss asset set
- src: '/template-assets/light-lifestyle-vertical-1.png',
- title: 'Sharing ideas',
- },
{
// light-lifestyle-horizontal-1 from xds_oss asset set
src: '/template-assets/light-lifestyle-horizontal-1.png',
title: 'Being free',
},
- {
- // light-home-square-2 from xds_oss asset set
- src: '/template-assets/light-home-square-2.png',
- title: 'Feeling at home',
- },
- {
- // light-lifestyle-vertical-4 from xds_oss asset set
- src: '/template-assets/light-lifestyle-vertical-4.png',
- title: 'Taking it easy',
- },
{
// light-working-horizontal-2 from xds_oss asset set
src: '/template-assets/light-working-horizontal-2.png',
- title: 'Getting things done',
+ title: 'Getting it done',
+ },
+ {
+ // light-scene-horizontal-1 from xds_oss asset set
+ src: '/template-assets/light-scene-horizontal-1.png',
+ title: 'Finding calm',
},
];
-// ─── Gallery Card with Hover Overlay ────────────────────────────────────────
+// ─── Gallery Card ─────────────────────────────────────────────────────────
+// XDSAspectRatio gives every cell a definite, self-contained height from its
+// ratio, so images can't overflow their grid cell (no row-track guesswork).
-function GalleryCard({image}: {image: GalleryImage}) {
+function GalleryCard({
+ image,
+ ratio,
+ xstyle,
+}: {
+ image: GalleryImage;
+ ratio: number;
+ xstyle?: stylex.StyleXStyles;
+}) {
return (
- <div {...stylex.props(styles.card)}>
+ <XDSAspectRatio ratio={ratio} xstyle={[styles.clip, xstyle]}>
<img src={image.src} alt={image.title} {...stylex.props(styles.img)} />
- </div>
+ </XDSAspectRatio>
);
}
@@ -102,58 +113,44 @@ export default function MixedGalleryTemplate() {
return (
<XDSLayout
height="auto"
+ contentWidth={1400}
content={
<XDSLayoutContent padding={6}>
- <XDSCenter axis="horizontal">
- <XDSSection
- variant="transparent"
- maxWidth={1400}
- width="100%"
- padding={0}>
- <XDSVStack gap={6}>
- {/* Header — capped with XDSSection maxWidth */}
- <XDSCenter axis="horizontal">
- <XDSSection variant="transparent" maxWidth={680}>
- <XDSVStack gap={2} xstyle={styles.textCenter}>
- <XDSHeading level={1}>
- Make every day a little more delightful, one detail at a
- time.
- </XDSHeading>
- <XDSText type="body">
- We believe the smallest details are the ones that matter
- most. That&apos;s what turns an ordinary day into
- something worth remembering.
- </XDSText>
- </XDSVStack>
- </XDSSection>
- </XDSCenter>
+ <XDSVStack gap={6} xstyle={styles.container}>
+ {/* Header */}
+ <XDSVStack gap={2} hAlign="center">
+ <XDSHeading level={1} justify="center">
+ Make every day a little more delightful, one detail at a time.
+ </XDSHeading>
+ <XDSText type="body" justify="center">
+ We believe the smallest details are the ones that matter most.
+ That&apos;s what turns an ordinary day into something worth
+ remembering.
+ </XDSText>
+ </XDSVStack>
- {/* Featured masonry — hero + sidebar + bottom row */}
- <XDSGrid columns={3} rowHeight={90} gap={3}>
- {/* Hero — 2 cols × 5 rows */}
- <XDSGridSpan columns={2} rows={5}>
- <GalleryCard image={IMAGES[0]} />
- </XDSGridSpan>
+ {/* Featured layout — a wide hero next to a single tile, above a row
+ of three. Every tile is 3:2 except the hero, which is 3:1 so that
+ (being 2 columns wide) it matches the row height exactly. All
+ rows are therefore the same height. Responsive via @container:
+ 3 columns → 1 column at ≤720px. */}
+ <div {...stylex.props(styles.grid)}>
+ {/* Hero — spans 2 columns; 3:1 keeps it level with the sidebar */}
+ <GalleryCard
+ image={IMAGES[0]}
+ ratio={3 / 1}
+ xstyle={styles.hero}
+ />
- {/* Sidebar — full height */}
- <XDSGridSpan rows={5}>
- <GalleryCard image={IMAGES[2]} />
- </XDSGridSpan>
+ {/* Sidebar — same height as the hero */}
+ <GalleryCard image={IMAGES[2]} ratio={3 / 2} />
- {/* Bottom row */}
- <XDSGridSpan rows={3}>
- <GalleryCard image={IMAGES[3]} />
- </XDSGridSpan>
- <XDSGridSpan rows={3}>
- <GalleryCard image={IMAGES[4]} />
- </XDSGridSpan>
- <XDSGridSpan rows={3}>
- <GalleryCard image={IMAGES[1]} />
- </XDSGridSpan>
- </XDSGrid>
- </XDSVStack>
- </XDSSection>
- </XDSCenter>
+ {/* Bottom row — three equal tiles */}
+ <GalleryCard image={IMAGES[3]} ratio={3 / 2} />
+ <GalleryCard image={IMAGES[4]} ratio={3 / 2} />
+ <GalleryCard image={IMAGES[1]} ratio={3 / 2} />
+ </div>
+ </XDSVStack>
</XDSLayoutContent>
}
/>
diff --git a/packages/cli/templates/pages/mixed-gallery/template.doc.mjs b/packages/cli/templates/pages/mixed-gallery/template.doc.mjs
index c027215c48..092ac65b3b 100644
--- a/packages/cli/templates/pages/mixed-gallery/template.doc.mjs
+++ b/packages/cli/templates/pages/mixed-gallery/template.doc.mjs
@@ -2,9 +2,9 @@
/** @type {import('../../../../core/src/docs-types').TemplateDoc} */
export const doc = {
- name: 'Mixed',
- displayName: 'Mixed',
- description: 'Masonry-style image gallery with varying image sizes',
+ name: 'Mixed Gallery',
+ displayName: 'Mixed Gallery',
+ description: 'Masonry-style image gallery with varying image sizes.',
type: 'page',
isReady: true,
category: 'Gallery - Mixed',