Skip to content

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

TypeScript

refactor(editor): restructure with XDSLayout for rubric Grade A (#1531)

rubyycheungcd4e0133d623
diff --git a/packages/cli/templates/pages/editor/page.tsx b/packages/cli/templates/pages/editor/page.tsx
index 2fc17400e9..2058fb044d 100644
--- a/packages/cli/templates/pages/editor/page.tsx
+++ b/packages/cli/templates/pages/editor/page.tsx
@@ -8,7 +8,13 @@ import {XDSCard} from '@xds/core/Card';
import {XDSCenter} from '@xds/core/Center';
import {XDSDivider} from '@xds/core/Divider';
import {XDSEmptyState} from '@xds/core/EmptyState';
-import {XDSHStack, XDSVStack} from '@xds/core/Layout';
+import {
+ XDSHStack,
+ XDSVStack,
+ XDSStackItem,
+ XDSLayout,
+ XDSLayoutContent,
+} from '@xds/core/Layout';
import {XDSIcon} from '@xds/core/Icon';
import {XDSList, XDSListItem} from '@xds/core/List';
import {XDSTable} from '@xds/core/Table';
@@ -251,17 +257,7 @@ function defaultProps(type: BlockType): Record<string, unknown> {
// ---------------------------------------------------------------------------
const editorStyles = stylex.create({
- shell: {
- position: 'fixed',
- inset: 0,
- display: 'flex',
- flexDirection: 'column',
- backgroundColor: colorVars['--color-background-body'],
- },
- bodyRow: {
- display: 'flex',
- flex: 1,
- overflow: 'hidden',
+ contentRelative: {
position: 'relative',
},
floatingPanel: {
@@ -276,14 +272,26 @@ const editorStyles = stylex.create({
boxShadow: shadowVars['--shadow-low'],
overflow: 'hidden',
},
+ headerPadding: {
+ paddingInline: 16,
+ },
floatingPanelCollapsed: {
bottom: 'auto',
paddingBlockEnd: 16,
},
panelScroll: {
- flex: 1,
overflowY: 'auto',
},
+ tabListWrapper: {
+ paddingInline: 4,
+ },
+ panelContentPadding: {
+ paddingInline: 8,
+ paddingBlockEnd: 16,
+ },
+ collapseButtonEdgeComp: {
+ marginInlineEnd: -8,
+ },
previewArea: {
flex: 1,
overflowY: 'auto',
@@ -293,7 +301,6 @@ const editorStyles = stylex.create({
canvas: (maxWidth: number) => ({
maxWidth,
width: '100%',
- marginInline: 'auto',
transition: 'max-width 0.3s ease',
}),
clickable: {
@@ -304,30 +311,6 @@ const editorStyles = stylex.create({
outlineColor: colorVars['--color-border-blue'],
outlineOffset: -2,
},
- flex1: {
- flex: 1,
- },
- sectionHeadingInline: {
- paddingInline: 0,
- },
- iconCircle: {
- width: 40,
- height: 40,
- borderRadius: '50%',
- backgroundColor: colorVars['--color-background-muted'],
- flexShrink: 0,
- },
- tabListWrapper: {
- paddingInline: 4,
- },
- panelContentPadding: {
- paddingInline: 16,
- paddingBlockEnd: 16,
- },
- tabFill: {
- flex: 1,
- textAlign: 'center',
- },
});
// ---------------------------------------------------------------------------
@@ -563,16 +546,18 @@ function BlockPreview({
onClick={onSelect}>
<XDSVStack gap={4}>
<XDSHStack gap={3} vAlign="start">
- <XDSVStack gap={1} xstyle={editorStyles.flex1}>
- <XDSHeading level={3}>
- {(props.heading as string) || 'Features'}
- </XDSHeading>
- {(props.description as string) && (
- <XDSText type="supporting" color="secondary">
- {props.description as string}
- </XDSText>
- )}
- </XDSVStack>
+ <XDSStackItem size="fill">
+ <XDSVStack gap={1}>
+ <XDSHeading level={3}>
+ {(props.heading as string) || 'Features'}
+ </XDSHeading>
+ {(props.description as string) && (
+ <XDSText type="supporting" color="secondary">
+ {props.description as string}
+ </XDSText>
+ )}
+ </XDSVStack>
+ </XDSStackItem>
<XDSButton label="View All" variant="secondary" size="sm" />
</XDSHStack>
<XDSTable
@@ -617,9 +602,7 @@ function BlockPreview({
xstyle={cardXstyle}
onClick={onSelect}>
<XDSHStack gap={4} vAlign="start">
- <XDSCenter xstyle={editorStyles.iconCircle}>
- <XDSIcon icon={LockClosedIcon} color="secondary" />
- </XDSCenter>
+ <XDSIcon icon={LockClosedIcon} color="secondary" size="lg" />
<XDSVStack gap={1}>
<XDSText type="label" weight="semibold">
{(props.heading as string) || 'Notice'}
@@ -706,7 +689,7 @@ export default function EditorPage() {
const blocksTabContent = (
<XDSVStack gap={2}>
<XDSVStack gap={1}>
- <XDSSection variant="transparent" padding={2} xstyle={editorStyles.sectionHeadingInline}>
+ <XDSSection variant="transparent" padding={2}>
<XDSHeading level={4}>Add Block</XDSHeading>
</XDSSection>
<XDSList density="balanced" hasDividers={false}>
@@ -724,7 +707,7 @@ export default function EditorPage() {
</XDSVStack>
<XDSVStack gap={1}>
- <XDSSection variant="transparent" padding={2} xstyle={editorStyles.sectionHeadingInline}>
+ <XDSSection variant="transparent" padding={2}>
<XDSHeading level={4}>Layers</XDSHeading>
</XDSSection>
<XDSList density="balanced" hasDividers={false}>
@@ -800,37 +783,40 @@ export default function EditorPage() {
);
return (
- <XDSVStack xstyle={editorStyles.shell}>
- <XDSHStack xstyle={editorStyles.bodyRow}>
- {/* Floating Sidebar */}
- <XDSVStack
- gap={4}
- xstyle={[
- editorStyles.floatingPanel,
- isPanelCollapsed && editorStyles.floatingPanelCollapsed,
- ]}>
- {/* Panel Header */}
- <XDSSection variant="transparent" padding={4}>
- <XDSVStack gap={4}>
- <XDSHStack gap={3} vAlign="center">
- <XDSVStack gap={0} xstyle={editorStyles.flex1}>
- {isEditingTitle ? (
- <XDSTextInput
- label="Page title"
- isLabelHidden
- value={pageTitle}
- onChange={setPageTitle}
- onKeyDown={(e: React.KeyboardEvent) => {
- if (e.key === 'Enter') setIsEditingTitle(false);
- }}
- hasAutoFocus
- onBlur={() => setIsEditingTitle(false)}
- />
- ) : (
- <XDSHeading level={2}>{pageTitle}</XDSHeading>
- )}
- </XDSVStack>
- <XDSHStack gap={1}>
+ <XDSLayout
+ height="fill"
+ content={
+ <XDSLayoutContent
+ padding={0}
+ isScrollable={false}
+ xstyle={editorStyles.contentRelative}>
+ {/* Floating Sidebar */}
+ <XDSVStack
+ gap={4}
+ xstyle={[
+ editorStyles.floatingPanel,
+ isPanelCollapsed && editorStyles.floatingPanelCollapsed,
+ ]}>
+ <XDSSection variant="transparent" padding={4} xstyle={editorStyles.headerPadding}>
+ <XDSVStack gap={4}>
+ <XDSHStack gap={3} vAlign="center">
+ <XDSStackItem size="fill">
+ {isEditingTitle ? (
+ <XDSTextInput
+ label="Page title"
+ isLabelHidden
+ value={pageTitle}
+ onChange={setPageTitle}
+ onKeyDown={(e: React.KeyboardEvent) => {
+ if (e.key === 'Enter') setIsEditingTitle(false);
+ }}
+ hasAutoFocus
+ onBlur={() => setIsEditingTitle(false)}
+ />
+ ) : (
+ <XDSHeading level={2}>{pageTitle}</XDSHeading>
+ )}
+ </XDSStackItem>
<XDSButton
label={
isPanelCollapsed ? 'Expand panel' : 'Collapse panel'
@@ -845,104 +831,113 @@ export default function EditorPage() {
size="sm"
onClick={() => setIsPanelCollapsed(v => !v)}
isIconOnly
+ xstyle={editorStyles.collapseButtonEdgeComp}
/>
</XDSHStack>
- </XDSHStack>
- <XDSToolbar
- label="Viewport and actions"
- padding={0}
- startContent={
- <XDSSegmentedControl
- label="Viewport size"
- value={viewport}
- onChange={(v: string) =>
- setViewport(v as ViewportSize)
- }>
- <XDSSegmentedControlItem
- value="desktop"
- label="Desktop"
- icon={<XDSIcon icon={ComputerDesktopIcon} size="sm" />}
- isLabelHidden
- />
- <XDSSegmentedControlItem
- value="tablet"
- label="Tablet"
- icon={<XDSIcon icon={DeviceTabletIcon} size="sm" />}
- isLabelHidden
- />
- <XDSSegmentedControlItem
- value="phone"
- label="Phone"
- icon={
- <XDSIcon icon={DevicePhoneMobileIcon} size="sm" />
- }
- isLabelHidden
- />
- </XDSSegmentedControl>
- }
- endContent={
- <XDSHStack gap={2}>
- <XDSButton
- label="Preview"
- icon={<XDSIcon icon={EyeIcon} size="sm" />}
- variant="ghost"
- isIconOnly
- />
- <XDSButton label="Publish" variant="primary" />
- </XDSHStack>
- }
- />
- </XDSVStack>
- </XDSSection>
+ <XDSToolbar
+ label="Viewport and actions"
+ padding={0}
+ startContent={
+ <XDSSegmentedControl
+ label="Viewport size"
+ value={viewport}
+ onChange={(v: string) =>
+ setViewport(v as ViewportSize)
+ }>
+ <XDSSegmentedControlItem
+ value="desktop"
+ label="Desktop"
+ icon={
+ <XDSIcon icon={ComputerDesktopIcon} size="sm" />
+ }
+ isLabelHidden
+ />
+ <XDSSegmentedControlItem
+ value="tablet"
+ label="Tablet"
+ icon={<XDSIcon icon={DeviceTabletIcon} size="sm" />}
+ isLabelHidden
+ />
+ <XDSSegmentedControlItem
+ value="phone"
+ label="Phone"
+ icon={
+ <XDSIcon icon={DevicePhoneMobileIcon} size="sm" />
+ }
+ isLabelHidden
+ />
+ </XDSSegmentedControl>
+ }
+ endContent={
+ <XDSHStack gap={2}>
+ <XDSButton
+ label="Preview"
+ icon={<XDSIcon icon={EyeIcon} size="sm" />}
+ variant="ghost"
+ isIconOnly
+ />
+ <XDSButton label="Publish" variant="primary" />
+ </XDSHStack>
+ }
+ />
+ </XDSVStack>
+ </XDSSection>
- {!isPanelCollapsed && (
- <>
+ {!isPanelCollapsed && (
+ <>
<XDSVStack gap={0} xstyle={editorStyles.tabListWrapper}>
<XDSTabList
value={sidebarTab}
- onChange={(v: string) => setSidebarTab(v as SidebarTab)}>
- <XDSTab value="blocks" label="Blocks" xstyle={editorStyles.tabFill} />
- <XDSTab value="properties" label="Properties" xstyle={editorStyles.tabFill} />
+ onChange={(v: string) => setSidebarTab(v as SidebarTab)}
+ layout="fill">
+ <XDSTab value="blocks" label="Blocks" />
+ <XDSTab value="properties" label="Properties" />
</XDSTabList>
<XDSDivider />
</XDSVStack>
<XDSSection
variant="transparent"
padding={0}
- xstyle={[editorStyles.panelScroll, editorStyles.panelContentPadding]}>
+ xstyle={[
+ editorStyles.panelScroll,
+ editorStyles.panelContentPadding,
+ ]}>
{sidebarTab === 'blocks'
? blocksTabContent
: propertiesTabContent}
</XDSSection>
- </>
- )}
- </XDSVStack>
-
- {/* Preview Canvas */}
- <XDSVStack xstyle={editorStyles.previewArea}>
- <XDSVStack
- gap={4}
- xstyle={editorStyles.canvas(VIEWPORT_MAX[viewport])}>
- {blocks.length > 0 ? (
- blocks.map(block => (
- <BlockPreview
- key={block.id}
- block={block}
- isSelected={block.id === selectedId}
- onSelect={() => selectBlock(block.id)}
- />
- ))
- ) : (
- <XDSEmptyState
- title="No blocks yet"
- description="Add blocks from the sidebar to start building your page"
- icon={<XDSIcon icon={PlusCircleIcon} />}
- />
+ </>
)}
</XDSVStack>
- </XDSVStack>
- </XDSHStack>
- </XDSVStack>
+
+ {/* Preview Canvas */}
+ <XDSVStack xstyle={editorStyles.previewArea}>
+ <XDSCenter axis="horizontal">
+ <XDSVStack
+ gap={4}
+ xstyle={editorStyles.canvas(VIEWPORT_MAX[viewport])}>
+ {blocks.length > 0 ? (
+ blocks.map(block => (
+ <BlockPreview
+ key={block.id}
+ block={block}
+ isSelected={block.id === selectedId}
+ onSelect={() => selectBlock(block.id)}
+ />
+ ))
+ ) : (
+ <XDSEmptyState
+ title="No blocks yet"
+ description="Add blocks from the sidebar to start building your page"
+ icon={<XDSIcon icon={PlusCircleIcon} />}
+ />
+ )}
+ </XDSVStack>
+ </XDSCenter>
+ </XDSVStack>
+ </XDSLayoutContent>
+ }
+ />
);
}