An open source design system that's fully customizable and agent ready
TypeScript
feat(resizable): add useResizable hook and XDSResizeHandle component (#1754)
Ernest726e54c910b5
diff --git a/apps/sandbox/src/app/(raw)/pages/shell-lab/page.tsx b/apps/sandbox/src/app/(raw)/pages/shell-lab/page.tsxindex 9b35381389..f66893be12 100644--- a/apps/sandbox/src/app/(raw)/pages/shell-lab/page.tsx+++ b/apps/sandbox/src/app/(raw)/pages/shell-lab/page.tsx@@ -34,6 +34,7 @@ import {XDSNavIcon} from '@xds/core/NavIcon';import {XDSBanner} from '@xds/core/Banner';import {XDSList, XDSListItem} from '@xds/core/List';import {XDSNavMenuItem} from '@xds/core/NavMenu';+import {useXDSResizable} from '@xds/core/Resizable';// =============================================================================// Configuration types@@ -536,6 +537,12 @@ function SampleSideNav({externalCollapsed?: boolean;setExternalCollapsed?: (v: boolean) => void;}) {+ const sidebar = useXDSResizable({+ defaultSize: 260,+ minSizePx: 180,+ maxSizePx: 480,+ });+const appNavIcon = (<XDSNavIconicon={@@ -601,104 +608,106 @@ function SampleSideNav({);return (- <XDSSideNav- collapsible={- config.isCollapsible- ? config.collapseToggleLocation === 'topnav'- ? {- isCollapsed: externalCollapsed,- onCollapsedChange: setExternalCollapsed,- hasButton: false,- }- : true- : false- }- resizable={config.isResizable}- header={heading}- topContent={- config.showTopContent ? (- <XDSSideNavItem label="Create New" />- ) : undefined- }- footer={- config.showFooter ? (- <XDSSideNavSection title="Account">- <XDSSideNavItem label="Jane Smith" />- <XDSSideNavItem label="Upgrade to Pro" />- </XDSSideNavSection>- ) : undefined- }- footerIcons={- config.showFooterIcons ? (- <>- <XDSButton- label="Help"- icon={- <svg- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 24 24"- fill="none"- stroke="currentColor"- strokeWidth={1.5}- width="16"- height="16">- <circle cx="12" cy="12" r="10" />- <path d="M9.09 9a3 3 0 015.83 1c0 2-3 3-3 3" />- <circle cx="12" cy="17" r=".5" fill="currentColor" />- </svg>- }- variant="ghost"- isIconOnly- />- <XDSButton- label="Settings"- icon={- <svg- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 24 24"- fill="none"- stroke="currentColor"- strokeWidth={1.5}- width="16"- height="16">- <path d="M12.22 2h-.44a2 2 0 00-2 2v.18a2 2 0 01-1 1.73l-.43.25a2 2 0 01-2 0l-.15-.08a2 2 0 00-2.73.73l-.22.38a2 2 0 00.73 2.73l.15.1a2 2 0 011 1.72v.51a2 2 0 01-1 1.74l-.15.09a2 2 0 00-.73 2.73l.22.38a2 2 0 002.73.73l.15-.08a2 2 0 012 0l.43.25a2 2 0 011 1.73V20a2 2 0 002 2h.44a2 2 0 002-2v-.18a2 2 0 011-1.73l.43-.25a2 2 0 012 0l.15.08a2 2 0 002.73-.73l.22-.39a2 2 0 00-.73-2.73l-.15-.08a2 2 0 01-1-1.74v-.5a2 2 0 011-1.74l.15-.09a2 2 0 00.73-2.73l-.22-.38a2 2 0 00-2.73-.73l-.15.08a2 2 0 01-2 0l-.43-.25a2 2 0 01-1-1.73V4a2 2 0 00-2-2z" />- <circle cx="12" cy="12" r="3" />- </svg>- }- variant="ghost"- isIconOnly- />- </>- ) : undefined- }>- <XDSSideNavSection title="Navigation">- <XDSSideNavItem- label="Dashboard"- isSelected- href="#"- icon={DashboardIcon}- />- <XDSSideNavItem- label="Projects"- href="#"- icon={ProjectsIcon}- endContent={<XDSBadge label={3} />}- />- <XDSSideNavItem label="Messages" href="#" icon={MessagesIcon} />- {config.showNestedItems && (- <XDSSideNavItem label="Settings" href="#" icon={SettingsIcon}>- <XDSSideNavItem label="General" href="#" />- <XDSSideNavItem label="Security" href="#" />- <XDSSideNavItem label="Notifications" href="#" />- </XDSSideNavItem>- )}- </XDSSideNavSection>- <XDSSideNavSection title="Resources">- <XDSSideNavItem label="Documentation" href="#" icon={DocsIcon} />- <XDSSideNavItem label="API Reference" href="#" />- <XDSSideNavItem label="Support" href="#" />- </XDSSideNavSection>- </XDSSideNav>+ <>+ <XDSSideNav+ collapsible={+ config.isCollapsible+ ? config.collapseToggleLocation === 'topnav'+ ? {+ isCollapsed: externalCollapsed,+ onCollapsedChange: setExternalCollapsed,+ hasButton: false,+ }+ : true+ : false+ }+ resizable={config.isResizable ? sidebar.props : false}+ header={heading}+ topContent={+ config.showTopContent ? (+ <XDSSideNavItem label="Create New" />+ ) : undefined+ }+ footer={+ config.showFooter ? (+ <XDSSideNavSection title="Account">+ <XDSSideNavItem label="Jane Smith" />+ <XDSSideNavItem label="Upgrade to Pro" />+ </XDSSideNavSection>+ ) : undefined+ }+ footerIcons={+ config.showFooterIcons ? (+ <>+ <XDSButton+ label="Help"+ icon={+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ width="16"+ height="16">+ <circle cx="12" cy="12" r="10" />+ <path d="M9.09 9a3 3 0 015.83 1c0 2-3 3-3 3" />+ <circle cx="12" cy="17" r=".5" fill="currentColor" />+ </svg>+ }+ variant="ghost"+ isIconOnly+ />+ <XDSButton+ label="Settings"+ icon={+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth={1.5}+ width="16"+ height="16">+ <path d="M12.22 2h-.44a2 2 0 00-2 2v.18a2 2 0 01-1 1.73l-.43.25a2 2 0 01-2 0l-.15-.08a2 2 0 00-2.73.73l-.22.38a2 2 0 00.73 2.73l.15.1a2 2 0 011 1.72v.51a2 2 0 01-1 1.74l-.15.09a2 2 0 00-.73 2.73l.22.38a2 2 0 002.73.73l.15-.08a2 2 0 012 0l.43.25a2 2 0 011 1.73V20a2 2 0 002 2h.44a2 2 0 002-2v-.18a2 2 0 011-1.73l.43-.25a2 2 0 012 0l.15.08a2 2 0 002.73-.73l.22-.39a2 2 0 00-.73-2.73l-.15-.08a2 2 0 01-1-1.74v-.5a2 2 0 011-1.74l.15-.09a2 2 0 00.73-2.73l-.22-.38a2 2 0 00-2.73-.73l-.15.08a2 2 0 01-2 0l-.43-.25a2 2 0 01-1-1.73V4a2 2 0 00-2-2z" />+ <circle cx="12" cy="12" r="3" />+ </svg>+ }+ variant="ghost"+ isIconOnly+ />+ </>+ ) : undefined+ }>+ <XDSSideNavSection title="Navigation">+ <XDSSideNavItem+ label="Dashboard"+ isSelected+ href="#"+ icon={DashboardIcon}+ />+ <XDSSideNavItem+ label="Projects"+ href="#"+ icon={ProjectsIcon}+ endContent={<XDSBadge label={3} />}+ />+ <XDSSideNavItem label="Messages" href="#" icon={MessagesIcon} />+ {config.showNestedItems && (+ <XDSSideNavItem label="Settings" href="#" icon={SettingsIcon}>+ <XDSSideNavItem label="General" href="#" />+ <XDSSideNavItem label="Security" href="#" />+ <XDSSideNavItem label="Notifications" href="#" />+ </XDSSideNavItem>+ )}+ </XDSSideNavSection>+ <XDSSideNavSection title="Resources">+ <XDSSideNavItem label="Documentation" href="#" icon={DocsIcon} />+ <XDSSideNavItem label="API Reference" href="#" />+ <XDSSideNavItem label="Support" href="#" />+ </XDSSideNavSection>+ </XDSSideNav>+ </>);}diff --git a/apps/storybook/stories/ChatComposer.stories.tsx b/apps/storybook/stories/ChatComposer.stories.tsxindex c3bc5b8fbe..18b2ead986 100644--- a/apps/storybook/stories/ChatComposer.stories.tsx+++ b/apps/storybook/stories/ChatComposer.stories.tsx@@ -121,8 +121,6 @@ export const WithFooterActions: Story = {size="md"icon={MicIcon}isIconOnly- iconOnly- isIconOnly/>}/>@@ -147,8 +145,6 @@ export const WithAttachments: Story = {size="sm"icon={PaperclipIcon}isIconOnly- iconOnly- isIconOnly/>}headerContext={@@ -185,8 +181,6 @@ export const FullFeatured: Story = {size="sm"icon={AtSignIcon}isIconOnly- iconOnly- isIconOnly/><XDSButtonlabel="Attach file"@@ -194,8 +188,6 @@ export const FullFeatured: Story = {size="sm"icon={PaperclipIcon}isIconOnly- iconOnly- isIconOnly/></>}@@ -215,8 +207,6 @@ export const FullFeatured: Story = {size="md"icon={MicIcon}isIconOnly- iconOnly- isIconOnly/>}/>diff --git a/apps/storybook/stories/Resizable.stories.tsx b/apps/storybook/stories/Resizable.stories.tsxnew file mode 100644index 0000000000..96ce6d6789--- /dev/null+++ b/apps/storybook/stories/Resizable.stories.tsx@@ -0,0 +1,519 @@+import type {Meta, StoryObj} from '@storybook/react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ spacingVars,+ radiusVars,+} from '@xds/core/theme/tokens.stylex';+import {XDSResizeHandle, useXDSResizable} from '@xds/core/Resizable';+import {XDSText, XDSHeading} from '@xds/core/Text';+import {+ XDSLayout,+ XDSLayoutContent,+ XDSLayoutPanel,+ XDSStack,+} from '@xds/core/Layout';+import {XDSSideNav, XDSSideNavItem} from '@xds/core/SideNav';+import {XDSDivider} from '@xds/core/Divider';++const ps = stylex.create({+ shell: {+ height: 400,+ width: '100%',+ borderWidth: 1,+ borderStyle: 'solid',+ borderColor: colorVars['--color-border'],+ borderRadius: radiusVars['--radius-container'],+ overflow: 'hidden',+ },+ sz: {opacity: 0.6, fontSize: 12, fontFamily: 'monospace'},+});++const meta: Meta<typeof XDSResizeHandle> = {+ title: 'Lab/Resizable',+ component: XDSResizeHandle,+ tags: ['autodocs'],+ parameters: {+ layout: 'padded',+ docs: {+ description: {+ component:+ 'Hook-based resizable panel system. useXDSResizable() manages size state; ' ++ 'XDSResizeHandle provides the interactive pill-grip separator with optional divider line.',+ },+ },+ },+};+export default meta;+type Story = StoryObj<typeof XDSResizeHandle>;+/** Basic horizontal split with divider line. */+export const HorizontalSplit: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 250,+ minSizePx: 150,+ maxSizePx: 500,+ });+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Sidebar</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{sidebar.size}px</span>+ </XDSText>+ <XDSText>+ Drag the handle to resize. Arrow keys when focused.+ </XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ label="Resize sidebar"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Content</XDSHeading>+ <XDSText>Main content area fills remaining space.</XDSText>+ </XDSStack>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Vertical split with divider line. */+export const VerticalSplit: Story = {+ render: () => {+ const top = useXDSResizable({+ defaultSize: 250,+ minSizePx: 100,+ maxSizePx: 350,+ });+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ header={+ <div style={{height: top.size}}>+ <XDSLayoutPanel padding={4} width="100%">+ <XDSStack gap="space2">+ <XDSHeading level={4}>Editor</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{top.size}px</span>+ </XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="vertical"+ hasDivider+ resizable={top.props}+ label="Resize editor"+ />+ </div>+ }+ content={+ <XDSLayoutContent>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Terminal</XDSHeading>+ <XDSText>Bottom panel fills remaining space.</XDSText>+ </XDSStack>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Collapsible sidebar — drag past threshold or double-click to collapse. */+export const Collapsible: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 260,+ minSizePx: 180,+ collapsible: true,+ collapsedSize: 60,+ });+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ {!sidebar.isCollapsed && (+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Sidebar</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{sidebar.size}px</span>+ </XDSText>+ <XDSText>+ Double-click handle or press Enter to collapse.+ </XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ )}+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ label="Resize sidebar"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Content</XDSHeading>+ <XDSText>+ Sidebar is {sidebar.isCollapsed ? 'collapsed' : 'expanded'}.+ {sidebar.isCollapsed && (+ <button+ onClick={() => sidebar.expand()}+ style={{marginLeft: 8}}>+ Expand+ </button>+ )}+ </XDSText>+ </XDSStack>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Three-panel IDE layout with nested horizontal + vertical splits. */+export const ThreePanelIDE: Story = {+ render: () => {+ const explorer = useXDSResizable({+ defaultSize: 220,+ minSizePx: 150,+ maxSizePx: 400,+ });+ const editor = useXDSResizable({+ defaultSize: 280,+ minSizePx: 100,+ maxSizePx: 350,+ });+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={explorer.size} hasDivider={false}>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Explorer</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{explorer.size}px</span>+ </XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={explorer.props}+ label="Resize explorer"+ />+ </>+ }+ content={+ <XDSLayoutContent padding={0}>+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ height: '100%',+ }}>+ <div style={{flex: 'none', height: editor.size, padding: 16}}>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Editor</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{editor.size}px</span>+ </XDSText>+ </XDSStack>+ </div>+ <XDSResizeHandle+ direction="vertical"+ hasDivider+ resizable={editor.props}+ label="Resize editor"+ />+ <div style={{flex: 1, padding: 16}}>+ <XDSHeading level={4}>Terminal</XDSHeading>+ </div>+ </div>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Snap points — sidebar snaps to predefined widths. */+export const SnapPoints: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 260,+ minSizePx: 56,+ maxSizePx: 600,+ snaps: [56, 160, 260, 400],+ });+ const isRail = sidebar.size <= 60;+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ {isRail ? (+ <XDSText>{'\u2630'}</XDSText>+ ) : (+ <XDSStack gap="space2">+ <XDSHeading level={4}>Sidebar</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{sidebar.size}px</span>+ </XDSText>+ <XDSText>+ Snaps to 56 \u00b7 160 \u00b7 260 \u00b7 400px.+ </XDSText>+ </XDSStack>+ )}+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ label="Resize sidebar"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSHeading level={4}>Content</XDSHeading>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Pill hidden at rest — only appears on hover/focus. */+export const HiddenPill: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 250,+ minSizePx: 150,+ maxSizePx: 500,+ });+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ <XDSStack gap="space2">+ <XDSHeading level={4}>Sidebar</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{sidebar.size}px</span>+ </XDSText>+ <XDSText>Pill only appears on hover.</XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ isAlwaysVisible={false}+ resizable={sidebar.props}+ label="Resize sidebar"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSHeading level={4}>Content</XDSHeading>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Disabled handle — divider visible but non-interactive. */+export const Disabled: Story = {+ render: () => {+ const sidebar = useXDSResizable({defaultSize: 250, minSizePx: 150});+ return (+ <div {...stylex.props(ps.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ <XDSHeading level={4}>Sidebar (locked)</XDSHeading>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ isDisabled+ label="Locked"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSHeading level={4}>Content</XDSHeading>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Integration with XDSLayout — resizable sidebar with collapsible. */+export const WithXDSLayout: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 260,+ minSizePx: 180,+ maxSizePx: 450,+ collapsible: true,+ collapsedSize: 50,+ });+ return (+ <div {...stylex.props(ps.shell)} style={{height: 500}}>+ <XDSLayout+ height="fill"+ start={+ <>+ {!sidebar.isCollapsed && (+ <XDSLayoutPanel+ resizable={sidebar.props}+ hasDivider={false}+ role="navigation"+ label="Sidebar">+ <XDSStack gap="space2">+ <XDSHeading level={4}>Navigation</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{sidebar.size}px</span>+ </XDSText>+ <XDSDivider />+ <XDSText>Drag the handle to resize.</XDSText>+ <XDSText>Double-click or press Enter to collapse.</XDSText>+ </XDSStack>+ </XDSLayoutPanel>+ )}+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ label="Resize navigation"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSStack gap="space3">+ <XDSHeading level={3}>Main Content</XDSHeading>+ <XDSText>+ XDSLayoutPanel with resizable prop + XDSResizeHandle with+ hasDivider.+ </XDSText>+ <XDSText>+ Sidebar is{' '}+ <strong>+ {sidebar.isCollapsed ? 'collapsed' : 'expanded'}+ </strong>+ {sidebar.isCollapsed && (+ <button+ onClick={() => sidebar.expand()}+ style={{marginLeft: 8}}>+ Expand+ </button>+ )}+ </XDSText>+ </XDSStack>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** AppShell with resizable SideNav. */+export const WithAppShell: Story = {+ render: () => {+ const nav = useXDSResizable({+ defaultSize: 260,+ minSizePx: 200,+ maxSizePx: 400,+ collapsible: true,+ collapsedSize: 50,+ snaps: [56, 260],+ });+ return (+ <div {...stylex.props(ps.shell)} style={{height: 500}}>+ <XDSLayout+ height="fill"+ start={+ <>+ {!nav.isCollapsed && (+ <XDSLayoutPanel width={nav.size} hasDivider={false} padding={0}>+ <XDSSideNav>+ <XDSSideNavItem label="Home" isSelected />+ <XDSSideNavItem label="Dashboard" />+ <XDSSideNavItem label="Settings" />+ </XDSSideNav>+ </XDSLayoutPanel>+ )}+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={nav.props}+ label="Resize navigation"+ />+ </>+ }+ content={+ <XDSLayoutContent>+ <XDSStack gap="space3">+ <XDSHeading level={3}>Dashboard</XDSHeading>+ <XDSText>+ <span {...stylex.props(ps.sz)}>{nav.size}px</span>+ {' \u2014 '}+ {nav.isCollapsed ? 'Collapsed' : 'Expanded'}+ </XDSText>+ <XDSText>+ SideNav width driven by useXDSResizable. Double-click handle+ to collapse.+ </XDSText>+ </XDSStack>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};diff --git a/apps/storybook/stories/useXDSResizable.stories.tsx b/apps/storybook/stories/useXDSResizable.stories.tsxnew file mode 100644index 0000000000..ed63dbc49c--- /dev/null+++ b/apps/storybook/stories/useXDSResizable.stories.tsx@@ -0,0 +1,337 @@+import type {Meta, StoryObj} from '@storybook/react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ radiusVars,+ spacingVars,+ typographyVars,+} from '@xds/core/theme/tokens.stylex';+import {useXDSResizable, XDSResizeHandle} from '@xds/core/Resizable';+import {XDSLayout, XDSLayoutContent, XDSLayoutPanel} from '@xds/core/Layout';+import {XDSText, XDSHeading} from '@xds/core/Text';++const s = stylex.create({+ shell: {+ height: 300,+ width: '100%',+ borderWidth: 1,+ borderStyle: 'solid',+ borderColor: colorVars['--color-border'],+ borderRadius: radiusVars['--radius-container'],+ overflow: 'hidden',+ },+ muted: {backgroundColor: colorVars['--color-background-muted']},+ card: {+ backgroundColor: colorVars['--color-background-card'],+ borderWidth: 1,+ borderStyle: 'solid',+ borderColor: colorVars['--color-border'],+ borderRadius: radiusVars['--radius-container'],+ margin: spacingVars['--spacing-2'],+ },+});++function HookDemo({children}: {children: React.ReactNode}) {+ return <div>{children}</div>;+}++const meta: Meta<typeof HookDemo> = {+ title: 'Core/Hooks/useXDSResizable',+ component: HookDemo,+ tags: ['autodocs'],+ parameters: {+ layout: 'padded',+ docs: {+ description: {+ component:+ 'Hook that manages resize state for panel regions. ' ++ 'Pair with XDSResizeHandle for interactive resizing.',+ },+ },+ },+};+export default meta;+type Story = StoryObj<typeof HookDemo>;++/** Two side-by-side panels with a divider handle. */+export const Horizontal: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 200,+ minSizePx: 100,+ maxSizePx: 500,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ Sidebar+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ />+ </>+ }+ content={<XDSLayoutContent>Content</XDSLayoutContent>}+ />+ </div>+ );+ },+};++/** Vertical layout — top and bottom panels. */+export const Vertical: Story = {+ render: () => {+ const top = useXDSResizable({+ defaultSize: 150,+ minSizePx: 60,+ maxSizePx: 250,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ header={+ <>+ <XDSLayoutPanel width="100%" padding={4}>+ <div style={{height: top.size}}>Header</div>+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="vertical"+ hasDivider+ resizable={top.props}+ />+ </>+ }+ content={<XDSLayoutContent>Content</XDSLayoutContent>}+ />+ </div>+ );+ },+};++/** Three panels with two handles — mail client layout. */+export const ThreePanel: Story = {+ render: () => {+ const left = useXDSResizable({+ defaultSize: 180,+ minSizePx: 120,+ maxSizePx: 300,+ });+ const right = useXDSResizable({+ defaultSize: 220,+ minSizePx: 150,+ maxSizePx: 400,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={left.size} hasDivider={false}>+ Folders+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={left.props}+ />+ </>+ }+ content={<XDSLayoutContent>Inbox</XDSLayoutContent>}+ end={+ <>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ isReversed+ resizable={right.props}+ />+ <XDSLayoutPanel width={right.size} hasDivider={false}>+ Preview+ </XDSLayoutPanel>+ </>+ }+ />+ </div>+ );+ },+};++/** Nested — horizontal split with a vertical split inside. */+export const Nested: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 200,+ minSizePx: 120,+ maxSizePx: 350,+ });+ const editor = useXDSResizable({+ defaultSize: 200,+ minSizePx: 80,+ maxSizePx: 250,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ Explorer+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ />+ </>+ }+ content={+ <XDSLayoutContent padding={0}>+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ height: '100%',+ }}>+ <div+ style={{+ height: editor.size,+ flexShrink: 0,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ }}>+ Editor+ </div>+ <XDSResizeHandle+ direction="vertical"+ hasDivider+ resizable={editor.props}+ />+ <div+ style={{+ flex: 1,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ }}>+ Terminal+ </div>+ </div>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};++/** Always-visible pill grip with divider line. */+export const AlwaysVisible: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 250,+ minSizePx: 100,+ maxSizePx: 500,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel width={sidebar.size} hasDivider={false}>+ Sidebar+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={sidebar.props}+ />+ </>+ }+ content={<XDSLayoutContent>Content</XDSLayoutContent>}+ />+ </div>+ );+ },+};++/** Mixed container styles — no divider lines, relying on background contrast. */+export const MixedContainers: Story = {+ render: () => {+ const sidebar = useXDSResizable({+ defaultSize: 200,+ minSizePx: 120,+ maxSizePx: 350,+ });+ const editor = useXDSResizable({+ defaultSize: 200,+ minSizePx: 80,+ maxSizePx: 250,+ });+ return (+ <div {...stylex.props(s.shell)}>+ <XDSLayout+ height="fill"+ start={+ <>+ <XDSLayoutPanel+ width={sidebar.size}+ hasDivider={false}+ xstyle={s.muted}>+ Explorer+ </XDSLayoutPanel>+ <XDSResizeHandle+ direction="horizontal"+ resizable={sidebar.props}+ />+ </>+ }+ content={+ <XDSLayoutContent padding={0}>+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ height: '100%',+ }}>+ <div+ style={{+ flex: 1,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ }}>+ Editor+ </div>+ <XDSResizeHandle+ direction="vertical"+ resizable={editor.props}+ />+ <div+ {...stylex.props(s.card)}+ style={{+ flex: 1,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ }}>+ Terminal+ </div>+ </div>+ </XDSLayoutContent>+ }+ />+ </div>+ );+ },+};diff --git a/packages/core/package.json b/packages/core/package.jsonindex a31b52bd63..0ce6baab59 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -360,6 +360,12 @@"import": "./dist/RadioList/index.mjs","require": "./dist/RadioList/index.js"},+ "./Resizable": {+ "source": "./src/Resizable/index.ts",+ "types": "./dist/Resizable/index.d.ts",+ "import": "./dist/Resizable/index.mjs",+ "require": "./dist/Resizable/index.js"+ },"./Section": {"source": "./src/Section/index.ts","types": "./dist/Section/index.d.ts",diff --git a/packages/core/src/Layout/XDSLayoutPanel.tsx b/packages/core/src/Layout/XDSLayoutPanel.tsxindex a867aa43dd..f54d5a175d 100644--- a/packages/core/src/Layout/XDSLayoutPanel.tsx+++ b/packages/core/src/Layout/XDSLayoutPanel.tsx@@ -22,6 +22,7 @@ import {XDSLayoutAreaContext} from './XDSLayoutAreaContext';import {XDSLayoutSlotsContext} from './XDSLayoutSlotsContext';import {xdsClassName, mergeProps} from '../utils';import type {SpacingStep} from '../utils/types';+import type {ResizableProps} from '../Resizable/useXDSResizable';import {paddingStyles,containerPaddingInlineVarStyles,@@ -115,6 +116,9 @@ export interface XDSLayoutPanelProps extends XDSBaseProps<HTMLDivElement> {* - Start panel: border on end edge (right in LTR)* - End panel: border on start edge (left in LTR)* When false, spacing collapse is applied automatically for seamless visual flow.+ *+ * Note: When using `resizable` with an adjacent `XDSResizeHandle hasDivider`,+ * set this to `false` to avoid a double-line artifact.* @default false*/hasDivider?: boolean;@@ -149,8 +153,25 @@ export interface XDSLayoutPanelProps extends XDSBaseProps<HTMLDivElement> {/*** Width of the panel.* Numbers are treated as pixels, strings are used as-is.+ * When `resizable` is provided, this is ignored — the hook controls width.*/width?: number | string;++ /**+ * Resize props from `useXDSResizable()`. When provided, the panel width+ * is driven by the hook and a resize handle should be placed adjacent+ * to this panel.+ *+ * @example+ * ```tsx+ * const sidebar = useXDSResizable({ defaultSize: 250, minSizePx: 200 });+ * <XDSLayoutPanel resizable={sidebar.props}>+ * <Navigation />+ * </XDSLayoutPanel>+ * <XDSResizeHandle resizable={sidebar.props} />+ * ```+ */+ resizable?: ResizableProps;}/**@@ -189,6 +210,7 @@ export function XDSLayoutPanel({padding,role,width,+ resizable,xstyle,className,style,@@ -198,6 +220,9 @@ export function XDSLayoutPanel({const area = useContext(XDSLayoutAreaContext);const {hasHeader, hasFooter} = useContext(XDSLayoutSlotsContext);+ // When resizable props are provided, use the hook-driven size+ const effectiveWidth = resizable ? resizable._size : width;+// Determine panel positionconst isStartPanel = area === 'start';const isEndPanel = area === 'end';@@ -231,7 +256,7 @@ export function XDSLayoutPanel({xdsClassName('layout-panel'),stylex.props(styles.panel,- dynamicStyles.sizing(width ?? null),+ dynamicStyles.sizing(effectiveWidth ?? null),// Outer padding on container edges (unless component is full bleed)isStartPanel &&!isZeroPadding &&diff --git a/packages/core/src/Resizable/Resizable.doc.mjs b/packages/core/src/Resizable/Resizable.doc.mjsnew file mode 100644index 0000000000..ea163fc61a--- /dev/null+++ b/packages/core/src/Resizable/Resizable.doc.mjs@@ -0,0 +1,181 @@+/** @type {import('../docs-types').ComponentDoc} */+export const docs = {+ name: 'Resizable',+ keywords: [+ 'resize',+ 'resizable',+ 'split',+ 'splitter',+ 'panel',+ 'drag',+ 'separator',+ 'divider',+ 'handle',+ 'grip',+ ],+ usage: {+ description:+ 'Hook-based resizable panel system. useXDSResizable() manages size state ' ++ 'and XDSResizeHandle provides the interactive pill-grip separator. ' ++ 'Pass resize props to existing layout components via their resizable prop.',+ bestPractices: [+ {+ guidance: true,+ description:+ 'Use useXDSResizable() with existing XDS layout components. ' ++ 'Pass the returned props to the resizable prop on XDSLayoutPanel or XDSSideNav.',+ },+ {+ guidance: true,+ description:+ 'Provide an accessible label on each XDSResizeHandle when multiple ' ++ 'handles exist (e.g. "Resize sidebar", "Resize terminal").',+ },+ {+ guidance: false,+ description:+ 'Wrap panels in extra container components for resize. The hook-first ' ++ 'architecture avoids extra DOM — use it directly on existing components.',+ },+ ],+ },+ theming: {+ targets: [{className: 'xds-resize-handle', visualProps: ['direction']}],+ vars: [+ {+ name: '--resize-handle-width',+ description: 'Visual width of the pill indicator',+ default: '3px',+ },+ {+ name: '--resize-handle-height',+ description: 'Height of the pill indicator',+ default: '32px',+ },+ {+ name: '--resize-handle-hit-area',+ description: 'Clickable area width around the pill',+ default: '16px',+ },+ ],+ },+ components: [+ {+ name: 'useXDSResizable',+ description:+ 'Hook that manages resize state for one or more panel regions. ' ++ 'Returns size, isCollapsed, collapse/expand/resize methods, and props to pass to handles.',+ props: [+ {+ name: 'defaultSize',+ type: 'number | string',+ description:+ 'Initial size in pixels or percentage string (e.g. "20%").',+ default: '250',+ },+ {+ name: 'minSizePx',+ type: 'number',+ description: 'Minimum size in pixels.',+ default: '50',+ },+ {+ name: 'maxSizePx',+ type: 'number',+ description: 'Maximum size in pixels.',+ default: 'Infinity',+ },+ {+ name: 'collapsible',+ type: 'boolean',+ description: 'Whether the region can collapse to size 0.',+ default: 'false',+ },+ {+ name: 'collapsedSize',+ type: 'number',+ description:+ 'Pixel threshold that triggers collapse during drag.',+ default: '40',+ },+ {+ name: 'snaps',+ type: 'number[]',+ description: 'Pixel values to snap to during resize.',+ },+ {+ name: 'shrinkOrder',+ type: 'number',+ description:+ 'Cascade priority — lower number shrinks first.',+ },+ {+ name: 'autoSaveId',+ type: 'string',+ description: 'Key for persisting sizes to localStorage.',+ },+ ],+ },+ {+ name: 'XDSResizeHandle',+ description:+ 'Draggable separator between panels. Pill-grip design: invisible at rest, ' ++ 'visible on hover (0.6 opacity), fully opaque during drag (1.0). Keyboard-accessible.',+ props: [+ {+ name: 'direction',+ type: "'horizontal' | 'vertical'",+ description:+ 'Layout direction — determines cursor and indicator orientation.',+ default: "'horizontal'",+ },+ {+ name: 'isReversed',+ type: 'boolean',+ description:+ 'Reverse drag direction. Use when the handle controls a panel on the end/right/bottom side.',+ default: 'false',+ },+ {+ name: 'isDisabled',+ type: 'boolean',+ description: 'Whether the handle is interactive.',+ default: 'false',+ },+ {+ name: 'hasDivider',+ type: 'boolean',+ description:+ 'Show a full-length 1px divider line through the handle. Use when adjacent panels share the same background.',+ default: 'false',+ },+ {+ name: 'isAlwaysVisible',+ type: 'boolean',+ description:+ 'Show the pill grip at rest instead of only on hover. Use when discoverability is important.',+ default: 'false',+ },+ {+ name: 'label',+ type: 'string',+ description: 'Accessible label for the separator.',+ default: "'Resize handle'",+ },+ {+ name: 'resizable',+ type: 'ResizableProps',+ description:+ 'Resize props from useXDSResizable — connects handle to panel.',+ required: true,+ },+ {+ name: 'children',+ type: 'ReactNode',+ description:+ 'Custom handle content. Overrides the default pill + divider.',+ },+ ],+ },+ ],+};diff --git a/packages/core/src/Resizable/XDSResizeHandle.tsx b/packages/core/src/Resizable/XDSResizeHandle.tsxnew file mode 100644index 0000000000..fb1508f13b--- /dev/null+++ b/packages/core/src/Resizable/XDSResizeHandle.tsx@@ -0,0 +1,418 @@+'use client';++/**+ * @file XDSResizeHandle.tsx+ * @input direction, isReversed, hasDivider, isAlwaysVisible, ResizableProps+ * @output Styled drag handle with WAI-ARIA separator role and keyboard support+ * @position Between resizable panels; consumed directly by builders+ *+ * Shadcn-inspired approach: the handle element is 1px wide (the divider line+ * itself), with an absolutely-positioned wider hit area for pointer interaction.+ * Optional pill grip indicator centered on the line.+ */++import {useCallback, useEffect, useRef, useState} from 'react';+import type {HTMLAttributes, ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {colorVars, durationVars, easeVars} from '../theme/tokens.stylex';+import {xdsClassName, mergeProps} from '../utils';+import type {ResizableProps} from './useXDSResizable';++const KEYBOARD_STEP = 10;+const KEYBOARD_LARGE_STEP = 50;++const styles = stylex.create({+ // The handle is 1px in layout flow — the visible divider line itself.+ // A wider hit area is achieved via the hitArea child.+ handle: {+ position: 'relative',+ flexShrink: 0,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ backgroundColor: colorVars['--color-border'],+ transitionProperty: 'background-color',+ transitionDuration: durationVars['--duration-fast'],+ transitionTimingFunction: easeVars['--ease-standard'],+ outline: {+ default: 'none',+ ':focus-visible': `2px solid ${colorVars['--color-accent']}`,+ },+ outlineOffset: {+ default: null,+ ':focus-visible': '2px',+ },+ },+ horizontal: {+ width: 1,+ height: '100%',+ cursor: 'col-resize',+ },+ vertical: {+ height: 1,+ width: '100%',+ cursor: 'row-resize',+ },+ // Zero-footprint mode: handle takes 0px in layout when no divider.+ // Hit area + pill use absolute positioning so they still work.+ noDividerHorizontal: {+ backgroundColor: 'transparent',+ width: 0,+ },+ noDividerVertical: {+ backgroundColor: 'transparent',+ height: 0,+ },+ handleHover: {+ backgroundColor: colorVars['--color-border'],+ },+ handleActive: {+ backgroundColor: colorVars['--color-border-emphasized'],+ },+ disabled: {+ cursor: 'default',+ pointerEvents: 'none',+ },++ // Wider invisible hit area — extends beyond the 1px line.+ hitArea: {+ position: 'absolute',+ zIndex: 1,+ touchAction: 'none',+ userSelect: 'none',+ },+ hitAreaHorizontal: {+ width: 'var(--resize-handle-hit-area, 16px)',+ top: 0,+ bottom: 0,+ left: '50%',+ transform: 'translateX(-50%)',+ cursor: 'col-resize',+ },+ hitAreaVertical: {+ height: 'var(--resize-handle-hit-area, 16px)',+ left: 0,+ right: 0,+ top: '50%',+ transform: 'translateY(-50%)',+ cursor: 'row-resize',+ },++ // Pill grip indicator — absolutely positioned so it's not constrained+ // by the 1px handle container. Without this, the vertical pill (3px tall)+ // gets squished to 1px by the flex layout of the 1px-tall handle.+ pill: {+ position: 'absolute',+ zIndex: 2,+ borderRadius: 2,+ backgroundColor: colorVars['--color-border'],+ transitionProperty: 'opacity, background-color',+ transitionDuration: durationVars['--duration-fast'],+ transitionTimingFunction: easeVars['--ease-standard'],+ },+ pillHorizontal: {+ width: 'var(--resize-handle-width, 3px)',+ height: 'var(--resize-handle-height, 32px)',+ // Centered on the 1px vertical line+ top: '50%',+ left: '50%',+ transform: 'translate(-50%, -50%)',+ },+ pillVertical: {+ height: 'var(--resize-handle-width, 3px)',+ width: 'var(--resize-handle-height, 32px)',+ // Centered on the 1px horizontal line+ top: '50%',+ left: '50%',+ transform: 'translate(-50%, -50%)',+ },+ pillHidden: {opacity: 0},+ pillVisible: {opacity: 1},+ pillHover: {+ opacity: 1,+ backgroundColor: colorVars['--color-border'],+ },+ pillActive: {+ opacity: 1,+ backgroundColor: colorVars['--color-border-emphasized'],+ },+});++export interface XDSResizeHandleProps extends Omit<+ HTMLAttributes<HTMLDivElement>,+ 'style' | 'className'+> {+ ref?: React.Ref<HTMLDivElement>;++ /**+ * Layout direction — determines cursor and indicator orientation.+ * @default 'horizontal'+ */+ direction?: 'horizontal' | 'vertical';++ /**+ * Reverse the drag direction. Use when the handle controls a panel+ * on the end/right/bottom side.+ * @default false+ */+ isReversed?: boolean;++ /**+ * Whether the handle is disabled (not interactive).+ * @default false+ */+ isDisabled?: boolean;++ /**+ * Show a 1px divider line. The line IS the handle — it takes only+ * 1px in the layout with a wider invisible hit area for interaction.+ * @default false+ */+ hasDivider?: boolean;++ /**+ * Show the pill grip indicator at rest. Set to `false` to only+ * reveal the pill on hover/focus.+ * @default true+ */+ isAlwaysVisible?: boolean;++ /**+ * Accessible label for the separator.+ * @default 'Resize handle'+ */+ label?: string;++ /** Resize props from useXDSResizable region. */+ resizable?: ResizableProps;++ /** Custom handle content. Overrides the default pill. */+ children?: ReactNode;++ /** StyleX styles override. */+ xstyle?: stylex.StyleXStyles;+}++export function XDSResizeHandle({+ direction = 'horizontal',+ isReversed = false,+ isDisabled = false,+ hasDivider = false,+ isAlwaysVisible = true,+ label = 'Resize handle',+ resizable,+ children,+ xstyle,+ ref,+ ...props+}: XDSResizeHandleProps) {+ const handleRef = useRef<HTMLDivElement>(null);+ const [isDragging, setIsDragging] = useState(false);+ const [isHovered, setIsHovered] = useState(false);+ const [isFocused, setIsFocused] = useState(false);+ const isHorizontal = direction === 'horizontal';+ const sign = isReversed ? -1 : 1;++ const getRTLMultiplier = useCallback((): number => {+ const el = handleRef.current;+ if (!el) return 1;+ return getComputedStyle(el).direction === 'rtl' ? -1 : 1;+ }, []);++ const isInteracting = isHovered || isFocused;++ // --- Pointer drag ---+ const handlePointerDown = useCallback(+ (e: React.PointerEvent) => {+ if (isDisabled || !resizable) return;+ e.preventDefault();+ e.stopPropagation();+ setIsDragging(true);+ resizable._onResizeStart();+ const startPos = isHorizontal ? e.clientX : e.clientY;+ const rtl = isHorizontal ? getRTLMultiplier() : 1;+ document.body.style.cursor = isHorizontal ? 'col-resize' : 'row-resize';+ document.body.style.userSelect = 'none';++ const onMove = (ev: PointerEvent) => {+ const currentPos = isHorizontal ? ev.clientX : ev.clientY;+ const delta = (currentPos - startPos) * rtl * sign;+ resizable._onResizeMove(delta);+ };+ const onUp = () => {+ cleanup();+ setIsDragging(false);+ resizable._onResizeEnd();+ document.body.style.cursor = '';+ document.body.style.userSelect = '';+ };+ const onCancel = () => {+ cleanup();+ setIsDragging(false);+ document.body.style.cursor = '';+ document.body.style.userSelect = '';+ };+ function cleanup() {+ window.removeEventListener('pointermove', onMove);+ window.removeEventListener('pointerup', onUp);+ window.removeEventListener('pointercancel', onCancel);+ }+ window.addEventListener('pointermove', onMove);+ window.addEventListener('pointerup', onUp);+ window.addEventListener('pointercancel', onCancel);+ },+ [isDisabled, resizable, isHorizontal, getRTLMultiplier, sign],+ );++ // --- Keyboard ---+ const handleKeyDown = useCallback(+ (e: React.KeyboardEvent) => {+ if (isDisabled || !resizable) return;+ const step = e.shiftKey ? KEYBOARD_LARGE_STEP : KEYBOARD_STEP;+ const rtl = isHorizontal ? getRTLMultiplier() : 1;++ switch (e.key) {+ case 'ArrowRight':+ case 'ArrowDown': {+ e.preventDefault();+ resizable._onResizeStart();+ resizable._onResizeMove(step * (isHorizontal ? rtl : 1) * sign);+ resizable._onResizeEnd();+ break;+ }+ case 'ArrowLeft':+ case 'ArrowUp': {+ e.preventDefault();+ resizable._onResizeStart();+ resizable._onResizeMove(-step * (isHorizontal ? rtl : 1) * sign);+ resizable._onResizeEnd();+ break;+ }+ case 'Home': {+ e.preventDefault();+ resizable._onResizeStart();+ resizable._onResizeMove(resizable._minSizePx - resizable._size);+ resizable._onResizeEnd();+ break;+ }+ case 'End': {+ e.preventDefault();+ if (resizable._maxSizePx !== Infinity) {+ resizable._onResizeStart();+ resizable._onResizeMove(resizable._maxSizePx - resizable._size);+ resizable._onResizeEnd();+ }+ break;+ }+ case 'Enter': {+ e.preventDefault();+ if (resizable._collapsible) {+ resizable._onResizeStart();+ resizable._onResizeMove(+ resizable._isCollapsed ? resizable._minSizePx : -resizable._size,+ );+ resizable._onResizeEnd();+ }+ break;+ }+ }+ },+ [isDisabled, resizable, isHorizontal, getRTLMultiplier, sign],+ );++ // --- Double-click collapse ---+ const handleDoubleClick = useCallback(() => {+ if (isDisabled || !resizable || !resizable._collapsible) return;+ resizable._onResizeStart();+ resizable._onResizeMove(+ resizable._isCollapsed ? resizable._minSizePx : -resizable._size,+ );+ resizable._onResizeEnd();+ }, [isDisabled, resizable]);++ // --- Cleanup on unmount ---+ useEffect(() => {+ return () => {+ if (isDragging) {+ document.body.style.cursor = '';+ document.body.style.userSelect = '';+ }+ };+ }, [isDragging]);++ // --- ARIA ---+ const ariaValueNow = resizable ? resizable._size : undefined;+ const ariaValueMin = resizable ? resizable._minSizePx : undefined;+ const ariaValueMax =+ resizable && resizable._maxSizePx !== Infinity+ ? resizable._maxSizePx+ : undefined;++ return (+ <div+ ref={node => {+ (handleRef as React.MutableRefObject<HTMLDivElement | null>).current =+ node;+ if (typeof ref === 'function') ref(node);+ else if (ref)+ (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;+ }}+ role="separator"+ aria-orientation={isHorizontal ? 'vertical' : 'horizontal'}+ aria-valuenow={ariaValueNow}+ aria-valuemin={ariaValueMin}+ aria-valuemax={ariaValueMax}+ aria-label={label}+ aria-disabled={isDisabled || undefined}+ tabIndex={isDisabled ? -1 : 0}+ onDoubleClick={handleDoubleClick}+ onFocus={() => setIsFocused(true)}+ onBlur={() => setIsFocused(false)}+ data-resizing={isDragging || undefined}+ {...mergeProps(+ xdsClassName('resize-handle'),+ stylex.props(+ styles.handle,+ isHorizontal ? styles.horizontal : styles.vertical,+ !hasDivider &&+ (isHorizontal+ ? styles.noDividerHorizontal+ : styles.noDividerVertical),+ hasDivider && isInteracting && !isDragging && styles.handleHover,+ hasDivider && isDragging && styles.handleActive,+ isDisabled && styles.disabled,+ xstyle,+ ),+ )}+ {...props}>+ {/* Wider invisible hit area for pointer interaction */}+ <div+ {...stylex.props(+ styles.hitArea,+ isHorizontal ? styles.hitAreaHorizontal : styles.hitAreaVertical,+ isDisabled && styles.disabled,+ )}+ onPointerDown={handlePointerDown}+ onPointerEnter={() => setIsHovered(true)}+ onPointerLeave={() => {+ if (!isDragging) setIsHovered(false);+ }}+ onKeyDown={handleKeyDown}+ />+ {/* Pill grip indicator */}+ {children ?? (+ <div+ {...stylex.props(+ styles.pill,+ isHorizontal ? styles.pillHorizontal : styles.pillVertical,+ isAlwaysVisible ? styles.pillVisible : styles.pillHidden,+ isInteracting && !isDragging && styles.pillHover,+ isDragging && styles.pillActive,+ )}+ />+ )}+ </div>+ );+}++XDSResizeHandle.displayName = 'XDSResizeHandle';diff --git a/packages/core/src/Resizable/index.ts b/packages/core/src/Resizable/index.tsnew file mode 100644index 0000000000..ef272cfa9c--- /dev/null+++ b/packages/core/src/Resizable/index.ts@@ -0,0 +1,20 @@+'use client';++/**+ * @file index.ts+ * @input Imports from useXDSResizable and XDSResizeHandle+ * @output Re-exports all public Resizable API+ * @position Package entry point for Resizable+ */++export {useXDSResizable} from './useXDSResizable';+export type {+ ResizableRegion,+ ResizableRegionConfig,+ ResizableProps,+ UseXDSResizableSingleConfig,+ UseXDSResizableMultiConfig,+} from './useXDSResizable';++export {XDSResizeHandle} from './XDSResizeHandle';+export type {XDSResizeHandleProps} from './XDSResizeHandle';diff --git a/packages/core/src/Resizable/useXDSResizable.ts b/packages/core/src/Resizable/useXDSResizable.tsnew file mode 100644index 0000000000..11c4d32adc--- /dev/null+++ b/packages/core/src/Resizable/useXDSResizable.ts@@ -0,0 +1,318 @@+'use client';++/**+ * @file useXDSResizable.ts+ * @input Resize configuration (defaultSize, minSizePx, maxSizePx, collapsible, snaps)+ * @output Hook return: size, isCollapsed, collapse/expand/resize methods, props for handle+ * @position Public hook; consumed by layout components via `resizable` prop+ */++import {useCallback, useEffect, useRef, useState} from 'react';++// =============================================================================+// Types+// =============================================================================++export interface ResizableRegionConfig {+ /** Default size in pixels, or percentage string (e.g. '20%'). */+ defaultSize?: number | string;+ /** Minimum size in pixels. @default 50 */+ minSizePx?: number;+ /** Maximum size in pixels. @default Infinity */+ maxSizePx?: number;+ /** Whether this region can collapse to 0. @default false */+ collapsible?: boolean;+ /** Size in px at which dragging triggers collapse. @default 40 */+ collapsedSize?: number;+ /** Pixel values to snap to during resize. */+ snaps?: number[];+ /** Cascade priority — lower number shrinks first. */+ shrinkOrder?: number;+}++export interface UseXDSResizableSingleConfig extends ResizableRegionConfig {+ /** Unique key for localStorage persistence. */+ autoSaveId?: string;+}++export interface UseXDSResizableMultiConfig {+ /** Layout direction. @default 'horizontal' */+ direction?: 'horizontal' | 'vertical';+ /** Named region configurations. */+ regions: Record<string, ResizableRegionConfig>;+ /** Unique key for localStorage persistence. */+ autoSaveId?: string;+}++export interface ResizableRegion {+ /** Current size in pixels. */+ size: number;+ /** Whether the region is currently collapsed. */+ isCollapsed: boolean;+ /** Collapse the region (if collapsible). */+ collapse: () => void;+ /** Expand from collapsed state. */+ expand: () => void;+ /** Resize to a specific pixel value. */+ resize: (size: number) => void;+ /** Props to pass to a component's `resizable` prop or XDSResizeHandle. */+ props: ResizableProps;+}++export interface ResizableProps {+ _size: number;+ // eslint-disable-next-line @xds/boolean-prop-naming+ _isCollapsed: boolean;+ _onResizeStart: () => void;+ _onResizeMove: (delta: number) => void;+ _onResizeEnd: () => void;+ _minSizePx: number;+ _maxSizePx: number;+ _snaps: number[];+ _collapsedSize: number;+ /** Whether the region supports collapsing. */+ // eslint-disable-next-line @xds/boolean-prop-naming+ _collapsible: boolean;+ _isResizableProps: true;+}++// =============================================================================+// Constants+// =============================================================================++const DEFAULT_MIN = 50;+const DEFAULT_COLLAPSED_SIZE = 40;+const STORAGE_PREFIX = 'xds-resizable:';++// =============================================================================+// Helpers+// =============================================================================++function clampSize(+ size: number,+ min: number,+ max: number,+ snaps: number[],+): number {+ const clamped = Math.min(max, Math.max(min, size));++ // When snap points are defined, always snap to the nearest one.+ // No intermediate positions — the panel can only rest at snap values.+ if (snaps.length > 0) {+ let nearest = snaps[0];+ let nearestDist = Math.abs(clamped - nearest);+ for (let i = 1; i < snaps.length; i++) {+ const dist = Math.abs(clamped - snaps[i]);+ if (dist < nearestDist) {+ nearest = snaps[i];+ nearestDist = dist;+ }+ }+ return Math.min(max, Math.max(min, nearest));+ }++ return clamped;+}++function loadPersistedSize(key: string): number | null {+ if (typeof window === 'undefined') return null;+ try {+ const raw = localStorage.getItem(STORAGE_PREFIX + key);+ if (raw != null) {+ const parsed = JSON.parse(raw);+ if (typeof parsed === 'number') return parsed;+ }+ } catch {+ /* ignore */+ }+ return null;+}++function persistSize(key: string, size: number): void {+ if (typeof window === 'undefined') return;+ try {+ localStorage.setItem(STORAGE_PREFIX + key, JSON.stringify(size));+ } catch {+ /* ignore */+ }+}++function resolveDefaultSize(defaultSize: number | string | undefined): number {+ if (defaultSize == null) return 250;+ if (typeof defaultSize === 'number') return defaultSize;+ if (defaultSize.endsWith('%')) {+ const pct = parseFloat(defaultSize);+ if (!isNaN(pct)) {+ const approx = typeof window !== 'undefined' ? window.innerWidth : 1200;+ return Math.round((pct / 100) * approx);+ }+ }+ return 250;+}++// =============================================================================+// Single-region hook+// =============================================================================++function useSingleResizable(+ config: UseXDSResizableSingleConfig,+): ResizableRegion {+ const {+ defaultSize,+ minSizePx = DEFAULT_MIN,+ maxSizePx = Infinity,+ collapsible = false,+ collapsedSize = DEFAULT_COLLAPSED_SIZE,+ snaps = [],+ autoSaveId,+ } = config;++ const resolvedDefault = resolveDefaultSize(defaultSize);+ const persisted = autoSaveId ? loadPersistedSize(autoSaveId) : null;+ const initial = persisted ?? resolvedDefault;++ const [size, setSize] = useState(() =>+ clampSize(initial, minSizePx, maxSizePx, snaps),+ );+ const [isCollapsed, setIsCollapsed] = useState(+ () => persisted === 0 && collapsible,+ );+ const preCollapseSize = useRef(size);+ const dragStartSize = useRef(size);++ useEffect(() => {+ if (autoSaveId) {+ persistSize(autoSaveId, isCollapsed ? 0 : size);+ }+ }, [size, isCollapsed, autoSaveId]);++ const collapse = useCallback(() => {+ if (!collapsible) return;+ preCollapseSize.current = size;+ setIsCollapsed(true);+ setSize(0);+ }, [collapsible, size]);++ const expand = useCallback(() => {+ setIsCollapsed(false);+ const restored = preCollapseSize.current || resolvedDefault;+ setSize(clampSize(restored, minSizePx, maxSizePx, snaps));+ }, [resolvedDefault, minSizePx, maxSizePx, snaps]);++ const resize = useCallback(+ (newSize: number) => {+ setSize(clampSize(newSize, minSizePx, maxSizePx, snaps));+ setIsCollapsed(false);+ },+ [minSizePx, maxSizePx, snaps],+ );++ const onResizeStart = useCallback(() => {+ dragStartSize.current = isCollapsed ? 0 : size;+ }, [size, isCollapsed]);++ const onResizeMove = useCallback(+ (delta: number) => {+ const raw = dragStartSize.current + delta;+ if (collapsible && raw < collapsedSize) {+ if (!isCollapsed) preCollapseSize.current = size;+ setIsCollapsed(true);+ setSize(0);+ return;+ }+ if (isCollapsed && raw >= collapsedSize) {+ setIsCollapsed(false);+ }+ setSize(clampSize(raw, minSizePx, maxSizePx, snaps));+ },+ [+ collapsible,+ collapsedSize,+ isCollapsed,+ size,+ minSizePx,+ maxSizePx,+ snaps,+ ],+ );++ const onResizeEnd = useCallback(() => {+ // Sizes already committed during move+ }, []);++ const props: ResizableProps = {+ _size: isCollapsed ? 0 : size,+ _isCollapsed: isCollapsed,+ _onResizeStart: onResizeStart,+ _onResizeMove: onResizeMove,+ _onResizeEnd: onResizeEnd,+ _minSizePx: minSizePx,+ _maxSizePx: maxSizePx,+ _snaps: snaps,+ _collapsedSize: collapsedSize,+ _collapsible: collapsible,+ _isResizableProps: true,+ };++ return {+ size: isCollapsed ? 0 : size,+ isCollapsed,+ collapse,+ expand,+ resize,+ props,+ };+}++// =============================================================================+// Multi-region hook+// =============================================================================++/**+ * Multi-region hook — delegates to individual useSingleResizable calls.+ * Region keys must be stable across renders (same count and order).+ * This is enforced by the caller providing a static `regions` object.+ */+function useMultiResizable(+ config: UseXDSResizableMultiConfig,+): Record<string, ResizableRegion> {+ const {regions, autoSaveId} = config;++ // Stable key order — callers must not change region keys between renders.+ // Using Object.keys is safe here because the regions object shape is static.+ const regionEntries = Object.entries(regions);++ // Call hooks unconditionally in stable order (same count every render).++ const regionResults = regionEntries.map(([key, regionConfig]) =>+ useSingleResizable({+ ...regionConfig,+ autoSaveId: autoSaveId ? `${autoSaveId}:${key}` : undefined,+ }),+ );++ const result: Record<string, ResizableRegion> = {};+ regionEntries.forEach(([key], i) => {+ result[key] = regionResults[i];+ });+ return result;+}++// =============================================================================+// Public API+// =============================================================================++export function useXDSResizable(+ config: UseXDSResizableSingleConfig,+): ResizableRegion;+export function useXDSResizable(+ config: UseXDSResizableMultiConfig,+): Record<string, ResizableRegion>;+export function useXDSResizable(+ config: UseXDSResizableSingleConfig | UseXDSResizableMultiConfig,+): ResizableRegion | Record<string, ResizableRegion> {+ if ('regions' in config) {+ return useMultiResizable(config);+ }+ return useSingleResizable(config);+}diff --git a/packages/core/src/SideNav/XDSSideNav.tsx b/packages/core/src/SideNav/XDSSideNav.tsxindex 8ed1565843..ffdb63e878 100644--- a/packages/core/src/SideNav/XDSSideNav.tsx+++ b/packages/core/src/SideNav/XDSSideNav.tsx@@ -23,13 +23,21 @@ import {useCallback, useState, type ReactNode} from 'react';import type {XDSBaseProps} from '../XDSBaseProps';import * as stylex from '@stylexjs/stylex';import type {StyleXStyles} from '@stylexjs/stylex';-import {borderVars, colorVars, durationVars, easeVars, spacingVars} from '../theme/tokens.stylex';+import {+ borderVars,+ colorVars,+ durationVars,+ easeVars,+ spacingVars,+} from '../theme/tokens.stylex';import {xdsClassName, mergeProps} from '../utils';import {XDSSideNavCollapseContext} from './XDSSideNavCollapseContext';import {XDSSideNavCollapseButton} from './XDSSideNavCollapseButton';import {useXDSSideNavRenderMode} from './XDSSideNavRenderContext';import {XDSMobileNav} from '../MobileNav/XDSMobileNav';import {useResizable} from './useResizable';+import type {ResizableProps} from '../Resizable/useXDSResizable';+import {XDSResizeHandle} from '../Resizable/XDSResizeHandle';// =============================================================================// Styles@@ -245,6 +253,7 @@ export interface XDSSideNavProps extends XDSBaseProps<HTMLElement> {* - Object — configured:* - `defaultWidth` — initial width in pixels (default: 260)* - `onWidthChange` — called when user finishes resizing+ * - `ResizableProps` — driven by `useXDSResizable()` hook from `@xds/core/Resizable`** @default false*/@@ -253,7 +262,8 @@ export interface XDSSideNavProps extends XDSBaseProps<HTMLElement> {| {defaultWidth?: number;onWidthChange?: (width: number) => void;- };+ }+ | ResizableProps;/*** Enables collapse behavior. The sidebar can be collapsed to a narrow@@ -324,8 +334,13 @@ export function XDSSideNav({const controlledCollapsed = collapsibleConfig.isCollapsed;const onCollapsedChange = collapsibleConfig.onCollapsedChange;- // Resizable config- const resizableConfig = typeof resizable === 'object' ? resizable : {};+ // Resizable config — detect if using new useXDSResizable() hook props+ const isResizableHook =+ typeof resizable === 'object' &&+ resizable !== null &&+ '_isResizableProps' in resizable;+ const resizableConfig =+ !isResizableHook && typeof resizable === 'object' ? resizable : {};const isResizable = !!resizable;// Collapse state (controlled + uncontrolled)@@ -349,20 +364,32 @@ export function XDSSideNav({};// =========================================================================- // Resize — extracted into useResizable hook+ // Resize — use new ResizableProps when available, else legacy hook// =========================================================================- const {- width,- containerRef,- showHandle: showResizeHandle,- handleProps: resizeHandleProps,- isHandleHovered,- } = useResizable({- enabled: isResizable,+ const legacyResize = useResizable({+ enabled: isResizable && !isResizableHook,config: resizableConfig,collapsed,});+ // When using the new hook, derive width/handle state from ResizableProps+ const resizableHookProps = isResizableHook+ ? (resizable as ResizableProps)+ : null;+ const width = resizableHookProps+ ? resizableHookProps._size+ : legacyResize.width;+ const showResizeHandle = resizableHookProps+ ? !collapsed+ : legacyResize.showHandle;+ const resizeHandleProps = resizableHookProps+ ? null+ : legacyResize.handleProps;+ const isHandleHovered = resizableHookProps+ ? false+ : legacyResize.isHandleHovered;+ const containerRef = resizableHookProps ? null : legacyResize.containerRef;+// Render mode — when inside AppShell mobile layout, render subsetsconst renderMode = useXDSSideNavRenderMode();@@ -499,11 +526,32 @@ export function XDSSideNav({</nav>);- // Wrap in resizable container when isResizable- const content = showResizeHandle ? (+ // Wrap in resizable container when using legacy resize (with built-in handle).+ // When using new ResizableProps, wrap in a flex container with the new+ // XDSResizeHandle. The container ensures the handle sits outside the nav's+ // overflow boundary (AppShell wraps sideNav in a LayoutPanel with overflow:clip).+ // When using legacy resize, use the old built-in drag handle.+ const content = resizableHookProps ? (+ <div+ {...mergeProps(stylex.props(styles.resizableContainer), undefined, {+ width: collapsed ? undefined : width,+ })}>+ {navElement}+ {!collapsed && (+ <XDSResizeHandle+ direction="horizontal"+ hasDivider+ resizable={resizableHookProps}+ label="Resize sidebar"+ />+ )}+ </div>+ ) : showResizeHandle ? (<divref={containerRef}- {...mergeProps(stylex.props(styles.resizableContainer), {style: {width}})}>+ {...mergeProps(stylex.props(styles.resizableContainer), {+ style: {width},+ })}>{navElement}<divdata-testid="xds-sidenav-resize-handle"diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 8b26ed9c30..9b1036b4a2 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -33,6 +33,7 @@ export * from './CheckboxInput';export * from './CheckboxList';export * from './Collapsible';export * from './RadioList';+export * from './Resizable';export * from './Divider';export * from './EmptyState';export * from './Link';