@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
5 lines (4 loc) • 7.68 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{d as b}from"./CKRTMNFR.js";import{a as x}from"./NNVH7JUI.js";import{E as u,F as l,G as z,I as k,R as y,c as h,d as r,e as p,h as f}from"./BJZTU5BQ.js";var a={percentage:"percentage",progressRing:"ring--progress",ring:"ring",rings:"rings",text:"text",trackRing:"ring--track"},w=h`:host{position:relative;margin-inline:auto;display:flex;align-items:center;justify-content:center;opacity:1;flex-direction:column;min-block-size:var(--calcite-loader-size);font-size:var(--calcite-loader-font-size);stroke-width:var(--calcite-internal-stroke-width);fill:none;transform:scale(1);padding-block:var(--calcite-loader-spacing, 4rem)}:host([scale=s]){--calcite-internal-stroke-width: 3;--calcite-internal-text-offset: var(--calcite-spacing-xxs);--calcite-internal-loader-font-size: var(--calcite-font-size--3);--calcite-internal-loader-size: 2rem;--calcite-internal-loader-size-inline: .75rem;--calcite-internal-loader-value-line-height: .625rem}:host([scale=m]){--calcite-internal-stroke-width: 6;--calcite-internal-text-offset: var(--calcite-spacing-sm);--calcite-internal-loader-font-size: var(--calcite-font-size-0);--calcite-internal-loader-size: 4rem;--calcite-internal-loader-size-inline: 1rem;--calcite-internal-loader-value-line-height: 1.375rem}:host([scale=l]){--calcite-internal-stroke-width: 8;--calcite-internal-text-offset: var(--calcite-spacing-md);--calcite-internal-loader-font-size: var(--calcite-font-size-2);--calcite-internal-loader-size: 6rem;--calcite-internal-loader-size-inline: 1.5rem;--calcite-internal-loader-value-line-height: 1.71875rem}.text{display:block;text-align:center;font-size:var(--calcite-font-size--2);line-height:1rem;margin-block-start:var(--calcite-loader-text-spacing, var(--calcite-internal-text-offset));font-weight:var(--calcite-loader-text-weight, var(--calcite-font-weight-normal));color:var(--calcite-loader-text-color, var(--calcite-color-text-1))}.percentage{display:block;text-align:center;font-size:var(--calcite-loader-font-size);inline-size:var(--calcite-loader-size, var(--calcite-internal-loader-size));line-height:var(--calcite-internal-loader-value-line-height);align-self:center;color:var(--calcite-loader-text-color, var(--calcite-color-text-1))}.rings{position:relative;display:flex;overflow:visible;opacity:1;inline-size:var(--calcite-loader-size, var(--calcite-internal-loader-size));block-size:var(--calcite-loader-size, var(--calcite-internal-loader-size))}.ring{position:absolute;inset-block-start:0px;transform-origin:center;overflow:visible;inset-inline-start:0;inline-size:var(--calcite-loader-size, var(--calcite-internal-loader-size));block-size:var(--calcite-loader-size, var(--calcite-internal-loader-size))}.ring--track{stroke:var(--calcite-loader-track-color, var(--calcite-color-transparent-press))}.ring--progress{stroke:var(--calcite-loader-progress-color, var(--calcite-color-brand));transform:rotate(-90deg);transition:all var(--calcite-internal-animation-timing-fast) linear}:host([type=indeterminate]) .ring--progress{animation:loader-clockwise calc(var(--calcite-internal-animation-timing-slow) / var(--calcite-internal-duration-factor) * 2 / var(--calcite-internal-duration-factor)) linear infinite}:host([inline]){--calcite-internal-stroke-width: 2;position:relative;margin:0;stroke:currentColor;stroke-width:2;padding-block:0px;block-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)));min-block-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)));inline-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)));vertical-align:calc(var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline))) * -1 * .2)}:host([inline]) .rings{inset-block-start:0px;margin:0;inset-inline-start:0;inline-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)));block-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)))}:host([inline]) .ring{inline-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)));block-size:var(--calcite-loader-size, var(--calcite-loader-size-inline, var(--calcite-internal-loader-size-inline)))}:host([inline]) .ring--progress{stroke:var(--calcite-loader-progress-color-inline, currentColor)}:host([complete]){opacity:0;transform:scale(.75);transform-origin:center;transition:opacity var(--calcite-internal-animation-timing-medium) linear 1s,transform var(--calcite-internal-animation-timing-medium) linear 1s}:host([complete]) .rings{opacity:0;transform:scale(.75);transform-origin:center;transition:opacity calc(.18s * var(--calcite-internal-duration-factor)) linear .8s,transform calc(.18s * var(--calcite-internal-duration-factor)) linear .8s}:host([complete]) .percentage{color:var(--calcite-color-brand);transform:scale(1.05);transform-origin:center;transition:color var(--calcite-internal-animation-timing-medium) linear,transform var(--calcite-internal-animation-timing-medium) linear} loader-clockwise{0%{transform:rotate(0)}to{transform:rotate(360deg)}}:host([hidden]){display:none}[hidden]{display:none}`,m=class extends u{constructor(){super(...arguments),this.messages=b({name:null}),this.complete=!1,this.inline=!1,this.scale="m",this.text="",this.type="indeterminate",this.value=0}static{this.properties={complete:[7,{},{reflect:!0,type:Boolean}],inline:[7,{},{reflect:!0,type:Boolean}],label:1,scale:[3,{},{reflect:!0}],text:1,type:[3,{},{reflect:!0}],value:[9,{},{type:Number}]}}static{this.styles=w}connectedCallback(){super.connectedCallback(),this.updateFormatter()}load(){requestAnimationFrame(()=>this.valueChangeHandler())}willUpdate(e){e.has("value")&&(this.hasUpdated||this.value!==0)&&this.valueChangeHandler(),(e.has("type")&&(this.hasUpdated||this.type!=="indeterminate")||e.has("messages"))&&this.updateFormatter()}valueChangeHandler(){this.complete=this.type.startsWith("determinate")&&this.value===100}formatValue(){return this.type!=="determinate-value"?`${this.value}`:this.formatter.format(this.value/100)}getSize(e){return{s:32,m:64,l:96}[e]}getInlineSize(e){return{s:12,m:16,l:24}[e]}updateFormatter(){this.type!=="determinate-value"||this.formatter?.resolvedOptions().locale===this.messages._lang||(this.formatter=new Intl.NumberFormat(this.messages._lang,{style:"percent"}))}render(){let{el:e,inline:n,label:s,text:c,type:i,value:v}=this,o=e.id||x(),t=i!=="indeterminate",d=Math.floor(v);return this.el.ariaLabel=s,this.el.ariaValueMax=t?"100":void 0,this.el.ariaValueMin=t?"0":void 0,this.el.ariaValueNow=t?d.toString():void 0,k(this.el,"id",o),this.el.role="progressbar",r`<div class=${l(a.rings)}>${this.renderRing("track")}${this.renderRing("progress")}${!n&&t&&r`<div class=${l(a.percentage)}>${this.formatValue()}</div>`||""}</div>${!n&&c&&r`<div class=${l(a.text)}>${c}</div>`||""}`}renderRing(e){let{inline:n,scale:s,value:c}=this,i=n?this.getInlineSize(s):this.getSize(s),o=i*.45,t;if(e==="progress"){let d=2*o*Math.PI,g=(this.type.startsWith("determinate")?c:24)/100*d,$=d-g;t={"stroke-dasharray":`${g} ${$}`}}return r`<svg aria-hidden=true class=${l({[a.ring]:!0,[a.trackRing]:e==="track",[a.progressRing]:e==="progress"})} style=${z(t)} viewBox=${`0 0 ${i} ${i}`}>${p`<circle cx=${i/2} cy=${i/2} r=${o??f} />`}</svg>`}};y("calcite-loader",m);export{m as Loader};