Spaces:
Running
Running
| class ProductCard extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| } | |
| connectedCallback() { | |
| const title = this.getAttribute('title') || 'Product'; | |
| const price = this.getAttribute('price') || '0.00'; | |
| const category = this.getAttribute('category') || 'Plugin'; | |
| const image = this.getAttribute('image') || 'http://static.photos/technology/640x360/1'; | |
| const rating = this.getAttribute('rating') || '5.0'; | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .card { | |
| background: white; | |
| border-radius: 0.75rem; | |
| overflow: hidden; | |
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); | |
| transition: transform 0.2s, box-shadow 0.2s; | |
| } | |
| .card:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); | |
| } | |
| .card-image { | |
| width: 100%; | |
| height: 180px; | |
| object-fit: cover; | |
| } | |
| .card-body { | |
| padding: 1.25rem; | |
| } | |
| .card-title { | |
| font-size: 1.125rem; | |
| font-weight: 600; | |
| margin-bottom: 0.5rem; | |
| color: #1a202c; | |
| } | |
| .card-category { | |
| display: inline-block; | |
| background-color: #ebf4ff; | |
| color: #4299e1; | |
| font-size: 0.75rem; | |
| font-weight: 500; | |
| padding: 0.25rem 0.5rem; | |
| border-radius: 9999px; | |
| margin-bottom: 0.75rem; | |
| text-transform: uppercase; | |
| letter-spacing: 0.05em; | |
| } | |
| .card-footer { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-top: 1rem; | |
| } | |
| .card-price { | |
| font-size: 1.25rem; | |
| font-weight: 700; | |
| color: #1a202c; | |
| } | |
| .free-badge { | |
| background-color: #48bb78; | |
| color: white; | |
| padding: 0.25rem 0.5rem; | |
| border-radius: 0.25rem; | |
| font-size: 0.75rem; | |
| font-weight: bold; | |
| } | |
| .card-rating { | |
| display: flex; | |
| align-items: center; | |
| color: #718096; | |
| font-size: 0.875rem; | |
| } | |
| .star-icon { | |
| color: #f6ad55; | |
| margin-right: 0.25rem; | |
| } | |
| /* Dark mode styles */ | |
| .dark .card { | |
| background: #2d3748; | |
| } | |
| .dark .card-title { | |
| color: #f7fafc; | |
| } | |
| .dark .card-category { | |
| background-color: #2b6cb0; | |
| color: #ebf8ff; | |
| } | |
| .dark .card-price { | |
| color: #f7fafc; | |
| } | |
| .dark .card-rating { | |
| color: #cbd5e0; | |
| } | |
| </style> | |
| <div class="card"> | |
| <img src="${image}" alt="${title}" class="card-image"> | |
| <div class="card-body"> | |
| <h3 class="card-title">${title}</h3> | |
| <span class="card-category">${category}</span> | |
| <div class="card-footer"> | |
| ${price === 'Free' ? | |
| '<span class="free-badge">FREE</span>' : | |
| `<span class="card-price">${price}</span>`} | |
| <span class="card-rating"> | |
| <i data-feather="star" class="star-icon"></i> | |
| ${rating} | |
| </span> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| // Initialize feather icons | |
| if (window.feather) { | |
| window.feather.replace(); | |
| } | |
| } | |
| } | |
| customElements.define('product-card', ProductCard); |