Skip to content

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

TypeScript

chore(docsite): consolidate content max-widths into shared constants (#2992)

rubyycheung2a748255ad3c
diff --git a/apps/docsite/src/app/(docs)/components/page.tsx b/apps/docsite/src/app/(docs)/components/page.tsx
index 90b66d3c63..aa0fccaec7 100644
--- a/apps/docsite/src/app/(docs)/components/page.tsx
+++ b/apps/docsite/src/app/(docs)/components/page.tsx
@@ -22,6 +22,7 @@ import {CodeExampleBlock} from '../../../components/CodeExampleBlock';
import {components as componentRegistry} from '../../../generated/componentRegistry';
import {blocks} from '../../../generated/blockRegistry';
import {ShowcaseThumbnail} from '../../../components/ShowcaseThumbnail';
+import {layout} from '../../../layout.stylex';
/**
* Category display order for the overview page.
@@ -130,7 +131,7 @@ export default function ComponentsGalleryPage() {
}, [categorizedItems]);
return (
- <Section maxWidth={1200} padding={6} xstyle={styles.section}>
+ <Section maxWidth={layout.contentMaxWidth} padding={6} xstyle={styles.section}>
<VStack gap={10}>
<VStack gap={4} hAlign="center">
<VStack gap={2} style={{alignItems: 'center'}}>
diff --git a/apps/docsite/src/app/(site)/_landing/AboutShowcase.tsx b/apps/docsite/src/app/(site)/_landing/AboutShowcase.tsx
index 8612216e3d..96d6fdafd4 100644
--- a/apps/docsite/src/app/(site)/_landing/AboutShowcase.tsx
+++ b/apps/docsite/src/app/(site)/_landing/AboutShowcase.tsx
@@ -8,6 +8,7 @@ import {VStack} from '@xds/core/Layout';
import {Heading, Text} from '@xds/core/Text';
import {Link} from '@xds/core/Link';
import {spacingVars} from '@xds/core/theme/tokens.stylex';
+import {layout} from '../../../layout.stylex';
// Editorial-style "about" section: a left-anchored heading block sits
// alongside three feature columns. Each feature column leads with a
@@ -32,12 +33,11 @@ const YELLOW_PASTEL = 'var(--color-background-yellow)';
const SHAPE_SIZE = 40;
const styles = stylex.create({
- // Cap the section at the same 1200px maxWidth used by sibling
- // showcases (Features, Discover) so all three sections line up
- // vertically inside the showcaseOverlay container.
+ // Cap the section so all three home showcases line up vertically
+ // inside the showcaseOverlay container.
sectionLayout: {
width: '100%',
- maxWidth: 1200,
+ maxWidth: layout.contentMaxWidth,
},
// Responsive grid for the heading + 3 feature columns.
//
diff --git a/apps/docsite/src/app/(site)/_landing/DiscoverShowcase.tsx b/apps/docsite/src/app/(site)/_landing/DiscoverShowcase.tsx
index 507fa7c6ed..4929c629b8 100644
--- a/apps/docsite/src/app/(site)/_landing/DiscoverShowcase.tsx
+++ b/apps/docsite/src/app/(site)/_landing/DiscoverShowcase.tsx
@@ -12,6 +12,7 @@ import {Button} from '@xds/core/Button';
import {spacingVars} from '@xds/core/theme/tokens.stylex';
import {AstryxLogo} from '../../../components/logos';
import {components} from '../../../generated/componentRegistry';
+import {layout} from '../../../layout.stylex';
// Count of public @xds/core components (excluding hooks and hidden entries),
// rounded down to the nearest 10 for marketing copy. Sourced from the
@@ -29,15 +30,12 @@ const styles = stylex.create({
overflowX: 'clip',
},
// The "stage" hosts the absolutely-positioned floating preview
- // images + the centered CTA card. maxWidth: 1200 matches the
- // shared marketing-section cap used by FeaturesShowcase and
- // AboutShowcase so all three sections line up vertically inside
- // showcaseOverlay; the value isn't on the spacing scale, it's a
- // marketing page measure intentionally kept as a literal.
+ // images + the centered CTA card, capped so all three home
+ // showcases line up vertically inside showcaseOverlay.
stage: {
position: 'relative',
width: '100%',
- maxWidth: 1200,
+ maxWidth: layout.contentMaxWidth,
overflow: 'hidden',
borderRadius: 'var(--radius-container)',
isolation: 'isolate',
diff --git a/apps/docsite/src/app/(site)/_landing/FeaturesShowcase.tsx b/apps/docsite/src/app/(site)/_landing/FeaturesShowcase.tsx
index bb64a9ee15..66548a36af 100644
--- a/apps/docsite/src/app/(site)/_landing/FeaturesShowcase.tsx
+++ b/apps/docsite/src/app/(site)/_landing/FeaturesShowcase.tsx
@@ -9,6 +9,7 @@ import {Heading, Text} from '@xds/core/Text';
import {Link} from '@xds/core/Link';
import {spacingVars} from '@xds/core/theme/tokens.stylex';
import {components} from '../../../generated/componentRegistry';
+import {layout} from '../../../layout.stylex';
// Count of public @xds/core components (excluding hooks and hidden entries).
// Sourced from the generated registry so the number stays accurate as the
@@ -45,17 +46,12 @@ const styles = stylex.create({
// direct children of the grid and the 1-col gridTemplateColumns
// can lay them all out in source order.
//
- // Literal pixel values are intentional marketing-section
- // dimensions, not derivable from the spacing scale:
- // • maxWidth 1200 — shared content cap across all three home
- // showcases (Features, About, Discover) so they line up.
- // • minHeight 720 — keeps the bento tall enough on desktop
- // that the dominant "Themes" card has room for its larger
- // image composition; below this height the right column
- // reads as cramped against the left/middle.
+ // minHeight 720 keeps the bento tall enough on desktop that the
+ // dominant "Themes" card has room for its larger image composition;
+ // below this the right column reads as cramped against the left/middle.
gridLayout: {
width: '100%',
- maxWidth: 1200,
+ maxWidth: layout.contentMaxWidth,
display: 'grid',
gap: spacingVars['--spacing-8'],
gridTemplateColumns: {
diff --git a/apps/docsite/src/app/(site)/_landing/ThemingShowcase.tsx b/apps/docsite/src/app/(site)/_landing/ThemingShowcase.tsx
index be01c2af42..89d834bce5 100644
--- a/apps/docsite/src/app/(site)/_landing/ThemingShowcase.tsx
+++ b/apps/docsite/src/app/(site)/_landing/ThemingShowcase.tsx
@@ -17,6 +17,7 @@ import {
import {packages} from '../../../generated/packageRegistry';
import {themeObjects} from '../../../generated/themeRegistry';
import {ThemeShowcaseTile} from '../../../components/ThemeShowcaseTile';
+import {layout} from '../../../layout.stylex';
// Gallery order — mirrors the dedicated /themes page (most restrained
// → most expressive). Keeps the landing showcase consistent with the
@@ -98,7 +99,6 @@ const CARD_HEIGHT = 620;
// content sits flush with the same 24px page rim as the other
// sections.
const PAGE_GUTTER = 24;
-const CONTENT_MAX_WIDTH = 1200;
// At wide viewports, the gutter resolves to the empty space
// between the viewport edge and the centered 1200px content
// column — same horizontal start as the other 1200px-centered
@@ -106,7 +106,7 @@ const CONTENT_MAX_WIDTH = 1200;
// At narrower viewports, the max() clamp kicks in and pads the
// content by PAGE_GUTTER from the viewport edge so things don't
// touch the screen rim.
-const CONTENT_GUTTER_FORMULA = `max(${PAGE_GUTTER}px, calc((100vw - ${CONTENT_MAX_WIDTH}px) / 2))`;
+const CONTENT_GUTTER_FORMULA = `max(${PAGE_GUTTER}px, calc((100vw - ${layout.contentMaxWidth}px) / 2))`;
const styles = stylex.create({
// Section root — adds breathing room above the heading so the
diff --git a/apps/docsite/src/app/(site)/community/page.tsx b/apps/docsite/src/app/(site)/community/page.tsx
index 415501fd9a..8b9bfd18a1 100644
--- a/apps/docsite/src/app/(site)/community/page.tsx
+++ b/apps/docsite/src/app/(site)/community/page.tsx
@@ -39,6 +39,7 @@ import {Button} from '@xds/core/Button';
import {getKey} from '@xds/core/utils';
import {AstryxLogo} from '../../../components/logos';
import {GITHUB_REPO} from '../../../constants';
+import {layout} from '../../../layout.stylex';
const WIKI_BASE = `${GITHUB_REPO}/wiki`;
@@ -46,21 +47,15 @@ const WIKI_BASE = `${GITHUB_REPO}/wiki`;
// Styles
// =============================================================================
-// Page max-width. Sized for the 3-card grids (channels, start-
-// here paths, contributors) to read comfortably without going
-// edge-to-edge on wide viewports. Matches the dedicated theme
-// page width so the two sibling pages feel visually aligned.
-const PAGE_MAX_WIDTH = 1200;
-
const styles = stylex.create({
- // Wrap the section so it caps at PAGE_MAX_WIDTH and centers in
- // the viewport. Done on a plain wrapper instead of via the
- // section's maxWidth prop because Section's negative-inline-
- // margin styles (used to break out of container padding
- // elsewhere) beat any margin-inline:auto we try to set on the
- // section itself. Same pattern used on /themes.
+ // Wrap the section so it caps at the shared content width and
+ // centers in the viewport. Done on a plain wrapper instead of via
+ // the section's maxWidth prop because Section's negative-inline-
+ // margin styles (used to break out of container padding elsewhere)
+ // beat any margin-inline:auto we try to set on the section itself.
+ // Same pattern used on /themes.
pageWrap: {
- maxWidth: PAGE_MAX_WIDTH,
+ maxWidth: layout.contentMaxWidth,
marginInline: 'auto',
width: '100%',
},
@@ -82,7 +77,7 @@ const styles = stylex.create({
// own width. Matches the 1200px max-width used by the home
// page's section grids (FeaturesShowcase, AboutShowcase,
// DiscoverShowcase) so the two pages feel visually aligned.
- maxWidth: 1200,
+ maxWidth: layout.contentMaxWidth,
width: '100%',
marginInline: 'auto',
},
diff --git a/apps/docsite/src/app/(site)/page.tsx b/apps/docsite/src/app/(site)/page.tsx
index e6bbf1b1bf..513ac20b33 100644
--- a/apps/docsite/src/app/(site)/page.tsx
+++ b/apps/docsite/src/app/(site)/page.tsx
@@ -14,6 +14,7 @@ import {spacingVars} from '@xds/core/theme/tokens.stylex';
// Built theme (__built:true) so <XDSTheme> uses the pre-built CSS and skips
// runtime style injection. Importing the source astryxTheme.ts re-triggers it.
import {astryxTheme} from '@/themes/astryx';
+import {layout} from '../../layout.stylex';
import {
HeroReelProvider,
HeroReelCards,
@@ -69,7 +70,7 @@ const styles = stylex.create({
'@media (min-width: 1024px)': 0,
},
paddingBlockEnd: spacingVars['--spacing-12'],
- maxWidth: 800,
+ maxWidth: layout.proseMaxWidth,
marginInline: 'auto',
paddingInline: spacingVars['--spacing-6'],
textAlign: 'center',
diff --git a/apps/docsite/src/app/(site)/templates/page.tsx b/apps/docsite/src/app/(site)/templates/page.tsx
index 7cbef6c4d8..35b1b5cd2c 100644
--- a/apps/docsite/src/app/(site)/templates/page.tsx
+++ b/apps/docsite/src/app/(site)/templates/page.tsx
@@ -25,6 +25,7 @@ import {buildPlaygroundHref} from '../../../components/playgroundLink';
import {TemplatePreviewDialog} from '../../../components/TemplatePreviewDialog';
import type {TemplatePreviewItem} from '../../../components/TemplatePreviewDialog';
import {trackOpenPlayground, trackView} from '../../../lib/analytics';
+import {layout} from '../../../layout.stylex';
const CARD_STYLE: CSSProperties & {'--color-overlay': string} = {
'--color-overlay':
@@ -198,7 +199,7 @@ export default function TemplatesPage() {
);
return (
- <Section maxWidth={1200} padding={6} style={{marginInline: 'auto'}}>
+ <Section maxWidth={layout.contentMaxWidth} padding={6} style={{marginInline: 'auto'}}>
<VStack gap={10}>
{/* Header */}
<VStack gap={6} align="stretch">
diff --git a/apps/docsite/src/components/ChangelogView.tsx b/apps/docsite/src/components/ChangelogView.tsx
index 37587cb05d..f701434748 100644
--- a/apps/docsite/src/components/ChangelogView.tsx
+++ b/apps/docsite/src/components/ChangelogView.tsx
@@ -11,6 +11,7 @@ import {Section} from '@xds/core/Section';
import {TabList, Tab} from '@xds/core/TabList';
import {Carousel} from '@xds/core/Carousel';
import {GITHUB_REPO} from '../constants';
+import {layout} from '../layout.stylex';
function linkifyPRs(markdown: string): string {
return markdown.replace(/(?<!\[)#(\d+)/g, `[#$1](${GITHUB_REPO}/pull/$1)`);
@@ -71,7 +72,7 @@ export function ChangelogView({
const active = changelogs.find(c => c.pkg === activeTab);
return (
- <Section maxWidth={800} padding={6} xstyle={styles.section}>
+ <Section maxWidth={layout.proseMaxWidth} padding={6} xstyle={styles.section}>
<VStack gap={8}>
<VStack gap={4}>
<Heading level={1} type="display-1">
diff --git a/apps/docsite/src/components/ThemePackagePage.tsx b/apps/docsite/src/components/ThemePackagePage.tsx
index 6c96d339cb..8b44234948 100644
--- a/apps/docsite/src/components/ThemePackagePage.tsx
+++ b/apps/docsite/src/components/ThemePackagePage.tsx
@@ -23,6 +23,7 @@ import {ThemeShowcaseStore} from '../../../../packages/cli/templates/pages/theme
import {getThemeShowcaseContent} from './themeShowcaseContent';
import {buildPlaygroundHref} from './playgroundLink';
import {packages} from '../generated/packageRegistry';
+import {layout} from '../layout.stylex';
import {themeObjects} from '../generated/themeRegistry';
import {templates} from '../generated/templateRegistry';
import {trackOpenPlayground, trackToggle} from '../lib/analytics';
@@ -422,14 +423,13 @@ const styles = stylex.create({
showcaseCard: {
overflow: 'hidden',
},
- // Caps the showcase at the site's "wide content" max-width (1200px,
- // matching home-page showcases / docs index) and centers it so it
- // doesn't run viewport-edge to viewport-edge on very wide screens.
- // overflow:hidden clips any template content that exceeds the
- // available width on mobile (e.g. inventory filter rows, tables).
+ // Caps the showcase at the site's wide-content width and centers it
+ // so it doesn't run edge-to-edge on very wide screens. overflow:hidden
+ // clips template content that exceeds the width on mobile (e.g.
+ // inventory filter rows, tables).
showcaseBlock: {
width: '100%',
- maxWidth: 1200,
+ maxWidth: layout.contentMaxWidth,
marginInline: 'auto',
overflow: 'hidden',
borderRadius: 'var(--radius-container)',
diff --git a/apps/docsite/src/components/blog/BlogArticle.tsx b/apps/docsite/src/components/blog/BlogArticle.tsx
index 538f01a4bc..4cee1d128e 100644
--- a/apps/docsite/src/components/blog/BlogArticle.tsx
+++ b/apps/docsite/src/components/blog/BlogArticle.tsx
@@ -4,8 +4,8 @@
* @file BlogArticle.tsx
*
* Article layout matching the docs page typography: a centered, readable column
- * (maxWidth 800) with a breadcrumb trail (Blog / post type), a display-1 title,
- * large regular-weight dek, byline, a neutral cover placeholder, the prose body
+ * with a breadcrumb trail (Blog / post type), a display-1 title, large
+ * regular-weight dek, byline, a neutral cover placeholder, the prose body
* (rendered via Markdown), optional curated related-doc links, and a link back to
* the blog index. No sidebar.
*
@@ -29,6 +29,7 @@ import {ClickableCard} from '@xds/core/ClickableCard';
import type {BlogPost} from '../../lib/blog/schema';
import {POST_TYPE_LABELS} from '../../lib/blog/schema';
import {AuthorByline} from './AuthorByline';
+import {layout} from '../../layout.stylex';
const styles = stylex.create({
section: {
@@ -62,7 +63,7 @@ export interface BlogArticleProps {
export function BlogArticle({post}: BlogArticleProps) {
return (
- <Section maxWidth={800} padding={6} xstyle={styles.section}>
+ <Section maxWidth={layout.proseMaxWidth} padding={6} xstyle={styles.section}>
<VStack gap={10}>
{/* Header — matches the docs page treatment */}
<VStack gap={4}>
diff --git a/apps/docsite/src/components/docs/DocPageLayout.tsx b/apps/docsite/src/components/docs/DocPageLayout.tsx
index c8db08a0ed..39f802c52c 100644
--- a/apps/docsite/src/components/docs/DocPageLayout.tsx
+++ b/apps/docsite/src/components/docs/DocPageLayout.tsx
@@ -13,6 +13,8 @@ import {Text, Heading} from '@xds/core/Text';
import {VStack} from '@xds/core/Layout';
import {Section} from '@xds/core/Section';
import {Divider} from '@xds/core/Divider';
+import {layout} from '../../layout.stylex';
+
const styles = stylex.create({
section: {
marginInline: 'auto',
@@ -29,7 +31,7 @@ export function DocPageLayout({
children: ReactNode;
}) {
return (
- <Section maxWidth={800} padding={6} xstyle={styles.section}>
+ <Section maxWidth={layout.proseMaxWidth} padding={6} xstyle={styles.section}>
<VStack gap={10}>
<VStack gap={4}>
<Heading level={1} type="display-1">
diff --git a/apps/docsite/src/components/docs/ProseBlock.tsx b/apps/docsite/src/components/docs/ProseBlock.tsx
index 031213289b..6b86b44e98 100644
--- a/apps/docsite/src/components/docs/ProseBlock.tsx
+++ b/apps/docsite/src/components/docs/ProseBlock.tsx
@@ -5,9 +5,10 @@
import * as stylex from '@stylexjs/stylex';
import {Text} from '@xds/core/Text';
import {renderInlineCode} from './renderInlineCode';
+import {layout} from '../../layout.stylex';
const styles = stylex.create({
- prose: {maxWidth: 800},
+ prose: {maxWidth: layout.proseMaxWidth},
});
export function ProseBlock({text}: {text: string}) {
diff --git a/apps/docsite/src/layout.stylex.ts b/apps/docsite/src/layout.stylex.ts
new file mode 100644
index 0000000000..1477973b6b
--- /dev/null
+++ b/apps/docsite/src/layout.stylex.ts
@@ -0,0 +1,15 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import * as stylex from '@stylexjs/stylex';
+
+/**
+ * Shared content max-widths, defined as StyleX compile-time consts so the same
+ * values can be used inside `stylex.create` and as component props.
+ *
+ * - contentMaxWidth: wide content cap for showcase/landing/index sections
+ * - proseMaxWidth: reading-width cap for docs, blog, and prose content
+ */
+export const layout = stylex.defineConsts({
+ contentMaxWidth: '1200px',
+ proseMaxWidth: '800px',
+});