Skip to content

Must Media Queries be nested as conditions within style properties? #477

Answered by nmn
jian-ong asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a better way to achieve we're after?

I'll start with the solution, which is CSS variables:

Create a file next to your base component and export a VarGroup called base tokens.

const baseTokens = stylex.defineVars({
  marginTop: "10px",
});

Update the base component to use this variable:

const baseTokens = stylex.defineVars({
  marginTop: baseTokens.marginTop,
});

Document these "base" tokens for override styles, so this can be done:

const extendedStyle = stylex.create({
  base: {
    marginTop: {
      default: baseTokens.marginTop,
      '@media only screen and (max-width: 640px)': '100px'
    }
  }
})'

const styles = stylex.props(baseStyle.base, extendedStyle.base)

Why things…

Replies: 1 comment

Comment options

nmn
Mar 4, 2024
Collaborator

You must be logged in to vote
0 replies
Answer selected by jian-ong
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