/** * ds-frontpage.js * Front page component for team workdesks * Refactored: Shadow DOM, extracted styles, uses ds-metric-card */ import contextStore from '../../stores/context-store.js'; import './ds-metric-card.js'; // Import the new reusable component export default class Frontpage extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); // Enable Shadow DOM this.state = { teamName: 'Team', metrics: {} }; } connectedCallback() { this.render(); this.setupEventListeners(); // Subscribe to context changes this.unsubscribe = contextStore.subscribe(({ state }) => { this.state.teamId = state.teamId; const teamNames = { 'ui': 'UI Team', 'ux': 'UX Team', 'qa': 'QA Team', 'admin': 'Admin' }; this.state.teamName = teamNames[state.teamId] || 'Team'; this.updateTeamName(); }); } disconnectedCallback() { if (this.unsubscribe) this.unsubscribe(); } render() { this.shadowRoot.innerHTML = `

Team Dashboard

Overview of design system adoption and metrics for your team

Quick Actions

`; this.updateTeamName(); } updateTeamName() { // Select from Shadow DOM const teamNameEl = this.shadowRoot.querySelector('#team-name'); if (teamNameEl) { teamNameEl.textContent = `${this.state.teamName} Dashboard`; } } setupEventListeners() { // Listen within Shadow DOM const buttons = this.shadowRoot.querySelectorAll('.action-btn'); buttons.forEach(btn => { btn.addEventListener('click', (e) => { const action = btn.dataset.action; this.handleQuickAction(action); }); }); } handleQuickAction(action) { console.log(`Quick action triggered: ${action}`); // Events bubble out of Shadow DOM if composed: true this.dispatchEvent(new CustomEvent('quick-action', { detail: { action }, bubbles: true, composed: true })); } } customElements.define('ds-frontpage', Frontpage);