Skip to content

Commit e5ed58e

Browse files
Merge branch 'main' of github.com:elliott-with-the-longest-name-on-github/svelte-themes
2 parents 9193871 + 043f3ef commit e5ed58e

File tree

17 files changed

+163
-147
lines changed

17 files changed

+163
-147
lines changed

.changeset/config.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": "@changesets/cli/changelog",
4-
"commit": false,
5-
"fixed": [],
6-
"linked": [],
7-
"access": "public",
8-
"baseBranch": "main",
9-
"updateInternalDependencies": "patch",
10-
"ignore": []
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
1111
}

.changeset/long-rivers-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sejohnson/svelte-themes': patch
3+
---
4+
5+
chore: Minor improvement to test release workflow

.github/workflows/e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ on:
88

99
jobs:
1010
test:
11-
name: Run Playwright tests
11+
name: Playwright
1212
timeout-minutes: 5
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Enable corepack
17-
run: corepack enable
17+
run: npm i -g --force corepack && corepack enable
1818
- uses: actions/setup-node@v4
1919
with:
2020
node-version: 20.x

.github/workflows/quality.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ on:
88

99
jobs:
1010
lint:
11-
name: Run Linter
11+
name: Lint
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Enable corepack
16-
run: corepack enable
16+
run: npm i -g --force corepack && corepack enable
1717
- uses: actions/setup-node@v4
1818
with:
1919
node-version: 20.x
@@ -23,15 +23,16 @@ jobs:
2323
env:
2424
CI: true
2525

26+
- run: pnpm -F @sejohnson/svelte-themes build
2627
- run: pnpm lint
2728

2829
check:
29-
name: Run Type Check
30+
name: Type Check
3031
runs-on: ubuntu-latest
3132
steps:
3233
- uses: actions/checkout@v4
3334
- name: Enable corepack
34-
run: corepack enable
35+
run: npm i -g --force corepack && corepack enable
3536
- uses: actions/setup-node@v4
3637
with:
3738
node-version: 20.x
@@ -41,4 +42,5 @@ jobs:
4142
env:
4243
CI: true
4344

45+
- run: pnpm -F @sejohnson/svelte-themes build
4446
- run: pnpm check

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v4
1717

18+
- name: Enable corepack
19+
run: npm i -g --force corepack && corepack enable
20+
1821
- name: Setup pnpm
1922
uses: pnpm/action-setup@v2
2023

.github/workflows/unit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ on:
88

99
jobs:
1010
test:
11-
name: Run Unit Tests
11+
name: Unit Test
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Enable corepack
16-
run: corepack enable
16+
run: npm i -g --force corepack && corepack enable
1717
- uses: actions/setup-node@v4
1818
with:
1919
node-version: 20.x

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ That's it, your SvelteKit app fully supports dark mode, including System prefere
5555

5656
```css
5757
:root {
58-
/* Your default theme */
59-
--background: white;
60-
--foreground: black;
58+
/* Your default theme */
59+
--background: white;
60+
--foreground: black;
6161
}
6262

6363
[data-theme='dark'] {
64-
--background: black;
65-
--foreground: white;
64+
--background: black;
65+
--foreground: white;
6666
}
6767
```
6868

@@ -72,28 +72,30 @@ Your UI will need to know the current theme and be able to change it. The `getTh
7272

7373
```svelte
7474
<script lang="ts">
75-
import { getTheme } from '@sejohnson/svelte-themes';
76-
const theme = getTheme();
75+
import { getTheme } from '@sejohnson/svelte-themes';
76+
const theme = getTheme();
7777
</script>
7878
7979
<div>
80-
The current theme is: {theme.selectedTheme}
81-
<button onclick={() => theme.selectedTheme = 'light'}>Light Mode</button>
82-
<button onclick={() => theme.selectedTheme = 'dark'}>Dark Mode</button>
83-
<button onclick={() => theme.selectedTheme = 'system'}>System</button>
80+
The current theme is: {theme.selectedTheme}
81+
<button onclick={() => (theme.selectedTheme = 'light')}>Light Mode</button>
82+
<button onclick={() => (theme.selectedTheme = 'dark')}>Dark Mode</button>
83+
<button onclick={() => (theme.selectedTheme = 'system')}>System</button>
8484
</div>
8585
```
8686

8787
### Without SvelteKit
8888

8989
Just be sure to wrap your root component in `ThemeProvider`!
9090

91+
<!-- prettier-ignore-start -->
9192

9293
> [!WARNING]
9394
> 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.
9495
>
9596
> You should delay rendering any theme toggling UI until mounted on the client. See the [example](#avoid-hydration-mismatch) for details.
9697
98+
<!-- prettier-ignore -->
9799
## API
98100

99101
Let's dig into the details.
@@ -132,10 +134,9 @@ All your theme configuration is passed to ThemeProvider.
132134
- `themes`: The list of themes passed to `ThemeProvider`.
133135

134136
> [!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.
136138
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.
139140
140141
## Examples
141142

@@ -157,7 +158,7 @@ If you don't want a System theme, disable it via `enableSystem`:
157158
<ThemeProvider enableSystem={false}>
158159
```
159160

160-
This will automatically remove `system` from the default `themes` array.
161+
This will automatically remove `system` from the default `themes` array.
161162

162163
### Class instead of data attribute
163164

@@ -193,7 +194,6 @@ const theme = getTheme();
193194
const disabled = Boolean(theme.forcedTheme);
194195
```
195196
196-
197197
### Disable transitions on theme change
198198
199199
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
217217
Done! To be extra clear, this affects only the DOM. Here's how all the values will look:
218218
219219
```js
220-
const theme = getTheme()
220+
const theme = getTheme();
221221
// theme.selectedTheme === "pink"
222222

