Skip to content

using stylex.defineConsts and exposing raw values from theme - #16

Merged
czarandy merged 1 commit into
mainfrom
defineConst
Jan 21, 2026
Merged

czarandy merged 1 commit into
mainfrom
defineConst

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Uses stylex defineConsts as well as meta/stylex#1219 for setting up variables.

I did it this way because I've found that we often need to have access to the raw values for some 3rd party library features like data visualizations or lexical. Using defineConsts allows us to have access to these raw values while still preserving the ability to use CSS variables at the cost of making those variables more publically accessible.

Right now the default theme raw values are like light-dark(A, B) but it's possible for us to parse our the specific values for each mode or handle other color types programmatically for 3P.

This also simplifies token access and application to our components.

Observe that theming still works in storybook:

Screenshot 2026-01-21 at 11 45 03 AM Screenshot 2026-01-21 at 11 44 57 AM Screenshot 2026-01-21 at 11 44 42 AM

@cixzhang
cixzhang requested a review from mellyeliu January 21, 2026 19:50
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 21, 2026
@czarandy
czarandy merged commit 530dd43 into main Jan 21, 2026
2 checks passed
@cixzhang
cixzhang deleted the defineConst branch January 21, 2026 19:53
@mellyeliu

Copy link
Copy Markdown
Member

There are two primary issues to using create/props instead of defineVars/createTheme:

  1. Losing the VarGroup guarantee that each theme sets all variables (and unset keys are reset)
  2. It creates a single class to set all variables and not one class per variable.

2 is pretty critical for performance

Will put something up that uses the -- defineVars syntax to do something similar

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants