import { ATTRIBUTE_TYPE, AlphaAttribute, AlphaComponent, UI_TYPE, adoptAlphaCommonStyle } from '@jatahworx/alpha-annotations-lib'; import { LitElement, html } from 'lit'; import { property } from 'lit/decorators.js'; import { componentStyles } from './{{componentSelector}}.styles.ts'; @AlphaComponent({ componentName: '{{componentSelector}}', componentVersion: '1.0.0', label: '{{componentLabel}}', selector: '{{componentSelectorPrefix}}-{{componentSelector}}', category: 'Input', icon: 'sample.png', }) @adoptAlphaCommonStyle() export class {{componentClassName}} extends LitElement { static styles = componentStyles; /** * @description * Attribute for property for the component * @param type -- ATTRIBUTE_TYPE.PROPERTY * @param uiType -- type of the component by which the value can get to this property * @param label -- Label on the editable component * @param defaultValue -- Default value to the property * @param placeholder -- placeholder on the editable component * @param fieldMappings -- the value of this attribute will assign to the path/property name defined here */ @AlphaAttribute({ type: ATTRIBUTE_TYPE.PROPERTY, uiType: UI_TYPE.INPUT, label: 'Initial Count', defaultValue: 0, placeholder: 'Enter label', fieldMappings: 'value' }) @property({ type: Number }) value = 0; @AlphaAttribute({ uiType: UI_TYPE.TYPED_INPUT, type: ATTRIBUTE_TYPE.PROPERTY, label: 'Value', category: 'Binding Variable', options: [ { name: 'CO', value: 'co' }, { name: 'CMS', value: 'cms' }, { name: 'Case Instance', value: 'case_instance' }, { name: 'Task Instance', value: 'task_instance' }, { name: 'Local', value: 'local' }, ], fieldMappings: { type: 'options.mappingType', value: 'options.modelPath', }, }) options = { mappingType: '', modelPath: '' } @property({ type: Boolean }) disabled = false; @property({ type: Boolean }) readonly = false; render() { return html` ${this.value || 0} `; } /** * @description * Attribute for Event from the component * @param type -- ATTRIBUTE_TYPE.EVENT * @param label -- Label of the Event to show in the trigger list * @param event -- Actual event name on which event listner will add */ @AlphaAttribute({ type: ATTRIBUTE_TYPE.EVENT, label: 'On Increment', event: 'onIncrement', }) increment(event) { this.change(1); const eventOptions = { detail: { event, element: this, value: this.value, }, bubbles: true, composed: true, }; this.dispatchEvent(new CustomEvent('onIncrement', eventOptions)); } @AlphaAttribute({ type: ATTRIBUTE_TYPE.EVENT, label: 'On Decrement', event: 'onDecrement', }) decrement(event) { this.change(-1); const eventOptions = { detail: { event, element: this, value: this.value, }, bubbles: true, composed: true, }; this.dispatchEvent(new CustomEvent('onDecrement', eventOptions)); } private change(delta: number) { this.value = Number(this.value) + delta; } }