@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 3.37 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{r as e,h as t,H as i,g as s}from"./index-Biu4X4Y_.js";import{c as a}from"./clsx-eK3rPvPS.js";import{f as l,e as o,x as n}from"./component-names-C3fyby67.js";import{d as c}from"./common-Dd0zJQbD.js";import{v as r}from"./href-rwDd36rS.js";import{v as h}from"./label-Dnmzb2S_.js";import{v as d}from"./open-CbvHO4XG.js";import{n as _}from"./dev.utils-Dg5aYzVg.js";const f=(e,t,a)=>{c(e,"_active",t,a)},b=class{constructor(t){e(this,t),this.groupId=`tree-group-${_()}`,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1}}render(){const{_href:e,_active:s,_hasChildren:n,_open:r,_label:c}=this.state;return t(i,{key:"442889bb000355873e79c2df59cce348ed0afb0c",onSlotchange:this.handleSlotchange.bind(this)},t("li",{key:"ab695fb7c3857e493631704e56f86b6c6211ad9f",class:"kol-tree-item",style:{"--level":`${this.level}`}},t(l,{key:"ac9855976707c3665cb09f90af3a6ecd490bb653",class:a("kol-tree-item__link",{"kol-tree-item__link--first-level":0===this.level,"kol-tree-item__link--active":s}),_href:e,_label:"",_role:"treeitem",_tabIndex:s?0:-1,_ariaExpanded:n?r:void 0,_ariaOwns:n?this.groupId:void 0,ref:e=>this.linkElement=e},t("span",{key:"9122a46258722d8df6bc5423cf8ee8b9412c763b",class:"kol-tree-item__link-inner",slot:"expert"},n?t("span",{class:"kol-tree-item__toggle-button",onClick:e=>r?void this.handleCollapseClick(e):void this.handleExpandClick(e)},t(o,{class:"kol-tree-item__toggle-button-icon",_icons:"codicon codicon-"+(r?"chevron-down":"chevron-right"),_label:""})):t("span",{class:"kol-tree-item__toggle-button-placeholder"}),t("span",{key:"b6108f314822588593d7426ad43f3bddaf42ae3c",class:"kol-tree-item__text"},c))),t("ul",{key:"2ca328f5ca9dfc25264ac1cf5a05ebf9b8a47eb8",class:"kol-tree-item__children",hidden:!n||!r,role:"group",id:this.groupId},t("slot",{key:"756437d12f6ea52ef666a5813221d84b6b29c575"}))))}validateActive(e){f(this,e||!1)}validateLabel(e){h(this,e)}validateOpen(e){d(this,e)}validateHref(e){r(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()!==n&&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 s(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{b as kol_tree_item_wc};