How do I get style values from the theme function? #100
-
ProblemRecently i updated the Twind version from In import { theme } from 'twind'
const paddingLeft = theme('padding', 'l-2')
console.log(paddingLeft) Output 0.25rem How do i do this in
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
🤦 Sorry. I did change the theme function to be a helper. There is currently no equivalent API but I'm planing to add it back. For the moment you can use this code to get a theme function as you know it: let theme
tw((context) => {
theme = context.theme
return ''
})
theme('colors.gray.500')
theme('padding', 'l-3') The idea behind the change was to only provide helper functions that are used with In the next release we will have a "native" theme accessor. The following API is on my mind: tw.theme('colors.gray.500')
tw.theme('padding', 'l-3') This would make clear which theme values are accessed. There may be other context properties that we can expose this way. You could try this API using the following snippet: tw((context) => {
tw.theme = context.theme
return ''
})
tw.theme('colors.gray.500')
tw.theme('padding', 'l-3') @lamualfa-client What do you think? PS The new theme function can be used like this: import { theme } from 'twind'
tw(() => ({
color: theme('colors.blue.500'),
})) For more examples take a look at the docs |
Beta Was this translation helpful? Give feedback.
🤦 Sorry. I did change the theme function to be a helper. There is currently no equivalent API but I'm planing to add it back.
For the moment you can use this code to get a theme function as you know it:
The idea behind the change was to only provide helper functions that are used with
tw
. I understand that at least access to the theme is often needed.In the next release we will have a "native" theme accessor. The following API is on my mind:
This would make clear which theme values are accessed. There may be other cont…