Skip to content

Commit 748b8f3

Browse files
authored
feat: added a new style for spotlight (#32)
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
1 parent ec4c6c7 commit 748b8f3

13 files changed

Lines changed: 373 additions & 13 deletions

File tree

docs/pages/en/integrations/vitepress-plugin-enhanced-readabilities/index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ export interface Options {
444444
* @default false
445445
*/
446446
defaultToggle?: boolean
447+
/**
448+
* Default style for spotlight
449+
*
450+
* @default SpotlightStyle.Aside (2)
451+
*/
452+
defaultStyle?: SpotlightStyle
447453
}
448454
}
449455
```
@@ -703,6 +709,48 @@ export interface Locale {
703709
* Option: Off help message
704710
*/
705711
optionOffHelpMessage?: string
712+
styles?: {
713+
/**
714+
* Title text
715+
*/
716+
title?: string
717+
/**
718+
* Title aria-label
719+
*/
720+
titleAriaLabel?: string
721+
/**
722+
* Title help message
723+
*/
724+
titleHelpMessage?: string
725+
/**
726+
* Title warning message for navigation menu in small screen
727+
*/
728+
titleScreenNavWarningMessage?: string
729+
/**
730+
* Option: Under text
731+
*/
732+
optionUnder?: string
733+
/**
734+
* Option: Under aria-label
735+
*/
736+
optionUnderAriaLabel?: string
737+
/**
738+
* Option: Under help message
739+
*/
740+
optionUnderHelpMessage?: string
741+
/**
742+
* Option: Aside text
743+
*/
744+
optionAside?: string
745+
/**
746+
* Option: Aside aria-label
747+
*/
748+
optionAsideAriaLabel?: string
749+
/**
750+
* Option: Aside help message
751+
*/
752+
optionAsideHelpMessage?: string
753+
}
706754
}
707755
}
708756
```

