Skip to content

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

TypeScript

feat(docsite): home blog showcase — hidden descriptions, equal-height split, and responsive type (#3908)

rubyycheung4d94d5efeaff
diff --git a/apps/docsite/src/app/(site)/_landing/BlogShowcase.tsx b/apps/docsite/src/app/(site)/_landing/BlogShowcase.tsx
index 4909803cce..4f2d6dd77d 100644
--- a/apps/docsite/src/app/(site)/_landing/BlogShowcase.tsx
+++ b/apps/docsite/src/app/(site)/_landing/BlogShowcase.tsx
@@ -28,11 +28,11 @@ import {ArrowRight} from 'lucide-react';
import {Heading} from '@astryxdesign/core/Text';
import {Icon} from '@astryxdesign/core/Icon';
import {VStack, HStack} from '@astryxdesign/core/Layout';
-import {Grid, GridSpan} from '@astryxdesign/core/Grid';
import {Button} from '@astryxdesign/core/Button';
import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
import {blogPosts} from '../../../generated/blogRegistry';
import {BlogCard} from '../../../components/blog/BlogCard';
+import {BlogFeatureCard} from '../../../components/blog/BlogFeatureCard';
// The featured-split layout (3+ posts) renders 1 feature (left) + 2 compact
// (right), filled by the 3 most recent posts (blogPosts is emitted latest-first
@@ -51,17 +51,26 @@ const styles = stylex.create({
alignItems: 'baseline',
rowGap: spacingVars['--spacing-2'],
},
- featureCell: {
- gridColumn: {
- default: '1 / -1',
- '@media (min-width: 900px)': 'span 2',
+ // Featured split (3+ posts): a wide feature card + a stack of two compact
+ // cards at a 2.4 : 1 ratio. align-items:stretch makes both columns equal
+ // height; collapses to one column below 1024px.
+ splitGrid: {
+ width: '100%',
+ display: 'grid',
+ gridTemplateColumns: {
+ default: '1fr',
+ '@media (min-width: 1024px)': '2.4fr 1fr',
},
+ gap: spacingVars['--spacing-8'],
+ alignItems: 'stretch',
},
- rightCell: {
- gridColumn: {
- default: '1 / -1',
- '@media (min-width: 900px)': 'span 1',
- },
+ rightCol: {
+ display: 'flex',
+ flexDirection: 'column',
+ justifyContent: 'space-between',
+ gap: spacingVars['--spacing-6'],
+ minWidth: 0,
+ height: '100%',
},
// Two equal cards, side by side when there's room and stacked otherwise.
// `min(480px, 100%)` clamps the track to the container so it never forces a
@@ -107,8 +116,8 @@ export function BlogShowcase() {
return (
<BlogSection>
<div {...stylex.props(styles.twoUpGrid)}>
- <BlogCard post={first} feature />
- <BlogCard post={second} feature />
+ <BlogCard post={first} feature hideDescription />
+ <BlogCard post={second} feature hideDescription />
</div>
</BlogSection>
);
@@ -120,18 +129,14 @@ export function BlogShowcase() {
return (
<BlogSection>
- <Grid columns={3} gap={8} width="100%" align="start">
- <GridSpan xstyle={styles.featureCell}>
- <BlogCard post={featurePost} feature />
- </GridSpan>
- <GridSpan xstyle={styles.rightCell}>
- <VStack gap={6}>
- {compactPosts.map(post => (
- <BlogCard key={post.slug} post={post} />
- ))}
- </VStack>
- </GridSpan>
- </Grid>
+ <div {...stylex.props(styles.splitGrid)}>
+ <BlogFeatureCard post={featurePost} hideDescription />
+ <div {...stylex.props(styles.rightCol)}>
+ {compactPosts.map(post => (
+ <BlogCard key={post.slug} post={post} hideDescription />
+ ))}
+ </div>
+ </div>
</BlogSection>
);
}
diff --git a/apps/docsite/src/components/blog/BlogCard.tsx b/apps/docsite/src/components/blog/BlogCard.tsx
index bfa6017037..13ae0a3b54 100644
--- a/apps/docsite/src/components/blog/BlogCard.tsx
+++ b/apps/docsite/src/components/blog/BlogCard.tsx
@@ -51,14 +51,42 @@ const styles = stylex.create({
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
},
+ // Below 720px (where the post grid becomes a single column) the feature
+ // card's title/excerpt match the regular cards' size for a consistent stack.
+ featureTitle: {
+ fontSize: {
+ default: 'var(--text-heading-3-size)',
+ '@media (min-width: 720px)': 'var(--text-heading-1-size)',
+ },
+ lineHeight: {
+ default: 'var(--text-heading-3-leading)',
+ '@media (min-width: 720px)': 'var(--text-heading-1-leading)',
+ },
+ },
+ featureExcerpt: {
+ fontSize: {
+ default: 'var(--text-body-size)',
+ '@media (min-width: 720px)': 'var(--text-large-size)',
+ },
+ lineHeight: {
+ default: 'var(--text-body-leading)',
+ '@media (min-width: 720px)': 'var(--text-large-leading)',
+ },
+ },
});
export interface BlogCardProps {
post: BlogPost;
feature?: boolean;
+ /** Hide the description/excerpt (e.g. to keep the home showcase tight). */
+ hideDescription?: boolean;
}
-export function BlogCard({post, feature = false}: BlogCardProps) {
+export function BlogCard({
+ post,
+ feature = false,
+ hideDescription = false,
+}: BlogCardProps) {
const releaseVersion = parseReleaseVersion(post.title);
return (
<Link
@@ -87,15 +115,25 @@ export function BlogCard({post, feature = false}: BlogCardProps) {
</AspectRatio>
<VStack gap={3}>
<VStack gap={1}>
- <Heading level={feature ? 1 : 3}>{post.title}</Heading>
- <Text
- type={feature ? 'large' : 'body'}
- weight="normal"
- color="secondary"
- xstyle={styles.excerpt}
- className={css.description}>
- {post.description}
- </Text>
+ <Heading
+ level={feature ? 1 : 3}
+ xstyle={feature ? styles.featureTitle : undefined}>
+ {post.title}
+ </Heading>
+ {hideDescription ? null : (
+ <Text
+ type={feature ? 'large' : 'body'}
+ weight="normal"
+ color="secondary"
+ xstyle={
+ feature
+ ? [styles.excerpt, styles.featureExcerpt]
+ : styles.excerpt
+ }
+ className={css.description}>
+ {post.description}
+ </Text>
+ )}
</VStack>
<AuthorByline
authors={post.authors}
diff --git a/apps/docsite/src/components/blog/BlogFeatureCard.tsx b/apps/docsite/src/components/blog/BlogFeatureCard.tsx
new file mode 100644
index 0000000000..c895b8598b
--- /dev/null
+++ b/apps/docsite/src/components/blog/BlogFeatureCard.tsx
@@ -0,0 +1,147 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file BlogFeatureCard.tsx
+ * Showcase-only feature card for BlogShowcase's equal-height split. Unlike the
+ * shared BlogCard (whose Link-wrapped body can't fill the card), this is a plain
+ * flex column that fills its stretched grid cell, with the cover growing to
+ * absorb extra height so the title + byline stay tight at the bottom.
+ *
+ * @input a blog post; hideDescription
+ * @output a full-height feature card for the home "Stay in the know" split
+ * @position Used only by BlogShowcase's featured-split layout.
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {Text, Heading} from '@astryxdesign/core/Text';
+import {VStack} from '@astryxdesign/core/Layout';
+import {Link} from '@astryxdesign/core/Link';
+import {AspectRatio} from '@astryxdesign/core/AspectRatio';
+import {VisuallyHidden} from '@astryxdesign/core/VisuallyHidden';
+import type {BlogPost} from '../../lib/blog/schema';
+import {AuthorByline} from './AuthorByline';
+import {BlogCoverArt} from './BlogCoverArt';
+import {ReleaseCoverArt} from './ReleaseCoverArt';
+import {parseReleaseVersion} from '../../lib/blog/release';
+import css from './BlogCard.module.css';
+
+const styles = stylex.create({
+ card: {
+ position: 'relative',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 'var(--spacing-4)',
+ minWidth: 0,
+ height: '100%',
+ color: 'inherit',
+ },
+ cover: {
+ borderRadius: 'var(--radius-container)',
+ backgroundColor: 'var(--color-background-muted)',
+ border: '1px solid var(--color-border)',
+ overflow: 'hidden',
+ // Absorb the card's extra height when stretched taller than 16:9 so the
+ // title/byline stay tight; the image (objectFit:cover) crops to fit.
+ flexGrow: 1,
+ },
+ coverImg: {
+ width: '100%',
+ height: '100%',
+ objectFit: 'cover',
+ display: 'block',
+ },
+ excerpt: {
+ display: '-webkit-box',
+ WebkitLineClamp: 2,
+ WebkitBoxOrient: 'vertical',
+ overflow: 'hidden',
+ },
+ // Below 1024px (where the showcase split stacks) match the compact cards'
+ // title size; scale up to the feature size only in the two-column split.
+ title: {
+ fontSize: {
+ default: 'var(--text-heading-3-size)',
+ '@media (min-width: 1024px)': 'var(--text-heading-1-size)',
+ },
+ lineHeight: {
+ default: 'var(--text-heading-3-leading)',
+ '@media (min-width: 1024px)': 'var(--text-heading-1-leading)',
+ },
+ },
+ link: {
+ position: 'absolute',
+ inset: 0,
+ borderRadius: 'var(--radius-container)',
+ },
+});
+
+export function BlogFeatureCard({
+ post,
+ hideDescription = false,
+}: {
+ post: BlogPost;
+ hideDescription?: boolean;
+}) {
+ const releaseVersion = parseReleaseVersion(post.title);
+
+ const coverContent = post.coverImage ? (
+ <img
+ src={post.coverImage}
+ alt={post.coverAlt ?? ''}
+ {...stylex.props(styles.coverImg)}
+ />
+ ) : releaseVersion ? (
+ <ReleaseCoverArt
+ version={releaseVersion}
+ packageName={post.releasePackage ?? undefined}
+ />
+ ) : (
+ <BlogCoverArt seed={post.slug} feature />
+ );
+
+ // Merge stylex's className with the CSS-module class; a bare
+ // className={css.card} after the spread would drop all of styles.card.
+ const cardProps = stylex.props(styles.card);
+
+ return (
+ <div
+ className={`${cardProps.className ?? ''} ${css.card}`}
+ style={cardProps.style}>
+ <AspectRatio ratio={16 / 9} xstyle={styles.cover} className={css.cover}>
+ {coverContent}
+ </AspectRatio>
+ <VStack gap={3}>
+ <VStack gap={1}>
+ <Heading level={1} xstyle={styles.title}>
+ {post.title}
+ </Heading>
+ {hideDescription ? null : (
+ <Text
+ type="large"
+ weight="normal"
+ color="secondary"
+ xstyle={styles.excerpt}
+ className={css.description}>
+ {post.description}
+ </Text>
+ )}
+ </VStack>
+ <AuthorByline
+ authors={post.authors}
+ date={post.date}
+ readingTimeMinutes={post.readingTimeMinutes}
+ variant="compact"
+ className={css.byline}
+ />
+ </VStack>
+ <Link
+ href={`/blog/${post.slug}`}
+ label={post.title}
+ color="inherit"
+ display="block"
+ xstyle={styles.link}>
+ <VisuallyHidden>{post.title}</VisuallyHidden>
+ </Link>
+ </div>
+ );
+}
diff --git a/apps/docsite/src/components/blog/ReleaseCoverArt.tsx b/apps/docsite/src/components/blog/ReleaseCoverArt.tsx
index 1dabd16845..173ae40535 100644
--- a/apps/docsite/src/components/blog/ReleaseCoverArt.tsx
+++ b/apps/docsite/src/components/blog/ReleaseCoverArt.tsx
@@ -37,10 +37,18 @@ const styles = stylex.create({
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
- gap: '1.8cqw',
overflow: 'hidden',
userSelect: 'none',
},
+ // Carries the vertical gap. Must be a child of root, not root itself: an
+ // element isn't its own container, so `gap: cqw` on root resolves against the
+ // viewport instead of the cover width and wouldn't scale in a small preview.
+ content: {
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ gap: '1.8cqw',
+ },
row: {
display: 'flex',
alignItems: 'center',
@@ -80,23 +88,25 @@ export function ReleaseCoverArt({
return (
<div {...stylex.props(styles.root)} role="presentation" aria-hidden="true">
- <div {...stylex.props(styles.row)}>
- {segments.map((segment, i) => (
- <Fragment key={i}>
- {i > 0 ? (
- <svg {...stylex.props(styles.mark)} viewBox="0 0 40 40">
- <path d={MARK_PATH} />
- </svg>
- ) : null}
- <Text type="code" weight="semibold" xstyle={styles.version}>
- {segment}
- </Text>
- </Fragment>
- ))}
+ <div {...stylex.props(styles.content)}>
+ <div {...stylex.props(styles.row)}>
+ {segments.map((segment, i) => (
+ <Fragment key={i}>
+ {i > 0 ? (
+ <svg {...stylex.props(styles.mark)} viewBox="0 0 40 40">
+ <path d={MARK_PATH} />
+ </svg>
+ ) : null}
+ <Text type="code" weight="semibold" xstyle={styles.version}>
+ {segment}
+ </Text>
+ </Fragment>
+ ))}
+ </div>
+ <Text type="code" color="secondary" as="div" xstyle={styles.handle}>
+ {packageName}
+ </Text>
</div>
- <Text type="code" color="secondary" as="div" xstyle={styles.handle}>
- {packageName}
- </Text>
</div>
);
}