diff --git a/src/assets/scss/_styles.scss b/src/assets/scss/_styles.scss index 5c185f2a..c30a105e 100644 --- a/src/assets/scss/_styles.scss +++ b/src/assets/scss/_styles.scss @@ -7,6 +7,10 @@ a { @extend %link; } +.header-icon { + @apply text-site-header-text hover:text-site-header-text-hover; +} + /* Badge CSS */ %badge { @apply px-3 py-2 border rounded-full border-style-primary; diff --git a/src/components/AppHeader.astro b/src/components/AppHeader.astro index 7b194b23..6dc0fa9b 100644 --- a/src/components/AppHeader.astro +++ b/src/components/AppHeader.astro @@ -1,14 +1,14 @@ --- import type { HTMLAttributes } from 'astro/types' +import Icon from '@/components/Icon.astro' +import ThemeSelector from '@/components/ThemeSelector.astro' import siteConfig from '@/configs/site' -import Icon from './Icon.astro' - export interface Props extends HTMLAttributes<'svg'> {} const { ...props } = Astro.props -const { title, description, author } = siteConfig +const { title, description, author, themes } = siteConfig ---
@@ -42,6 +42,12 @@ const { title, description, author } = siteConfig +
@@ -52,10 +58,6 @@ const { title, description, author } = siteConfig @apply bg-site-header-bg border-b-site-header-border; } - .header-icon { - @apply text-site-header-text hover:text-site-header-text-hover; - } - .site-title { @apply text-site-title hover:text-site-header-text-hover; } diff --git a/src/components/ThemeSelector.astro b/src/components/ThemeSelector.astro new file mode 100644 index 00000000..411c8234 --- /dev/null +++ b/src/components/ThemeSelector.astro @@ -0,0 +1,162 @@ +--- +import bi from '@iconify-json/bi/icons.json' + +import Icon from '@/components/Icon.astro' + +interface ThemeMeta { + name: string + icon: string +} + +export interface Props { + themes: Record + fallbackLightTheme: string + fallbackDarkTheme: string + iconClass: string +} + +const STORAGE_KEY_THEME: string = 'theme' + +const { themes, fallbackLightTheme, fallbackDarkTheme, iconClass } = Astro.props +const defaultTheme = fallbackDarkTheme +const icons = bi.icons +--- + +
+ + +
+ + + + diff --git a/src/configs/site.ts b/src/configs/site.ts index 01ba0d13..ed0eb3af 100644 --- a/src/configs/site.ts +++ b/src/configs/site.ts @@ -16,6 +16,16 @@ export default { }, favicon: '/favicon.ico', faviconMimeType: 'image/x-icon', + themes: { + 'leetcode-light': { + name: 'LeetCode Light', + icon: 'bi:sun-fill', + }, + 'leetcode-dark': { + name: 'LeetCode Dark', + icon: 'bi:moon-fill', + }, + }, plugins: { counterAnalytics: { projectId: env.COUNTER_ANALYTICS_ID, diff --git a/theme.config.cjs b/theme.config.cjs index 7b0f1cea..c2455b4a 100644 --- a/theme.config.cjs +++ b/theme.config.cjs @@ -46,6 +46,9 @@ const darkTheme = ({ primary, secondary, tertiary }) => { 'header-text': baseColors.text, 'header-text-hover': baseColors.fill, }, + 'theme-menu': { + 'text-hover': baseColors.fill, + }, difficulty: { ...textDifficultyColors, }, @@ -60,6 +63,10 @@ const darkTheme = ({ primary, secondary, tertiary }) => { 'bg': '#1a1a1a', 'header-bg': '#282828', }, + 'theme-menu': { + 'bg': colors.zinc['800'], + 'bg-hover': tertiary, + }, difficulty: { easy: themeColors.leetcode.easy, 'easy-hover': baseColors.text, @@ -118,6 +125,9 @@ const lightTheme = ({ primary, secondary, tertiary }) => { 'header-text': baseColors['text-inverted'], 'header-text-hover': colors.gray['300'], }, + 'theme-menu': { + 'text-hover': baseColors.fill, + }, difficulty: { ...textDifficultyColors, }, @@ -132,6 +142,10 @@ const lightTheme = ({ primary, secondary, tertiary }) => { 'bg': colors.white, 'header-bg': primary, }, + 'theme-menu': { + 'bg': baseColors['text-inverted'], + 'bg-hover': colors.gray['100'], + }, difficulty: { easy: themeColors.leetcode.easy, 'easy-hover': baseColors.text,