Skip to content

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

TypeScript

refactor: reduce CommandPalette surface area, extract XDSKbd, fix Dialog integration (#462)

Cindy Zhangf9f055d5381b
diff --git a/apps/storybook/stories/CommandPalette.stories.tsx b/apps/storybook/stories/CommandPalette.stories.tsx
index 62b3f79a98..b7262bec4e 100644
--- a/apps/storybook/stories/CommandPalette.stories.tsx
+++ b/apps/storybook/stories/CommandPalette.stories.tsx
@@ -6,15 +6,12 @@ import {
XDSCommandPaletteList,
XDSCommandPaletteItem,
XDSCommandPaletteGroup,
- XDSCommandPaletteEmpty,
- XDSCommandPaletteShortcut,
- XDSCommandPaletteFooter,
- XDSCommandPaletteSeparator,
- XDSCommandPaletteLoading,
XDSCommandPaletteProvider,
useXDSCommandPaletteRegister,
useXDSCommandPalette,
} from '@xds/core/CommandPalette';
+import {XDSKbd} from '@xds/core/Kbd';
+import {XDSDivider} from '@xds/core/Divider';
import {XDSIcon} from '@xds/core/Icon';
import {XDSButton} from '@xds/core/Button';
@@ -58,14 +55,14 @@ export const Composable: Story = {
onSelect={() => setIsShown(false)}>
<XDSIcon icon="home" size="sm" />
<span style={{flex: 1}}>Go Home</span>
- <XDSCommandPaletteShortcut keys="mod+h" />
+ <XDSKbd keys="mod+h" />
</XDSCommandPaletteItem>
<XDSCommandPaletteItem
value="settings"
onSelect={() => setIsShown(false)}>
<XDSIcon icon="settings" size="sm" />
<span style={{flex: 1}}>Settings</span>
- <XDSCommandPaletteShortcut keys="mod+," />
+ <XDSKbd keys="mod+," />
</XDSCommandPaletteItem>
<XDSCommandPaletteItem
value="profile"
@@ -74,30 +71,24 @@ export const Composable: Story = {
<span style={{flex: 1}}>Profile</span>
</XDSCommandPaletteItem>
</XDSCommandPaletteGroup>
- <XDSCommandPaletteSeparator />
+ <XDSDivider />
<XDSCommandPaletteGroup heading="Actions">
<XDSCommandPaletteItem
value="new-file"
onSelect={() => setIsShown(false)}>
<XDSIcon icon="add" size="sm" />
<span style={{flex: 1}}>New File</span>
- <XDSCommandPaletteShortcut keys="mod+n" />
+ <XDSKbd keys="mod+n" />
</XDSCommandPaletteItem>
<XDSCommandPaletteItem
value="save"
onSelect={() => setIsShown(false)}>
<XDSIcon icon="check" size="sm" />
<span style={{flex: 1}}>Save</span>
- <XDSCommandPaletteShortcut keys="mod+s" />
+ <XDSKbd keys="mod+s" />
</XDSCommandPaletteItem>
</XDSCommandPaletteGroup>
- <XDSCommandPaletteEmpty>No results found</XDSCommandPaletteEmpty>
</XDSCommandPaletteList>
- <XDSCommandPaletteFooter>
- <span>↑↓ Navigate</span>
- <span>↵ Select</span>
- <span>Esc Close</span>
- </XDSCommandPaletteFooter>
</XDSCommandPalette>
</>
);
@@ -191,7 +182,6 @@ export const Filtering: Story = {
{item.label}
</XDSCommandPaletteItem>
))}
- <XDSCommandPaletteEmpty>No pages found</XDSCommandPaletteEmpty>
</XDSCommandPaletteList>
</XDSCommandPalette>
</>
@@ -274,26 +264,3 @@ export const Provider: Story = {
);
},
};
-
-/**
- * Loading state for async command fetching.
- */
-export const Loading: Story = {
- render: function LoadingStory() {
- const [isShown, setIsShown] = useState(false);
-
- return (
- <>
- <XDSButton label="Open Palette" onClick={() => setIsShown(true)} />
- <XDSCommandPalette
- isShown={isShown}
- onOpenChange={open => setIsShown(open)}>
- <XDSCommandPaletteInput placeholder="Search..." />
- <XDSCommandPaletteList>
- <XDSCommandPaletteLoading>Searching...</XDSCommandPaletteLoading>
- </XDSCommandPaletteList>
- </XDSCommandPalette>
- </>
- );
- },
-};
diff --git a/packages/core/src/CommandPalette/README.md b/packages/core/src/CommandPalette/README.md
index ff8e1e392b..a015f4a5ce 100644
--- a/packages/core/src/CommandPalette/README.md
+++ b/packages/core/src/CommandPalette/README.md
@@ -23,11 +23,6 @@ Three layers, each building on the last:
| `XDSCommandPaletteList.tsx` | Scrollable results container (listbox) |
| `XDSCommandPaletteItem.tsx` | Selectable item (option) |
| `XDSCommandPaletteGroup.tsx` | Visual grouping with heading |
-| `XDSCommandPaletteEmpty.tsx` | Empty state |
-| `XDSCommandPaletteLoading.tsx` | Loading indicator |
-| `XDSCommandPaletteSeparator.tsx` | Visual divider (wraps XDSDivider) |
-| `XDSCommandPaletteShortcut.tsx` | Keyboard shortcut display |
-| `XDSCommandPaletteFooter.tsx` | Footer bar |
| `XDSCommandPaletteProvider.tsx` | Registry provider + hooks |
| `useXDSCommandPaletteHistory.ts` | Optional history hook |
@@ -43,15 +38,10 @@ Three layers, each building on the last:
<XDSCommandPaletteItem value="home" onSelect={() => navigate('/')}>
<XDSIcon icon="home" size="sm" />
<span>Go Home</span>
- <XDSCommandPaletteShortcut keys="mod+h" />
+ <XDSKbd keys="mod+h" />
</XDSCommandPaletteItem>
</XDSCommandPaletteGroup>
- <XDSCommandPaletteEmpty>No results</XDSCommandPaletteEmpty>
</XDSCommandPaletteList>
- <XDSCommandPaletteFooter>
- <span>↑↓ Navigate</span>
- <span>↵ Select</span>
- </XDSCommandPaletteFooter>
</XDSCommandPalette>
```
diff --git a/packages/core/src/CommandPalette/XDSCommandPalette.test.tsx b/packages/core/src/CommandPalette/XDSCommandPalette.test.tsx
index f8c66ad4cc..de0ec84616 100644
--- a/packages/core/src/CommandPalette/XDSCommandPalette.test.tsx
+++ b/packages/core/src/CommandPalette/XDSCommandPalette.test.tsx
@@ -12,10 +12,7 @@ import {XDSCommandPaletteInput} from './XDSCommandPaletteInput';
import {XDSCommandPaletteList} from './XDSCommandPaletteList';
import {XDSCommandPaletteItem} from './XDSCommandPaletteItem';
import {XDSCommandPaletteGroup} from './XDSCommandPaletteGroup';
-import {XDSCommandPaletteEmpty} from './XDSCommandPaletteEmpty';
-import {XDSCommandPaletteShortcut} from './XDSCommandPaletteShortcut';
-import {XDSCommandPaletteFooter} from './XDSCommandPaletteFooter';
-import {XDSCommandPaletteLoading} from './XDSCommandPaletteLoading';
+import {XDSKbd} from '../Kbd';
import {useXDSCommandPaletteHistory} from './useXDSCommandPaletteHistory';
import {defaultFilter} from './filter';
@@ -69,9 +66,9 @@ describe('defaultFilter', () => {
// Shortcut display tests
// =============================================================================
-describe('XDSCommandPaletteShortcut', () => {
+describe('XDSKbd', () => {
it('renders modifier keys as symbols', () => {
- const {container} = render(<XDSCommandPaletteShortcut keys="mod+k" />);
+ const {container} = render(<XDSKbd keys="mod+k" />);
const kbds = container.querySelectorAll('kbd');
expect(kbds).toHaveLength(2);
expect(kbds[0].textContent).toBe('\u2318'); // ⌘
@@ -79,9 +76,7 @@ describe('XDSCommandPaletteShortcut', () => {
});
it('renders multi-key shortcuts', () => {
- const {container} = render(
- <XDSCommandPaletteShortcut keys="mod+shift+p" />,
- );
+ const {container} = render(<XDSKbd keys="mod+shift+p" />);
const kbds = container.querySelectorAll('kbd');
expect(kbds).toHaveLength(3);
});
@@ -129,7 +124,7 @@ describe('XDSCommandPalette (composable)', () => {
<XDSCommandPalette isOpen={true} onOpenChange={vi.fn()}>
<XDSCommandPaletteInput />
<XDSCommandPaletteList>
- <XDSCommandPaletteEmpty>No results found</XDSCommandPaletteEmpty>
+ <div role="status">No results found</div>
</XDSCommandPaletteList>
</XDSCommandPalette>,
);
@@ -141,7 +136,9 @@ describe('XDSCommandPalette (composable)', () => {
<XDSCommandPalette isOpen={true} onOpenChange={vi.fn()}>
<XDSCommandPaletteInput />
<XDSCommandPaletteList>
- <XDSCommandPaletteLoading>Searching...</XDSCommandPaletteLoading>
+ <div role="status" aria-live="polite">
+ Searching...
+ </div>
</XDSCommandPaletteList>
</XDSCommandPalette>,
);
@@ -157,9 +154,9 @@ describe('XDSCommandPalette (composable)', () => {
Test
</XDSCommandPaletteItem>
</XDSCommandPaletteList>
- <XDSCommandPaletteFooter>
+ <div>
<span>↵ Select</span>
- </XDSCommandPaletteFooter>
+ </div>
</XDSCommandPalette>,
);
expect(screen.getByText('↵ Select')).toBeInTheDocument();
diff --git a/packages/core/src/CommandPalette/XDSCommandPalette.tsx b/packages/core/src/CommandPalette/XDSCommandPalette.tsx
index 8addab5f98..831baafa6c 100644
--- a/packages/core/src/CommandPalette/XDSCommandPalette.tsx
+++ b/packages/core/src/CommandPalette/XDSCommandPalette.tsx
@@ -21,16 +21,17 @@ import {
type ReactNode,
} from 'react';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {XDSDialog} from '../Dialog';
import {CommandPaletteContext} from './CommandPaletteContext';
import {defaultFilter} from './filter';
import type {CommandPaletteFilterFn} from './types';
const styles = stylex.create({
- dialog: {
- // Override dialog defaults for command palette appearance
+ content: {
+ display: 'flex',
+ flexDirection: 'column',
overflow: 'hidden',
+ height: '100%',
},
});
@@ -89,11 +90,6 @@ export interface XDSCommandPaletteProps {
*/
maxHeight?: number | string;
- /**
- * StyleX overrides for the dialog container.
- */
- xstyle?: StyleXStyles;
-
/**
* Composable content: XDSCommandPaletteInput, XDSCommandPaletteList, etc.
*
@@ -115,12 +111,12 @@ export interface XDSCommandPaletteProps {
/**
* Command palette root component.
*
- * Composes with XDSDialog for modal behavior and provides context
- * for composable sub-components (Input, List, Item, Group, etc.).
+ * Composes with XDSDialog for modal behavior (top layer, backdrop,
+ * focus trapping, dismiss on Escape/backdrop click) and provides
+ * context for composable sub-components (Input, List, Item, Group).
*
- * Supports two usage patterns:
- * 1. Composable (Layer 1): Render sub-components directly as children
- * 2. Provider (Layer 2): Use XDSCommandPaletteProvider for distributed command registration
+ * Positioned at top-center of the viewport, matching the standard
+ * command palette convention (Cmd+K in VS Code, Linear, etc.).
*/
export function XDSCommandPalette({
isOpen,
@@ -132,7 +128,6 @@ export function XDSCommandPalette({
label = 'Command palette',
width = 640,
maxHeight = 480,
- xstyle,
children,
}: XDSCommandPaletteProps) {
const listId = useId();
@@ -220,11 +215,11 @@ export function XDSCommandPalette({
onOpenChange={handleOpenChange}
width={width}
maxHeight={maxHeight}
+ position={{top: '15vh'}}
purpose="info"
- aria-label={label}
- {...stylex.props(styles.dialog, xstyle)}>
+ aria-label={label}>
<CommandPaletteContext.Provider value={contextValue}>
- {children}
+ <div {...stylex.props(styles.content)}>{children}</div>
</CommandPaletteContext.Provider>
</XDSDialog>
);
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteEmpty.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteEmpty.tsx
deleted file mode 100644
index c5d6f255ca..0000000000
--- a/packages/core/src/CommandPalette/XDSCommandPaletteEmpty.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * @file XDSCommandPaletteEmpty.tsx
- * @input Uses React, StyleX
- * @output Exports XDSCommandPaletteEmpty component
- * @position Sub-component; shown when no results match
- */
-
-import type {ReactNode} from 'react';
-import * as stylex from '@stylexjs/stylex';
-import {
- colorVars,
- spacingVars,
- textSizeVars,
- typographyVars,
-} from '../theme/tokens.stylex';
-
-const styles = stylex.create({
- empty: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- paddingBlock: spacingVars['--spacing-6'],
- paddingInline: spacingVars['--spacing-4'],
- fontFamily: typographyVars['--font-body'],
- fontSize: textSizeVars['--text-sm'],
- color: colorVars['--color-text-secondary'],
- userSelect: 'none',
- },
-});
-
-export interface XDSCommandPaletteEmptyProps {
- /** Content to display when no results are found. */
- children: ReactNode;
-}
-
-/**
- * Empty state shown when no command palette items match the search.
- */
-export function XDSCommandPaletteEmpty({children}: XDSCommandPaletteEmptyProps) {
- return (
- <div role="status" {...stylex.props(styles.empty)}>
- {children}
- </div>
- );
-}
-
-XDSCommandPaletteEmpty.displayName = 'XDSCommandPaletteEmpty';
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteFooter.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteFooter.tsx
deleted file mode 100644
index 71dd3ae64c..0000000000
--- a/packages/core/src/CommandPalette/XDSCommandPaletteFooter.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * @file XDSCommandPaletteFooter.tsx
- * @input Uses React, StyleX
- * @output Exports XDSCommandPaletteFooter component
- * @position Sub-component; footer bar with hints
- */
-
-import type {ReactNode} from 'react';
-import * as stylex from '@stylexjs/stylex';
-import {
- colorVars,
- spacingVars,
- textSizeVars,
- typographyVars,
-} from '../theme/tokens.stylex';
-
-const styles = stylex.create({
- footer: {
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-4'],
- paddingInline: spacingVars['--spacing-4'],
- paddingBlock: spacingVars['--spacing-2'],
- borderTopWidth: '1px',
- borderTopStyle: 'solid',
- borderTopColor: colorVars['--color-divider'],
- fontFamily: typographyVars['--font-body'],
- fontSize: textSizeVars['--text-xsm'],
- color: colorVars['--color-text-secondary'],
- userSelect: 'none',
- },
-});
-
-export interface XDSCommandPaletteFooterProps {
- /** Footer content — typically keyboard navigation hints. */
- children: ReactNode;
-}
-
-/**
- * Footer bar for the command palette.
- * Typically shows keyboard navigation hints.
- *
- * @example
- * ```
- * <XDSCommandPaletteFooter>
- * <span>↑↓ Navigate</span>
- * <span>↵ Select</span>
- * <span>Esc Close</span>
- * </XDSCommandPaletteFooter>
- * ```
- */
-export function XDSCommandPaletteFooter({children}: XDSCommandPaletteFooterProps) {
- return (
- <div {...stylex.props(styles.footer)}>
- {children}
- </div>
- );
-}
-
-XDSCommandPaletteFooter.displayName = 'XDSCommandPaletteFooter';
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteItem.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteItem.tsx
index 76c0552dfd..82c0349ef8 100644
--- a/packages/core/src/CommandPalette/XDSCommandPaletteItem.tsx
+++ b/packages/core/src/CommandPalette/XDSCommandPaletteItem.tsx
@@ -105,7 +105,7 @@ export interface XDSCommandPaletteItemProps {
* <XDSCommandPaletteItem value="settings" onSelect={() => navigate("/settings")}>
* <XDSIcon icon="settings" size="sm" />
* <span>Settings</span>
- * <XDSCommandPaletteShortcut keys="mod+," />
+ * <XDSKbd keys="mod+," />
* </XDSCommandPaletteItem>
* ```
*/
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteLoading.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteLoading.tsx
deleted file mode 100644
index fdd25e4496..0000000000
--- a/packages/core/src/CommandPalette/XDSCommandPaletteLoading.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * @file XDSCommandPaletteLoading.tsx
- * @input Uses React, StyleX, XDSSpinner
- * @output Exports XDSCommandPaletteLoading component
- * @position Sub-component; loading indicator
- */
-
-import type {ReactNode} from 'react';
-import * as stylex from '@stylexjs/stylex';
-import {
- colorVars,
- spacingVars,
- textSizeVars,
- typographyVars,
-} from '../theme/tokens.stylex';
-
-const styles = stylex.create({
- loading: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-4'],
- paddingInline: spacingVars['--spacing-4'],
- fontFamily: typographyVars['--font-body'],
- fontSize: textSizeVars['--text-sm'],
- color: colorVars['--color-text-secondary'],
- },
-});
-
-export interface XDSCommandPaletteLoadingProps {
- /** Loading content. */
- children?: ReactNode;
-}
-
-/**
- * Loading indicator for async command fetching.
- */
-export function XDSCommandPaletteLoading({
- children = 'Loading...',
-}: XDSCommandPaletteLoadingProps) {
- return (
- <div role="status" aria-live="polite" {...stylex.props(styles.loading)}>
- {children}
- </div>
- );
-}
-
-XDSCommandPaletteLoading.displayName = 'XDSCommandPaletteLoading';
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteProvider.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteProvider.tsx
index 1a237c4e42..d7a5b4c1d2 100644
--- a/packages/core/src/CommandPalette/XDSCommandPaletteProvider.tsx
+++ b/packages/core/src/CommandPalette/XDSCommandPaletteProvider.tsx
@@ -26,12 +26,14 @@ import {XDSCommandPaletteInput} from './XDSCommandPaletteInput';
import {XDSCommandPaletteList} from './XDSCommandPaletteList';
import {XDSCommandPaletteItem} from './XDSCommandPaletteItem';
import {XDSCommandPaletteGroup} from './XDSCommandPaletteGroup';
-import {XDSCommandPaletteEmpty} from './XDSCommandPaletteEmpty';
-import {XDSCommandPaletteShortcut} from './XDSCommandPaletteShortcut';
-import {XDSCommandPaletteFooter} from './XDSCommandPaletteFooter';
-import {XDSCommandPaletteLoading} from './XDSCommandPaletteLoading';
+import {XDSKbd} from '../Kbd';
import * as stylex from '@stylexjs/stylex';
-import {colorVars, textSizeVars} from '../theme/tokens.stylex';
+import {
+ colorVars,
+ spacingVars,
+ textSizeVars,
+ typographyVars,
+} from '../theme/tokens.stylex';
import {XDSIcon} from '../Icon';
import type {XDSCommand, CommandPaletteFilterFn} from './types';
@@ -315,11 +317,11 @@ export function XDSCommandPaletteProvider({
// Default footer with keyboard hints
const defaultFooter = (
- <XDSCommandPaletteFooter>
+ <div {...stylex.props(providerStyles.footer)}>
<span>↑↓ Navigate</span>
<span>↵ Select</span>
<span>Esc Close</span>
- </XDSCommandPaletteFooter>
+ </div>
);
return (
@@ -346,9 +348,18 @@ export function XDSCommandPaletteProvider({
</XDSCommandPaletteGroup>
),
)}
- {isFetching && <XDSCommandPaletteLoading />}
+ {isFetching && (
+ <div
+ role="status"
+ aria-live="polite"
+ {...stylex.props(providerStyles.loading)}>
+ Loading...
+ </div>
+ )}
{!isFetching && allCommands.length === 0 && (
- <XDSCommandPaletteEmpty>{emptyContent}</XDSCommandPaletteEmpty>
+ <div role="status" {...stylex.props(providerStyles.empty)}>
+ {emptyContent}
+ </div>
)}
</XDSCommandPaletteList>
{footer ?? defaultFooter}
@@ -363,7 +374,7 @@ XDSCommandPaletteProvider.displayName = 'XDSCommandPaletteProvider';
// Default command item renderer
// =============================================================================
-const commandItemStyles = stylex.create({
+const providerStyles = stylex.create({
label: {
flex: 1,
},
@@ -371,6 +382,42 @@ const commandItemStyles = stylex.create({
color: colorVars['--color-text-secondary'],
fontSize: textSizeVars['--text-sm'],
},
+ empty: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ paddingBlock: spacingVars['--spacing-6'],
+ paddingInline: spacingVars['--spacing-4'],
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-sm'],
+ color: colorVars['--color-text-secondary'],
+ userSelect: 'none',
+ },
+ loading: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: spacingVars['--spacing-2'],
+ paddingBlock: spacingVars['--spacing-4'],
+ paddingInline: spacingVars['--spacing-4'],
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-sm'],
+ color: colorVars['--color-text-secondary'],
+ },
+ footer: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-4'],
+ paddingInline: spacingVars['--spacing-4'],
+ paddingBlock: spacingVars['--spacing-2'],
+ borderTopWidth: '1px',
+ borderTopStyle: 'solid',
+ borderTopColor: colorVars['--color-divider'],
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-xsm'],
+ color: colorVars['--color-text-secondary'],
+ userSelect: 'none',
+ },
});
function CommandItem({command}: {command: XDSCommand}) {
@@ -394,15 +441,13 @@ function CommandItem({command}: {command: XDSCommand}) {
keywords={command.keywords}
isDisabled={command.isDisabled}>
{command.icon && <XDSIcon icon={command.icon} size="sm" />}
- <span {...stylex.props(commandItemStyles.label)}>{command.label}</span>
+ <span {...stylex.props(providerStyles.label)}>{command.label}</span>
{command.description && (
- <span {...stylex.props(commandItemStyles.description)}>
+ <span {...stylex.props(providerStyles.description)}>
{command.description}
</span>
)}
- {command.shortcut && (
- <XDSCommandPaletteShortcut keys={command.shortcut} />
- )}
+ {command.shortcut && <XDSKbd keys={command.shortcut} />}
</XDSCommandPaletteItem>
);
}
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteSeparator.tsx b/packages/core/src/CommandPalette/XDSCommandPaletteSeparator.tsx
deleted file mode 100644
index 1f36b5656d..0000000000
--- a/packages/core/src/CommandPalette/XDSCommandPaletteSeparator.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * @file XDSCommandPaletteSeparator.tsx
- * @input Uses XDSDivider
- * @output Exports XDSCommandPaletteSeparator component
- * @position Sub-component; visual divider between groups
- */
-
-import * as stylex from '@stylexjs/stylex';
-import {spacingVars} from '../theme/tokens.stylex';
-import {XDSDivider} from '../Divider';
-
-const styles = stylex.create({
- separator: {
- marginBlock: spacingVars['--spacing-1'],
- },
-});
-
-/**
- * Visual separator between command palette groups.
- * Uses XDSDivider internally for theming/swizzle compatibility.
- */
-export function XDSCommandPaletteSeparator() {
- return <XDSDivider xstyle={styles.separator} />;
-}
-
-XDSCommandPaletteSeparator.displayName = 'XDSCommandPaletteSeparator';
diff --git a/packages/core/src/CommandPalette/index.ts b/packages/core/src/CommandPalette/index.ts
index c901c32f08..60b8e3b3bd 100644
--- a/packages/core/src/CommandPalette/index.ts
+++ b/packages/core/src/CommandPalette/index.ts
@@ -7,7 +7,7 @@
* SYNC: When modified, update /packages/core/src/CommandPalette/README.md
*/
-// Layer 1: Composable primitives
+// Layer 1: Composable primitives — the CommandPalette family
export {XDSCommandPalette} from './XDSCommandPalette';
export type {XDSCommandPaletteProps} from './XDSCommandPalette';
@@ -23,21 +23,7 @@ export type {XDSCommandPaletteItemProps} from './XDSCommandPaletteItem';
export {XDSCommandPaletteGroup} from './XDSCommandPaletteGroup';
export type {XDSCommandPaletteGroupProps} from './XDSCommandPaletteGroup';
-export {XDSCommandPaletteEmpty} from './XDSCommandPaletteEmpty';
-export type {XDSCommandPaletteEmptyProps} from './XDSCommandPaletteEmpty';
-
-export {XDSCommandPaletteLoading} from './XDSCommandPaletteLoading';
-export type {XDSCommandPaletteLoadingProps} from './XDSCommandPaletteLoading';
-
-export {XDSCommandPaletteSeparator} from './XDSCommandPaletteSeparator';
-
-export {XDSCommandPaletteShortcut} from './XDSCommandPaletteShortcut';
-export type {XDSCommandPaletteShortcutProps} from './XDSCommandPaletteShortcut';
-
-export {XDSCommandPaletteFooter} from './XDSCommandPaletteFooter';
-export type {XDSCommandPaletteFooterProps} from './XDSCommandPaletteFooter';
-
-// Layer 2: Registry provider
+// Layer 2: Provider for distributed command registration
export {
XDSCommandPaletteProvider,
useXDSCommandPalette,
@@ -45,16 +31,11 @@ export {
} from './XDSCommandPaletteProvider';
export type {XDSCommandPaletteProviderProps} from './XDSCommandPaletteProvider';
-// Layer 3: Optional history
+// Hooks
export {useXDSCommandPaletteHistory} from './useXDSCommandPaletteHistory';
-export type {
- CommandPaletteHistoryOptions,
- CommandPaletteHistoryEntry,
-} from './useXDSCommandPaletteHistory';
-
-// Shared types
-export type {
- XDSCommand,
- CommandItemRenderProps,
- CommandPaletteFilterFn,
-} from './types';
+
+// Utilities
+export {defaultFilter as commandPaletteFilter} from './filter';
+
+// Types
+export type {CommandPaletteFilterFn} from './types';
diff --git a/packages/core/src/Kbd/XDSKbd.test.tsx b/packages/core/src/Kbd/XDSKbd.test.tsx
new file mode 100644
index 0000000000..6603903981
--- /dev/null
+++ b/packages/core/src/Kbd/XDSKbd.test.tsx
@@ -0,0 +1,58 @@
+/**
+ * @file XDSKbd.test.tsx
+ * @input Uses React Testing Library, XDSKbd
+ * @output Tests for XDSKbd component
+ */
+
+import {render, screen} from '@testing-library/react';
+import {XDSKbd} from './XDSKbd';
+
+describe('XDSKbd', () => {
+ it('renders a single key', () => {
+ render(<XDSKbd keys="k" />);
+ const kbd = screen.getByText('K');
+ expect(kbd.tagName).toBe('KBD');
+ });
+
+ it('renders multiple keys separated by +', () => {
+ render(<XDSKbd keys="mod+k" />);
+ // mod should render as ⌘
+ expect(screen.getByText('\u2318')).toBeInTheDocument();
+ expect(screen.getByText('K')).toBeInTheDocument();
+ });
+
+ it('maps modifier keys to symbols', () => {
+ render(<XDSKbd keys="ctrl+alt+shift+k" />);
+ expect(screen.getByText('\u2303')).toBeInTheDocument(); // ⌃
+ expect(screen.getByText('\u2325')).toBeInTheDocument(); // ⌥
+ expect(screen.getByText('\u21E7')).toBeInTheDocument(); // ⇧
+ expect(screen.getByText('K')).toBeInTheDocument();
+ });
+
+ it('maps special keys', () => {
+ render(<XDSKbd keys="enter" />);
+ expect(screen.getByText('\u21B5')).toBeInTheDocument(); // ↵
+ });
+
+ it('renders escape as text', () => {
+ render(<XDSKbd keys="escape" />);
+ expect(screen.getByText('Esc')).toBeInTheDocument();
+ });
+
+ it('is aria-hidden', () => {
+ const {container} = render(<XDSKbd keys="mod+k" />);
+ const wrapper = container.firstChild as HTMLElement;
+ expect(wrapper.getAttribute('aria-hidden')).toBe('true');
+ });
+
+ it('uppercases unknown keys', () => {
+ render(<XDSKbd keys="f1" />);
+ expect(screen.getByText('F1')).toBeInTheDocument();
+ });
+
+ it('handles whitespace around keys', () => {
+ render(<XDSKbd keys="mod + k" />);
+ expect(screen.getByText('\u2318')).toBeInTheDocument();
+ expect(screen.getByText('K')).toBeInTheDocument();
+ });
+});
diff --git a/packages/core/src/CommandPalette/XDSCommandPaletteShortcut.tsx b/packages/core/src/Kbd/XDSKbd.tsx
similarity index 68%
rename from packages/core/src/CommandPalette/XDSCommandPaletteShortcut.tsx
rename to packages/core/src/Kbd/XDSKbd.tsx
index a11e231192..d21eb27f53 100644
--- a/packages/core/src/CommandPalette/XDSCommandPaletteShortcut.tsx
+++ b/packages/core/src/Kbd/XDSKbd.tsx
@@ -1,11 +1,16 @@
/**
- * @file XDSCommandPaletteShortcut.tsx
- * @input Uses React, StyleX
- * @output Exports XDSCommandPaletteShortcut component
- * @position Sub-component; keyboard shortcut display
+ * @file XDSKbd.tsx
+ * @input Uses React, StyleX, theme tokens
+ * @output Exports XDSKbd component and XDSKbdProps
+ * @position Core implementation; renders styled keyboard shortcut indicators
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/Kbd/README.md
+ * - /packages/core/src/Kbd/index.ts
*/
import * as stylex from '@stylexjs/stylex';
+import type {StyleXStyles} from '@stylexjs/stylex';
import {
colorVars,
spacingVars,
@@ -18,10 +23,9 @@ import {
const styles = stylex.create({
wrapper: {
- display: 'flex',
+ display: 'inline-flex',
alignItems: 'center',
gap: spacingVars['--spacing-1'],
- marginInlineStart: 'auto',
flexShrink: 0,
},
kbd: {
@@ -60,35 +64,42 @@ const KEY_DISPLAY: Record<string, string> = {
right: '\u2192',
};
-export interface XDSCommandPaletteShortcutProps {
+export interface XDSKbdProps {
/**
* Keyboard shortcut string. Use "+" to separate keys.
* Special keys: mod (Cmd on Mac), ctrl, alt, shift, enter, backspace, escape.
*
* @example
* ```
- * "mod+k", "mod+shift+p", "enter"
+ * "mod+k"
+ * "mod+shift+p"
+ * "enter"
* ```
*/
keys: string;
+
+ /**
+ * StyleX overrides for the wrapper element.
+ */
+ xstyle?: StyleXStyles;
}
/**
* Displays a keyboard shortcut as styled <kbd> elements.
*
+ * A general-purpose component for rendering keyboard shortcuts
+ * anywhere in the system — tooltips, menus, documentation, etc.
+ *
* @example
* ```
- * <XDSCommandPaletteShortcut keys="mod+k" />
- * // Renders: ⌘ K
+ * <XDSKbd keys="mod+k" />
* ```
*/
-export function XDSCommandPaletteShortcut({
- keys,
-}: XDSCommandPaletteShortcutProps) {
+export function XDSKbd({keys, xstyle}: XDSKbdProps) {
const parts = keys.split('+').map(key => key.trim().toLowerCase());
return (
- <span {...stylex.props(styles.wrapper)} aria-hidden="true">
+ <span {...stylex.props(styles.wrapper, xstyle)} aria-hidden="true">
{parts.map((key, i) => (
<kbd key={i} {...stylex.props(styles.kbd)}>
{KEY_DISPLAY[key] ?? key.toUpperCase()}
@@ -98,4 +109,4 @@ export function XDSCommandPaletteShortcut({
);
}
-XDSCommandPaletteShortcut.displayName = 'XDSCommandPaletteShortcut';
+XDSKbd.displayName = 'XDSKbd';
diff --git a/packages/core/src/Kbd/index.ts b/packages/core/src/Kbd/index.ts
new file mode 100644
index 0000000000..5a0c4d6e45
--- /dev/null
+++ b/packages/core/src/Kbd/index.ts
@@ -0,0 +1,9 @@
+/**
+ * @file index.ts
+ * @input Imports XDSKbd component and types
+ * @output Exports public API for @xds/core Kbd
+ * @position Component entry point; re-exported by /packages/core/src/index.ts
+ */
+
+export {XDSKbd} from './XDSKbd';
+export type {XDSKbdProps} from './XDSKbd';
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index c8fdbfd0f8..768fb73179 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -46,6 +46,9 @@ export * from './Token';
export * from './Typeahead';
export * from './Tokenizer';
export * from './CommandPalette';
+
+// Keyboard shortcut display
+export * from './Kbd';
export * from './Dialog';
export * from './DropdownMenu';
export * from './MoreMenu';