Skip to content

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

TypeScript

refactor(inputs): extract shared input appearance styles into Field/inputStyles (#441)

Cindy Zhang3d1104a93167
diff --git a/packages/core/src/DateInput/XDSDateInput.tsx b/packages/core/src/DateInput/XDSDateInput.tsx
index 16b28f78c5..31bf88f7bb 100644
--- a/packages/core/src/DateInput/XDSDateInput.tsx
+++ b/packages/core/src/DateInput/XDSDateInput.tsx
@@ -27,15 +27,21 @@ import type {XDSIconName} from '../Icon';
import {
colorVars,
sizeVars,
- spacingVars,
radiusVars,
elevationVars,
- transitionVars,
typographyVars,
textSizeVars,
lineHeightVars,
} from '../theme/tokens.stylex';
-import {XDSField, type XDSInputStatus, type XDSInputStatusType} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ type XDSInputStatusType,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSIcon} from '../Icon';
import {XDSSpinner} from '../Spinner';
import {
@@ -47,43 +53,6 @@ import {useXDSPopover} from '../Layer';
import {parseDateInput, formatDisplayDate} from '../utils';
const styles = stylex.create({
- wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-1'],
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: 1,
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
- },
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
- },
iconButton: {
display: 'flex',
alignItems: 'center',
@@ -146,67 +115,6 @@ const sizeStyles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
export type XDSDateInputSize = keyof typeof sizeStyles;
// Re-export shared types for convenience
@@ -568,12 +476,12 @@ export const XDSDateInput = forwardRef<HTMLInputElement, XDSDateInputProps>(
<div
ref={popover.triggerRef}
{...stylex.props(
- styles.wrapper,
+ inputWrapperStyles.base,
sizeStyles[size],
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
wrapperOverride,
)}>
<button
diff --git a/packages/core/src/Field/README.md b/packages/core/src/Field/README.md
index d6a3cc28b2..a5d6629fb6 100644
--- a/packages/core/src/Field/README.md
+++ b/packages/core/src/Field/README.md
@@ -25,18 +25,18 @@ Form field wrapper that provides label, description, and optional/required indic
</XDSField>
```
-| Prop | Type | Default | Description |
-| ---------------- | ------------- | ------- | ----------------------------------------------------- |
-| `label` | `string` | — | Label text (required for accessibility) |
-| `isLabelHidden` | `boolean` | `false` | Visually hide the label |
-| `description` | `string` | — | Description text between label and input |
-| `inputID` | `string` | — | ID for the input (used for label's htmlFor) |
-| `descriptionID` | `string` | — | ID for the description (for aria-describedby) |
-| `isOptional` | `boolean` | `false` | Show "Optional" indicator |
-| `isRequired` | `boolean` | `false` | Show "Required" indicator |
-| `labelStartIcon` | `XDSIconType` | — | Icon before the label text |
-| `labelTooltip` | `string` | — | Tooltip text for info icon at end of label |
-| `children` | `ReactNode` | — | The input or control to render |
+| Prop | Type | Default | Description |
+| ---------------- | ------------- | ------- | --------------------------------------------- |
+| `label` | `string` | — | Label text (required for accessibility) |
+| `isLabelHidden` | `boolean` | `false` | Visually hide the label |
+| `description` | `string` | — | Description text between label and input |
+| `inputID` | `string` | — | ID for the input (used for label's htmlFor) |
+| `descriptionID` | `string` | — | ID for the description (for aria-describedby) |
+| `isOptional` | `boolean` | `false` | Show "Optional" indicator |
+| `isRequired` | `boolean` | `false` | Show "Required" indicator |
+| `labelStartIcon` | `XDSIconType` | — | Icon before the label text |
+| `labelTooltip` | `string` | — | Tooltip text for info icon at end of label |
+| `children` | `ReactNode` | — | The input or control to render |
### XDSFieldLabel
@@ -46,16 +46,16 @@ Standalone label component with optional/required indicators and tooltip support
<XDSFieldLabel label="Username" inputID={id} isRequired />
```
-| Prop | Type | Default | Description |
-| ---------------- | ------------- | ------- | ------------------------------------------- |
-| `label` | `string` | — | Label text (required) |
-| `inputID` | `string` | — | ID of the input this label is for |
-| `isLabelHidden` | `boolean` | `false` | Visually hide the label |
-| `isDisabled` | `boolean` | `false` | Whether the associated input is disabled |
-| `isOptional` | `boolean` | `false` | Show "Optional" indicator |
-| `isRequired` | `boolean` | `false` | Show "Required" indicator |
-| `startIcon` | `XDSIconType` | — | Icon before the label text |
-| `tooltip` | `string` | — | Tooltip text for info icon at end of label |
+| Prop | Type | Default | Description |
+| --------------- | ------------- | ------- | ------------------------------------------ |
+| `label` | `string` | — | Label text (required) |
+| `inputID` | `string` | — | ID of the input this label is for |
+| `isLabelHidden` | `boolean` | `false` | Visually hide the label |
+| `isDisabled` | `boolean` | `false` | Whether the associated input is disabled |
+| `isOptional` | `boolean` | `false` | Show "Optional" indicator |
+| `isRequired` | `boolean` | `false` | Show "Required" indicator |
+| `startIcon` | `XDSIconType` | — | Icon before the label text |
+| `tooltip` | `string` | — | Tooltip text for info icon at end of label |
### XDSFieldStatus
@@ -65,12 +65,12 @@ Status message component for form field validation feedback.
<XDSFieldStatus type="error" message="This field is required" />
```
-| Prop | Type | Default | Description |
-| --------- | ------------------------------------------ | ------------ | ----------------------------------------------- |
-| `type` | `'error' \| 'warning' \| 'success'` | — | Status type |
-| `message` | `string` | — | Status message text |
-| `id` | `string` | — | ID for aria-describedby association |
-| `variant` | `'attached' \| 'detached'` | `'attached'` | Visual variant (overlaps vs floats below input) |
+| Prop | Type | Default | Description |
+| --------- | ----------------------------------- | ------------ | ----------------------------------------------- |
+| `type` | `'error' \| 'warning' \| 'success'` | — | Status type |
+| `message` | `string` | — | Status message text |
+| `id` | `string` | — | ID for aria-describedby association |
+| `variant` | `'attached' \| 'detached'` | `'attached'` | Visual variant (overlaps vs floats below input) |
## Usage
@@ -167,11 +167,16 @@ const theme: Theme = {
## Files
-| File | Role | Purpose |
-| ------------------- | ----- | --------------------------- |
-| `index.ts` | Entry | Exports component and types |
-| `XDSField.tsx` | Core | Component implementation |
-| `XDSField.test.tsx` | Test | Unit tests |
+| File | Role | Purpose |
+| ------------------------ | ------ | ------------------------------------------------- |
+| `index.ts` | Entry | Exports component, types, and shared input styles |
+| `XDSField.tsx` | Core | Component implementation |
+| `XDSFieldLabel.tsx` | Core | Standalone label component |
+| `XDSFieldStatus.tsx` | Core | Status message component |
+| `XDSField.test.tsx` | Test | Unit tests |
+| `XDSFieldLabel.test.tsx` | Test | Unit tests for label component |
+| `types.ts` | Types | Shared input types (status, size) |
+| `inputStyles.stylex.ts` | Styles | Shared input wrapper appearance styles |
## Implementation Notes
diff --git a/packages/core/src/Field/index.ts b/packages/core/src/Field/index.ts
index ace958e4f8..973e8c7bfc 100644
--- a/packages/core/src/Field/index.ts
+++ b/packages/core/src/Field/index.ts
@@ -23,3 +23,12 @@ export type {
// Shared input types
export type {XDSInputStatus, XDSInputStatusType, XDSInputSize} from './types';
+
+// Shared input styles
+export {
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+ inputStatusFocusStyles,
+} from './inputStyles.stylex';
diff --git a/packages/core/src/Field/inputStyles.stylex.ts b/packages/core/src/Field/inputStyles.stylex.ts
new file mode 100644
index 0000000000..ac4bc12a32
--- /dev/null
+++ b/packages/core/src/Field/inputStyles.stylex.ts
@@ -0,0 +1,167 @@
+/**
+ * @file inputStyles.stylex.ts
+ * @input Uses theme tokens (color, spacing, radius, elevation, transition)
+ * @output Exports shared input wrapper appearance styles
+ * @position Shared styles consumed by TextInput, TextArea, NumberInput, DateInput,
+ * TimeInput, Selector, Typeahead, and Tokenizer
+ *
+ * Centralizes the input wrapper appearance (borders, focus outlines, hover shadows,
+ * disabled state, status variants) so all input components stay in sync.
+ * Individual components layer their own overrides (padding, alignment, etc.)
+ * via stylex.props composition.
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {
+ colorVars,
+ spacingVars,
+ radiusVars,
+ elevationVars,
+ transitionVars,
+} from '../theme/tokens.stylex';
+
+/**
+ * Base wrapper styles shared by all input components.
+ * Components apply these as a foundation and override specific properties
+ * (e.g. padding, alignItems, gap) as needed.
+ */
+export const inputWrapperStyles = stylex.create({
+ base: {
+ boxSizing: 'border-box',
+ position: 'relative',
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ borderWidth: '1px',
+ borderStyle: 'solid',
+ borderColor: {
+ default: colorVars['--color-divider-emphasized'],
+ ':hover': {
+ '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
+ },
+ },
+ borderRadius: radiusVars['--radius-element'],
+ backgroundColor: colorVars['--color-surface'],
+ transitionProperty: 'border-color, outline, box-shadow',
+ transitionDuration: transitionVars['--transition-fast'],
+ boxShadow: {
+ default: 'none',
+ ':hover': {
+ '@media (hover: hover)': elevationVars['--elevation-input-hover'],
+ },
+ },
+ outline: {
+ default: 'none',
+ ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
+ },
+ outlineOffset: '0',
+ },
+ disabled: {
+ cursor: 'not-allowed',
+ opacity: 0.5,
+ borderColor: colorVars['--color-divider-emphasized'],
+ },
+});
+
+/**
+ * Status border colors for input wrappers.
+ * Keyed by XDSInputStatusType.
+ */
+export const inputStatusBorderStyles = stylex.create({
+ warning: {
+ borderColor: colorVars['--color-warning'],
+ },
+ error: {
+ borderColor: colorVars['--color-negative'],
+ },
+ success: {
+ borderColor: colorVars['--color-positive'],
+ },
+});
+
+/**
+ * Status hover shadow styles for input wrappers.
+ * Keyed by XDSInputStatusType.
+ */
+export const inputStatusHoverShadowStyles = stylex.create({
+ warning: {
+ boxShadow: {
+ default: 'none',
+ ':hover': {
+ '@media (hover: hover)':
+ elevationVars['--elevation-input-hover-warning'],
+ },
+ },
+ },
+ error: {
+ boxShadow: {
+ default: 'none',
+ ':hover': {
+ '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
+ },
+ },
+ },
+ success: {
+ boxShadow: {
+ default: 'none',
+ ':hover': {
+ '@media (hover: hover)':
+ elevationVars['--elevation-input-hover-success'],
+ },
+ },
+ },
+});
+
+/**
+ * Status focus outline styles using :focus-within.
+ * Used by input wrappers that contain a child input/textarea element.
+ * Keyed by XDSInputStatusType.
+ */
+export const inputStatusFocusWithinStyles = stylex.create({
+ warning: {
+ outline: {
+ default: 'none',
+ ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
+ },
+ },
+ error: {
+ outline: {
+ default: 'none',
+ ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
+ },
+ },
+ success: {
+ outline: {
+ default: 'none',
+ ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
+ },
+ },
+});
+
+/**
+ * Status focus outline styles using :focus.
+ * Used by components where the wrapper itself receives focus (e.g. Selector button).
+ * Keyed by XDSInputStatusType.
+ */
+export const inputStatusFocusStyles = stylex.create({
+ warning: {
+ outline: {
+ default: 'none',
+ ':focus': `1px solid ${colorVars['--color-focus-outline-warning']}`,
+ },
+ },
+ error: {
+ outline: {
+ default: 'none',
+ ':focus': `1px solid ${colorVars['--color-focus-outline-error']}`,
+ },
+ },
+ success: {
+ outline: {
+ default: 'none',
+ ':focus': `1px solid ${colorVars['--color-focus-outline-success']}`,
+ },
+ },
+});
diff --git a/packages/core/src/NumberInput/XDSNumberInput.tsx b/packages/core/src/NumberInput/XDSNumberInput.tsx
index 92a112541f..e80263cc7a 100644
--- a/packages/core/src/NumberInput/XDSNumberInput.tsx
+++ b/packages/core/src/NumberInput/XDSNumberInput.tsx
@@ -27,55 +27,24 @@ import type {XDSIconName} from '../Icon';
import {
colorVars,
sizeVars,
- spacingVars,
- radiusVars,
- elevationVars,
- transitionVars,
typographyVars,
textSizeVars,
lineHeightVars,
} from '../theme/tokens.stylex';
-import {XDSField, type XDSInputStatus, type XDSInputStatusType} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ type XDSInputStatusType,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSIcon, type XDSIconType} from '../Icon';
const styles = stylex.create({
wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
zIndex: 1,
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-1'],
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: '1px',
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
- },
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
},
input: {
display: 'block',
@@ -121,67 +90,6 @@ const sizeStyles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
export type XDSNumberInputSize = keyof typeof sizeStyles;
// Re-export shared types for convenience
@@ -563,12 +471,13 @@ export const XDSNumberInput = forwardRef<HTMLInputElement, XDSNumberInputProps>(
labelTooltip={labelTooltip}>
<div
{...stylex.props(
+ inputWrapperStyles.base,
styles.wrapper,
sizeStyles[size],
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
wrapperOverride,
)}>
{startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
diff --git a/packages/core/src/Selector/XDSSelector.tsx b/packages/core/src/Selector/XDSSelector.tsx
index df56a40739..13257800c6 100644
--- a/packages/core/src/Selector/XDSSelector.tsx
+++ b/packages/core/src/Selector/XDSSelector.tsx
@@ -22,7 +22,11 @@ import * as stylex from '@stylexjs/stylex';
import {useXDSLayer} from '../Layer/useXDSLayer';
import {XDSIcon} from '../Icon';
import type {XDSIconName} from '../Icon';
-import {XDSField} from '../Field';
+import {
+ XDSField,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+} from '../Field';
import {XDSDivider} from '../Divider';
import {XDSSpinner} from '../Spinner';
import {
@@ -208,68 +212,6 @@ const sizeStyles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
const STATUS_ICON_MAP: Record<XDSSelectorStatusType, XDSIconName> = {
warning: 'warning',
error: 'xCircle',
@@ -675,8 +617,8 @@ export function XDSSelector<T extends XDSSelectorOption>({
sizeStyles[size],
isDisabled && styles.triggerDisabled,
!selectedItem && styles.triggerPlaceholder,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
triggerOverride,
)}>
<span>{selectedItem?.label ?? placeholder}</span>
diff --git a/packages/core/src/TextArea/XDSTextArea.tsx b/packages/core/src/TextArea/XDSTextArea.tsx
index 847245d9f3..ffad16d166 100644
--- a/packages/core/src/TextArea/XDSTextArea.tsx
+++ b/packages/core/src/TextArea/XDSTextArea.tsx
@@ -25,14 +25,17 @@ import type {XDSIconName} from '../Icon';
import {
colorVars,
spacingVars,
- radiusVars,
- elevationVars,
- transitionVars,
typographyVars,
textSizeVars,
lineHeightVars,
} from '../theme/tokens.stylex';
-import {XDSField} from '../Field';
+import {
+ XDSField,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSIcon, type XDSIconType} from '../Icon';
import {XDSSpinner} from '../Spinner';
import {ThemeContext} from '../theme/ThemeContext';
@@ -40,42 +43,9 @@ import type {StyleXStyles as ThemeStyleXStyles} from '../theme/types';
const styles = stylex.create({
wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
zIndex: 1,
- display: 'flex',
alignItems: 'flex-start',
- gap: spacingVars['--spacing-2'],
paddingBlock: spacingVars['--spacing-2'],
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: '1px',
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
- },
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
},
textarea: {
display: 'block',
@@ -112,67 +82,6 @@ const styles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
export type XDSTextAreaStatusType = 'warning' | 'error' | 'success';
export interface XDSTextAreaStatus {
@@ -396,11 +305,12 @@ export const XDSTextArea = forwardRef<HTMLTextAreaElement, XDSTextAreaProps>(
labelTooltip={labelTooltip}>
<div
{...stylex.props(
+ inputWrapperStyles.base,
styles.wrapper,
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
wrapperOverride,
)}>
{startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
diff --git a/packages/core/src/TextInput/XDSTextInput.tsx b/packages/core/src/TextInput/XDSTextInput.tsx
index 38fb2dfd87..27c6f8a48f 100644
--- a/packages/core/src/TextInput/XDSTextInput.tsx
+++ b/packages/core/src/TextInput/XDSTextInput.tsx
@@ -24,56 +24,25 @@ import type {XDSIconName} from '../Icon';
import {
colorVars,
sizeVars,
- spacingVars,
- radiusVars,
- elevationVars,
- transitionVars,
typographyVars,
textSizeVars,
lineHeightVars,
} from '../theme/tokens.stylex';
-import {XDSField, type XDSInputStatus, type XDSInputStatusType} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ type XDSInputStatusType,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSIcon, type XDSIconType} from '../Icon';
import {XDSSpinner} from '../Spinner';
const styles = stylex.create({
wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
zIndex: 1,
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-1'],
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: '1px',
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
- },
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
},
input: {
display: 'block',
@@ -109,68 +78,6 @@ const sizeStyles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-
export type XDSTextInputSize = keyof typeof sizeStyles;
// Re-export shared types for convenience
@@ -376,12 +283,13 @@ export const XDSTextInput = forwardRef<HTMLInputElement, XDSTextInputProps>(
labelTooltip={labelTooltip}>
<div
{...stylex.props(
+ inputWrapperStyles.base,
styles.wrapper,
sizeStyles[size],
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
wrapperOverride,
)}>
{startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
diff --git a/packages/core/src/TimeInput/XDSTimeInput.tsx b/packages/core/src/TimeInput/XDSTimeInput.tsx
index b7e25914f7..0249e240ce 100644
--- a/packages/core/src/TimeInput/XDSTimeInput.tsx
+++ b/packages/core/src/TimeInput/XDSTimeInput.tsx
@@ -29,15 +29,20 @@ import type {XDSIconName} from '../Icon';
import {
colorVars,
sizeVars,
- spacingVars,
radiusVars,
- elevationVars,
- transitionVars,
typographyVars,
textSizeVars,
lineHeightVars,
} from '../theme/tokens.stylex';
-import {XDSField, type XDSInputStatus, type XDSInputStatusType} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ type XDSInputStatusType,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSIcon} from '../Icon';
import {XDSSpinner} from '../Spinner';
import {
@@ -51,43 +56,6 @@ import {
} from '../utils';
const styles = stylex.create({
- wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- gap: spacingVars['--spacing-2'],
- paddingBlock: spacingVars['--spacing-1'],
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: 1,
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
- },
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
- },
icon: {
display: 'flex',
alignItems: 'center',
@@ -148,67 +116,6 @@ const sizeStyles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
export type XDSTimeInputSize = keyof typeof sizeStyles;
export type XDSTimeInputHourFormat = '12h' | '24h';
@@ -608,12 +515,12 @@ export const XDSTimeInput = forwardRef<HTMLInputElement, XDSTimeInputProps>(
labelTooltip={labelTooltip}>
<div
{...stylex.props(
- styles.wrapper,
+ inputWrapperStyles.base,
sizeStyles[size],
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
wrapperOverride,
)}>
<div {...stylex.props(styles.icon)}>
diff --git a/packages/core/src/Tokenizer/XDSTokenizer.tsx b/packages/core/src/Tokenizer/XDSTokenizer.tsx
index 9c8a48024f..955f6776b8 100644
--- a/packages/core/src/Tokenizer/XDSTokenizer.tsx
+++ b/packages/core/src/Tokenizer/XDSTokenizer.tsx
@@ -20,7 +20,14 @@ import React, {
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {XDSBaseTypeahead} from '../Typeahead/XDSBaseTypeahead';
-import {XDSField, type XDSInputStatus} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSToken} from '../Token';
import {XDSIcon} from '../Icon';
import {
@@ -28,8 +35,6 @@ import {
spacingVars,
radiusVars,
sizeVars,
- transitionVars,
- elevationVars,
} from '../theme/tokens.stylex';
import type {XDSSearchableItem, XDSSearchSource} from '../Typeahead/types';
@@ -114,46 +119,13 @@ export interface XDSTokenizerProps<T extends XDSSearchableItem> {
const styles = stylex.create({
wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
flexWrap: 'wrap',
gap: spacingVars['--spacing-1'],
// Standard padding minus border width to prevent height jump
// when tokens (28px) are added inside the input
paddingBlock: `calc(${spacingVars['--spacing-1']} - 1px)`,
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: '1px',
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
cursor: 'text',
},
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
- },
tokenContainer: {
display: 'flex',
flexWrap: 'wrap',
@@ -203,68 +175,6 @@ const styles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-
// =============================================================================
// Component
// =============================================================================
@@ -486,12 +396,13 @@ export function XDSTokenizer<T extends XDSSearchableItem>({
onClick={handleWrapperClick}
data-testid={testId}
{...stylex.props(
+ inputWrapperStyles.base,
styles.wrapper,
sizeStyle,
- isDisabled && styles.wrapperDisabled,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
xstyle,
)}>
{tokens.length > 0 && (
diff --git a/packages/core/src/Typeahead/XDSTypeahead.tsx b/packages/core/src/Typeahead/XDSTypeahead.tsx
index 4ea4be842d..9ba3077680 100644
--- a/packages/core/src/Typeahead/XDSTypeahead.tsx
+++ b/packages/core/src/Typeahead/XDSTypeahead.tsx
@@ -18,7 +18,14 @@ import React, {useCallback, useId, useRef, useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {XDSBaseTypeahead} from './XDSBaseTypeahead';
-import {XDSField, type XDSInputStatus} from '../Field';
+import {
+ XDSField,
+ type XDSInputStatus,
+ inputWrapperStyles,
+ inputStatusBorderStyles,
+ inputStatusHoverShadowStyles,
+ inputStatusFocusWithinStyles,
+} from '../Field';
import {XDSToken} from '../Token';
import {XDSIcon} from '../Icon';
import {
@@ -26,8 +33,6 @@ import {
spacingVars,
radiusVars,
sizeVars,
- transitionVars,
- elevationVars,
} from '../theme/tokens.stylex';
import type {XDSSearchableItem, XDSSearchSource} from './types';
import type {ReactNode} from 'react';
@@ -98,46 +103,13 @@ export interface XDSTypeaheadProps<T extends XDSSearchableItem> {
const styles = stylex.create({
wrapper: {
- boxSizing: 'border-box',
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
flexWrap: 'wrap',
gap: spacingVars['--spacing-1'],
// Standard padding minus border width to prevent height jump
// when a token (28px) is added inside the input
paddingBlock: `calc(${spacingVars['--spacing-1']} - 1px)`,
- paddingInline: spacingVars['--spacing-2'],
- borderWidth: '1px',
- borderStyle: 'solid',
- borderColor: {
- default: colorVars['--color-divider-emphasized'],
- ':hover': {
- '@media (hover: hover)': colorVars['--color-divider-high-contrast'],
- },
- },
- borderRadius: radiusVars['--radius-element'],
- backgroundColor: colorVars['--color-surface'],
- transitionProperty: 'border-color, outline, box-shadow',
- transitionDuration: transitionVars['--transition-fast'],
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover'],
- },
- },
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline']}`,
- },
- outlineOffset: '0',
cursor: 'text',
},
- wrapperDisabled: {
- cursor: 'not-allowed',
- opacity: 0.5,
- borderColor: colorVars['--color-divider-emphasized'],
- },
token: {
// Offset token so it sits 3px from the inner edge (4px from outer edge
// accounting for 1px border). Default inline padding is 8px, so
@@ -176,68 +148,6 @@ const styles = stylex.create({
},
});
-const statusBorderStyles = stylex.create({
- warning: {
- borderColor: colorVars['--color-warning'],
- },
- error: {
- borderColor: colorVars['--color-negative'],
- },
- success: {
- borderColor: colorVars['--color-positive'],
- },
-});
-
-const statusHoverShadowStyles = stylex.create({
- warning: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-warning'],
- },
- },
- },
- error: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)': elevationVars['--elevation-input-hover-error'],
- },
- },
- },
- success: {
- boxShadow: {
- default: 'none',
- ':hover': {
- '@media (hover: hover)':
- elevationVars['--elevation-input-hover-success'],
- },
- },
- },
-});
-
-const statusFocusStyles = stylex.create({
- warning: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-warning']}`,
- },
- },
- error: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-error']}`,
- },
- },
- success: {
- outline: {
- default: 'none',
- ':focus-within': `1px solid ${colorVars['--color-focus-outline-success']}`,
- },
- },
-});
-
// =============================================================================
// Component
// =============================================================================
@@ -431,12 +341,13 @@ export function XDSTypeahead<T extends XDSSearchableItem>({
onClick={handleWrapperClick}
onBlur={handleBlur}
{...stylex.props(
+ inputWrapperStyles.base,
styles.wrapper,
sizeStyle,
- status && statusBorderStyles[status.type],
- status && statusHoverShadowStyles[status.type],
- status && statusFocusStyles[status.type],
- isDisabled && styles.wrapperDisabled,
+ status && inputStatusBorderStyles[status.type],
+ status && inputStatusHoverShadowStyles[status.type],
+ status && inputStatusFocusWithinStyles[status.type],
+ isDisabled && inputWrapperStyles.disabled,
xstyle,
)}>
{showToken && (