Skip to content

[material-ui] POC: public agnostic CSS variables + density#48568

Draft
siriwatknp wants to merge 4 commits into
mui:masterfrom
siriwatknp:poc/css-vars-map
Draft

[material-ui] POC: public agnostic CSS variables + density#48568
siriwatknp wants to merge 4 commits into
mui:masterfrom
siriwatknp:poc/css-vars-map

Conversation

@siriwatknp
Copy link
Copy Markdown
Member

POC / not for merge. Exploratory draft to discuss public CSS variables + density for Material UI components.

What

POC exploring whether Material UI components should expose hand-authorable, agnostic CSS variables for color/border/radius/shadow/font-size/spacing, so theming is easier and "density" can be experimented with via a single dial.

Scope: Button (direct-padding density) + OutlinedInput / TextField / InputBase (layered, height-derived density). FilledInput / standard Input / Select deferred.

Key ideas

  • Public CSS variable = agnostic. Exactly one var per styleable property, no variant/size/color/state in the name (--Button-bg, --Button-radius, --TextField-border-color). No --mui- prefix. Overriding it opts that property out of the Material spec and hands the consumer full control.
  • Two-tier color. Public agnostic vars layer over the existing private --variant-* palette source: var(--Button-bg, var(--variant-containedBg)). Default falls through to the spec → unbroken. Color is resting-only by design (customize color → you own hover/active states).
  • Density via --mui-spacing. Reuses the single base spacing dial emitted under cssVariables: true. Override it at a scope (class or @media) → whole UI reflows. Button padding scales directly; input height scales (--InputBase-height defaults to spacing(7)/spacing(5)) and padding is derived to keep text centered.
  • Inward dependency rule. A component's fallback chain references only its own vars and the vars of components it renders/extends — never its consumers'. TextField maps --OutlinedInput-*: var(--TextField-*); OutlinedInput (extends InputBase) may reference --InputBase-*; InputBase mentions neither.

Docs in this PR

  • CONTEXT.md — language, decisions, relationships
  • docs/adr/0001-public-css-var-inward-dependency.md
  • docs/adr/0002-agnostic-public-css-vars.md
  • docs/design/public-css-var-layering.md — worked example + rejected alternatives
  • docs/pages/experiments/css-vars-density.tsx — live demo (Different Apps via class scope; Different Viewports via @media)

Open questions

  • Named spacing-token scale (xxs…xxl) — deferred; would slot under the single dial without component changes.
  • Font-weight + remaining color axes deferred.
  • Negative-padding floor when height < line-height·font-size.

Expose hand-authorable padding/height CSS vars on Button, InputBase,
OutlinedInput, TextField; rewire to theme.spacing() so --mui-spacing
drives holistic density. Inputs are height-driven (padding derived).
Adds CONTEXT.md, ADR-0001, layering design doc, experiment page.
--Button-font-size on all sizes; inputs via --InputBase-font-size with
variant chain --OutlinedInput-font-size and TextField mapping
--TextField-font-size. Input height formula's 1em tracks font-size, so
text re-centers in the fixed height automatically. Adds responsive
font-size experiment section; switch demo rows to useFlexGap.
…vars

--Button-bg/color/border-color/border-width/radius/shadow, layered over
private --variant-* spec source; resting-only. --Button-border-width also
drives outlined padding compensation. Adds ADR-0002 (agnostic public vars
are the public API contract).
--TextField-color/border-color/border-width/radius mapped to variant-level
--OutlinedInput-* (inward rule), consumed by NotchedOutline slot + root.
Border-width focus uses var(--OutlinedInput-border-width, 2px): default
1px->2px preserved, focus = resting when customized. No --TextField-bg
(InputBase styles no background). Resting-only.
@code-infra-dashboard
Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48568--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+2.96KB(+0.58%) 🔺+528B(+0.36%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant