@postnord/web-components
Version:
PostNord Web Components
5 lines • 4.31 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import{transformTag as r,proxyCustomElement as e,HTMLElement as s,h as t,Host as a}from"@stencil/core/internal/client";import{a as o}from"./alert_exclamation_circle.js";import{c as i}from"./check_circle.js";import{u as n}from"./helpers.js";import{d}from"./pn-icon2.js";const p=e(class extends s{constructor(r){super(),!1!==r&&this.__registerHost()}uniqueId=n();idProgress=`pn-progress-bar-${this.uniqueId}`;idLabel=`${this.idProgress}-label`;idText=`${this.idProgress}-text`;get hostElement(){return this}progressPercentage;label;progress=0;progressText;successText;error;progressId=this.idProgress;setProgress(){if(!Number.isInteger(this.progress))return;const r=this.progress<100?Math.ceil(this.progress):100;this.progressPercentage=`${r.toString()}%`,this.hostElement.style.setProperty("--progress-value",this.progressPercentage)}componentWillLoad(){this.setProgress()}hasLabel(){return!!this.label?.length}hasText(){return!!this.successText?.length}hasError(){return!!this.error?.length}isValid(){return 100===this.progress}hasIcon(){return this.isValid()||this.hasError()}getSubtext(){return this.hasError()?this.error:this.isValid()&&this.hasText()?this.successText:this.progressText?this.progressText:this.progressPercentage}getIconSvg(){return this.hasError()?o:i}getIconColor(){return this.hasError()?"warning":"green500"}render(){return t(a,{key:"141fef1da768dc423cf53dfa8088f1b98429236c"},this.hasLabel()&&t("p",{key:"294199499037e6ed0e816f8a68850dfede795884",id:this.idLabel,class:"pn-progress-bar-label"},t("span",{key:"f292e951e29878d186b7f7896d7346fd41677006"},this.label),this.hasIcon()&&t("pn-icon",{key:"47b8065b97a8cd0f0d3e57ea4f68b07ad09c12a5",icon:this.getIconSvg(),color:this.getIconColor()})),t("div",{key:"0dd5189948aad2e501ee10076ed212987a52e4d8",id:this.progressId,class:"pn-progress-bar-container",role:"progressbar","aria-labelledby":this.idLabel,"aria-describedby":this.hasIcon()?this.idText:null,"aria-valuenow":this.progress,"aria-valuetext":this.progressPercentage},t("div",{key:"51ceae38d589385687dd3e25c86526b4758f2792",class:"pn-progress-bar-meter"},t("div",{key:"714d0aa19a487bf625ae10bcdd68d21d54b6f48a",class:"pn-progress-bar-value","data-error":this.hasError(),"data-valid":this.isValid()}))),t("p",{key:"b540a56c9d7fdfae49f508472d315ce1eeda5e99",id:this.idText,class:"pn-progress-bar-subtext",role:this.hasError()?"alert":null},t("span",{key:"35d515a823d117a6ab31e3cda778a2ada8093233"},this.getSubtext())))}static get watchers(){return{progress:[{setProgress:0}]}}static get style(){return`${r("pn-progress-bar")} .pn-progress-bar-label{margin-bottom:0.5em;color:#2d2013;font-weight:500;display:flex;justify-content:space-between;align-items:center;gap:0.5em}${r("pn-progress-bar")} .pn-progress-bar-subtext{margin-top:0.5em;color:#5e554a;font-weight:400}${r("pn-progress-bar")} .pn-progress-bar-container{overflow:hidden;padding:0.0625em;height:0.75em;border-radius:0.5em}${r("pn-progress-bar")} .pn-progress-bar-meter{position:relative;width:100%;background:#f3f2f2;height:0.625em;border-radius:0.5em;box-shadow:0 0 0 0.0625em #969087}${r("pn-progress-bar")} .pn-progress-bar-value{position:absolute;top:-0.0625em;left:-0.0625em;height:0.75em;background-color:#005d92;width:var(--progress-value);border-radius:0.5em 0 0 0.5em;transition-property:width, border-radius, background-color;transition-duration:0.2s, 0.2s, 0.5s;transition-timing-function:linear} (prefers-reduced-motion: reduce){${r("pn-progress-bar")} .pn-progress-bar-value{transition-duration:0s}}${r("pn-progress-bar")} .pn-progress-bar-value[data-valid]{width:calc(var(--progress-value) + 0.125em);background-color:#0aa85c;border-top-right-radius:0.5em;border-bottom-right-radius:0.5em}${r("pn-progress-bar")} .pn-progress-bar-value[data-error]{background-color:#a70707}`}},[512,"pn-progress-bar",{label:[1],progress:[2],progressText:[1,"progress-text"],successText:[1,"success-text"],error:[1],progressId:[1,"progress-id"],progressPercentage:[32]},void 0,{progress:[{setProgress:0}]}]);function c(){"undefined"!=typeof customElements&&["pn-progress-bar","pn-icon"].forEach((e=>{switch(e){case"pn-progress-bar":customElements.get(r(r(e)))||customElements.define(r(r(e)),p);break;case"pn-icon":customElements.get(r(r(e)))||d()}}))}export{p as P,c as d}