File size: 2,283 Bytes
bc2f68f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | class ProgressItem extends HTMLElement {
static get observedAttributes() {
return ['label', 'value', 'progress'];
}
attributeChangedCallback(name, oldValue, newValue) {
if (this.shadowRoot) {
this.render();
}
}
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.render();
}
render() {
const label = this.getAttribute('label') || '';
const value = this.getAttribute('value') || '0%';
const progress = parseInt(this.getAttribute('progress') || '0');
this.shadowRoot.innerHTML = `
<style>
.progress-item {
display: flex;
flex-direction: column;
}
.progress-header {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
}
.progress-label {
font-size: 0.875rem;
color: #64748B;
}
.progress-value {
font-size: 0.875rem;
font-weight: 600;
color: #1E293B;
}
.progress-bar {
height: 6px;
background-color: #E2E8F0;
border-radius: 3px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 3px;
background-color: #4F46E5;
transition: width 0.5s ease-out;
}
</style>
<div class="progress-item fade-in">
<div class="progress-header">
<span class="progress-label">${label}</span>
<span class="progress-value">${value}</span>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${progress}%"></div>
</div>
</div>
`;
}
}
customElements.define('progress-item', ProgressItem); |