mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-29 03:45:20 +03:00
✨ Users custom colors are applied on load
This commit is contained in:
parent
04b98ae66c
commit
4c44ddef26
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="`theme-configurator-wrapper ${showingAllVars ? 'showing-all' : ''}`">
|
<div :class="`theme-configurator-wrapper ${showingAllVars ? 'showing-all' : ''}`">
|
||||||
<h3 class="configurator-title">Custom Configurator</h3>
|
<h3 class="configurator-title">Theme Configurator</h3>
|
||||||
<div class="color-row-container">
|
<div class="color-row-container">
|
||||||
<div class="color-row" v-for="colorName in Object.keys(customColors)" :key="colorName">
|
<div class="color-row" v-for="colorName in Object.keys(customColors)" :key="colorName">
|
||||||
<label :for="`color-input-${colorName}`" class="color-name">
|
<label :for="`color-input-${colorName}`" class="color-name">
|
||||||
@ -31,7 +31,10 @@
|
|||||||
/>
|
/>
|
||||||
</div> <!-- End of color list -->
|
</div> <!-- End of color list -->
|
||||||
</div>
|
</div>
|
||||||
<p @click="findAllVariableNames" class="show-more-variables">
|
<p @click="resetAndSave" class="action-text-btn show-all-vars-btn">
|
||||||
|
Reset Styles for '{{ themeToEdit }}'
|
||||||
|
</p>
|
||||||
|
<p @click="findAllVariableNames" class="action-text-btn">
|
||||||
Show All Variables
|
Show All Variables
|
||||||
</p>
|
</p>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
@ -44,14 +47,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import VSwatches from 'vue-swatches';
|
import VSwatches from 'vue-swatches';
|
||||||
import 'vue-swatches/dist/vue-swatches.css';
|
import 'vue-swatches/dist/vue-swatches.css';
|
||||||
import { localStorageKeys } from '@/utils/defaults';
|
import { localStorageKeys, mainCssVars } from '@/utils/defaults';
|
||||||
|
|
||||||
import Button from '@/components/FormElements/Button';
|
import Button from '@/components/FormElements/Button';
|
||||||
import SaveIcon from '@/assets/interface-icons/save-config.svg';
|
import SaveIcon from '@/assets/interface-icons/save-config.svg';
|
||||||
import CancelIcon from '@/assets/interface-icons/config-cancel.svg';
|
import CancelIcon from '@/assets/interface-icons/config-cancel.svg';
|
||||||
|
|
||||||
const mainVariables = ['primary', 'background', 'background-darker'];
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ThemeMaker',
|
name: 'ThemeMaker',
|
||||||
components: {
|
components: {
|
||||||
@ -62,7 +63,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
customColors: this.makeInitialData(mainVariables),
|
customColors: this.makeInitialData(mainCssVars),
|
||||||
showingAllVars: false,
|
showingAllVars: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -92,8 +93,14 @@ export default {
|
|||||||
variables.forEach((variable) => {
|
variables.forEach((variable) => {
|
||||||
document.documentElement.style.removeProperty(`--${variable}`);
|
document.documentElement.style.removeProperty(`--${variable}`);
|
||||||
});
|
});
|
||||||
|
this.customColors = this.makeInitialData(mainCssVars);
|
||||||
this.$emit('closeThemeConfigurator');
|
this.$emit('closeThemeConfigurator');
|
||||||
},
|
},
|
||||||
|
resetAndSave() {
|
||||||
|
this.resetUnsavedColors();
|
||||||
|
this.customColors = this.makeInitialData(mainCssVars);
|
||||||
|
this.saveChanges();
|
||||||
|
},
|
||||||
/* Returns a JSON object, with the variable name as key, and color as value */
|
/* Returns a JSON object, with the variable name as key, and color as value */
|
||||||
makeInitialData(variableArray) {
|
makeInitialData(variableArray) {
|
||||||
const data = {};
|
const data = {};
|
||||||
@ -218,7 +225,7 @@ div.theme-configurator-wrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.show-more-variables {
|
p.action-text-btn {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin: 0.5rem auto 0;
|
margin: 0.5rem auto 0;
|
||||||
padding: 0.2rem 0.4rem;
|
padding: 0.2rem 0.4rem;
|
||||||
@ -243,6 +250,7 @@ p.show-more-variables {
|
|||||||
|
|
||||||
div.action-buttons {
|
div.action-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
button {
|
button {
|
||||||
min-width: 6rem;
|
min-width: 6rem;
|
||||||
padding: 0.25rem 0.5rem;
|
padding: 0.25rem 0.5rem;
|
||||||
@ -255,7 +263,7 @@ div.theme-configurator-wrapper.showing-all {
|
|||||||
div.color-row-container {
|
div.color-row-container {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
p.show-more-variables {
|
p.show-all-vars-btn {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,11 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import CustomThemeMaker from '@/components/Settings/CustomThemeMaker';
|
import CustomThemeMaker from '@/components/Settings/CustomThemeMaker';
|
||||||
import { LoadExternalTheme, ApplyLocalTheme, ApplyCustomTheme } from '@/utils/ThemeHelper';
|
import {
|
||||||
|
LoadExternalTheme,
|
||||||
|
ApplyLocalTheme,
|
||||||
|
ApplyCustomVariables,
|
||||||
|
} from '@/utils/ThemeHelper';
|
||||||
import Defaults, { localStorageKeys } from '@/utils/defaults';
|
import Defaults, { localStorageKeys } from '@/utils/defaults';
|
||||||
import IconPalette from '@/assets/interface-icons/config-color-palette.svg';
|
import IconPalette from '@/assets/interface-icons/config-color-palette.svg';
|
||||||
|
|
||||||
@ -52,7 +56,7 @@ export default {
|
|||||||
themeHelper: new LoadExternalTheme(),
|
themeHelper: new LoadExternalTheme(),
|
||||||
themeConfiguratorOpen: false, // Control the opening of theme config popup
|
themeConfiguratorOpen: false, // Control the opening of theme config popup
|
||||||
ApplyLocalTheme,
|
ApplyLocalTheme,
|
||||||
ApplyCustomTheme,
|
ApplyCustomVariables,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -100,9 +104,7 @@ export default {
|
|||||||
/* Updates theme. Checks if the new theme is local or external,
|
/* Updates theme. Checks if the new theme is local or external,
|
||||||
and calls appropirate updating function. Updates local storage */
|
and calls appropirate updating function. Updates local storage */
|
||||||
updateTheme(newTheme) {
|
updateTheme(newTheme) {
|
||||||
if (newTheme === 'custom') {
|
if (newTheme === 'Deafault') {
|
||||||
this.ApplyCustomTheme();
|
|
||||||
} else if (newTheme === 'Deafault') {
|
|
||||||
this.resetToDefault();
|
this.resetToDefault();
|
||||||
this.themeHelper.theme = 'Deafault';
|
this.themeHelper.theme = 'Deafault';
|
||||||
} else if (this.isThemeLocal(newTheme)) {
|
} else if (this.isThemeLocal(newTheme)) {
|
||||||
@ -110,6 +112,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.themeHelper.theme = newTheme;
|
this.themeHelper.theme = newTheme;
|
||||||
}
|
}
|
||||||
|
this.ApplyCustomVariables(newTheme);
|
||||||
localStorage.setItem(localStorageKeys.THEME, newTheme);
|
localStorage.setItem(localStorageKeys.THEME, newTheme);
|
||||||
},
|
},
|
||||||
/* Removes any applied themes */
|
/* Removes any applied themes */
|
||||||
|
@ -1,9 +1,22 @@
|
|||||||
import ErrorHandler from '@/utils/ErrorHandler';
|
import ErrorHandler from '@/utils/ErrorHandler';
|
||||||
import { getTheme } from '@/utils/ConfigHelpers';
|
import { getTheme } from '@/utils/ConfigHelpers';
|
||||||
|
import { localStorageKeys, mainCssVars } from '@/utils/defaults';
|
||||||
|
|
||||||
/* Returns users current theme */
|
/* Returns users current theme */
|
||||||
export const GetTheme = () => getTheme();
|
export const GetTheme = () => getTheme();
|
||||||
|
|
||||||
|
/* Gets user custom color preferences for current theme, and applies to DOM */
|
||||||
|
export const ApplyCustomVariables = (theme) => {
|
||||||
|
mainCssVars.forEach((vName) => { document.documentElement.style.removeProperty(`--${vName}`); });
|
||||||
|
const customColors = JSON.parse(localStorage[localStorageKeys.CUSTOM_COLORS] || '{}');
|
||||||
|
const themeColors = customColors[theme];
|
||||||
|
if (themeColors) {
|
||||||
|
Object.keys(themeColors).forEach((customVar) => {
|
||||||
|
document.documentElement.style.setProperty(`--${customVar}`, themeColors[customVar]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* Sets the theme, by updating data-theme attribute on the html tag */
|
/* Sets the theme, by updating data-theme attribute on the html tag */
|
||||||
export const ApplyLocalTheme = (newTheme) => {
|
export const ApplyLocalTheme = (newTheme) => {
|
||||||
const htmlTag = document.getElementsByTagName('html')[0];
|
const htmlTag = document.getElementsByTagName('html')[0];
|
||||||
@ -11,11 +24,6 @@ export const ApplyLocalTheme = (newTheme) => {
|
|||||||
htmlTag.setAttribute('data-theme', newTheme);
|
htmlTag.setAttribute('data-theme', newTheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sets specific CSS variables, for the users custom theme */
|
|
||||||
export const ApplyCustomTheme = () => {
|
|
||||||
ApplyLocalTheme('custom');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function for pre-loading, and easy switching of external stylesheets
|
* A function for pre-loading, and easy switching of external stylesheets
|
||||||
* External CSS is preloaded to avoid FOUC
|
* External CSS is preloaded to avoid FOUC
|
||||||
|
@ -80,6 +80,11 @@ module.exports = {
|
|||||||
APP_CONFIG: 'appConfig',
|
APP_CONFIG: 'appConfig',
|
||||||
SECTIONS: 'sections',
|
SECTIONS: 'sections',
|
||||||
},
|
},
|
||||||
|
mainCssVars: ['primary', 'background', 'background-darker'],
|
||||||
|
splashScreenTime: 1900,
|
||||||
|
metaTagData: [
|
||||||
|
{ name: 'description', content: 'A simple static homepage for you\'re server' },
|
||||||
|
],
|
||||||
toastedOptions: {
|
toastedOptions: {
|
||||||
position: 'bottom-center',
|
position: 'bottom-center',
|
||||||
duration: 2500,
|
duration: 2500,
|
||||||
@ -88,10 +93,6 @@ module.exports = {
|
|||||||
iconPack: 'fontawesome',
|
iconPack: 'fontawesome',
|
||||||
},
|
},
|
||||||
backupEndpoint: 'https://dashy-sync-service.as93.net',
|
backupEndpoint: 'https://dashy-sync-service.as93.net',
|
||||||
splashScreenTime: 1900,
|
|
||||||
metaTagData: [
|
|
||||||
{ name: 'description', content: 'A simple static homepage for you\'re server' },
|
|
||||||
],
|
|
||||||
faviconApiEndpoints: {
|
faviconApiEndpoints: {
|
||||||
mcapi: 'https://eu.mc-api.net/v3/server/favicon/$URL',
|
mcapi: 'https://eu.mc-api.net/v3/server/favicon/$URL',
|
||||||
clearbit: 'https://logo.clearbit.com/$URL',
|
clearbit: 'https://logo.clearbit.com/$URL',
|
||||||
|
Loading…
Reference in New Issue
Block a user