cynx-lib 1.3.59 → 1.3.61

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cynx-lib",
3
- "version": "1.3.59",
3
+ "version": "1.3.61",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,52 +1,145 @@
1
- import Button from './Button';
2
- import { ChevronLeft, ChevronRight } from 'lucide-react';
3
-
4
- export function Pagination({ page = 1, pages = 1, total, perPage, onChange, style = {} }) {
5
- const totalPages = pages || (total && perPage ? Math.ceil(total / perPage) : 0);
6
- if (!totalPages || totalPages <= 1) return null;
7
-
8
- const items = [];
9
- for (let i = 1; i <= totalPages; i++) {
10
- if (i === 1 || i === totalPages || (i >= page - 1 && i <= page + 1)) items.push(i);
11
- else if (items[items.length - 1] !== '...') items.push('...');
12
- }
13
-
14
- const start = perPage ? (page - 1) * perPage + 1 : null;
15
- const end = perPage ? Math.min(page * perPage, total) : null;
16
-
17
- return (
18
- <div style={{
19
- display: 'flex',
20
- alignItems: 'center',
21
- gap: 8,
22
- ...style,
23
- }}>
24
- {start !== null && (
25
- <div style={{ fontSize: '.72rem', color: 'var(--muted, #797b8d)', fontFamily: 'var(--mono, ui-monospace, monospace)' }}>
26
- {start}–{end} of {total}
27
- </div>
28
- )}
29
- <div style={{ display: 'flex', gap: 4, alignItems: 'center', marginLeft: start !== null ? 'auto' : 0 }}>
30
- <Button
31
- variant="ghost"
32
- size="xs"
33
- icon={<ChevronLeft size={14} />}
34
- onClick={() => onChange?.(page - 1)}
35
- disabled={page <= 1}
36
- />
37
- {items.map((item, i) =>
38
- item === '...'
39
- ? <span key={`e${i}`} style={{ padding: '0 4px', color: 'var(--muted, #797b8d)', fontSize: '.78rem' }}>…</span>
40
- : <Button key={item} variant={item === page ? 'primary' : 'no-line'} size="xs" onClick={() => onChange?.(item)} style={{ minWidth: 28 }}>{item}</Button>
41
- )}
42
- <Button
43
- variant="ghost"
44
- size="xs"
45
- icon={<ChevronRight size={14} />}
46
- onClick={() => onChange?.(page + 1)}
47
- disabled={page >= totalPages}
48
- />
49
- </div>
50
- </div>
51
- );
52
- }
1
+ import React from 'react';
2
+ import { ChevronLeft, ChevronRight } from 'lucide-react';
3
+
4
+ export function Pagination({ page = 1, pages = 1, total, perPage, pageSize, onChange, size = 'md', style = {} }) {
5
+ const effectivePerPage = pageSize || perPage || 20;
6
+ const totalPages = pages || (total && effectivePerPage ? Math.ceil(total / effectivePerPage) : 0);
7
+ if (!totalPages || totalPages <= 1) return null;
8
+
9
+ const items = [];
10
+ for (let i = 1; i <= totalPages; i++) {
11
+ if (i === 1 || i === totalPages || (i >= page - 1 && i <= page + 1)) items.push(i);
12
+ else if (items[items.length - 1] !== '...') items.push('...');
13
+ }
14
+
15
+ const start = effectivePerPage ? (page - 1) * effectivePerPage + 1 : null;
16
+ const end = effectivePerPage ? Math.min(page * effectivePerPage, total) : null;
17
+
18
+ const SIZES = {
19
+ xs: { box: 26, icon: 13, font: '11px', gap: 6 },
20
+ sm: { box: 30, icon: 15, font: '12px', gap: 8 },
21
+ md: { box: 34, icon: 17, font: '13.5px', gap: 10 },
22
+ lg: { box: 38, icon: 19, font: '15px', gap: 12 },
23
+ };
24
+ const currentSize = SIZES[size] || SIZES.md;
25
+
26
+ return (
27
+ <div
28
+ style={{
29
+ display: 'flex',
30
+ alignItems: 'center',
31
+ justifyContent: 'space-between',
32
+ width: '100%',
33
+ padding: '8px 0',
34
+ userSelect: 'none',
35
+ ...style,
36
+ }}
37
+ >
38
+ {start !== null && (
39
+ <div style={{ fontSize: '.75rem', color: 'var(--muted, #797b8d)', fontFamily: 'var(--mono, ui-monospace, monospace)' }}>
40
+ {start}–{end} of {total}
41
+ </div>
42
+ )}
43
+
44
+ <div style={{ display: 'flex', gap: currentSize.gap, alignItems: 'center', marginLeft: start !== null ? 'auto' : 0 }}>
45
+ {/* Prev Button */}
46
+ <button
47
+ type="button"
48
+ disabled={page <= 1}
49
+ onClick={() => onChange?.(page - 1)}
50
+ style={{
51
+ display: 'inline-flex',
52
+ alignItems: 'center',
53
+ justifyContent: 'center',
54
+ width: currentSize.box,
55
+ height: currentSize.box,
56
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
57
+ background: 'var(--surface, #ffffff)',
58
+ border: '1px solid var(--border, var(--bd, #e2e8f0))',
59
+ boxShadow: '0 2px 5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02)',
60
+ color: 'var(--muted, #64748b)',
61
+ cursor: page <= 1 ? 'not-allowed' : 'pointer',
62
+ opacity: page <= 1 ? 0.35 : 1,
63
+ transition: 'all .14s',
64
+ }}
65
+ title="Previous page"
66
+ >
67
+ <ChevronLeft size={currentSize.icon} strokeWidth={2.2} />
68
+ </button>
69
+
70
+ {/* Page numbers */}
71
+ {items.map((item, i) =>
72
+ item === '...' ? (
73
+ <span
74
+ key={`e${i}`}
75
+ style={{
76
+ display: 'inline-flex',
77
+ alignItems: 'center',
78
+ justifyContent: 'center',
79
+ minWidth: currentSize.box,
80
+ height: currentSize.box,
81
+ color: 'var(--muted, #94a3b8)',
82
+ fontSize: currentSize.font,
83
+ fontWeight: 500,
84
+ }}
85
+ >
86
+ …
87
+ </span>
88
+ ) : (
89
+ <button
90
+ key={item}
91
+ type="button"
92
+ onClick={() => onChange?.(item)}
93
+ style={{
94
+ display: 'inline-flex',
95
+ alignItems: 'center',
96
+ justifyContent: 'center',
97
+ minWidth: currentSize.box,
98
+ height: currentSize.box,
99
+ padding: '0 6px',
100
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
101
+ fontSize: currentSize.font,
102
+ fontWeight: item === page ? 600 : 500,
103
+ background: item === page ? 'var(--accent, #12675D)' : 'transparent',
104
+ color: item === page ? '#ffffff' : 'var(--muted, #64748b)',
105
+ boxShadow: item === page ? '0 3px 8px rgba(0, 0, 0, 0.12)' : 'none',
106
+ border: 'none',
107
+ cursor: 'pointer',
108
+ transition: 'all .14s',
109
+ }}
110
+ >
111
+ {item}
112
+ </button>
113
+ )
114
+ )}
115
+
116
+ {/* Next Button */}
117
+ <button
118
+ type="button"
119
+ disabled={page >= totalPages}
120
+ onClick={() => onChange?.(page + 1)}
121
+ style={{
122
+ display: 'inline-flex',
123
+ alignItems: 'center',
124
+ justifyContent: 'center',
125
+ width: currentSize.box,
126
+ height: currentSize.box,
127
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
128
+ background: 'var(--surface, #ffffff)',
129
+ border: '1px solid var(--border, var(--bd, #e2e8f0))',
130
+ boxShadow: '0 2px 5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02)',
131
+ color: 'var(--muted, #64748b)',
132
+ cursor: page >= totalPages ? 'not-allowed' : 'pointer',
133
+ opacity: page >= totalPages ? 0.35 : 1,
134
+ transition: 'all .14s',
135
+ }}
136
+ title="Next page"
137
+ >
138
+ <ChevronRight size={currentSize.icon} strokeWidth={2.2} />
139
+ </button>
140
+ </div>
141
+ </div>
142
+ );
143
+ }
144
+
145
+ export default Pagination;
@@ -1,7 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from "vue";
3
3
  import { ChevronLeft, ChevronRight } from "lucide-vue-next";