docs/pages/zh-CN/integrations/vitepress-plugin-enhanced-readabilities/index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ export interface Options {
443443
* @default false
444444
*/
445445
defaultToggle?: boolean
446+
/**
447+
* Default style for spotlight
448+
*
449+
* @default SpotlightStyle.Aside (2)
450+
*/
451+
defaultStyle?: SpotlightStyle
446452
}
447453
}
448454
```
@@ -702,6 +708,48 @@ export interface Locale {
702708
* Option: Off help message
703709
*/
704710
optionOffHelpMessage?: string
711+
styles?: {
712+
/**
713+
* Title text
714+
*/
715+
title?: string
716+
/**
717+
* Title aria-label
718+
*/
719+
titleAriaLabel?: string
720+
/**
721+
* Title help message
722+
*/
723+
titleHelpMessage?: string
724+
/**
725+
* Title warning message for navigation menu in small screen
726+
*/
727+
titleScreenNavWarningMessage?: string
728+
/**
729+
* Option: Under text
730+
*/
731+
optionUnder?: string
732+
/**
733+
* Option: Under aria-label
734+
*/
735+
optionUnderAriaLabel?: string
736+
/**
737+
* Option: Under help message
738+
*/
739+
optionUnderHelpMessage?: string
740+
/**
741+
* Option: Aside text
742+
*/
743+
optionAside?: string
744+
/**
745+
* Option: Aside aria-label
746+
*/
747+
optionAsideAriaLabel?: string
748+
/**
749+
* Option: Aside help message
750+
*/
751+
optionAsideHelpMessage?: string
752+
}
705753
}
706754
}
707755
```

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitch.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const disabled = ref(false)
1818
1919
const mounted = useMounted()
2020
const isLargerThanMobile = useMediaQuery('(min-width: 768px)')
21-
const layoutMode = useLocalStorage(LayoutSwitchModeStorageKey, options.layoutSwitch?.defaultMode || LayoutMode.Original)
21+
const layoutMode = useLocalStorage<LayoutMode>(LayoutSwitchModeStorageKey, options.layoutSwitch?.defaultMode || LayoutMode.Original)
2222
const { t } = useI18n()
2323
const { trigger: triggerAnimation } = useLayoutAppearanceChangeAnimation()
2424

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitchContentLayoutMaxWidthSlider.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ watch(maxWidthValue, (val) => {
9999

100100
<template>
101101
<Transition name="fade-shift">
102-
<div v-if="layoutMode === LayoutMode.BothWidthAdjustable" space-y-2 role="range" class="VPNolebaseEnhancedReadabilitiesContentLayoutWidthSlider">
102+
<div
103+
v-if="layoutMode === LayoutMode.BothWidthAdjustable"
104+
space-y-2
105+
role="range"
106+
class="VPNolebaseEnhancedReadabilitiesContentLayoutWidthSlider"
107+
>
103108
<div ref="menuTitleElementRef" flex items-center>
104109
<MenuTitle
105110
icon="i-icon-park-outline:auto-line-width"

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitchPageLayoutMaxWidthSlider.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ watch(maxWidthValue, (val) => {
9898

9999
<template>
100100
<Transition name="fade-shift">
101-
<div v-if="layoutMode === LayoutMode.SidebarWidthAdjustableOnly || layoutMode === LayoutMode.BothWidthAdjustable" space-y-2 role="range" class="VPNolebaseEnhancedReadabilitiesPageLayoutWidthSlider">
101+
<div
102+
v-if="layoutMode === LayoutMode.SidebarWidthAdjustableOnly || layoutMode === LayoutMode.BothWidthAdjustable"
103+
space-y-2
104+
role="range"
105+
class="VPNolebaseEnhancedReadabilitiesPageLayoutWidthSlider"
106+
>
102107
<div ref="menuTitleElementRef" flex items-center>
103108
<MenuTitle
104109
icon="i-icon-park-outline:auto-width-one"

packages/vitepress-plugin-enhanced-readabilities/src/components/Menu.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { useI18n } from '../composables/i18n'
66
77
import LayoutSwitchLayoutIcon from './MenuIcon.vue'
88
import LayoutSwitch from './LayoutSwitch.vue'
9-
import MouseOverElementHighlight from './Spotlight.vue'
109
import LayoutSwitchPageLayoutWidthInput from './LayoutSwitchPageLayoutMaxWidthSlider.vue'
1110
import LayoutSwitchContentLayoutWidthInput from './LayoutSwitchContentLayoutMaxWidthSlider.vue'
11+
import Spotlight from './Spotlight.vue'
12+
import SpotlightStyles from './SpotlightStyles.vue'
1213
1314
const mounted = useMounted()
1415
const { t } = useI18n()
@@ -23,7 +24,8 @@ const { t } = useI18n()
2324
<LayoutSwitch />
2425
<LayoutSwitchPageLayoutWidthInput />
2526
<LayoutSwitchContentLayoutWidthInput />
26-
<MouseOverElementHighlight />
27+
<Spotlight />
28+
<SpotlightStyles />
2729
</div>
2830
</VPFlyout>
2931
</template>

packages/vitepress-plugin-enhanced-readabilities/src/components/Spotlight.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ const { t } = useI18n()
2121
2222
const fieldOptions = computed(() => [
2323
{
24+
value: true,
2425
title: t('spotlight.optionOn'),
2526
ariaLabel: t('spotlight.optionOnAriaLabel'),
26-
value: true,
2727
text: 'ON',
2828
name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch',
2929
},
3030
{
31+
value: false,
3132
title: t('spotlight.optionOff'),
3233
ariaLabel: t('spotlight.optionOffAriaLabel'),
33-
value: false,
3434
text: 'OFF',
3535
name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch',
3636
},

packages/vitepress-plugin-enhanced-readabilities/src/components/SpotlightHoverBlock.vue

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<script setup lang="ts">
22
import { inject, onMounted, reactive, ref, watch } from 'vue'
3-
import { useElementBounding, useElementByPoint, useElementVisibility, useEventListener, useMouse, useMouseInElement } from '@vueuse/core'
3+
import {
4+
useElementBounding,
5+
useElementByPoint,
6+
useElementVisibility,
7+
useEventListener,
8+
useMouse,
9+
useMouseInElement,
10+
useStorage,
11+
} from '@vueuse/core'
412
import { useRoute } from 'vitepress'
5-
import { InjectionKey } from '../constants'
13+
14+
import { InjectionKey, SpotlightStyle, SpotlightStylesStorageKey } from '../constants'
615
716
const props = defineProps<{ enabled: boolean }>()
817
@@ -17,10 +26,15 @@ const { isOutside } = useMouseInElement(vpDocElement)
1726
const { element } = useElementByPoint({ x, y })
1827
const bounding = reactive(useElementBounding(element))
1928
const elementVisibility = useElementVisibility(highlightedElement)
29+
const spotlightStyle = useStorage<SpotlightStyle>(SpotlightStylesStorageKey, options.spotlight?.defaultStyle || SpotlightStyle.Aside)
2030
const route = useRoute()
2131
2232
useEventListener('scroll', bounding.update, true)
2333
34+
onMounted(() => {
35+
document.body.style.setProperty('--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color', options?.spotlight?.hoverBlockColor || `rgb(240 197 52 / 10%)`)
36+
})
37+
2438
onMounted(() => {
2539
vpDocElement.value = document.querySelector('.VPDoc main .vp-doc') as HTMLDivElement
2640
})
@@ -41,7 +55,6 @@ function computeBoxStyles(bounding: {
4155
height: `${bounding.height + 8}px`,
4256
left: `${bounding.left - 4}px`,
4357
top: `${bounding.top - 4}px`,
44-
backgroundColor: options?.spotlight?.hoverBlockColor || 'rgb(240 197 52 / 10%)',
4558
transition: 'all 0.2s ease',
4659
borderRadius: '8px',
4760
}
@@ -134,9 +147,34 @@ watch(() => props.enabled, (val) => {
134147
:style="boxStyles"
135148
aria-hidden="true"
136149
focusable="false"
137-
pointer-events-none fixed z-50
150+
pointer-events-none fixed
138151
border="1 $vp-c-brand"
139-
class="VPNolebaseSpotlightHoverBlock"
152+
class="VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock"
153+
:class="[
154+
spotlightStyle === SpotlightStyle.Under ? 'VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockUnder' : '',
155+
spotlightStyle === SpotlightStyle.Aside ? 'VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockAside' : '',
156+
]"
140157
/>
141158
</Teleport>
142159
</template>
160+
161+
<style less scoped>
162+
:root {
163+
--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color: rgb(240 197 52 / 10%);
164+
}
165+
166+
.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockUnder {
167+
background-color: var(--vp-nolebase-enhanced-readabilities-spotlight-under-bg-color);
168+
}
169+
170+
.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlock.VPNolebaseEnhancedReadabilitiesSpotlightHoverBlockAside::before {
171+
content: '';
172+
position: absolute;
173+
display: block;
174+
width: 4px;
175+
height: 100%;
176+
border-radius: 4px;
177+
background-color: var(--vp-c-brand);
178+
left: -24px;
179+
}
180+
</style>

0 commit comments

Comments
 (0)