Retese's picture
Make a clone of Toolsvana.com.
b8048e2 verified
Raw History Blame Contribute Delete
2.2 kB
class ToolCard extends HTMLElement {
static get observedAttributes() {
return ['title', 'description', 'icon', 'category', 'link'];
}
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.render();
}
attributeChangedCallback(name, oldValue, newValue) {
this.render();
}
render() {
const title = this.getAttribute('title') || 'Tool Name';
const description = this.getAttribute('description') || 'Tool description goes here';
const icon = this.getAttribute('icon') || 'tool';
const category = this.getAttribute('category') || 'Category';
const link = this.getAttribute('link') || '#';
this.shadowRoot.innerHTML = `
<style>
.card {
transition: all 0.2s ease;
}
.card:hover {
transform: translateY(-4px);
}
.card-icon {
background-color: #EFF6FF;
}
.card-badge {
background-color: #F0FDF4;
color: #16A34A;
}
</style>
<a href="${link}" class="card block bg-white rounded-lg overflow-hidden shadow-tool hover:shadow-tool-hover transition-all fade-in">
<div class="p-6">
<div class="card-icon w-12 h-12 rounded-lg flex items-center justify-center mb-4">
<i data-feather="${icon}" class="text-blue-600"></i>
</div>
<h3 class="text-xl font-semibold text-gray-800 mb-2">${title}</h3>
<p class="text-gray-600 mb-4">${description}</p>
<span class="card-badge text-sm font-medium px-3 py-1 rounded-full inline-block">
${category}
</span>
</div>
</a>
`;
// Replace feather icons after rendering
if (this.shadowRoot.querySelector('[data-feather]')) {
feather.replace();
}
}
}
customElements.define('tool-card', ToolCard);