-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prefers-color-scheme in appearance
- Loading branch information
Showing
5 changed files
with
62 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,65 @@ | ||
<script setup> | ||
import { useI18n } from 'vue-i18n' | ||
import { ref } from 'vue' | ||
import { ref,onBeforeMount,computed,watch } from 'vue' | ||
import SettingsAppearanceRadioGroup from '@/components/Settings/SettingsAppearance/SettingsAppearanceRadioGroup' | ||
import DismissableAlert from '@/components/Dismissable/DismissableAlert.vue'; | ||
defineProps({ | ||
options: { type: Array, required: true } | ||
onBeforeMount(() => { | ||
options.value = retrieveThemes() | ||
}) | ||
const { t } = useI18n() | ||
const infoLabel = t('settings.appearance.info') | ||
const dismissInfoLabel = t('settings.appearance.dismissInfo') | ||
const show = ref(true) | ||
function closeAndSave() { | ||
console.warn('save settings in local storage') | ||
show.value = false | ||
const infoLabel = computed(()=>t('settings.appearance.info')) | ||
const dismissInfoLabel = computed(()=>t('settings.appearance.dismissInfo')) | ||
const DEFAULT_THEME = window.matchMedia("(prefers-color-scheme: dark)").matches ? 'dark' : 'light'; | ||
const LOCAL_STORAGE_KEY = 'data-bs-theme' | ||
function getSelectedTheme(){ | ||
return localStorage.getItem(LOCAL_STORAGE_KEY) || DEFAULT_THEME | ||
} | ||
const selectedTheme = ref(getSelectedTheme()) | ||
const options = ref([]) | ||
function retrieveThemes(){ | ||
return [ | ||
{ | ||
icon: 'sun', | ||
name: DEFAULT_THEME, | ||
label: 'Light mode', | ||
thumbnail: 'https://placehold.co/169x95' | ||
}, | ||
{ | ||
icon: 'moon', | ||
name: 'dark', | ||
label: 'Dark mode', | ||
thumbnail: 'https://placehold.co/169x95' | ||
} | ||
] | ||
} | ||
const useTheme = (theme) => { | ||
const app = document.getElementById('app') | ||
app.setAttribute("data-bs-theme",theme) | ||
} | ||
const persistSelectedTheme = (theme) => { | ||
localStorage.setItem(LOCAL_STORAGE_KEY, theme) | ||
} | ||
watch(() => selectedTheme.value, (theme) => { | ||
persistSelectedTheme(theme) | ||
useTheme(theme) | ||
}, { immediate: true }) | ||
</script> | ||
|
||
<template> | ||
<b-alert v-model="show" variant="info" dismissible close-class="close-class" class="d-flex align-items-center gap-2"> | ||
{{ infoLabel }} | ||
<b-button variant="outline-info" class="bg-light-subtle" @click="closeAndSave">{{ | ||
dismissInfoLabel | ||
}}</b-button></b-alert | ||
> | ||
<settings-appearance-radio-group :options="options" /> | ||
<dismissable-alert no-icon persist name="appearance" variant="info" :infoLabel="infoLabel" :linkLabel="dismissInfoLabel"> | ||
{{infoLabel}} | ||
</dismissable-alert> | ||
|
||
<settings-appearance-radio-group :options="options" v-model="selectedTheme"/> | ||
</template> | ||
<style lang="scss"> | ||
.close-class { | ||
top: unset; | ||
} | ||
</style> | ||
|