Skip to content

Commit

Permalink
fix(theme/i18n): support customizing dark mode switch titles (#3311)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
mrcego and brc-dd committed Dec 30, 2023
1 parent bb64ecb commit 50c9758
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/reference/default-theme-config.md
Expand Up @@ -406,6 +406,20 @@ export interface DocFooter {

Can be used to customize the dark mode switch label. This label is only displayed in the mobile view.

## lightModeSwitchTitle

- Type: `string`
- Default: `Switch to light theme`

Can be used to customize the light mode switch title that appears on hovering.

## darkModeSwitchTitle

- Type: `string`
- Default: `Switch to dark theme`

Can be used to customize the dark mode switch title that appears on hovering.

## sidebarMenuLabel

- Type: `string`
Expand Down
6 changes: 4 additions & 2 deletions src/client/theme-default/components/VPSwitchAppearance.vue
Expand Up @@ -5,14 +5,16 @@ import VPSwitch from './VPSwitch.vue'
import VPIconMoon from './icons/VPIconMoon.vue'
import VPIconSun from './icons/VPIconSun.vue'
const { isDark } = useData()
const { isDark, theme } = useData()
const toggleAppearance = inject('toggle-appearance', () => {
isDark.value = !isDark.value
})
const switchTitle = computed(() => {
return isDark.value ? 'Switch to light theme' : 'Switch to dark theme'
return isDark.value
? theme.value.lightModeSwitchTitle || 'Switch to light theme'
: theme.value.darkModeSwitchTitle || 'Switch to dark theme'
})
</script>

Expand Down
10 changes: 10 additions & 0 deletions types/default-theme.d.ts
Expand Up @@ -96,6 +96,16 @@ export namespace DefaultTheme {
*/
darkModeSwitchLabel?: string

/**
* @default 'Switch to light theme'
*/
lightModeSwitchTitle?: string

/**
* @default 'Switch to dark theme'
*/
darkModeSwitchTitle?: string

/**
* @default 'Menu'
*/
Expand Down

0 comments on commit 50c9758

Please sign in to comment.