Skip to content

Commit 4422cba

Browse files
authored
refactor: improve AccentColorId type constraints (#1972)
1 parent 6e8f2b2 commit 4422cba

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

app/composables/useSettings.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type { RemovableRef } from '@vueuse/core'
22
import { useLocalStorage } from '@vueuse/core'
3-
import { ACCENT_COLORS } from '#shared/utils/constants'
3+
import { ACCENT_COLORS, type AccentColorId } from '#shared/utils/constants'
44
import type { LocaleObject } from '@nuxtjs/i18n'
55
import { BACKGROUND_THEMES } from '#shared/utils/constants'
66

77
type BackgroundThemeId = keyof typeof BACKGROUND_THEMES
88

9-
type AccentColorId = keyof typeof ACCENT_COLORS.light
10-
119
/** Available search providers */
1210
export type SearchProvider = 'npm' | 'algolia'
1311

app/utils/prehydrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function initPreferencesOnPrehydrate() {
1818
'violet',
1919
'magenta',
2020
'neutral',
21-
])
21+
] satisfies typeof ACCENT_COLOR_IDS)
2222

2323
// Valid package manager IDs
2424
const validPMs = new Set(['npm', 'pnpm', 'yarn', 'bun', 'deno', 'vlt'])

shared/utils/constants.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ export const DISCORD_COMMUNITY_URL = 'https://chat.npmx.dev'
5959
export const DISCORD_BUILDERS_URL = 'https://build.npmx.dev'
6060

6161
// Theming
62+
export const ACCENT_COLOR_IDS = [
63+
'sky',
64+
'coral',
65+
'amber',
66+
'emerald',
67+
'violet',
68+
'magenta',
69+
'neutral',
70+
] as const
71+
72+
export type AccentColorId = (typeof ACCENT_COLOR_IDS)[number]
73+
6274
export const ACCENT_COLORS = {
6375
light: {
6476
sky: 'oklch(0.53 0.16 247.27)',
@@ -78,7 +90,7 @@ export const ACCENT_COLORS = {
7890
magenta: 'oklch(0.78 0.15 330)',
7991
neutral: 'oklch(1 0 0)',
8092
},
81-
} as const
93+
} as const satisfies Record<'light' | 'dark', Record<AccentColorId, string>>
8294

8395
export const BACKGROUND_THEMES = {
8496
neutral: 'oklch(0.555 0 0)',

0 commit comments

Comments
 (0)