UNPKG

bruno-ui

Version:
60 lines (57 loc) 1.92 kB
import { r as registerInstance, c as createEvent, h, d as getElement } from './core-23b55849.js'; import { A as AppHelper } from './app.helper-c6a170e0.js'; const TabComponent = class { constructor(hostRef) { registerInstance(this, hostRef); this.active = false; this._active = false; this.tabLoaded = createEvent(this, "tabLoaded", 7); this.tabChanged = createEvent(this, "tabChanged", 7); } ActiveChangeHandler(value) { this._active = value; this.TabChanged(); } componentWillLoad() { this._identifier = AppHelper.GetId(); this._active = this.active; } componentDidLoad() { const tab = this.GetTab(); this.tabLoaded.emit(tab); } render() { return (h("div", { class: { 'brn-tab--active': this._active } }, h("slot", null))); } TabChanged() { const tab = this.GetTab(); this.tabChanged.emit(tab); } GetTab() { const tab = { Identifier: this._identifier, Index: this.GetIndex(), Name: this.name, Active: this._active, OnActive: (value) => { this._active = value; } }; return tab; } GetIndex() { const parent = this._element.closest("brn-tabs"); if (parent) { const tabs = parent.getElementsByTagName('brn-tab'); return Array.prototype.indexOf.call(tabs, this._element); } console.warn('"brn-tab" components must be wrapped with "brn-tabs" component'); return 0; } get _element() { return getElement(this); } static get watchers() { return { "active": ["ActiveChangeHandler"] }; } static get style() { return "brn-tab > div {\n display: none;\n}\nbrn-tab > div.brn-tab--active {\n display: block;\n}"; } }; export { TabComponent as brn_tab };