UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

4 lines 3.5 kB
/*! * KoliBri - The accessible HTML-Standard */ import{r as e,h as t,H as i,g as s}from"./index-DyUiyxj3.js";import{c as a}from"./clsx-eK3rPvPS.js";import{f as l,e as o,y as n}from"./component-names-B_kYyA8u.js";import{d as r}from"./common-BXXICkFX.js";import{v as c}from"./href-BDekIhFd.js";import{v as d}from"./label-Dkj9sxQK.js";import{v as h}from"./open-Cuy37cT5.js";import{n as f}from"./dev.utils-EtfHgKpk.js";const _=(e,t,a)=>{r(e,"_active",t,a)},v=class{constructor(t){e(this,t),this.groupId=`tree-group-${f()}`,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1}}render(){const{_href:e,_active:s,_hasChildren:n,_open:r,_label:d}=this.state;return t(i,{key:"e99bc051fe9fe90cd4a5aaf861d61d0d512c808a",onSlotchange:this.handleSlotchange.bind(this)},t("li",{key:"e0ae86b656eab778f80852a40dd84cda832695a9",class:"kol-tree-item",style:{"--level":`${this.level}`}},t(l,{key:"3ffea17f30ab8e461e936d691d7fd4389f04bf2c",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:"dfd6fa644efe7efe4700ec74a5f1c50e82262494",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:"kolicon kolicon-"+(r?"chevron-down":"chevron-right"),_label:""})):t("span",{class:"kol-tree-item__toggle-button-placeholder"}),t("span",{key:"ef4714af7a6a63c447b3df2647dc605d5c9693b9",class:"kol-tree-item__text"},d))),t("ul",{key:"34f5c43c0d6b3ecc0d78d6eb2101aa451e5d1cb2",class:"kol-tree-item__children",hidden:!n||!r,role:"group",id:this.groupId},t("slot",{key:"1ef6c1855acdebee823d68f7d0849fcd79d5d558"}))))}validateActive(e){_(this,e||!1)}validateLabel(e){d(this,e)}validateOpen(e){h(this,e)}validateHref(e){c(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 focus(){var e;return Promise.resolve(null===(e=this.linkElement)||void 0===e?void 0:e.focus())}async handleExpandClick(e){var t;e.preventDefault(),await(null===(t=this.linkElement)||void 0===t?void 0:t.focus()),await this.expand()}async expand(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!0}))}async handleCollapseClick(e){var t;e.preventDefault(),await(null===(t=this.linkElement)||void 0===t?void 0:t.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{v as kol_tree_item_wc};