4
- import Button from "./Button.vue";
5
4
 
6
5
  const props = withDefaults(
7
6
  defineProps<{
@@ -11,6 +10,7 @@ const props = withDefaults(
11
10
  perPage?: number;
12
11
  pageSize?: number;
13
12
  disabled?: boolean;
13
+ size?: "xs" | "sm" | "md" | "lg";
14
14
  }>(),
15
15
  {
16
16
  page: 1,
@@ -18,6 +18,7 @@ const props = withDefaults(
18
18
  total: 0,
19
19
  perPage: 20,
20
20
  disabled: false,
21
+ size: "md",
21
22
  }
22
23
  );
23
24
 
@@ -69,59 +70,130 @@ const handlePageChange = (newPage: number) => {
69
70
  emit("update:page", newPage);
70
71
  emit("change", newPage);
71
72
  };
73
+
74
+ const SIZES = {
75
+ xs: { box: 26, icon: 13, font: "11px", gap: "6px" },
76
+ sm: { box: 30, icon: 15, font: "12px", gap: "8px" },
77
+ md: { box: 34, icon: 17, font: "13.5px", gap: "10px" },
78
+ lg: { box: 38, icon: 19, font: "15px", gap: "12px" },
79
+ };
80
+
81
+ const currentSize = computed(() => SIZES[props.size] || SIZES.md);
72
82
  </script>
73
83
 
74
84
  <template>
75
- <div v-if="totalPages > 1 || (total != null && total > 0)" class="flex items-center justify-between w-full py-2 select-none">
85
+ <div
86
+ v-if="totalPages > 1 || (total != null && total > 0)"
87
+ class="flex items-center justify-between w-full py-2 select-none"
88
+ >
76
89
  <!-- Info Counter -->
77
90
  <div v-if="startItem !== null" class="text-xs text-slate-500 dark:text-slate-400 font-mono">
78
91
  {{ startItem }}–{{ endItem }} of {{ total }}
79
92
  </div>
80
93
  <div v-else />
81
94
 
82
- <!-- Page Buttons -->
83
- <div class="flex items-center gap-1">
84
- <Button
85
- variant="ghost"
86
- size="xs"
95
+ <!-- Page Controls Container -->
96
+ <div
97
+ class="flex items-center"
98
+ :style="{ gap: currentSize.gap }"
99
+ >
100
+ <!-- Prev Arrow Button (Card Style) -->
101
+ <button
102
+ type="button"
87
103
  :disabled="disabled || page <= 1"
104
+ class="cynx-page-arrow inline-flex items-center justify-center transition-all"
105
+ :style="{
106
+ width: `${currentSize.box}px`,
107
+ height: `${currentSize.box}px`,
108
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
109
+ background: 'var(--surface, #ffffff)',
110
+ border: '1px solid var(--border, var(--bd, #e2e8f0))',
111
+ boxShadow: '0 2px 5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02)',
112
+ color: 'var(--muted, #64748b)',
113
+ cursor: disabled || page <= 1 ? 'not-allowed' : 'pointer',
114
+ opacity: disabled || page <= 1 ? 0.35 : 1,
115
+ }"
88
116
  title="Previous page"
89
117
  @click="handlePageChange(page - 1)"
90
118
  >
91
- <template #icon>
92
- <ChevronLeft :size="14" />
93
- </template>
94
- </Button>
119
+ <ChevronLeft :size="currentSize.icon" :stroke-width="2.2" />
120
+ </button>
95
121
 
96
- <template v-for="(item, i) in pageItems" :key="`p-${i}`">
122
+ <!-- Page Numbers / Ellipsis -->
123
+ <template v-for="(item, i) in pageItems" :key="`page-${i}`">
124
+ <!-- Ellipsis -->
97
125
  <span
98
126
  v-if="item === '...'"
99
- class="px-1 text-xs text-slate-400 dark:text-slate-500"
127
+ class="inline-flex items-center justify-center text-slate-400 dark:text-slate-500 select-none font-medium"
128
+ :style="{
129
+ minWidth: `${currentSize.box}px`,
130
+ height: `${currentSize.box}px`,
131
+ fontSize: currentSize.font,
132
+ }"
100
133
  >
