An open source design system that's fully customizable and agent ready
TypeScript
feat(collapsible): anchor body typography on content area (#4126)
Cindy Zhang30638c8581ab
diff --git a/.changeset/collapsible-content-typography.md b/.changeset/collapsible-content-typography.mdnew file mode 100644index 0000000000..832313c9df--- /dev/null+++ b/.changeset/collapsible-content-typography.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[feat] Collapsible: the content area now anchors body typography (font family, size, weight, line-height) instead of inheriting from its surroundings, and exposes a stable `astryx-collapsible-content` theme target so revealed text can be themed externally.+@cixzhangdiff --git a/packages/core/src/Collapsible/Collapsible.doc.mjs b/packages/core/src/Collapsible/Collapsible.doc.mjsindex 0d9a8d7732..20362dae55 100644--- a/packages/core/src/Collapsible/Collapsible.doc.mjs+++ b/packages/core/src/Collapsible/Collapsible.doc.mjs@@ -17,6 +17,7 @@ export const docs = {theming: {targets: [{className: 'astryx-collapsible', visualProps: ['density']},+ {className: 'astryx-collapsible-content', visualProps: ['density']},{className: 'astryx-collapsible-group', visualProps: ['density']},],},diff --git a/packages/core/src/Collapsible/Collapsible.test.tsx b/packages/core/src/Collapsible/Collapsible.test.tsxindex 14c15a5b0c..2b9acd3147 100644--- a/packages/core/src/Collapsible/Collapsible.test.tsx+++ b/packages/core/src/Collapsible/Collapsible.test.tsx@@ -72,6 +72,12 @@ describe('Collapsible', () => {expect(screen.getByTestId('root')).toHaveClass('astryx-collapsible');});+ it('renders the stable astryx-collapsible-content class on the content area', () => {+ render(<Collapsible trigger="T">c</Collapsible>);+ const content = contentFor(screen.getByRole('button'));+ expect(content).toHaveClass('astryx-collapsible-content');+ });+it('renders a ReactNode trigger, not just a string', () => {render(<Collapsible trigger={<span data-testid="rich">Rich</span>}>diff --git a/packages/core/src/Collapsible/Collapsible.tsx b/packages/core/src/Collapsible/Collapsible.tsxindex 6b1d586668..8b9d863631 100644--- a/packages/core/src/Collapsible/Collapsible.tsx+++ b/packages/core/src/Collapsible/Collapsible.tsx@@ -39,6 +39,7 @@ import {durationVars,easeVars,} from '../theme/tokens.stylex';+import {useCollapsible} from './useCollapsible';import {CollapsibleGroupPresentationContext} from './CollapsibleGroupContext';import {getIcon} from '../Icon/globalIconRegistry';@@ -102,8 +103,17 @@ const styles = stylex.create({contentHidden: {display: 'none',},+ // Anchors body typography so revealed text renders at the system's body+ // scale (family/size/weight/leading) instead of inheriting from wherever+ // the Collapsible is placed. External themes override via the+ // `astryx-collapsible-content` target.content: {paddingBlockStart: spacingVars['--spacing-1'],+ fontFamily: typographyVars['--font-family-body'],+ fontSize: typeScaleVars['--text-body-size'],+ fontWeight: typeScaleVars['--text-body-weight'],+ lineHeight: typeScaleVars['--text-body-leading'],+ color: colorVars['--color-text-primary'],},// Group divider chrome — a hairline above every item except the first.// The group's wrapper (or 'all' mode) owns the outer edges.@@ -286,10 +296,15 @@ export function Collapsible({</button><divid={contentId}- {...stylex.props(- styles.content,- density != null && contentDensity[density],- !isOpen && styles.contentHidden,+ {...mergeProps(+ themeProps('collapsible-content', {+ density: density ?? undefined,+ }),+ stylex.props(+ styles.content,+ density != null && contentDensity[density],+ !isOpen && styles.contentHidden,+ ),)}>{presentation != null ? (<CollapsibleGroupPresentationContext value={null}>