class CustomApiShowcase extends HTMLElement { static get observedAttributes() { return ['api-name', 'category', 'description', 'endpoint', 'docs-url']; } constructor() { super(); this.apiName = 'API Name'; this.category = 'Category'; this.description = 'API description goes here.'; this.endpoint = 'https://api.example.com'; this.docsUrl = 'https://docs.example.com'; } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) { this[name] = newValue; this.render(); } } connectedCallback() { this.render(); } getCategoryColor() { const colors = { 'Data Mocking': 'bg-blue-100 text-blue-800', 'Fun & Images': 'bg-purple-100 text-purple-800', 'Weather Data': 'bg-green-100 text-green-800', 'Finance': 'bg-emerald-100 text-emerald-800', 'Social': 'bg-pink-100 text-pink-800', 'Development': 'bg-orange-100 text-orange-800', 'Business': 'bg-indigo-100 text-indigo-800' }; return colors[this.category] || 'bg-gray-100 text-gray-800'; } render() { const categoryColor = this.getCategoryColor(); this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `

${this.apiName}

${this.category}

${this.description}

Endpoint
${this.endpoint}
99.9% Uptime
<100ms Response
HTTPS Only
`; // Add copy functionality const copyBtn = this.shadowRoot.querySelector('.copy-btn'); if (copyBtn) { copyBtn.addEventListener('click', async () => { const textToCopy = copyBtn.getAttribute('data-copy'); try { await navigator.clipboard.writeText(textToCopy); const originalHTML = copyBtn.innerHTML; copyBtn.innerHTML = 'Copied!'; feather.replace(); setTimeout(() => { copyBtn.innerHTML = originalHTML; feather.replace(); }, 2000); } catch (err) { console.error('Failed to copy:', err); } }); } // Initialize icons in shadow DOM setTimeout(() => { feather.replace(); }, 100); } } customElements.define('custom-api-showcase', CustomApiShowcase);