@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
5 lines (4 loc) • 4.29 kB
JavaScript
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details.
v3.2.1 */
import{a as h}from"./M7EAHGE3.js";import{b as u}from"./5RDOSP2E.js";import{B as p}from"./3ADX47DD.js";import{d as w}from"./HPN2C7M6.js";import"./JOSABGK6.js";import"./NNVH7JUI.js";import{E as d,F as m,R as f,c,d as l}from"./BJZTU5BQ.js";var n={frame:"frame",frameAdvancing:"frame--advancing",frameRetreating:"frame--retreating"},g=c`:host{box-sizing:border-box;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-2);font-size:var(--calcite-font-size--1)}:host *{box-sizing:border-box}:host{position:relative;display:flex;inline-size:100%;flex:1 1 auto;align-items:stretch;overflow:hidden;background-color:transparent}:host .frame{position:relative;margin:0;display:flex;inline-size:100%;flex:1 1 auto;flex-direction:column;align-items:stretch;padding:0;animation-name:none;animation-duration:var(--calcite-animation-timing);background-color:var(--calcite-flow-background-color)}:host ::slotted(*){display:none;block-size:100%}:host ::slotted(*[selected]){display:flex}:host ::slotted(.calcite-match-height:last-child){display:flex;flex:1 1 auto;overflow:hidden}:host .frame--advancing{animation-name:calcite-frame-advance}:host .frame--retreating{animation-name:calcite-frame-retreat} calcite-frame-advance{0%{--tw-bg-opacity: .5;transform:translate3d(50px,0,0)}to{--tw-bg-opacity: 1;transform:translateZ(0)}} calcite-frame-retreat{0%{--tw-bg-opacity: .5;transform:translate3d(-50px,0,0)}to{--tw-bg-opacity: 1;transform:translateZ(0)}}:host([hidden]){display:none}[hidden]{display:none}`,o=class extends d{constructor(){super(),this.itemMutationObserver=h("mutation",()=>this.updateItemsAndProps()),this.items=[],this.selectedIndex=-1,this.flowDirection="standby",this.listen("calciteInternalFlowItemChange",this.handleCalciteInternalFlowItemChange),this.listen("calciteFlowItemBack",this.handleItemBackClick)}static{this.properties={flowDirection:[16,{},{state:!0}],customItemSelectors:1}}static{this.styles=g}async back(){let{items:e,selectedIndex:i}=this,t=e[i],s=e[i-1];if(!t||!s)return;let a=t.beforeBack?t.beforeBack:()=>Promise.resolve();try{await a.call(t)}catch{return}return t.selected=!1,s.selected=!0,s}async setFocus(){await w(this);let{items:e}=this;return e[this.selectedIndex]?.setFocus()}connectedCallback(){super.connectedCallback(),this.itemMutationObserver?.observe(this.el,{childList:!0,subtree:!0})}willUpdate(e){e.has("flowDirection")&&(this.hasUpdated||this.flowDirection!=="standby")&&this.handleFlowDirectionChange(this.flowDirection)}loaded(){this.updateItemsAndProps()}disconnectedCallback(){super.disconnectedCallback(),this.itemMutationObserver?.disconnect()}async handleFlowDirectionChange(e){e!=="standby"&&(await p(this.frameEl,e==="retreating"?"calcite-frame-retreat":"calcite-frame-advance"),this.resetFlowDirection())}handleCalciteInternalFlowItemChange(e){e.stopPropagation(),this.updateFlowProps()}async handleItemBackClick(e){if(!e.defaultPrevented)return await this.back(),this.setFocus()}resetFlowDirection(){this.flowDirection="standby"}getFlowDirection(e,i){let t=e>0;return!(e>-1&&i>0)&&!t?"standby":i<e?"retreating":"advancing"}updateItemsAndProps(){let{customItemSelectors:e,el:i}=this,t=Array.from(i.querySelectorAll(`calcite-flow-item${e?`,${e}`:""}`)).filter(s=>s.closest("calcite-flow")===i);this.items=t,this.ensureSelectedFlowItemExists(),this.updateFlowProps()}updateFlowProps(){let{selectedIndex:e,items:i}=this,t=this.findSelectedFlowItemIndex(i);i.forEach((s,a)=>{let r=a===t;r||(s.menuOpen=!1),s.showBackButton=r&&t>0}),t!==-1&&(e!==t&&(this.flowDirection=this.getFlowDirection(e,t)),this.selectedIndex=t)}findSelectedFlowItemIndex(e){let i=e.slice(0).reverse().find(t=>!!t.selected);return e.indexOf(i)}ensureSelectedFlowItemExists(){let{items:e}=this;if(this.findSelectedFlowItemIndex(e)!==-1)return;let t=e[e.length-1];t&&(t.selected=!0)}setFrameEl(e){this.frameEl=e}render(){let{flowDirection:e}=this,i={[n.frame]:!0,[n.frameAdvancing]:e==="advancing",[n.frameRetreating]:e==="retreating"};return l`<div class=${m(i)} ${u(this.setFrameEl)}><slot></slot></div>`}};f("calcite-flow",o);export{o as Flow};