mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-21 04:35:15 +02:00
🚧 WIP Built the get all variables feature
This commit is contained in:
parent
2f04a5ec6c
commit
942e47c41b
@ -10,6 +10,7 @@
|
|||||||
show-fallback
|
show-fallback
|
||||||
fallback-input-type="color"
|
fallback-input-type="color"
|
||||||
popover-x="left"
|
popover-x="left"
|
||||||
|
@input="setVariable(colorName, customColors[colorName])"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
:id="`color-input-${colorName}`"
|
:id="`color-input-${colorName}`"
|
||||||
@ -21,9 +22,10 @@
|
|||||||
/>
|
/>
|
||||||
</v-swatches>
|
</v-swatches>
|
||||||
</div> <!-- End of color list -->
|
</div> <!-- End of color list -->
|
||||||
|
<p class="show-more-variables" @click="findAllVariableNames">Show All Variables</p>
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<Button><SaveIcon />Save</Button>
|
<Button><SaveIcon />Save</Button>
|
||||||
<Button><CancelIcon />Cancel</Button>
|
<Button :click="resetUnsavedColors"><CancelIcon />Cancel</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -52,21 +54,34 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
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 */
|
/* Finds the current dominent value for a given CSS variable */
|
||||||
getCssVariableValue(cssVar) {
|
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 */
|
/* Returns a JSON object, with the variable name as key, and color as value */
|
||||||
makeInitialData(variableArray) {
|
makeInitialData(variableArray) {
|
||||||
const data = {};
|
const data = {};
|
||||||
|
const addDash = (colorVar) => (/^--/.exec(colorVar) ? colorVar : `--${colorVar}`);
|
||||||
variableArray.forEach((colorName) => {
|
variableArray.forEach((colorName) => {
|
||||||
data[colorName] = this.getCssVariableValue(`--${colorName}`);
|
data[colorName.replace('--', '')] = this.getCssVariableValue(addDash(colorName));
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
/* If a builtin theme is applied, grab it's colors */
|
/* If a builtin theme is applied, grab it's colors */
|
||||||
findAllVariableNames() {
|
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))
|
.filter(sheet => sheet.href === null || sheet.href.startsWith(window.location.origin))
|
||||||
.reduce(
|
.reduce(
|
||||||
((acc, sheet) => ([
|
((acc, sheet) => ([
|
||||||
@ -79,6 +94,7 @@ export default {
|
|||||||
])),
|
])),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
this.customColors = this.makeInitialData(availableVariables);
|
||||||
},
|
},
|
||||||
/* Returns a complmenting text color for the palete foreground */
|
/* Returns a complmenting text color for the palete foreground */
|
||||||
/* White if the color is dark, otherwise black */
|
/* White if the color is dark, otherwise black */
|
||||||
@ -113,6 +129,7 @@ div.theme-configurator-wrapper {
|
|||||||
max-height: 20rem;
|
max-height: 20rem;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
|
overflow-y: auto;
|
||||||
background: var(--config-settings-background);
|
background: var(--config-settings-background);
|
||||||
color: var(--config-settings-color);
|
color: var(--config-settings-color);
|
||||||
border-radius: var(--curve-factor);
|
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 {
|
div.action-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
button {
|
button {
|
||||||
|
@ -13,7 +13,10 @@
|
|||||||
class="color-button"
|
class="color-button"
|
||||||
@click="openThemeConfigurator"
|
@click="openThemeConfigurator"
|
||||||
/>
|
/>
|
||||||
<CustomThemeMaker v-if="themeConfiguratorOpen" />
|
<CustomThemeMaker
|
||||||
|
v-if="themeConfiguratorOpen"
|
||||||
|
@closeThemeConfigurator="closeThemeConfigurator()"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user