An open source design system that's fully customizable and agent ready
TypeScript
feat(theme): let the textarea slot drive --_textarea-inline-padding (#4793)
freddymeta0b5a38e98831
diff --git a/.changeset/textarea-padding-inline-theme.md b/.changeset/textarea-padding-inline-theme.mdnew file mode 100644index 0000000000..4712cd9f24--- /dev/null+++ b/.changeset/textarea-padding-inline-theme.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] TextArea: theme the text inset by writing `paddingInline` on the `textarea` component key — it now drives the internal `--_textarea-inline-padding` var instead of landing on the wrapper. The wrapper stays flush (`padding: 0`), so the native resize grip keeps its true-corner position and the start icon, status, and character counter stay aligned to the text. Adds a `replaces` option to derived var entries for the general "map a property onto a var without emitting it on the class element" case.++@freddymetadiff --git a/packages/cli/authoring/doctypes/base/type.ts b/packages/cli/authoring/doctypes/base/type.tsindex ef545e6078..bb909f0e64 100644--- a/packages/cli/authoring/doctypes/base/type.ts+++ b/packages/cli/authoring/doctypes/base/type.ts@@ -270,6 +270,12 @@ export interface ComponentThemingDerivedVar {/** Named expansion strategy instead of specific vars.* `'container'` — expands padding to 7 container layout tokens. */expand?: 'container';+ /** Emit only the internal `vars`, dropping the source property from the+ * generated rule. Use when the class-carrying element must not receive the+ * standard property itself — the value reaches a child through the var+ * (e.g. TextArea's flush wrapper drives the inner textarea's inline+ * padding). Without this, the property is emitted alongside the var. */+ replaces?: boolean;}/**diff --git a/packages/core/src/TextArea/TextArea.doc.mjs b/packages/core/src/TextArea/TextArea.doc.mjsindex fe8a609669..b4931d9591 100644--- a/packages/core/src/TextArea/TextArea.doc.mjs+++ b/packages/core/src/TextArea/TextArea.doc.mjs@@ -181,6 +181,18 @@ export const docs = {targets: [{className: 'astryx-textarea', visualProps: ['size', 'status'], states: ['disabled']},],+ vars: [+ {+ name: '--_textarea-inline-padding',+ description:+ "Inline padding of the textarea's text. The wrapper stays flush (padding: 0) so the native resize grip sits in the true corner; this var carries the inset on the inner <textarea>, and the start icon, status/spinner, and character counter align to it.",+ default: 'var(--spacing-2)',+ private: true,+ },+ ],+ derived: [+ {property: 'paddingInline', vars: ['--_textarea-inline-padding'], replaces: true},+ ],},usage: {description:@@ -357,6 +369,18 @@ export const docsZh = {targets: [{className: 'astryx-textarea', visualProps: ['size', 'status'], states: ['disabled']},],+ vars: [+ {+ name: '--_textarea-inline-padding',+ description:+ '文本域文本的行内内边距。外层容器保持无内边距(padding: 0),使原生缩放手柄位于真正的角落;该变量在内部 <textarea> 上承载内边距,起始图标、状态/加载指示器和字符计数器都与之对齐。',+ default: 'var(--spacing-2)',+ private: true,+ },+ ],+ derived: [+ {property: 'paddingInline', vars: ['--_textarea-inline-padding'], replaces: true},+ ],},usage: {description:diff --git a/packages/core/src/theme/derivedVarRegistry.test.ts b/packages/core/src/theme/derivedVarRegistry.test.tsindex 94b52e14a3..da50250ebc 100644--- a/packages/core/src/theme/derivedVarRegistry.test.ts+++ b/packages/core/src/theme/derivedVarRegistry.test.ts@@ -197,6 +197,7 @@ const DIR_TO_REGISTRY_KEY: Record<string, string> = {Popover: 'popover',Section: 'section',SegmentedControl: 'segmented-control',+ TextArea: 'textarea',};/**@@ -339,4 +340,11 @@ describe('getDerivedVars', () => {it('returns empty for unregistered property', () => {expect(getDerivedVars('card', 'color')).toEqual([]);});++ it('marks textarea paddingInline as replacing the source property', () => {+ const result = getDerivedVars('textarea', 'paddingInline');+ expect(result).toHaveLength(1);+ expect(result[0].vars).toEqual(['--_textarea-inline-padding']);+ expect(result[0].replaces).toBe(true);+ });});diff --git a/packages/core/src/theme/derivedVarRegistry.ts b/packages/core/src/theme/derivedVarRegistry.tsindex 3a037c2f4a..9b977dd2ee 100644--- a/packages/core/src/theme/derivedVarRegistry.ts+++ b/packages/core/src/theme/derivedVarRegistry.ts@@ -25,6 +25,14 @@ export interface DerivedVarEntry {vars?: string[];/** Named expansion strategy. 'container' expands padding to container tokens. */expand?: 'container';+ /**+ * Emit only the internal `vars`, dropping the source property from the rule.+ * Use when the class-carrying element must NOT receive the standard property+ * itself — the value is consumed by a child through the var instead. Without+ * this, the property is emitted alongside the var (correct when the same+ * element both reads the var and applies the property, e.g. Chat/DropdownMenu).+ */+ replaces?: boolean;}/**@@ -61,6 +69,13 @@ export const derivedVarRegistry: Record<string, DerivedVarEntry[]> = {{property: 'borderRadius', vars: ['--_segmented-control-radius']},{property: 'padding', vars: ['--_segmented-control-padding']},],+ textarea: [+ {+ property: 'paddingInline',+ vars: ['--_textarea-inline-padding'],+ replaces: true,+ },+ ],};/**diff --git a/packages/core/src/theme/generateThemeRules.test.ts b/packages/core/src/theme/generateThemeRules.test.tsindex d8c4f886b8..7e3747a860 100644--- a/packages/core/src/theme/generateThemeRules.test.ts+++ b/packages/core/src/theme/generateThemeRules.test.ts@@ -475,6 +475,27 @@ describe('derived var expansion', () => {expect(rule).toContain('border-radius: 16px');expect(rule).toContain('--_card-radius: 16px');});++ it('replaces paddingInline with the var for textarea (no raw property)', () => {+ const theme = defineTheme({+ name: 'test-derived-textarea',+ components: {+ textarea: {+ base: {paddingInline: 'var(--eps-input-padding-x)'},+ },+ },+ });+ const rules = generateThemeRules(theme);+ const rule = rules.find(r => r.includes('.astryx-textarea'));+ expect(rule).toBeDefined();+ // Value flows to the inner <textarea> via the var…+ expect(rule).toContain(+ '--_textarea-inline-padding: var(--eps-input-padding-x)',+ );+ // …and must NOT land on the flush wrapper, which would re-inset the+ // full-bleed textarea and push the native resize grip off the corner.+ expect(rule).not.toContain('padding-inline: var(--eps-input-padding-x)');+ });});describe('brutalist-style derived expansion', () => {diff --git a/packages/core/src/theme/generateThemeRules.ts b/packages/core/src/theme/generateThemeRules.tsindex 8bbeaea935..f48f317902 100644--- a/packages/core/src/theme/generateThemeRules.ts+++ b/packages/core/src/theme/generateThemeRules.ts@@ -350,9 +350,11 @@ function generateComponentRules(// Entries are processed in order (priority).// - `vars`: emit internal CSS custom property declarations// - `expand: 'container'`: expand padding to container layout tokens+ // - `replaces: true`: emit only the var, dropping the source propertylet finalProps = props;const derivedProps: [string, string][] = [];let containerExpanded = false;+ const replacedProps = new Set<string>();for (const [prop, value] of props) {const derived = getDerivedVars(component, prop);@@ -366,6 +368,9 @@ function generateComponentRules(if (entry.expand === 'container' && PADDING_PROPS.has(prop)) {containerExpanded = true;}+ if (entry.replaces) {+ replacedProps.add(prop);+ }if (entry.vars) {for (const varName of entry.vars) {derivedProps.push([varName, value]);@@ -384,6 +389,12 @@ function generateComponentRules(finalProps = [...nonPaddingProps, ...containerTokens];}+ // Drop properties whose derived entry set `replaces` — their value is+ // carried by the emitted var and must not land on the class element.+ if (replacedProps.size > 0) {+ finalProps = finalProps.filter(([p]) => !replacedProps.has(p));+ }+if (derivedProps.length > 0) {finalProps = [...finalProps, ...derivedProps];}