class CustomCard extends HTMLElement { static get observedAttributes() { return ['title', 'icon', 'color']; } constructor() { super(); this.title = this.getAttribute('title') || 'Titre de la carte'; this.icon = this.getAttribute('icon') || 'info'; this.color = this.getAttribute('color') || 'primary'; } connectedCallback() { this.attachShadow({ mode: 'open' }); this.render(); this.initInteractions(); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) { this[name] = newValue; this.render(); } } getColorScheme() { const schemes = { primary: { bg: 'rgba(46, 125, 50, 0.1)', border: 'rgba(46, 125, 50, 0.3)', gradient: 'linear-gradient(135deg, rgba(46, 125, 50, 0.2), rgba(76, 175, 80, 0.1))', icon: '#4CAF50' }, secondary: { bg: 'rgba(33, 150, 243, 0.1)', border: 'rgba(33, 150, 243, 0.3)', gradient: 'linear-gradient(135deg, rgba(33, 150, 243, 0.2), rgba(21, 101, 192, 0.1))', icon: '#2196F3' }, accent: { bg: 'rgba(0, 191, 165, 0.1)', border: 'rgba(0, 191, 165, 0.3)', gradient: 'linear-gradient(135deg, rgba(0, 191, 165, 0.2), rgba(0, 150, 136, 0.1))', icon: '#00BFA5' } }; return schemes[this.color] || schemes.primary; } render() { const colors = this.getColorScheme(); this.shadowRoot.innerHTML = `

${this.title}

`; // Initialiser les icônes Feather if (typeof feather !== 'undefined') { feather.replace(); } } initInteractions() { const card = this.shadowRoot.querySelector('.card'); const learnMoreBtn = this.shadowRoot.querySelector('#learnMore'); // Animation d'entrée setTimeout(() => { card.style.opacity = '0'; card.style.transform = 'translateY(20px)'; card.style.transition = 'all 0.6s ease'; setTimeout(() => { card.style.opacity = '1'; card.style.transform = 'translateY(0)'; }, 100); }, 100); // Bouton "En savoir plus" if (learnMoreBtn) { learnMoreBtn.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('card-action', { detail: { action: 'learn-more', title: this.title, color: this.color }, bubbles: true, composed: true })); // Animation de clic learnMoreBtn.style.transform = 'scale(0.95)'; setTimeout(() => { learnMoreBtn.style.transform = ''; }, 150); }); } // Effets de survol card.addEventListener('mouseenter', () => { const icon = this.shadowRoot.querySelector('.card-icon i'); if (icon) { icon.style.transform = 'rotate(15deg) scale(1.1)'; icon.style.transition = 'transform 0.3s ease'; } }); card.addEventListener('mouseleave', () => { const icon = this.shadowRoot.querySelector('.card-icon i'); if (icon) { icon.style.transform = 'rotate(0) scale(1)'; } }); // Gestion des tags const tags = this.shadowRoot.querySelectorAll('.card-tag'); tags.forEach(tag => { tag.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('tag-click', { detail: { tag: tag.textContent }, bubbles: true, composed: true })); }); }); } } customElements.define('custom-card', CustomCard);