UNPKG

@sandlada/mdc

Version:

@sandlada/mdc is an open source component library that follows the Material Design 3 design specifications.

11 lines 3.68 kB
import{property as e}from"../../../node_modules/@lit/reactive-element/decorators/property.js";import{query as t}from"../../../node_modules/@lit/reactive-element/decorators/query.js";import"../../../node_modules/lit/decorators.js";import{html as n,nothing as r}from"../../../node_modules/lit-html/lit-html.js";import{LitElement as i}from"../../../node_modules/lit-element/lit-element.js";import"../../../node_modules/lit/index.js";import{classMap as a}from"../../../node_modules/lit-html/directives/class-map.js";import"../../../node_modules/lit/directives/class-map.js";import{mixinElementInternals as o}from"../../../utils/behaviors/element-internals.js";import{composeMixin as s}from"../../../utils/compose-mixin/compose-mixin.js";import c from"../../../_virtual/_@oxc-project_runtime@0.144.0/helpers/esm/decorate.js";import{mixinDelegatesAria as l}from"../../../utils/aria/delegate.js";import{mixinFocusRingOptions as u}from"../../focus-ring/focus-ring-options.mixin.js";import{mixinRippleOptions as d}from"../../ripple/ripple-options.mixin.js"; /** * @license * Copyright 2026 Kai-Orion & Sandlada * SPDX-License-Identifier: MIT * * @fileoverview * Internal base class for `mdc-on-this-page-item` — an in-page navigation link item. */ const f=Symbol(`onThisPageItemRequestActivate`);var p=class extends s(l,o,d,u)(i){static{this.shadowRootOptions={...i.shadowRootOptions,delegatesFocus:!0}}get rippleControl(){return this.disabled?null:this.itemElement}get focusRingControl(){return this.disabled?null:this.itemElement}constructor(){super(),this.href=``,this.target=``,this.label=``,this.active=!1,this.disabled=!1,this.level=1,this.index=0,this.handleClick=e=>{if(this.disabled){e.preventDefault(),e.stopImmediatePropagation();return}let t=new CustomEvent(`mdc-on-this-page-item-click`,{bubbles:!0,composed:!0,cancelable:!0,detail:{item:this}});this.dispatchEvent(t)||e.preventDefault()},this.handleKeyDown=e=>{(e.key===` `||e.key===`Spacebar`)&&(e.preventDefault(),this.itemElement?.click())},this.focusRingInward=!0}get targetId(){if(this.target)return this.target;if(this.href){let e=this.href.indexOf(`#`);return e===-1?this.href:decodeURIComponent(this.href.slice(e+1))}return``}getItemBounds(){return this.itemElement?.getBoundingClientRect()??this.getBoundingClientRect()}getLabelBounds(){return this.labelElement?.getBoundingClientRect()??this.getItemBounds()}getRenderClasses(){return{item:!0,active:this.active,disabled:this.disabled,[`level-${this.level}`]:this.level>1}}render(){let e=this.href?this.href.startsWith(`#`)?this.href:`#${this.href}`:void 0;return n`<a class="${a(this.getRenderClasses())}" href="${e??r}" role="link" aria-current="${this.active?`true`:r}" aria-disabled="${this.disabled?`true`:r}" tabindex="${this.disabled?-1:0}" @click="${this.handleClick}" @keydown="${this.handleKeyDown}">${this.renderFocusRing()} ${this.renderRipple()} <span class="label" part="label"><slot>${this.label}</slot></span></a>`}updated(e){super.updated(e),e.has(`active`)&&this.setAttribute(`aria-current`,this.active?`true`:`false`)}};c([e({type:String,reflect:!0})],p.prototype,`href`,void 0),c([e({type:String,reflect:!0})],p.prototype,`target`,void 0),c([e({type:String})],p.prototype,`label`,void 0),c([e({type:Boolean,reflect:!0})],p.prototype,`active`,void 0),c([e({type:Boolean,reflect:!0})],p.prototype,`disabled`,void 0),c([e({type:Number,reflect:!0})],p.prototype,`level`,void 0),c([e({type:Number})],p.prototype,`index`,void 0),c([t(`.item`)],p.prototype,`itemElement`,void 0),c([t(`.label`)],p.prototype,`labelElement`,void 0);export{p as BaseOnThisPageItem,f as ON_THIS_PAGE_ITEM_REQUEST_ACTIVATE}; //# sourceMappingURL=base-on-this-page-item.js.map