101
134
  …
102
135
  </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"
136
+
137
+ <!-- Page Button -->
138
+ <button
139
+ v-else
140
+ type="button"
107
141
  :disabled="disabled"
142
+ class="cynx-page-num inline-flex items-center justify-center transition-all"
143
+ :class="[
144
+ item === page ? 'cynx-page-num--active font-semibold' : 'cynx-page-num--inactive font-medium hover:bg-slate-100/70 dark:hover:bg-slate-800/70'
145
+ ]"
146
+ :style="{
147
+ minWidth: `${currentSize.box}px`,
148
+ height: `${currentSize.box}px`,
149
+ padding: '0 6px',
150
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
151
+ fontSize: currentSize.font,
152
+ background: item === page ? 'var(--accent, #12675D)' : 'transparent',
153
+ color: item === page ? '#ffffff' : 'var(--muted, #64748b)',
154
+ boxShadow: item === page ? '0 3px 8px rgba(0, 0, 0, 0.12)' : 'none',
155
+ border: 'none',
156
+ cursor: disabled ? 'not-allowed' : 'pointer',
157
+ }"
108
158
  @click="handlePageChange(Number(item))"
109
159
  >
110
160
  {{ item }}
111
- </Button>
161
+ </button>
112
162
  </template>
113
163
 
