8. Add ThemeProvider of "solid style components", add GlobalStyles and its Container component, create a button using inline style in your App component..
```typescript
import type { Component } from "solid-js";
import { ThemeProvider } from "solid-styled-components";
import { Container } from "./components/Container";
import { useTheme } from "./contexts/theme";
import { GlobalStyles } from "./styles/theme/global";
const App: Component = () => {
const [{ theme }, { toggleTheme, themeName }] = useTheme();
return (
<ThemeProvider theme={theme()}>
<Container>
<button
style={{
padding: "10px",
background: theme().colors.background.header,
color: "red",
}}
onClick={() =>
themeName() === "dark" ? toggleTheme("light") : toggleTheme("dark")
}
>
{themeName()} - {JSON.stringify(theme(), null, 2)}
</button>
</Container>
<GlobalStyles />
</ThemeProvider>
);
};
export default App;
Import AppThemeProvider in index.tsx
import { render } from "solid-js/web";
import App from "./App";
import { AppThemeProvider } from "./contexts/theme";
render(
() => (
),
document.getElementById("root") as HTMLElement
);
#### Notice that the style button in lina gets the theme change, but the component Container created by styled from "solid-styled-components" doesn't seem to notice the change of ThemeProvider props.
### My Environment
<!--
Please add any other relevant dependencies to this table at the end.
For example: Electron, React Native, or NestJS.
-->
| Dependency | Version |
| --- | --- |
| Operating System | windows |
| Node.js version | 16.15.1 |
| Typescript version | 4.8.2 |
| Vite version | 3.0.9 |
| Vite Plugin Solid version | 2.3.0 |
| Solidjs version | 1.5.1 |
| Solidjs Styled Components version | 0.28.5 |
### Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
- ✅ I don't know how to solve this bug, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Issue Description
Expected Behavior
Change props theme in styled of the "solid-styled-components" via createSignal or createContext.
Actual Behavior
When receiving context or signal, styled of the ThemeProvider doesn't seem to notice the change in state.
Erros Presented
Solid did not show errors in console or browser
Steps to Reproduce
Create a light and a dark theme in src/styles/theme/index.ts.
export const themes = { light: lightTheme, dark: darkTheme, } export type TThemeName = keyof typeof themes; export type TThemeType = typeof themes.light | typeof themes.dark;
import { themes } from "../../styles/theme"; import { TThemeName, TThemeType } from "../../styles/theme";
export type ThemeContextState = { theme: () => TThemeType; };
export type ThemeContextValue = [ state: ThemeContextState, actions: { toggleTheme: (selectTheme: TThemeName) => void; themeName: () => TThemeName; } ];
const AppThemeContext = createContext([
{
theme: () => themes["dark"],
},
{
toggleTheme: () => undefined,
themeName: () => "dark",
},
]);
export const AppThemeProvider: ParentComponent = (props) => { const [modeTheme, setModeTheme] = createSignal("dark");
const toggleTheme = (mode: TThemeName) => { setModeTheme(mode); };
const themeName = () => { return modeTheme(); };
const theme = () => { return themes[modeTheme()]; };
return ( <AppThemeContext.Provider value={[{ theme }, { toggleTheme, themeName }]}> {props.children} </AppThemeContext.Provider> ); };
export const useTheme = () => useContext(AppThemeContext);
const Content = styled("div")
width: 100vw; height: 100vh; background-color: ${({ theme }) => theme?.colors.background.index};
;interface IProps { children: JSXElement; }
export const Container: Component = ({ children }) => {
return {children} ;
};
import App from "./App"; import { AppThemeProvider } from "./contexts/theme";
render( () => (
), document.getElementById("root") as HTMLElement );