@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.84 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{watch as s,initial as t}from"../../../core/reactiveUtils.js";import{property as r,subclass as o}from"../../../core/accessorSupport/decorators.js";import i from"../../Widget.js";import{css as n}from"./css.js";import{loadCalciteComponents as a}from"../../support/componentsUtils.js";import{globalCss as h}from"../../support/globalCss.js";import{tsx as l}from"../../support/widget.js";const c={nextPhase:"nextPhase",previousPhase:"previousPhase"};let u=class extends i{constructor(e,s){super(e,s),this._phasesContainer=null,this._shouldScrollCurrentPhaseIntoView=!0,this._shouldFocusCurrentPhase=!1,this._onKeyDown=e=>{const{vm:s}=this;switch(e.key){case"ArrowDown":case"ArrowLeft":e.stopPropagation(),e.preventDefault(),s.previous(),this._shouldFocusCurrentPhase=!0;break;case"ArrowUp":case"ArrowRight":e.stopPropagation(),e.preventDefault(),s.next(),this._shouldFocusCurrentPhase=!0}},this._onArrowLeftClick=()=>{this.vm.previous()},this._onArrowRightClick=()=>{this.vm.next()},this._onPhasesContainerAfterCreate=e=>{this._phasesContainer=e,requestAnimationFrame(this._scrollOrFocusPhase)},this._scrollOrFocusPhase=()=>{const e=this._phasesContainer;if(this.destroyed||null==e)return;const s=e.querySelector(`.${n.phaseCurrent}`);if(s){if(this._shouldScrollCurrentPhaseIntoView){const t=e.offsetWidth,r=s.offsetLeft,o=s.offsetWidth;e.scrollLeft=-t/2+r+o/2,this._shouldScrollCurrentPhaseIntoView=!1}this._shouldFocusCurrentPhase&&(s.focus(),this._shouldFocusCurrentPhase=!1)}}}loadDependencies(){return a({action:()=>import("@esri/calcite-components/dist/components/calcite-action")})}initialize(){this.addHandles([s(()=>[this._currentPhase,this._phasesContainer,this.container],()=>{this._shouldScrollCurrentPhaseIntoView=!0,requestAnimationFrame(this._scrollOrFocusPhase)},t),s(()=>({container:this.container,numPhases:this._phases.length}),({container:e,numPhases:s})=>{e&&e.style.setProperty("--num-phases",String(s))},t)])}get _phases(){return this.vm.allowedValues}get _currentPhase(){const{vm:e}=this;return e.enabled?e.value:null}render(){if(this._phases.length<2)return l("div",{key:"no-phases"});const{vm:e,messages:s}=this,{previousPhase:t,nextPhase:r}=s??c;return l("div",{class:this.classes(h.widget,n.base),key:this,onkeydown:this._onKeyDown},p({className:n.arrowLeft,disabled:!e.hasPrevious,icon:"chevron-left",onClick:this._onArrowLeftClick,text:t}),l("div",{afterCreate:this._onPhasesContainerAfterCreate,class:n.phasesContainer},this._renderPhaseButtons()),p({className:n.arrowRight,disabled:!e.hasNext,icon:"chevron-right",onClick:this._onArrowRightClick,text:r}))}_renderPhaseButtons(){const e=this._phases,s=this._currentPhase,t=[];for(let r=0;r<e.length;++r){const o=e[r],i={phase:o,active:null!=s&&o<=s,current:null!=s&&o===s};r>0&&t.push(this._renderDivider(i)),t.push(this._renderPhaseButton(i))}return t}_renderPhaseButton({phase:e,active:s,current:t}){const{vm:r}=this,o=r.getValueLabel(e);return l("button",{"aria-label":o,class:this.classes(n.phase,{[n.phaseActive]:s,[n.phaseCurrent]:t}),key:`phase-${e}`,onclick:()=>r.select(e),title:o,type:"button"},e)}_renderDivider({phase:e,active:s}){return l("div",{class:this.classes(n.divider,{[n.dividerActive]:s}),key:`phase-divider-${e}`})}};function p(e){return l("calcite-action",{class:e.className,disabled:e.disabled,icon:e.icon,iconFlipRtl:!0,key:e.className,onclick:e.onClick,scale:"s",text:e.text,textEnabled:!1,title:e.text})}e([r({nonNullable:!0})],u.prototype,"vm",void 0),e([r()],u.prototype,"messages",void 0),e([r()],u.prototype,"_phases",null),e([r()],u.prototype,"_currentPhase",null),e([r()],u.prototype,"_phasesContainer",void 0),u=e([o("esri.widgets.BuildingExplorer.BuildingPhasePicker.BuildingPhasePicker")],u);const d=u;export{d as default};