Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CssClass {
- constructor(nameCssClass) {
- this.nameCssClass = nameCssClass
- this.cssStyle = []
- }
- getCssStyle(cssName) {
- return this.cssStyle.find((it) => {
- if (it.name == cssName) {
- return it;
- }
- })
- }
- setCssStyle(cssName, value) {
- if (this.getCssStyle(cssName) == undefined) {
- return this.cssStyle.push({ name: cssName, value: value });
- } else {
- this.getCssStyle(cssName).value = value;
- }
- }
- removeStyle(cssName) {
- return this.cssStyle.splice(this.cssStyle.findIndex(it => it.name === cssName), 1);
- }
- toCssStyle() {
- return this.cssStyle.reduce((prev, it) => {
- return `${prev}${it.name}: ${it.value}; `
- }
- , '')
- }
- getCss() {
- return `.${this.nameCssClass} { ${this.toCssStyle()} } `;
- }
- }
- let css1 = new CssClass('wrap');
- css1.setCssStyle("display", "flex");
- let css2 = new CssClass('block');
- css2.setCssStyle("width", "300px");
- css2.setCssStyle("margin", "10px");
- css2.setCssStyle("color", "red");
- css2.removeStyle("margin");
- let css3 = new CssClass('img');
- css3.setCssStyle("width", "100%");
- let result = [css1.getCss(), css2.getCss(), css3.getCss()].join('');
- console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement