cynx-lib 1.3.101 → 1.3.102
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/gen.js +77 -77
- package/package.json +1 -1
- package/ui/components/ActionsMenu.jsx +357 -357
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Globe.jsx +764 -0
- package/ui/components/HoverCard.jsx +85 -85
- package/ui/components/Input.jsx +54 -4
- package/ui/components/Pagination.jsx +145 -145
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/ui/components/XTable.jsx +112 -112
- package/ui/index.cjs +5 -0
- package/ui/index.js +3 -0
- package/utils/index.js +24 -24
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/server.js +371 -371
- package/utils/utils/session.js +131 -131
- package/utils/utils/session_manager.js +580 -580
- package/utils/utils/sso_manager.js +702 -702
- package/utils/utils/storage.js +393 -393
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +388 -388
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +140 -140
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* HoverCard — reusable tooltip/popover on hover
|
|
5
|
-
*
|
|
6
|
-
* Props:
|
|
7
|
-
* trigger — React node as hover target
|
|
8
|
-
* children — popup content
|
|
9
|
-
* position — 'top' | 'bottom' (default: 'top')
|
|
10
|
-
* width — min-width (default: 180)
|
|
11
|
-
* style — extra popup styles
|
|
12
|
-
* arrow — show arrow indicator (default: false)
|
|
13
|
-
* style — extra popup styles
|
|
14
|
-
* triggerStyle — extra trigger wrapper styles
|
|
15
|
-
*/
|
|
16
|
-
export default function HoverCard({ trigger, children, position = 'top', width = 180, arrow = false, style, triggerStyle }) {
|
|
17
|
-
const [open, setOpen] = useState(false);
|
|
18
|
-
const [pos, setPos] = useState({ x: 0, y: 0 });
|
|
19
|
-
const wrapRef = useRef(null);
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (open && wrapRef.current) {
|
|
23
|
-
const r = wrapRef.current.getBoundingClientRect();
|
|
24
|
-
setPos({ x: r.left + r.width / 2, y: position === 'top' ? r.top : r.bottom });
|
|
25
|
-
}
|
|
26
|
-
}, [open, position]);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!open) return;
|
|
30
|
-
const close = (e) => {
|
|
31
|
-
if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);
|
|
32
|
-
};
|
|
33
|
-
document.addEventListener('mousedown', close);
|
|
34
|
-
return () => document.removeEventListener('mousedown', close);
|
|
35
|
-
}, [open]);
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div
|
|
39
|
-
ref={wrapRef}
|
|
40
|
-
onMouseEnter={() => setOpen(true)}
|
|
41
|
-
onMouseLeave={() => setOpen(false)}
|
|
42
|
-
style={{ display: 'inline-block', position: 'relative', ...triggerStyle }}
|
|
43
|
-
>
|
|
44
|
-
{trigger}
|
|
45
|
-
{open && (
|
|
46
|
-
<div style={{
|
|
47
|
-
position: 'fixed',
|
|
48
|
-
left: pos.x,
|
|
49
|
-
top: position === 'top' ? 'auto' : pos.y + 6,
|
|
50
|
-
bottom: position === 'top' ? window.innerHeight - pos.y + 6 : 'auto',
|
|
51
|
-
transform: 'translateX(-50%)',
|
|
52
|
-
zIndex: 9999,
|
|
53
|
-
minWidth: width,
|
|
54
|
-
background: 'var(--surface,#fff)',
|
|
55
|
-
border: '1px solid var(--border, #e2e8f0)',
|
|
56
|
-
borderRadius: 'var(--rads, 8px)',
|
|
57
|
-
padding: '10px 14px',
|
|
58
|
-
boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))',
|
|
59
|
-
pointerEvents: 'none',
|
|
60
|
-
animation: 'hoverCardIn .15s ease',
|
|
61
|
-
...style,
|
|
62
|
-
}}>
|
|
63
|
-
{children}
|
|
64
|
-
{arrow && (
|
|
65
|
-
<div style={{
|
|
66
|
-
position: 'absolute', left: '50%',
|
|
67
|
-
[position === 'top' ? 'bottom' : 'top']: -5,
|
|
68
|
-
transform: 'translateX(-50%) rotate(45deg)',
|
|
69
|
-
width: 8, height: 8, background: 'var(--surface,#fff)',
|
|
70
|
-
borderRight: '1px solid var(--border, #e2e8f0)',
|
|
71
|
-
borderBottom: position === 'top' ? 'none' : '1px solid var(--border, #e2e8f0)',
|
|
72
|
-
borderTop: position === 'top' ? '1px solid var(--border, #e2e8f0)' : 'none',
|
|
73
|
-
}} />
|
|
74
|
-
)}
|
|
75
|
-
</div>
|
|
76
|
-
)}
|
|
77
|
-
<style>{`
|
|
78
|
-
@keyframes hoverCardIn {
|
|
79
|
-
from { opacity: 0; transform: translateX(-50%) translateY(4px); }
|
|
80
|
-
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
81
|
-
}
|
|
82
|
-
`}</style>
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HoverCard — reusable tooltip/popover on hover
|
|
5
|
+
*
|
|
6
|
+
* Props:
|
|
7
|
+
* trigger — React node as hover target
|
|
8
|
+
* children — popup content
|
|
9
|
+
* position — 'top' | 'bottom' (default: 'top')
|
|
10
|
+
* width — min-width (default: 180)
|
|
11
|
+
* style — extra popup styles
|
|
12
|
+
* arrow — show arrow indicator (default: false)
|
|
13
|
+
* style — extra popup styles
|
|
14
|
+
* triggerStyle — extra trigger wrapper styles
|
|
15
|
+
*/
|
|
16
|
+
export default function HoverCard({ trigger, children, position = 'top', width = 180, arrow = false, style, triggerStyle }) {
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const [pos, setPos] = useState({ x: 0, y: 0 });
|
|
19
|
+
const wrapRef = useRef(null);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (open && wrapRef.current) {
|
|
23
|
+
const r = wrapRef.current.getBoundingClientRect();
|
|
24
|
+
setPos({ x: r.left + r.width / 2, y: position === 'top' ? r.top : r.bottom });
|
|
25
|
+
}
|
|
26
|
+
}, [open, position]);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!open) return;
|
|
30
|
+
const close = (e) => {
|
|
31
|
+
if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener('mousedown', close);
|
|
34
|
+
return () => document.removeEventListener('mousedown', close);
|
|
35
|
+
}, [open]);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
ref={wrapRef}
|
|
40
|
+
onMouseEnter={() => setOpen(true)}
|
|
41
|
+
onMouseLeave={() => setOpen(false)}
|
|
42
|
+
style={{ display: 'inline-block', position: 'relative', ...triggerStyle }}
|
|
43
|
+
>
|
|
44
|
+
{trigger}
|
|
45
|
+
{open && (
|
|
46
|
+
<div style={{
|
|
47
|
+
position: 'fixed',
|
|
48
|
+
left: pos.x,
|
|
49
|
+
top: position === 'top' ? 'auto' : pos.y + 6,
|
|
50
|
+
bottom: position === 'top' ? window.innerHeight - pos.y + 6 : 'auto',
|
|
51
|
+
transform: 'translateX(-50%)',
|
|
52
|
+
zIndex: 9999,
|
|
53
|
+
minWidth: width,
|
|
54
|
+
background: 'var(--surface,#fff)',
|
|
55
|
+
border: '1px solid var(--border, #e2e8f0)',
|
|
56
|
+
borderRadius: 'var(--rads, 8px)',
|
|
57
|
+
padding: '10px 14px',
|
|
58
|
+
boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))',
|
|
59
|
+
pointerEvents: 'none',
|
|
60
|
+
animation: 'hoverCardIn .15s ease',
|
|
61
|
+
...style,
|
|
62
|
+
}}>
|
|
63
|
+
{children}
|
|
64
|
+
{arrow && (
|
|
65
|
+
<div style={{
|
|
66
|
+
position: 'absolute', left: '50%',
|
|
67
|
+
[position === 'top' ? 'bottom' : 'top']: -5,
|
|
68
|
+
transform: 'translateX(-50%) rotate(45deg)',
|
|
69
|
+
width: 8, height: 8, background: 'var(--surface,#fff)',
|
|
70
|
+
borderRight: '1px solid var(--border, #e2e8f0)',
|
|
71
|
+
borderBottom: position === 'top' ? 'none' : '1px solid var(--border, #e2e8f0)',
|
|
72
|
+
borderTop: position === 'top' ? '1px solid var(--border, #e2e8f0)' : 'none',
|
|
73
|
+
}} />
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
<style>{`
|
|
78
|
+
@keyframes hoverCardIn {
|
|
79
|
+
from { opacity: 0; transform: translateX(-50%) translateY(4px); }
|
|
80
|
+
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
81
|
+
}
|
|
82
|
+
`}</style>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
package/ui/components/Input.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useRef, useState } from 'react';
|
|
2
|
+
import { Eye, EyeOff } from 'lucide-react';
|
|
2
3
|
|
|
3
4
|
const SIZES = {
|
|
4
5
|
xs: { height: 24, fontSize: 11, paddingH: 6 },
|
|
@@ -23,18 +24,25 @@ export default function Input({
|
|
|
23
24
|
className = '',
|
|
24
25
|
style = {},
|
|
25
26
|
value,
|
|
27
|
+
toggle,
|
|
28
|
+
togglePassword,
|
|
26
29
|
...props
|
|
27
30
|
}) {
|
|
28
31
|
const inputRef = useRef(null);
|
|
29
32
|
const [focused, setFocused] = useState(false);
|
|
30
33
|
const [hovered, setHovered] = useState(false);
|
|
34
|
+
const [revealed, setRevealed] = useState(false);
|
|
31
35
|
const s = SIZES[size] || SIZES.md;
|
|
32
36
|
|
|
33
37
|
const isPasswd = type === 'passwd';
|
|
34
|
-
const
|
|
38
|
+
const isPassword = type === 'password';
|
|
39
|
+
const isSecret = isPasswd || isPassword;
|
|
40
|
+
const showToggle = isSecret && toggle !== false && togglePassword !== false && !props.disabled && !multiline;
|
|
41
|
+
|
|
42
|
+
const resolvedType = isPassword ? (revealed ? 'text' : 'password') : (isPasswd ? 'text' : type);
|
|
35
43
|
const hasValue = value !== undefined && value !== null && value !== '';
|
|
36
44
|
|
|
37
|
-
const passwdStyle = isPasswd ? {
|
|
45
|
+
const passwdStyle = (isPasswd && !revealed) ? {
|
|
38
46
|
WebkitTextSecurity: 'disc',
|
|
39
47
|
textSecurity: 'disc',
|
|
40
48
|
fontFamily: hasValue ? 'monospace' : 'var(--f,var(--sans,inherit))',
|
|
@@ -42,6 +50,13 @@ export default function Input({
|
|
|
42
50
|
letterSpacing: hasValue ? '0.15em' : 'normal',
|
|
43
51
|
} : {};
|
|
44
52
|
|
|
53
|
+
const passwdAttrs = isPasswd ? {
|
|
54
|
+
autoComplete: props.autoComplete !== undefined ? props.autoComplete : 'off',
|
|
55
|
+
'data-1p-ignore': 'true',
|
|
56
|
+
'data-form-type': 'other',
|
|
57
|
+
'data-bwignore': 'true',
|
|
58
|
+
} : {};
|
|
59
|
+
|
|
45
60
|
function handleClear() {
|
|
46
61
|
if (props.onChange) props.onChange({ target: { value: '' } });
|
|
47
62
|
if (onClear) onClear();
|
|
@@ -52,7 +67,8 @@ export default function Input({
|
|
|
52
67
|
const hasIconRight = !!iconRight;
|
|
53
68
|
const showClear = clearable && !!value && !props.disabled && !multiline;
|
|
54
69
|
const hasSuffix = !!suffix && !multiline;
|
|
55
|
-
const showRightSlot = showClear || hasSuffix;
|
|
70
|
+
const showRightSlot = showClear || hasSuffix || showToggle;
|
|
71
|
+
const rightSlotPadding = (showClear && showToggle) ? 54 : (hasIconRight || showRightSlot) ? 34 : s.paddingH;
|
|
56
72
|
|
|
57
73
|
return (
|
|
58
74
|
<div style={{
|
|
@@ -164,7 +180,7 @@ export default function Input({
|
|
|
164
180
|
height: s.height,
|
|
165
181
|
padding: `0 ${s.paddingH}px`,
|
|
166
182
|
paddingLeft: hasIconLeft ? 34 : s.paddingH,
|
|
167
|
-
paddingRight:
|
|
183
|
+
paddingRight: rightSlotPadding,
|
|
168
184
|
outline: 'none',
|
|
169
185
|
transition: 'border-color .14s, box-shadow .14s',
|
|
170
186
|
boxShadow: error
|
|
@@ -178,6 +194,7 @@ export default function Input({
|
|
|
178
194
|
...style,
|
|
179
195
|
}}
|
|
180
196
|
value={value}
|
|
197
|
+
{...passwdAttrs}
|
|
181
198
|
{...props}
|
|
182
199
|
onFocus={e => { setFocused(true); props.onFocus?.(e); }}
|
|
183
200
|
onBlur={e => { setFocused(false); setHovered(false); props.onBlur?.(e); }}
|
|
@@ -186,6 +203,39 @@ export default function Input({
|
|
|
186
203
|
/>
|
|
187
204
|
)}
|
|
188
205
|
|
|
206
|
+
{showToggle && (
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
tabIndex={-1}
|
|
210
|
+
onClick={() => setRevealed(r => !r)}
|
|
211
|
+
style={{
|
|
212
|
+
position: 'absolute',
|
|
213
|
+
right: showClear ? 28 : 8,
|
|
214
|
+
top: '50%',
|
|
215
|
+
transform: 'translateY(-50%)',
|
|
216
|
+
display: 'flex',
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
justifyContent: 'center',
|
|
219
|
+
width: 20,
|
|
220
|
+
height: 20,
|
|
221
|
+
borderRadius: 'var(--radxs,4px)',
|
|
222
|
+
background: 'transparent',
|
|
223
|
+
border: 'none',
|
|
224
|
+
cursor: 'pointer',
|
|
225
|
+
color: 'var(--t3,#9b9daa)',
|
|
226
|
+
padding: 0,
|
|
227
|
+
lineHeight: 0,
|
|
228
|
+
transition: 'color .15s',
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
{revealed ? (
|
|
232
|
+
<EyeOff size={size === 'xs' ? 12 : size === 'sm' ? 13 : 15} />
|
|
233
|
+
) : (
|
|
234
|
+
<Eye size={size === 'xs' ? 12 : size === 'sm' ? 13 : 15} />
|
|
235
|
+
)}
|
|
236
|
+
</button>
|
|
237
|
+
)}
|
|
238
|
+
|
|
189
239
|
{showClear && (
|
|
190
240
|
<button
|
|
191
241
|
type="button"
|
|
@@ -1,145 +1,145 @@
|
|
|
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
|
+
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;
|