Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
c915c3a713 | |||
5009068b56 | |||
62136c8d20 | |||
06b7f7fd12 | |||
07be13cf39 | |||
20e539edf0 | |||
a06752b09f | |||
d697fa2437 | |||
a0cad2f4bc | |||
240e34b7d0 | |||
4d4dd59b9b | |||
746ebe1490 | |||
b6fc6b4f31 | |||
fae10a3240 | |||
8390ba67b3 | |||
d5872511b8 | |||
a322c9a929 | |||
6301d827e1 | |||
a0e7ef2beb | |||
3d144ff81d | |||
3b62cdee88 | |||
487ff89ee5 | |||
9e120ba280 | |||
f577ef0e61 | |||
390f42061e | |||
e2f7fadc83 |
2209
package-lock.json
generated
2209
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-element",
|
"name": "@designestate/dees-element",
|
||||||
"version": "1.0.4",
|
"version": "1.0.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a custom element class extending lit element class",
|
"description": "a custom element class extending lit element class",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -13,15 +13,17 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.80",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.44",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^14.11.2",
|
"@types/node": "^14.14.37",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@designestate/dees-domtools": "^1.0.70",
|
"@designestate/dees-domtools": "^1.0.87",
|
||||||
|
"@pushrocks/isounique": "^1.0.4",
|
||||||
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"lit-element": "^2.4.0"
|
"lit-element": "^2.4.0"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
23
test/test.browser.ts
Normal file
23
test/test.browser.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as deesElement from '../ts/index';
|
||||||
|
|
||||||
|
tap.test('should create a static element', async () => {
|
||||||
|
@deesElement.customElement('my-button')
|
||||||
|
class MyButton extends deesElement.DeesElement {
|
||||||
|
// STATIC
|
||||||
|
public static styles = [
|
||||||
|
deesElement.css`
|
||||||
|
.buttonClass {
|
||||||
|
background: ${deesElement.cssManager.bdTheme('blue', 'black')};
|
||||||
|
}
|
||||||
|
`
|
||||||
|
];
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
render() {
|
||||||
|
return deesElement.html`<div class="buttonClass">My Button</div>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,6 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as deesElement from '../ts/index';
|
|
||||||
|
|
||||||
tap.test('first test', async () => {});
|
|
||||||
|
|
||||||
tap.start();
|
|
68
ts/dees-element.classes.cssmanager.ts
Normal file
68
ts/dees-element.classes.cssmanager.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { CSSResult } from 'lit-element';
|
||||||
|
import * as plugins from './dees-element.plugins';
|
||||||
|
import * as domtools from '@designestate/dees-domtools';
|
||||||
|
|
||||||
|
export interface IBdVarTriplet {
|
||||||
|
cssVarName: string;
|
||||||
|
darkValue: string;
|
||||||
|
brightValue: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CssManager {
|
||||||
|
public domtoolsPromise = domtools.DomTools.setupDomTools();
|
||||||
|
public goBright: boolean = false;
|
||||||
|
public bdVarTripletStore: IBdVarTriplet[] = [];
|
||||||
|
|
||||||
|
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 get defaultStyles () {
|
||||||
|
return domtools.elementBasic.staticStyles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bdTheme(brightValueArg: string, darkValueArg: string): CSSResult {
|
||||||
|
let returnCssVar: string;
|
||||||
|
const existingTriplet = this.bdVarTripletStore.find(
|
||||||
|
(tripletArg) =>
|
||||||
|
tripletArg.darkValue === darkValueArg && tripletArg.brightValue === brightValueArg
|
||||||
|
);
|
||||||
|
if (existingTriplet) {
|
||||||
|
returnCssVar = existingTriplet.cssVarName;
|
||||||
|
} else {
|
||||||
|
const newTriplet: IBdVarTriplet = {
|
||||||
|
cssVarName: `--${plugins.isounique.uni()}`,
|
||||||
|
brightValue: brightValueArg,
|
||||||
|
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 => {
|
||||||
|
let returnString = ``;
|
||||||
|
for (let i = 0; i < amountOfColumnsArg; i++) {
|
||||||
|
returnString += ` calc((100%/${amountOfColumnsArg}) - (${
|
||||||
|
gapSizeArg * (amountOfColumnsArg - 1)
|
||||||
|
}px/${amountOfColumnsArg}))`;
|
||||||
|
}
|
||||||
|
return plugins.litElement.unsafeCSS(returnString);
|
||||||
|
};
|
||||||
|
}
|
38
ts/dees-element.classes.dees-element.ts
Normal file
38
ts/dees-element.classes.dees-element.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import * as plugins from './dees-element.plugins';
|
||||||
|
|
||||||
|
export class DeesElement extends plugins.litElement.LitElement {
|
||||||
|
// INSTANCE
|
||||||
|
@plugins.litElement.property({ type: Boolean })
|
||||||
|
public goBright: boolean = false;
|
||||||
|
|
||||||
|
// domtools
|
||||||
|
public domtoolsPromise = plugins.domtools.elementBasic.setup(this);
|
||||||
|
|
||||||
|
@plugins.litElement.property()
|
||||||
|
domtools?: plugins.domtools.DomTools;
|
||||||
|
|
||||||
|
private themeSubscription: plugins.smartrx.rxjs.Subscription;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.domtoolsPromise.then((domtoolsArg) => {
|
||||||
|
this.domtools = domtoolsArg;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public connectedCallback() {
|
||||||
|
super.connectedCallback();
|
||||||
|
this.domtoolsPromise.then(async (domtools) => {
|
||||||
|
this.themeSubscription = domtools.themeManager.themeObservable.subscribe((goBrightArg) => {
|
||||||
|
this.goBright = goBrightArg;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.dispatchEvent(new CustomEvent('deesElementConnected'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this.themeSubscription.unsubscribe();
|
||||||
|
this.dispatchEvent(new CustomEvent('deesElementDisconnected'));
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,19 @@
|
|||||||
import { LitElement } from 'lit-element';
|
// pushrocks scope
|
||||||
|
import * as isounique from '@pushrocks/isounique';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
|
export {
|
||||||
|
isounique,
|
||||||
|
smartrx
|
||||||
|
};
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import { css, unsafeCSS, LitElement, property } from 'lit-element';
|
||||||
const litElement = {
|
const litElement = {
|
||||||
LitElement
|
css,
|
||||||
|
unsafeCSS,
|
||||||
|
LitElement,
|
||||||
|
property
|
||||||
};
|
};
|
||||||
|
|
||||||
import * as domtools from '@designestate/dees-domtools';
|
import * as domtools from '@designestate/dees-domtools';
|
||||||
|
27
ts/index.ts
27
ts/index.ts
@ -1,19 +1,16 @@
|
|||||||
|
import { CssManager } from './dees-element.classes.cssmanager';
|
||||||
import * as plugins from './dees-element.plugins';
|
import * as plugins from './dees-element.plugins';
|
||||||
|
|
||||||
|
export {
|
||||||
|
customElement,
|
||||||
|
property,
|
||||||
|
internalProperty,
|
||||||
|
html,
|
||||||
|
TemplateResult,
|
||||||
|
css,
|
||||||
|
unsafeCSS
|
||||||
|
} from 'lit-element';
|
||||||
|
|
||||||
|
export { DeesElement } from './dees-element.classes.dees-element';
|
||||||
|
|
||||||
export class DeesElement extends plugins.litElement.LitElement {
|
export const cssManager = new CssManager();
|
||||||
|
|
||||||
public goBright: boolean = false;
|
|
||||||
public domtoolsPromise = plugins.domtools.elementBasic.setup(this);
|
|
||||||
|
|
||||||
public connectedCallback() {
|
|
||||||
super.connectedCallback();
|
|
||||||
this.dispatchEvent(new CustomEvent('domtools-connected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public disconnectedCallback() {
|
|
||||||
super.disconnectedCallback();
|
|
||||||
this.dispatchEvent(new CustomEvent('domtools-disconnected'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user