Advertisement
avr39-ripe

buttonClass

Apr 9th, 2020
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Button
  2. {
  3.     constructor(name, width, height)
  4.     {
  5.         this._name = name
  6.         this._styles = [{name: 'width', value: width},{name: 'height', value: height}];
  7.     };
  8.    
  9.     getName() { return this._name;};
  10.     setName(name) {this._name = name;};
  11.     _getStyle(styleName){ return this._styles.find((it)=>{ if (it.name === styleName){return it};}) };
  12.     _setStyle(styleName,value) {this._getStyle(styleName).value = value;};
  13.     getSize(){return {width: this._getStyle('width').value, height: this._getStyle('height').value};};
  14.     setSize(width, height){ this._setStyle('width', width); this._setStyle('height', height); };
  15.    
  16.     _toStyle(){ return this._styles.reduce((prev,it)=>{
  17.         return `${prev}${it.name}: ${it.value}; `;
  18.         },'');};
  19.    
  20.     _toHtml(){return `<button style="${this._toStyle()}">${this._name}</button>`;};
  21.     showBtn() { document.write(this._toHtml());};
  22. }
  23.  
  24. class BootstrapButton extends Button
  25. {
  26.     constructor(name, width, height, color)
  27.     {
  28.         super(name, width, height);
  29.         this._styles.push({name: 'background-color', value: color});
  30.     }
  31.     getColor(){return this._getStyle('background-color').value;};
  32.     setColor(color){ this._setStyle('background-color', color);};
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement