cynx-lib 1.3.60 → 1.3.62

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.60",
3
+ "version": "1.3.62",
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<{
@@ -72,73 +71,129 @@ const handlePageChange = (newPage: number) => {
72
71
  emit("change", newPage);
73
72
  };
74
73
 
75
- const iconSize = computed(() => {
76
- if (props.size === "xs") return 13;
77
- if (props.size === "sm") return 14;
78
- if (props.size === "lg") return 18;
79
- return 16;
80
- });
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
+ };
81
80
 
82
- const buttonHeightClass = computed(() => {
83
- if (props.size === "xs") return "h-6 min-w-[24px] text-[11px]";
84
- if (props.size === "sm") return "h-7 min-w-[28px] text-[11.5px]";
85
- if (props.size === "lg") return "h-9 min-w-[36px] text-sm";
86
- return "h-8 min-w-[32px] text-xs";
87
- });
81
+ const currentSize = computed(() => SIZES[props.size] || SIZES.md);
88
82
  </script>
89
83
 
90
84
  <template>
91
- <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
+ >
92
89
  <!-- Info Counter -->
93
90
  <div v-if="startItem !== null" class="text-xs text-slate-500 dark:text-slate-400 font-mono">
94
91
  {{ startItem }}–{{ endItem }} of {{ total }}
95
92
  </div>
96
93
  <div v-else />
97
94
 
98
- <!-- Page Buttons -->
99
- <div class="flex items-center gap-1.5">
100
- <Button
101
- variant="icon"
102
- :size="size"
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"
103
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
+ }"
104
116
  title="Previous page"
105
117
  @click="handlePageChange(page - 1)"
106
118
  >
107
- <template #icon>
108
- <ChevronLeft :size="iconSize" />
109
- </template>
110
- </Button>
119
+ <ChevronLeft :size="currentSize.icon" :stroke-width="2.2" />
120
+ </button>
111
121
 
112
- <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 -->
113
125
  <span
114
126
  v-if="item === '...'"
115
- :class="[buttonHeightClass, 'inline-flex items-center justify-center text-slate-400 dark:text-slate-500 font-medium select-none']"
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
+ }"
116
133
  >
117
134
  …
118
135
  </span>
119
- <Button
136
+
137
+ <!-- Page Button -->
138
+ <button
120
139
  v-else
121
- :variant="item === page ? 'primary' : 'ghost'"
122
- :size="size"
123
- :class="[buttonHeightClass, 'px-2 font-semibold transition-colors', item !== page ? 'hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-200' : '']"
140
+ type="button"
124
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
+ }"
125
158
  @click="handlePageChange(Number(item))"
126
159
  >
127
160
  {{ item }}
128
- </Button>
161
+ </button>
129
162
  </template>
130
163
 
131
- <Button
132
- variant="icon"
133
- :size="size"
164
+ <!-- Next Arrow Button (Card Style) -->
165
+ <button
166
+ type="button"
134
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
+ }"
135
180
  title="Next page"
136
181
  @click="handlePageChange(page + 1)"
137
182
  >
138
- <template #icon>
139
- <ChevronRight :size="iconSize" />
140
- </template>
141
- </Button>
183
+ <ChevronRight :size="currentSize.icon" :stroke-width="2.2" />
184
+ </button>
142
185
  </div>
143
186
  </div>
144
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>