You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just be sure to wrap your root component in `ThemeProvider`!
90
90
91
+
<!-- prettier-ignore-start -->
91
92
92
93
> [!WARNING]
93
94
> The above code is hydration _unsafe_ and will throw a hydration mismatch warning when rendering with SSR. This is because we cannot know the `theme` on the server, so it will always be `undefined` until mounted on the client.
94
95
>
95
96
> You should delay rendering any theme toggling UI until mounted on the client. See the [example](#avoid-hydration-mismatch) for details.
96
97
98
+
<!-- prettier-ignore -->
97
99
## API
98
100
99
101
Let's dig into the details.
@@ -132,10 +134,9 @@ All your theme configuration is passed to ThemeProvider.
132
134
-`themes`: The list of themes passed to `ThemeProvider`.
133
135
134
136
> [!NOTE]
135
-
> For `forcedTheme`, `defaultTheme`, and `selectedTheme`, be sure all values you plan on assigning are members of the `themes` array.
137
+
> For `forcedTheme`, `defaultTheme`, and `selectedTheme`, be sure all values you plan on assigning are members of the `themes` array.
136
138
137
-
> [!WARNING]
138
-
> `getTheme` relies on the [Context API](https://svelte.dev/docs/svelte/context), so you must call it during component initialization.
139
+
> [!WARNING] > `getTheme` relies on the [Context API](https://svelte.dev/docs/svelte/context), so you must call it during component initialization.
139
140
140
141
## Examples
141
142
@@ -157,7 +158,7 @@ If you don't want a System theme, disable it via `enableSystem`:
157
158
<ThemeProvider enableSystem={false}>
158
159
```
159
160
160
-
This will automatically remove `system` from the default `themes` array.
161
+
This will automatically remove `system` from the default `themes` array.
161
162
162
163
### Class instead of data attribute
163
164
@@ -193,7 +194,6 @@ const theme = getTheme();
193
194
constdisabled=Boolean(theme.forcedTheme);
194
195
```
195
196
196
-
197
197
### Disable transitions on theme change
198
198
199
199
Paco wrote about [this technique here](https://paco.sh/blog/disable-theme-transitions). We can forcefully disable all CSS transitions before the theme is changed, and re-enable them immediately afterwards. This ensures your UI with different transition durations won't feel inconsistent when changing the theme.
@@ -217,13 +217,13 @@ If we want the DOM to instead render `data-theme="my-pink-theme"` when the theme
217
217
Done! To be extra clear, this affects only the DOM. Here's how all the values will look:
0 commit comments