Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the current color mode to functions used in sx #2065

Open
benface opened this issue Jan 7, 2022 · 3 comments
Open

Pass the current color mode to functions used in sx #2065

benface opened this issue Jan 7, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@benface
Copy link

benface commented Jan 7, 2022

Is your feature request related to a problem? Please describe.
I wouldn’t say it’s a problem, but something that could be improved.

Describe the solution you'd like
I would like to be able to do this:

<div
  sx={{
    boxShadow: (theme, colorMode) => colorMode === 'dark' ? `0px 0px 20px ${theme.colors.Shadow}` : `0px 0px 40px ${theme.colors.Shadow}`
  }}
/>

Describe alternatives you've considered
I know I can get the current color mode with the useThemeUI hook, but the above is terser and nicer in some cases. For instance, if I want to extract the function above for reuse, it would be easy to do:

<div
  sx={{
    boxShadow: BoxShadow.M,
  }}
/>

vs what I have to do at the moment:

const { colorMode } = useThemeUI()

<div
  sx={{
    boxShadow: getBoxShadow(BoxShadow.M, colorMode),
  }}
/>

Additional context
I am not sure if it’s possible/easy to add a second argument to the function. Perhaps instead it could be added as a property on the theme?

Thank you very much for your consideration!

@lachlanjc lachlanjc added the enhancement New feature or request label Jan 8, 2022
@lachlanjc
Copy link
Member

Note that we also have a simpler useColorMode() hook, but agree this would be nice to have too!

@lachlanjc
Copy link
Member

@hasparus I'm not sure if this is possible with how our packages are set up; since color-modes is an optional package, how would we override this line if that context exists?

@hasparus
Copy link
Member

Aren't all functions dependent on colors unsafe in SSR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants