An open source design system that's fully customizable and agent ready
TypeScript
feat(core): add EmptyState title and description theme targets (#4942)
freddymetabbc3612b8b83
diff --git a/.changeset/empty-state-title-description-targets.md b/.changeset/empty-state-title-description-targets.mdnew file mode 100644index 0000000000..e4c431da8c--- /dev/null+++ b/.changeset/empty-state-title-description-targets.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] EmptyState: add `empty-state-title` and `empty-state-description` theme targets on the title heading and the description. A theme can now restyle the title and description directly (e.g. font size, color, per `variant`) instead of reaching them through structural `> div:has(> :is(h1..h6))` selectors that reverse-engineer which element is which.++@freddymetadiff --git a/packages/core/src/EmptyState/EmptyState.doc.mjs b/packages/core/src/EmptyState/EmptyState.doc.mjsindex 542ac6d393..1fcd7a7e9e 100644--- a/packages/core/src/EmptyState/EmptyState.doc.mjs+++ b/packages/core/src/EmptyState/EmptyState.doc.mjs@@ -66,6 +66,8 @@ export const docs = {theming: {targets: [{className: 'astryx-empty-state', visualProps: ['variant']},+ {className: 'astryx-empty-state-title', visualProps: ['variant']},+ {className: 'astryx-empty-state-description', visualProps: ['variant']},],},usage: {@@ -141,6 +143,8 @@ export const docsZh = {theming: {targets: [{className: 'astryx-empty-state', visualProps: ['variant']},+ {className: 'astryx-empty-state-title', visualProps: ['variant']},+ {className: 'astryx-empty-state-description', visualProps: ['variant']},],},usage: {diff --git a/packages/core/src/EmptyState/EmptyState.test.tsx b/packages/core/src/EmptyState/EmptyState.test.tsxindex 300d4380f0..88933a6c24 100644--- a/packages/core/src/EmptyState/EmptyState.test.tsx+++ b/packages/core/src/EmptyState/EmptyState.test.tsx@@ -3,6 +3,13 @@import {describe, it, expect} from 'vitest';import {render, screen} from '@testing-library/react';import {EmptyState} from './EmptyState';+import {defineTheme} from '../theme/defineTheme';+import {generateThemeCSS} from '../theme/generateThemeRules';++function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {+ const {prose, component} = generateThemeCSS(theme);+ return [prose, component].filter(Boolean).join('\n\n');+}describe('EmptyState', () => {it('renders with title', () => {@@ -148,4 +155,59 @@ describe('EmptyState', () => {expect(screen.getByText('Clear filters')).toBeInTheDocument();expect(screen.getByText('Go back')).toBeInTheDocument();});++ describe('theming targets', () => {+ it('puts astryx-empty-state-title on the title heading', () => {+ render(<EmptyState title="No results" />);+ const heading = screen.getByRole('heading', {name: 'No results'});+ expect(heading).toHaveClass('astryx-empty-state-title');+ });++ it('puts astryx-empty-state-description on the description', () => {+ render(+ <EmptyState title="No results" description="Try another search." />,+ );+ const description = screen.getByText('Try another search.');+ expect(description).toHaveClass('astryx-empty-state-description');+ });++ it('reflects the compact variant on the title and description targets', () => {+ render(+ <EmptyState+ title="No results"+ description="Try another search."+ isCompact+ />,+ );+ expect(screen.getByRole('heading', {name: 'No results'})).toHaveAttribute(+ 'data-variant',+ 'compact',+ );+ expect(screen.getByText('Try another search.')).toHaveAttribute(+ 'data-variant',+ 'compact',+ );+ });++ it('exposes the title and description as themeable defineTheme targets', () => {+ // jsdom can't resolve the @layer cascade, so this asserts the targets are+ // reachable by a theme via the sanctioned defineTheme channel — replacing+ // the structural `> div:has(> :is(h1..h6))` heading-detection selectors a+ // consumer would otherwise need to restyle the title and description.+ const theme = defineTheme({+ name: 'empty-state-target-test',+ components: {+ 'empty-state-title': {+ base: {fontSize: 'var(--text-large-size)'},+ },+ 'empty-state-description': {+ base: {color: 'var(--color-text-secondary)'},+ },+ },+ });+ const css = generateThemeTestCSS(theme);+ expect(css).toContain('.astryx-empty-state-title');+ expect(css).toContain('.astryx-empty-state-description');+ });+ });});diff --git a/packages/core/src/EmptyState/EmptyState.tsx b/packages/core/src/EmptyState/EmptyState.tsxindex 820c75ad71..1fec136e78 100644--- a/packages/core/src/EmptyState/EmptyState.tsx+++ b/packages/core/src/EmptyState/EmptyState.tsx@@ -173,7 +173,12 @@ export function EmptyState({<div {...stylex.props(styles.textGroup)}>{createElement(HeadingTag,- stylex.props(styles.title, isCompact && styles.titleCompact),+ mergeProps(+ themeProps('empty-state-title', {+ variant: isCompact ? 'compact' : null,+ }),+ stylex.props(styles.title, isCompact && styles.titleCompact),+ ),title,)}{description != null && (@@ -182,9 +187,14 @@ export function EmptyState({// mismatches. The StyleX style sets margin: 0, so appearance is// unchanged.<div- {...stylex.props(- styles.description,- isCompact && styles.descriptionCompact,+ {...mergeProps(+ themeProps('empty-state-description', {+ variant: isCompact ? 'compact' : null,+ }),+ stylex.props(+ styles.description,+ isCompact && styles.descriptionCompact,+ ),)}>{description}</div>