An open source design system that's fully customizable and agent ready
TypeScript
feat(Text): add justify prop to XDSText and XDSHeading (#2438)
Kenton Quatman35144e00f56f
diff --git a/packages/core/src/Text/XDSHeading.tsx b/packages/core/src/Text/XDSHeading.tsxindex 2f9b4f88cb..9903c1375c 100644--- a/packages/core/src/Text/XDSHeading.tsx+++ b/packages/core/src/Text/XDSHeading.tsx@@ -21,6 +21,7 @@ import * as stylex from '@stylexjs/stylex';import type {XDSTextColor,XDSTextDisplay,+ XDSTextJustify,XDSWordBreak,XDSTextWrap,} from '../theme/types';@@ -30,6 +31,7 @@ import {sizeByTypeStyles,defaultWeightByTypeStyles,displayStyles,+ justifyStyles,truncationStyles,wordBreakStyles,textWrapStyles,@@ -139,6 +141,13 @@ export interface XDSHeadingProps extends Omit<*/textWrap?: XDSTextWrap;+ /**+ * Text alignment (justification). Uses logical values (start/end)+ * for i18n/RTL compatibility.+ * @default 'start'+ */+ justify?: XDSTextJustify;+/*** Enable optical alignment (text-box-trim).* Forces block display.@@ -193,6 +202,7 @@ export function XDSHeading({hasTruncateTooltip = true,wordBreak,textWrap,+ justify = 'start',hasCapsize = false,hasStrikethrough = false,xstyle,@@ -252,6 +262,8 @@ export function XDSHeading({maxLines > 0 && wordBreakStyles[resolvedWordBreak],// Text wraptextWrap && textWrapStyles[textWrap],+ // Justify (text alignment)+ justify !== 'start' && justifyStyles[justify],// CapsizehasCapsize && capsizeStyles.enabled,// Decorationsdiff --git a/packages/core/src/Text/XDSText.tsx b/packages/core/src/Text/XDSText.tsxindex 5bd0871380..2ef471be98 100644--- a/packages/core/src/Text/XDSText.tsx+++ b/packages/core/src/Text/XDSText.tsx@@ -25,6 +25,7 @@ import type {XDSTextColor,XDSTextWeight,XDSTextDisplay,+ XDSTextJustify,XDSWordBreak,XDSTextWrap,} from '../theme/types';@@ -34,6 +35,7 @@ import {sizeByTypeStyles,weightStyles,displayStyles,+ justifyStyles,truncationStyles,wordBreakStyles,textWrapStyles,@@ -117,6 +119,13 @@ export interface XDSTextProps extends Omit<XDSBaseProps, 'children'> {*/textWrap?: XDSTextWrap;+ /**+ * Text alignment (justification). Uses logical values (start/end)+ * for i18n/RTL compatibility.+ * @default 'start'+ */+ justify?: XDSTextJustify;+/*** Enable optical alignment (text-box-trim).* Forces block display.@@ -199,6 +208,7 @@ export function XDSText({hasTruncateTooltip = true,wordBreak,textWrap,+ justify = 'start',hasCapsize = false,hasStrikethrough = false,hasTabularNumbers = false,@@ -259,6 +269,8 @@ export function XDSText({maxLines > 0 && wordBreakStyles[resolvedWordBreak],// Text wraptextWrap && textWrapStyles[textWrap],+ // Justify (text alignment)+ justify !== 'start' && justifyStyles[justify],// CapsizehasCapsize && capsizeStyles.enabled,// Decorationsdiff --git a/packages/core/src/Text/index.ts b/packages/core/src/Text/index.tsindex 859e094c55..941fe43335 100644--- a/packages/core/src/Text/index.ts+++ b/packages/core/src/Text/index.ts@@ -25,6 +25,7 @@ export type {XDSTextColor,XDSTextWeight,XDSTextDisplay,+ XDSTextJustify,XDSWordBreak,XDSTextWrap,XDSTextXStyleAllowed,diff --git a/packages/core/src/Text/text.stylex.ts b/packages/core/src/Text/text.stylex.tsindex 02cdbf286d..e184ed891b 100644--- a/packages/core/src/Text/text.stylex.ts+++ b/packages/core/src/Text/text.stylex.ts@@ -283,6 +283,22 @@ export const tabularNumbersStyle = stylex.create({},});+// =============================================================================+// Justify (Text Alignment) Styles+// =============================================================================++export const justifyStyles = stylex.create({+ start: {+ textAlign: 'start',+ },+ center: {+ textAlign: 'center',+ },+ end: {+ textAlign: 'end',+ },+});+// =============================================================================// Truncation Tooltip Content Style// =============================================================================diff --git a/packages/core/src/theme/types.ts b/packages/core/src/theme/types.tsindex 95bc657328..350a73801f 100644--- a/packages/core/src/theme/types.ts+++ b/packages/core/src/theme/types.ts@@ -181,6 +181,12 @@ export type XDSWordBreak = 'break-word' | 'break-all';*/export type XDSTextWrap = 'wrap' | 'nowrap' | 'balance' | 'pretty';+/**+ * Text alignment (justification). Uses logical properties (start/end)+ * for i18n/RTL compatibility.+ */+export type XDSTextJustify = 'start' | 'center' | 'end';+/*** Allowed CSS properties for XDSText/XDSHeading xstyle prop.* Constrained to layout-only properties to prevent typography escapes.