Skip to content

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

TypeScript

fix(theme): chat-composer borderRadius and padding set the composer's derived vars (#10249)

Utsav Ojha65d2e526883b
diff --git a/.changeset/chat-composer-derived-vars.md b/.changeset/chat-composer-derived-vars.md
new file mode 100644
index 0000000000..6610095014
--- /dev/null
+++ b/.changeset/chat-composer-derived-vars.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A theme's `borderRadius` and `padding` on the `chat-composer` target now also set the composer's `--_chat-composer-radius` and `--_chat-composer-padding`, so the composer body, its status strip, and the concentric send and attach button radius follow the theme. With `density="compact"`, the body keeps its compact padding, and its radius still follows. Before, the derived-variable registry filed these two mappings under `chat`, a key no element renders, so `defineTheme({components: {'chat-composer': {base: {borderRadius: '16px', padding: '8px'}}}})` emitted only `border-radius` and `padding` on the composer root, and everything that reads the two variables kept the default geometry.
+
+@utsavo-afk
diff --git a/packages/core/src/theme/derivedVarRegistry.test.ts b/packages/core/src/theme/derivedVarRegistry.test.ts
index a9aa276c22..790e3d70c7 100644
--- a/packages/core/src/theme/derivedVarRegistry.test.ts
+++ b/packages/core/src/theme/derivedVarRegistry.test.ts
@@ -37,6 +37,7 @@ const SRC_DIR = join(__dirname, '..');
type ComponentDocModule = {
docs?: {
theming?: {
+ targets?: {className: string}[];
vars?: {name: string}[];
derived?: DerivedDocEntry[];
};
@@ -184,6 +185,7 @@ interface ComponentInfo {
sourceVars: string[];
docVars: string[];
docDerived: {property: string; vars?: string[]; expand?: string}[];
+ docTargetKeys: string[];
}
function discoverComponents(): ComponentInfo[] {
@@ -225,10 +227,14 @@ function discoverComponents(): ComponentInfo[] {
let docVars: string[] = [];
let docDerived: DerivedDocEntry[] = [];
+ let docTargetKeys: string[] = [];
try {
const mod = require(docPath) as ComponentDocModule;
docVars = (mod.docs?.theming?.vars || []).map(v => v.name);
docDerived = mod.docs?.theming?.derived || [];
+ docTargetKeys = (mod.docs?.theming?.targets || []).map(t =>
+ t.className.replace(/^astryx-/, ''),
+ );
} catch {
/* skip */
}
@@ -248,6 +254,7 @@ function discoverComponents(): ComponentInfo[] {
sourceVars: [...allVars],
docVars,
docDerived,
+ docTargetKeys,
});
}
return results;
@@ -263,7 +270,7 @@ const DIR_TO_REGISTRY_KEY: Record<string, string> = {
BottomSheet: 'bottom-sheet',
Button: 'button',
Card: 'card',
- Chat: 'chat',
+ Chat: 'chat-composer',
ContextMenu: 'context-menu',
Dialog: 'dialog',
Drawer: 'drawer',
@@ -501,7 +508,7 @@ describe('component CSS vars are documented and themeable', () => {
describe('derivedVarRegistry ↔ doc file consistency', () => {
const components = discoverComponents();
- for (const {dir, docDerived} of components) {
+ for (const {dir, docDerived, docTargetKeys} of components) {
const key = DIR_TO_REGISTRY_KEY[dir];
if (!key || docDerived.length === 0) {
continue;
@@ -512,6 +519,12 @@ describe('derivedVarRegistry ↔ doc file consistency', () => {
expect(registryEntries).toBeDefined();
expect(registryEntries).toEqual(docDerived);
});
+
+ // generateThemeRules looks the registry up by the theme's components key,
+ // so a key that is not one of the doc's targets never expands.
+ it(`${dir} (${key}): registry key is a documented theming target`, () => {
+ expect(docTargetKeys).toContain(key);
+ });
}
// Catch new doc files with derived that have no registry key mapping
diff --git a/packages/core/src/theme/derivedVarRegistry.ts b/packages/core/src/theme/derivedVarRegistry.ts
index ecee2776ea..c6d6aef7a6 100644
--- a/packages/core/src/theme/derivedVarRegistry.ts
+++ b/packages/core/src/theme/derivedVarRegistry.ts
@@ -51,7 +51,7 @@ export const derivedVarRegistry: Record<string, DerivedVarEntry[]> = {
{property: 'borderRadius', vars: ['--_card-radius']},
{property: 'padding', expand: 'container'},
],
- chat: [
+ 'chat-composer': [
{property: 'borderRadius', vars: ['--_chat-composer-radius']},
{property: 'padding', vars: ['--_chat-composer-padding']},
],
diff --git a/packages/core/src/theme/generateThemeRules.test.ts b/packages/core/src/theme/generateThemeRules.test.ts
index 569978af44..1c43039fe8 100644
--- a/packages/core/src/theme/generateThemeRules.test.ts
+++ b/packages/core/src/theme/generateThemeRules.test.ts
@@ -991,18 +991,20 @@ describe('derived var expansion', () => {
expect(spaciousRule).toContain('--_item-inset-inline: var(--spacing-4)');
});
- it('emits internal vars for chat composer', () => {
+ it('emits internal vars for the chat-composer target', () => {
const theme = defineTheme({
- name: 'test-derived-chat',
+ name: 'test-derived-chat-composer',
components: {
- chat: {
+ 'chat-composer': {
base: {borderRadius: '24px', padding: '12px'},
},
},
});
const rules = generateThemeRules(theme);
- const rule = rules.find(r => r.includes('.astryx-chat'));
+ const rule = rules.find(r => r.includes('.astryx-chat-composer'));
expect(rule).toBeDefined();
+ expect(rule).toMatch(/^\s*border-radius: 24px;/m);
+ expect(rule).toMatch(/^\s*padding: 12px;/m);
expect(rule).toContain('--_chat-composer-radius: 24px');
expect(rule).toContain('--_chat-composer-padding: 12px');
});