Skip to content

Using Stylex with Theme hook #147

Closed Answered by nmn
Amrender-Singh asked this question in Q&A
Dec 12, 2023 · 4 comments · 9 replies
Discussion options

You must be logged in to vote

Please use the StyleX theme APIs.

Short explanations. I'll use a theme of just a few colors as an example.

First define the "default theme".

Define all the variables you need along with default values in a file that ends with .stylex.ts.

import * as stylex from '@stylexjs/stylex'

export const colors = stylex.defineVars({
  primaryText: 'black',
  secondaryText: 'rgb(60,60,60)',
  primaryBg: 'white',
  secondaryBg: 'rgb(200,200,200)',
});

Define a bunch of themes in a separate file:

import * as stylex from '@stylexjs/stylex';
import {colors} from './vars.stylex';

export const dark = stylex.createTheme(colors, {
  primaryText: 'white',
  secondaryText: 'rgb(200,200,200)',
  primaryBg: 'rg…

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
4 replies
@Amrender-Singh
Comment options

@nmn
Comment options

nmn Dec 13, 2023
Collaborator

@Amrender-Singh
Comment options

@nmn
Comment options

nmn Dec 13, 2023
Collaborator

Answer selected by nmn
Comment options

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

nmn Feb 26, 2024
Collaborator

@fredrivett
Comment options

Comment options

You must be logged in to vote
1 reply
@fredrivett
Comment options

Comment options

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

nmn Mar 4, 2024
Collaborator

@sinthujan-calcey
Comment options

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