/**
* ds-token-list.js
* Design token listing and management
* View, edit, and validate design tokens
*/
import contextStore from '../../stores/context-store.js';
export default class TokenList extends HTMLElement {
constructor() {
super();
this.tokens = [
{ id: 'color-primary', name: 'Primary Color', category: 'Colors', value: '#0066CC', usage: 156 },
{ id: 'color-success', name: 'Success Color', category: 'Colors', value: '#4caf50', usage: 89 },
{ id: 'color-error', name: 'Error Color', category: 'Colors', value: '#f44336', usage: 76 },
{ id: 'color-warning', name: 'Warning Color', category: 'Colors', value: '#ff9800', usage: 54 },
{ id: 'spacing-xs', name: 'Extra Small Spacing', category: 'Spacing', value: '4px', usage: 234 },
{ id: 'spacing-sm', name: 'Small Spacing', category: 'Spacing', value: '8px', usage: 312 },
{ id: 'spacing-md', name: 'Medium Spacing', category: 'Spacing', value: '16px', usage: 445 },
{ id: 'spacing-lg', name: 'Large Spacing', category: 'Spacing', value: '24px', usage: 198 },
{ id: 'font-body', name: 'Body Font', category: 'Typography', value: 'Inter, sans-serif', usage: 678 },
{ id: 'font-heading', name: 'Heading Font', category: 'Typography', value: 'Poppins, sans-serif', usage: 234 },
];
this.selectedCategory = 'All';
this.editingTokenId = null;
}
connectedCallback() {
this.render();
this.setupEventListeners();
}
render() {
this.innerHTML = `
Design Tokens
Manage and track design token usage across the system
${['All', 'Colors', 'Spacing', 'Typography', 'Shadows', 'Borders'].map(cat => `
`).join('')}
Token Name
Category
Value
Usage
Actions
${this.renderTokenRows()}
`;
}
renderTokenRows() {
const filtered = this.selectedCategory === 'All'
? this.tokens
: this.tokens.filter(t => t.category === this.selectedCategory);
return filtered.map(token => `
${token.name}
${token.id}
${token.category}
${token.value}
${token.usage}
`).join('');
}
setupEventListeners() {
// Filter buttons
this.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
this.selectedCategory = btn.dataset.category;
this.render();
this.setupEventListeners();
});
});
// Export button
const exportBtn = this.querySelector('#export-btn');
if (exportBtn) {
exportBtn.addEventListener('click', () => {
const tokenData = JSON.stringify(this.tokens, null, 2);
const blob = new Blob([tokenData], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'design-tokens.json';
a.click();
URL.revokeObjectURL(url);
});
}
// Edit token buttons
this.querySelectorAll('.edit-token-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tokenId = btn.dataset.tokenId;
const token = this.tokens.find(t => t.id === tokenId);
this.dispatchEvent(new CustomEvent('edit-token', {
detail: { token },
bubbles: true,
composed: true
}));
});
});
// Copy token buttons
this.querySelectorAll('.copy-token-btn').forEach(btn => {
btn.addEventListener('click', () => {
const value = btn.dataset.tokenValue;
navigator.clipboard.writeText(value).then(() => {
const originalText = btn.textContent;
btn.textContent = '✓ Copied';
setTimeout(() => {
btn.textContent = originalText;
}, 1500);
});
});
});
}
}
customElements.define('ds-token-list', TokenList);