Skip to content

Commit 96bb9ad

Browse files
font switcher (#604)
* font switcher * Update packages/site-kit/src/lib/styles/tokens.css * Update packages/site-kit/src/lib/components/FontDropdown.svelte * fix * use atkinson hyperlegible * icons * make it a two-way toggle * tidy up * oops * tidy up --------- Co-authored-by: Simon H <[email protected]>
1 parent a39ae9a commit 96bb9ad

File tree

15 files changed

+118
-11
lines changed

15 files changed

+118
-11
lines changed

apps/svelte.dev/src/app.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
JSON.parse(localStorage.getItem('svelte:theme'))?.current ??
2424
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
2525
);
26+
27+
document.documentElement.classList.add(
28+
`font-${localStorage.getItem('svelte:font') ?? 'elegant'}`
29+
);
2630
</script>
2731

2832
%sveltekit.head%

packages/repl/src/lib/Output/Output.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
overflow: hidden;
150150
white-space: nowrap;
151151
box-sizing: border-box;
152+
font: var(--sk-font-ui-small);
152153
153154
/* fake border (allows tab borders to appear above it) */
154155
&::before {

packages/site-kit/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
},
2323
"homepage": "https://github.com/sveltejs/svelte.dev/tree/main/packages/site-kit#readme",
2424
"dependencies": {
25-
"@lezer/common": "^1.0.4",
2625
"@codemirror/autocomplete": "^6.9.0",
2726
"@codemirror/commands": "^6.2.5",
2827
"@codemirror/lang-css": "^6.2.1",
@@ -33,16 +32,18 @@
3332
"@codemirror/search": "^6.5.2",
3433
"@codemirror/state": "^6.2.1",
3534
"@codemirror/view": "^6.17.1",
35+
"@fontsource/atkinson-hyperlegible": "^5.1.0",
3636
"@fontsource/dm-serif-display": "^5.1.0",
3737
"@fontsource/eb-garamond": "^5.1.0",
3838
"@fontsource/fira-mono": "^5.1.0",
3939
"@fontsource/fira-sans": "^5.1.0",
40+
"@lezer/common": "^1.0.4",
41+
"@replit/codemirror-lang-svelte": "^6.0.0",
4042
"@shikijs/twoslash": "^1.22.0",
4143
"esm-env": "^1.0.0",
4244
"json5": "^2.2.3",
4345
"shiki": "^1.22.0",
44-
"svelte-persisted-store": "^0.9.2",
45-
"@replit/codemirror-lang-svelte": "^6.0.0"
46+
"svelte-persisted-store": "^0.9.2"
4647
},
4748
"devDependencies": {
4849
"@sveltejs/kit": "^2.6.3",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script lang="ts">
2+
let font = $state('elegant');
3+
4+
$effect(() => {
5+
font = localStorage.getItem('svelte:font') ?? 'elegant';
6+
});
7+
8+
function toggle() {
9+
font = font === 'elegant' ? 'boring' : 'elegant';
10+
11+
document.documentElement.classList.remove('font-elegant');
12+
document.documentElement.classList.remove('font-boring');
13+
14+
document.documentElement.classList.add(`font-${font}`);
15+
localStorage.setItem('svelte:font', font);
16+
}
17+
</script>
18+
19+
<button
20+
onclick={toggle}
21+
class="raised icon"
22+
type="button"
23+
aria-pressed={font === 'boring'}
24+
aria-label="Toggle font"
25+
></button>
26+
27+
<style>
28+
button {
29+
background-size: 2rem;
30+
}
31+
32+
button[aria-pressed='true'] {
33+
background-image: url(../icons/font-boring-light.svg);
34+
35+
:global(.dark) & {
36+
background-image: url(../icons/font-boring-dark.svg);
37+
}
38+
}
39+
40+
button[aria-pressed='false'] {
41+
background-image: url(../icons/font-elegant-light.svg);
42+
43+
:global(.dark) & {
44+
background-image: url(../icons/font-elegant-dark.svg);
45+
}
46+
}
47+
</style>

packages/site-kit/src/lib/components/Icons.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,14 @@ Provides a list of svg icons that can be referenced through the `Icon` component
195195
d="M5 22q-.825 0-1.413-.588T3 20V6h2v14h11v2H5Zm4-4q-.825 0-1.413-.588T7 16V4q0-.825.588-1.413T9 2h9q.825 0 1.413.588T20 4v12q0 .825-.588 1.413T18 18H9Z"
196196
/>
197197
</symbol>
198+
199+
<symbol viewBox="0 0 24 24" id="font-toggle">
200+
<g stroke="currentColor">
201+
<path d="m3 15 4-8 4 8" />
202+
<path d="M4 13h6" />
203+
<circle cx="18" cy="12" r="3" />
204+
<path d="M21 9v6" />
205+
</g>
206+
</symbol>
198207
</svg>
199208
</div>
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)