223-
localStorage.getItem('theme')
223+
localStorage.getItem('theme');
224224
// => "pink"
225225

226-
document.documentElement.getAttribute('data-theme')
226+
document.documentElement.getAttribute('data-theme');
227227
// => "my-pink-theme"
228228
```
229229
@@ -259,14 +259,14 @@ This library does not rely on your theme styling using CSS variables. You can ha
259259
```css
260260
html,
261261
body {
262-
color: #000;
263-
background: #fff;
262+
color: #000;
263+
background: #fff;
264264
}
265265

266266
[data-theme='dark'],
267267
[data-theme='dark'] body {
268-
color: #fff;
269-
background: #000;
268+
color: #fff;
269+
background: #000;
270270
}
271271
```
272272
@@ -278,15 +278,15 @@ The following code sample is **unsafe**:
278278
279279
```svelte
280280
<script lang="ts">
281-
import { getTheme } from '@sejohnson/svelte-themes'
282-
const theme = getTheme();
281+
import { getTheme } from '@sejohnson/svelte-themes';
282+
const theme = getTheme();
283283
</script>
284284

285285
<!-- Do NOT do this! It will cause a hydration mismatch! -->
286286
<select bind:value={theme.selectedTheme}>
287-
<option value="system">System</option>
288-
<option value="dark">Dark</option>
289-
<option value="light">Light</option>
287+
<option value="system">System</option>
288+
<option value="dark">Dark</option>
289+
<option value="light">Light</option>
290290
</select>
291291
```
292292
@@ -300,11 +300,11 @@ To fix this, make sure you only use JavaScript to render UI that uses the curren
300300
</script>
301301

302302
{#if watcher.hydrated}
303-
<select bind:value={theme.selectedTheme}>
304-
<option value="system">System</option>
305-
<option value="light">Light</option>
306-
<option value="dark">Dark</option>
307-
</select>
303+
<select bind:value={theme.selectedTheme}>
304+
<option value="system">System</option>
305+
<option value="light">Light</option>
306+
<option value="dark">Dark</option>
307+
</select>
308308
{/if}
309309
```
310310
@@ -322,19 +322,19 @@ You can also use CSS to hide or show content based on the current theme. To avoi
322322
```svelte
323323
<!-- When the theme is dark, hide this div -->
324324
<div data-hide-on-theme="dark">
325-
<img src="light.png" width={400} height={400} />
325+
<img src="light.png" width={400} height={400} />
326326
</div>
327327

328328
<!-- When the theme is light, hide this div -->
329329
<div data-hide-on-theme="light">
330-
<img src="dark.png" width={400} height={400} />
330+
<img src="dark.png" width={400} height={400} />
331331
</div>
332332
```
333333
334334
```css
335335
[data-theme='dark'] [data-hide-on-theme='dark'],
336336
[data-theme='light'] [data-hide-on-theme='light'] {
337-
display: none;
337+
display: none;
338338
}
339339
```
340340
@@ -350,7 +350,7 @@ Modern Tailwind uses `prefers-color-scheme` to switch between `light` and `dark`
350350
351351
Done! `system`, `dark`, and `light` will all work as expected.
352352
353-
If you need to support custom color schemes, you can define your own `@custom-variant` rules to match `data-theme=<whatever>`.
353+
If you need to support custom color schemes, you can define your own `@custom-variant` rules to match `data-theme=<whatever>`.
354354
355355
## Discussion
356356

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import ts from 'typescript-eslint';
88
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
99

1010
export default ts.config(
11+
{
12+
// I have no idea what ESLint's problem with this file is but I don't care
13+
ignores: ['svelte-themes/src/lib/head-script.svelte']
14+
},
1115
includeIgnoreFile(gitignorePath),
1216
js.configs.recommended,
1317
...ts.configs.recommended,

examples/multi-theme/src/app.css

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
44

55
@layer base {
6-
:root {
7-
--primary: #1e293b;
8-
--primary-foreground: #f8fafc;
9-
}
6+
:root {
7+
--primary: #1e293b;
8+
--primary-foreground: #f8fafc;
9+
}
1010

11-
html[data-theme='dark-classic'] {
12-
--primary: #cbd5e1;
13-
--primary-foreground: #0f172a;
14-
}
11+
html[data-theme='dark-classic'] {
12+
--primary: #cbd5e1;
13+
--primary-foreground: #0f172a;
14+
}
1515

16-
html[data-theme='tangerine'] {
17-
--primary: #fcd34d;
18-
--primary-foreground: #0f172a;
19-
}
16+
html[data-theme='tangerine'] {
17+
--primary: #fcd34d;
18+
--primary-foreground: #0f172a;
19+
}
2020

21-
html[data-theme='dark-tangerine'] {
22-
--primary: #d97706;
23-
--primary-foreground: #0f172a;
24-
}
21+
html[data-theme='dark-tangerine'] {
22+
--primary: #d97706;
23+
--primary-foreground: #0f172a;
24+
}
2525

26-
html[data-theme='mint'] {
27-
--primary: #6ee7b7;
28-
--primary-foreground: #0f172a;
29-
}
26+
html[data-theme='mint'] {
27+
--primary: #6ee7b7;
28+
--primary-foreground: #0f172a;
29+
}
3030

31-
html[data-theme='dark-mint'] {
32-
--primary: #047857;
33-
--primary-foreground: #f8fafc;
34-
}
35-
}
31+
html[data-theme='dark-mint'] {
32+
--primary: #047857;
33+
--primary-foreground: #f8fafc;
34+
}
35+
}

examples/multi-theme/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import adapter from "@sveltejs/adapter-vercel";
1+
import adapter from '@sveltejs/adapter-vercel';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */

0 commit comments

Comments
 (0)