cynx-ui 1.2.16 → 1.2.18
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/components/ActionsMenu.jsx +149 -149
- package/components/ActivityCard.jsx +184 -184
- package/components/Button.jsx +159 -159
- package/components/Card.jsx +62 -62
- package/components/CircularProgress.jsx +163 -163
- package/components/Dropdown.jsx +116 -116
- package/components/Dropzone.jsx +29 -29
- package/components/HoverCard.jsx +81 -81
- package/components/LineProgress.jsx +109 -109
- package/components/Modal.jsx +218 -218
- package/components/MultiSelect.jsx +10 -3
- package/components/Pagination.jsx +41 -41
- package/components/SearchableDropdown.jsx +23 -14
- package/components/Spinner.jsx +52 -52
- package/components/StatBarCard.jsx +25 -25
- package/components/StatsCard.jsx +171 -171
- package/components/TabBar.jsx +156 -156
- package/components/Tabs.jsx +16 -16
- package/components/Toast.jsx +88 -88
- package/components/Toggle.jsx +67 -67
- package/components/UptimeBar.jsx +200 -200
- package/components/XTable.jsx +28 -22
- package/index.js +94 -94
- package/package.json +1 -1
package/components/Modal.jsx
CHANGED
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import Button from './Button';
|
|
4
|
-
|
|
5
|
-
const STYLES = `
|
|
6
|
-
/* ── Modal ─────────────────────────────────────────────────── */
|
|
7
|
-
.modal-backdrop {
|
|
8
|
-
position: fixed; inset: 0;
|
|
9
|
-
background: rgba(20,22,41,.45);
|
|
10
|
-
display: flex; align-items: center; justify-content: center;
|
|
11
|
-
z-index: 8000; padding: 20px;
|
|
12
|
-
}
|
|
13
|
-
.modal {
|
|
14
|
-
background: var(--surface); border: 1px solid var(--border);
|
|
15
|
-
border-radius: 14px; width: 100%; max-width: 480px;
|
|
16
|
-
box-shadow: var(--shadow-lg);
|
|
17
|
-
overflow: visible;
|
|
18
|
-
}
|
|
19
|
-
.modal-hdr {
|
|
20
|
-
display: flex; align-items: center; justify-content: space-between;
|
|
21
|
-
padding: 15px 20px; border-bottom: 1px solid var(--border-light);
|
|
22
|
-
border-radius: 14px 14px 0 0;
|
|
23
|
-
}
|
|
24
|
-
.modal-title { font-size: .88rem; font-weight: 700; letter-spacing: -.01em; }
|
|
25
|
-
.modal-body { padding: 20px; overflow: visible; }
|
|
26
|
-
.modal-footer {
|
|
27
|
-
display: flex; justify-content: flex-end; gap: 8px;
|
|
28
|
-
padding: 13px 20px; border-top: 1px solid var(--border-light);
|
|
29
|
-
background: var(--grey-1); border-radius: 0 0 14px 14px;
|
|
30
|
-
}
|
|
31
|
-
.modal-card {
|
|
32
|
-
background: var(--surface); border: 1px solid var(--border);
|
|
33
|
-
border-radius: 14px; width: 100%; max-width: 480px;
|
|
34
|
-
box-shadow: var(--shadow-lg); overflow: visible;
|
|
35
|
-
display: flex; flex-direction: column;
|
|
36
|
-
}
|
|
37
|
-
.modal-close {
|
|
38
|
-
background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px;
|
|
39
|
-
color: var(--muted); display: flex; align-items: center; transition: all .14s;
|
|
40
|
-
}
|
|
41
|
-
.modal-close:hover { color: var(--primary-text); background: var(--grey-1); }
|
|
42
|
-
.confirm-icon {
|
|
43
|
-
width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 12px;
|
|
44
|
-
display: flex; align-items: center; justify-content: center;
|
|
45
|
-
}
|
|
46
|
-
.confirm-icon.danger { background: rgba(246,71,71,.1); }
|
|
47
|
-
.confirm-icon.warning { background: rgba(249,158,44,.1); }
|
|
48
|
-
.confirm-icon.info { background: rgba(39,130,228,.1); }
|
|
49
|
-
|
|
50
|
-
/* Modal scale */
|
|
51
|
-
@keyframes modalIn {
|
|
52
|
-
from { opacity: 0; transform: scale(.97); }
|
|
53
|
-
to { opacity: 1; transform: scale(1); }
|
|
54
|
-
}
|
|
55
|
-
.modal { animation: modalIn .16s ease; }
|
|
56
|
-
|
|
57
|
-
/* ── Modal open animation ──────────────────────────────────── */
|
|
58
|
-
@keyframes modalPop {
|
|
59
|
-
from { opacity: 0; transform: scale(.96) translateY(-8px); }
|
|
60
|
-
to { opacity: 1; transform: scale(1) translateY(0); }
|
|
61
|
-
}
|
|
62
|
-
@keyframes backdropFade {
|
|
63
|
-
from { opacity: 0; }
|
|
64
|
-
to { opacity: 1; }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* ── Modal close animations ────────────────────────────────── */
|
|
68
|
-
@keyframes modalClose {
|
|
69
|
-
from { opacity: 1; transform: scale(1) translateY(0); }
|
|
70
|
-
to { opacity: 0; transform: scale(.96) translateY(-8px); }
|
|
71
|
-
}
|
|
72
|
-
@keyframes backdropClose {
|
|
73
|
-
from { opacity: 1; }
|
|
74
|
-
to { opacity: 0; }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* ── cynx-ui Modal keyframes ────────────────────────────────── */
|
|
78
|
-
@keyframes modalFadeIn { from { opacity:0 } to { opacity:1 } }
|
|
79
|
-
@keyframes modalFadeOut { from { opacity:1 } to { opacity:0 } }
|
|
80
|
-
@keyframes modalCardIn { from { opacity:0; transform:scale(.96) translateY(-8px) } to { opacity:1; transform:scale(1) translateY(0) } }
|
|
81
|
-
@keyframes modalCardOut { from { opacity:1; transform:scale(1) translateY(0) } to { opacity:0; transform:scale(.96) translateY(-8px) } }
|
|
82
|
-
`;
|
|
83
|
-
|
|
84
|
-
let _id = 'cynx-modal-styles';
|
|
85
|
-
function ensureStyles() {
|
|
86
|
-
if (typeof document === 'undefined') return;
|
|
87
|
-
if (document.getElementById(_id)) return;
|
|
88
|
-
const tag = document.createElement('style');
|
|
89
|
-
tag.id = _id;
|
|
90
|
-
tag.textContent = STYLES;
|
|
91
|
-
document.head.appendChild(tag);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Auto-inject on module load
|
|
95
|
-
if (typeof document !== 'undefined') ensureStyles();
|
|
96
|
-
|
|
97
|
-
export function Modal({ open, onClose, onBeforeClose, title, children, footer, maxWidth = 520, bodyStyle }) {
|
|
98
|
-
const [closing, setClosing] = useState(false);
|
|
99
|
-
const mounted = useRef(open);
|
|
100
|
-
|
|
101
|
-
ensureStyles();
|
|
102
|
-
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (open) {
|
|
105
|
-
mounted.current = true;
|
|
106
|
-
setClosing(false);
|
|
107
|
-
document.body.style.overflow = 'hidden';
|
|
108
|
-
}
|
|
109
|
-
return () => { document.body.style.overflow = ''; };
|
|
110
|
-
}, [open]);
|
|
111
|
-
|
|
112
|
-
function close() {
|
|
113
|
-
if (closing) return;
|
|
114
|
-
if (onBeforeClose && onBeforeClose() === false) return;
|
|
115
|
-
setClosing(true);
|
|
116
|
-
setTimeout(() => {
|
|
117
|
-
mounted.current = false;
|
|
118
|
-
setClosing(false);
|
|
119
|
-
onClose();
|
|
120
|
-
}, 260);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (!open) return;
|
|
125
|
-
function onKey(e) { if (e.key === 'Escape') close(); }
|
|
126
|
-
document.addEventListener('keydown', onKey);
|
|
127
|
-
return () => document.removeEventListener('keydown', onKey);
|
|
128
|
-
}, [open, closing]);
|
|
129
|
-
|
|
130
|
-
if (!open && !closing) return null;
|
|
131
|
-
|
|
132
|
-
const resolvedFooter = typeof footer === 'function' ? footer(close) : footer;
|
|
133
|
-
const resolvedChildren = typeof children === 'function' ? children(close) : children;
|
|
134
|
-
|
|
135
|
-
return createPortal(
|
|
136
|
-
<div
|
|
137
|
-
className="modal-backdrop"
|
|
138
|
-
style={{
|
|
139
|
-
position: 'fixed', inset: 0,
|
|
140
|
-
background: 'rgba(20,22,41,.45)',
|
|
141
|
-
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
142
|
-
zIndex: 8000, padding: 20,
|
|
143
|
-
animation: `${closing ? 'modalFadeOut' : 'modalFadeIn'} .26s ease forwards`,
|
|
144
|
-
}}
|
|
145
|
-
onMouseDown={e => { if (e.target === e.currentTarget) close(); }}
|
|
146
|
-
>
|
|
147
|
-
<div
|
|
148
|
-
className="modal-card"
|
|
149
|
-
style={{
|
|
150
|
-
background: 'var(--surface)', border: '1px solid var(--border)',
|
|
151
|
-
borderRadius: 14, width: '100%', maxWidth,
|
|
152
|
-
boxShadow: '0 20px 60px rgba(0,0,0,.25)',
|
|
153
|
-
overflow: 'visible', display: 'flex', flexDirection: 'column',
|
|
154
|
-
animation: `${closing ? 'modalCardOut' : 'modalCardIn'} .26s cubic-bezier(.4,0,.2,1) forwards`,
|
|
155
|
-
}}
|
|
156
|
-
onMouseDown={e => e.stopPropagation()}
|
|
157
|
-
>
|
|
158
|
-
<div className="modal-hdr" style={{
|
|
159
|
-
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
160
|
-
padding: '15px 20px', borderBottom: '1px solid var(--border-light)',
|
|
161
|
-
borderRadius: '14px 14px 0 0',
|
|
162
|
-
}}>
|
|
163
|
-
<span className="modal-title" style={{ fontSize: '.88rem', fontWeight: 700, letterSpacing: '-.01em' }}>{title}</span>
|
|
164
|
-
<button className="modal-close" onClick={close} style={{
|
|
165
|
-
background: 'none', border: 'none', cursor: 'pointer', padding: 4, borderRadius: 6,
|
|
166
|
-
color: 'var(--muted)', display: 'flex', alignItems: 'center', transition: 'all .14s',
|
|
167
|
-
}}
|
|
168
|
-
onMouseEnter={e => { e.currentTarget.style.color = 'var(--primary-text)'; e.currentTarget.style.background = 'var(--grey-1)'; }}
|
|
169
|
-
onMouseLeave={e => { e.currentTarget.style.color = 'var(--muted)'; e.currentTarget.style.background = 'none'; }}>
|
|
170
|
-
<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor"
|
|
171
|
-
strokeWidth="2" strokeLinecap="round">
|
|
172
|
-
<line x1="1.5" y1="1.5" x2="11.5" y2="11.5"/>
|
|
173
|
-
<line x1="11.5" y1="1.5" x2="1.5" y2="11.5"/>
|
|
174
|
-
</svg>
|
|
175
|
-
</button>
|
|
176
|
-
</div>
|
|
177
|
-
<div className="modal-body" style={{ padding: 20, overflowX: 'hidden', overflowY: 'auto', flex: 1, minHeight: 0, ...bodyStyle }}>{resolvedChildren}</div>
|
|
178
|
-
{resolvedFooter && <div className="modal-footer" style={{
|
|
179
|
-
display: 'flex', justifyContent: 'flex-end', gap: 8,
|
|
180
|
-
padding: '13px 20px', borderTop: '1px solid var(--border-light)',
|
|
181
|
-
background: 'var(--grey-1)', borderRadius: '0 0 14px 14px',
|
|
182
|
-
}}>{resolvedFooter}</div>}
|
|
183
|
-
</div>
|
|
184
|
-
</div>,
|
|
185
|
-
document.body
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function Confirm({ open, onClose, onConfirm, title, message, variant = 'danger', confirmLabel = 'Confirm', loading = false }) {
|
|
190
|
-
const iconColor = { danger: 'var(--danger)', warning: 'var(--accent)', info: 'var(--blue)' }[variant] || 'var(--danger)';
|
|
191
|
-
const btnVariant = variant === 'danger' ? 'danger' : 'primary';
|
|
192
|
-
|
|
193
|
-
const icon = variant === 'danger'
|
|
194
|
-
? <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke={iconColor} strokeWidth="2" strokeLinecap="round"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
|
|
195
|
-
: <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke={iconColor} strokeWidth="2" strokeLinecap="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>;
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<Modal open={open} onClose={onClose} title="" maxWidth={400}
|
|
199
|
-
footer={
|
|
200
|
-
<>
|
|
201
|
-
<Button variant="ghost" size="sm" onClick={onClose} disabled={loading}>Cancel</Button>
|
|
202
|
-
<Button variant={btnVariant} size="sm" onClick={onConfirm} disabled={loading}>
|
|
203
|
-
{loading ? 'Please wait...' : confirmLabel}
|
|
204
|
-
</Button>
|
|
205
|
-
</>
|
|
206
|
-
}>
|
|
207
|
-
<div style={{ textAlign: 'center', padding: '4px 0 8px' }}>
|
|
208
|
-
<div className={`confirm-icon ${variant}`} style={{
|
|
209
|
-
width: 48, height: 48, borderRadius: '50%', margin: '0 auto 12px',
|
|
210
|
-
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
211
|
-
background: variant === 'danger' ? 'rgba(246,71,71,.1)' : variant === 'warning' ? 'rgba(249,158,44,.1)' : 'rgba(39,130,228,.1)',
|
|
212
|
-
}}>{icon}</div>
|
|
213
|
-
<div style={{ fontSize: '.9rem', fontWeight: 700, marginBottom: 8 }}>{title}</div>
|
|
214
|
-
{message && <div style={{ fontSize: '.8rem', color: 'var(--muted)', lineHeight: 1.5 }}>{message}</div>}
|
|
215
|
-
</div>
|
|
216
|
-
</Modal>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import Button from './Button';
|
|
4
|
+
|
|
5
|
+
const STYLES = `
|
|
6
|
+
/* ── Modal ─────────────────────────────────────────────────── */
|
|
7
|
+
.modal-backdrop {
|
|
8
|
+
position: fixed; inset: 0;
|
|
9
|
+
background: rgba(20,22,41,.45);
|
|
10
|
+
display: flex; align-items: center; justify-content: center;
|
|
11
|
+
z-index: 8000; padding: 20px;
|
|
12
|
+
}
|
|
13
|
+
.modal {
|
|
14
|
+
background: var(--surface); border: 1px solid var(--border);
|
|
15
|
+
border-radius: 14px; width: 100%; max-width: 480px;
|
|
16
|
+
box-shadow: var(--shadow-lg);
|
|
17
|
+
overflow: visible;
|
|
18
|
+
}
|
|
19
|
+
.modal-hdr {
|
|
20
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
21
|
+
padding: 15px 20px; border-bottom: 1px solid var(--border-light);
|
|
22
|
+
border-radius: 14px 14px 0 0;
|
|
23
|
+
}
|
|
24
|
+
.modal-title { font-size: .88rem; font-weight: 700; letter-spacing: -.01em; }
|
|
25
|
+
.modal-body { padding: 20px; overflow: visible; }
|
|
26
|
+
.modal-footer {
|
|
27
|
+
display: flex; justify-content: flex-end; gap: 8px;
|
|
28
|
+
padding: 13px 20px; border-top: 1px solid var(--border-light);
|
|
29
|
+
background: var(--grey-1); border-radius: 0 0 14px 14px;
|
|
30
|
+
}
|
|
31
|
+
.modal-card {
|
|
32
|
+
background: var(--surface); border: 1px solid var(--border);
|
|
33
|
+
border-radius: 14px; width: 100%; max-width: 480px;
|
|
34
|
+
box-shadow: var(--shadow-lg); overflow: visible;
|
|
35
|
+
display: flex; flex-direction: column;
|
|
36
|
+
}
|
|
37
|
+
.modal-close {
|
|
38
|
+
background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px;
|
|
39
|
+
color: var(--muted); display: flex; align-items: center; transition: all .14s;
|
|
40
|
+
}
|
|
41
|
+
.modal-close:hover { color: var(--primary-text); background: var(--grey-1); }
|
|
42
|
+
.confirm-icon {
|
|
43
|
+
width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 12px;
|
|
44
|
+
display: flex; align-items: center; justify-content: center;
|
|
45
|
+
}
|
|
46
|
+
.confirm-icon.danger { background: rgba(246,71,71,.1); }
|
|
47
|
+
.confirm-icon.warning { background: rgba(249,158,44,.1); }
|
|
48
|
+
.confirm-icon.info { background: rgba(39,130,228,.1); }
|
|
49
|
+
|
|
50
|
+
/* Modal scale */
|
|
51
|
+
@keyframes modalIn {
|
|
52
|
+
from { opacity: 0; transform: scale(.97); }
|
|
53
|
+
to { opacity: 1; transform: scale(1); }
|
|
54
|
+
}
|
|
55
|
+
.modal { animation: modalIn .16s ease; }
|
|
56
|
+
|
|
57
|
+
/* ── Modal open animation ──────────────────────────────────── */
|
|
58
|
+
@keyframes modalPop {
|
|
59
|
+
from { opacity: 0; transform: scale(.96) translateY(-8px); }
|
|
60
|
+
to { opacity: 1; transform: scale(1) translateY(0); }
|
|
61
|
+
}
|
|
62
|
+
@keyframes backdropFade {
|
|
63
|
+
from { opacity: 0; }
|
|
64
|
+
to { opacity: 1; }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* ── Modal close animations ────────────────────────────────── */
|
|
68
|
+
@keyframes modalClose {
|
|
69
|
+
from { opacity: 1; transform: scale(1) translateY(0); }
|
|
70
|
+
to { opacity: 0; transform: scale(.96) translateY(-8px); }
|
|
71
|
+
}
|
|
72
|
+
@keyframes backdropClose {
|
|
73
|
+
from { opacity: 1; }
|
|
74
|
+
to { opacity: 0; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ── cynx-ui Modal keyframes ────────────────────────────────── */
|
|
78
|
+
@keyframes modalFadeIn { from { opacity:0 } to { opacity:1 } }
|
|
79
|
+
@keyframes modalFadeOut { from { opacity:1 } to { opacity:0 } }
|
|
80
|
+
@keyframes modalCardIn { from { opacity:0; transform:scale(.96) translateY(-8px) } to { opacity:1; transform:scale(1) translateY(0) } }
|
|
81
|
+
@keyframes modalCardOut { from { opacity:1; transform:scale(1) translateY(0) } to { opacity:0; transform:scale(.96) translateY(-8px) } }
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
let _id = 'cynx-modal-styles';
|
|
85
|
+
function ensureStyles() {
|
|
86
|
+
if (typeof document === 'undefined') return;
|
|
87
|
+
if (document.getElementById(_id)) return;
|
|
88
|
+
const tag = document.createElement('style');
|
|
89
|
+
tag.id = _id;
|
|
90
|
+
tag.textContent = STYLES;
|
|
91
|
+
document.head.appendChild(tag);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Auto-inject on module load
|
|
95
|
+
if (typeof document !== 'undefined') ensureStyles();
|
|
96
|
+
|
|
97
|
+
export function Modal({ open, onClose, onBeforeClose, title, children, footer, maxWidth = 520, bodyStyle }) {
|
|
98
|
+
const [closing, setClosing] = useState(false);
|
|
99
|
+
const mounted = useRef(open);
|
|
100
|
+
|
|
101
|
+
ensureStyles();
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (open) {
|
|
105
|
+
mounted.current = true;
|
|
106
|
+
setClosing(false);
|
|
107
|
+
document.body.style.overflow = 'hidden';
|
|
108
|
+
}
|
|
109
|
+
return () => { document.body.style.overflow = ''; };
|
|
110
|
+
}, [open]);
|
|
111
|
+
|
|
112
|
+
function close() {
|
|
113
|
+
if (closing) return;
|
|
114
|
+
if (onBeforeClose && onBeforeClose() === false) return;
|
|
115
|
+
setClosing(true);
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
mounted.current = false;
|
|
118
|
+
setClosing(false);
|
|
119
|
+
onClose();
|
|
120
|
+
}, 260);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!open) return;
|
|
125
|
+
function onKey(e) { if (e.key === 'Escape') close(); }
|
|
126
|
+
document.addEventListener('keydown', onKey);
|
|
127
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
128
|
+
}, [open, closing]);
|
|
129
|
+
|
|
130
|
+
if (!open && !closing) return null;
|
|
131
|
+
|
|
132
|
+
const resolvedFooter = typeof footer === 'function' ? footer(close) : footer;
|
|
133
|
+
const resolvedChildren = typeof children === 'function' ? children(close) : children;
|
|
134
|
+
|
|
135
|
+
return createPortal(
|
|
136
|
+
<div
|
|
137
|
+
className="modal-backdrop"
|
|
138
|
+
style={{
|
|
139
|
+
position: 'fixed', inset: 0,
|
|
140
|
+
background: 'rgba(20,22,41,.45)',
|
|
141
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
142
|
+
zIndex: 8000, padding: 20,
|
|
143
|
+
animation: `${closing ? 'modalFadeOut' : 'modalFadeIn'} .26s ease forwards`,
|
|
144
|
+
}}
|
|
145
|
+
onMouseDown={e => { if (e.target === e.currentTarget) close(); }}
|
|
146
|
+
>
|
|
147
|
+
<div
|
|
148
|
+
className="modal-card"
|
|
149
|
+
style={{
|
|
150
|
+
background: 'var(--surface)', border: '1px solid var(--border)',
|
|
151
|
+
borderRadius: 14, width: '100%', maxWidth,
|
|
152
|
+
boxShadow: '0 20px 60px rgba(0,0,0,.25)',
|
|
153
|
+
overflow: 'visible', display: 'flex', flexDirection: 'column',
|
|
154
|
+
animation: `${closing ? 'modalCardOut' : 'modalCardIn'} .26s cubic-bezier(.4,0,.2,1) forwards`,
|
|
155
|
+
}}
|
|
156
|
+
onMouseDown={e => e.stopPropagation()}
|
|
157
|
+
>
|
|
158
|
+
<div className="modal-hdr" style={{
|
|
159
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
160
|
+
padding: '15px 20px', borderBottom: '1px solid var(--border-light)',
|
|
161
|
+
borderRadius: '14px 14px 0 0',
|
|
162
|
+
}}>
|
|
163
|
+
<span className="modal-title" style={{ fontSize: '.88rem', fontWeight: 700, letterSpacing: '-.01em' }}>{title}</span>
|
|
164
|
+
<button className="modal-close" onClick={close} style={{
|
|
165
|
+
background: 'none', border: 'none', cursor: 'pointer', padding: 4, borderRadius: 6,
|
|
166
|
+
color: 'var(--muted)', display: 'flex', alignItems: 'center', transition: 'all .14s',
|
|
167
|
+
}}
|
|
168
|
+
onMouseEnter={e => { e.currentTarget.style.color = 'var(--primary-text)'; e.currentTarget.style.background = 'var(--grey-1)'; }}
|
|
169
|
+
onMouseLeave={e => { e.currentTarget.style.color = 'var(--muted)'; e.currentTarget.style.background = 'none'; }}>
|
|
170
|
+
<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor"
|
|
171
|
+
strokeWidth="2" strokeLinecap="round">
|
|
172
|
+
<line x1="1.5" y1="1.5" x2="11.5" y2="11.5"/>
|
|
173
|
+
<line x1="11.5" y1="1.5" x2="1.5" y2="11.5"/>
|
|
174
|
+
</svg>
|
|
175
|
+
</button>
|
|
176
|
+
</div>
|
|
177
|
+
<div className="modal-body" style={{ padding: 20, overflowX: 'hidden', overflowY: 'auto', flex: 1, minHeight: 0, ...bodyStyle }}>{resolvedChildren}</div>
|
|
178
|
+
{resolvedFooter && <div className="modal-footer" style={{
|
|
179
|
+
display: 'flex', justifyContent: 'flex-end', gap: 8,
|
|
180
|
+
padding: '13px 20px', borderTop: '1px solid var(--border-light)',
|
|
181
|
+
background: 'var(--grey-1)', borderRadius: '0 0 14px 14px',
|
|
182
|
+
}}>{resolvedFooter}</div>}
|
|
183
|
+
</div>
|
|
184
|
+
</div>,
|
|
185
|
+
document.body
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function Confirm({ open, onClose, onConfirm, title, message, variant = 'danger', confirmLabel = 'Confirm', loading = false }) {
|
|
190
|
+
const iconColor = { danger: 'var(--danger)', warning: 'var(--accent)', info: 'var(--blue)' }[variant] || 'var(--danger)';
|
|
191
|
+
const btnVariant = variant === 'danger' ? 'danger' : 'primary';
|
|
192
|
+
|
|
193
|
+
const icon = variant === 'danger'
|
|
194
|
+
? <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke={iconColor} strokeWidth="2" strokeLinecap="round"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
|
|
195
|
+
: <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke={iconColor} strokeWidth="2" strokeLinecap="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>;
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<Modal open={open} onClose={onClose} title="" maxWidth={400}
|
|
199
|
+
footer={
|
|
200
|
+
<>
|
|
201
|
+
<Button variant="ghost" size="sm" onClick={onClose} disabled={loading}>Cancel</Button>
|
|
202
|
+
<Button variant={btnVariant} size="sm" onClick={onConfirm} disabled={loading}>
|
|
203
|
+
{loading ? 'Please wait...' : confirmLabel}
|
|
204
|
+
</Button>
|
|
205
|
+
</>
|
|
206
|
+
}>
|
|
207
|
+
<div style={{ textAlign: 'center', padding: '4px 0 8px' }}>
|
|
208
|
+
<div className={`confirm-icon ${variant}`} style={{
|
|
209
|
+
width: 48, height: 48, borderRadius: '50%', margin: '0 auto 12px',
|
|
210
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
211
|
+
background: variant === 'danger' ? 'rgba(246,71,71,.1)' : variant === 'warning' ? 'rgba(249,158,44,.1)' : 'rgba(39,130,228,.1)',
|
|
212
|
+
}}>{icon}</div>
|
|
213
|
+
<div style={{ fontSize: '.9rem', fontWeight: 700, marginBottom: 8 }}>{title}</div>
|
|
214
|
+
{message && <div style={{ fontSize: '.8rem', color: 'var(--muted)', lineHeight: 1.5 }}>{message}</div>}
|
|
215
|
+
</div>
|
|
216
|
+
</Modal>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
@@ -28,8 +28,13 @@ export default function MultiSelect({ value = [], onChange, options = [], placeh
|
|
|
28
28
|
setQuery('');
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
document.addEventListener('mousedown', close, true);
|
|
33
|
+
}, 0);
|
|
34
|
+
return () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
document.removeEventListener('mousedown', close, true);
|
|
37
|
+
};
|
|
33
38
|
}, [open]);
|
|
34
39
|
|
|
35
40
|
useEffect(() => {
|
|
@@ -97,7 +102,9 @@ export default function MultiSelect({ value = [], onChange, options = [], placeh
|
|
|
97
102
|
) : filtered.map(o => {
|
|
98
103
|
const isSelected = selected.some(s => s.value === o.value);
|
|
99
104
|
return (
|
|
100
|
-
<div key={o.value}
|
|
105
|
+
<div key={o.value}
|
|
106
|
+
onMouseDown={e => e.stopPropagation()}
|
|
107
|
+
onClick={() => toggle(o)} style={{
|
|
101
108
|
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
102
109
|
padding: '8px 12px', fontSize: '.8rem', cursor: 'pointer',
|
|
103
110
|
background: isSelected ? 'var(--accent-bg)' : 'transparent',
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import Button from './Button';
|
|
2
|
-
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
3
|
-
|
|
4
|
-
export function Pagination({ page, pages, total, perPage, onChange }) {
|
|
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', alignItems: 'center', justifyContent: 'space-between',
|
|
20
|
-
padding: '10px 16px',
|
|
21
|
-
borderTop: '1px solid var(--border-light)',
|
|
22
|
-
background: 'var(--surface)',
|
|
23
|
-
borderRadius: '0 0 var(--rad) var(--rad)',
|
|
24
|
-
}}>
|
|
25
|
-
{start !== null && (
|
|
26
|
-
<div style={{ fontSize: '.72rem', color: 'var(--muted)', fontFamily: 'var(--mono)' }}>
|
|
27
|
-
{start}–{end} of {total}
|
|
28
|
-
</div>
|
|
29
|
-
)}
|
|
30
|
-
<div style={{ display: 'flex', gap: 4, alignItems: 'center', marginLeft: start !== null ? 'auto' : 0 }}>
|
|
31
|
-
<Button variant="ghost" size="xs" icon={<ChevronLeft size={14} />} onClick={() => onChange(page - 1)} disabled={page <= 1} />
|
|
32
|
-
{items.map((item, i) =>
|
|
33
|
-
item === '...'
|
|
34
|
-
? <span key={`e${i}`} style={{ padding: '0 4px', color: 'var(--muted)', fontSize: '.78rem' }}>…</span>
|
|
35
|
-
: <Button key={item} variant={item === page ? 'primary' : 'no-line'} size="xs" onClick={() => onChange(item)} style={{ minWidth: 28 }}>{item}</Button>
|
|
36
|
-
)}
|
|
37
|
-
<Button variant="ghost" size="xs" icon={<ChevronRight size={14} />} onClick={() => onChange(page + 1)} disabled={page >= totalPages} />
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
1
|
+
import Button from './Button';
|
|
2
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
export function Pagination({ page, pages, total, perPage, onChange }) {
|
|
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', alignItems: 'center', justifyContent: 'space-between',
|
|
20
|
+
padding: '10px 16px',
|
|
21
|
+
borderTop: '1px solid var(--border-light)',
|
|
22
|
+
background: 'var(--surface)',
|
|
23
|
+
borderRadius: '0 0 var(--rad) var(--rad)',
|
|
24
|
+
}}>
|
|
25
|
+
{start !== null && (
|
|
26
|
+
<div style={{ fontSize: '.72rem', color: 'var(--muted)', fontFamily: 'var(--mono)' }}>
|
|
27
|
+
{start}–{end} of {total}
|
|
28
|
+
</div>
|
|
29
|
+
)}
|
|
30
|
+
<div style={{ display: 'flex', gap: 4, alignItems: 'center', marginLeft: start !== null ? 'auto' : 0 }}>
|
|
31
|
+
<Button variant="ghost" size="xs" icon={<ChevronLeft size={14} />} onClick={() => onChange(page - 1)} disabled={page <= 1} />
|
|
32
|
+
{items.map((item, i) =>
|
|
33
|
+
item === '...'
|
|
34
|
+
? <span key={`e${i}`} style={{ padding: '0 4px', color: 'var(--muted)', fontSize: '.78rem' }}>…</span>
|
|
35
|
+
: <Button key={item} variant={item === page ? 'primary' : 'no-line'} size="xs" onClick={() => onChange(item)} style={{ minWidth: 28 }}>{item}</Button>
|
|
36
|
+
)}
|
|
37
|
+
<Button variant="ghost" size="xs" icon={<ChevronRight size={14} />} onClick={() => onChange(page + 1)} disabled={page >= totalPages} />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -2,14 +2,13 @@ import { useState, useRef, useEffect } from 'react';
|
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { ChevronDown, Search, Check } from 'lucide-react';
|
|
4
4
|
|
|
5
|
-
// SearchableDropdown — reusable searchable select
|
|
6
|
-
// Props: value, onChange, options [{value, label}], placeholder
|
|
7
5
|
export function SearchableDropdown({ value, onChange, options = [], placeholder = 'Select...' }) {
|
|
8
6
|
const [open, setOpen] = useState(false);
|
|
9
7
|
const [query, setQuery] = useState('');
|
|
10
8
|
const ref = useRef(null);
|
|
11
9
|
const inputRef = useRef(null);
|
|
12
10
|
const btnRef = useRef(null);
|
|
11
|
+
const menuRef = useRef(null);
|
|
13
12
|
const [menuStyle, setMenuStyle] = useState({});
|
|
14
13
|
|
|
15
14
|
const selected = options.find(o => o.value === value);
|
|
@@ -20,9 +19,19 @@ export function SearchableDropdown({ value, onChange, options = [], placeholder
|
|
|
20
19
|
|
|
21
20
|
useEffect(() => {
|
|
22
21
|
if (!open) return;
|
|
23
|
-
function close(e) {
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
function close(e) {
|
|
23
|
+
if (!ref.current?.contains(e.target) && !menuRef.current?.contains(e.target)) {
|
|
24
|
+
setOpen(false);
|
|
25
|
+
setQuery('');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const timer = setTimeout(() => {
|
|
29
|
+
document.addEventListener('mousedown', close, true);
|
|
30
|
+
}, 0);
|
|
31
|
+
return () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
document.removeEventListener('mousedown', close, true);
|
|
34
|
+
};
|
|
26
35
|
}, [open]);
|
|
27
36
|
|
|
28
37
|
useEffect(() => {
|
|
@@ -35,7 +44,7 @@ export function SearchableDropdown({ value, onChange, options = [], placeholder
|
|
|
35
44
|
top: rect.bottom + 4,
|
|
36
45
|
left: rect.left,
|
|
37
46
|
width: rect.width,
|
|
38
|
-
zIndex:
|
|
47
|
+
zIndex: 999999,
|
|
39
48
|
});
|
|
40
49
|
setTimeout(() => inputRef.current?.focus(), 50);
|
|
41
50
|
}, [open]);
|
|
@@ -51,13 +60,13 @@ export function SearchableDropdown({ value, onChange, options = [], placeholder
|
|
|
51
60
|
<button type="button" ref={btnRef} onClick={() => setOpen(o => !o)} style={{
|
|
52
61
|
display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 6,
|
|
53
62
|
width: '100%', padding: '6px 10px', height: 32,
|
|
54
|
-
border:
|
|
63
|
+
border: `1px solid ${open ? 'var(--accent)' : 'var(--border)'}`, borderRadius: 'var(--rads)',
|
|
55
64
|
background: 'var(--surface)', color: selected ? 'var(--primary-text)' : 'var(--muted)',
|
|
56
65
|
cursor: 'pointer', fontSize: '.8rem', fontFamily: 'var(--sans)',
|
|
57
|
-
transition: 'border-color .15s', boxShadow: 'var(--shadow)',
|
|
66
|
+
transition: 'border-color .15s', boxShadow: open ? '0 0 0 3px rgba(249,158,44,.12)' : 'var(--shadow)',
|
|
58
67
|
}}
|
|
59
|
-
onMouseEnter={e => e.currentTarget.style.borderColor = 'var(--accent)'}
|
|
60
|
-
onMouseLeave={e => e.currentTarget.style.borderColor = 'var(--border)'}>
|
|
68
|
+
onMouseEnter={e => { if (!open) e.currentTarget.style.borderColor = 'var(--accent)'; }}
|
|
69
|
+
onMouseLeave={e => { if (!open) e.currentTarget.style.borderColor = 'var(--border)'; }}>
|
|
61
70
|
<span style={{ flex: 1, textAlign: 'left', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
62
71
|
{selected?.label || placeholder}
|
|
63
72
|
</span>
|
|
@@ -65,13 +74,12 @@ export function SearchableDropdown({ value, onChange, options = [], placeholder
|
|
|
65
74
|
</button>
|
|
66
75
|
|
|
67
76
|
{open && createPortal(
|
|
68
|
-
<div style={{
|
|
77
|
+
<div ref={menuRef} style={{
|
|
69
78
|
...menuStyle,
|
|
70
79
|
background: 'var(--surface)', border: '1px solid var(--border)',
|
|
71
80
|
borderRadius: 'var(--rads)', boxShadow: 'var(--shadow-lg)',
|
|
72
81
|
overflow: 'hidden', animation: 'dropdownOpen .12s ease',
|
|
73
82
|
}}>
|
|
74
|
-
{/* Search input */}
|
|
75
83
|
<div style={{ padding: '6px 8px', borderBottom: '1px solid var(--border-light)', display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
76
84
|
<Search size={12} style={{ color: 'var(--muted)', flexShrink: 0 }} />
|
|
77
85
|
<input
|
|
@@ -82,12 +90,13 @@ export function SearchableDropdown({ value, onChange, options = [], placeholder
|
|
|
82
90
|
style={{ border: 'none', background: 'transparent', outline: 'none', fontSize: '.78rem', color: 'var(--primary-text)', width: '100%', fontFamily: 'var(--sans)' }}
|
|
83
91
|
/>
|
|
84
92
|
</div>
|
|
85
|
-
{/* Options */}
|
|
86
93
|
<div style={{ maxHeight: 200, overflowY: 'auto', scrollbarWidth: 'thin' }}>
|
|
87
94
|
{filtered.length === 0 ? (
|
|
88
95
|
<div style={{ padding: '10px 12px', fontSize: '.78rem', color: 'var(--muted)', textAlign: 'center' }}>No results</div>
|
|
89
96
|
) : filtered.map(o => (
|
|
90
|
-
<div key={o.value}
|
|
97
|
+
<div key={o.value}
|
|
98
|
+
onMouseDown={e => e.stopPropagation()}
|
|
99
|
+
onClick={() => select(o.value)} style={{
|
|
91
100
|
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
|
92
101
|
padding: '8px 12px', fontSize: '.8rem', cursor: 'pointer',
|
|
93
102
|
background: o.value === value ? 'var(--accent-bg)' : 'transparent',
|