Skip to content

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

TypeScript

fix: extend XDSBaseProps on Spinner, StatusDot, TabList + export TabList context hook (#1405)

Cindy Zhanga1cdf050dc0c
diff --git a/packages/core/src/Spinner/XDSSpinner.tsx b/packages/core/src/Spinner/XDSSpinner.tsx
index fe244ff6a3..3dc29e2383 100644
--- a/packages/core/src/Spinner/XDSSpinner.tsx
+++ b/packages/core/src/Spinner/XDSSpinner.tsx
@@ -15,8 +15,8 @@
import {useEffect, useRef, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {colorVars, durationVars, spacingVars} from '../theme/tokens.stylex';
+import {XDSBaseProps} from '../XDSBaseProps';
import {XDSText} from '../Text/XDSText';
import {xdsClassName, mergeProps} from '../utils';
@@ -79,7 +79,7 @@ export type XDSSpinnerSize = keyof typeof SIZES;
export type XDSSpinnerShade = 'default' | 'onMedia' | 'subtle';
-export interface XDSSpinnerProps {
+export interface XDSSpinnerProps extends XDSBaseProps<HTMLSpanElement> {
/** Ref forwarded to the root element */
ref?: React.Ref<HTMLSpanElement>;
/**
@@ -99,27 +99,6 @@ export interface XDSSpinnerProps {
* @default 'default'
*/
shade?: XDSSpinnerShade;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <Component xstyle={overrides.root} />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element. Spread after StyleX
- * inline styles, so these values take priority.
- */
- style?: React.CSSProperties;
/**
* Visible content displayed below the spinner.
* Accepts a string or ReactNode for rich content.
@@ -134,11 +113,6 @@ export interface XDSSpinnerProps {
* ```
*/
label?: ReactNode;
- /**
- * Accessible label for screen readers.
- * Defaults to `label` when label is a string, otherwise "Loading".
- */
- 'aria-label'?: string;
/**
* Test ID for the root element.
*/
@@ -171,6 +145,7 @@ export function XDSSpinner({
'aria-label': ariaLabel,
'data-testid': testId,
ref,
+ ...restProps
}: XDSSpinnerProps) {
const canvasRef = useRef<HTMLCanvasElement>(null);
@@ -247,6 +222,7 @@ export function XDSSpinner({
role="status"
aria-label={resolvedAriaLabel}
data-testid={hasLabel ? undefined : testId}
+ {...(hasLabel ? {} : restProps)}
{...mergeProps(
hasLabel ? '' : xdsClassName('spinner', {size, shade}),
stylex.props(styles.spinner, !hasLabel && xstyle),
@@ -265,6 +241,7 @@ export function XDSSpinner({
<div
ref={ref as React.Ref<HTMLDivElement>}
data-testid={testId}
+ {...restProps}
{...mergeProps(
xdsClassName('spinner', {size, shade}),
stylex.props(styles.wrapper, xstyle),
diff --git a/packages/core/src/StatusDot/XDSStatusDot.tsx b/packages/core/src/StatusDot/XDSStatusDot.tsx
index b7dd2f3628..c7cf5cfa7f 100644
--- a/packages/core/src/StatusDot/XDSStatusDot.tsx
+++ b/packages/core/src/StatusDot/XDSStatusDot.tsx
@@ -12,8 +12,8 @@
*/
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {colorVars} from '../theme/tokens.stylex';
+import {XDSBaseProps} from '../XDSBaseProps';
import {xdsClassName, mergeProps} from '../utils';
/**
@@ -97,7 +97,7 @@ export interface XDSStatusDotVariantMap {
*/
export type XDSStatusDotVariant = keyof XDSStatusDotVariantMap;
-export interface XDSStatusDotProps {
+export interface XDSStatusDotProps extends XDSBaseProps<HTMLSpanElement> {
/** Ref forwarded to the root element */
ref?: React.Ref<HTMLSpanElement>;
/**
@@ -114,31 +114,6 @@ export interface XDSStatusDotProps {
* @default false
*/
isPulsing?: boolean;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <Component xstyle={overrides.root} />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element. Spread after StyleX
- * inline styles, so these values take priority.
- */
- style?: React.CSSProperties;
- /**
- * Optional test ID for testing.
- */
- 'data-testid'?: string;
}
/**
diff --git a/packages/core/src/TabList/XDSTab.tsx b/packages/core/src/TabList/XDSTab.tsx
index 54da66fded..2558512127 100644
--- a/packages/core/src/TabList/XDSTab.tsx
+++ b/packages/core/src/TabList/XDSTab.tsx
@@ -14,7 +14,6 @@
import {useCallback, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {
colorVars,
spacingVars,
@@ -25,6 +24,7 @@ import {
fontWeightVars,
typeScaleVars,
} from '../theme/tokens.stylex';
+import {XDSBaseProps} from '../XDSBaseProps';
import {useXDSTabListContext} from './XDSTabListContext';
import type {XDSTabListSize} from './XDSTabListContext';
import {tabScope} from './tab.markers.stylex';
@@ -32,7 +32,7 @@ import {useXDSLinkComponent} from '../Link/useXDSLinkComponent';
import type {XDSLinkComponentType} from '../Link/types';
import {xdsClassName, mergeProps} from '../utils';
-export interface XDSTabProps {
+export interface XDSTabProps extends XDSBaseProps<HTMLButtonElement> {
/**
* Custom component to render instead of `<a>` for link tabs.
* Overrides the provider-level default set by XDSLinkProvider.
@@ -59,26 +59,6 @@ export interface XDSTabProps {
* Icon element shown when tab is selected. Falls back to `icon` if not provided.
*/
selectedIcon?: ReactNode;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { paddingInline: 16 } });
- * <XDSTab xstyle={overrides.root} ... />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element.
- */
- style?: React.CSSProperties;
}
// =============================================================================
@@ -227,6 +207,7 @@ export function XDSTab({
xstyle,
className,
style,
+ ...restProps
}: XDSTabProps) {
const tabListCtx = useXDSTabListContext();
const LinkComponent = useXDSLinkComponent(as);
@@ -247,6 +228,7 @@ export function XDSTab({
) : null;
const sharedProps = {
+ ...restProps,
'aria-current': isSelected ? ('page' as const) : undefined,
...mergeProps(
xdsClassName('tab', {
diff --git a/packages/core/src/TabList/XDSTabList.tsx b/packages/core/src/TabList/XDSTabList.tsx
index cb7e79b9a9..b45e893640 100644
--- a/packages/core/src/TabList/XDSTabList.tsx
+++ b/packages/core/src/TabList/XDSTabList.tsx
@@ -14,13 +14,16 @@
import {useMemo, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {borderVars, colorVars, spacingVars} from '../theme/tokens.stylex';
+import {XDSBaseProps} from '../XDSBaseProps';
import {XDSTabListContext} from './XDSTabListContext';
import type {XDSTabListSize} from './XDSTabListContext';
import {xdsClassName, mergeProps} from '../utils';
-export interface XDSTabListProps {
+export interface XDSTabListProps extends Omit<
+ XDSBaseProps<HTMLElement>,
+ 'onChange'
+> {
/**
* The currently selected tab value.
*/
@@ -46,26 +49,6 @@ export interface XDSTabListProps {
* @default false
*/
hasDivider?: boolean;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <XDSTabList xstyle={overrides.root} ... />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element.
- */
- style?: React.CSSProperties;
/**
* XDSTab and XDSTabMenu children.
*/
@@ -114,6 +97,7 @@ export function XDSTabList({
className,
style,
children,
+ ...restProps
}: XDSTabListProps) {
const contextValue = useMemo(
() => ({value, onChange, size, layout}),
@@ -124,6 +108,7 @@ export function XDSTabList({
<XDSTabListContext.Provider value={contextValue}>
<nav
aria-label="Tabs"
+ {...restProps}
{...mergeProps(
xdsClassName('tab-list', {size}),
stylex.props(
diff --git a/packages/core/src/TabList/index.ts b/packages/core/src/TabList/index.ts
index d9828f9373..3f7cf4ceca 100644
--- a/packages/core/src/TabList/index.ts
+++ b/packages/core/src/TabList/index.ts
@@ -18,4 +18,5 @@ export type {XDSTabProps} from './XDSTab';
export {XDSTabMenu} from './XDSTabMenu';
export type {XDSTabMenuProps, XDSTabMenuOption} from './XDSTabMenu';
-export type {XDSTabListSize} from './XDSTabListContext';
+export {useXDSTabListContext} from './XDSTabListContext';
+export type {XDSTabListSize, XDSTabListLayout} from './XDSTabListContext';