Skip to content

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

TypeScript

fix: component audit — xdsClassName, semantic tokens, escape hatches, exports (#937)

Cindy Zhang4eb77532a003
diff --git a/packages/core/src/MetadataList/index.ts b/packages/core/src/MetadataList/index.ts
index b42041de07..8d20cba160 100644
--- a/packages/core/src/MetadataList/index.ts
+++ b/packages/core/src/MetadataList/index.ts
@@ -16,3 +16,4 @@ export type {
} from './XDSMetadataList';
export {XDSMetadataListItem} from './XDSMetadataListItem';
export type {XDSMetadataListItemProps} from './XDSMetadataListItem';
+export type {XDSMetadataListLabelConfig} from './XDSMetadataListContext';
diff --git a/packages/core/src/SegmentedControl/XDSSegmentedControl.tsx b/packages/core/src/SegmentedControl/XDSSegmentedControl.tsx
index 0d15bf586a..48118c23ff 100644
--- a/packages/core/src/SegmentedControl/XDSSegmentedControl.tsx
+++ b/packages/core/src/SegmentedControl/XDSSegmentedControl.tsx
@@ -12,7 +12,7 @@
* - /packages/core/src/SegmentedControl/XDSSegmentedControl.test.tsx
*/
-import {useMemo, useRef, useCallback, type ReactNode} from 'react';
+import React, {useMemo, useRef, useCallback, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {colorVars, spacingVars, radiusVars} from '../theme/tokens.stylex';
@@ -51,6 +51,16 @@ export interface XDSSegmentedControlProps {
* Additional StyleX styles for the container.
*/
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;
}
// =============================================================================
@@ -108,6 +118,8 @@ export function XDSSegmentedControl({
isDisabled = false,
children,
xstyle,
+ className,
+ style,
}: XDSSegmentedControlProps) {
const containerRef = useRef<HTMLDivElement>(null);
@@ -185,6 +197,8 @@ export function XDSSegmentedControl({
isDisabled && styles.disabled,
xstyle,
),
+ className,
+ style,
)}>
{children}
</div>
diff --git a/packages/core/src/SegmentedControl/XDSSegmentedControlItem.tsx b/packages/core/src/SegmentedControl/XDSSegmentedControlItem.tsx
index b9b64cf641..3dcfe23cfc 100644
--- a/packages/core/src/SegmentedControl/XDSSegmentedControlItem.tsx
+++ b/packages/core/src/SegmentedControl/XDSSegmentedControlItem.tsx
@@ -20,7 +20,6 @@ import {
sizeVars,
durationVars,
easeVars,
- textSizeVars,
fontWeightVars,
shadowVars,
typeScaleVars,
@@ -72,7 +71,7 @@ const styles = stylex.create({
borderWidth: 0,
borderStyle: 'none',
fontFamily: 'inherit',
- fontSize: textSizeVars['--font-size-base'],
+ fontSize: typeScaleVars['--text-label-size'],
lineHeight: typeScaleVars['--text-label-leading'],
fontWeight: fontWeightVars['--font-weight-medium'],
color: colorVars['--color-text-secondary'],
@@ -123,7 +122,7 @@ const sizeStyles = stylex.create({
height: `calc(${sizeVars['--size-element-sm']} - 4px)`,
borderRadius: CONCENTRIC_RADIUS,
paddingInline: spacingVars['--spacing-2'],
- fontSize: textSizeVars['--font-size-sm'],
+ fontSize: typeScaleVars['--text-supporting-size'],
},
md: {
height: `calc(${sizeVars['--size-element-md']} - 4px)`,
diff --git a/packages/core/src/Typeahead/XDSBaseTypeahead.tsx b/packages/core/src/Typeahead/XDSBaseTypeahead.tsx
index 66e851a8e1..13d7d21a86 100644
--- a/packages/core/src/Typeahead/XDSBaseTypeahead.tsx
+++ b/packages/core/src/Typeahead/XDSBaseTypeahead.tsx
@@ -38,6 +38,7 @@ import {
shadowVars,
typeScaleVars,
} from '../theme/tokens.stylex';
+import {xdsClassName, mergeProps} from '../utils';
import type {XDSSearchableItem, XDSSearchSource} from './types';
// =============================================================================
@@ -611,7 +612,10 @@ export const XDSBaseTypeahead = function XDSBaseTypeahead<
id={listboxId}
role="listbox"
aria-label="Search results"
- {...stylex.props(styles.dropdown)}>
+ {...mergeProps(
+ xdsClassName('typeahead-dropdown'),
+ stylex.props(styles.dropdown),
+ )}>
{results.length === 0 && hasSearched ? (
<div {...stylex.props(styles.emptyState)}>
{emptySearchResultsText}
diff --git a/packages/core/src/Typeahead/XDSTypeahead.tsx b/packages/core/src/Typeahead/XDSTypeahead.tsx
index bec3a4518f..3e24d95c40 100644
--- a/packages/core/src/Typeahead/XDSTypeahead.tsx
+++ b/packages/core/src/Typeahead/XDSTypeahead.tsx
@@ -37,6 +37,7 @@ import {
radiusVars,
sizeVars,
} from '../theme/tokens.stylex';
+import {xdsClassName, mergeProps} from '../utils';
import type {XDSSearchableItem, XDSSearchSource} from './types';
import type {ReactNode} from 'react';
@@ -375,14 +376,17 @@ export function XDSTypeahead<T extends XDSSearchableItem>({
data-testid={testId}
onClick={handleWrapperClick}
onBlur={handleBlur}
- {...stylex.props(
- inputWrapperStyles.base,
- styles.wrapper,
- sizeStyle,
- status && inputStatusBorderStyles[status.type],
- status && inputStatusHoverShadowStyles[status.type],
- status && inputStatusFocusWithinStyles[status.type],
- isDisabled && inputWrapperStyles.disabled,
+ {...mergeProps(
+ xdsClassName('typeahead', {size, status: status?.type}),
+ stylex.props(
+ inputWrapperStyles.base,
+ styles.wrapper,
+ sizeStyle,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ ),
)}>
{startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
{showToken && (