diff --git a/src/components/ModsList.astro b/src/components/ModsList.astro index eb118b7..b2d99ff 100644 --- a/src/components/ModsList.astro +++ b/src/components/ModsList.astro @@ -1,5 +1,6 @@ --- import { icon, library } from '@fortawesome/fontawesome-svg-core' +import ChevronDownIcon from '~/icons/ChevronDownIcon.astro' import { faSort, faSortDown, faSortUp } from '@fortawesome/free-solid-svg-icons' import { type ZenTheme } from '~/mods' import { getPath, type Locale } from '~/utils/i18n' @@ -40,14 +41,16 @@ const totalPages = Math.ceil(allMods.length / defaultLimit) /> -
+
-
+
-
-
@@ -309,6 +338,13 @@ const totalPages = Math.ceil(allMods.length / defaultLimit) } }) } + + document.addEventListener('limit-changed', e => { + if (e instanceof CustomEvent) { + const newLimit = e.detail.value + this.setState({ limit: newLimit, page: 1 }) + } + }) } setState(newState) { // Prevent multiple renders @@ -676,4 +712,60 @@ const totalPages = Math.ceil(allMods.length / defaultLimit) // Initialize the mods search new ModsSearch() + + class CustomDropdown { + constructor() { + this.button = document.getElementById('limit-button') + this.dropdown = document.getElementById('limit-dropdown') + this.valueSpan = document.getElementById('limit-value') + + if (!this.button || !this.dropdown || !this.valueSpan) return + + this.button.addEventListener('click', () => this.toggle()) + this.dropdown.addEventListener('click', e => this.handleOptionClick(e)) + + // Close dropdown when clicking outside + document.addEventListener('click', e => { + if (!this.button?.contains(e.target) && !this.dropdown?.contains(e.target)) { + this.close() + } + }) + } + + toggle() { + const isExpanded = this.button?.getAttribute('aria-expanded') === 'true' + if (isExpanded) { + this.close() + } else { + this.open() + } + } + + open() { + this.button?.setAttribute('aria-expanded', 'true') + this.dropdown?.classList.remove('hidden') + } + + close() { + this.button?.setAttribute('aria-expanded', 'false') + this.dropdown?.classList.add('hidden') + } + + handleOptionClick(e) { + const target = e.target + if (target instanceof HTMLButtonElement && target.dataset.value) { + const value = target.dataset.value + if (this.valueSpan) { + this.valueSpan.textContent = value + } + // Trigger change event for ModsSearch + const event = new CustomEvent('limit-changed', { detail: { value: parseInt(value, 10) } }) + document.dispatchEvent(event) + this.close() + } + } + } + + // Initialize the custom dropdown + new CustomDropdown()