stylex icon indicating copy to clipboard operation
stylex copied to clipboard

API for CSS variable fallback inside defineConsts and defineVars.

Open chbybnwr opened this issue 9 months ago • 0 comments

Describe the feature request

Feature request

I would like to be able to use fallback for css variables inside defineConsts and defineVars.

Suggestion 1

I suggest an API like:

stylex.defineConsts({
  myShadow: `0px 1px 1px ${stylex.firstThatWorks(vars.myShadowColor, vars.myShadowDefaultColor)}`,
});

Which would be compiled to:

0px 1px 1px var(--x-myShadowColor, --x-myShadowDefaultColor)

Workaround

stylex.defineConsts({
  myShadow: `0px 1px 1px var(--my-shadow-color, ${vars.myShadowDefaultColor})`,
});

chbybnwr avatar Feb 10 '26 05:02 chbybnwr