| class CustomCard extends HTMLElement { | |
| static get observedAttributes() { | |
| return ['title', 'description', 'icon']; | |
| } | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| } | |
| connectedCallback() { | |
| this.render(); | |
| } | |
| attributeChangedCallback() { | |
| this.render(); | |
| } | |
| render() { | |
| const title = this.getAttribute('title') || 'Card Title'; | |
| const description = this.getAttribute('description') || 'Default card description'; | |
| const icon = this.getAttribute('icon') || 'box'; | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| display: block; | |
| } | |
| .card { | |
| background-color: white; | |
| border-radius: 0.5rem; | |
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); | |
| padding: 1.5rem; | |
| transition: all 0.3s ease; | |
| height: 100%; | |
| } | |
| .card:hover { | |
| transform: translateY(-4px); | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); | |
| } | |
| .card-icon { | |
| width: 3rem; | |
| height: 3rem; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| background-color: #e0e7ff; | |
| border-radius: 0.5rem; | |
| margin-bottom: 1rem; | |
| color: #4f46e5; | |
| } | |
| .card-title { | |
| font-size: 1.25rem; | |
| font-weight: 600; | |
| margin-bottom: 0.5rem; | |
| color: #111827; | |
| } | |
| .card-description { | |
| color: #6b7280; | |
| line-height: 1.5; | |
| } | |
| </style> | |
| <div class="card"> | |
| <div class="card-icon"> | |
| <i data-feather="${icon}"></i> | |
| </div> | |
| <h3 class="card-title">${title}</h3> | |
| <p class="card-description">${description}</p> | |
| </div> | |
| `; | |
| } | |
| } | |
| customElements.define('custom-card', CustomCard); |