UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.18 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import{watch as s,initial as t}from"../../../core/reactiveUtils.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as o}from"../../../core/accessorSupport/decorators/subclass.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"../../support/widgetUtils.js";import{tsx as c}from"../../support/jsxFactory.js";const l={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 c("div",{key:"no-phases"});const{vm:e,messages:s}=this,{previousPhase:t,nextPhase:r}=s??l;return c("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}),c("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 c("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 c("div",{class:this.classes(n.divider,{[n.dividerActive]:s}),key:`phase-divider-${e}`})}};function p(e){return c("calcite-action",{appearance:"transparent",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};