Compare commits

...

10 Commits

Author SHA1 Message Date
62136c8d20 1.0.16 2021-03-28 20:10:51 +00:00
06b7f7fd12 fix(core): update 2021-03-28 20:10:51 +00:00
07be13cf39 1.0.15 2021-03-28 19:57:46 +00:00
20e539edf0 fix(core): update 2021-03-28 19:57:45 +00:00
a06752b09f 1.0.14 2021-03-28 14:38:18 +00:00
d697fa2437 fix(core): update 2021-03-28 14:38:17 +00:00
a0cad2f4bc 1.0.13 2021-03-27 18:25:39 +00:00
240e34b7d0 fix(core): update 2021-03-27 18:25:39 +00:00
4d4dd59b9b 1.0.12 2021-03-27 18:21:39 +00:00
746ebe1490 fix(core): update 2021-03-27 18:21:38 +00:00
4 changed files with 41 additions and 15 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@designestate/dees-element",
"version": "1.0.11",
"version": "1.0.16",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@designestate/dees-element",
"version": "1.0.11",
"version": "1.0.16",
"private": false,
"description": "a custom element class extending lit element class",
"main": "dist_ts/index.js",

View File

@ -8,7 +8,7 @@ tap.test('should create a static element', async () => {
public static styles = [
deesElement.css`
.buttonClass {
background: ${deesElement.cssManager.dbTheme('blue', 'black')};
background: ${deesElement.cssManager.bdTheme('blue', 'black')};
}
`
];

View File

@ -1,29 +1,55 @@
import { CSSResult } from 'lit-element';
import * as plugins from './dees-element.plugins';
import * as domtools from '@designestate/dees-domtools';
export interface IDbVarTriplet {
export interface IBdVarTriplet {
cssVarName: string;
darkValue: string;
brightValue: string;
}
export class CssManager {
public dbVarTripletStore: IDbVarTriplet[] = [];
public domtoolsPromise = domtools.DomTools.setupDomTools();
public goBright: boolean = false;
public bdVarTripletStore: IBdVarTriplet[] = [];
public dbTheme(darkValueArg: string, brightValueArg: string): CSSResult {
const existingTriplet = this.dbVarTripletStore.find(tripletArg => tripletArg.darkValue === darkValueArg && tripletArg.brightValue === brightValueArg);
constructor() {
this.domtoolsPromise.then(async (domtoolsArg) => {
domtoolsArg.themeManager.themeObservable.subscribe(async (goBrightArg) => {
this.goBright = goBrightArg;
await domtoolsArg.domReady;
for (const bdTripletArg of this.bdVarTripletStore) {
document.body.style.setProperty(
bdTripletArg.cssVarName,
this.goBright ? bdTripletArg.brightValue : bdTripletArg.darkValue
);
}
});
});
}
public bdTheme(brightValueArg: string, darkValueArg: string): CSSResult {
let returnCssVar: string;
const existingTriplet = this.bdVarTripletStore.find(
(tripletArg) =>
tripletArg.darkValue === darkValueArg && tripletArg.brightValue === brightValueArg
);
if (existingTriplet) {
return plugins.litElement.unsafeCSS(existingTriplet.cssVarName)
returnCssVar = existingTriplet.cssVarName;
} else {
const newTriplet: IDbVarTriplet = {
const newTriplet: IBdVarTriplet = {
cssVarName: `--${plugins.isounique.uni()}`,
brightValue: brightValueArg,
darkValue: darkValueArg
}
this.dbVarTripletStore.push(newTriplet)
document.body.style.setProperty(newTriplet.cssVarName, newTriplet.darkValue);
return plugins.litElement.unsafeCSS(newTriplet.cssVarName);
darkValue: darkValueArg,
};
this.bdVarTripletStore.push(newTriplet);
this.domtoolsPromise.then(async (domtoolsArg) => {
await domtoolsArg.domReady.promise;
document.body.style.setProperty(newTriplet.cssVarName, this.goBright ? newTriplet.brightValue : newTriplet.darkValue);
});
returnCssVar = newTriplet.cssVarName;
}
return plugins.litElement.unsafeCSS(`var(${returnCssVar})`);
}
public cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number): CSSResult => {
@ -35,4 +61,4 @@ export class CssManager {
}
return plugins.litElement.unsafeCSS(returnString);
};
}
}