forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListControls.vue
More file actions
90 lines (81 loc) · 2.51 KB
/
ListControls.vue
File metadata and controls
90 lines (81 loc) · 2.51 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<script setup lang="ts">
export type SortOption = 'downloads' | 'updated' | 'name-asc' | 'name-desc'
const props = defineProps<{
/** Current search/filter text */
filter: string
/** Current sort option */
sort: SortOption
/** Placeholder text for the search input */
placeholder?: string
/** Total count of packages (before filtering) */
totalCount?: number
/** Filtered count of packages */
filteredCount?: number
}>()
const emit = defineEmits<{
'update:filter': [value: string]
'update:sort': [value: SortOption]
}>()
const filterValue = computed({
get: () => props.filter,
set: value => emit('update:filter', value),
})
const sortValue = computed({
get: () => props.sort,
set: value => emit('update:sort', value),
})
const sortOptions = computed(
() =>
[
{ value: 'downloads', label: $t('package.sort.downloads') },
{ value: 'updated', label: $t('package.sort.published') },
{ value: 'name-asc', label: $t('package.sort.name_asc') },
{ value: 'name-desc', label: $t('package.sort.name_desc') },
] as const,
)
// Show filter count when filtering is active
const showFilteredCount = computed(() => {
return (
props.filter &&
props.filteredCount !== undefined &&
props.totalCount !== undefined &&
props.filteredCount !== props.totalCount
)
})
</script>
<template>
<div class="flex flex-col sm:flex-row gap-3 mb-6">
<!-- Filter input -->
<div class="flex-1 relative">
<label for="package-filter" class="sr-only">{{ $t('package.list.filter_label') }}</label>
<div
class="absolute h-full w-10 flex items-center justify-center text-fg-subtle pointer-events-none"
aria-hidden="true"
>
<div class="i-carbon:search w-4 h-4" />
</div>
<InputBase
id="package-filter"
v-model="filterValue"
type="search"
:placeholder="placeholder ?? $t('package.list.filter_placeholder')"
no-correct
class="w-full min-w-25 ps-10"
size="medium"
/>
</div>
<!-- Sort select -->
<SelectField
:label="$t('package.list.sort_label')"
hidden-label
id="package-sort"
class="relative shrink-0"
v-model="sortValue"
:items="sortOptions.map(option => ({ label: option.label, value: option.value }))"
/>
</div>
<!-- Filtered count indicator -->
<p v-if="showFilteredCount" class="text-fg-subtle text-xs font-mono mb-4">
{{ $t('package.list.showing_count', { filtered: filteredCount, total: totalCount }) }}
</p>
</template>