facebook / facebook/stylex

API for CSS variable fallback inside defineConsts and defineVars.

Open
#1,483 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
10.3k
Forks
481
Avg merge
3d 8h
Merged PRs (30d)
13

Description

### 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:

```js
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
```js
stylex.defineConsts({
myShadow: `0px 1px 1px var(--my-shadow-color, ${vars.myShadowDefaultColor})`,
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.