Skip to content

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

TypeScript

refactor(templates): rework payment-form for XDS purity + reliability (#2606)

rubyycheung98ea440fe3f0
diff --git a/apps/docsite/public/template-assets/google-pay-logo-dark.svg b/apps/docsite/public/template-assets/google-pay-logo-dark.svg
new file mode 100644
index 0000000000..897983550c
--- /dev/null
+++ b/apps/docsite/public/template-assets/google-pay-logo-dark.svg
@@ -0,0 +1 @@
+<svg width="41" height="17" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path d="M19.526 2.635v4.083h2.518c.6 0 1.096-.202 1.488-.605.403-.402.605-.882.605-1.437 0-.544-.202-1.018-.605-1.422-.392-.413-.888-.62-1.488-.62h-2.518zm0 5.52v4.736h-1.504V1.198h3.99c1.013 0 1.873.337 2.582 1.012.72.675 1.08 1.497 1.08 2.466 0 .991-.36 1.819-1.08 2.482-.697.665-1.559.996-2.583.996h-2.485v.001zm7.668 2.287c0 .392.166.718.499.98.332.26.722.391 1.168.391.633 0 1.196-.234 1.692-.701.497-.469.744-1.019.744-1.65-.469-.37-1.123-.555-1.962-.555-.61 0-1.12.148-1.528.442-.409.294-.613.657-.613 1.093m1.946-5.815c1.112 0 1.989.297 2.633.89.642.594.964 1.408.964 2.442v4.932h-1.439v-1.11h-.065c-.622.914-1.45 1.372-2.486 1.372-.882 0-1.621-.262-2.215-.784-.594-.523-.891-1.176-.891-1.96 0-.828.313-1.486.94-1.976s1.463-.735 2.51-.735c.892 0 1.629.163 2.206.49v-.344c0-.522-.207-.966-.621-1.33a2.132 2.132 0 0 0-1.455-.547c-.84 0-1.504.353-1.995 1.062l-1.324-.834c.73-1.045 1.81-1.568 3.238-1.568m11.853.262l-5.02 11.53H34.42l1.864-4.034-3.302-7.496h1.635l2.387 5.749h.032l2.322-5.75z" fill="#FFF"/><path d="M13.448 7.134c0-.473-.04-.93-.116-1.366H6.988v2.588h3.634a3.11 3.11 0 0 1-1.344 2.042v1.68h2.169c1.27-1.17 2.001-2.9 2.001-4.944" fill="#4285F4"/><path d="M6.988 13.7c1.816 0 3.344-.595 4.459-1.621l-2.169-1.681c-.603.406-1.38.643-2.29.643-1.754 0-3.244-1.182-3.776-2.774H.978v1.731a6.728 6.728 0 0 0 6.01 3.703" fill="#34A853"/><path d="M3.212 8.267a4.034 4.034 0 0 1 0-2.572V3.964H.978A6.678 6.678 0 0 0 .261 6.98c0 1.085.26 2.11.717 3.017l2.234-1.731z" fill="#FABB05"/><path d="M6.988 2.921c.992 0 1.88.34 2.58 1.008v.001l1.92-1.918C10.324.928 8.804.262 6.989.262a6.728 6.728 0 0 0-6.01 3.702l2.234 1.731c.532-1.592 2.022-2.774 3.776-2.774" fill="#E94235"/></g></svg>
\ No newline at end of file
diff --git a/packages/cli/templates/pages/payment-form/beagle.png b/packages/cli/templates/pages/payment-form/beagle.png
deleted file mode 100644
index 1f3567d2ca..0000000000
Binary files a/packages/cli/templates/pages/payment-form/beagle.png and /dev/null differ
diff --git a/packages/cli/templates/pages/payment-form/page.tsx b/packages/cli/templates/pages/payment-form/page.tsx
index e5d867cd56..beb49ca0c4 100644
--- a/packages/cli/templates/pages/payment-form/page.tsx
+++ b/packages/cli/templates/pages/payment-form/page.tsx
@@ -20,11 +20,9 @@ import {XDSSelector} from '@xds/core/Selector';
import {XDSCheckboxInput} from '@xds/core/CheckboxInput';
import {XDSRadioList, XDSRadioListItem} from '@xds/core/RadioList';
import {XDSLink} from '@xds/core/Link';
-import pinkTeddyImg from './pink-teddy.png';
-import redHeartImg from './red-heart.png';
-import beagleImg from './beagle.png';
import {XDSTextArea} from '@xds/core/TextArea';
import {XDSDivider} from '@xds/core/Divider';
+import {XDSBanner} from '@xds/core/Banner';
import {XDSCard} from '@xds/core/Card';
import {XDSCollapsible} from '@xds/core/Collapsible';
import {XDSBadge} from '@xds/core/Badge';
@@ -32,17 +30,17 @@ import {XDSNumberInput} from '@xds/core/NumberInput';
import {useMediaQuery} from '@xds/core/hooks';
import {XDSSection} from '@xds/core/Section';
import {XDSCenter} from '@xds/core/Center';
-import {XDSAspectRatio} from '@xds/core/AspectRatio';
+import {XDSThumbnail} from '@xds/core/Thumbnail';
import {XDSIcon} from '@xds/core/Icon';
import {ShieldCheckIcon} from '@heroicons/react/24/outline';
import {LockClosedIcon} from '@heroicons/react/24/outline';
import {CheckCircleIcon} from '@heroicons/react/24/outline';
-import {ArrowRightIcon} from '@heroicons/react/24/outline';
import {TruckIcon} from '@heroicons/react/24/outline';
import {
colorVars,
spacingVars,
radiusVars,
+ borderVars,
} from '@xds/core/theme/tokens.stylex';
// ── Constants ─────────────────────────────────────────────────────────────────
@@ -116,33 +114,35 @@ const US_STATES = [
'Wyoming',
];
+// Product photos from the local template-assets set (committed to the
+// docsite; the CLI swaps these for an inline placeholder on scaffold).
const ITEM_IMAGES: Record<string, {src: string}> = {
- '1': pinkTeddyImg,
- '2': redHeartImg,
- '3': beagleImg,
+ '1': {src: '/template-assets/light-product-1.png'},
+ '2': {src: '/template-assets/light-product-4.png'},
+ '3': {src: '/template-assets/light-product-5.png'},
};
const ORDER_ITEMS = [
{
id: '1',
- name: 'Pink Teddy Keychain',
- variant: 'Soft plush keychain · One size',
- price: 75,
+ name: 'Speckled Stoneware Mug',
+ variant: 'Hand-thrown · 12 oz',
+ price: 78,
qty: 1,
limited: false,
},
{
id: '2',
- name: 'Red Heart Keychain',
- variant: 'Velvet finish · One size',
- price: 75,
+ name: 'Stoneware Dinner Plate',
+ variant: 'Reactive glaze · 10 in',
+ price: 72,
qty: 1,
limited: false,
},
{
id: '3',
- name: 'Beagle Keychain',
- variant: 'Cotton handmade · One size',
+ name: 'Cereal Bowl',
+ variant: 'Speckled clay · 6 in',
price: 80,
qty: 1,
limited: true,
@@ -159,27 +159,46 @@ const fmt = (n: number) => `$${n.toFixed(2)}`;
const styles = stylex.create({
fullWidth: {width: '100%'},
- orderThumb: {
- width: spacingVars['--spacing-12'],
- height: spacingVars['--spacing-12'],
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-neutral'],
- flexShrink: 0,
- overflow: 'hidden',
- },
- freeBanner: {
- backgroundColor: colorVars['--color-background-blue'],
- borderRadius: radiusVars['--radius-element'],
- padding: spacingVars['--spacing-3'],
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-2'],
+ // XDSLayoutContent clips overflow by default, which traps position:sticky
+ // children (the sticky order summary). With height="auto" the page scrolls
+ // at the window, so let overflow be visible here so sticky can pin.
+ visibleOverflow: {overflow: 'visible'},
+ // Form column flex-basis so the two checkout columns share width evenly.
+ formColBasis: {flexBasis: 0},
+ // Space the Order Summary content below its collapsible trigger title.
+ summaryContent: {paddingBlockStart: spacingVars['--spacing-2']},
+ // Order-summary column: sticky beside the form on desktop.
+ summarySticky: {
+ flexBasis: 0,
+ position: 'sticky',
+ top: spacingVars['--spacing-4'],
+ alignSelf: 'flex-start',
},
- headerArea: {
- marginBottom: spacingVars['--spacing-6'],
+ // On mobile the summary moves above the form.
+ summaryMobileOrder: {order: -1},
+ // Express-checkout brand buttons (fixed brand colors).
+ paypalButton: {backgroundColor: '#FFC439', borderColor: '#FFC439'},
+ // Official Google Pay dark button: black background with the unaltered
+ // dark-variant mark (white "Google Pay" text + full-color G), per the
+ // Google Pay brand guidelines.
+ gpayButton: {backgroundColor: '#000', borderColor: '#000'},
+ // Brand logos inside the express-checkout buttons.
+ paypalLogo: {height: spacingVars['--spacing-5'], width: 'auto'},
+ // Unaltered Google Pay mark (no filter/recolor — brand requirement),
+ // sized so it keeps comfortable clear space inside the lg button.
+ gpayLogo: {
+ height: spacingVars['--spacing-5'],
+ width: 'auto',
},
- dividerWrap: {
- marginTop: spacingVars['--spacing-6'],
+ // Accepted card-network marks (Visa/Mastercard/Amex), shared style.
+ cardLogo: {
+ height: spacingVars['--spacing-7'],
+ width: 'auto',
+ borderRadius: radiusVars['--radius-element'],
+ borderWidth: borderVars['--border-width'],
+ borderStyle: 'solid',
+ borderColor: colorVars['--color-border'],
+ backgroundColor: colorVars['--color-background-surface'],
},
});
@@ -259,7 +278,7 @@ export default function PaymentFormPage() {
<XDSLayout
height="auto"
content={
- <XDSLayoutContent padding={0}>
+ <XDSLayoutContent padding={0} xstyle={styles.visibleOverflow}>
<XDSCenter axis="horizontal">
<XDSSection
variant="transparent"
@@ -268,17 +287,17 @@ export default function PaymentFormPage() {
padding={6}>
<XDSVStack gap={5}>
{/* Page header */}
- <XDSVStack gap={2} {...stylex.props(styles.headerArea)}>
- <XDSText type="display-1" as="h1">
- Payment Request
- </XDSText>
- <XDSText type="body" color="secondary">
- Review your order and complete your purchase. All
- transactions are secured with 256-bit SSL encryption.
- </XDSText>
- <div {...stylex.props(styles.dividerWrap)}>
- <XDSDivider />
- </div>
+ <XDSVStack gap={6}>
+ <XDSVStack gap={2}>
+ <XDSText type="display-1" as="h1">
+ Payment Request
+ </XDSText>
+ <XDSText type="body" color="secondary">
+ Review your order and complete your purchase. All
+ transactions are secured with 256-bit SSL encryption.
+ </XDSText>
+ </XDSVStack>
+ <XDSDivider />
</XDSVStack>
<XDSStack
@@ -287,7 +306,7 @@ export default function PaymentFormPage() {
vAlign="start">
<XDSStackItem
size="fill"
- style={{flexBasis: isMobile ? undefined : 0}}>
+ xstyle={isMobile ? undefined : styles.formColBasis}>
<XDSVStack gap={8}>
{/* Sign in */}
<XDSVStack gap={1}>
@@ -488,36 +507,26 @@ export default function PaymentFormPage() {
<XDSButton
label="PayPal"
variant="primary"
- size="sm"
+ size="lg"
onClick={() => {}}
- style={{
- backgroundColor: '#FFC439',
- borderColor: '#FFC439',
- }}>
+ xstyle={styles.paypalButton}>
<img
src="/template-assets/paypal-logo.png"
alt="PayPal"
- style={{height: 20, width: 'auto'}}
+ {...stylex.props(styles.paypalLogo)}
/>
</XDSButton>
{/* Google Pay */}
<XDSButton
label="Google Pay"
variant="primary"
- size="sm"
+ size="lg"
onClick={() => {}}
- style={{
- backgroundColor: '#000',
- borderColor: '#000',
- }}>
+ xstyle={styles.gpayButton}>
<img
- src="/template-assets/google-pay-logo.svg"
+ src="/template-assets/google-pay-logo-dark.svg"
alt="Google Pay"
- style={{
- height: 22,
- width: 'auto',
- filter: 'brightness(0) invert(1)',
- }}
+ {...stylex.props(styles.gpayLogo)}
/>
</XDSButton>
</XDSGrid>
@@ -543,41 +552,17 @@ export default function PaymentFormPage() {
<img
src="/template-assets/visa.svg"
alt="Visa"
- style={{
- height: 'var(--spacing-7)',
- width: 'auto',
- borderRadius: 'var(--radius-element)',
- border:
- 'var(--border-width) solid var(--color-border)',
- backgroundColor:
- 'var(--color-background-surface)',
- }}
+ {...stylex.props(styles.cardLogo)}
/>
<img
src="/template-assets/mastercard.svg"
alt="Mastercard"
- style={{
- height: 'var(--spacing-7)',
- width: 'auto',
- borderRadius: 'var(--radius-element)',
- border:
- 'var(--border-width) solid var(--color-border)',
- backgroundColor:
- 'var(--color-background-surface)',
- }}
+ {...stylex.props(styles.cardLogo)}
/>
<img
src="/template-assets/amex.svg"
alt="Amex"
- style={{
- height: 'var(--spacing-7)',
- width: 'auto',
- borderRadius: 'var(--radius-element)',
- border:
- 'var(--border-width) solid var(--color-border)',
- backgroundColor:
- 'var(--color-background-surface)',
- }}
+ {...stylex.props(styles.cardLogo)}
/>
</XDSHStack>
<XDSTextInput
@@ -726,15 +711,17 @@ export default function PaymentFormPage() {
Promo Code
</XDSText>
<XDSHStack gap={2} vAlign="center">
- <XDSTextInput
- size="lg"
- label="Promo code"
- isLabelHidden
- placeholder="Enter promo code"
- value={promo}
- onChange={setPromo}
- xstyle={styles.fullWidth}
- />
+ <XDSStackItem size="fill">
+ <XDSTextInput
+ size="lg"
+ label="Promo code"
+ isLabelHidden
+ placeholder="Enter promo code"
+ value={promo}
+ onChange={setPromo}
+ xstyle={styles.fullWidth}
+ />
+ </XDSStackItem>
<XDSButton
label="Apply"
variant="secondary"
@@ -826,16 +813,9 @@ export default function PaymentFormPage() {
size="lg"
xstyle={styles.fullWidth}
onClick={() => setSubmitted(true)}
- endContent={
- <XDSIcon
- icon={ArrowRightIcon}
- size="sm"
- color="inherit"
- />
- }
/>
<XDSButton
- label="← Continue Shopping"
+ label="Continue Shopping"
variant="secondary"
size="lg"
xstyle={styles.fullWidth}
@@ -863,15 +843,10 @@ export default function PaymentFormPage() {
<XDSStackItem
size="fill"
- style={
+ xstyle={
isMobile
- ? {order: -1}
- : {
- flexBasis: 0,
- position: 'sticky',
- top: 16,
- alignSelf: 'flex-start',
- }
+ ? styles.summaryMobileOrder
+ : styles.summarySticky
}>
<XDSCard padding={5}>
<XDSVStack gap={4}>
@@ -879,27 +854,15 @@ export default function PaymentFormPage() {
<XDSCollapsible
trigger="Order Summary"
defaultIsOpen={true}>
- <XDSVStack gap={4}>
+ <XDSVStack gap={4} xstyle={styles.summaryContent}>
{/* Line items */}
{ORDER_ITEMS.map(item => (
<XDSVStack key={item.id} gap={3}>
<XDSHStack gap={3} vAlign="start">
- {/* Placeholder thumbnail */}
- <div {...stylex.props(styles.orderThumb)}>
- <XDSAspectRatio ratio={1}>
- <img
- src={
- (
- ITEM_IMAGES[item.id] as {
- src: string;
- }
- ).src
- }
- alt={item.name}
- style={{objectFit: 'cover'}}
- />
- </XDSAspectRatio>
- </div>
+ <XDSThumbnail
+ src={ITEM_IMAGES[item.id].src}
+ alt={item.name}
+ />
<XDSStackItem size="fill">
<XDSVStack gap={1}>
<XDSHStack
@@ -1003,16 +966,11 @@ export default function PaymentFormPage() {
)}
</XDSText>
</XDSHStack>
- <div {...stylex.props(styles.freeBanner)}>
- <XDSIcon
- icon={TruckIcon}
- size="sm"
- color="primary"
- />
- <XDSText type="supporting">
- Free shipping on orders over $300
- </XDSText>
- </div>
+ <XDSBanner
+ status="info"
+ icon={<XDSIcon icon={TruckIcon} size="sm" />}
+ title="Free shipping on orders over $300"
+ />
</XDSVStack>
</XDSVStack>
</XDSCollapsible>
diff --git a/packages/cli/templates/pages/payment-form/payment-form-responsive.css b/packages/cli/templates/pages/payment-form/payment-form-responsive.css
deleted file mode 100644
index 4b431ca8e5..0000000000
--- a/packages/cli/templates/pages/payment-form/payment-form-responsive.css
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (c) Meta Platforms, Inc. and affiliates. */
-
-/* Payment Form — responsive layout */
-
-/* Prevent layout shift when scrollbar appears/disappears (e.g. accordion toggle) */
-html {
- scrollbar-gutter: stable;
-}
-
-/* Mobile only: single column, order summary on top */
-@media (max-width: 767px) {
- .pf-body {
- flex-direction: column !important;
- }
- .pf-body > * {
- flex: 1 1 100% !important;
- width: 100% !important;
- min-width: 0 !important;
- position: static !important;
- }
- .pf-right {
- order: -1;
- }
-}
diff --git a/packages/cli/templates/pages/payment-form/payment-form.css b/packages/cli/templates/pages/payment-form/payment-form.css
deleted file mode 100644
index e73ab7bbb6..0000000000
--- a/packages/cli/templates/pages/payment-form/payment-form.css
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright (c) Meta Platforms, Inc. and affiliates. */
-
-/* Prevent layout shift when scrollbar appears/disappears (e.g. accordion toggle) */
-html {
- scrollbar-gutter: stable;
-}
-
-.pf-page {
- min-height: 100svh;
- background-color: var(--color-background-surface);
- display: flex;
- justify-content: center;
- padding: 48px 32px;
-}
-
-.pf-inner {
- max-width: 1100px;
- width: 100%;
- display: flex;
- flex-direction: column;
- gap: 40px;
-}
-
-/* Header */
-.pf-heading {
- font-size: 40px;
- font-weight: 700;
- line-height: 1.1;
- letter-spacing: -0.02em;
- margin: 0;
-}
-
-/* Two-column body — layout handled by XDSHStack, this class is for responsive targeting only */
-.pf-body {
-}
-
-/* Left column */
-.pf-form {
- display: flex;
- flex-direction: column;
- gap: 32px;
-}
-
-.pf-section {
- display: flex;
- flex-direction: column;
- gap: 16px;
-}
-
-.pf-section-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
-}
-
-.pf-section-title {
- font-size: 18px;
- font-weight: 700;
- line-height: 1.3;
- margin: 0;
-}
-
-.pf-inline {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 12px;
-}
-
-.pf-inline-3 {
- display: grid;
- grid-template-columns: 1fr 1fr 1fr;
- gap: 12px;
-}
-
-/* Right column — sticky order summary */
-.pf-summary {
- position: sticky;
- top: 32px;
- background-color: var(--color-background-muted);
- border-radius: 12px;
- padding: 24px;
- display: flex;
- flex-direction: column;
- gap: 16px;
-}
-
-.pf-order-item {
- display: grid;
- grid-template-columns: auto 1fr auto;
- gap: 12px;
- align-items: start;
-}
-
-.pf-order-thumb {
- width: 56px;
- height: 56px;
- border-radius: 8px;
- background-color: var(--color-neutral);
- position: relative;
- flex-shrink: 0;
-}
-
-.pf-qty-badge {
- position: absolute;
- top: -6px;
- right: -6px;
-}
-
-.pf-summary-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
-}
-
-.pf-total-row {
- display: flex;
- justify-content: space-between;
- align-items: baseline;
-}
-
-.pf-or-divider {
- display: flex;
- align-items: center;
- gap: 12px;
-}
-
-.pf-or-line {
- flex: 1;
- height: 1px;
- background-color: var(--color-border);
-}
-
-.pf-secure-note {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 6px;
-}
-
-@media (max-width: 820px) {
- .pf-body {
- grid-template-columns: 1fr;
- }
- .pf-summary {
- position: static;
- order: -1;
- }
- .pf-page {
- padding: 24px 16px;
- }
-}
diff --git a/packages/cli/templates/pages/payment-form/pink-teddy.png b/packages/cli/templates/pages/payment-form/pink-teddy.png
deleted file mode 100644
index 1277b479aa..0000000000
Binary files a/packages/cli/templates/pages/payment-form/pink-teddy.png and /dev/null differ
diff --git a/packages/cli/templates/pages/payment-form/red-heart.png b/packages/cli/templates/pages/payment-form/red-heart.png
deleted file mode 100644
index bf52531196..0000000000
Binary files a/packages/cli/templates/pages/payment-form/red-heart.png and /dev/null differ
diff --git a/packages/cli/templates/pages/payment-form/venmo-logo.svg b/packages/cli/templates/pages/payment-form/venmo-logo.svg
deleted file mode 100644
index 9049144fc5..0000000000
--- a/packages/cli/templates/pages/payment-form/venmo-logo.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Venmo</title><path d="M21.772 13.119c-.267 0-.381-.251-.38-.655 0-.533.121-1.575.712-1.575.267 0 .357.243.357.598 0 .533-.13 1.632-.689 1.632Zm.502-3.377c-1.677 0-2.405 1.285-2.405 2.658 0 1.042.421 1.874 1.693 1.874 1.717 0 2.438-1.406 2.438-2.763 0-1.025-.462-1.769-1.726-1.769Zm-3.833 0c-.558 0-.964.17-1.393.477-.154-.275-.462-.477-.932-.477-.542 0-.947.219-1.247.437l-.04-.364H13.54l-.688 4.354h1.506l.479-3.053c.129-.065.323-.154.518-.154.145 0 .267.049.267.267 0 .056-.016.145-.024.218l-.429 2.722h1.498l.478-3.053c.138-.073.324-.154.51-.154.146 0 .268.049.268.267 0 .056-.017.145-.025.218l-.429 2.722h1.499l.461-2.908c.025-.153.049-.388.049-.549 0-.582-.267-.97-1.037-.97Zm-6.871 0c-.575 0-.98.219-1.287.421l-.017-.348H8.962l-.689 4.354H9.78l.478-3.053c.13-.065.324-.154.518-.154.147 0 .268.049.268.242 0 .081-.024.227-.032.299l-.422 2.666h1.499l.462-2.908c.024-.153.049-.388.049-.549 0-.582-.268-.97-1.03-.97Zm-5.631 1.834c.041-.485.413-.824.697-.824.162 0 .299.097.299.291 0 .404-.713.533-.996.533Zm.843-1.834c-1.604 0-2.382 1.39-2.382 2.698 0 1.01.478 1.817 1.814 1.817.527 0 1.07-.113 1.418-.282l.186-1.26c-.494.25-.874.347-1.271.347-.365 0-.64-.194-.64-.687.826-.008 2.252-.347 2.252-1.453 0-.687-.494-1.18-1.377-1.18Zm-4.239.267c.089.186.146.412.146.743 0 .606-.429 1.494-.777 2.06l-.373-2.989L0 9.969l.705 4.2h1.757c.77-1.01 1.718-2.448 1.718-3.554 0-.347-.073-.622-.235-.889l-1.402.283Z"/></svg>
\ No newline at end of file