cynx-lib 1.3.28
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/index.js +3 -0
- package/package.json +36 -0
- package/ui/components/ActionsMenu.jsx +158 -0
- package/ui/components/ActivityCard.jsx +184 -0
- package/ui/components/AuthOverlay.jsx +94 -0
- package/ui/components/Badge.jsx +186 -0
- package/ui/components/BrandingCard.jsx +146 -0
- package/ui/components/Button.jsx +148 -0
- package/ui/components/Card.jsx +132 -0
- package/ui/components/Checkbox.jsx +59 -0
- package/ui/components/ChipSelect.jsx +54 -0
- package/ui/components/CircularProgress.jsx +216 -0
- package/ui/components/Confirm.jsx +79 -0
- package/ui/components/DatePicker.jsx +605 -0
- package/ui/components/Divider.jsx +96 -0
- package/ui/components/Dropzone.jsx +203 -0
- package/ui/components/FilePicker.jsx +205 -0
- package/ui/components/HoverCard.jsx +81 -0
- package/ui/components/ImageUpload.jsx +147 -0
- package/ui/components/InfoBadge.jsx +204 -0
- package/ui/components/Input.jsx +229 -0
- package/ui/components/LineProgress.jsx +133 -0
- package/ui/components/LinearProgress.jsx +132 -0
- package/ui/components/Modal.jsx +212 -0
- package/ui/components/Pagination.jsx +52 -0
- package/ui/components/PulseDot.jsx +77 -0
- package/ui/components/Select.jsx +415 -0
- package/ui/components/Skeleton.jsx +118 -0
- package/ui/components/Spinner.jsx +108 -0
- package/ui/components/StatBarCard.jsx +25 -0
- package/ui/components/StatsBar.jsx +88 -0
- package/ui/components/StatsCard.jsx +171 -0
- package/ui/components/TabBar.jsx +404 -0
- package/ui/components/Tabs.jsx +29 -0
- package/ui/components/TimePicker.jsx +1069 -0
- package/ui/components/Toast.jsx +106 -0
- package/ui/components/Toggle.jsx +67 -0
- package/ui/components/UptimeBar.jsx +135 -0
- package/ui/components/XTable.jsx +44 -0
- package/ui/index.js +97 -0
- package/utils/index.js +11 -0
- package/utils/utils/oidc.js +209 -0
- package/utils/utils/realtime.js +1040 -0
- package/utils/utils/storage.js +393 -0
- package/utils/utils/tz.js +625 -0
- package/utils/utils/uid.js +252 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const SIZE_CONFIG = {
|
|
4
|
+
xs: { hMargin: '8px 0', vMargin: '0 4px', vHeight: '14px', fontSize: '.7rem', padding: '0 8px' },
|
|
5
|
+
sm: { hMargin: '12px 0', vMargin: '0 8px', vHeight: '18px', fontSize: '.75rem', padding: '0 10px' },
|
|
6
|
+
md: { hMargin: '16px 0', vMargin: '0 12px', vHeight: '24px', fontSize: '.82rem', padding: '0 12px' },
|
|
7
|
+
lg: { hMargin: '24px 0', vMargin: '0 16px', vHeight: '32px', fontSize: '.9rem', padding: '0 16px' },
|
|
8
|
+
xl: { hMargin: '32px 0', vMargin: '0 24px', vHeight: '48px', fontSize: '1rem', padding: '0 20px' },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default function Divider({
|
|
12
|
+
children,
|
|
13
|
+
label,
|
|
14
|
+
orientation = 'horizontal',
|
|
15
|
+
align = 'center',
|
|
16
|
+
size = 'md',
|
|
17
|
+
color = 'var(--border-light, #ebebf0)',
|
|
18
|
+
thickness = 1,
|
|
19
|
+
variant = 'solid',
|
|
20
|
+
style = {},
|
|
21
|
+
className = '',
|
|
22
|
+
...props
|
|
23
|
+
}) {
|
|
24
|
+
const content = children || label;
|
|
25
|
+
const cfg = SIZE_CONFIG[size] || SIZE_CONFIG.md;
|
|
26
|
+
const thickStr = typeof thickness === 'number' ? `${thickness}px` : thickness;
|
|
27
|
+
const lineStyle = `${thickStr} ${variant} ${color}`;
|
|
28
|
+
|
|
29
|
+
if (orientation === 'vertical') {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
className={`cynx-divider cynx-divider-vertical ${className}`}
|
|
33
|
+
style={{
|
|
34
|
+
display: 'inline-block',
|
|
35
|
+
width: 0,
|
|
36
|
+
height: style.height || cfg.vHeight,
|
|
37
|
+
margin: style.margin || cfg.vMargin,
|
|
38
|
+
borderLeft: lineStyle,
|
|
39
|
+
verticalAlign: 'middle',
|
|
40
|
+
alignSelf: 'center',
|
|
41
|
+
flexShrink: 0,
|
|
42
|
+
...style,
|
|
43
|
+
}}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Horizontal Divider
|
|
50
|
+
if (content) {
|
|
51
|
+
const leftFlex = align === 'left' ? '0 0 16px' : '1';
|
|
52
|
+
const rightFlex = align === 'right' ? '0 0 16px' : '1';
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
className={`cynx-divider cynx-divider-horizontal ${className}`}
|
|
57
|
+
style={{
|
|
58
|
+
display: 'flex',
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
width: '100%',
|
|
61
|
+
margin: style.margin || cfg.hMargin,
|
|
62
|
+
...style,
|
|
63
|
+
}}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
<div style={{ flex: leftFlex, borderBottom: lineStyle }} />
|
|
67
|
+
<span
|
|
68
|
+
style={{
|
|
69
|
+
padding: cfg.padding,
|
|
70
|
+
fontSize: cfg.fontSize,
|
|
71
|
+
color: 'var(--muted, #9b9daa)',
|
|
72
|
+
fontWeight: 500,
|
|
73
|
+
whiteSpace: 'nowrap',
|
|
74
|
+
lineHeight: 1,
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{content}
|
|
78
|
+
</span>
|
|
79
|
+
<div style={{ flex: rightFlex, borderBottom: lineStyle }} />
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
className={`cynx-divider cynx-divider-horizontal ${className}`}
|
|
87
|
+
style={{
|
|
88
|
+
width: '100%',
|
|
89
|
+
margin: style.margin || cfg.hMargin,
|
|
90
|
+
borderBottom: lineStyle,
|
|
91
|
+
...style,
|
|
92
|
+
}}
|
|
93
|
+
{...props}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { useState, useRef } from 'react';
|
|
2
|
+
import { UploadCloud, Paperclip, FileCheck, X, Eye, Trash2 } from 'lucide-react';
|
|
3
|
+
import LineProgress from './LineProgress.jsx';
|
|
4
|
+
import Badge from './Badge.jsx';
|
|
5
|
+
import Button from './Button.jsx';
|
|
6
|
+
|
|
7
|
+
function formatBytes(bytes, decimals = 1) {
|
|
8
|
+
if (!bytes || bytes === 0) return '0 B';
|
|
9
|
+
const k = 1024;
|
|
10
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
11
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
12
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
13
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function Dropzone({
|
|
17
|
+
onFiles,
|
|
18
|
+
onFile,
|
|
19
|
+
accept = 'image/*,application/pdf,.*',
|
|
20
|
+
multiple = true,
|
|
21
|
+
hint = 'Поддерживаются изображения, PDF документы и любые файлы',
|
|
22
|
+
uploadingFiles = [],
|
|
23
|
+
existingFiles = [],
|
|
24
|
+
onRemoveUploading,
|
|
25
|
+
onRemoveExisting,
|
|
26
|
+
onPreview,
|
|
27
|
+
label = 'Прикрепить файлы (Фото, PDF, документы)',
|
|
28
|
+
}) {
|
|
29
|
+
const [over, setOver] = useState(false);
|
|
30
|
+
const inputRef = useRef(null);
|
|
31
|
+
|
|
32
|
+
const handleFiles = (fileList) => {
|
|
33
|
+
const arr = Array.from(fileList || []);
|
|
34
|
+
if (arr.length === 0) return;
|
|
35
|
+
if (onFiles) onFiles(arr);
|
|
36
|
+
else if (onFile) arr.forEach(f => onFile(f));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleDrop = (e) => {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
setOver(false);
|
|
43
|
+
if (e.dataTransfer && e.dataTransfer.files) {
|
|
44
|
+
handleFiles(e.dataTransfer.files);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
50
|
+
{label && (
|
|
51
|
+
<label style={{ fontSize: 11, fontWeight: 600, color: 'var(--t2, #797b8d)', textTransform: 'uppercase', letterSpacing: '.08em', display: 'block' }}>
|
|
52
|
+
{label}
|
|
53
|
+
</label>
|
|
54
|
+
)}
|
|
55
|
+
|
|
56
|
+
<div
|
|
57
|
+
className={`dropzone${over ? ' over' : ''}`}
|
|
58
|
+
onDragOver={e => { e.preventDefault(); e.stopPropagation(); setOver(true); }}
|
|
59
|
+
onDragLeave={e => { e.preventDefault(); e.stopPropagation(); setOver(false); }}
|
|
60
|
+
onDrop={handleDrop}
|
|
61
|
+
onClick={() => inputRef.current?.click()}
|
|
62
|
+
style={{
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
justifyContent: 'center',
|
|
67
|
+
padding: '20px 20px',
|
|
68
|
+
border: `2px dashed ${over ? 'var(--accent, #3b82f6)' : 'var(--border-light, #ebebf0)'}`,
|
|
69
|
+
borderRadius: 'var(--rad, 10px)',
|
|
70
|
+
cursor: 'pointer',
|
|
71
|
+
background: over ? 'rgba(59, 130, 246, 0.08)' : 'var(--grey-1, #f5f5f8)',
|
|
72
|
+
transition: 'all .2s ease',
|
|
73
|
+
textAlign: 'center',
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<input
|
|
77
|
+
ref={inputRef}
|
|
78
|
+
type="file"
|
|
79
|
+
accept={accept}
|
|
80
|
+
multiple={multiple}
|
|
81
|
+
onChange={e => {
|
|
82
|
+
handleFiles(e.target.files);
|
|
83
|
+
e.target.value = '';
|
|
84
|
+
}}
|
|
85
|
+
style={{ display: 'none' }}
|
|
86
|
+
/>
|
|
87
|
+
<UploadCloud size={24} color="var(--accent, #3b82f6)" style={{ marginBottom: 6, pointerEvents: 'none' }} />
|
|
88
|
+
<span style={{ fontSize: '.82rem', fontWeight: 600, pointerEvents: 'none' }}>
|
|
89
|
+
Выберите файлы, перетащите их сюда или вставьте через Ctrl+V
|
|
90
|
+
</span>
|
|
91
|
+
{hint && <span style={{ fontSize: '.72rem', color: 'var(--muted, #797b8d)', marginTop: 2, pointerEvents: 'none' }}>{hint}</span>}
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
{/* Uploading progress items */}
|
|
95
|
+
{uploadingFiles.length > 0 && (
|
|
96
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
|
97
|
+
{uploadingFiles.map((item) => (
|
|
98
|
+
<div
|
|
99
|
+
key={item.tempId || item.name}
|
|
100
|
+
style={{
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flexDirection: 'column',
|
|
103
|
+
gap: 4,
|
|
104
|
+
padding: '8px 10px',
|
|
105
|
+
background: 'var(--surface, #ffffff)',
|
|
106
|
+
border: '1px solid var(--border-light, #ebebf0)',
|
|
107
|
+
borderRadius: 'var(--rads, 8px)',
|
|
108
|
+
fontSize: '.8rem',
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
112
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
|
|
113
|
+
{item.status === 'uploading' && <Paperclip size={14} color="var(--accent, #f99e2c)" />}
|
|
114
|
+
{item.status === 'done' && <FileCheck size={14} color="var(--success, #22c55e)" />}
|
|
115
|
+
{item.status === 'error' && <X size={14} color="var(--err, #ef4444)" />}
|
|
116
|
+
<span style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', fontWeight: 500 }}>
|
|
117
|
+
{item.name} <span style={{ color: 'var(--muted, #797b8d)', fontSize: '.72rem' }}>({formatBytes(item.size)})</span>
|
|
118
|
+
</span>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
122
|
+
{item.status === 'uploading' && (
|
|
123
|
+
<span style={{ fontSize: '.75rem', fontWeight: 600, color: 'var(--accent, #3b82f6)' }}>
|
|
124
|
+
{item.progress}%
|
|
125
|
+
</span>
|
|
126
|
+
)}
|
|
127
|
+
{item.status === 'done' && <Badge variant="ok" size="xs">Загружен</Badge>}
|
|
128
|
+
{item.status === 'error' && <Badge variant="err" size="xs">{item.error || 'Ошибка'}</Badge>}
|
|
129
|
+
{onRemoveUploading && (
|
|
130
|
+
<button
|
|
131
|
+
onClick={(e) => { e.stopPropagation(); onRemoveUploading(item.tempId); }}
|
|
132
|
+
style={{ border: 'none', background: 'none', cursor: 'pointer', padding: 2, color: 'var(--muted, #797b8d)' }}
|
|
133
|
+
>
|
|
134
|
+
<X size={14} />
|
|
135
|
+
</button>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{item.status === 'uploading' && (
|
|
141
|
+
<LineProgress
|
|
142
|
+
value={item.progress}
|
|
143
|
+
color="var(--accent, #3b82f6)"
|
|
144
|
+
height={4}
|
|
145
|
+
showPercent={false}
|
|
146
|
+
style={{ marginTop: 2 }}
|
|
147
|
+
/>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
{/* Existing saved files list */}
|
|
155
|
+
{existingFiles.length > 0 && (
|
|
156
|
+
<div style={{ marginTop: 4 }}>
|
|
157
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
|
158
|
+
{existingFiles.map((f) => (
|
|
159
|
+
<div
|
|
160
|
+
key={f.id}
|
|
161
|
+
style={{
|
|
162
|
+
display: 'flex',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
justifyContent: 'space-between',
|
|
165
|
+
padding: '6px 10px',
|
|
166
|
+
background: 'var(--surface, #ffffff)',
|
|
167
|
+
border: '1px solid var(--border-light, #ebebf0)',
|
|
168
|
+
borderRadius: 'var(--rads, 8px)',
|
|
169
|
+
fontSize: '.8rem',
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
|
|
173
|
+
<Paperclip size={14} color="var(--accent, #f99e2c)" />
|
|
174
|
+
<span style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', fontWeight: 500 }}>
|
|
175
|
+
{f.original_name || f.originalName} <span style={{ color: 'var(--muted, #797b8d)', fontSize: '.72rem' }}>({formatBytes(f.file_size || f.fileSize)})</span>
|
|
176
|
+
</span>
|
|
177
|
+
</div>
|
|
178
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
179
|
+
{onPreview && (
|
|
180
|
+
<Button
|
|
181
|
+
variant="ghost"
|
|
182
|
+
size="xs"
|
|
183
|
+
icon={<Eye size={13} />}
|
|
184
|
+
onClick={(e) => { e.stopPropagation(); onPreview(f); }}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
{onRemoveExisting && (
|
|
188
|
+
<Button
|
|
189
|
+
variant="ghost"
|
|
190
|
+
size="xs"
|
|
191
|
+
icon={<Trash2 size={13} color="var(--err, #f64747)" />}
|
|
192
|
+
onClick={(e) => { e.stopPropagation(); onRemoveExisting(f.id); }}
|
|
193
|
+
/>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
))}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { useState, useRef } from 'react';
|
|
2
|
+
import { UploadCloud, Paperclip, FileCheck, X, Eye, Trash2 } from 'lucide-react';
|
|
3
|
+
import LinearProgress from './LinearProgress.jsx';
|
|
4
|
+
import Badge from './Badge.jsx';
|
|
5
|
+
import Button from './Button.jsx';
|
|
6
|
+
|
|
7
|
+
function formatBytes(bytes, decimals = 1) {
|
|
8
|
+
if (!bytes || bytes === 0) return '0 B';
|
|
9
|
+
const k = 1024;
|
|
10
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
11
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
12
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
13
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function FilePicker({
|
|
17
|
+
onFiles,
|
|
18
|
+
onFile,
|
|
19
|
+
accept = 'image/*,application/pdf,.*',
|
|
20
|
+
multiple = true,
|
|
21
|
+
hint = 'Поддерживаются изображения, PDF документы и любые файлы',
|
|
22
|
+
uploadingFiles = [],
|
|
23
|
+
existingFiles = [],
|
|
24
|
+
onRemoveUploading,
|
|
25
|
+
onRemoveExisting,
|
|
26
|
+
onPreview,
|
|
27
|
+
label = 'Прикрепить файлы (Фото, PDF, документы)',
|
|
28
|
+
}) {
|
|
29
|
+
const [over, setOver] = useState(false);
|
|
30
|
+
const inputRef = useRef(null);
|
|
31
|
+
|
|
32
|
+
const handleFiles = (fileList) => {
|
|
33
|
+
const arr = Array.from(fileList || []);
|
|
34
|
+
if (arr.length === 0) return;
|
|
35
|
+
if (onFiles) onFiles(arr);
|
|
36
|
+
else if (onFile) arr.forEach(f => onFile(f));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleDrop = (e) => {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
setOver(false);
|
|
43
|
+
if (e.dataTransfer && e.dataTransfer.files) {
|
|
44
|
+
handleFiles(e.dataTransfer.files);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
50
|
+
{label && (
|
|
51
|
+
<label style={{ fontSize: 11, fontWeight: 600, color: 'var(--t2, #797b8d)', textTransform: 'uppercase', letterSpacing: '.08em', display: 'block' }}>
|
|
52
|
+
{label}
|
|
53
|
+
</label>
|
|
54
|
+
)}
|
|
55
|
+
|
|
56
|
+
<div
|
|
57
|
+
className={`file-picker${over ? ' over' : ''}`}
|
|
58
|
+
onDragOver={e => { e.preventDefault(); e.stopPropagation(); setOver(true); }}
|
|
59
|
+
onDragLeave={e => { e.preventDefault(); e.stopPropagation(); setOver(false); }}
|
|
60
|
+
onDrop={handleDrop}
|
|
61
|
+
onClick={() => inputRef.current?.click()}
|
|
62
|
+
style={{
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
justifyContent: 'center',
|
|
67
|
+
padding: '20px 20px',
|
|
68
|
+
border: `2px dashed ${over ? 'var(--accent, #3b82f6)' : 'var(--border-light, #ebebf0)'}`,
|
|
69
|
+
borderRadius: 'var(--rad, 10px)',
|
|
70
|
+
cursor: 'pointer',
|
|
71
|
+
background: over ? 'rgba(59, 130, 246, 0.08)' : 'var(--grey-1, #f5f5f8)',
|
|
72
|
+
transition: 'all .2s ease',
|
|
73
|
+
textAlign: 'center',
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<input
|
|
77
|
+
ref={inputRef}
|
|
78
|
+
type="file"
|
|
79
|
+
accept={accept}
|
|
80
|
+
multiple={multiple}
|
|
81
|
+
onChange={e => {
|
|
82
|
+
handleFiles(e.target.files);
|
|
83
|
+
e.target.value = '';
|
|
84
|
+
}}
|
|
85
|
+
style={{ display: 'none' }}
|
|
86
|
+
/>
|
|
87
|
+
<UploadCloud size={24} color="var(--accent, #3b82f6)" style={{ marginBottom: 6, pointerEvents: 'none' }} />
|
|
88
|
+
<span style={{ fontSize: '.82rem', fontWeight: 600, pointerEvents: 'none' }}>
|
|
89
|
+
Выберите файлы, перетащите их сюда или вставьте через Ctrl+V
|
|
90
|
+
</span>
|
|
91
|
+
{hint && <span style={{ fontSize: '.72rem', color: 'var(--muted, #797b8d)', marginTop: 2, pointerEvents: 'none' }}>{hint}</span>}
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
{/* Uploading progress items */}
|
|
95
|
+
{uploadingFiles.length > 0 && (
|
|
96
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
|
97
|
+
{uploadingFiles.map((item) => (
|
|
98
|
+
<div
|
|
99
|
+
key={item.tempId || item.name}
|
|
100
|
+
style={{
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flexDirection: 'column',
|
|
103
|
+
gap: 4,
|
|
104
|
+
padding: '8px 10px',
|
|
105
|
+
background: 'var(--surface, #ffffff)',
|
|
106
|
+
border: '1px solid var(--border-light, #ebebf0)',
|
|
107
|
+
borderRadius: 'var(--rads, 8px)',
|
|
108
|
+
fontSize: '.8rem',
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
112
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
|
|
113
|
+
{item.status === 'uploading' && <Paperclip size={14} color="var(--accent, #f99e2c)" />}
|
|
114
|
+
{item.status === 'done' && <FileCheck size={14} color="var(--success, #22c55e)" />}
|
|
115
|
+
{item.status === 'error' && <X size={14} color="var(--err, #ef4444)" />}
|
|
116
|
+
<span style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', fontWeight: 500 }}>
|
|
117
|
+
{item.name} <span style={{ color: 'var(--muted, #797b8d)', fontSize: '.72rem' }}>({formatBytes(item.size)})</span>
|
|
118
|
+
</span>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
122
|
+
{item.status === 'uploading' && (
|
|
123
|
+
<span style={{ fontSize: '.75rem', fontWeight: 600, color: 'var(--accent, #3b82f6)' }}>
|
|
124
|
+
{item.progress}%
|
|
125
|
+
</span>
|
|
126
|
+
)}
|
|
127
|
+
{item.status === 'done' && <Badge variant="ok" size="xs">Загружен</Badge>}
|
|
128
|
+
{item.status === 'error' && <Badge variant="err" size="xs">{item.error || 'Ошибка'}</Badge>}
|
|
129
|
+
{onRemoveUploading && (
|
|
130
|
+
<button
|
|
131
|
+
onClick={(e) => { e.stopPropagation(); onRemoveUploading(item.tempId); }}
|
|
132
|
+
style={{ border: 'none', background: 'none', cursor: 'pointer', padding: 2, color: 'var(--muted, #797b8d)' }}
|
|
133
|
+
>
|
|
134
|
+
<X size={14} />
|
|
135
|
+
</button>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{item.status === 'uploading' && (
|
|
141
|
+
<LinearProgress
|
|
142
|
+
value={item.progress}
|
|
143
|
+
color="var(--accent, #3b82f6)"
|
|
144
|
+
height={4}
|
|
145
|
+
showPercent={false}
|
|
146
|
+
style={{ marginTop: 2 }}
|
|
147
|
+
/>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
{/* Existing saved files list */}
|
|
155
|
+
{existingFiles.length > 0 && (
|
|
156
|
+
<div style={{ marginTop: 4 }}>
|
|
157
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
|
158
|
+
{existingFiles.map((f) => (
|
|
159
|
+
<div
|
|
160
|
+
key={f.id}
|
|
161
|
+
style={{
|
|
162
|
+
display: 'flex',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
justifyContent: 'space-between',
|
|
165
|
+
padding: '6px 10px',
|
|
166
|
+
background: 'var(--surface, #ffffff)',
|
|
167
|
+
border: '1px solid var(--border-light, #ebebf0)',
|
|
168
|
+
borderRadius: 'var(--rads, 8px)',
|
|
169
|
+
fontSize: '.8rem',
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 }}>
|
|
173
|
+
<Paperclip size={14} color="var(--accent, #f99e2c)" />
|
|
174
|
+
<span style={{ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', fontWeight: 500 }}>
|
|
175
|
+
{f.original_name || f.originalName} <span style={{ color: 'var(--muted, #797b8d)', fontSize: '.72rem' }}>({formatBytes(f.file_size || f.fileSize)})</span>
|
|
176
|
+
</span>
|
|
177
|
+
</div>
|
|
178
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
179
|
+
{onPreview && (
|
|
180
|
+
<Button
|
|
181
|
+
variant="ghost"
|
|
182
|
+
size="xs"
|
|
183
|
+
icon={<Eye size={13} />}
|
|
184
|
+
onClick={(e) => { e.stopPropagation(); onPreview(f); }}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
{onRemoveExisting && (
|
|
188
|
+
<Button
|
|
189
|
+
variant="ghost"
|
|
190
|
+
size="xs"
|
|
191
|
+
icon={<Trash2 size={13} color="var(--err, #f64747)" />}
|
|
192
|
+
onClick={(e) => { e.stopPropagation(); onRemoveExisting(f.id); }}
|
|
193
|
+
/>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
))}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export default FilePicker;
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
* triggerStyle — extra trigger wrapper styles
|
|
13
|
+
*/
|
|
14
|
+
export default function HoverCard({ trigger, children, position = 'top', width = 180, style, triggerStyle }) {
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
|
+
const [pos, setPos] = useState({ x: 0, y: 0 });
|
|
17
|
+
const wrapRef = useRef(null);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (open && wrapRef.current) {
|
|
21
|
+
const r = wrapRef.current.getBoundingClientRect();
|
|
22
|
+
setPos({ x: r.left + r.width / 2, y: position === 'top' ? r.top : r.bottom });
|
|
23
|
+
}
|
|
24
|
+
}, [open, position]);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!open) return;
|
|
28
|
+
const close = (e) => {
|
|
29
|
+
if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('mousedown', close);
|
|
32
|
+
return () => document.removeEventListener('mousedown', close);
|
|
33
|
+
}, [open]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
ref={wrapRef}
|
|
38
|
+
onMouseEnter={() => setOpen(true)}
|
|
39
|
+
onMouseLeave={() => setOpen(false)}
|
|
40
|
+
style={{ display: 'inline-block', position: 'relative', ...triggerStyle }}
|
|
41
|
+
>
|
|
42
|
+
{trigger}
|
|
43
|
+
{open && (
|
|
44
|
+
<div style={{
|
|
45
|
+
position: 'fixed',
|
|
46
|
+
left: pos.x,
|
|
47
|
+
top: position === 'top' ? 'auto' : pos.y + 6,
|
|
48
|
+
bottom: position === 'top' ? window.innerHeight - pos.y + 6 : 'auto',
|
|
49
|
+
transform: 'translateX(-50%)',
|
|
50
|
+
zIndex: 9999,
|
|
51
|
+
minWidth: width,
|
|
52
|
+
background: 'var(--surface,#fff)',
|
|
53
|
+
border: '1px solid var(--border, #e2e8f0)',
|
|
54
|
+
borderRadius: 'var(--rads, 8px)',
|
|
55
|
+
padding: '10px 14px',
|
|
56
|
+
boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))',
|
|
57
|
+
pointerEvents: 'none',
|
|
58
|
+
animation: 'hoverCardIn .15s ease',
|
|
59
|
+
...style,
|
|
60
|
+
}}>
|
|
61
|
+
{children}
|
|
62
|
+
<div style={{
|
|
63
|
+
position: 'absolute', left: '50%',
|
|
64
|
+
[position === 'top' ? 'bottom' : 'top']: -5,
|
|
65
|
+
transform: 'translateX(-50%) rotate(45deg)',
|
|
66
|
+
width: 8, height: 8, background: 'var(--surface,#fff)',
|
|
67
|
+
borderRight: '1px solid var(--border, #e2e8f0)',
|
|
68
|
+
borderBottom: position === 'top' ? 'none' : '1px solid var(--border, #e2e8f0)',
|
|
69
|
+
borderTop: position === 'top' ? '1px solid var(--border, #e2e8f0)' : 'none',
|
|
70
|
+
}} />
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
<style>{`
|
|
74
|
+
@keyframes hoverCardIn {
|
|
75
|
+
from { opacity: 0; transform: translateX(-50%) translateY(4px); }
|
|
76
|
+
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
77
|
+
}
|
|
78
|
+
`}</style>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|