From 56ea6c95b6634433eaa57f9977c7035b206867ac Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Mon, 15 Dec 2025 00:25:37 -0800 Subject: Add state when file uploaded --- src/ts/script.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/ts') diff --git a/src/ts/script.ts b/src/ts/script.ts index 81c61f7..79a9a75 100644 --- a/src/ts/script.ts +++ b/src/ts/script.ts @@ -112,10 +112,41 @@ function initFairyDust(): void { }); } +function initFileInputs(): void { + const fileInputs = document.querySelectorAll('input[type="file"]'); + + fileInputs.forEach((input) => { + const label = document.querySelector( + `label.file-input-button[for="${input.id}"]` + ); + if (!label) return; + + const originalText = label.textContent || 'Browse Files'; + + input.addEventListener('change', () => { + const files = input.files; + if (!files || files.length === 0) { + label.textContent = originalText; + label.classList.remove('has-file'); + return; + } + + label.classList.add('has-file'); + + if (files.length === 1) { + label.textContent = `✓ ${files[0].name}`; + } else { + label.textContent = `✓ ${files.length} files selected`; + } + }); + }); +} + function init(): void { setAssetBase(); initThemeToggle(); initFairyDust(); + initFileInputs(); Prism.highlightAll(); initOneko(); } -- cgit v1.2.3-70-g09d2