mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -05:00
@@ -12,25 +12,27 @@ export class PyButton extends BaseEvalElement {
|
||||
mount_name: string;
|
||||
constructor() {
|
||||
super();
|
||||
this.defaultClass = ['p-2', 'text-white', 'bg-blue-600', 'border', 'border-blue-600','rounded']
|
||||
|
||||
this.defaultClass = ['p-2', 'text-white', 'bg-blue-600', 'border', 'border-blue-600', 'rounded'];
|
||||
|
||||
if (this.hasAttribute('label')) {
|
||||
this.label = this.getAttribute('label');
|
||||
}
|
||||
|
||||
// Styling does the same thing as class in normal HTML. Using the name "class" makes the style to malfunction
|
||||
if (this.hasAttribute('styling')) {
|
||||
let klass = this.getAttribute('styling');
|
||||
if (klass.trim() == ''){
|
||||
this.class = this.defaultClass
|
||||
}else{
|
||||
klass = klass.trim()
|
||||
const newClassArray = klass.split(' ');
|
||||
const klass = this.getAttribute('styling').trim();
|
||||
if (klass === '') {
|
||||
this.class = this.defaultClass;
|
||||
} else {
|
||||
// trim each element to remove unnecessary spaces which makes the button style to malfunction
|
||||
this.class = (() => {const concatenatedString = []; for (let i = 0; i < newClassArray.length; i++) {if (newClassArray[i].trim() !== '')(concatenatedString.push(newClassArray[i].trim()));} return concatenatedString;})();
|
||||
this.class = klass
|
||||
.split(' ')
|
||||
.map(x => x.trim())
|
||||
.filter(x => x !== '');
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.class = this.defaultClass
|
||||
} else {
|
||||
this.class = this.defaultClass;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user