Spaces:
Running
Running
File size: 1,660 Bytes
1a8e166 4c08787 1a8e166 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | class TableWidget extends HTMLElement {
connectedCallback() {
const config = JSON.parse(this.getAttribute('config') || '{}');
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
background: white;
border-radius: 0.75rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
padding: 1rem;
}
.title {
font-weight: 600;
margin-bottom: 1rem;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 0.5rem;
text-align: left;
border-bottom: 1px solid #e5e7eb;
}
th {
font-weight: 600;
background: #f9fafb;
}
</style>
<div class="title">${config.title}</div>
<table>
<thead>
<tr>
${config.columns.map(col => `<th>${col}</th>`).join('')}
</tr>
</thead>
<tbody>
${config.rows.map(row => `
<tr>
${row.map(cell => `<td>${cell}</td>`).join('')}
</tr>
`).join('')}
</tbody>
</table>
`;
}
}
customElements.define('table-widget', TableWidget); |