Skip to content

feat(core): make TreeList per-level indent a themeable CSS variable - #4530

Merged
cixzhang merged 1 commit into
mainfrom
feat/tree-list-indent-var
Jul 30, 2026
Merged

cixzhang merged 1 commit into
mainfrom
feat/tree-list-indent-var

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Summary

The TreeList per-level indentation step was hardcoded to --spacing-4 and applied as an inline margin-inline-start on the row's content wrapper — the same element that carries the astryx-tree-list-item theme target. Because an inline longhand outranks every cascade layer, the indent was unreachable from @layer astryx-theme, so a theme couldn't retune it (the exact problem RFC #4308 raised).

This makes the step a public, documented, themeable CSS variable: --tree-list-indent (default var(--spacing-4)), set on the tree-list root. A theme can now widen or tighten the indent — e.g. to var(--spacing-5) — through the sanctioned channel:

defineTheme({
  name: 'wide-tree',
  components: {
    'tree-list': { base: { '--tree-list-indent': 'var(--spacing-5)' } },
  },
});

Both the row margins (TreeListItem) and the guide-line offsets (TreeListBranches) read the same variable, so guides stay aligned when the step is retuned.

How it works

  • Public lever — --tree-list-indent is declared on styles.root (the tree-list target) and documented in TreeList.doc.mjs theming.vars[], so it shows up in astryx component TreeList and the theming panel. It follows the --<component>-<property> naming convention (public → no --_ prefix).
  • Cascade fix (RFC RFC: Make TreeList row indentation themeable (currently an inline style on the highlighted element) #4308, Option A) — the computed per-row distance (calc(level * var(--tree-list-indent)), plus the fixed chevron-column offset for leaves) now rides the private --_tree-indent custom property instead of the inline longhand. The margin-inline-start declaration lives in @layer astryx-base (via StyleX), so the theme layer overrides it in normal cascade order. A custom property carries a value, not a declaration, so it doesn't create the same specificity floor.

Rendering is unchanged at every nesting depth (same default --spacing-4 step, same leaf chevron offset).

Relationship to #4448

#4448 implements Option A of the same RFC (moving the indent value off the inline longhand) but keeps the step hardcoded via the private --_tree-indent. This PR does that cascade fix and exposes the step itself as the public, documented --tree-list-indent lever — which is the "one-line rename to a documented --astryx-* lever" that PR's author explicitly offered. If maintainers prefer to land these separately, this can be rebased on top of #4448; happy to defer.

Tests

  • Updated the existing noGuides indentation test to read the published --_tree-indent distance instead of the removed inline longhand (intent unchanged: indent survives noGuides and grows with depth).
  • Added an indent lever describe block: a defineTheme override test proving --tree-list-indent reaches the tree-list target in generated CSS, and a test that rows consume var(--tree-list-indent) in their published distance.

All 66 TreeList tests pass, plus the theming.vars/theming.targets consistency suites. Core typecheck, lint, build, and docsite generate are green.

The per-level indentation step was hardcoded to --spacing-4 and applied
as an inline margin-inline-start on the row's content wrapper — the same
element that carries the astryx-tree-list-item theme target. An inline
longhand outranks every cascade layer, so the indent was unreachable from
@layer astryx-theme.

Publish the step as the public --tree-list-indent variable (default
var(--spacing-4)) set on the tree-list root. Both the row margins and the
guide-line offsets read it, so a theme can retune the indent metric (e.g.
to var(--spacing-5)) via defineTheme on the tree-list target and the
guides stay aligned. The computed per-row distance now rides the private
--_tree-indent custom property instead of the inline longhand, so the
margin-inline-start declaration lives in @layer astryx-base and the theme
layer overrides it in normal cascade order (#4308).
@vercel

vercel Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Jul 29, 2026 11:55pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 29, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Jul 29, 2026
github-actions Bot added a commit that referenced this pull request Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

TreeList · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 762 -
Complexity N/A Very High (78) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang marked this pull request as ready for review July 30, 2026 01:10
@cixzhang
cixzhang merged commit e6c6c23 into main Jul 30, 2026
21 checks passed
@github-actions
github-actions Bot deleted the feat/tree-list-indent-var branch July 30, 2026 06:57
cixzhang added a commit that referenced this pull request Aug 24, 2026
… but unsettable (#5409)

collectThemingVars joins collectThemingTargets as part of the one theming
enumeration, and two checks ride on it. A documented public var no component
reads compiles to a declaration that never applies (#5012). A var the component
writes inline outranks every cascade layer, so no theme can reach it (#4530).
Both shipped, and neither is visible in the generated theme CSS, which is the
artifact the jsdom suites assert on.
cixzhang added a commit that referenced this pull request Aug 24, 2026
… in a production build (#5410)

* test(cli): guard public component theme vars against being documented but unsettable

collectThemingVars joins collectThemingTargets as part of the one theming
enumeration, and two checks ride on it. A documented public var no component
reads compiles to a declaration that never applies (#5012). A var the component
writes inline outranks every cascade layer, so no theme can reach it (#4530).
Both shipped, and neither is visible in the generated theme CSS, which is the
artifact the jsdom suites assert on.

* fix(build): theme component overrides now apply in a production build

StyleX emits its rules into its own top-level @layer priority1...priorityN. The
dev server re-serves those wrapped in astryx-base and the pre-compiled
astryx.css ships them wrapped, but a Vite build did neither, so the priority
layers sorted after astryx-theme and outranked it. Every components: {} override
a theme sets was silently dropped in the built app while working in dev.

All seven shipped themes carry components: blocks, so this changes what a built
app renders. theme-var-reachability.js drives Chromium against the built
Storybook and fails when a theme's declaration does not land on the element; it
fails on all four documented public vars before this fix and passes after.

* fix(build): split Astryx and product styles into their layers, do not wrap both

The previous commit wrapped everything StyleX emitted in the library layer.
That fixed the theme and broke the app: product StyleX landed below
astryx-theme too, so a theme could silently restyle code it does not own.

Partition by source file, the way the dev server always has. StyleX's shared
rule store is reachable at build time and is keyed by absolute source path,
which is the only place the origin survives — by the time the CSS is text it is
gone, so the wrap had nothing sound to split on. Both plugins now call one
renderSplitLayers helper; the lifecycles differ, the partition does not.

The replacement runs the same lightningcss pass StyleX does, or the build would
quietly lose the vendor prefixes the original output had.

Tests: vite.build.test.ts runs a real Vite build of a fixture app that renders
an Astryx component and authors its own StyleX, then reads the emitted
stylesheet. theme-layer-cascade.js renders that build in Chromium and asserts
Astryx < theme < product, which no jsdom test can. Both were watched failing
against the unsplit and the wrapped builds.

* chore(build): copyright header on the layer-split fixture page

* ci: run the theme layer cascade guard in its own job

It was in pr-a11y, which runs only when packages/core or packages/lab changed.
What it guards is packages/build, so on this PR — the one that changes the
splitting logic — it did not run at all.

* fix(build): link the stylesheet StyleX writes when an app imports no CSS

An app that imports no stylesheet of its own gives StyleX no bundle asset to
append to, so it writes assets/stylex.css itself — outside Rollup's graph, which
means Vite's HTML plugin never learns about it and emits no <link>. The app
shipped every Astryx style correctly split into layers and a completely
unstyled page. Importing any stylesheet hides it, which is why it survived: one
line of the project's own CSS and the symptom disappears.

Only orphans are linked. A stylesheet a page already references is Vite's, and
touching it would load it twice; a build with no HTML at all — library mode —
is left alone, because its consumer imports the CSS themselves.

The build test now covers both emission paths as two fixtures running the same
assertions, including that the page links the stylesheet exactly once. Verified
across app shapes: css-import, no-css-import, no-product-StyleX (no empty
product layer), multiple entries, library mode, write:false, minify on and off,
and an app with no Astryx at all (no spurious build failure).
AKnassa added a commit to AKnassa/astryx that referenced this pull request Aug 27, 2026
Conflicts: TreeList.tsx, TreeListItem.tsx, TreeListTypes.ts, index.ts —
resolved as a union of main's TreeListVariant / Icon-rendered chevron /
flush-leaf column logic (meta#4838, meta#4540, meta#4530, meta#4334) and this branch's
renderExpandIcon. A leaf that renders its own indicator no longer reserves
the chevron column. The four alignment tests now read the published
--_tree-indent custom property instead of the removed inline marginLeft.

This branch was successfully deployed

1 active deployment
Preview — 6bde7857 Deployed Jul 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant