Spaces:
Running

volatilitybot-pro / components /stats-card.js
Fraqim's picture
Add martingale 0.5 incase of a loss to recover
fab03ee verified
Raw History Blame Contribute Delete
4.47 kB
class CustomStatsCard extends HTMLElement {
static get observedAttributes() {
return ['title', 'value', 'icon', 'color'];
}
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
attributeChangedCallback(name, oldValue, newValue) {
this.render();
}
connectedCallback() {
this.render();
}
render() {
const title = this.getAttribute('title') || 'Title';
const value = this.getAttribute('value') || '0';
const icon = this.getAttribute('icon') || 'activity';
const color = this.getAttribute('color') || 'primary';
const colorClasses = {
primary: 'from-primary-500 to-primary-600 shadow-primary-500/25',
secondary: 'from-secondary-500 to-secondary-600 shadow-secondary-500/25',
blue: 'from-blue-500 to-blue-600 shadow-blue-500/25',
emerald: 'from-emerald-500 to-emerald-600 shadow-emerald-500/25',
rose: 'from-rose-500 to-rose-600 shadow-rose-500/25'
};
const iconColors = {
primary: 'text-primary-400',
secondary: 'text-secondary-400',
blue: 'text-blue-400',
emerald: 'text-emerald-400',
rose: 'text-rose-400'
};
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
}
.card {
background: rgba(30, 41, 59, 0.6);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.05);
transition: all 0.3s ease;
}
.card:hover {
transform: translateY(-2px);
border-color: rgba(99, 102, 241, 0.3);
box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
}
.icon-box {
background: linear-gradient(135deg, ${color === 'primary' ? '#6366f1' : color === 'secondary' ? '#10b981' : color === 'blue' ? '#3b82f6' : color === 'emerald' ? '#10b981' : '#f43f5e'}20, transparent);
}
.value-text {
font-variant-numeric: tabular-nums;
}
</style>
<div class="card rounded-2xl p-5 relative overflow-hidden">
<div class="absolute top-0 right-0 w-32 h-32 bg-gradient-to-br ${colorClasses[color]} opacity-5 rounded-full blur-3xl -mr-16 -mt-16"></div>
<div class="flex items-start justify-between relative z-10">
<div>
<p class="text-slate-400 text-sm font-medium mb-1">${title}</p>
<h3 class="text-2xl font-bold text-white value-text tracking-tight">${value}</h3>
</div>
<div class="icon-box w-10 h-10 rounded-xl flex items-center justify-center ${iconColors[color]}">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
${this.getIconPath(icon)}
</svg>
</div>
</div>
<div class="mt-4 flex items-center gap-2">
<span class="text-xs text-slate-500">Updated just now</span>
<div class="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></div>
</div>
</div>
`;
}
getIconPath(icon) {
const icons = {
'dollar-sign': '<line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path>',
'trending-up': '<polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline><polyline points="17 6 23 6 23 12"></polyline>',
'activity': '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline>',
'bar-chart-2': '<line x1="18" y1="20" x2="18" y2="10"></line><line x1="12" y1="20" x2="12" y2="4"></line><line x1="6" y1="20" x2="6" y2="14"></line>',
'user': '<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle>'
};
return icons[icon] || icons['activity'];
}
}
customElements.define('custom-stats-card', CustomStatsCard);