Skip to content

Commit 9f3efa8

Browse files
committed
persist theme & cleanup
1 parent f0e1217 commit 9f3efa8

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

app/app.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { useEventListener } from '@vueuse/core'
33
44
const route = useRoute()
55
const router = useRouter()
6+
const { settings } = useSettings()
67
78
const isHomepage = computed(() => route.path === '/')
9+
const theme = settings.value.theme === 'dark' ? 'dark' : 'light'
810
911
useHead({
1012
htmlAttrs: {
11-
'data-theme': 'light',
13+
'data-theme': 'dark',
1214
},
1315
titleTemplate: titleChunk => {
1416
return titleChunk ? titleChunk : 'npmx - Better npm Package Browser'
@@ -73,19 +75,23 @@ if (import.meta.client) {
7375
}
7476
7577
:root[data-theme='dark'] {
78+
/* background colors */
7679
--bg: oklch(0.145 0 0);
7780
--bg-subtle: oklch(0.178 0 0);
7881
--bg-muted: oklch(0.218 0 0);
7982
--bg-elevated: oklch(0.252 0 0);
8083
84+
/* text colors */
8185
--fg: oklch(0.985 0 0);
8286
--fg-muted: oklch(0.709 0 0);
8387
--fg-subtle: oklch(0.633 0 0);
8488
89+
/* border, seperator colors */
8590
--border: oklch(0.269 0 0);
8691
--border-subtle: oklch(0.239 0 0);
8792
--border-hover: oklch(0.371 0 0);
8893
94+
/* user selected accent */
8995
--accent: oklch(1 0 0);
9096
--accent-muted: oklch(0.922 0 0);
9197

app/components/PackageDownloadStats.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ const config = computed(() => ({
3030
show: false,
3131
},
3232
area: {
33-
color: '#6A6A6A',
3433
useGradient: false,
34+
// here css variable doesn't seem to work here
35+
color: '#6A6A6A',
3536
opacity: 10,
3637
},
3738
dataLabel: {
3839
offsetX: -10,
3940
fontSize: 28,
4041
bold: false,
41-
color: '#FAFAFA',
42+
color: 'var(--fg)',
4243
},
4344
line: {
44-
color: '#6A6A6A',
45+
color: 'var(--fg-subtle)',
4546
pulse: {
4647
show: true,
4748
loop: true, // runs only once if false
4849
radius: 2,
49-
color: '#8A8A8A',
50+
color: 'var(--fg-muted)',
5051
easing: 'ease-in-out',
5152
trail: {
5253
show: true,
@@ -56,17 +57,17 @@ const config = computed(() => ({
5657
},
5758
plot: {
5859
radius: 6,
59-
stroke: '#FAFAFA',
60+
stroke: 'var(--fg)',
6061
},
6162
title: {
6263
text: lastDatapoint.value,
6364
fontSize: 12,
64-
color: '#8A8A8A',
65+
color: 'var(--fg)',
6566
bold: false,
6667
},
6768
verticalIndicator: {
6869
strokeDasharray: 0,
69-
color: '#FAFAFA',
70+
color: 'var(--fg-muted)',
7071
},
7172
},
7273
}))

app/components/SettingsMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ onKeyStroke(',', e => {
113113
<!-- Include @types in install toggle -->
114114
<button
115115
type="button"
116-
class="w-full flex items-center justify-between gap-3 px-2 py-2 rounded-md hover:bg-bg-muted transition-[background-color] duration-150 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 inset-shadow"
116+
class="w-full flex items-center justify-between gap-3 px-2 py-2 rounded-md hover:bg-bg-muted transition-[background-color] duration-150 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
117117
role="menuitemcheckbox"
118118
:aria-checked="settings.includeTypesInInstall"
119119
@click="settings.includeTypesInInstall = !settings.includeTypesInInstall"

app/composables/useSettings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ export interface AppSettings {
99
relativeDates: boolean
1010
/** Include @types/* package in install command for packages without built-in types */
1111
includeTypesInInstall: boolean
12+
/** Theme of site, default dark */
13+
theme: 'dark' | 'light'
1214
}
1315

1416
const DEFAULT_SETTINGS: AppSettings = {
1517
relativeDates: false,
1618
includeTypesInInstall: true,
19+
theme: 'dark',
1720
}
1821

1922
const STORAGE_KEY = 'npmx-settings'

0 commit comments

Comments
 (0)