An open source design system that's fully customizable and agent ready
TypeScript
docs(Button): add icon-only button examples and guidance (#227)
Cindy Zhangc22ece175396
diff --git a/packages/core/src/Button/README.md b/packages/core/src/Button/README.mdindex 4b80d07a93..a9b084ee70 100644--- a/packages/core/src/Button/README.md+++ b/packages/core/src/Button/README.md@@ -28,8 +28,30 @@ import { XDSButton } from '@xds/core/Button';// Destructive action<XDSButton label="Delete" variant="destructive" />++// Icon-only button (renders as a square)+// Pass `icon` without `children` β `label` becomes the aria-label+<XDSButton label="Settings" icon={<GearIcon />} variant="ghost" />++// Icon-only with emoji or text content+<XDSButton label="Select rocket emoji" icon={<span>π</span>} variant="ghost" size="sm" />++// Icon + visible label (pass children to show text alongside icon)+<XDSButton label="Edit" icon={<PencilIcon />}>Edit</XDSButton>```+### Icon-Only Buttons++When `icon` is provided without `children`, the button becomes **icon-only**:++- Renders as a perfect square (`aspectRatio: 1/1`)+- `label` is used as `aria-label` for accessibility (not rendered visually)+- Works with any `ReactNode` as the icon β SVG components, emoji, or text++Use icon-only buttons for toolbars, action grids, compact controls, and anywhere+you need a small clickable element. Always prefer `XDSButton` over `<div onClick>`+or `<span onClick>` for accessibility (keyboard navigation, focus management, screen readers).+## Props| Prop | Type | Default | Description |diff --git a/packages/core/src/Button/XDSButton.tsx b/packages/core/src/Button/XDSButton.tsxindex 1e271af2a7..2b88326f96 100644--- a/packages/core/src/Button/XDSButton.tsx+++ b/packages/core/src/Button/XDSButton.tsx@@ -256,7 +256,13 @@ const loadingStyles = stylex.create({* <XDSButton label="Click me" />* <XDSButton label="Primary action" variant="primary" />* <XDSButton label="Delete" variant="destructive" />- * <XDSButton label="Settings" icon={<GearIcon />} />+ *+ * // Icon-only (square) β pass icon without children+ * <XDSButton label="Settings" icon={<GearIcon />} variant="ghost" />+ * <XDSButton label="Pick emoji" icon={<span>π</span>} variant="ghost" size="sm" />+ *+ * // Icon + visible label+ * <XDSButton label="Edit" icon={<PencilIcon />}>Edit</XDSButton>* ```*/export const XDSButton = forwardRef<HTMLButtonElement, XDSButtonProps>(diff --git a/packages/core/src/Grid/README.md b/packages/core/src/Grid/README.mdindex 06f1a35f58..4bf0ad741b 100644--- a/packages/core/src/Grid/README.md+++ b/packages/core/src/Grid/README.md@@ -35,4 +35,14 @@ import {XDSGrid, XDSGridSpan} from '@xds/core/Grid';<XDSGridSpan span={2}>Wide item</XDSGridSpan><div>Normal item</div></XDSGrid>++// Dense grid (e.g. color swatches, icon grids, compact controls)+<XDSGrid columns={6} gap="space2">+ {items.map(item => (+ <XDSButton key={item.id} label={item.label} icon={item.icon} variant="ghost" size="sm" />+ ))}+</XDSGrid>```++Use `XDSGrid` for any grid layout instead of manual CSS grid (`display: 'grid'`,+`gridTemplateColumns`). It handles gap tokens and works with any column count.