dees-element/ts/dees-element.classes.cssmanager.ts

44 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-03-27 16:52:06 +00:00
import { CSSResult } from 'lit-element';
import * as plugins from './dees-element.plugins';
2021-03-27 18:25:39 +00:00
import * as domtools from '@designestate/dees-domtools';
2021-03-27 16:52:06 +00:00
export interface IDbVarTriplet {
cssVarName: string;
darkValue: string;
brightValue: string;
}
export class CssManager {
public dbVarTripletStore: IDbVarTriplet[] = [];
public dbTheme(darkValueArg: string, brightValueArg: string): CSSResult {
2021-03-28 14:38:17 +00:00
let returnCssVar: string;
2021-03-27 16:52:06 +00:00
const existingTriplet = this.dbVarTripletStore.find(tripletArg => tripletArg.darkValue === darkValueArg && tripletArg.brightValue === brightValueArg);
if (existingTriplet) {
2021-03-28 14:38:17 +00:00
returnCssVar = existingTriplet.cssVarName;
2021-03-27 16:52:06 +00:00
} else {
const newTriplet: IDbVarTriplet = {
cssVarName: `--${plugins.isounique.uni()}`,
brightValue: brightValueArg,
darkValue: darkValueArg
2021-03-28 14:38:17 +00:00
};
this.dbVarTripletStore.push(newTriplet);
domtools.DomTools.setupDomTools().then(async (domtools) => {
await domtools.domReady.promise;
document.body.style.setProperty(newTriplet.cssVarName, newTriplet.darkValue);
});
returnCssVar = newTriplet.cssVarName;
2021-03-27 16:52:06 +00:00
}
2021-03-28 14:38:17 +00:00
return plugins.litElement.unsafeCSS(`var(${returnCssVar})`);
2021-03-27 16:52:06 +00:00
}
public cssGridColumns = (amountOfColumnsArg: number, gapSizeArg: number): CSSResult => {
let returnString = ``;
for (let i = 0; i < amountOfColumnsArg; i++) {
returnString += ` calc((100%/${amountOfColumnsArg}) - (${
gapSizeArg * (amountOfColumnsArg - 1)
}px/${amountOfColumnsArg}))`;
}
return plugins.litElement.unsafeCSS(returnString);
};
}