Skip to content

Toggle dark mode stylex facebook #511

Answered by nmn
felpereira asked this question in Q&A
Mar 30, 2024 · 3 comments · 12 replies
Discussion options

You must be logged in to vote

You'd need two themes as well.

import {color} from './globalTheme.stylex'

export const light = stylex.createTheme(color, {
  primaryText: 'black',
  secondaryText: '#333',
  accent: 'blue',
  background: 'white',
  lineColor: 'gray',
});

export const dark = stylex.defineVars({
  primaryText: 'white',
  secondaryText: '#ccc',
  accent: 'lightblue',
  background: 'black',
  lineColor: 'lightgray',
});

Now, somewhere near the root of your app you can conditionally wrap everything with one of the two themes.

import {light, dark} from './themes'

function Root({children}) {
  const [theme, setTheme] = useState('auto');

  return (
    <div {...stylex.props(
      theme === 'light' && light,

Replies: 3 comments 12 replies

Comment options

You must be logged in to vote
4 replies
@TxHawks
Comment options

@nmn
Comment options

nmn May 21, 2024
Collaborator

@TxHawks
Comment options

@nmn
Comment options

nmn May 21, 2024
Collaborator

Answer selected by felpereira
Comment options

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

nmn Apr 1, 2024
Collaborator

@felpereira
Comment options

Comment options

You must be logged in to vote
6 replies
@predaytor
Comment options

@predaytor
Comment options

@nmn
Comment options

nmn Apr 24, 2024
Collaborator

@predaytor
Comment options

@nmn
Comment options

nmn Jun 30, 2024
Collaborator

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