[material-ui][Badge] Use inline CSS variables for anchorOrigin/overlap positioning by siriwatknp · Pull Request #48549 · mui/material-ui (original) (raw)
Follow-up to #47742.
Instead of computing positioning via a style: ({ ownerState }) => {...} callback in the styled variants array, this PR:
- Replaces the callback with a plain object that references CSS variables.
- Moves the
anchorOrigin×overlapconditional logic onto the badge slot's inlinestyle, which sets those CSS variables.
Why
- Keeps the styled
variantspurely declarative (plain objects only). - Pushes per-render conditional logic out of the styled engine — cheaper at render time and easier for static extraction tools.
Variables
Three CSS variables drive positioning, leveraging existing CSS shorthand:
--Badge-translate—translateX, translateY(comma-separated, for thetranslate()function)--Badge-inset—top right bottom left(space-separated, for theinsetshorthand)--Badge-origin—X Y(space-separated, fortransform-origin)
Follows the same "inline-style sets a --ComponentName-* variable, styled CSS consumes it" pattern already used by:
AvatarGroup—--AvatarGroup-spacing(from thespacingprop)Typography—--Typography-textAlign(from thealignprop)TabScrollButton—--TabScrollButton-svgRotate(from RTL + orientation)
Behavior
No visible change. Same eight outcomes (top/bottom × left/right × rectangular/circular) produce the same CSS output as before #47742.