Skip to content

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

TypeScript

fix: hardening audit — ToggleButton theming + Chat barrel export (#1812)

Cindy Zhang297ad1d16d31
diff --git a/packages/core/src/ToggleButton/XDSToggleButton.tsx b/packages/core/src/ToggleButton/XDSToggleButton.tsx
index afb6c8f059..5bf2d4631f 100644
--- a/packages/core/src/ToggleButton/XDSToggleButton.tsx
+++ b/packages/core/src/ToggleButton/XDSToggleButton.tsx
@@ -10,7 +10,7 @@
* - `onPressedChange` controlled toggle callback
* - `pressedIcon` for outline-to-filled icon swap
* - Font weight shift on press with width reservation to prevent layout shift
- * - Group integration via ToggleButtonGroupContext
+ * - Group integration via XDSToggleButtonGroupContext
*
* SYNC: When modified, update these files to stay in sync:
* - /packages/core/src/ToggleButton/index.ts (exports if types change)
@@ -21,6 +21,8 @@
import {useCallback, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import {colorVars, fontWeightVars} from '../theme/tokens.stylex';
+import type {StyleXStyles} from '@stylexjs/stylex';
+import {xdsClassName} from '../utils';
import {XDSButton, type XDSButtonSize} from '../Button';
import {useXDSToggleButtonGroup} from './XDSToggleButtonGroup';
@@ -167,6 +169,22 @@ export interface XDSToggleButtonProps {
/** Test ID for testing frameworks. */
'data-testid'?: string;
+
+ /**
+ * StyleX styles created via `stylex.create()`. Merged with the component's
+ * base styles inside a single `stylex.props()` call for optimal deduplication.
+ */
+ 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;
}
// =============================================================================
@@ -209,6 +227,9 @@ export function XDSToggleButton({
children,
tooltip,
value,
+ xstyle,
+ className,
+ style,
...props
}: XDSToggleButtonProps): ReactNode {
// Read group context if inside a group
@@ -284,7 +305,16 @@ export function XDSToggleButton({
aria-pressed={isPressed}
icon={resolvedIcon}
tooltip={tooltip}
- xstyle={isPressed ? pressedStyles.background : undefined}
+ className={xdsClassName('toggle-button', {
+ isPressed: isPressed ? 'true' : 'false',
+ })}
+ xstyle={
+ [
+ isPressed ? pressedStyles.background : undefined,
+ xstyle,
+ ] as unknown as StyleXStyles
+ }
+ style={style}
onClick={handleClick}
{...props}>
{labelContent}
diff --git a/packages/core/src/ToggleButton/XDSToggleButtonGroup.tsx b/packages/core/src/ToggleButton/XDSToggleButtonGroup.tsx
index 5094ed622f..89a64a5b67 100644
--- a/packages/core/src/ToggleButton/XDSToggleButtonGroup.tsx
+++ b/packages/core/src/ToggleButton/XDSToggleButtonGroup.tsx
@@ -33,7 +33,7 @@ import type {StyleXStyles} from '@stylexjs/stylex';
// Context
// =============================================================================
-interface ToggleButtonGroupContextValue {
+interface XDSToggleButtonGroupContextValue {
/** Currently selected value(s). */
selectedValues: Set<string>;
/** Toggle a value on/off. */
@@ -44,15 +44,15 @@ interface ToggleButtonGroupContextValue {
isDisabled?: boolean;
}
-export const ToggleButtonGroupContext =
- createContext<ToggleButtonGroupContextValue | null>(null);
+export const XDSToggleButtonGroupContext =
+ createContext<XDSToggleButtonGroupContextValue | null>(null);
/**
* Hook for XDSToggleButton to read group context.
* Returns null when used outside a group.
*/
-export function useXDSToggleButtonGroup(): ToggleButtonGroupContextValue | null {
- return useContext(ToggleButtonGroupContext);
+export function useXDSToggleButtonGroup(): XDSToggleButtonGroupContextValue | null {
+ return useContext(XDSToggleButtonGroupContext);
}
// =============================================================================
@@ -218,7 +218,7 @@ export function XDSToggleButtonGroup(
);
return (
- <ToggleButtonGroupContext.Provider value={contextValue}>
+ <XDSToggleButtonGroupContext.Provider value={contextValue}>
<div
role="group"
aria-label={label}
@@ -233,7 +233,7 @@ export function XDSToggleButtonGroup(
)}>
{children}
</div>
- </ToggleButtonGroupContext.Provider>
+ </XDSToggleButtonGroupContext.Provider>
);
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 9b1036b4a2..aa84a70b30 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -28,6 +28,7 @@ export * from './Calendar';
export * from './Center';
export * from './CodeBlock';
export * from './CommandPalette';
+export * from './Chat';
export * from './Markdown';
export * from './CheckboxInput';
export * from './CheckboxList';