Access nested colors?
See original GitHub issueI 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:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The
useThemeUI
hook had a bug where the color mode was not reflected incontext.theme
, but that should have been fixed in #226Generally, 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 itClosing as duplicate of #224