UNPKG

integralui-web-tabstrip

Version:

IntegralUI Web Lite - TabStrip is a native Web Component that consists of multiple panels with tabs that share the same space.

15 lines (12 loc) 9.27 kB
/* filename: integralui.tab.js version : 20.2.0 Copyright © 2020 Lidor Systems. All rights reserved. This file is part of the "IntegralUI Web Lite" Library. The contents of this file are subject to the IntegralUI Web Lite License, and may not be used except in compliance with the License. A copy of the License should have been installed in the product's root installation directory or it can be found at http://www.lidorsystems.com/products/web/lite/license-agreement.aspx. This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws. */ import{c as css,h as html}from"../external/lit-element.js";import{c as classMap}from"../external/class-map.js";import{s as styleMap}from"../external/style-map.js";import{IntegralUIAnimationType,IntegralUIObjectState,IntegralUITheme}from"./integralui.enums.js";import IntegralUIBase from"./integralui.base.js";import{iuiTabDefaultStyle}from"../styles/integralui.tab.style.js";import{iuiTabOfficeStyle}from"../themes/office/integralui.tab.office.js";import{iuiTabMidnightStyle}from"../themes/midnight/integralui.tab.midnight.js";class IntegralUITab extends IntegralUIBase{_ini(){super._ini();this._cAnm=IntegralUIAnimationType.Fade;this._isDgAlw=!1;this._isDpAlw=!0;this._cntOvw="auto";this._cIco="";this._cTxt="";this._cntHdn=!0;this._pCtr=null;this._isSel=!1;this._tpPs=0;this._lfPs=0;this._elWh="0";this._elHt="0";this._elOrd=0;this._elBdClr="gray";this._cntOp=1;this._cntCS={};this._cntCSName="";this._hdrCsNm=""}connectedCallback(){}disconnectedCallback(){}_iniContent(){let t=this,e=setTimeout(function(){if(t._contentSlotElem)t._maxBlockHeight=t._contentSlotElem.offsetHeight;clearTimeout(e)},100)}_iniStyle(){this._gnrCsNm="iui-tab";this._hdrCsNm=this._gnrCsNm+"-header";this._cntCSName=this._gnrCsNm+"-content";this._dfSty={general:{disabled:this._gnrCsNm+"-disabled",focused:this._gnrCsNm+"-focused",normal:this._gnrCsNm,hovered:this._gnrCsNm+"-hovered",selected:this._gnrCsNm+"-selected"},header:{disabled:this._hdrCsNm+"-disabled",focused:this._hdrCsNm+"-focused",normal:this._hdrCsNm,hovered:this._hdrCsNm+"-hovered",selected:this._hdrCsNm+"-selected"},content:{disabled:this._cntCSName+"-disabled",focused:this._cntCSName+"-focused",normal:this._cntCSName,hovered:this._cntCSName+"-hovered",selected:this._cntCSName+"-selected"}};this.refresh()}setParent(t){this._pCtr=t}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s)}static get properties(){return{allowDrag:{type:Boolean,attribute:"allow-drag",reflect:!0},allowDrop:{type:Boolean,attribute:"allow-drop",reflect:!0},animation:{converter:{fromAttribute:t=>{switch((t=t.replace(/"|'/,"").replace(/"|'/,"")).toLowerCase()){case"fade":return IntegralUIAnimationType.Fade;case"slide":return IntegralUIAnimationType.Slide;default:return IntegralUIAnimationType.None}},toAttribute:t=>{switch(t){case IntegralUIAnimationType.Fade:return"Fade";case IntegralUIAnimationType.Slide:return"Slide";default:return"None"}}},reflect:!0},icon:{type:String,reflect:!0},selected:{type:Boolean,reflect:!0},text:{type:String,reflect:!0}}}get allowDrag(){return this._isDgAlw}set allowDrag(t){if(this._isDgAlw!==t){const e=this._isDgAlw;this._isDgAlw=t;this.requestUpdate("allowDrag",e)}}get allowDrop(){return this._isDpAlw}set allowDrop(t){if(this._isDpAlw!==t){const e=this._isDpAlw;this._isDpAlw=t;this.requestUpdate("allowDrop",e)}}get animation(){return this._cAnm}set animation(t){if(this._cAnm!==t){const e=this._cAnm;this._cAnm=t;this.requestUpdate("animation",e)}}get icon(){return this._cIco}set icon(t){if(this._cIco!==t){const e=this._cIco;this._cIco=t;this.requestUpdate("icon",e)}}get selected(){return this._isSel}set selected(t){if(this._isSel!==t){if(t)this.state|=IntegralUIObjectState.Selected;else this.state&=~IntegralUIObjectState.Selected;const e=this._isSel;this._isSel=t;this._elOrd=t?2:0;this._cntHdn=!1===t?!0:!1;this.requestUpdate("selected",e);this.update()}}get text(){return this._cTxt}set text(t){if(this._cTxt!==t){const e=this._cTxt;this._cTxt=t;this.requestUpdate("text",e);this.update()}}processStateChanged(){this._upCntCs()}getSize(t){let e={width:0,height:0};if(t)e={width:t.offsetWidth,height:t.offsetHeight};return e}updateLayout(t,e,s){this._tpPs=t.top;this._lfPs=t.left;let i={top:0,right:0,bottom:0,left:0};if(this._eRf)i=this._cmnSrv.getPadding(this._eRf);this._elWh=e.width-(i.left+i.right)+"px";if("auto"===e.height)this._elHt="auto";else this._elHt=e.height-(i.top+i.bottom)+"px";this._cntHdn=s;this.update()}updateOpacity(t){this._cntOp=t;this.update()}updatePos(t){this._tpPs=void 0!==t.top?t.top:this._tpPs;this._lfPs=void 0!==t.left?t.left:this._lfPs;this.update()}updateVisibility(t){this._cntHdn=t;this.update()}updateContentOverflow(t){this._cntOvw=t;this.update()}getLayoutParams(){let t={size:{width:0,height:0},padding:{top:0,right:0,bottom:0,left:0}};if(this._eRf){let e=this._eRf.children[0];t.size=this._getSize(e);t.padding=this._cmnSrv.getPadding(e)}return t}_upCntCs(){this._cntCS={};this._cntCS[this._cntCSName]=!0;this._cntCS[this._opt.currentStyle.content.normal]=!0;if(this.state&IntegralUIObjectState.Disabled)this._cntCS[this._opt.currentStyle.content.disabled]=!0;else if(this.state&IntegralUIObjectState.Focused)this._cntCS[this._opt.currentStyle.content.focused]=!0;else if(this.state&IntegralUIObjectState.Selected)this._cntCS[this._opt.currentStyle.content.selected]=!0;else if(this.state&IntegralUIObjectState.Hovered)this._cntCS[this._opt.currentStyle.content.hovered]=!0}_gCntCs(){return this._cntCS}_gCntSty(t){if(this._cmnSrv.isString(t))return t;else if(t)return{disabled:this._cmnSrv.isFieldAvailable(t.disabled,this._cntCSName+"-disabled"),focused:this._cmnSrv.isFieldAvailable(t.focused,this._cntCSName+"-focused"),hovered:this._cmnSrv.isFieldAvailable(t.hovered,this._cntCSName+"-hovered"),normal:this._cmnSrv.isFieldAvailable(t.normal,this._cntCSName),selected:this._cmnSrv.isFieldAvailable(t.selected,this._cntCSName+"-selected")};else return{disabled:this._dfSty.content.disabled,focused:this._dfSty.content.focused,hovered:this._dfSty.content.hovered,normal:this._dfSty.content.normal,selected:this._dfSty.content.selected}}_gHdrSty(t){if(this._cmnSrv.isString(t))return t;else if(t)return{disabled:this._cmnSrv.isFieldAvailable(t.disabled,this._hdrCsNm+"-disabled"),focused:this._cmnSrv.isFieldAvailable(t.focused,this._hdrCsNm+"-focused"),hovered:this._cmnSrv.isFieldAvailable(t.hovered,this._hdrCsNm+"-hovered"),normal:this._cmnSrv.isFieldAvailable(t.normal,this._hdrCsNm),selected:this._cmnSrv.isFieldAvailable(t.selected,this._hdrCsNm+"-selected")};else return{disabled:this._dfSty.header.disabled,focused:this._dfSty.header.focused,hovered:this._dfSty.header.hovered,normal:this._dfSty.header.normal,selected:this._dfSty.header.selected}}_uSty(t){if(t)this._opt.currentStyle={general:this._gGnSty(t.general),header:this._gHdrSty(t.header),content:this._gCntSty(t.content)};else this._opt.currentStyle={general:{disabled:this._dfSty.general.disabled,focused:this._dfSty.general.focused,hovered:this._dfSty.general.hovered,normal:this._dfSty.general.normal,selected:this._dfSty.general.selected},header:{disabled:this._dfSty.header.disabled,focused:this._dfSty.header.focused,hovered:this._dfSty.header.hovered,normal:this._dfSty.header.normal,selected:this._dfSty.header.selected},content:{disabled:this._dfSty.content.disabled,focused:this._dfSty.content.focused,hovered:this._dfSty.content.hovered,normal:this._dfSty.content.normal,selected:this._dfSty.content.selected}}}_gCTbSty(){return this._opt.currentStyle}_uThSt(t){this._cThmSettings=css``;switch(t){case IntegralUITheme.Office:this._cThmSettings.cssText=this._cmnSrv.replaceAll(iuiTabOfficeStyle.cssText,"../icons",this._cRsPt);break;case IntegralUITheme.Midnight:this._cThmSettings.cssText=this._cmnSrv.replaceAll(iuiTabMidnightStyle.cssText,"../icons",this._cRsPt);break;default:this._cThmSettings.cssText=""}}firstUpdated(t){this._uRf();this._iniContent()}refresh(){this._uSty(this.controlStyle);this._uCtrCs();this._upCntCs();this.update();this._uRf()}render(){return html`\n <style>\n ${iuiTabDefaultStyle}\n ${this._cThmSettings}\n ${this._cCmSty}\n </style>\n <div data-ctrl="tab" class=${classMap(this._gCntCs())}" style=${styleMap({overflow:this._cntOvw,top:this._tpPs+"px",left:this._lfPs+"px",width:this._elWh,height:this._elHt,opacity:this._cntOp})}" .hidden="${this._cntHdn&&this.animation!==IntegralUIAnimationType.Slide}">\n <div id="tab-content">\n <slot></slot>\n </div>\n </div>\n `}_uRf(){this._contentElem=this.shadowRoot.querySelector("#tab-content");this._contentSlotElem=this.shadowRoot.querySelector("slot").assignedNodes()[1];this._eRf=this.shadowRoot.querySelector("div[data-ctrl=tab]")}}window.customElements.define("iui-tab",IntegralUITab);export default IntegralUITab;