mirror of
https://github.com/fmhy/edit.git
synced 2026-01-14 07:51:25 +11:00
Add indexes toggle and disable starred
This commit is contained in:
parent
2373c0acfd
commit
01dfd2ec26
5 changed files with 68 additions and 13 deletions
|
|
@ -4,6 +4,7 @@ import ColorPicker from './ColorPicker.vue'
|
|||
import ThemeSelector from './ThemeSelector.vue'
|
||||
import InputField from './InputField.vue'
|
||||
import ToggleStarred from './ToggleStarred.vue'
|
||||
import ToggleIndexes from './ToggleIndexes.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -26,6 +27,11 @@ import ToggleStarred from './ToggleStarred.vue'
|
|||
<ToggleStarred />
|
||||
</template>
|
||||
</InputField>
|
||||
<InputField id="toggle-indexes" label="Toggle Indexes">
|
||||
<template #display>
|
||||
<ToggleIndexes />
|
||||
</template>
|
||||
</InputField>
|
||||
|
||||
<div class="mt-4">
|
||||
<ColorPicker />
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ const enabled = ref(false)
|
|||
.switch.enabled {
|
||||
background-color: var(--vp-c-brand);
|
||||
}
|
||||
|
||||
.switch.disabled {
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
background-color: var(--vp-c-bg-soft);
|
||||
border-color: var(--vp-c-divider);
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
16
docs/.vitepress/theme/components/ToggleIndexes.vue
Normal file
16
docs/.vitepress/theme/components/ToggleIndexes.vue
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<script setup lang="ts">
|
||||
import Switch from './Switch.vue'
|
||||
|
||||
const toggleIndexes = () =>
|
||||
document.documentElement.classList.toggle('indexes-only')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Switch @click="toggleIndexes()" />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.indexes-only li:not(.index) {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,12 +1,34 @@
|
|||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import Switch from './Switch.vue'
|
||||
|
||||
const toggleStarred = () =>
|
||||
const isDisabled = ref(false)
|
||||
|
||||
const syncDisabled = () => {
|
||||
isDisabled.value = document.documentElement.classList.contains('indexes-only')
|
||||
}
|
||||
|
||||
let observer: MutationObserver | undefined
|
||||
|
||||
onMounted(() =>
|
||||
(observer = new MutationObserver(syncDisabled)).observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class']
|
||||
})
|
||||
)
|
||||
|
||||
onMounted(syncDisabled)
|
||||
|
||||
onBeforeUnmount(() => observer?.disconnect())
|
||||
|
||||
const toggleStarred = () => {
|
||||
if (isDisabled.value) return
|
||||
document.documentElement.classList.toggle('starred-only')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Switch @click="toggleStarred()" />
|
||||
<Switch :class="{ disabled: isDisabled }" @click="toggleStarred()" />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue