cynx-lib 1.3.51 → 1.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+ import { ChevronLeft, ChevronRight } from "lucide-vue-next";
4
+ import Button from "./Button.vue";
5
+
6
+ const props = withDefaults(
7
+ defineProps<{
8
+ page?: number;
9
+ pages?: number;
10
+ total?: number;
11
+ perPage?: number;
12
+ pageSize?: number;
13
+ disabled?: boolean;
14
+ }>(),
15
+ {
16
+ page: 1,
17
+ pages: 1,
18
+ total: 0,
19
+ perPage: 20,
20
+ disabled: false,
21
+ }
22
+ );
23
+
24
+ const emit = defineEmits<{
25
+ (e: "update:page", page: number): void;
26
+ (e: "change", page: number): void;
27
+ }>();
28
+
29
+ const effectivePerPage = computed(() => props.pageSize || props.perPage || 20);
30
+
31
+ const totalPages = computed(() => {
32
+ if (props.pages && props.pages > 1) return props.pages;
33
+ if (props.total && effectivePerPage.value) {
34
+ return Math.ceil(props.total / effectivePerPage.value);
35
+ }
36
+ return 1;
37
+ });
38
+
39
+ const pageItems = computed(() => {
40
+ const totalP = totalPages.value;
41
+ if (!totalP || totalP <= 1) return [];
42
+
43
+ const cur = props.page || 1;
44
+ const items: (number | string)[] = [];
45
+
46
+ for (let i = 1; i <= totalP; i++) {
47
+ if (i === 1 || i === totalP || (i >= cur - 1 && i <= cur + 1)) {
48
+ items.push(i);
49
+ } else if (items[items.length - 1] !== "...") {
50
+ items.push("...");
51
+ }
52
+ }
53
+
54
+ return items;
55
+ });
56
+
57
+ const startItem = computed(() => {
58
+ if (!props.total) return null;
59
+ return (props.page - 1) * effectivePerPage.value + 1;
60
+ });
61
+
62
+ const endItem = computed(() => {
63
+ if (!props.total) return null;
64
+ return Math.min(props.page * effectivePerPage.value, props.total);
65
+ });
66
+
67
+ const handlePageChange = (newPage: number) => {
68
+ if (props.disabled || newPage < 1 || newPage > totalPages.value || newPage === props.page) return;
69
+ emit("update:page", newPage);
70
+ emit("change", newPage);
71
+ };
72
+ </script>
73
+
74
+ <template>
75
+ <div v-if="totalPages > 1 || (total != null && total > 0)" class="flex items-center justify-between w-full py-2 select-none">
76
+ <!-- Info Counter -->
77
+ <div v-if="startItem !== null" class="text-xs text-slate-500 dark:text-slate-400 font-mono">
78
+ {{ startItem }}–{{ endItem }} of {{ total }}
79
+ </div>
80
+ <div v-else />
81
+
82
+ <!-- Page Buttons -->
83
+ <div class="flex items-center gap-1">
84
+ <Button
85
+ variant="ghost"
86
+ size="xs"
87
+ :disabled="disabled || page <= 1"
88
+ title="Previous page"
89
+ @click="handlePageChange(page - 1)"
90
+ >
91
+ <template #icon>
92
+ <ChevronLeft :size="14" />
93
+ </template>
94
+ </Button>
95
+
96
+ <template v-for="(item, i) in pageItems" :key="`p-${i}`">
97
+ <span
98
+ v-if="item === '...'"
99
+ class="px-1 text-xs text-slate-400 dark:text-slate-500"
100
+ >
101
+ …
102
+ </span>
103
+ <Button
104
+ :variant="item === page ? 'primary' : 'ghost'"
105
+ size="xs"
106
+ class="min-w-[28px] h-7 px-2 font-semibold text-xs"
107
+ :disabled="disabled"
108
+ @click="handlePageChange(Number(item))"
109
+ >
110
+ {{ item }}
111
+ </Button>
112
+ </template>
113
+
114
+ <Button
115
+ variant="ghost"
116
+ size="xs"
117
+ :disabled="disabled || page >= totalPages"
118
+ title="Next page"
119
+ @click="handlePageChange(page + 1)"
120
+ >
121
+ <template #icon>
122
+ <ChevronRight :size="14" />
123
+ </template>
124
+ </Button>
125
+ </div>
126
+ </div>
127
+ </template>