UNPKG

fonteva-design-guide

Version:

## Dev, Build and Test

42 lines (35 loc) 1.49 kB
import { LightningElement, api, track } from 'lwc'; import { publishEvent } from 'c/pubsub'; export default class PfmTableCustomActionButton extends LightningElement { @api rowId; @api actionButtonAttributes; @track iconName = ''; @track iconSize = 'x-small'; @track buttonType = 'outline'; @track buttonName = ''; @track classes = 'pfm-custom_action_button'; @track renderedCallbackTriggered = false; renderedCallback() { if (!this.renderedCallbackTriggered && this.actionButtonAttributes) { const actionName = this.actionButtonAttributes.actionName; this.buttonName = actionName + '-' + this.rowId; this.classes += ' pfm-custom_action_button-' + actionName; const button = this.template.querySelector('c-pfm-button'); Object.keys(this.actionButtonAttributes).forEach(key => { button[key] = this.actionButtonAttributes[key]; }); button.icon = this.actionButtonAttributes.iconName; if (this.actionButtonAttributes.buttonType) { button.type = this.actionButtonAttributes.buttonType; } button.refreshAttributes(); this.renderedCallbackTriggered = true; } } handleClick() { publishEvent(this.actionButtonAttributes.actionName, { rowId: this.rowId, thisButton: this }); } }