@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 3.82 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index$1=require("./index-03ef29aa.js"),index=require("./index-8b802221.js"),componentNames=require("./component-names-82c4d68d.js"),dev_utils=require("./dev.utils-f6da9b54.js"),clsx=require("./clsx-dd4d6dd1.js"),label=require("./label-21c38949.js"),open=require("./open-4dee9006.js"),href=require("./href-273fdbde.js"),validateActive=(e,t,i)=>{index.watchBoolean(e,"_active",t,i)},KolTreeItemWc=class{constructor(e){index$1.registerInstance(this,e),this.groupId=`tree-group-${dev_utils.nonce()}`,this.level=void 0,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1},this._active=void 0,this._label=void 0,this._open=void 0,this._href=void 0}render(){const{_href:e,_active:t,_hasChildren:i,_open:a,_label:l}=this.state;return index$1.h(index$1.Host,{key:"1358f3b8f8c7ae14535f30e3c2ff1ef8ab6904b1",onSlotchange:this.handleSlotchange.bind(this)},index$1.h("li",{key:"d6271238a133cac44eb78bf8ed0b94a951135432",class:"kol-tree-item",style:{"--level":`${this.level}`}},index$1.h(componentNames.KolLinkWcTag,{key:"329b9adc28bacf6742544123bc02fe82f2ceb9b5",class:clsx.clsx("kol-tree-item__link",{"kol-tree-item__link--first-level":0===this.level,"kol-tree-item__link--active":t}),_href:e,_label:"",_role:"treeitem",_tabIndex:t?0:-1,_ariaExpanded:i?a:void 0,_ariaOwns:i?this.groupId:void 0,ref:e=>this.linkElement=e},index$1.h("span",{key:"0292f071a8abfe0f9332ef4a8561149d38f804e2",class:"kol-tree-item__link-inner",slot:"expert"},i?index$1.h("span",{class:"kol-tree-item__toggle-button",onClick:e=>a?void this.handleCollapseClick(e):void this.handleExpandClick(e)},index$1.h(componentNames.KolIconTag,{class:"kol-tree-item__toggle-button-icon",_icons:"codicon codicon-"+(a?"chevron-down":"chevron-right"),_label:""})):index$1.h("span",{class:"kol-tree-item__toggle-button-placeholder"}),index$1.h("span",{key:"ed810a798a4e2ba38f848ce0c6fdfc3893c3c86d",class:"kol-tree-item__text"},l))),index$1.h("ul",{key:"0e8ea268f1c26f79e55d45bfeda91d230bc4789d",class:"kol-tree-item__children",hidden:!i||!a,role:"group",id:this.groupId},index$1.h("slot",{key:"a6509011c3fa851be4c6cace3aadf2b6d6bbfc7b"}))))}validateActive(e){validateActive(this,e||!1)}validateLabel(e){label.validateLabel(this,e)}validateOpen(e){open.validateOpen(this,e)}validateHref(e){href.validateHref(this,e)}componentWillLoad(){this.validateActive(this._active),this.validateLabel(this._label),this.validateOpen(this._open),this.validateHref(this._href),this.checkForChildren(),this.determineTreeItemDepth()}determineTreeItemDepth(){let e=0,t=this.host.parentNode.host.parentNode;for(;null!==t&&t.tagName.toLowerCase()!==componentNames.KolTreeTag&&t!==document.body;)t=t.parentElement,e+=1;this.level=e}handleSlotchange(){this.checkForChildren()}checkForChildren(){var e,t;this.state=Object.assign(Object.assign({},this.state),{_hasChildren:Boolean(null===(t=null===(e=this.host.querySelector("slot"))||void 0===e?void 0:e.assignedElements)||void 0===t?void 0:t.call(e).length)})}async focusLink(){await this.linkElement.kolFocus()}async handleExpandClick(e){e.preventDefault(),await this.linkElement.kolFocus(),await this.expand()}async expand(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!0}))}async handleCollapseClick(e){e.preventDefault(),this.linkElement.focus(),await this.collapse()}async collapse(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!1}))}async isOpen(){var e;return null!==(e=this.state._open)&&void 0!==e&&e}get host(){return index$1.getElement(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};exports.kol_tree_item_wc=KolTreeItemWc;