@postnord/web-components
Version:
PostNord Web Components
5 lines • 3.71 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import{t as r,r as e,g as s,h as a,a as t}from"./p-CAEP792y.js";import{a as i}from"./p-B88w-Zxn.js";import{c as o}from"./p-D4GZ__oQ.js";import{uuidv4 as n}from"./index.esm.js";const d=class{constructor(r){e(this,r)}uniqueId=n();idProgress=`pn-progress-bar-${this.uniqueId}`;idLabel=`${this.idProgress}-label`;idText=`${this.idProgress}-text`;get hostElement(){return s(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()?i:o}getIconColor(){return this.hasError()?"warning":"green500"}render(){return a(t,{key:"141fef1da768dc423cf53dfa8088f1b98429236c"},this.hasLabel()&&a("p",{key:"294199499037e6ed0e816f8a68850dfede795884",id:this.idLabel,class:"pn-progress-bar-label"},a("span",{key:"f292e951e29878d186b7f7896d7346fd41677006"},this.label),this.hasIcon()&&a("pn-icon",{key:"47b8065b97a8cd0f0d3e57ea4f68b07ad09c12a5",icon:this.getIconSvg(),color:this.getIconColor()})),a("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},a("div",{key:"51ceae38d589385687dd3e25c86526b4758f2792",class:"pn-progress-bar-meter"},a("div",{key:"714d0aa19a487bf625ae10bcdd68d21d54b6f48a",class:"pn-progress-bar-value","data-error":this.hasError(),"data-valid":this.isValid()}))),a("p",{key:"b540a56c9d7fdfae49f508472d315ce1eeda5e99",id:this.idText,class:"pn-progress-bar-subtext",role:this.hasError()?"alert":null},a("span",{key:"35d515a823d117a6ab31e3cda778a2ada8093233"},this.getSubtext())))}static get watchers(){return{progress:[{setProgress:0}]}}};d.style=`${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}`;export{d as pn_progress_bar}