From 942e47c41b3260b9b4c0c81615ea8fbba752dbd1 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 17 Jul 2021 21:29:16 +0100 Subject: [PATCH] :construction: WIP Built the get all variables feature --- src/components/Settings/CustomThemeMaker.vue | 45 ++++++++++++++++++-- src/components/Settings/ThemeSelector.vue | 5 ++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/components/Settings/CustomThemeMaker.vue b/src/components/Settings/CustomThemeMaker.vue index fa674374..f908015b 100644 --- a/src/components/Settings/CustomThemeMaker.vue +++ b/src/components/Settings/CustomThemeMaker.vue @@ -10,6 +10,7 @@ show-fallback fallback-input-type="color" popover-x="left" + @input="setVariable(colorName, customColors[colorName])" > +

Show All Variables

- +
@@ -52,21 +54,34 @@ export default { }; }, methods: { + /* Sets the value to a given variable in the DOM */ + setVariable(variable, value) { + document.documentElement.style.setProperty(`--${variable}`, value); + }, + /* Itterates over available variables, removing them from the DOM */ + resetUnsavedColors() { + const variables = Object.keys(this.customColors); + variables.forEach((variable) => { + document.documentElement.style.removeProperty(`--${variable}`); + }); + this.$emit('closeThemeConfigurator'); + }, /* Finds the current dominent value for a given CSS variable */ getCssVariableValue(cssVar) { - return getComputedStyle(document.documentElement).getPropertyValue(cssVar) || 'inherit'; + return getComputedStyle(document.documentElement).getPropertyValue(cssVar).trim() || 'inherit'; }, /* Returns a JSON object, with the variable name as key, and color as value */ makeInitialData(variableArray) { const data = {}; + const addDash = (colorVar) => (/^--/.exec(colorVar) ? colorVar : `--${colorVar}`); variableArray.forEach((colorName) => { - data[colorName] = this.getCssVariableValue(`--${colorName}`); + data[colorName.replace('--', '')] = this.getCssVariableValue(addDash(colorName)); }); return data; }, /* If a builtin theme is applied, grab it's colors */ findAllVariableNames() { - Array.from(document.styleSheets) // Get all stylesheets, filter out irrelevant ones + const availableVariables = Array.from(document.styleSheets) .filter(sheet => sheet.href === null || sheet.href.startsWith(window.location.origin)) .reduce( ((acc, sheet) => ([ @@ -79,6 +94,7 @@ export default { ])), [], ); + this.customColors = this.makeInitialData(availableVariables); }, /* Returns a complmenting text color for the palete foreground */ /* White if the color is dark, otherwise black */ @@ -113,6 +129,7 @@ div.theme-configurator-wrapper { max-height: 20rem; padding: 0.5rem; z-index: 5; + overflow-y: auto; background: var(--config-settings-background); color: var(--config-settings-color); border-radius: var(--curve-factor); @@ -155,6 +172,26 @@ div.theme-configurator-wrapper { } } +p.show-more-variables { + cursor: pointer; + margin: 0.5rem auto 0; + padding: 0.2rem 0.4rem; + width: fit-content; + text-align: center; + text-decoration: underline; + border-radius: var(--curve-factor); + border: 1px solid var(--background-darker); + &:hover { + background: var(--background); + border-color: var(--primary); + text-decoration: none; + } + &:active { + background: var(--primary); + color: var(--background); + } +} + div.action-buttons { display: flex; button { diff --git a/src/components/Settings/ThemeSelector.vue b/src/components/Settings/ThemeSelector.vue index 20ed3c49..eef7e1e0 100644 --- a/src/components/Settings/ThemeSelector.vue +++ b/src/components/Settings/ThemeSelector.vue @@ -13,7 +13,10 @@ class="color-button" @click="openThemeConfigurator" /> - +