question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access nested colors?

See original GitHub issue

I looked for a similar issue, but couldn’t find one, realizing I may not know exactly how to ask this question, but here goes:

Is there a way to access nested colors defined in theme.js? E.g., if I have a theme like:

initialColorMode: 'default',
  useCustomProperties: true,
  colors: {
    text: "#000",
    background: "#fff",
    base: {
       primary: "#..",
       secondary: "#.."
    },
    accent: { ... },
    modes: {
      saturated: {
         base: {
             primary: "#...",
             secondary: "#..."
         }, ...
    }
}

is there a way in the sx prop to refer to these nested values so that I can flip the colorMode switch and the nested values of the mode get chosen?

I’ve had no luck with:

<div
      sx={{
        backgroundColor: 'base.primary',
      }}
    >

but using useThemeUI like:

  const context = useThemeUI()
  const {
    theme
  } = context

// then...
   <div
      sx={{
        backgroundColor: theme.colors.base.primary,
        padding: '20px 0',
        width: '100%'
      }}
    >

works, but doesn’t this marry the component to the default colorMode?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jxnblkcommented, Jul 30, 2019

The useThemeUI hook had a bug where the color mode was not reflected in context.theme, but that should have been fixed in #226

Generally, the first approach with backgroundColor: 'base.primary' should work, but you might’ve found a bug. I’ll look into this to see if I can reproduce it

0reactions
jxnblkcommented, Jul 30, 2019

Closing as duplicate of #224

Read more comments on GitHub >

github_iconTop Results From Across the Web

SCSS – How to get specific value from a nested map
Codepen. In this case then: $white: #fff; $black: #000; $colors: ( white: ( $white, $black, ), ); @function returnColor($value) { @return ...
Read more >
Material Design 2 in Compose - Jetpack - Android Developers
A Material Theme contains color, typography and shape attributes. ... This approach makes it possible to easily support dark theme and nested themes....
Read more >
Work with nested components in Adobe XD
Learn how to work with nested components across design systems in Adobe XD. ... Notice that the other buttons don't get the color...
Read more >
Avoiding nested Steams in Spring Webflux - Tolkiana
Avoiding nested streams in Spring Webflux & Kotlin ... natural approach is nesting the result so at the end you can get access...
Read more >
Nested field type | Elasticsearch Guide [8.5] | Elastic
Because nested documents are indexed as separate documents, they can only be accessed within the scope of the nested query, the nested /...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found