docs/.vitepress/theme/components/settings/Spotlight.vue

1181c28da7f00dffc07621ad877fea1f9578faee
wotaku/docs/.vitepress/theme/components/settings/Spotlight.vue
taskylizard wotaku 2bea9706e6c 1 year ago

94 lines · 3375 bytes

 1<script setup lang="ts">
 2import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui'
 3import { useMediaQuery, useMounted, useStorage } from '@vueuse/core'
 4import { computed, inject, onMounted, ref, watch } from 'vue'
 5
 6import MenuHelp from './MenuHelp.vue'
 7import MenuTitle from './MenuTitle.vue'
 8import SpotlightHoverBlock from './SpotlightHoverBlock.vue'
 9
10import { InjectionKey, SpotlightToggledStorageKey } from '../../constants'
11
12const options = inject(InjectionKey, {})
13
14const menuTitleElementRef = ref<HTMLDivElement>()
15const isMenuHelpPoppedUp = ref(false)
16const disabled = ref(false)
17
18const mounted = useMounted()
19const isTouchScreen = useMediaQuery('(pointer: coarse)')
20const spotlightToggledOn = useStorage(
21  SpotlightToggledStorageKey,
22  options.spotlight?.defaultToggle || false
23)
24
25const fieldOptions = computed(() => [
26  {
27    value: true,
28    title: 'On',
29    ariaLabel: 'On',
30    text: 'ON',
31    name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch'
32  },
33  {
34    value: false,
35    title: 'Off',
36    ariaLabel: 'Off',
37    text: 'OFF',
38    name: 'VitePress Nolebase Enhanced Readabilities Spotlight Toggle Switch'
39  }
40])
41
42onMounted(() => {
43  disabled.value = isTouchScreen.value
44})
45
46watch(isTouchScreen, () => {
47  disabled.value = isTouchScreen.value
48})
49</script>
50
51<template>
52  <div space-y-2 role="radiogroup">
53    <SpotlightHoverBlock v-if="mounted && spotlightToggledOn && !disabled" :enabled="spotlightToggledOn && !disabled" />
54    <div ref="menuTitleElementRef" relative flex items-center>
55      <MenuTitle title="Spotlight" aria-label="Spotlight" :disabled="disabled" flex="1" pr-4>
56        <template #icon>
57          <span i-icon-park-outline:click mr-1 aria-hidden="true" />
58        </template>
59      </MenuTitle>
60      <MenuHelp v-if="!options.spotlight?.disableHelp" v-model:is-popped-up="isMenuHelpPoppedUp"
61        :menu-title-element-ref="menuTitleElementRef">
62        <h4 text-md mb-1 font-semibold>Spotlight</h4>
63        <p text="sm" mb-2 max-w-100>
64          <span>
65            Highlight the line where the mouse is currently hovering in the
66            content to optimize for users who may have reading and focusing
67            difficulties.
68          </span>
69        </p>
70        <div space-y-2 class="VPNolebaseEnhancedReadabilitiesMenu">
71          <div text="sm" bg="$vp-nolebase-enhanced-readabilities-menu-background-color" max-w-100 rounded-xl p-3>
72            <h5 text="sm" mb-2>
73              <span mr-1 font-bold>ON</span>
74              <span font-semibold>On</span>
75            </h5>
76            <span>Turn on the Spotlight feature</span>
77          </div>
78          <div text="sm" bg="$vp-nolebase-enhanced-readabilities-menu-background-color" max-w-100 rounded-xl p-3>
79            <h5 text="sm" mb-2>
80              <span mr-1 font-bold>OFF</span>
81              <span font-semibold>Off</span>
82            </h5>
83            <span>Turn off the Spotlight feature</span>
84          </div>
85        </div>
86      </MenuHelp>
87    </div>
88    <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
89      <NuInputHorizontalRadioGroup v-model="spotlightToggledOn"
90        bg="$vp-nolebase-enhanced-readabilities-menu-background-color"
91        text="sm $vp-nolebase-enhanced-readabilities-menu-text-color" :options="fieldOptions" :disabled="disabled" />
92    </NuInputHighlight>
93  </div>
94</template>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form