taskforge-pro / components /tag-item.js
Fadikkop's picture
Promote version 4549c0d to main
a12aab2 verified
// Tag Item Component
class TagItem extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.render();
this.setupEventListeners();
}
static get observedAttributes() {
return ['tag-id', 'tag-name', 'tag-color'];
}
attributeChangedCallback() {
this.render();
}
render() {
const tagName = this.getAttribute('tag-name') || '';
const tagColor = this.getAttribute('tag-color') || '#f97316';
const tagId = this.getAttribute('tag-id') || '';
this.shadowRoot.innerHTML = `
<style>
:host {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
border-radius: 16px;
font-size: 14px;
font-weight: 500;
transition: all 0.2s ease;
}
.tag-content {
background-color: ${tagColor}20;
color: ${tagColor};
padding: 4px 12px;
border-radius: 16px;
display: flex;
align-items: center;
gap: 6px;
}
.tag-name {
user-select: none;
}
.delete-btn {
background: none;
border: none;
color: inherit;
cursor: pointer;
padding: 2px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.delete-btn:hover {
background-color: rgba(0, 0, 0, 0.1);
transform: scale(1.1);
}
.delete-btn i {
width: 14px;
height: 14px;
}
</style>
<div class="tag-content">
<span class="tag-name">${tagName}</span>
<button class="delete-btn" @click="${this.handleDelete}">
<i data-feather="x"></i>
</button>
</div>
`;
// Replace feather icon
const iconEl = this.shadowRoot.querySelector('i[data-feather]');
if (iconEl) {
iconEl.outerHTML = feather.icons.x.toSvg({ width: 14, height: 14 });
}
}
setupEventListeners() {
this.shadowRoot.addEventListener('click', (e) => {
const deleteBtn = e.target.closest('.delete-btn');
if (deleteBtn) {
e.stopPropagation();
this.handleDelete(e);
}
});
}
handleDelete(e) {
if (confirm('Tag wirklich löschen?')) {
this.dispatchEvent(new CustomEvent('delete', {
bubbles: true,
detail: { tagId: this.getAttribute('tag-id') }
}));
}
}
}
customElements.define('tag-item', TagItem);