idhyksi097's picture
It is not complex enough please make it more complex
0751b83 verified
Raw History Blame Contribute Delete
2.91 kB
class QuantumFile extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
padding: 10px;
margin: 5px 0;
border-radius: 6px;
background: rgba(50, 50, 70, 0.3);
transition: all 0.2s ease;
}
:host(:hover) {
background: rgba(70, 70, 90, 0.5);
transform: translateX(5px);
}
.file-item {
display: flex;
align-items: center;
cursor: pointer;
}
.file-icon {
margin-right: 10px;
width: 24px;
text-align: center;
}
.file-name {
flex: 1;
}
.file-size {
font-size: 0.8em;
opacity: 0.7;
}
.file-date {
font-size: 0.7em;
opacity: 0.5;
margin-left: 15px;
}
.directory {
color: var(--system-accent);
}
</style>
<div class="file-item">
<div class="file-icon">
<i class="fas" id="icon"></i>
</div>
<div class="file-name"><slot></slot></div>
<div class="file-size" id="size"></div>
<div class="file-date" id="date"></div>
</div>
`;
}
connectedCallback() {
const type = this.getAttribute('type') || 'file';
const icon = this.shadowRoot.getElementById('icon');
const sizeEl = this.shadowRoot.getElementById('size');
const dateEl = this.shadowRoot.getElementById('date');
if (type === 'directory') {
icon.classList.add('fa-folder', 'directory');
sizeEl.textContent = '';
} else {
icon.classList.add('fa-file');
sizeEl.textContent = this.getAttribute('size') || '';
}
dateEl.textContent = this.getAttribute('date') || '';
this.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('file-select', {
bubbles: true,
composed: true,
detail: {
path: this.getAttribute('path'),
type: type
}
}));
});
}
}
customElements.define('quantum-file', QuantumFile);