Skip to content

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

TypeScript

fix(Code): reflect size on the code theme target (#10186)

Cindy Zhang27211b79746c
diff --git a/.changeset/code-size-theme-reflection.md b/.changeset/code-size-theme-reflection.md
new file mode 100644
index 0000000000..d0c999b9dd
--- /dev/null
+++ b/.changeset/code-size-theme-reflection.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Code: the `code` theme target now reflects `size` as `data-size`, so a theme can restyle code that inherits the surrounding text size (`size="inherit"`) differently from code at the default code size. When `size` is omitted, no `data-size` attribute is rendered.
+
+@cixzhang
diff --git a/packages/core/src/Code/Code.doc.mjs b/packages/core/src/Code/Code.doc.mjs
index e08560fc8a..52f01c09d9 100644
--- a/packages/core/src/Code/Code.doc.mjs
+++ b/packages/core/src/Code/Code.doc.mjs
@@ -98,7 +98,7 @@ export const docs = {
},
],
theming: {
- targets: [{className: 'astryx-code', visualProps: ['color']}],
+ targets: [{className: 'astryx-code', visualProps: ['color', 'size']}],
},
};
diff --git a/packages/core/src/Code/Code.test.tsx b/packages/core/src/Code/Code.test.tsx
index 462ca443cb..900ceb3311 100644
--- a/packages/core/src/Code/Code.test.tsx
+++ b/packages/core/src/Code/Code.test.tsx
@@ -51,6 +51,17 @@ describe('Code', () => {
expect(screen.getByText('code')).toHaveAttribute('data-color', 'inherit');
});
+ it('reflects an inherited size on the code target', () => {
+ render(<Code size="inherit">code</Code>);
+ expect(screen.getByText('code')).toHaveClass('astryx-code');
+ expect(screen.getByText('code')).toHaveAttribute('data-size', 'inherit');
+ });
+
+ it('reflects no size when size is omitted', () => {
+ render(<Code>code</Code>);
+ expect(screen.getByText('code')).not.toHaveAttribute('data-size');
+ });
+
it('forwards supported root props and composes styling inputs', () => {
render(
<Code
diff --git a/packages/core/src/Code/Code.tsx b/packages/core/src/Code/Code.tsx
index ec697b3b44..f7bec94ddd 100644
--- a/packages/core/src/Code/Code.tsx
+++ b/packages/core/src/Code/Code.tsx
@@ -114,7 +114,7 @@ export function Code({
ref={ref}
{...props}
{...mergeProps(
- themeProps('code', {color}),
+ themeProps('code', {color, size}),
stylex.props(
styles.base,
colorStyles[color],
diff --git a/packages/core/src/theme/themingTargets.test.ts b/packages/core/src/theme/themingTargets.test.ts
index c9adc04b0e..2b68b9cfdf 100644
--- a/packages/core/src/theme/themingTargets.test.ts
+++ b/packages/core/src/theme/themingTargets.test.ts
@@ -1007,11 +1007,6 @@ const UNREFLECTED_STYLE_AXIS_EXCEPTIONS: ReadonlyMap<string, string> = new Map([
'The composer body paints the elevation but has no target. How to expose ' +
'the body to themes is an open owner decision.',
],
- [
- 'Code.size',
- 'The code target paints the size. Adding the prop to its themeProps() ' +
- 'call is a product change that ships separately.',
- ],
[
'Skeleton.radius',
'The skeleton target paints the radius. Adding the prop to its ' +