Spaces:
Running
Running
File size: 3,442 Bytes
1235104 | 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 75 76 77 78 79 80 81 82 83 84 85 | class CustomThreadCard extends HTMLElement {
static get observedAttributes() {
return ['title', 'author', 'date', 'comments', 'likes', 'tags', 'category'];
}
connectedCallback() {
this.render();
}
attributeChangedCallback() {
this.render();
}
render() {
const title = this.getAttribute('title') || 'Untitled Thread';
const author = this.getAttribute('author') || 'Anonymous';
const date = this.getAttribute('date') || 'Just now';
const comments = this.getAttribute('comments') || '0';
const likes = this.getAttribute('likes') || '0';
const tags = this.getAttribute('tags') || '';
const category = this.getAttribute('category') || 'General';
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.card {
transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}
.tag {
transition: background-color 0.2s;
}
.tag:hover {
background-color: #e0e7ff;
}
.category-badge {
position: absolute;
top: -10px;
right: 10px;
}
</style>
<div class="card bg-white rounded-lg shadow p-4 relative">
<div class="category-badge bg-indigo-600 text-white text-xs px-2 py-1 rounded-full">
${category}
</div>
<h3 class="text-lg font-semibold mb-2">${title}</h3>
<div class="flex items-center text-sm text-gray-500 mb-3">
<span>Posted by <span class="font-medium">${author}</span></span>
<span class="mx-2">•</span>
<span>${date}</span>
</div>
<div class="flex flex-wrap gap-2 mb-4">
${tags.split(',').map(tag => `
<span class="tag bg-indigo-100 text-indigo-800 text-xs px-2 py-1 rounded">${tag.trim()}</span>
`).join('')}
</div>
<div class="flex justify-between items-center">
<div class="flex space-x-4">
<div class="flex items-center text-gray-500 text-sm">
<i data-feather="message-square" class="mr-1 w-4 h-4"></i>
${comments} comments
</div>
<div class="flex items-center text-gray-500 text-sm">
<i data-feather="thumbs-up" class="mr-1 w-4 h-4"></i>
${likes} likes
</div>
</div>
<button class="text-indigo-600 hover:text-indigo-800 text-sm font-medium flex items-center">
<i data-feather="chevron-right" class="mr-1 w-4 h-4"></i>
View Thread
</button>
</div>
</div>
`;
}
}
customElements.define('custom-thread-card', CustomThreadCard); |