File size: 3,352 Bytes
a12aab2
 
 
 
 
 
3d9c9a5
a12aab2
 
 
 
eac69cf
a12aab2
 
 
eac69cf
a12aab2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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);