-
Subjecttopic DescriptionTo dynamically change values similar to ThemeProvider in styled-components, what is the best approach in Panda CSS? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 19 replies
-
@ryuji-1to can you add a link example that shows what you mean. |
Beta Was this translation helpful? Give feedback.
-
I would say no, this is a build-time library and rely on the engine to generate the css, something like tailwindcss. |
Beta Was this translation helpful? Give feedback.
-
@anubra266 // Define your themes
const lightTheme = {
backgroundColor: '#FFFFFF',
textColor: '#000000',
};
const darkTheme = {
backgroundColor: '#000000',
textColor: '#FFFFFF',
};
// Define a styled component that uses the theme
const StyledComponent = styled.div`
background-color: ${props => props.theme.backgroundColor};
color: ${props => props.theme.textColor};
`;
// Create a component that renders the styled component inside a ThemeProvider
const ThemeChangeComponent = ({ isDarkMode }) => {
const theme = isDarkMode ? darkTheme : lightTheme;
return (
<ThemeProvider theme={theme}>
<StyledComponent>Content</StyledComponent>
</ThemeProvider>
);
};
export default ThemeChangeComponent; https://styled-components.com/docs/advanced In Panda CSS, what would be the best approach to achieve something like this? cva? |
Beta Was this translation helpful? Give feedback.
-
@ryuji-1to light/dark are not themes. They're color modes. You can do that in panda through semanticTokens. Then use |
Beta Was this translation helpful? Give feedback.
-
Sorry to hijack the convo, does the multi-theme setup suggested in
I am wondering how do I achieve multi-brand theming in Panda with the same component/build? Ideally 1 css per brand so I don't send un-used css to another brand. For example, I have Brand1, Brand2, Brand3
What about stylings for components that are lazy imported based on user interaction? currently those lazy component styles are also part of the initial bootstrap css. Any suggestion would be great, thanks a lot |
Beta Was this translation helpful? Give feedback.
-
Using panda.config.ts
Providers.tsx component which wraps my app in the global
Toggle Button:
Then finally the theming in use:
|
Beta Was this translation helpful? Give feedback.
-
Pigment CSS managed to generate styles based on runtime values as seen here. |
Beta Was this translation helpful? Give feedback.
-
For runtime dynamic values, I use CSS vars in the panda styles and inject their values via the const className = css({
color: 'var(--fg)',
_dark: {
color: 'var(--fg-dark)',
},
})
const cssVars = {
'--fg': inputLightValue,
'--fg-dark': inputDarkValue
} as React.CSSProperties
return <div className={className} style={cssVars}>{children}</div> With this solution you can also take benefit of the panda conditions like dark mode, without having to write conditional assignments in JS. |
Beta Was this translation helpful? Give feedback.
@ryuji-1to light/dark are not themes. They're color modes. You can do that in panda through semanticTokens. Then use
data-color-mode
attribute on body to detect color mode.As for theme, example is here https://panda-css.com/docs/guides/multiple-themes
Lemme know if there's anything you don't understand