UNPKG

@freshworks/crayons

Version:
187 lines (186 loc) 5.43 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { Component, Element, Prop, h } from '@stencil/core'; import { hasSlot } from '../../utils'; import { i18n } from '../../global/Translation'; export class ModalFooter { constructor() { /** * The text for the submit button */ this.submitText = ''; /** * The text for the cancel button */ this.cancelText = ''; /** * Default state of submit button */ this.submitDisabled = false; /** * The color of submit button */ this.submitColor = 'primary'; /** * Set to true if we want to render slot instead of default footer */ this.custom = null; /** * Function to call on submit of modal */ // eslint-disable-next-line @typescript-eslint/no-empty-function this.submit = () => { }; /** * Function to call on close of modal */ // eslint-disable-next-line @typescript-eslint/no-empty-function this.close = () => { }; } /** * lifecycle event, called once just after the component is first connected to the DOM */ componentWillLoad() { if (this.custom === null) { this.custom = hasSlot(this.el); } } /** * render slot when custom attribute is passed, else renders the default footer with submit and cancel buttons * @returns {JSX.Element} */ render() { return (h("div", { class: 'modal-footer-container' }, h("div", { class: 'modal-footer' }, this.custom ? (h("slot", null)) : (h("span", null, h("fw-button", { color: 'secondary', onClick: () => this.close() }, this.cancelText), h("fw-button", { color: this.submitColor, disabled: this.submitDisabled, onClick: () => this.submit() }, this.submitText)))))); } static get is() { return "fw-modal-footer"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["modal-footer.scss"] }; } static get styleUrls() { return { "$": ["modal-footer.css"] }; } static get properties() { return { "submitText": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The text for the submit button" }, "attribute": "submit-text", "reflect": false, "defaultValue": "''" }, "cancelText": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The text for the cancel button" }, "attribute": "cancel-text", "reflect": false, "defaultValue": "''" }, "submitDisabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Default state of submit button" }, "attribute": "submit-disabled", "reflect": false, "defaultValue": "false" }, "submitColor": { "type": "string", "mutable": false, "complexType": { "original": "'primary' | 'secondary' | 'danger' | 'link' | 'text'", "resolved": "\"danger\" | \"link\" | \"primary\" | \"secondary\" | \"text\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The color of submit button" }, "attribute": "submit-color", "reflect": false, "defaultValue": "'primary'" }, "submit": { "type": "any", "mutable": false, "complexType": { "original": "any", "resolved": "any", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Function to call on submit of modal" }, "attribute": "submit", "reflect": false, "defaultValue": "() => {}" }, "close": { "type": "any", "mutable": false, "complexType": { "original": "any", "resolved": "any", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Function to call on close of modal" }, "attribute": "close", "reflect": false, "defaultValue": "() => {}" } }; } static get elementRef() { return "el"; } } __decorate([ i18n({ keyName: 'modal.ok' }) ], ModalFooter.prototype, "submitText", void 0); __decorate([ i18n({ keyName: 'modal.cancel' }) ], ModalFooter.prototype, "cancelText", void 0);