An open source design system that's fully customizable and agent ready
TypeScript
Improve Button docs page and block examples (#1554)
rubyycheung0ceab8b0ee55
diff --git a/packages/cli/templates/blocks/components/Button/ButtonLinkButton.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonLinkButton.doc.mjsdeleted file mode 100644index c4520e9518..0000000000--- a/packages/cli/templates/blocks/components/Button/ButtonLinkButton.doc.mjs+++ /dev/null@@ -1,10 +0,0 @@-/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */-export const doc = {- type: 'block',- name: 'Button — Link Buttons',- description:- 'Buttons rendering as anchor elements when an href prop is provided.',- isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['Button'],-};diff --git a/packages/cli/templates/blocks/components/Button/ButtonLinkButton.tsx b/packages/cli/templates/blocks/components/Button/ButtonLinkButton.tsxdeleted file mode 100644index 08cab8fe85..0000000000--- a/packages/cli/templates/blocks/components/Button/ButtonLinkButton.tsx+++ /dev/null@@ -1,27 +0,0 @@-'use client';--import {XDSButton} from '@xds/core/Button';--export default function ButtonLinkButton() {- return (- <div style={{display: 'flex', gap: 12, alignItems: 'center'}}>- <XDSButton- label="Visit Example"- href="https://example.com"- variant="primary"- />- <XDSButton- label="Open in new tab"- href="https://example.com"- target="_blank"- rel="noopener noreferrer"- variant="secondary"- />- <XDSButton- label="Ghost link"- href="https://example.com"- variant="ghost"- />- </div>- );-}diff --git a/packages/cli/templates/blocks/components/Button/ButtonLoading.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonLoading.doc.mjsdeleted file mode 100644index 61027a0a08..0000000000--- a/packages/cli/templates/blocks/components/Button/ButtonLoading.doc.mjs+++ /dev/null@@ -1,9 +0,0 @@-/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */-export const doc = {- type: 'block',- name: 'Button — Loading State',- description: 'Buttons in loading state across all four variants.',- isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['Button'],-};diff --git a/packages/cli/templates/blocks/components/Button/ButtonLoading.tsx b/packages/cli/templates/blocks/components/Button/ButtonLoading.tsxdeleted file mode 100644index 6d110b223b..0000000000--- a/packages/cli/templates/blocks/components/Button/ButtonLoading.tsx+++ /dev/null@@ -1,14 +0,0 @@-'use client';--import {XDSButton} from '@xds/core/Button';--export default function ButtonLoading() {- return (- <div style={{display: 'flex', gap: 12}}>- <XDSButton label="Loading..." variant="primary" isLoading />- <XDSButton label="Loading..." variant="secondary" isLoading />- <XDSButton label="Loading..." variant="ghost" isLoading />- <XDSButton label="Loading..." variant="destructive" isLoading />- </div>- );-}diff --git a/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.doc.mjsindex e9c1db1918..a9c1cc2b80 100644--- a/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.doc.mjs+++ b/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.doc.mjs@@ -1,9 +1,9 @@/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */export const doc = {type: 'block',- name: 'Button — Size Variants',- description: 'Primary buttons in small, medium, and large sizes side by side.',+ name: 'Button — Sizes',+ description: 'Small, medium, and large buttons side by side. Use small in dense UIs like toolbars, medium for most cases, and large for prominent CTAs.',isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['Button'],+ aspectRatio: 16 / 9,+ componentsUsed: ['Button', 'Layout', 'Text'],};diff --git a/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.tsx b/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.tsxindex 6940f17d2c..c73c744d82 100644--- a/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.tsx+++ b/packages/cli/templates/blocks/components/Button/ButtonSizeVariants.tsx@@ -1,13 +1,43 @@'use client';import {XDSButton} from '@xds/core/Button';+import {XDSStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';++const SIZES = [+ {size: 'sm' as const, label: 'Small'},+ {size: 'md' as const, label: 'Medium'},+ {size: 'lg' as const, label: 'Large'},+];export default function ButtonSizeVariants() {return (- <div style={{display: 'flex', gap: 12, alignItems: 'center'}}>- <XDSButton label="Small" variant="primary" size="sm" />- <XDSButton label="Medium" variant="primary" size="md" />- <XDSButton label="Large" variant="primary" size="lg" />- </div>+ <XDSStack direction="vertical" gap={4}>+ <XDSStack direction="vertical" gap={1}>+ <XDSText type="supporting" color="secondary">+ Primary+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ {SIZES.map(({size, label}) => (+ <XDSButton key={size} label={label} variant="primary" size={size} />+ ))}+ </XDSStack>+ </XDSStack>+ <XDSStack direction="vertical" gap={1}>+ <XDSText type="supporting" color="secondary">+ Secondary+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ {SIZES.map(({size, label}) => (+ <XDSButton+ key={size}+ label={label}+ variant="secondary"+ size={size}+ />+ ))}+ </XDSStack>+ </XDSStack>+ </XDSStack>);}diff --git a/packages/cli/templates/blocks/components/Button/ButtonVariants.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonVariants.doc.mjsnew file mode 100644index 0000000000..fbe2732fa9--- /dev/null+++ b/packages/cli/templates/blocks/components/Button/ButtonVariants.doc.mjs@@ -0,0 +1,9 @@+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */+export const doc = {+ type: 'block',+ name: 'Button — Variants',+ description: 'All 4 button variants in default, disabled, and loading states. Use primary for the main action, secondary for most others, ghost for low-emphasis, and destructive for dangerous actions.',+ isReady: true,+ aspectRatio: 16 / 9,+ componentsUsed: ['Button', 'Layout', 'Text'],+};diff --git a/packages/cli/templates/blocks/components/Button/ButtonVariants.tsx b/packages/cli/templates/blocks/components/Button/ButtonVariants.tsxnew file mode 100644index 0000000000..00e4742ff0--- /dev/null+++ b/packages/cli/templates/blocks/components/Button/ButtonVariants.tsx@@ -0,0 +1,59 @@+'use client';++import {XDSButton} from '@xds/core/Button';+import {XDSStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';++const VARIANTS = [+ {variant: 'primary' as const, label: 'Primary'},+ {variant: 'secondary' as const, label: 'Secondary'},+ {variant: 'ghost' as const, label: 'Ghost'},+ {variant: 'destructive' as const, label: 'Destructive'},+];++export default function ButtonVariants() {+ return (+ <XDSStack direction="vertical" gap={4}>+ <XDSStack direction="vertical" gap={1}>+ <XDSText type="supporting" color="secondary">+ Default+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ {VARIANTS.map(({variant, label}) => (+ <XDSButton key={variant} label={label} variant={variant} />+ ))}+ </XDSStack>+ </XDSStack>+ <XDSStack direction="vertical" gap={1}>+ <XDSText type="supporting" color="secondary">+ Disabled+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ {VARIANTS.map(({variant, label}) => (+ <XDSButton+ key={variant}+ label={label}+ variant={variant}+ isDisabled+ />+ ))}+ </XDSStack>+ </XDSStack>+ <XDSStack direction="vertical" gap={1}>+ <XDSText type="supporting" color="secondary">+ Loading+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ {VARIANTS.map(({variant, label}) => (+ <XDSButton+ key={variant}+ label={label}+ variant={variant}+ isLoading+ />+ ))}+ </XDSStack>+ </XDSStack>+ </XDSStack>+ );+}diff --git a/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.doc.mjsindex 96257b3cb8..17835c5f04 100644--- a/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.doc.mjs+++ b/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.doc.mjs@@ -1,9 +1,9 @@/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */export const doc = {type: 'block',- name: 'Button — With Badge End Slot',- description: 'Buttons with badge components rendered in the end slot.',+ name: 'Button — End Slot',+ description: 'Buttons with a trailing badge showing a count or status. Use for notification counts, unread messages, or any button that needs a visual indicator.',isReady: true,- aspectRatio: 4 / 3,- componentsUsed: ['Button', 'Badge'],+ aspectRatio: 16 / 9,+ componentsUsed: ['Button', 'Badge', 'Layout', 'Text'],};diff --git a/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.tsx b/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.tsxindex ee0b538bd1..2d70f47bc9 100644--- a/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.tsx+++ b/packages/cli/templates/blocks/components/Button/ButtonWithEndSlot.tsx@@ -2,20 +2,32 @@import {XDSButton} from '@xds/core/Button';import {XDSBadge} from '@xds/core/Badge';+import {XDSStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';export default function ButtonWithEndSlot() {return (- <div style={{display: 'flex', gap: 12, alignItems: 'center'}}>- <XDSButton- label="Messages"- variant="primary"- endContent={<XDSBadge variant="info" label={3} />}- />- <XDSButton- label="Notifications"- variant="secondary"- endContent={<XDSBadge variant="neutral" label="New" />}- />- </div>+ <XDSStack direction="vertical" gap={4}>+ <XDSText type="supporting" color="secondary">+ Trailing badges for counts or status+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ <XDSButton+ label="Messages"+ variant="primary"+ endContent={<XDSBadge variant="info" label={3} />}+ />+ <XDSButton+ label="Notifications"+ variant="secondary"+ endContent={<XDSBadge variant="warning" label={12} />}+ />+ <XDSButton+ label="Updates"+ variant="ghost"+ endContent={<XDSBadge variant="neutral" label="New" />}+ />+ </XDSStack>+ </XDSStack>);}diff --git a/packages/cli/templates/blocks/components/Button/ButtonWithIcon.doc.mjs b/packages/cli/templates/blocks/components/Button/ButtonWithIcon.doc.mjsnew file mode 100644index 0000000000..d4d276ad7c--- /dev/null+++ b/packages/cli/templates/blocks/components/Button/ButtonWithIcon.doc.mjs@@ -0,0 +1,9 @@+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */+export const doc = {+ type: 'block',+ name: 'Button — Icon',+ description: 'Buttons with a leading icon that reinforces the label. Use when the icon helps the user identify the action faster, like a plus for "New" or a trash can for "Delete".',+ isReady: true,+ aspectRatio: 16 / 9,+ componentsUsed: ['Button', 'Icon', 'Layout'],+};diff --git a/packages/cli/templates/blocks/components/Button/ButtonWithIcon.tsx b/packages/cli/templates/blocks/components/Button/ButtonWithIcon.tsxnew file mode 100644index 0000000000..897e790cd6--- /dev/null+++ b/packages/cli/templates/blocks/components/Button/ButtonWithIcon.tsx@@ -0,0 +1,44 @@+'use client';++import {XDSButton} from '@xds/core/Button';+import {XDSIcon} from '@xds/core/Icon';+import {XDSStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';+import {+ ArrowDownTrayIcon,+ PencilSquareIcon,+ PlusIcon,+ TrashIcon,+} from '@heroicons/react/24/outline';++export default function ButtonWithIcon() {+ return (+ <XDSStack direction="vertical" gap={4}>+ <XDSText type="supporting" color="secondary">+ Icons reinforce the action+ </XDSText>+ <XDSStack direction="horizontal" gap={3} vAlign="center">+ <XDSButton+ label="New item"+ variant="primary"+ icon={<XDSIcon icon={PlusIcon} />}+ />+ <XDSButton+ label="Edit"+ variant="secondary"+ icon={<XDSIcon icon={PencilSquareIcon} />}+ />+ <XDSButton+ label="Download"+ variant="ghost"+ icon={<XDSIcon icon={ArrowDownTrayIcon} />}+ />+ <XDSButton+ label="Delete"+ variant="destructive"+ icon={<XDSIcon icon={TrashIcon} />}+ />+ </XDSStack>+ </XDSStack>+ );+}diff --git a/packages/core/src/Button/Button.doc.mjs b/packages/core/src/Button/Button.doc.mjsindex 0dabd27cec..9fa1740d11 100644--- a/packages/core/src/Button/Button.doc.mjs+++ b/packages/core/src/Button/Button.doc.mjs@@ -7,18 +7,21 @@ export const docs = {usage: {description:- 'Buttons provide visual cues for actions and events. These fundamental components allow users to commit actions and navigate a page flow. Use a Button when a user needs to submit a form, start a new task or action, or trigger a new UI element to appear on the page.',+ 'Button triggers an action when clicked. Use it for form submissions, confirmations, navigation, or any interaction that needs a clear call to action.',bestPractices: [- {guidance: true, description: 'Use secondary for most actions and reserve primary for a single emphasized action per layout.'},- {guidance: true, description: 'Include a clear, concise label that describes the action the button performs.'},+ {guidance: true, description: 'Reserve primary for the single most important action in the view. Use secondary or ghost for everything else based on emphasis.'},+ {guidance: true, description: 'Write labels that describe the action — "Save changes", "Delete account", "Send invite" — not vague labels like "OK" or "Click here".'},+ {guidance: true, description: 'Show a loading state for actions that take time, like saving or submitting, so the user knows it is working.'},+ {guidance: true, description: 'Always provide a label for icon-only buttons so screen readers can announce what the button does. Add a tooltip for sighted users.'},{guidance: false, description: 'Place more than one primary button in the same view — this dilutes the visual hierarchy.'},- {guidance: false, description: 'Use the destructive variant without a confirmation step for irreversible actions.'},+ {guidance: false, description: 'Use the destructive variant without a confirmation step for irreversible actions like deleting data.'},+ {guidance: false, description: 'Use a button for navigation — if it only takes the user to another page, use a link instead. Buttons are for actions like saving, deleting, or submitting.'},],anatomy: [- {name: 'Icon', required: false, description: 'A leading icon that visually represents the meaning of the button label.'},- {name: 'Label', required: true, description: 'A text label describing the button action. Required for accessibility.'},- {name: 'End content', required: false, description: 'Trailing content that provides affordance to the type of action performed. Recommended when the expected action is non-obvious.'},- {name: 'Spinner', required: false, description: 'Indicates a loading state when the button action is not immediate.'},+ {name: 'Icon', required: false, description: 'A leading icon that reinforces the label, like a trash icon on a Delete button.'},+ {name: 'Label', required: true, description: 'The visible text describing the action. Also used as the accessible name.'},+ {name: 'End content', required: false, description: 'A trailing badge or icon after the label, like a notification count or dropdown arrow.'},+ {name: 'Spinner', required: false, description: 'Replaces the icon during loading to show the action is in progress.'},],},@@ -140,18 +143,21 @@ export const docsZh = {name: 'Button',usage: {description:- 'Buttons provide visual cues for actions and events. These fundamental components allow users to commit actions and navigate a page flow. Use a Button when a user needs to submit a form, start a new task or action, or trigger a new UI element to appear on the page.',+ 'Button triggers an action when clicked. Use it for form submissions, confirmations, navigation, or any interaction that needs a clear call to action.',bestPractices: [- {guidance: true, description: 'Use secondary for most actions and reserve primary for a single emphasized action per layout.'},- {guidance: true, description: 'Include a clear, concise label that describes the action the button performs.'},+ {guidance: true, description: 'Reserve primary for the single most important action in the view. Use secondary or ghost for everything else based on emphasis.'},+ {guidance: true, description: 'Write labels that describe the action — "Save changes", "Delete account", "Send invite" — not vague labels like "OK" or "Click here".'},+ {guidance: true, description: 'Show a loading state for actions that take time, like saving or submitting, so the user knows it is working.'},+ {guidance: true, description: 'Always provide a label for icon-only buttons so screen readers can announce what the button does. Add a tooltip for sighted users.'},{guidance: false, description: 'Place more than one primary button in the same view — this dilutes the visual hierarchy.'},- {guidance: false, description: 'Use the destructive variant without a confirmation step for irreversible actions.'},+ {guidance: false, description: 'Use the destructive variant without a confirmation step for irreversible actions like deleting data.'},+ {guidance: false, description: 'Use a button for navigation — if it only takes the user to another page, use a link instead. Buttons are for actions like saving, deleting, or submitting.'},],anatomy: [- {name: 'Icon', required: false, description: 'A leading icon that visually represents the meaning of the button label.'},- {name: 'Label', required: true, description: 'A text label describing the button action. Required for accessibility.'},- {name: 'End content', required: false, description: 'Trailing content that provides affordance to the type of action performed. Recommended when the expected action is non-obvious.'},- {name: 'Spinner', required: false, description: 'Indicates a loading state when the button action is not immediate.'},+ {name: 'Icon', required: false, description: 'A leading icon that reinforces the label, like a trash icon on a Delete button.'},+ {name: 'Label', required: true, description: 'The visible text describing the action. Also used as the accessible name.'},+ {name: 'End content', required: false, description: 'A trailing badge or icon after the label, like a notification count or dropdown arrow.'},+ {name: 'Spinner', required: false, description: 'Replaces the icon during loading to show the action is in progress.'},],},props: [@@ -215,21 +221,18 @@ export const docsZh = {/** @type {import('../docs-types').TranslationDoc} */export const docsDense = {- description: 'button w/ multiple variants, sizes, loading state',+ description: 'action trigger w/ 4 variants, 3 sizes, loading state',usage: {description:- 'Buttons provide visual cues for actions and events. These fundamental components allow users to commit actions and navigate a page flow. Use a Button when a user needs to submit a form, start a new task or action, or trigger a new UI element to appear on the page.',+ 'Button triggers an action when clicked. Use for form submissions, confirmations, navigation, or any interaction needing a clear CTA.',bestPractices: [- {guidance: true, description: 'Use secondary for most actions and reserve primary for a single emphasized action per layout.'},- {guidance: true, description: 'Include a clear, concise label that describes the action the button performs.'},- {guidance: false, description: 'Place more than one primary button in the same view — this dilutes the visual hierarchy.'},- {guidance: false, description: 'Use the destructive variant without a confirmation step for irreversible actions.'},- ],- anatomy: [- {name: 'Icon', required: false, description: 'A leading icon that visually represents the meaning of the button label.'},- {name: 'Label', required: true, description: 'A text label describing the button action. Required for accessibility.'},- {name: 'End content', required: false, description: 'Trailing content that provides affordance to the type of action performed. Recommended when the expected action is non-obvious.'},- {name: 'Spinner', required: false, description: 'Indicates a loading state when the button action is not immediate.'},+ {guidance: true, description: 'Primary for the single most important action. Secondary or ghost for the rest.'},+ {guidance: true, description: 'Labels that describe the action — "Save changes" not "OK" or "Click here".'},+ {guidance: true, description: 'Show loading state for async actions so the user knows it is working.'},+ {guidance: true, description: 'Icon-only buttons need a label for screen readers and a tooltip for sighted users.'},+ {guidance: false, description: 'Multiple primary buttons in one view — dilutes hierarchy.'},+ {guidance: false, description: 'Destructive without confirmation for irreversible actions.'},+ {guidance: false, description: 'Button for navigation — use a link if it only takes the user to another page.'},],},propDescriptions: {