gov-gui
Version:
Gov UI Component Library Typscript Build
361 lines (360 loc) • 13.6 kB
JavaScript
import { h, Fragment } from "@stencil/core";
import { getGlobalPropsClasses } from "../../global/global-styles-helper";
import { getAnimationClasses } from "../../global/animation-helpers";
export class GovButton {
constructor() {
this.hasSuffix = false;
this.hasPrefix = false;
this.iconSize = 'md';
this.typeVariant = 'button'; // Add the typeVariant prop
// Add the disabled prop
this.disabled = false;
this.animationDelay = '2s';
this.allClasses = '';
this.sizes = ['sm', 'lg', 'extended'];
this.validVariants = ['primary', 'secondary', 'info', 'success', 'warning', 'danger', 'white', 'disabled'];
}
//watching for any change in animations to trigger them
watchAnimations() {
this.provideClass();
}
watchAnimationsDelay() {
this.provideClass();
}
watchAnimationsSpeed() {
this.provideClass();
}
// inject the animations and styles on component load
componentWillLoad() {
const animationClasses = getAnimationClasses({
animation: this.animation,
animationDelay: this.animationDelay,
animationSpeed: this.animationSpeed
});
this.allClasses = getGlobalPropsClasses({
classes: ' ' + animationClasses,
});
}
//Called on change of any animation related property to trigger change
provideClass() {
const animationClasses = getAnimationClasses({
animation: this.animation,
animationDelay: this.animationDelay,
animationSpeed: this.animationSpeed
});
this.allClasses = getGlobalPropsClasses({
classes: ' ' + animationClasses,
});
}
render() {
const sizeClass = this.sizes.includes(this.size) ? this.size : '';
const variantClass = this.validVariants.includes(this.variant) ? this.variant : '';
const typeVariantClass = this.typeVariant;
// If the button is disabled, apply the 'disabled' class and prevent clicking
const buttonClasses = `btn ${sizeClass} ${this.disabled ? 'disabled' : variantClass} ${typeVariantClass}`;
return (h("button", { key: 'a5c9ed8f18c3dee4d8f920f69390afb014768b41', type: this.type, class: `${buttonClasses} ${this.allClasses}`, onClick: this.disabled ? undefined : this.clicked, disabled: this.disabled }, this.typeVariant === 'iconButton' && this.icon != "" && h("span", { key: '8cb815f7b9c790261960afa44d0f57249a84ed84', class: "" }, h("gov-icon", { key: '7b35d0d82ded88958caa71fca2180c03dff74112', name: this.icon, size: this.iconSize == 'md' || 'lg' || 'sm' ? this.iconSize : 'md', variant: this.disabled ? 'disabled' : this.variant })), this.typeVariant === 'button' && (h(Fragment, null, h("div", { key: 'e0edcc1a08e9a6b1c2e974622b567761ab0fa047', style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } }, this.icon && this.hasPrefix && h("span", { key: '3c205d99b8faccb64c5307b5b8a9fb08055415e5', class: "icon", style: { marginRight: '8px', marginTop: '3px' } }, h("gov-icon", { key: '5346010d6510c9aa25d6e865801a9df595982cc0', name: this.icon, size: this.iconSize == 'md' || 'lg' || 'sm' ? this.iconSize : 'md', variant: "white" })), this.label && h("span", { key: 'de6cfdb93745126d8394eca7f6c0aacef8c5c358', class: "label" }, this.label), this.icon && this.hasSuffix && h("span", { key: '88dd19b29651748e3303dc55240d68bb976ec5d0', class: "icon", style: { marginLeft: '8px', marginTop: '3px' } }, h("gov-icon", { key: '150fb5ef8bcd100cd0384d7bc4ab32e5af652d5f', name: this.icon, size: this.iconSize == 'md' || 'lg' || 'sm' ? this.iconSize : 'md', variant: "white" }))))), this.typeVariant === 'textButton' && h("span", { key: '107d2e7a20fefde27a7638f971e0d5e154ef96f8', class: "label" }, this.label)));
}
static get is() { return "gov-button"; }
static get originalStyleUrls() {
return {
"$": ["gov-button.css"]
};
}
static get styleUrls() {
return {
"$": ["gov-button.css"]
};
}
static get properties() {
return {
"label": {
"type": "any",
"mutable": false,
"complexType": {
"original": "string | number",
"resolved": "number | string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "label",
"reflect": false
},
"icon": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "icon",
"reflect": false
},
"hasSuffix": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "has-suffix",
"reflect": false,
"defaultValue": "false"
},
"hasPrefix": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "has-prefix",
"reflect": false,
"defaultValue": "false"
},
"size": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "size",
"reflect": false
},
"iconSize": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'sm' | 'md' | 'lg'",
"resolved": "\"lg\" | \"md\" | \"sm\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "icon-size",
"reflect": false,
"defaultValue": "'md'"
},
"type": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "type",
"reflect": false
},
"variant": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "variant",
"reflect": false
},
"clicked": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "(event: MouseEvent) => void",
"resolved": "(event: MouseEvent) => void",
"references": {
"MouseEvent": {
"location": "global",
"id": "global::MouseEvent"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false
},
"typeVariant": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'button' | 'textButton' | 'iconButton'",
"resolved": "\"button\" | \"iconButton\" | \"textButton\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "type-variant",
"reflect": false,
"defaultValue": "'button'"
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "disabled",
"reflect": false,
"defaultValue": "false"
},
"animation": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "animation",
"reflect": false
},
"animationDelay": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'2s' | '3s' | '4s' | '5s'",
"resolved": "\"2s\" | \"3s\" | \"4s\" | \"5s\"",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "animation-delay",
"reflect": false,
"defaultValue": "'2s'"
},
"animationSpeed": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'slow' | 'slower' | 'fast' | 'faster'",
"resolved": "\"fast\" | \"faster\" | \"slow\" | \"slower\"",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "animation-speed",
"reflect": false
}
};
}
static get watchers() {
return [{
"propName": "animation",
"methodName": "watchAnimations"
}, {
"propName": "animationDelay",
"methodName": "watchAnimationsDelay"
}, {
"propName": "animationSpeed",
"methodName": "watchAnimationsSpeed"
}];
}
}
//# sourceMappingURL=gov-button.js.map