UNPKG

@public-ui/components

Version:

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

5 lines 18.5 kB
/*! * KoliBri - The accessible HTML-Standard */ import{r as n,h as t,g as e}from"./index-BQlHOxik.js";import{_ as o}from"./tslib.es6-QNbPBOk5.js";import{b as i,e as a,j as s,s as l,N as r,H as c,I as h,Q as d}from"./common-Cx_AGO_M.js";import{v as f}from"./align-DxZmRFcp.js";import{v as b}from"./label-Fyi30H9j.js";import{b as u}from"./component-names-Dy77vq43.js";import{t as p}from"./i18n-Br16IAnY.js";import{K as m}from"./keyboard-DNd73LVa.js";import{c as k}from"./clsx-COFh-Vc8.js";import{d as g,a as y,c as v}from"./element-interaction-Bv-mPSBn.js";import{d as w,K as _}from"./events-VVvk1win.js";import"./i18n-B2d_exHc.js";import"./element-focus-CRwW4N4R.js";const x=["select-automatic","select-manual"];const T=(n,t)=>{i(n,`_behavior`,(n=>typeof n==="string"&&x.includes(n)),new Set([`KoliBriTabBehavior {${x.join(", ")}`]),t)};const z=(n,t)=>{a(n,"_hasCreateButton",t)};const C='/* forward the rem function */\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without verifying the contrast ratio of its background and font colors.\n * By initially setting the background color to white and the font color to black,\n * the contrast ratio is ensured and explicit adjustment is forced.\n */\n color: black;\n background-color: white;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n /*\n * Text should be aligned left by default to provide a predictable starting point.\n */\n text-align: left;\n }\n * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n word-break: break-word;\n }\n /*\n * All interactive elements should have a minimum size of to-rem(44).\n */\n /* input:not([type=\'checkbox\'], [type=\'radio\'], [type=\'range\']), */\n /* option, */\n /* select, */\n /* textarea, */\n button,\n .kol-input .input {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n }\n /*\n * Some interactive elements should not inherit the font-family and font-size.\n */\n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n /*\n * All elements should inherit the text color from his parent element.\n */\n color: inherit;\n /*\n * All elements should inherit the font family from his parent element.\n */\n font-family: inherit;\n /*\n * All elements should inherit the font size from his parent element.\n */\n font-size: inherit;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /**\n * Sometimes we need the semantic element for accessibility reasons,\n * but we don\'t want to show it.\n *\n * - https://www.a11yproject.com/posts/how-to-hide-content/\n */\n .visually-hidden {\n position: fixed;\n top: 0;\n left: 0;\n width: 1px;\n height: 1px;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n}\n@layer kol-global {\n /*\n * Dieses CSS stellt sicher, dass der Standard-Style\n * von A und Button resettet werden.\n */\n :is(a, button) {\n background-color: transparent;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n /* 100% needed for custom width from outside */\n }\n /*\n * Ensure elements with hidden attribute to be actually not visible\n * @see https://meowni.ca/hidden.is.a.lie.html\n */\n [hidden] {\n display: none !important;\n }\n .badge-text-hint {\n color: black;\n background-color: white;\n }\n}\n@layer kol-global {\n :host {\n /*\n * The max-width is needed to prevent the table from overflowing the\n * parent node, if the table is wider than the parent node.\n */\n max-width: 100%;\n font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n }\n * {\n /*\n * We prefer to box-sizing: border-box for all elements.\n */\n box-sizing: border-box;\n }\n .kol-span {\n /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: center;\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n }\n .kol-span__container {\n display: flex;\n align-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .kol-span .kol-span__label--hide-label .kol-span__label {\n display: none;\n }\n /* Reset browser agent style. */\n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n outline: none;\n cursor: not-allowed;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n .hastooltip {\n z-index: 900 !important;\n }\n}\n@layer kol-component {\n :host {\n display: block;\n }\n}\n@font-face {\n font-family: "kolicons";\n src: url("kolicons.eot?t=1780571516250"); /* IE9*/\n src: url("kolicons.eot?t=1780571516250#iefix") format("embedded-opentype"), url("kolicons.woff2?t=1780571516250") format("woff2"), url("kolicons.woff?t=1780571516250") format("woff"), url("kolicons.ttf?t=1780571516250") format("truetype"), url("kolicons.svg?t=1780571516250#kolicons") format("svg"); /* iOS 4.1- */\n}\n@layer kol-component {\n [class^=kolicon-], [class*=" kolicon-"] {\n font-family: "kolicons";\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n .kolicon-alert-error::before {\n content: "\\ea01";\n }\n .kolicon-alert-info::before {\n content: "\\ea02";\n }\n .kolicon-alert-success::before {\n content: "\\ea03";\n }\n .kolicon-alert-warning::before {\n content: "\\ea04";\n }\n .kolicon-check::before {\n content: "\\ea05";\n }\n .kolicon-chevron-double-left::before {\n content: "\\ea06";\n }\n .kolicon-chevron-double-right::before {\n content: "\\ea07";\n }\n .kolicon-chevron-down::before {\n content: "\\ea08";\n }\n .kolicon-chevron-left::before {\n content: "\\ea09";\n }\n .kolicon-chevron-right::before {\n content: "\\ea0a";\n }\n .kolicon-chevron-up::before {\n content: "\\ea0b";\n }\n .kolicon-cogwheel::before {\n content: "\\ea0c";\n }\n .kolicon-cross::before {\n content: "\\ea0d";\n }\n .kolicon-eye-closed::before {\n content: "\\ea0e";\n }\n .kolicon-eye::before {\n content: "\\ea0f";\n }\n .kolicon-house::before {\n content: "\\ea10";\n }\n .kolicon-kolibri::before {\n content: "\\ea11";\n }\n .kolicon-link-external::before {\n content: "\\ea12";\n }\n .kolicon-link::before {\n content: "\\ea13";\n }\n .kolicon-minus::before {\n content: "\\ea14";\n }\n .kolicon-plus::before {\n content: "\\ea15";\n }\n .kolicon-settings::before {\n content: "\\ea16";\n }\n .kolicon-sort-asc::before {\n content: "\\ea17";\n }\n .kolicon-sort-desc::before {\n content: "\\ea18";\n }\n .kolicon-sort-neutral::before {\n content: "\\ea19";\n }\n .kolicon-up::before {\n content: "\\ea1a";\n }\n .kolicon-version::before {\n content: "\\ea1b";\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-tooltip {\n display: contents;\n }\n .kol-tooltip__floating {\n opacity: 0;\n display: none;\n position: fixed;\n /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n top: 0;\n left: 0;\n /* Can be used to specify the tooltip-width from the outside. Unset by default. */\n width: var(--kol-tooltip-width, max-content);\n min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n max-width: 90vw;\n max-height: 90vh;\n animation-direction: normal;\n /* Can be used to specify the animation duration from the outside. 250ms by default. */\n animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n animation-fill-mode: forwards;\n animation-iteration-count: 1;\n animation-timing-function: ease-in;\n }\n .kol-tooltip__floating.hide {\n animation-name: hideTooltip;\n }\n .kol-tooltip__floating.show {\n animation-name: showTooltip;\n }\n .kol-tooltip__arrow {\n transform: rotate(45deg);\n color: black;\n background-color: white;\n position: absolute;\n z-index: 999;\n width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-tooltip__content {\n color: black;\n background-color: white;\n position: relative;\n z-index: 1000;\n }\n @keyframes hideTooltip {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n display: none;\n }\n }\n @keyframes showTooltip {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-tabs {\n display: var(--display);\n grid-template-columns: var(--grid-template-columns);\n grid-template-rows: var(--grid-template-rows);\n }\n .kol-tabs--align-right {\n --display: grid;\n --grid-template-columns: 1fr auto;\n --button-group-flex-direction: column;\n --button-group-order: 2;\n }\n .kol-tabs--align-left {\n --display: grid;\n --grid-template-columns: auto 1fr;\n --button-group-flex-direction: column;\n --button-group-order: 0;\n }\n .kol-tabs--align-bottom {\n --display: grid;\n --grid-template-rows: 1fr auto;\n --button-group-order: 2;\n }\n .kol-tabs__tabs-align-top {\n --display: grid;\n --grid-template-rows: auto 1fr;\n --button-group-order: 0;\n }\n .kol-tabs__button-group {\n display: flex;\n order: var(--button-group-order);\n flex-direction: var(--button-group-flex-direction);\n flex-wrap: wrap;\n }\n .kol-tabs__button-group .kol-button {\n border-bottom-color: transparent;\n display: block;\n border-bottom-style: solid;\n }\n .kol-tabs__panel {\n height: 100%;\n }\n}';const j=class{constructor(t){n(this,t);this.onCreateLabel=`${p("kol-new")} …`;this.ctaRef=v();this.nextPossibleTabIndex=(n,t,e=1)=>{const o=t+e;if(o<n.length){if(n[o]._disabled){return this.nextPossibleTabIndex(n,t,e+1)}return o}return t};this.prevPossibleTabIndex=(n,t,e=1)=>{const o=t-e;if(o>=0){if(n[o]._disabled){return this.prevPossibleTabIndex(n,t,e+1)}return o}return t};this.onKeyDown=n=>{switch(n.key){case m.ArrowRight:this.goToNextTab(n);break;case m.ArrowLeft:this.goToPreviousTab(n);break;case m.Space:case m.Enter:this.activateFocusedTab(n);break}};this.onClickSelect=(n,t)=>{this.selectNextTabEvent(n,t)};this.onMouseDown=n=>{n.preventDefault()};this.callbacks={onClick:this.onClickSelect,onMouseDown:this.onMouseDown};this.catchTabPanelHost=n=>{this.tabPanelHost=n};this._align="top";this._hasCreateButton=false;this._selected=0;this.state={_align:"top",_label:"",_selected:0,_tabs:[]};this.selectNextNotDisabledTab=(n,t,e=true,o)=>{if(n>t.length-1){n=t.length-1}if(n<0){n=0}if(Array.isArray(t)&&t[n]){if(t[n]._disabled){if(e===true){if(n<t.length-1){return this.selectNextNotDisabledTab(n+1,t,true,o||n)}else{n=o||n;e=false}}if(e===false){if(n>0){return this.selectNextNotDisabledTab(n-1,t,false,o||n)}else{s(`[KolTabs] All tabs are disabled, and therefore no tab can be displayed.`)}}}}return n};this.syncSelectedAndTabs=(n,t,e,o)=>{let i;if(o==="_selected"){i=n}else{i=this.state._selected}let a;if(o==="_tabs"){a=n}else{a=this.state._tabs}if(a.length>0){t.set("_selected",this.selectNextNotDisabledTab(i,a))}};this.refreshTabPanels=()=>{var n,t,e,o;if(!this.tabPanelHost)return;while(this.tabPanelHost.firstChild){this.tabPanelHost.removeChild(this.tabPanelHost.firstChild)}for(let i=0;i<((n=this.state._tabs)===null||n===void 0?void 0:n.length);i++){const n=document.createElement("div");n.setAttribute("aria-labelledby",`${this.state._label.replace(/\s/g,"-")}-tab-${i}`);n.setAttribute("id",`tabpanel-${i}`);n.setAttribute("role","tabpanel");n.setAttribute("hidden","");n.setAttribute("tabindex","0");const a=document.createElement("slot");a.setAttribute("name",`tabpanel-slot-${i}`);n.appendChild(a);(t=this.tabPanelHost)===null||t===void 0?void 0:t.appendChild(n);if(typeof HTMLCollection!=="undefined"&&((e=this.host)===null||e===void 0?void 0:e.children)instanceof HTMLCollection&&((o=this.host)===null||o===void 0?void 0:o.children[i])){this.host.children[i].setAttribute("slot",`tabpanel-slot-${i}`)}}this.updateVisiblePanel()};this.updateVisiblePanel=()=>{if(!this.tabPanelHost)return;Array.from(this.tabPanelHost.children).forEach(((n,t)=>{if(t===this.state._selected){n.removeAttribute("hidden")}else{n.setAttribute("hidden","")}}))};this.onCreate=n=>{var t,e;n.preventDefault();(e=(t=this.state._on)===null||t===void 0?void 0:t.onCreate)===null||e===void 0?void 0:e.call(t,n);if(this.host){w(this.host,_.create)}};this.onBlur=()=>{this.currentFocusIndex=undefined}}getCurrentFocusIndex(){if(typeof this.currentFocusIndex==="number"){return this.currentFocusIndex}return this.state._selected}getKeyboardTabChangeMode(){if(this._behavior==="select-manual"){return"selectFocusOnly"}return"activateCompletely"}goToNextTab(n){const t=this.nextPossibleTabIndex(this.state._tabs,this.getCurrentFocusIndex());this.selectNextTabEvent(n,t,this.getKeyboardTabChangeMode())}goToPreviousTab(n){const t=this.prevPossibleTabIndex(this.state._tabs,this.getCurrentFocusIndex());this.selectNextTabEvent(n,t,this.getKeyboardTabChangeMode())}activateFocusedTab(n){if(typeof this.currentFocusIndex==="number"){this.onSelect(n,this.currentFocusIndex)}}selectNextTabEvent(n,t,e="activateCompletely"){var o,i;this.currentFocusIndex=t;this.focusTabById(t);if(e==="activateCompletely"){this._selected=t;const e=this.state._tabs[t];(i=(o=e._on)===null||o===void 0?void 0:o.onSelect)===null||i===void 0?void 0:i.call(o,n,t);this.onSelect(n,t)}}async focus(){}async click(){}renderButtonGroup(){return t("div",{"aria-label":this.state._label,class:"kol-tabs__button-group",role:"tablist",onKeyDown:this.onKeyDown,onBlur:this.onBlur},this.state._tabs.map(((n,e)=>t(u,{ref:this.state._selected===e?this.ctaRef:undefined,_disabled:n._disabled,_icons:n._icons,_hideLabel:n._hideLabel,_label:n._label,_on:this.callbacks,_tabIndex:this.state._selected===e?0:-1,_tooltipAlign:n._tooltipAlign,_variant:this.state._selected===e?"custom":undefined,_customClass:this.state._selected===e?"selected":"",_ariaControls:`tabpanel-${e}`,_ariaSelected:this.state._selected===e,_id:`${this.state._label.replace(/\s/g,"-")}-tab-${e}`,_role:"tab",_value:e}))),this.state._hasCreateButton&&t(u,{class:"kol-tabs__button-create",_label:this.onCreateLabel,_on:{onClick:this.onCreate},_icons:"kolicon-plus","data-testid":"tabs-create-button"}))}render(){return t("div",{key:"03faa28ca436d156581f60b422a46eca57ff9d48",ref:n=>{this.tabPanelsElement=n},class:k("kol-tabs",`kol-tabs--align-${this.state._align}`)},this.renderButtonGroup(),t("div",{key:"61e93a5f157c7d31a60ec9fef085422955cb7311",class:"kol-tabs__content",ref:this.catchTabPanelHost}))}validateAlign(n){f(this,n)}validateBehavior(n){T(this,n)}validateHasCreateButton(n){z(this,n)}validateLabel(n){b(this,n,{required:true})}validateOn(n){if(typeof n==="object"&&n!==null){const t={};if(typeof n.onCreate==="function"){t.onCreate=n.onCreate}if(typeof n.onSelect==="function"){t.onSelect=n.onSelect}l(this,"_on",t)}}validateSelected(n){r(this,"_selected",n,{hooks:{beforePatch:this.syncSelectedAndTabs}})}validateTabs(n){c(this,"_tabs",(n=>typeof n==="object"&&n!==null&&typeof n._label==="string"&&n._label.length>0),n,undefined,{hooks:{beforePatch:this.syncSelectedAndTabs,afterPatch:this.refreshTabPanels}});h("KolTabs",this.state._tabs.length)}componentWillLoad(){this.validateAlign(this._align);this.validateLabel(this._label);this.validateOn(this._on);this.validateSelected(this._selected);this.validateTabs(this._tabs);this.validateBehavior(this._behavior);this.validateHasCreateButton(this._hasCreateButton)}componentDidRender(){this.refreshTabPanels()}focusTabById(n){if(this.tabPanelsElement){const t=d(`button#${this.state._label.replace(/\s/g,"-")}-tab-${n}`,this.tabPanelsElement);t===null||t===void 0?void 0:t.focus()}}onSelect(n,t){var e,o;(o=(e=this._on)===null||e===void 0?void 0:e.onSelect)===null||o===void 0?void 0:o.call(e,n,t);if(this.host){w(this.host,_.select,t)}this.focusTabById(t)}get host(){return e(this)}static get watchers(){return{_align:["validateAlign"],_behavior:["validateBehavior"],_hasCreateButton:["validateHasCreateButton"],_label:["validateLabel"],_on:["validateOn"],_selected:["validateSelected"],_tabs:["validateTabs"]}}};o([g("ctaRef")],j.prototype,"focus",null);o([y("ctaRef")],j.prototype,"click",null);j.style={default:C};export{j as kol_tabs}; //# sourceMappingURL=kol-tabs.entry.js.map