114
- <Button
115
- variant="ghost"
116
- size="xs"
164
+ <!-- Next Arrow Button (Card Style) -->
165
+ <button
166
+ type="button"
117
167
  :disabled="disabled || page >= totalPages"
168
+ class="cynx-page-arrow inline-flex items-center justify-center transition-all"
169
+ :style="{
170
+ width: `${currentSize.box}px`,
171
+ height: `${currentSize.box}px`,
172
+ borderRadius: 'var(--radm, var(--rads, var(--radius, 10px)))',
173
+ background: 'var(--surface, #ffffff)',
174
+ border: '1px solid var(--border, var(--bd, #e2e8f0))',
175
+ boxShadow: '0 2px 5px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02)',
176
+ color: 'var(--muted, #64748b)',
177
+ cursor: disabled || page >= totalPages ? 'not-allowed' : 'pointer',
178
+ opacity: disabled || page >= totalPages ? 0.35 : 1,
179
+ }"
118
180
  title="Next page"
119
181
  @click="handlePageChange(page + 1)"
120
182
  >
121
- <template #icon>
122
- <ChevronRight :size="14" />
123
- </template>
124
- </Button>
183
+ <ChevronRight :size="currentSize.icon" :stroke-width="2.2" />
184
+ </button>
125
185
  </div>
126
186
  </div>
127
187
  </template>
188
+
189
+ <style scoped>
190
+ .cynx-page-arrow:not(:disabled):hover {
191
+ color: var(--t, #0f111c);
192
+ border-color: var(--border-hover, #cbd5e1);
193
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.07);
194
+ }
195
+
196
+ .cynx-page-num--inactive:not(:disabled):hover {
197
+ color: var(--t, #0f111c);
198
+ }
199
+ </style>