An open source design system that's fully customizable and agent ready
TypeScript
feat(collapsible): expose trigger as a distinct theming target (#4501)
freddymeta7770012b58b3
diff --git a/.changeset/collapsible-trigger-theme-target.md b/.changeset/collapsible-trigger-theme-target.mdnew file mode 100644index 0000000000..4154a2bf4e--- /dev/null+++ b/.changeset/collapsible-trigger-theme-target.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[feat] Collapsible: expose the trigger button as a distinct theming target (`astryx-collapsible-trigger`) so themes can style the trigger independently from the content — e.g. a heading font on the trigger while the content keeps the body font.+@freddymetadiff --git a/packages/core/src/Collapsible/Collapsible.doc.mjs b/packages/core/src/Collapsible/Collapsible.doc.mjsindex caf74dd6f5..2ee620df1b 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-trigger', 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 e833a74092..fb1c359708 100644--- a/packages/core/src/Collapsible/Collapsible.test.tsx+++ b/packages/core/src/Collapsible/Collapsible.test.tsx@@ -72,6 +72,13 @@ describe('Collapsible', () => {expect(screen.getByTestId('root')).toHaveClass('astryx-collapsible');});+ it('renders the stable astryx-collapsible-trigger class on the trigger button', () => {+ render(<Collapsible trigger="T">c</Collapsible>);+ expect(screen.getByRole('button')).toHaveClass(+ 'astryx-collapsible-trigger',+ );+ });+it('renders the stable astryx-collapsible-content class on the content area', () => {render(<Collapsible trigger="T">c</Collapsible>);const content = contentFor(screen.getByRole('button'));diff --git a/packages/core/src/Collapsible/Collapsible.tsx b/packages/core/src/Collapsible/Collapsible.tsxindex ef03a7c0c8..88e551cb1f 100644--- a/packages/core/src/Collapsible/Collapsible.tsx+++ b/packages/core/src/Collapsible/Collapsible.tsx@@ -51,7 +51,12 @@ const styles = stylex.create({root: {width: '100%',},- // Trigger button — full width, flex row, no browser button styling+ // Trigger button — full width, flex row, no browser button styling.+ // Anchors heading-adjacent typography (body family, large size, semibold)+ // so the label reads as a section header regardless of where the+ // Collapsible is placed. External themes retarget it independently from the+ // content via the `astryx-collapsible-trigger` target — e.g. a heading font+ // on the trigger while the content stays on the body font.trigger: {all: 'unset',boxSizing: 'border-box',@@ -113,7 +118,7 @@ const styles = stylex.create({// 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.+ // `astryx-collapsible-content` target, independently from the trigger.content: {paddingBlockStart: spacingVars['--spacing-1'],fontFamily: typographyVars['--font-family-body'],@@ -318,10 +323,15 @@ export function Collapsible({// the system-wide disabled convention (never native `disabled`, which// would swallow events like a wrapping tooltip's hover).tabIndex={isDisabled ? -1 : undefined}- {...stylex.props(- styles.trigger,- density != null && triggerDensity[density],- isDisabled && styles.triggerDisabled,+ {...mergeProps(+ themeProps('collapsible-trigger', {+ density: density ?? undefined,+ }),+ stylex.props(+ styles.trigger,+ density != null && triggerDensity[density],+ isDisabled && styles.triggerDisabled,+ ),)}><span {...stylex.props(styles.triggerLabel)}>{trigger}</span><span