Skip to content
Discussion options

You must be logged in to vote

Yes, this is a supported pattern. Create an issue if you run into issues with this.

Note: You still need to define all variables in .stylex.ts files and export the consts as named exports.


I would recommend rewriting your code as follows:

// <filename>.stylex.ts
const [DARK] = '@media (prefers-color-scheme: dark)';

export const colors = stylex.defineVars({
  accent: {
    default: '#1763CF',
    [DARK]: '#1763CF',
  },
  accent2: 'red',
});

export const tokens = stylex.defineVars({
  badgeBgColorBlue:  colors.accent,
  badgeBgColorRed':  colors.accent2,
});

The key names in the defineVars have no effect on the generated variables names (they are hashes), so you might as well use keys t…

Replies: 1 comment 3 replies

Comment options

nmn
Dec 9, 2023
Collaborator

You must be logged in to vote
3 replies
@nmn
Comment options

nmn Dec 9, 2023
Collaborator

@tienlx97
Comment options

@nmn
Comment options

nmn Dec 10, 2023
Collaborator

Answer selected by nmn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants