Skip to content

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

TypeScript

fix(text): apply explicit size overrides (#3648)

Abu Hossain Foysalcd0c1068cf0a
diff --git a/.changeset/text-size-override.md b/.changeset/text-size-override.md
new file mode 100644
index 0000000000..8d7ed47a61
--- /dev/null
+++ b/.changeset/text-size-override.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Text: apply the documented `size` prop as a font-size override (#3615)
+
+`Text` now reflects `size` in theme props and applies the corresponding typography size token after its type-based baseline styles. The override changes font size while preserving the selected text type's line-height, weight, and family behavior.
+
+@ahfoysal
diff --git a/packages/core/src/Text/Text.doc.mjs b/packages/core/src/Text/Text.doc.mjs
index 3b60fb372b..e4714d98f8 100644
--- a/packages/core/src/Text/Text.doc.mjs
+++ b/packages/core/src/Text/Text.doc.mjs
@@ -16,7 +16,7 @@ export const docs = {
theming: {
targets: [
{className: 'astryx-heading', visualProps: ['level', 'color']},
- {className: 'astryx-text', visualProps: ['type', 'color']},
+ {className: 'astryx-text', visualProps: ['type', 'size', 'color']},
],
},
description: 'Semantic body text component that renders text with type-based styling from the theme, with optional truncation, decoration, and layout props.',
@@ -174,4 +174,4 @@ export const docsDense = {
{ guidance: false, description: 'Text for headings: use Heading with level (1\u20136).' },
],
},
-};
\ No newline at end of file
+};
diff --git a/packages/core/src/Text/Text.test.tsx b/packages/core/src/Text/Text.test.tsx
index e499d0d32b..d360ac31cd 100644
--- a/packages/core/src/Text/Text.test.tsx
+++ b/packages/core/src/Text/Text.test.tsx
@@ -114,6 +114,17 @@ describe('Text', () => {
expect(screen.getByText('Bold text')).toBeInTheDocument();
});
+ it('reflects explicit size overrides for styling and theming', () => {
+ render(
+ <Text type="code" size="2xs">
+ Tiny code
+ </Text>,
+ );
+ const element = screen.getByText('Tiny code');
+ expect(element).toHaveAttribute('data-size', '2xs');
+ expect(element.className).toContain('size-2xs');
+ });
+
it('accepts display prop', () => {
render(
<Text type="body" display="block">
diff --git a/packages/core/src/Text/Text.tsx b/packages/core/src/Text/Text.tsx
index 0f2968cf21..d6be12f894 100644
--- a/packages/core/src/Text/Text.tsx
+++ b/packages/core/src/Text/Text.tsx
@@ -32,6 +32,7 @@ import type {
import {
colorStyles,
defaultWeightByTypeStyles,
+ sizeStyles,
sizeByTypeStyles,
weightStyles,
displayStyles,
@@ -201,7 +202,7 @@ function resolveStyleType(type: TextType): BuiltinTextType {
*/
export function Text({
type = 'body',
- size: _size,
+ size,
color,
weight,
display = 'inline',
@@ -254,10 +255,11 @@ export function Text({
<Component
ref={mergeRefs(ref, truncation.ref, textRef)}
{...mergeProps(
- themeProps('text', {type, color: resolvedColor}),
+ themeProps('text', {type, size, color: resolvedColor}),
stylex.props(
colorStyles[resolvedColor],
sizeByTypeStyles[styleType],
+ size && sizeStyles[size],
defaultWeightByTypeStyles[styleType],
weight && weightStyles[weight],
// Display: use truncation styles when maxLines > 0
diff --git a/packages/core/src/Text/text.stylex.ts b/packages/core/src/Text/text.stylex.ts
index d612e49ca0..c25ad13fb6 100644
--- a/packages/core/src/Text/text.stylex.ts
+++ b/packages/core/src/Text/text.stylex.ts
@@ -14,6 +14,7 @@ import * as stylex from '@stylexjs/stylex';
import {
colorVars,
fontWeightVars,
+ textSizeVars,
typeScaleVars,
typographyVars,
} from '../theme/tokens.stylex';
@@ -145,6 +146,46 @@ export const sizeByTypeStyles = stylex.create({
},
});
+// =============================================================================
+// Explicit Size Override
+// =============================================================================
+
+export const sizeStyles = stylex.create({
+ '4xs': {
+ fontSize: textSizeVars['--font-size-4xs'],
+ },
+ '3xs': {
+ fontSize: textSizeVars['--font-size-3xs'],
+ },
+ '2xs': {
+ fontSize: textSizeVars['--font-size-2xs'],
+ },
+ xsm: {
+ fontSize: textSizeVars['--font-size-xs'],
+ },
+ sm: {
+ fontSize: textSizeVars['--font-size-sm'],
+ },
+ base: {
+ fontSize: textSizeVars['--font-size-base'],
+ },
+ lg: {
+ fontSize: textSizeVars['--font-size-lg'],
+ },
+ xl: {
+ fontSize: textSizeVars['--font-size-xl'],
+ },
+ '2xl': {
+ fontSize: textSizeVars['--font-size-2xl'],
+ },
+ '3xl': {
+ fontSize: textSizeVars['--font-size-3xl'],
+ },
+ '4xl': {
+ fontSize: textSizeVars['--font-size-4xl'],
+ },
+});
+
// =============================================================================
// Baseline Size/Leading by Heading Level (from type-scale tokens)
//