cynx-ui 1.3.13 → 1.3.15
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 +148 -148
- package/components/CircularProgress.jsx +216 -216
- package/components/DatePicker.jsx +229 -64
- package/components/Dropzone.jsx +203 -203
- package/components/HoverCard.jsx +81 -81
- package/components/LineProgress.jsx +133 -133
- package/components/Pagination.jsx +41 -41
- package/components/StatBarCard.jsx +25 -25
- package/components/StatsCard.jsx +171 -171
- package/components/TabBar.jsx +13 -7
- package/components/Tabs.jsx +29 -29
- package/components/TimePicker.jsx +1078 -1078
- package/components/UptimeBar.jsx +200 -200
- package/components/XTable.jsx +28 -28
- package/package.json +1 -1
|
@@ -1,1078 +1,1078 @@
|
|
|
1
|
-
import { useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import { Clock, ChevronDown, ChevronUp, Check, X, Globe, List, Sliders } from 'lucide-react';
|
|
4
|
-
|
|
5
|
-
const STYLES = `
|
|
6
|
-
@keyframes cynxTimePickerPopIn {
|
|
7
|
-
0% {
|
|
8
|
-
opacity: 0;
|
|
9
|
-
transform: translateY(-8px) scale(0.96);
|
|
10
|
-
}
|
|
11
|
-
100% {
|
|
12
|
-
opacity: 1;
|
|
13
|
-
transform: translateY(0) scale(1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@keyframes cynxTimePickerPopOut {
|
|
18
|
-
0% {
|
|
19
|
-
opacity: 1;
|
|
20
|
-
transform: translateY(0) scale(1);
|
|
21
|
-
}
|
|
22
|
-
100% {
|
|
23
|
-
opacity: 0;
|
|
24
|
-
transform: translateY(-8px) scale(0.96);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.cynx-timepicker-drop {
|
|
29
|
-
animation: cynxTimePickerPopIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
30
|
-
will-change: opacity, transform;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.cynx-timepicker-drop.closing {
|
|
34
|
-
animation: cynxTimePickerPopOut 0.14s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.cynx-timepicker-cell {
|
|
38
|
-
transition: background-color 0.12s ease, color 0.12s ease;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.cynx-timepicker-cell:hover {
|
|
42
|
-
background-color: var(--hover-bg, var(--grey-1, #f5f5f8));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.cynx-timepicker-stepper-btn {
|
|
46
|
-
display: flex;
|
|
47
|
-
align-items: center;
|
|
48
|
-
justify-content: center;
|
|
49
|
-
width: 100%;
|
|
50
|
-
height: 28px;
|
|
51
|
-
border-radius: var(--rads, 8px);
|
|
52
|
-
border: 1px solid var(--bd, var(--border, #d7d8e0));
|
|
53
|
-
background: var(--grey-1, #f5f5f8);
|
|
54
|
-
color: var(--t1, var(--primary-text, #1a1a2e));
|
|
55
|
-
cursor: pointer;
|
|
56
|
-
transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.cynx-timepicker-stepper-btn:hover {
|
|
60
|
-
background: var(--surface, #ffffff);
|
|
61
|
-
border-color: var(--accent);
|
|
62
|
-
color: var(--accent);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.cynx-timepicker-stepper-btn:active {
|
|
66
|
-
background: var(--accent-bg, rgba(249,158,44,0.08));
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
|
|
70
|
-
const STYLE_ID = 'cynx-timepicker-styles';
|
|
71
|
-
|
|
72
|
-
function ensureStyles() {
|
|
73
|
-
if (typeof document === 'undefined') return;
|
|
74
|
-
if (document.getElementById(STYLE_ID)) return;
|
|
75
|
-
const tag = document.createElement('style');
|
|
76
|
-
tag.id = STYLE_ID;
|
|
77
|
-
tag.textContent = STYLES;
|
|
78
|
-
document.head.appendChild(tag);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const COMMON_TIMEZONES = [
|
|
82
|
-
{ value: 'system', label: 'Системное время (Local)' },
|
|
83
|
-
{ value: 'Asia/Tashkent', label: 'Ташкент (UTC+5)' },
|
|
84
|
-
{ value: 'America/New_York', label: 'Нью-Йорк (UTC-5)' },
|
|
85
|
-
{ value: 'Europe/London', label: 'Лондон (UTC+0)' },
|
|
86
|
-
{ value: 'Asia/Tokyo', label: 'Токио (UTC+9)' },
|
|
87
|
-
{ value: 'UTC', label: 'UTC' },
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
function pad(n) {
|
|
91
|
-
return String(n).padStart(2, '0');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function to12h(h24) {
|
|
95
|
-
const h = parseInt(h24, 10);
|
|
96
|
-
if (isNaN(h)) return { h12: '12', ampm: 'AM' };
|
|
97
|
-
const ampm = h >= 12 ? 'PM' : 'AM';
|
|
98
|
-
let h12 = h % 12;
|
|
99
|
-
if (h12 === 0) h12 = 12;
|
|
100
|
-
return { h12: pad(h12), ampm };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function to24h(h12, ampm) {
|
|
104
|
-
let h = parseInt(h12, 10);
|
|
105
|
-
if (isNaN(h)) return '00';
|
|
106
|
-
if (ampm === 'PM' && h < 12) h += 12;
|
|
107
|
-
if (ampm === 'AM' && h === 12) h = 0;
|
|
108
|
-
return pad(h);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function parseTime(val, is12h, showSeconds) {
|
|
112
|
-
if (!val || typeof val !== 'string') return { h24: '00', h12: '12', m: '00', s: '00', ampm: 'AM' };
|
|
113
|
-
|
|
114
|
-
let str = val.trim();
|
|
115
|
-
let ampm = 'AM';
|
|
116
|
-
if (/pm/i.test(str)) { ampm = 'PM'; str = str.replace(/pm/i, '').trim(); }
|
|
117
|
-
else if (/am/i.test(str)) { ampm = 'AM'; str = str.replace(/am/i, '').trim(); }
|
|
118
|
-
|
|
119
|
-
let p0 = 0, p1 = 0, p2 = 0;
|
|
120
|
-
|
|
121
|
-
if (str.includes(':')) {
|
|
122
|
-
const parts = str.split(':').map(p => p.trim());
|
|
123
|
-
p0 = parseInt(parts[0], 10) || 0;
|
|
124
|
-
p1 = parseInt(parts[1], 10) || 0;
|
|
125
|
-
p2 = parseInt(parts[2], 10) || 0;
|
|
126
|
-
} else if (/^\d{3,6}$/.test(str)) {
|
|
127
|
-
p0 = parseInt(str.slice(0, 2), 10) || 0;
|
|
128
|
-
p1 = parseInt(str.slice(2, 4), 10) || 0;
|
|
129
|
-
p2 = parseInt(str.slice(4, 6), 10) || 0;
|
|
130
|
-
} else {
|
|
131
|
-
p0 = parseInt(str, 10) || 0;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let h24 = '00';
|
|
135
|
-
let h12 = '12';
|
|
136
|
-
|
|
137
|
-
if (is12h) {
|
|
138
|
-
if (p0 > 12) {
|
|
139
|
-
h24 = pad(Math.min(23, Math.max(0, p0)));
|
|
140
|
-
const conv = to12h(h24);
|
|
141
|
-
h12 = conv.h12;
|
|
142
|
-
ampm = conv.ampm;
|
|
143
|
-
} else {
|
|
144
|
-
let hNum = Math.min(12, Math.max(1, p0));
|
|
145
|
-
h12 = pad(hNum);
|
|
146
|
-
h24 = to24h(h12, ampm);
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
let hNum = Math.min(23, Math.max(0, p0));
|
|
150
|
-
h24 = pad(hNum);
|
|
151
|
-
const conv = to12h(h24);
|
|
152
|
-
h12 = conv.h12;
|
|
153
|
-
ampm = conv.ampm;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const m = pad(Math.min(59, Math.max(0, p1)));
|
|
157
|
-
const s = pad(Math.min(59, Math.max(0, p2)));
|
|
158
|
-
|
|
159
|
-
return { h24, h12, m, s, ampm };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function TimePicker({
|
|
163
|
-
value = '',
|
|
164
|
-
onChange,
|
|
165
|
-
variant = 'list', // 'stepper' (+/- buttons) | 'list' (full 00..59 scrollable list)
|
|
166
|
-
showVariantToggle = false, // Default false: clean list mode by default!
|
|
167
|
-
format = '24h', // '24h' | '12h'
|
|
168
|
-
showSeconds = false,
|
|
169
|
-
showIcon = false, // Default false: clock icon hidden by default, set showIcon={true} to display
|
|
170
|
-
hideIcon = false, // Legacy prop alias for showIcon = false
|
|
171
|
-
showFormatToggle = false, // Minimal default: false
|
|
172
|
-
showPresets = false, // Minimal default: false
|
|
173
|
-
showTimezoneSelect = false, // Minimal default: false
|
|
174
|
-
showPlaceholder = false, // Minimal default: false
|
|
175
|
-
timezone = 'Asia/Tashkent',
|
|
176
|
-
label,
|
|
177
|
-
placeholder,
|
|
178
|
-
size = 'sm', // 'xs' | 'sm' | 'md'
|
|
179
|
-
disabled = false,
|
|
180
|
-
readOnly = false,
|
|
181
|
-
style = {},
|
|
182
|
-
className = '',
|
|
183
|
-
}) {
|
|
184
|
-
const displayClockIcon = showIcon && !hideIcon;
|
|
185
|
-
const [open, setOpen] = useState(false);
|
|
186
|
-
const [rendered, setRendered] = useState(false);
|
|
187
|
-
const [closing, setClosing] = useState(false);
|
|
188
|
-
|
|
189
|
-
const [activeVariant, setActiveVariant] = useState(variant);
|
|
190
|
-
const [mode, setMode] = useState(format);
|
|
191
|
-
const [tz, setTz] = useState(timezone);
|
|
192
|
-
const [showTzPicker, setShowTzPicker] = useState(false);
|
|
193
|
-
|
|
194
|
-
const btnRef = useRef(null);
|
|
195
|
-
const dropRef = useRef(null);
|
|
196
|
-
const isTypingRef = useRef(false);
|
|
197
|
-
|
|
198
|
-
const [pos, setPos] = useState({ top: 0, left: 0, width: 230 });
|
|
199
|
-
|
|
200
|
-
ensureStyles();
|
|
201
|
-
|
|
202
|
-
useEffect(() => { setActiveVariant(variant); }, [variant]);
|
|
203
|
-
useEffect(() => { setMode(format); }, [format]);
|
|
204
|
-
useEffect(() => { setTz(timezone); }, [timezone]);
|
|
205
|
-
|
|
206
|
-
const openPicker = useCallback(() => {
|
|
207
|
-
if (disabled || readOnly) return;
|
|
208
|
-
setRendered(true);
|
|
209
|
-
setClosing(false);
|
|
210
|
-
setOpen(true);
|
|
211
|
-
}, [disabled, readOnly]);
|
|
212
|
-
|
|
213
|
-
const closePicker = useCallback(() => {
|
|
214
|
-
if (!open) return;
|
|
215
|
-
setClosing(true);
|
|
216
|
-
setOpen(false);
|
|
217
|
-
setShowTzPicker(false);
|
|
218
|
-
setTimeout(() => {
|
|
219
|
-
setRendered(false);
|
|
220
|
-
setClosing(false);
|
|
221
|
-
}, 140);
|
|
222
|
-
}, [open]);
|
|
223
|
-
|
|
224
|
-
const togglePicker = useCallback(() => {
|
|
225
|
-
if (open) closePicker();
|
|
226
|
-
else openPicker();
|
|
227
|
-
}, [open, closePicker, openPicker]);
|
|
228
|
-
|
|
229
|
-
const formatOutput = useCallback((parsedObj, useMode = mode) => {
|
|
230
|
-
const { h24, h12, m, s, ampm } = parsedObj;
|
|
231
|
-
if (useMode === '12h') {
|
|
232
|
-
return showSeconds ? `${h12}:${m}:${s} ${ampm}` : `${h12}:${m} ${ampm}`;
|
|
233
|
-
}
|
|
234
|
-
return showSeconds ? `${h24}:${m}:${s}` : `${h24}:${m}`;
|
|
235
|
-
}, [mode, showSeconds]);
|
|
236
|
-
|
|
237
|
-
const parsed = parseTime(value, mode === '12h', showSeconds);
|
|
238
|
-
const [inputValue, setInputValue] = useState(() => value ? formatOutput(parsed) : '');
|
|
239
|
-
|
|
240
|
-
// Keep inputValue in sync with props ONLY when user is NOT actively typing!
|
|
241
|
-
useEffect(() => {
|
|
242
|
-
if (!isTypingRef.current) {
|
|
243
|
-
if (value) {
|
|
244
|
-
const p = parseTime(value, mode === '12h', showSeconds);
|
|
245
|
-
setInputValue(formatOutput(p));
|
|
246
|
-
} else {
|
|
247
|
-
setInputValue('');
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}, [value, mode, showSeconds, formatOutput]);
|
|
251
|
-
|
|
252
|
-
const calcPos = useCallback(() => {
|
|
253
|
-
if (!btnRef.current) return;
|
|
254
|
-
const r = btnRef.current.getBoundingClientRect();
|
|
255
|
-
const dropW = mode === '12h' ? 290 : 230;
|
|
256
|
-
const dropH = dropRef.current ? dropRef.current.offsetHeight : 230;
|
|
257
|
-
|
|
258
|
-
let left = r.left;
|
|
259
|
-
if (left + dropW > window.innerWidth - 12) {
|
|
260
|
-
left = Math.max(12, r.right - dropW);
|
|
261
|
-
}
|
|
262
|
-
if (left < 12) left = 12;
|
|
263
|
-
|
|
264
|
-
let top = r.bottom + 4;
|
|
265
|
-
if (top + dropH > window.innerHeight - 12 && r.top - 4 - dropH > 12) {
|
|
266
|
-
top = r.top - 4 - dropH;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
setPos({ top, left, width: Math.max(r.width, dropW) });
|
|
270
|
-
}, [mode]);
|
|
271
|
-
|
|
272
|
-
useLayoutEffect(() => {
|
|
273
|
-
if (!rendered) return;
|
|
274
|
-
calcPos();
|
|
275
|
-
}, [rendered, calcPos]);
|
|
276
|
-
|
|
277
|
-
useEffect(() => {
|
|
278
|
-
if (!rendered || closing) return;
|
|
279
|
-
function onDown(e) {
|
|
280
|
-
const inBtn = btnRef.current && btnRef.current.contains(e.target);
|
|
281
|
-
const inDrop = dropRef.current && dropRef.current.contains(e.target);
|
|
282
|
-
if (!inBtn && !inDrop) {
|
|
283
|
-
closePicker();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
const timer = setTimeout(() => {
|
|
287
|
-
document.addEventListener('mousedown', onDown, true);
|
|
288
|
-
}, 0);
|
|
289
|
-
window.addEventListener('scroll', calcPos, true);
|
|
290
|
-
window.addEventListener('resize', calcPos);
|
|
291
|
-
return () => {
|
|
292
|
-
clearTimeout(timer);
|
|
293
|
-
document.removeEventListener('mousedown', onDown, true);
|
|
294
|
-
window.removeEventListener('scroll', calcPos, true);
|
|
295
|
-
window.removeEventListener('resize', calcPos);
|
|
296
|
-
};
|
|
297
|
-
}, [rendered, closing, calcPos, closePicker]);
|
|
298
|
-
|
|
299
|
-
const emitChange = (parsedObj, useMode = mode) => {
|
|
300
|
-
const formatted = formatOutput(parsedObj, useMode);
|
|
301
|
-
setInputValue(formatted);
|
|
302
|
-
if (onChange) {
|
|
303
|
-
onChange(formatted, {
|
|
304
|
-
hours: parseInt(parsedObj.h24, 10),
|
|
305
|
-
minutes: parseInt(parsedObj.m, 10),
|
|
306
|
-
seconds: parseInt(parsedObj.s, 10),
|
|
307
|
-
ampm: parsedObj.ampm,
|
|
308
|
-
format: useMode,
|
|
309
|
-
timezone: tz,
|
|
310
|
-
variant: activeVariant,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
const handleKeyDown = (e) => {
|
|
316
|
-
if (
|
|
317
|
-
['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key) ||
|
|
318
|
-
e.ctrlKey || e.metaKey || e.altKey
|
|
319
|
-
) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const allowed = mode === '12h' ? /^[0-9:\sAPMapm]$/ : /^[0-9:]$/;
|
|
323
|
-
if (!allowed.test(e.key)) {
|
|
324
|
-
e.preventDefault();
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const handleInputChange = (e) => {
|
|
329
|
-
let raw = e.target.value;
|
|
330
|
-
isTypingRef.current = true;
|
|
331
|
-
|
|
332
|
-
// 1. Strict filter: allow ONLY digits and colon (and AM/PM in 12h)
|
|
333
|
-
if (mode === '12h') {
|
|
334
|
-
raw = raw.replace(/[^0-9:\sAPMapm]/g, '');
|
|
335
|
-
} else {
|
|
336
|
-
raw = raw.replace(/[^0-9:]/g, '');
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// 2. Single-digit hour shortcut (e.g. typing "3" -> "03:")
|
|
340
|
-
if (mode === '24h' && /^[3-9]$/.test(raw)) {
|
|
341
|
-
raw = '0' + raw + ':';
|
|
342
|
-
} else if (mode === '12h' && /^[2-9]$/.test(raw) && !/pm|am/i.test(raw)) {
|
|
343
|
-
raw = '0' + raw + ':';
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// 3. Auto-append 1st colon after 2 hour digits + cap hour max (23 in 24h, 12 in 12h)
|
|
347
|
-
if (/^\d{2}$/.test(raw) && !inputValue.endsWith(':')) {
|
|
348
|
-
const hNum = parseInt(raw, 10);
|
|
349
|
-
if (mode === '24h' && hNum > 23) raw = '23:';
|
|
350
|
-
else if (mode === '12h' && hNum > 12) raw = '12:';
|
|
351
|
-
else raw = raw + ':';
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// 4. Minutes tens digit validation: first digit of minute (after 1st colon) CANNOT be > 5!
|
|
355
|
-
if (/^\d{2}:[6-9]/.test(raw)) {
|
|
356
|
-
raw = raw.replace(/^(\d{2}:)[6-9]/, '$15');
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// 5. Auto-append 2nd colon after 2 minute digits if showSeconds is true (e.g. "16:16" -> "16:16:")
|
|
360
|
-
if (showSeconds && /^\d{2}:\d{2}$/.test(raw) && !inputValue.endsWith(':')) {
|
|
361
|
-
const mNum = parseInt(raw.slice(3, 5), 10);
|
|
362
|
-
if (mNum > 59) raw = raw.slice(0, 3) + '59:';
|
|
363
|
-
else raw = raw + ':';
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// 6. Seconds tens digit validation (if showSeconds): first digit of second CANNOT be > 5!
|
|
367
|
-
if (showSeconds && /^\d{2}:\d{2}:[6-9]/.test(raw)) {
|
|
368
|
-
raw = raw.replace(/^(\d{2}:\d{2}:)[6-9]/, '$15');
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// 7. Prevent 3rd minute digit when showSeconds is FALSE! (e.g. "16:166" -> "16:16")
|
|
372
|
-
if (!showSeconds && /^\d{2}:\d{3,}/.test(raw)) {
|
|
373
|
-
raw = raw.slice(0, 5);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// 8. Prevent 3rd second digit when showSeconds is TRUE! (e.g. "16:16:666" -> "16:16:66")
|
|
377
|
-
if (showSeconds && /^\d{2}:\d{2}:\d{3,}/.test(raw)) {
|
|
378
|
-
raw = raw.slice(0, 8);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// 9. Strict Max length capping
|
|
382
|
-
const maxLen = mode === '12h' ? (showSeconds ? 11 : 8) : (showSeconds ? 8 : 5);
|
|
383
|
-
if (raw.length > maxLen) {
|
|
384
|
-
raw = raw.slice(0, maxLen);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
e.target.value = raw;
|
|
388
|
-
setInputValue(raw);
|
|
389
|
-
|
|
390
|
-
if (!raw) {
|
|
391
|
-
if (onChange) onChange('', { hours: null, minutes: null, seconds: null, ampm: null, format: mode, timezone: tz, variant: activeVariant });
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Emit change if raw matches a complete valid time pattern
|
|
396
|
-
if (/^\d{1,2}:\d{1,2}(:\d{1,2})?(\s*[ap]m)?$/i.test(raw) || /^\d{4}$/.test(raw)) {
|
|
397
|
-
const p = parseTime(raw, mode === '12h', showSeconds);
|
|
398
|
-
const formatted = formatOutput(p);
|
|
399
|
-
if (onChange) {
|
|
400
|
-
onChange(formatted, {
|
|
401
|
-
hours: parseInt(p.h24, 10),
|
|
402
|
-
minutes: parseInt(p.m, 10),
|
|
403
|
-
seconds: parseInt(p.s, 10),
|
|
404
|
-
ampm: p.ampm,
|
|
405
|
-
format: mode,
|
|
406
|
-
timezone: tz,
|
|
407
|
-
variant: activeVariant,
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
const handleInputBlur = () => {
|
|
414
|
-
isTypingRef.current = false;
|
|
415
|
-
if (!inputValue) return;
|
|
416
|
-
const p = parseTime(inputValue, mode === '12h', showSeconds);
|
|
417
|
-
emitChange(p);
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
// Stepper Up/Down (+/-) handlers
|
|
421
|
-
const stepHour = (delta) => {
|
|
422
|
-
isTypingRef.current = false;
|
|
423
|
-
let curH = mode === '12h' ? parseInt(parsed.h12, 10) : parseInt(parsed.h24, 10);
|
|
424
|
-
if (isNaN(curH)) curH = mode === '12h' ? 12 : 0;
|
|
425
|
-
|
|
426
|
-
if (mode === '12h') {
|
|
427
|
-
let nextH12 = curH + delta;
|
|
428
|
-
let nextAmPm = parsed.ampm;
|
|
429
|
-
if (nextH12 > 12) { nextH12 = 1; }
|
|
430
|
-
else if (nextH12 < 1) { nextH12 = 12; }
|
|
431
|
-
const h12 = pad(nextH12);
|
|
432
|
-
const h24 = to24h(h12, nextAmPm);
|
|
433
|
-
emitChange({ ...parsed, h12, h24, ampm: nextAmPm });
|
|
434
|
-
} else {
|
|
435
|
-
let nextH24 = (curH + delta + 24) % 24;
|
|
436
|
-
const h24 = pad(nextH24);
|
|
437
|
-
const { h12, ampm } = to12h(h24);
|
|
438
|
-
emitChange({ ...parsed, h24, h12, ampm });
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
const stepMinute = (delta) => {
|
|
443
|
-
isTypingRef.current = false;
|
|
444
|
-
let curM = parseInt(parsed.m, 10);
|
|
445
|
-
if (isNaN(curM)) curM = 0;
|
|
446
|
-
let nextM = (curM + delta + 60) % 60;
|
|
447
|
-
const m = pad(nextM);
|
|
448
|
-
emitChange({ ...parsed, m });
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
const stepSecond = (delta) => {
|
|
452
|
-
isTypingRef.current = false;
|
|
453
|
-
let curS = parseInt(parsed.s, 10);
|
|
454
|
-
if (isNaN(curS)) curS = 0;
|
|
455
|
-
let nextS = (curS + delta + 60) % 60;
|
|
456
|
-
const s = pad(nextS);
|
|
457
|
-
emitChange({ ...parsed, s });
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// List direct selection handlers
|
|
461
|
-
const selectH24 = (hNum) => {
|
|
462
|
-
isTypingRef.current = false;
|
|
463
|
-
const h24 = pad(hNum);
|
|
464
|
-
const { h12, ampm } = to12h(h24);
|
|
465
|
-
emitChange({ ...parsed, h24, h12, ampm });
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
const selectH12 = (hNum12) => {
|
|
469
|
-
isTypingRef.current = false;
|
|
470
|
-
const h12 = pad(hNum12);
|
|
471
|
-
const h24 = to24h(h12, parsed.ampm);
|
|
472
|
-
emitChange({ ...parsed, h24, h12 });
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
const selectMin = (mNum) => {
|
|
476
|
-
isTypingRef.current = false;
|
|
477
|
-
const m = pad(mNum);
|
|
478
|
-
emitChange({ ...parsed, m });
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
const selectSec = (sNum) => {
|
|
482
|
-
isTypingRef.current = false;
|
|
483
|
-
const s = pad(sNum);
|
|
484
|
-
emitChange({ ...parsed, s });
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
const toggleAmPm = (targetAmPm) => {
|
|
488
|
-
isTypingRef.current = false;
|
|
489
|
-
const ampm = targetAmPm;
|
|
490
|
-
const h24 = to24h(parsed.h12, ampm);
|
|
491
|
-
emitChange({ ...parsed, ampm, h24 });
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const switchMode = (newMode) => {
|
|
495
|
-
isTypingRef.current = false;
|
|
496
|
-
setMode(newMode);
|
|
497
|
-
emitChange(parsed, newMode);
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
const clearTime = (e) => {
|
|
501
|
-
e?.stopPropagation();
|
|
502
|
-
isTypingRef.current = false;
|
|
503
|
-
setInputValue('');
|
|
504
|
-
if (onChange) onChange('', { hours: null, minutes: null, seconds: null, ampm: null, format: mode, timezone: tz, variant: activeVariant });
|
|
505
|
-
closePicker();
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const defaultPlaceholder = showPlaceholder
|
|
509
|
-
? (mode === '12h'
|
|
510
|
-
? (showSeconds ? 'hh:mm:ss AM' : 'hh:mm AM')
|
|
511
|
-
: (showSeconds ? 'HH:MM:SS' : 'HH:MM'))
|
|
512
|
-
: '';
|
|
513
|
-
const ph = placeholder !== undefined ? placeholder : defaultPlaceholder;
|
|
514
|
-
|
|
515
|
-
const hours24List = Array.from({ length: 24 }, (_, i) => i);
|
|
516
|
-
const hours12List = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
517
|
-
const fullMinutesList = Array.from({ length: 60 }, (_, i) => i);
|
|
518
|
-
|
|
519
|
-
const presets24 = ['00:00', '07:00', '08:00', '09:00', '12:00', '18:00', '23:00'];
|
|
520
|
-
const presets12 = ['07:00 AM', '09:00 AM', '12:00 PM', '03:00 PM', '06:00 PM', '11:00 PM'];
|
|
521
|
-
|
|
522
|
-
const inputHeight = style?.height
|
|
523
|
-
? (typeof style.height === 'number' ? `${style.height}px` : style.height)
|
|
524
|
-
: (size === 'xs' ? '24px' : (size === 'sm' ? '32px' : '38px'));
|
|
525
|
-
const fontSize = (size === 'xs' || (style?.height && parseInt(style.height) <= 26)) ? '.72rem' : (size === 'sm' ? '.78rem' : '.85rem');
|
|
526
|
-
|
|
527
|
-
return (
|
|
528
|
-
<div
|
|
529
|
-
className={`cynx-timepicker-wrap ${className}`}
|
|
530
|
-
style={{ display: 'inline-flex', flexDirection: 'column', position: 'relative', width: style?.width || 'auto', boxSizing: 'border-box', minWidth: 0, ...style }}
|
|
531
|
-
>
|
|
532
|
-
{label && (
|
|
533
|
-
<label
|
|
534
|
-
style={{ fontSize: 11, fontWeight: 600, color: 'var(--t2, var(--muted))', textTransform: 'uppercase', letterSpacing: '.08em', display: 'block', marginBottom: 4 }}
|
|
535
|
-
>
|
|
536
|
-
{label}
|
|
537
|
-
</label>
|
|
538
|
-
)}
|
|
539
|
-
|
|
540
|
-
{/* Input Trigger Field */}
|
|
541
|
-
<div ref={btnRef} style={{ position: 'relative', display: 'flex', alignItems: 'center', width: '100%', boxSizing: 'border-box', minWidth: 0 }}>
|
|
542
|
-
{displayClockIcon && (
|
|
543
|
-
<button
|
|
544
|
-
type="button"
|
|
545
|
-
onClick={togglePicker}
|
|
546
|
-
disabled={disabled || readOnly}
|
|
547
|
-
title="Выбрать время"
|
|
548
|
-
style={{
|
|
549
|
-
position: 'absolute',
|
|
550
|
-
left: 10,
|
|
551
|
-
background: 'none',
|
|
552
|
-
border: 'none',
|
|
553
|
-
cursor: (disabled || readOnly) ? 'default' : 'pointer',
|
|
554
|
-
padding: 0,
|
|
555
|
-
display: 'flex',
|
|
556
|
-
alignItems: 'center',
|
|
557
|
-
justifyContent: 'center',
|
|
558
|
-
color: open ? 'var(--accent)' : 'var(--t2, var(--muted, #9b9daa))',
|
|
559
|
-
zIndex: 1,
|
|
560
|
-
transition: 'color .15s ease',
|
|
561
|
-
}}
|
|
562
|
-
>
|
|
563
|
-
<Clock size={size === 'sm' ? 14 : 16} />
|
|
564
|
-
</button>
|
|
565
|
-
)}
|
|
566
|
-
|
|
567
|
-
<input
|
|
568
|
-
type="text"
|
|
569
|
-
value={inputValue}
|
|
570
|
-
onChange={handleInputChange}
|
|
571
|
-
onKeyDown={handleKeyDown}
|
|
572
|
-
onBlur={handleInputBlur}
|
|
573
|
-
onFocus={openPicker}
|
|
574
|
-
maxLength={mode === '12h' ? (showSeconds ? 11 : 8) : (showSeconds ? 8 : 5)}
|
|
575
|
-
placeholder={ph}
|
|
576
|
-
disabled={disabled}
|
|
577
|
-
readOnly={readOnly}
|
|
578
|
-
style={{
|
|
579
|
-
display: 'flex',
|
|
580
|
-
width: '100%',
|
|
581
|
-
minWidth: 0,
|
|
582
|
-
maxWidth: '100%',
|
|
583
|
-
boxSizing: 'border-box',
|
|
584
|
-
height: inputHeight,
|
|
585
|
-
paddingLeft: displayClockIcon ? (size === 'xs' ? 22 : 28) : (size === 'xs' ? 6 : 10),
|
|
586
|
-
paddingRight: size === 'xs' ? 18 : 26,
|
|
587
|
-
border: `1px solid ${open ? 'var(--accent)' : 'var(--bd, var(--border, #d7d8e0))'}`,
|
|
588
|
-
borderRadius: 'var(--rads, 8px)',
|
|
589
|
-
fontSize: fontSize,
|
|
590
|
-
background: disabled ? 'var(--grey-1, #f5f5f8)' : 'var(--input-bg, var(--surface, #ffffff))',
|
|
591
|
-
color: 'var(--t1, var(--primary-text, #1a1a2e))',
|
|
592
|
-
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
593
|
-
letterSpacing: '0.03em',
|
|
594
|
-
fontWeight: 600,
|
|
595
|
-
fontVariantNumeric: 'tabular-nums',
|
|
596
|
-
textAlign: 'left',
|
|
597
|
-
outline: 'none',
|
|
598
|
-
boxShadow: open
|
|
599
|
-
? 'var(--pd, rgba(249,158,44,.12)), var(--shadow, 0 1px 3px rgba(20,22,41,.1))'
|
|
600
|
-
: 'var(--shadow, 0 1px 3px rgba(20,22,41,.1))',
|
|
601
|
-
opacity: disabled ? 0.5 : 1,
|
|
602
|
-
cursor: disabled ? 'not-allowed' : undefined,
|
|
603
|
-
transition: 'border-color .14s, box-shadow .14s',
|
|
604
|
-
}}
|
|
605
|
-
/>
|
|
606
|
-
|
|
607
|
-
<div style={{ position: 'absolute', right: 8, display: 'flex', alignItems: 'center' }}>
|
|
608
|
-
{inputValue && !disabled && !readOnly ? (
|
|
609
|
-
<button
|
|
610
|
-
type="button"
|
|
611
|
-
onClick={clearTime}
|
|
612
|
-
title="Очистить"
|
|
613
|
-
style={{
|
|
614
|
-
background: 'none',
|
|
615
|
-
border: 'none',
|
|
616
|
-
cursor: 'pointer',
|
|
617
|
-
color: 'var(--t2, var(--muted, #9b9daa))',
|
|
618
|
-
padding: 2,
|
|
619
|
-
display: 'flex',
|
|
620
|
-
alignItems: 'center',
|
|
621
|
-
justifyContent: 'center',
|
|
622
|
-
transition: 'color .14s ease',
|
|
623
|
-
}}
|
|
624
|
-
onMouseEnter={e => e.currentTarget.style.color = 'var(--danger, #f64747)'}
|
|
625
|
-
onMouseLeave={e => e.currentTarget.style.color = 'var(--t2, var(--muted, #9b9daa))'}
|
|
626
|
-
>
|
|
627
|
-
<X size={13} />
|
|
628
|
-
</button>
|
|
629
|
-
) : (
|
|
630
|
-
<ChevronDown
|
|
631
|
-
size={13}
|
|
632
|
-
style={{
|
|
633
|
-
color: open ? 'var(--accent)' : 'var(--t2, var(--muted, #9b9daa))',
|
|
634
|
-
transform: open ? 'rotate(180deg)' : 'none',
|
|
635
|
-
transition: 'transform .2s ease, color .15s ease',
|
|
636
|
-
pointerEvents: 'none',
|
|
637
|
-
}}
|
|
638
|
-
/>
|
|
639
|
-
)}
|
|
640
|
-
</div>
|
|
641
|
-
</div>
|
|
642
|
-
|
|
643
|
-
{/* PORTAL DROPDOWN POPUP */}
|
|
644
|
-
{rendered && createPortal(
|
|
645
|
-
<div
|
|
646
|
-
ref={dropRef}
|
|
647
|
-
className={`cynx-timepicker-drop ${closing ? 'closing' : ''}`}
|
|
648
|
-
style={{
|
|
649
|
-
position: 'fixed',
|
|
650
|
-
top: pos.top,
|
|
651
|
-
left: pos.left,
|
|
652
|
-
zIndex: 999999,
|
|
653
|
-
background: 'var(--surface, #ffffff)',
|
|
654
|
-
border: '1px solid var(--border, var(--bd, #d7d8e0))',
|
|
655
|
-
borderRadius: 'var(--rad, 10px)',
|
|
656
|
-
boxShadow: 'var(--shadow-lg, 0 10px 25px rgba(0,0,0,0.15))',
|
|
657
|
-
padding: 10,
|
|
658
|
-
width: mode === '12h' ? 290 : 240,
|
|
659
|
-
maxWidth: 'calc(100vw - 24px)',
|
|
660
|
-
boxSizing: 'border-box',
|
|
661
|
-
fontSize: '.78rem',
|
|
662
|
-
userSelect: 'none',
|
|
663
|
-
fontFamily: 'var(--sans, inherit)',
|
|
664
|
-
}}
|
|
665
|
-
>
|
|
666
|
-
{/* Header Bar: Variant Switcher */}
|
|
667
|
-
{showVariantToggle && (
|
|
668
|
-
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
669
|
-
<span style={{ fontSize: '.68rem', fontWeight: 700, color: 'var(--fg, var(--t1))', textTransform: 'uppercase', letterSpacing: '.05em' }}>
|
|
670
|
-
Режим
|
|
671
|
-
</span>
|
|
672
|
-
|
|
673
|
-
<div style={{ display: 'inline-flex', background: 'var(--grey-1, var(--surface-hover))', padding: 2, borderRadius: 6, border: '1px solid var(--border-light, var(--border))' }}>
|
|
674
|
-
<button
|
|
675
|
-
type="button"
|
|
676
|
-
onClick={() => setActiveVariant('stepper')}
|
|
677
|
-
className="cynx-timepicker-cell"
|
|
678
|
-
style={{
|
|
679
|
-
padding: '2px 8px',
|
|
680
|
-
borderRadius: 4,
|
|
681
|
-
border: 'none',
|
|
682
|
-
fontSize: '.68rem',
|
|
683
|
-
fontWeight: activeVariant === 'stepper' ? 700 : 500,
|
|
684
|
-
background: activeVariant === 'stepper' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
685
|
-
color: activeVariant === 'stepper' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
686
|
-
boxShadow: activeVariant === 'stepper' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
687
|
-
cursor: 'pointer',
|
|
688
|
-
display: 'flex',
|
|
689
|
-
alignItems: 'center',
|
|
690
|
-
gap: 3,
|
|
691
|
-
}}
|
|
692
|
-
>
|
|
693
|
-
<Sliders size={11} /> Спиннер (+/-)
|
|
694
|
-
</button>
|
|
695
|
-
|
|
696
|
-
<button
|
|
697
|
-
type="button"
|
|
698
|
-
onClick={() => setActiveVariant('list')}
|
|
699
|
-
className="cynx-timepicker-cell"
|
|
700
|
-
style={{
|
|
701
|
-
padding: '2px 8px',
|
|
702
|
-
borderRadius: 4,
|
|
703
|
-
border: 'none',
|
|
704
|
-
fontSize: '.68rem',
|
|
705
|
-
fontWeight: activeVariant === 'list' ? 700 : 500,
|
|
706
|
-
background: activeVariant === 'list' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
707
|
-
color: activeVariant === 'list' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
708
|
-
boxShadow: activeVariant === 'list' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
709
|
-
cursor: 'pointer',
|
|
710
|
-
display: 'flex',
|
|
711
|
-
alignItems: 'center',
|
|
712
|
-
gap: 3,
|
|
713
|
-
}}
|
|
714
|
-
>
|
|
715
|
-
<List size={11} /> Список (00-59)
|
|
716
|
-
</button>
|
|
717
|
-
</div>
|
|
718
|
-
</div>
|
|
719
|
-
)}
|
|
720
|
-
|
|
721
|
-
{/* Optional Format Switcher (24h / 12h) */}
|
|
722
|
-
{showFormatToggle && (
|
|
723
|
-
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
724
|
-
<span style={{ fontSize: '.68rem', fontWeight: 700, color: 'var(--fg, var(--t1))', textTransform: 'uppercase', letterSpacing: '.05em' }}>
|
|
725
|
-
Формат
|
|
726
|
-
</span>
|
|
727
|
-
|
|
728
|
-
<div style={{ display: 'inline-flex', background: 'var(--grey-1, var(--surface-hover))', padding: 2, borderRadius: 6, border: '1px solid var(--border-light, var(--border))' }}>
|
|
729
|
-
<button
|
|
730
|
-
type="button"
|
|
731
|
-
onClick={() => switchMode('24h')}
|
|
732
|
-
className="cynx-timepicker-cell"
|
|
733
|
-
style={{
|
|
734
|
-
padding: '2px 8px',
|
|
735
|
-
borderRadius: 4,
|
|
736
|
-
border: 'none',
|
|
737
|
-
fontSize: '.68rem',
|
|
738
|
-
fontWeight: mode === '24h' ? 700 : 500,
|
|
739
|
-
background: mode === '24h' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
740
|
-
color: mode === '24h' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
741
|
-
boxShadow: mode === '24h' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
742
|
-
cursor: 'pointer',
|
|
743
|
-
}}
|
|
744
|
-
>
|
|
745
|
-
24h
|
|
746
|
-
</button>
|
|
747
|
-
<button
|
|
748
|
-
type="button"
|
|
749
|
-
onClick={() => switchMode('12h')}
|
|
750
|
-
className="cynx-timepicker-cell"
|
|
751
|
-
style={{
|
|
752
|
-
padding: '2px 8px',
|
|
753
|
-
borderRadius: 4,
|
|
754
|
-
border: 'none',
|
|
755
|
-
fontSize: '.68rem',
|
|
756
|
-
fontWeight: mode === '12h' ? 700 : 500,
|
|
757
|
-
background: mode === '12h' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
758
|
-
color: mode === '12h' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
759
|
-
boxShadow: mode === '12h' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
760
|
-
cursor: 'pointer',
|
|
761
|
-
}}
|
|
762
|
-
>
|
|
763
|
-
12h AM/PM
|
|
764
|
-
</button>
|
|
765
|
-
</div>
|
|
766
|
-
</div>
|
|
767
|
-
)}
|
|
768
|
-
|
|
769
|
-
{/* Optional Timezone Selector Header */}
|
|
770
|
-
{showTimezoneSelect && (
|
|
771
|
-
<div style={{ marginBottom: 8 }}>
|
|
772
|
-
<button
|
|
773
|
-
type="button"
|
|
774
|
-
onClick={() => setShowTzPicker(prev => !prev)}
|
|
775
|
-
className="cynx-timepicker-cell"
|
|
776
|
-
style={{
|
|
777
|
-
display: 'flex',
|
|
778
|
-
alignItems: 'center',
|
|
779
|
-
justifyContent: 'space-between',
|
|
780
|
-
width: '100%',
|
|
781
|
-
padding: '4px 8px',
|
|
782
|
-
borderRadius: 6,
|
|
783
|
-
border: '1px solid var(--border-light, var(--border))',
|
|
784
|
-
background: 'var(--grey-1, var(--surface-hover))',
|
|
785
|
-
fontSize: '.68rem',
|
|
786
|
-
color: 'var(--fg, var(--t1))',
|
|
787
|
-
cursor: 'pointer',
|
|
788
|
-
fontWeight: 500,
|
|
789
|
-
}}
|
|
790
|
-
>
|
|
791
|
-
<span style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
792
|
-
<Globe size={12} color="var(--accent, var(--blue))" />
|
|
793
|
-
{COMMON_TIMEZONES.find(t => t.value === tz)?.label || tz}
|
|
794
|
-
</span>
|
|
795
|
-
<ChevronDown size={12} color="var(--muted, var(--t2))" />
|
|
796
|
-
</button>
|
|
797
|
-
|
|
798
|
-
{showTzPicker && (
|
|
799
|
-
<div style={{ marginTop: 4, background: 'var(--surface, var(--bg))', border: '1px solid var(--border-light, var(--border))', borderRadius: 6, boxShadow: 'var(--shadow)', padding: 4, display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
800
|
-
{COMMON_TIMEZONES.map(t => (
|
|
801
|
-
<button
|
|
802
|
-
key={t.value}
|
|
803
|
-
type="button"
|
|
804
|
-
onClick={() => { setTz(t.value); setShowTzPicker(false); }}
|
|
805
|
-
className="cynx-timepicker-cell"
|
|
806
|
-
style={{
|
|
807
|
-
padding: '4px 6px',
|
|
808
|
-
borderRadius: 4,
|
|
809
|
-
border: 'none',
|
|
810
|
-
textAlign: 'left',
|
|
811
|
-
fontSize: '.68rem',
|
|
812
|
-
background: tz === t.value ? 'var(--accent, var(--blue))' : 'transparent',
|
|
813
|
-
color: tz === t.value ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
814
|
-
cursor: 'pointer',
|
|
815
|
-
fontWeight: tz === t.value ? 600 : 400,
|
|
816
|
-
}}
|
|
817
|
-
>
|
|
818
|
-
{t.label}
|
|
819
|
-
</button>
|
|
820
|
-
))}
|
|
821
|
-
</div>
|
|
822
|
-
)}
|
|
823
|
-
</div>
|
|
824
|
-
)}
|
|
825
|
-
|
|
826
|
-
{/* Optional Quick Presets Bar */}
|
|
827
|
-
{showPresets && (
|
|
828
|
-
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
829
|
-
{(mode === '12h' ? presets12 : presets24).map(p => (
|
|
830
|
-
<button
|
|
831
|
-
key={p}
|
|
832
|
-
type="button"
|
|
833
|
-
onClick={() => {
|
|
834
|
-
const newP = parseTime(p, mode === '12h', showSeconds);
|
|
835
|
-
emitChange(newP);
|
|
836
|
-
}}
|
|
837
|
-
className="cynx-timepicker-cell"
|
|
838
|
-
style={{
|
|
839
|
-
padding: '3px 6px',
|
|
840
|
-
borderRadius: 4,
|
|
841
|
-
fontSize: '.68rem',
|
|
842
|
-
border: '1px solid var(--border-light, var(--border))',
|
|
843
|
-
background: inputValue === p ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
844
|
-
color: inputValue === p ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
845
|
-
cursor: 'pointer',
|
|
846
|
-
fontWeight: 500,
|
|
847
|
-
}}
|
|
848
|
-
>
|
|
849
|
-
{p}
|
|
850
|
-
</button>
|
|
851
|
-
))}
|
|
852
|
-
</div>
|
|
853
|
-
)}
|
|
854
|
-
|
|
855
|
-
{/* AM / PM Segment Selector (Only for 12h mode) */}
|
|
856
|
-
{mode === '12h' && (
|
|
857
|
-
<div style={{ display: 'flex', gap: 6, marginBottom: 8, justifyContent: 'center' }}>
|
|
858
|
-
<button
|
|
859
|
-
type="button"
|
|
860
|
-
onClick={() => toggleAmPm('AM')}
|
|
861
|
-
className="cynx-timepicker-cell"
|
|
862
|
-
style={{
|
|
863
|
-
flex: 1,
|
|
864
|
-
padding: '4px 0',
|
|
865
|
-
borderRadius: 6,
|
|
866
|
-
border: '1px solid var(--border-light, var(--border))',
|
|
867
|
-
fontSize: '.75rem',
|
|
868
|
-
fontWeight: parsed.ampm === 'AM' ? 700 : 500,
|
|
869
|
-
background: parsed.ampm === 'AM' ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
870
|
-
color: parsed.ampm === 'AM' ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
871
|
-
cursor: 'pointer',
|
|
872
|
-
textAlign: 'center',
|
|
873
|
-
}}
|
|
874
|
-
>
|
|
875
|
-
AM (Утро)
|
|
876
|
-
</button>
|
|
877
|
-
<button
|
|
878
|
-
type="button"
|
|
879
|
-
onClick={() => toggleAmPm('PM')}
|
|
880
|
-
className="cynx-timepicker-cell"
|
|
881
|
-
style={{
|
|
882
|
-
flex: 1,
|
|
883
|
-
padding: '4px 0',
|
|
884
|
-
borderRadius: 6,
|
|
885
|
-
border: '1px solid var(--border-light, var(--border))',
|
|
886
|
-
fontSize: '.75rem',
|
|
887
|
-
fontWeight: parsed.ampm === 'PM' ? 700 : 500,
|
|
888
|
-
background: parsed.ampm === 'PM' ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
889
|
-
color: parsed.ampm === 'PM' ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
890
|
-
cursor: 'pointer',
|
|
891
|
-
textAlign: 'center',
|
|
892
|
-
}}
|
|
893
|
-
>
|
|
894
|
-
PM (Вечер)
|
|
895
|
-
</button>
|
|
896
|
-
</div>
|
|
897
|
-
)}
|
|
898
|
-
|
|
899
|
-
{/* VARIANT 1: STEPPER MODE (Up/Down +/- Buttons) */}
|
|
900
|
-
{activeVariant === 'stepper' ? (
|
|
901
|
-
<div style={{ display: 'grid', gridTemplateColumns: showSeconds ? '1fr 1fr 1fr' : '1fr 1fr', gap: 10, padding: '4px 0' }}>
|
|
902
|
-
{/* Hours Stepper */}
|
|
903
|
-
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
904
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>
|
|
905
|
-
{mode === '12h' ? 'Час (1-12)' : 'Час (0-23)'}
|
|
906
|
-
</div>
|
|
907
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepHour(1)} title="+1 Час">
|
|
908
|
-
<ChevronUp size={14} />
|
|
909
|
-
</button>
|
|
910
|
-
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
911
|
-
{mode === '12h' ? parsed.h12 : parsed.h24}
|
|
912
|
-
</div>
|
|
913
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepHour(-1)} title="-1 Час">
|
|
914
|
-
<ChevronDown size={14} />
|
|
915
|
-
</button>
|
|
916
|
-
</div>
|
|
917
|
-
|
|
918
|
-
{/* Minutes Stepper */}
|
|
919
|
-
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
920
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>Мин (0-59)</div>
|
|
921
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepMinute(1)} title="+1 Мин">
|
|
922
|
-
<ChevronUp size={14} />
|
|
923
|
-
</button>
|
|
924
|
-
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
925
|
-
{parsed.m}
|
|
926
|
-
</div>
|
|
927
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepMinute(-1)} title="-1 Мин">
|
|
928
|
-
<ChevronDown size={14} />
|
|
929
|
-
</button>
|
|
930
|
-
</div>
|
|
931
|
-
|
|
932
|
-
{/* Seconds Stepper */}
|
|
933
|
-
{showSeconds && (
|
|
934
|
-
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
935
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>Сек (0-59)</div>
|
|
936
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepSecond(1)} title="+1 Сек">
|
|
937
|
-
<ChevronUp size={14} />
|
|
938
|
-
</button>
|
|
939
|
-
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
940
|
-
{parsed.s}
|
|
941
|
-
</div>
|
|
942
|
-
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepSecond(-1)} title="-1 Сек">
|
|
943
|
-
<ChevronDown size={14} />
|
|
944
|
-
</button>
|
|
945
|
-
</div>
|
|
946
|
-
)}
|
|
947
|
-
</div>
|
|
948
|
-
) : (
|
|
949
|
-
/* VARIANT 2: LIST MODE (Full List 00..59) */
|
|
950
|
-
<div style={{ display: 'grid', gridTemplateColumns: showSeconds ? '1fr 1fr 1fr' : '1fr 1fr', gap: 6 }}>
|
|
951
|
-
{/* Hours Column */}
|
|
952
|
-
<div>
|
|
953
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>
|
|
954
|
-
{mode === '12h' ? 'Час (1-12)' : 'Час (0-23)'}
|
|
955
|
-
</div>
|
|
956
|
-
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2, paddingRight: 2 }}>
|
|
957
|
-
{(mode === '12h' ? hours12List : hours24List).map(hNum => {
|
|
958
|
-
const isSelected = mode === '12h' ? parsed.h12 === pad(hNum) : parsed.h24 === pad(hNum);
|
|
959
|
-
return (
|
|
960
|
-
<button
|
|
961
|
-
key={hNum}
|
|
962
|
-
type="button"
|
|
963
|
-
onClick={() => (mode === '12h' ? selectH12(hNum) : selectH24(hNum))}
|
|
964
|
-
className="cynx-timepicker-cell"
|
|
965
|
-
style={{
|
|
966
|
-
padding: '3px 6px',
|
|
967
|
-
borderRadius: 4,
|
|
968
|
-
border: 'none',
|
|
969
|
-
textAlign: 'center',
|
|
970
|
-
fontSize: '.75rem',
|
|
971
|
-
cursor: 'pointer',
|
|
972
|
-
fontWeight: isSelected ? 700 : 400,
|
|
973
|
-
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
974
|
-
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
975
|
-
}}
|
|
976
|
-
>
|
|
977
|
-
{pad(hNum)}
|
|
978
|
-
</button>
|
|
979
|
-
);
|
|
980
|
-
})}
|
|
981
|
-
</div>
|
|
982
|
-
</div>
|
|
983
|
-
|
|
984
|
-
{/* Minutes Column: FULL LIST 00 to 59! */}
|
|
985
|
-
<div>
|
|
986
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>Мин (00-59)</div>
|
|
987
|
-
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2, paddingRight: 2 }}>
|
|
988
|
-
{fullMinutesList.map(mNum => {
|
|
989
|
-
const mStr = pad(mNum);
|
|
990
|
-
const isSelected = parsed.m === mStr;
|
|
991
|
-
return (
|
|
992
|
-
<button
|
|
993
|
-
key={mNum}
|
|
994
|
-
type="button"
|
|
995
|
-
onClick={() => selectMin(mNum)}
|
|
996
|
-
className="cynx-timepicker-cell"
|
|
997
|
-
style={{
|
|
998
|
-
padding: '3px 6px',
|
|
999
|
-
borderRadius: 4,
|
|
1000
|
-
border: 'none',
|
|
1001
|
-
textAlign: 'center',
|
|
1002
|
-
fontSize: '.75rem',
|
|
1003
|
-
cursor: 'pointer',
|
|
1004
|
-
fontWeight: isSelected ? 700 : 400,
|
|
1005
|
-
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
1006
|
-
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
1007
|
-
}}
|
|
1008
|
-
>
|
|
1009
|
-
{mStr}
|
|
1010
|
-
</button>
|
|
1011
|
-
);
|
|
1012
|
-
})}
|
|
1013
|
-
</div>
|
|
1014
|
-
</div>
|
|
1015
|
-
|
|
1016
|
-
{/* Seconds Column (if showSeconds): FULL LIST 00 to 59! */}
|
|
1017
|
-
{showSeconds && (
|
|
1018
|
-
<div>
|
|
1019
|
-
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>Сек (00-59)</div>
|
|
1020
|
-
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
1021
|
-
{fullMinutesList.map(sNum => {
|
|
1022
|
-
const sStr = pad(sNum);
|
|
1023
|
-
const isSelected = parsed.s === sStr;
|
|
1024
|
-
return (
|
|
1025
|
-
<button
|
|
1026
|
-
key={sNum}
|
|
1027
|
-
type="button"
|
|
1028
|
-
onClick={() => selectSec(sNum)}
|
|
1029
|
-
className="cynx-timepicker-cell"
|
|
1030
|
-
style={{
|
|
1031
|
-
padding: '3px 6px',
|
|
1032
|
-
borderRadius: 4,
|
|
1033
|
-
border: 'none',
|
|
1034
|
-
textAlign: 'center',
|
|
1035
|
-
fontSize: '.75rem',
|
|
1036
|
-
cursor: 'pointer',
|
|
1037
|
-
fontWeight: isSelected ? 700 : 400,
|
|
1038
|
-
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
1039
|
-
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
1040
|
-
}}
|
|
1041
|
-
>
|
|
1042
|
-
{sStr}
|
|
1043
|
-
</button>
|
|
1044
|
-
);
|
|
1045
|
-
})}
|
|
1046
|
-
</div>
|
|
1047
|
-
</div>
|
|
1048
|
-
)}
|
|
1049
|
-
</div>
|
|
1050
|
-
)}
|
|
1051
|
-
|
|
1052
|
-
{/* Footer Actions */}
|
|
1053
|
-
<div style={{ marginTop: 8, paddingTop: 6, borderTop: '1px solid var(--border-light, var(--border))', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
1054
|
-
<button
|
|
1055
|
-
type="button"
|
|
1056
|
-
onClick={clearTime}
|
|
1057
|
-
className="cynx-timepicker-cell"
|
|
1058
|
-
style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--danger)', fontSize: '.7rem', fontWeight: 500 }}
|
|
1059
|
-
>
|
|
1060
|
-
Сбросить
|
|
1061
|
-
</button>
|
|
1062
|
-
<button
|
|
1063
|
-
type="button"
|
|
1064
|
-
onClick={closePicker}
|
|
1065
|
-
className="cynx-timepicker-cell"
|
|
1066
|
-
style={{ padding: '3px 10px', borderRadius: 4, border: 'none', background: 'var(--accent, var(--blue))', color: '#ffffff', fontSize: '.7rem', cursor: 'pointer', fontWeight: 600, display: 'flex', alignItems: 'center', gap: 4 }}
|
|
1067
|
-
>
|
|
1068
|
-
<Check size={12} /> Готово
|
|
1069
|
-
</button>
|
|
1070
|
-
</div>
|
|
1071
|
-
</div>,
|
|
1072
|
-
document.body
|
|
1073
|
-
)}
|
|
1074
|
-
</div>
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
export default TimePicker;
|
|
1
|
+
import { useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { Clock, ChevronDown, ChevronUp, Check, X, Globe, List, Sliders } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
const STYLES = `
|
|
6
|
+
@keyframes cynxTimePickerPopIn {
|
|
7
|
+
0% {
|
|
8
|
+
opacity: 0;
|
|
9
|
+
transform: translateY(-8px) scale(0.96);
|
|
10
|
+
}
|
|
11
|
+
100% {
|
|
12
|
+
opacity: 1;
|
|
13
|
+
transform: translateY(0) scale(1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@keyframes cynxTimePickerPopOut {
|
|
18
|
+
0% {
|
|
19
|
+
opacity: 1;
|
|
20
|
+
transform: translateY(0) scale(1);
|
|
21
|
+
}
|
|
22
|
+
100% {
|
|
23
|
+
opacity: 0;
|
|
24
|
+
transform: translateY(-8px) scale(0.96);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.cynx-timepicker-drop {
|
|
29
|
+
animation: cynxTimePickerPopIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
30
|
+
will-change: opacity, transform;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.cynx-timepicker-drop.closing {
|
|
34
|
+
animation: cynxTimePickerPopOut 0.14s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.cynx-timepicker-cell {
|
|
38
|
+
transition: background-color 0.12s ease, color 0.12s ease;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.cynx-timepicker-cell:hover {
|
|
42
|
+
background-color: var(--hover-bg, var(--grey-1, #f5f5f8));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.cynx-timepicker-stepper-btn {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: 28px;
|
|
51
|
+
border-radius: var(--rads, 8px);
|
|
52
|
+
border: 1px solid var(--bd, var(--border, #d7d8e0));
|
|
53
|
+
background: var(--grey-1, #f5f5f8);
|
|
54
|
+
color: var(--t1, var(--primary-text, #1a1a2e));
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.cynx-timepicker-stepper-btn:hover {
|
|
60
|
+
background: var(--surface, #ffffff);
|
|
61
|
+
border-color: var(--accent);
|
|
62
|
+
color: var(--accent);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.cynx-timepicker-stepper-btn:active {
|
|
66
|
+
background: var(--accent-bg, rgba(249,158,44,0.08));
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const STYLE_ID = 'cynx-timepicker-styles';
|
|
71
|
+
|
|
72
|
+
function ensureStyles() {
|
|
73
|
+
if (typeof document === 'undefined') return;
|
|
74
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
75
|
+
const tag = document.createElement('style');
|
|
76
|
+
tag.id = STYLE_ID;
|
|
77
|
+
tag.textContent = STYLES;
|
|
78
|
+
document.head.appendChild(tag);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const COMMON_TIMEZONES = [
|
|
82
|
+
{ value: 'system', label: 'Системное время (Local)' },
|
|
83
|
+
{ value: 'Asia/Tashkent', label: 'Ташкент (UTC+5)' },
|
|
84
|
+
{ value: 'America/New_York', label: 'Нью-Йорк (UTC-5)' },
|
|
85
|
+
{ value: 'Europe/London', label: 'Лондон (UTC+0)' },
|
|
86
|
+
{ value: 'Asia/Tokyo', label: 'Токио (UTC+9)' },
|
|
87
|
+
{ value: 'UTC', label: 'UTC' },
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
function pad(n) {
|
|
91
|
+
return String(n).padStart(2, '0');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function to12h(h24) {
|
|
95
|
+
const h = parseInt(h24, 10);
|
|
96
|
+
if (isNaN(h)) return { h12: '12', ampm: 'AM' };
|
|
97
|
+
const ampm = h >= 12 ? 'PM' : 'AM';
|
|
98
|
+
let h12 = h % 12;
|
|
99
|
+
if (h12 === 0) h12 = 12;
|
|
100
|
+
return { h12: pad(h12), ampm };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function to24h(h12, ampm) {
|
|
104
|
+
let h = parseInt(h12, 10);
|
|
105
|
+
if (isNaN(h)) return '00';
|
|
106
|
+
if (ampm === 'PM' && h < 12) h += 12;
|
|
107
|
+
if (ampm === 'AM' && h === 12) h = 0;
|
|
108
|
+
return pad(h);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseTime(val, is12h, showSeconds) {
|
|
112
|
+
if (!val || typeof val !== 'string') return { h24: '00', h12: '12', m: '00', s: '00', ampm: 'AM' };
|
|
113
|
+
|
|
114
|
+
let str = val.trim();
|
|
115
|
+
let ampm = 'AM';
|
|
116
|
+
if (/pm/i.test(str)) { ampm = 'PM'; str = str.replace(/pm/i, '').trim(); }
|
|
117
|
+
else if (/am/i.test(str)) { ampm = 'AM'; str = str.replace(/am/i, '').trim(); }
|
|
118
|
+
|
|
119
|
+
let p0 = 0, p1 = 0, p2 = 0;
|
|
120
|
+
|
|
121
|
+
if (str.includes(':')) {
|
|
122
|
+
const parts = str.split(':').map(p => p.trim());
|
|
123
|
+
p0 = parseInt(parts[0], 10) || 0;
|
|
124
|
+
p1 = parseInt(parts[1], 10) || 0;
|
|
125
|
+
p2 = parseInt(parts[2], 10) || 0;
|
|
126
|
+
} else if (/^\d{3,6}$/.test(str)) {
|
|
127
|
+
p0 = parseInt(str.slice(0, 2), 10) || 0;
|
|
128
|
+
p1 = parseInt(str.slice(2, 4), 10) || 0;
|
|
129
|
+
p2 = parseInt(str.slice(4, 6), 10) || 0;
|
|
130
|
+
} else {
|
|
131
|
+
p0 = parseInt(str, 10) || 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let h24 = '00';
|
|
135
|
+
let h12 = '12';
|
|
136
|
+
|
|
137
|
+
if (is12h) {
|
|
138
|
+
if (p0 > 12) {
|
|
139
|
+
h24 = pad(Math.min(23, Math.max(0, p0)));
|
|
140
|
+
const conv = to12h(h24);
|
|
141
|
+
h12 = conv.h12;
|
|
142
|
+
ampm = conv.ampm;
|
|
143
|
+
} else {
|
|
144
|
+
let hNum = Math.min(12, Math.max(1, p0));
|
|
145
|
+
h12 = pad(hNum);
|
|
146
|
+
h24 = to24h(h12, ampm);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
let hNum = Math.min(23, Math.max(0, p0));
|
|
150
|
+
h24 = pad(hNum);
|
|
151
|
+
const conv = to12h(h24);
|
|
152
|
+
h12 = conv.h12;
|
|
153
|
+
ampm = conv.ampm;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const m = pad(Math.min(59, Math.max(0, p1)));
|
|
157
|
+
const s = pad(Math.min(59, Math.max(0, p2)));
|
|
158
|
+
|
|
159
|
+
return { h24, h12, m, s, ampm };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function TimePicker({
|
|
163
|
+
value = '',
|
|
164
|
+
onChange,
|
|
165
|
+
variant = 'list', // 'stepper' (+/- buttons) | 'list' (full 00..59 scrollable list)
|
|
166
|
+
showVariantToggle = false, // Default false: clean list mode by default!
|
|
167
|
+
format = '24h', // '24h' | '12h'
|
|
168
|
+
showSeconds = false,
|
|
169
|
+
showIcon = false, // Default false: clock icon hidden by default, set showIcon={true} to display
|
|
170
|
+
hideIcon = false, // Legacy prop alias for showIcon = false
|
|
171
|
+
showFormatToggle = false, // Minimal default: false
|
|
172
|
+
showPresets = false, // Minimal default: false
|
|
173
|
+
showTimezoneSelect = false, // Minimal default: false
|
|
174
|
+
showPlaceholder = false, // Minimal default: false
|
|
175
|
+
timezone = 'Asia/Tashkent',
|
|
176
|
+
label,
|
|
177
|
+
placeholder,
|
|
178
|
+
size = 'sm', // 'xs' | 'sm' | 'md'
|
|
179
|
+
disabled = false,
|
|
180
|
+
readOnly = false,
|
|
181
|
+
style = {},
|
|
182
|
+
className = '',
|
|
183
|
+
}) {
|
|
184
|
+
const displayClockIcon = showIcon && !hideIcon;
|
|
185
|
+
const [open, setOpen] = useState(false);
|
|
186
|
+
const [rendered, setRendered] = useState(false);
|
|
187
|
+
const [closing, setClosing] = useState(false);
|
|
188
|
+
|
|
189
|
+
const [activeVariant, setActiveVariant] = useState(variant);
|
|
190
|
+
const [mode, setMode] = useState(format);
|
|
191
|
+
const [tz, setTz] = useState(timezone);
|
|
192
|
+
const [showTzPicker, setShowTzPicker] = useState(false);
|
|
193
|
+
|
|
194
|
+
const btnRef = useRef(null);
|
|
195
|
+
const dropRef = useRef(null);
|
|
196
|
+
const isTypingRef = useRef(false);
|
|
197
|
+
|
|
198
|
+
const [pos, setPos] = useState({ top: 0, left: 0, width: 230 });
|
|
199
|
+
|
|
200
|
+
ensureStyles();
|
|
201
|
+
|
|
202
|
+
useEffect(() => { setActiveVariant(variant); }, [variant]);
|
|
203
|
+
useEffect(() => { setMode(format); }, [format]);
|
|
204
|
+
useEffect(() => { setTz(timezone); }, [timezone]);
|
|
205
|
+
|
|
206
|
+
const openPicker = useCallback(() => {
|
|
207
|
+
if (disabled || readOnly) return;
|
|
208
|
+
setRendered(true);
|
|
209
|
+
setClosing(false);
|
|
210
|
+
setOpen(true);
|
|
211
|
+
}, [disabled, readOnly]);
|
|
212
|
+
|
|
213
|
+
const closePicker = useCallback(() => {
|
|
214
|
+
if (!open) return;
|
|
215
|
+
setClosing(true);
|
|
216
|
+
setOpen(false);
|
|
217
|
+
setShowTzPicker(false);
|
|
218
|
+
setTimeout(() => {
|
|
219
|
+
setRendered(false);
|
|
220
|
+
setClosing(false);
|
|
221
|
+
}, 140);
|
|
222
|
+
}, [open]);
|
|
223
|
+
|
|
224
|
+
const togglePicker = useCallback(() => {
|
|
225
|
+
if (open) closePicker();
|
|
226
|
+
else openPicker();
|
|
227
|
+
}, [open, closePicker, openPicker]);
|
|
228
|
+
|
|
229
|
+
const formatOutput = useCallback((parsedObj, useMode = mode) => {
|
|
230
|
+
const { h24, h12, m, s, ampm } = parsedObj;
|
|
231
|
+
if (useMode === '12h') {
|
|
232
|
+
return showSeconds ? `${h12}:${m}:${s} ${ampm}` : `${h12}:${m} ${ampm}`;
|
|
233
|
+
}
|
|
234
|
+
return showSeconds ? `${h24}:${m}:${s}` : `${h24}:${m}`;
|
|
235
|
+
}, [mode, showSeconds]);
|
|
236
|
+
|
|
237
|
+
const parsed = parseTime(value, mode === '12h', showSeconds);
|
|
238
|
+
const [inputValue, setInputValue] = useState(() => value ? formatOutput(parsed) : '');
|
|
239
|
+
|
|
240
|
+
// Keep inputValue in sync with props ONLY when user is NOT actively typing!
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (!isTypingRef.current) {
|
|
243
|
+
if (value) {
|
|
244
|
+
const p = parseTime(value, mode === '12h', showSeconds);
|
|
245
|
+
setInputValue(formatOutput(p));
|
|
246
|
+
} else {
|
|
247
|
+
setInputValue('');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}, [value, mode, showSeconds, formatOutput]);
|
|
251
|
+
|
|
252
|
+
const calcPos = useCallback(() => {
|
|
253
|
+
if (!btnRef.current) return;
|
|
254
|
+
const r = btnRef.current.getBoundingClientRect();
|
|
255
|
+
const dropW = mode === '12h' ? 290 : 230;
|
|
256
|
+
const dropH = dropRef.current ? dropRef.current.offsetHeight : 230;
|
|
257
|
+
|
|
258
|
+
let left = r.left;
|
|
259
|
+
if (left + dropW > window.innerWidth - 12) {
|
|
260
|
+
left = Math.max(12, r.right - dropW);
|
|
261
|
+
}
|
|
262
|
+
if (left < 12) left = 12;
|
|
263
|
+
|
|
264
|
+
let top = r.bottom + 4;
|
|
265
|
+
if (top + dropH > window.innerHeight - 12 && r.top - 4 - dropH > 12) {
|
|
266
|
+
top = r.top - 4 - dropH;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
setPos({ top, left, width: Math.max(r.width, dropW) });
|
|
270
|
+
}, [mode]);
|
|
271
|
+
|
|
272
|
+
useLayoutEffect(() => {
|
|
273
|
+
if (!rendered) return;
|
|
274
|
+
calcPos();
|
|
275
|
+
}, [rendered, calcPos]);
|
|
276
|
+
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (!rendered || closing) return;
|
|
279
|
+
function onDown(e) {
|
|
280
|
+
const inBtn = btnRef.current && btnRef.current.contains(e.target);
|
|
281
|
+
const inDrop = dropRef.current && dropRef.current.contains(e.target);
|
|
282
|
+
if (!inBtn && !inDrop) {
|
|
283
|
+
closePicker();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const timer = setTimeout(() => {
|
|
287
|
+
document.addEventListener('mousedown', onDown, true);
|
|
288
|
+
}, 0);
|
|
289
|
+
window.addEventListener('scroll', calcPos, true);
|
|
290
|
+
window.addEventListener('resize', calcPos);
|
|
291
|
+
return () => {
|
|
292
|
+
clearTimeout(timer);
|
|
293
|
+
document.removeEventListener('mousedown', onDown, true);
|
|
294
|
+
window.removeEventListener('scroll', calcPos, true);
|
|
295
|
+
window.removeEventListener('resize', calcPos);
|
|
296
|
+
};
|
|
297
|
+
}, [rendered, closing, calcPos, closePicker]);
|
|
298
|
+
|
|
299
|
+
const emitChange = (parsedObj, useMode = mode) => {
|
|
300
|
+
const formatted = formatOutput(parsedObj, useMode);
|
|
301
|
+
setInputValue(formatted);
|
|
302
|
+
if (onChange) {
|
|
303
|
+
onChange(formatted, {
|
|
304
|
+
hours: parseInt(parsedObj.h24, 10),
|
|
305
|
+
minutes: parseInt(parsedObj.m, 10),
|
|
306
|
+
seconds: parseInt(parsedObj.s, 10),
|
|
307
|
+
ampm: parsedObj.ampm,
|
|
308
|
+
format: useMode,
|
|
309
|
+
timezone: tz,
|
|
310
|
+
variant: activeVariant,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const handleKeyDown = (e) => {
|
|
316
|
+
if (
|
|
317
|
+
['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key) ||
|
|
318
|
+
e.ctrlKey || e.metaKey || e.altKey
|
|
319
|
+
) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const allowed = mode === '12h' ? /^[0-9:\sAPMapm]$/ : /^[0-9:]$/;
|
|
323
|
+
if (!allowed.test(e.key)) {
|
|
324
|
+
e.preventDefault();
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const handleInputChange = (e) => {
|
|
329
|
+
let raw = e.target.value;
|
|
330
|
+
isTypingRef.current = true;
|
|
331
|
+
|
|
332
|
+
// 1. Strict filter: allow ONLY digits and colon (and AM/PM in 12h)
|
|
333
|
+
if (mode === '12h') {
|
|
334
|
+
raw = raw.replace(/[^0-9:\sAPMapm]/g, '');
|
|
335
|
+
} else {
|
|
336
|
+
raw = raw.replace(/[^0-9:]/g, '');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 2. Single-digit hour shortcut (e.g. typing "3" -> "03:")
|
|
340
|
+
if (mode === '24h' && /^[3-9]$/.test(raw)) {
|
|
341
|
+
raw = '0' + raw + ':';
|
|
342
|
+
} else if (mode === '12h' && /^[2-9]$/.test(raw) && !/pm|am/i.test(raw)) {
|
|
343
|
+
raw = '0' + raw + ':';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 3. Auto-append 1st colon after 2 hour digits + cap hour max (23 in 24h, 12 in 12h)
|
|
347
|
+
if (/^\d{2}$/.test(raw) && !inputValue.endsWith(':')) {
|
|
348
|
+
const hNum = parseInt(raw, 10);
|
|
349
|
+
if (mode === '24h' && hNum > 23) raw = '23:';
|
|
350
|
+
else if (mode === '12h' && hNum > 12) raw = '12:';
|
|
351
|
+
else raw = raw + ':';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// 4. Minutes tens digit validation: first digit of minute (after 1st colon) CANNOT be > 5!
|
|
355
|
+
if (/^\d{2}:[6-9]/.test(raw)) {
|
|
356
|
+
raw = raw.replace(/^(\d{2}:)[6-9]/, '$15');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// 5. Auto-append 2nd colon after 2 minute digits if showSeconds is true (e.g. "16:16" -> "16:16:")
|
|
360
|
+
if (showSeconds && /^\d{2}:\d{2}$/.test(raw) && !inputValue.endsWith(':')) {
|
|
361
|
+
const mNum = parseInt(raw.slice(3, 5), 10);
|
|
362
|
+
if (mNum > 59) raw = raw.slice(0, 3) + '59:';
|
|
363
|
+
else raw = raw + ':';
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// 6. Seconds tens digit validation (if showSeconds): first digit of second CANNOT be > 5!
|
|
367
|
+
if (showSeconds && /^\d{2}:\d{2}:[6-9]/.test(raw)) {
|
|
368
|
+
raw = raw.replace(/^(\d{2}:\d{2}:)[6-9]/, '$15');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 7. Prevent 3rd minute digit when showSeconds is FALSE! (e.g. "16:166" -> "16:16")
|
|
372
|
+
if (!showSeconds && /^\d{2}:\d{3,}/.test(raw)) {
|
|
373
|
+
raw = raw.slice(0, 5);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 8. Prevent 3rd second digit when showSeconds is TRUE! (e.g. "16:16:666" -> "16:16:66")
|
|
377
|
+
if (showSeconds && /^\d{2}:\d{2}:\d{3,}/.test(raw)) {
|
|
378
|
+
raw = raw.slice(0, 8);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// 9. Strict Max length capping
|
|
382
|
+
const maxLen = mode === '12h' ? (showSeconds ? 11 : 8) : (showSeconds ? 8 : 5);
|
|
383
|
+
if (raw.length > maxLen) {
|
|
384
|
+
raw = raw.slice(0, maxLen);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
e.target.value = raw;
|
|
388
|
+
setInputValue(raw);
|
|
389
|
+
|
|
390
|
+
if (!raw) {
|
|
391
|
+
if (onChange) onChange('', { hours: null, minutes: null, seconds: null, ampm: null, format: mode, timezone: tz, variant: activeVariant });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Emit change if raw matches a complete valid time pattern
|
|
396
|
+
if (/^\d{1,2}:\d{1,2}(:\d{1,2})?(\s*[ap]m)?$/i.test(raw) || /^\d{4}$/.test(raw)) {
|
|
397
|
+
const p = parseTime(raw, mode === '12h', showSeconds);
|
|
398
|
+
const formatted = formatOutput(p);
|
|
399
|
+
if (onChange) {
|
|
400
|
+
onChange(formatted, {
|
|
401
|
+
hours: parseInt(p.h24, 10),
|
|
402
|
+
minutes: parseInt(p.m, 10),
|
|
403
|
+
seconds: parseInt(p.s, 10),
|
|
404
|
+
ampm: p.ampm,
|
|
405
|
+
format: mode,
|
|
406
|
+
timezone: tz,
|
|
407
|
+
variant: activeVariant,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const handleInputBlur = () => {
|
|
414
|
+
isTypingRef.current = false;
|
|
415
|
+
if (!inputValue) return;
|
|
416
|
+
const p = parseTime(inputValue, mode === '12h', showSeconds);
|
|
417
|
+
emitChange(p);
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// Stepper Up/Down (+/-) handlers
|
|
421
|
+
const stepHour = (delta) => {
|
|
422
|
+
isTypingRef.current = false;
|
|
423
|
+
let curH = mode === '12h' ? parseInt(parsed.h12, 10) : parseInt(parsed.h24, 10);
|
|
424
|
+
if (isNaN(curH)) curH = mode === '12h' ? 12 : 0;
|
|
425
|
+
|
|
426
|
+
if (mode === '12h') {
|
|
427
|
+
let nextH12 = curH + delta;
|
|
428
|
+
let nextAmPm = parsed.ampm;
|
|
429
|
+
if (nextH12 > 12) { nextH12 = 1; }
|
|
430
|
+
else if (nextH12 < 1) { nextH12 = 12; }
|
|
431
|
+
const h12 = pad(nextH12);
|
|
432
|
+
const h24 = to24h(h12, nextAmPm);
|
|
433
|
+
emitChange({ ...parsed, h12, h24, ampm: nextAmPm });
|
|
434
|
+
} else {
|
|
435
|
+
let nextH24 = (curH + delta + 24) % 24;
|
|
436
|
+
const h24 = pad(nextH24);
|
|
437
|
+
const { h12, ampm } = to12h(h24);
|
|
438
|
+
emitChange({ ...parsed, h24, h12, ampm });
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const stepMinute = (delta) => {
|
|
443
|
+
isTypingRef.current = false;
|
|
444
|
+
let curM = parseInt(parsed.m, 10);
|
|
445
|
+
if (isNaN(curM)) curM = 0;
|
|
446
|
+
let nextM = (curM + delta + 60) % 60;
|
|
447
|
+
const m = pad(nextM);
|
|
448
|
+
emitChange({ ...parsed, m });
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const stepSecond = (delta) => {
|
|
452
|
+
isTypingRef.current = false;
|
|
453
|
+
let curS = parseInt(parsed.s, 10);
|
|
454
|
+
if (isNaN(curS)) curS = 0;
|
|
455
|
+
let nextS = (curS + delta + 60) % 60;
|
|
456
|
+
const s = pad(nextS);
|
|
457
|
+
emitChange({ ...parsed, s });
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// List direct selection handlers
|
|
461
|
+
const selectH24 = (hNum) => {
|
|
462
|
+
isTypingRef.current = false;
|
|
463
|
+
const h24 = pad(hNum);
|
|
464
|
+
const { h12, ampm } = to12h(h24);
|
|
465
|
+
emitChange({ ...parsed, h24, h12, ampm });
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const selectH12 = (hNum12) => {
|
|
469
|
+
isTypingRef.current = false;
|
|
470
|
+
const h12 = pad(hNum12);
|
|
471
|
+
const h24 = to24h(h12, parsed.ampm);
|
|
472
|
+
emitChange({ ...parsed, h24, h12 });
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const selectMin = (mNum) => {
|
|
476
|
+
isTypingRef.current = false;
|
|
477
|
+
const m = pad(mNum);
|
|
478
|
+
emitChange({ ...parsed, m });
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
const selectSec = (sNum) => {
|
|
482
|
+
isTypingRef.current = false;
|
|
483
|
+
const s = pad(sNum);
|
|
484
|
+
emitChange({ ...parsed, s });
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const toggleAmPm = (targetAmPm) => {
|
|
488
|
+
isTypingRef.current = false;
|
|
489
|
+
const ampm = targetAmPm;
|
|
490
|
+
const h24 = to24h(parsed.h12, ampm);
|
|
491
|
+
emitChange({ ...parsed, ampm, h24 });
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const switchMode = (newMode) => {
|
|
495
|
+
isTypingRef.current = false;
|
|
496
|
+
setMode(newMode);
|
|
497
|
+
emitChange(parsed, newMode);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const clearTime = (e) => {
|
|
501
|
+
e?.stopPropagation();
|
|
502
|
+
isTypingRef.current = false;
|
|
503
|
+
setInputValue('');
|
|
504
|
+
if (onChange) onChange('', { hours: null, minutes: null, seconds: null, ampm: null, format: mode, timezone: tz, variant: activeVariant });
|
|
505
|
+
closePicker();
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const defaultPlaceholder = showPlaceholder
|
|
509
|
+
? (mode === '12h'
|
|
510
|
+
? (showSeconds ? 'hh:mm:ss AM' : 'hh:mm AM')
|
|
511
|
+
: (showSeconds ? 'HH:MM:SS' : 'HH:MM'))
|
|
512
|
+
: '';
|
|
513
|
+
const ph = placeholder !== undefined ? placeholder : defaultPlaceholder;
|
|
514
|
+
|
|
515
|
+
const hours24List = Array.from({ length: 24 }, (_, i) => i);
|
|
516
|
+
const hours12List = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
517
|
+
const fullMinutesList = Array.from({ length: 60 }, (_, i) => i);
|
|
518
|
+
|
|
519
|
+
const presets24 = ['00:00', '07:00', '08:00', '09:00', '12:00', '18:00', '23:00'];
|
|
520
|
+
const presets12 = ['07:00 AM', '09:00 AM', '12:00 PM', '03:00 PM', '06:00 PM', '11:00 PM'];
|
|
521
|
+
|
|
522
|
+
const inputHeight = style?.height
|
|
523
|
+
? (typeof style.height === 'number' ? `${style.height}px` : style.height)
|
|
524
|
+
: (size === 'xs' ? '24px' : (size === 'sm' ? '32px' : '38px'));
|
|
525
|
+
const fontSize = (size === 'xs' || (style?.height && parseInt(style.height) <= 26)) ? '.72rem' : (size === 'sm' ? '.78rem' : '.85rem');
|
|
526
|
+
|
|
527
|
+
return (
|
|
528
|
+
<div
|
|
529
|
+
className={`cynx-timepicker-wrap ${className}`}
|
|
530
|
+
style={{ display: 'inline-flex', flexDirection: 'column', position: 'relative', width: style?.width || 'auto', boxSizing: 'border-box', minWidth: 0, ...style }}
|
|
531
|
+
>
|
|
532
|
+
{label && (
|
|
533
|
+
<label
|
|
534
|
+
style={{ fontSize: 11, fontWeight: 600, color: 'var(--t2, var(--muted))', textTransform: 'uppercase', letterSpacing: '.08em', display: 'block', marginBottom: 4 }}
|
|
535
|
+
>
|
|
536
|
+
{label}
|
|
537
|
+
</label>
|
|
538
|
+
)}
|
|
539
|
+
|
|
540
|
+
{/* Input Trigger Field */}
|
|
541
|
+
<div ref={btnRef} style={{ position: 'relative', display: 'flex', alignItems: 'center', width: '100%', boxSizing: 'border-box', minWidth: 0 }}>
|
|
542
|
+
{displayClockIcon && (
|
|
543
|
+
<button
|
|
544
|
+
type="button"
|
|
545
|
+
onClick={togglePicker}
|
|
546
|
+
disabled={disabled || readOnly}
|
|
547
|
+
title="Выбрать время"
|
|
548
|
+
style={{
|
|
549
|
+
position: 'absolute',
|
|
550
|
+
left: 10,
|
|
551
|
+
background: 'none',
|
|
552
|
+
border: 'none',
|
|
553
|
+
cursor: (disabled || readOnly) ? 'default' : 'pointer',
|
|
554
|
+
padding: 0,
|
|
555
|
+
display: 'flex',
|
|
556
|
+
alignItems: 'center',
|
|
557
|
+
justifyContent: 'center',
|
|
558
|
+
color: open ? 'var(--accent)' : 'var(--t2, var(--muted, #9b9daa))',
|
|
559
|
+
zIndex: 1,
|
|
560
|
+
transition: 'color .15s ease',
|
|
561
|
+
}}
|
|
562
|
+
>
|
|
563
|
+
<Clock size={size === 'sm' ? 14 : 16} />
|
|
564
|
+
</button>
|
|
565
|
+
)}
|
|
566
|
+
|
|
567
|
+
<input
|
|
568
|
+
type="text"
|
|
569
|
+
value={inputValue}
|
|
570
|
+
onChange={handleInputChange}
|
|
571
|
+
onKeyDown={handleKeyDown}
|
|
572
|
+
onBlur={handleInputBlur}
|
|
573
|
+
onFocus={openPicker}
|
|
574
|
+
maxLength={mode === '12h' ? (showSeconds ? 11 : 8) : (showSeconds ? 8 : 5)}
|
|
575
|
+
placeholder={ph}
|
|
576
|
+
disabled={disabled}
|
|
577
|
+
readOnly={readOnly}
|
|
578
|
+
style={{
|
|
579
|
+
display: 'flex',
|
|
580
|
+
width: '100%',
|
|
581
|
+
minWidth: 0,
|
|
582
|
+
maxWidth: '100%',
|
|
583
|
+
boxSizing: 'border-box',
|
|
584
|
+
height: inputHeight,
|
|
585
|
+
paddingLeft: displayClockIcon ? (size === 'xs' ? 22 : 28) : (size === 'xs' ? 6 : 10),
|
|
586
|
+
paddingRight: size === 'xs' ? 18 : 26,
|
|
587
|
+
border: `1px solid ${open ? 'var(--accent)' : 'var(--bd, var(--border, #d7d8e0))'}`,
|
|
588
|
+
borderRadius: 'var(--rads, 8px)',
|
|
589
|
+
fontSize: fontSize,
|
|
590
|
+
background: disabled ? 'var(--grey-1, #f5f5f8)' : 'var(--input-bg, var(--surface, #ffffff))',
|
|
591
|
+
color: 'var(--t1, var(--primary-text, #1a1a2e))',
|
|
592
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
593
|
+
letterSpacing: '0.03em',
|
|
594
|
+
fontWeight: 600,
|
|
595
|
+
fontVariantNumeric: 'tabular-nums',
|
|
596
|
+
textAlign: 'left',
|
|
597
|
+
outline: 'none',
|
|
598
|
+
boxShadow: open
|
|
599
|
+
? 'var(--pd, rgba(249,158,44,.12)), var(--shadow, 0 1px 3px rgba(20,22,41,.1))'
|
|
600
|
+
: 'var(--shadow, 0 1px 3px rgba(20,22,41,.1))',
|
|
601
|
+
opacity: disabled ? 0.5 : 1,
|
|
602
|
+
cursor: disabled ? 'not-allowed' : undefined,
|
|
603
|
+
transition: 'border-color .14s, box-shadow .14s',
|
|
604
|
+
}}
|
|
605
|
+
/>
|
|
606
|
+
|
|
607
|
+
<div style={{ position: 'absolute', right: 8, display: 'flex', alignItems: 'center' }}>
|
|
608
|
+
{inputValue && !disabled && !readOnly ? (
|
|
609
|
+
<button
|
|
610
|
+
type="button"
|
|
611
|
+
onClick={clearTime}
|
|
612
|
+
title="Очистить"
|
|
613
|
+
style={{
|
|
614
|
+
background: 'none',
|
|
615
|
+
border: 'none',
|
|
616
|
+
cursor: 'pointer',
|
|
617
|
+
color: 'var(--t2, var(--muted, #9b9daa))',
|
|
618
|
+
padding: 2,
|
|
619
|
+
display: 'flex',
|
|
620
|
+
alignItems: 'center',
|
|
621
|
+
justifyContent: 'center',
|
|
622
|
+
transition: 'color .14s ease',
|
|
623
|
+
}}
|
|
624
|
+
onMouseEnter={e => e.currentTarget.style.color = 'var(--danger, #f64747)'}
|
|
625
|
+
onMouseLeave={e => e.currentTarget.style.color = 'var(--t2, var(--muted, #9b9daa))'}
|
|
626
|
+
>
|
|
627
|
+
<X size={13} />
|
|
628
|
+
</button>
|
|
629
|
+
) : (
|
|
630
|
+
<ChevronDown
|
|
631
|
+
size={13}
|
|
632
|
+
style={{
|
|
633
|
+
color: open ? 'var(--accent)' : 'var(--t2, var(--muted, #9b9daa))',
|
|
634
|
+
transform: open ? 'rotate(180deg)' : 'none',
|
|
635
|
+
transition: 'transform .2s ease, color .15s ease',
|
|
636
|
+
pointerEvents: 'none',
|
|
637
|
+
}}
|
|
638
|
+
/>
|
|
639
|
+
)}
|
|
640
|
+
</div>
|
|
641
|
+
</div>
|
|
642
|
+
|
|
643
|
+
{/* PORTAL DROPDOWN POPUP */}
|
|
644
|
+
{rendered && createPortal(
|
|
645
|
+
<div
|
|
646
|
+
ref={dropRef}
|
|
647
|
+
className={`cynx-timepicker-drop ${closing ? 'closing' : ''}`}
|
|
648
|
+
style={{
|
|
649
|
+
position: 'fixed',
|
|
650
|
+
top: pos.top,
|
|
651
|
+
left: pos.left,
|
|
652
|
+
zIndex: 999999,
|
|
653
|
+
background: 'var(--surface, #ffffff)',
|
|
654
|
+
border: '1px solid var(--border, var(--bd, #d7d8e0))',
|
|
655
|
+
borderRadius: 'var(--rad, 10px)',
|
|
656
|
+
boxShadow: 'var(--shadow-lg, 0 10px 25px rgba(0,0,0,0.15))',
|
|
657
|
+
padding: 10,
|
|
658
|
+
width: mode === '12h' ? 290 : 240,
|
|
659
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
660
|
+
boxSizing: 'border-box',
|
|
661
|
+
fontSize: '.78rem',
|
|
662
|
+
userSelect: 'none',
|
|
663
|
+
fontFamily: 'var(--sans, inherit)',
|
|
664
|
+
}}
|
|
665
|
+
>
|
|
666
|
+
{/* Header Bar: Variant Switcher */}
|
|
667
|
+
{showVariantToggle && (
|
|
668
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
669
|
+
<span style={{ fontSize: '.68rem', fontWeight: 700, color: 'var(--fg, var(--t1))', textTransform: 'uppercase', letterSpacing: '.05em' }}>
|
|
670
|
+
Режим
|
|
671
|
+
</span>
|
|
672
|
+
|
|
673
|
+
<div style={{ display: 'inline-flex', background: 'var(--grey-1, var(--surface-hover))', padding: 2, borderRadius: 6, border: '1px solid var(--border-light, var(--border))' }}>
|
|
674
|
+
<button
|
|
675
|
+
type="button"
|
|
676
|
+
onClick={() => setActiveVariant('stepper')}
|
|
677
|
+
className="cynx-timepicker-cell"
|
|
678
|
+
style={{
|
|
679
|
+
padding: '2px 8px',
|
|
680
|
+
borderRadius: 4,
|
|
681
|
+
border: 'none',
|
|
682
|
+
fontSize: '.68rem',
|
|
683
|
+
fontWeight: activeVariant === 'stepper' ? 700 : 500,
|
|
684
|
+
background: activeVariant === 'stepper' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
685
|
+
color: activeVariant === 'stepper' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
686
|
+
boxShadow: activeVariant === 'stepper' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
687
|
+
cursor: 'pointer',
|
|
688
|
+
display: 'flex',
|
|
689
|
+
alignItems: 'center',
|
|
690
|
+
gap: 3,
|
|
691
|
+
}}
|
|
692
|
+
>
|
|
693
|
+
<Sliders size={11} /> Спиннер (+/-)
|
|
694
|
+
</button>
|
|
695
|
+
|
|
696
|
+
<button
|
|
697
|
+
type="button"
|
|
698
|
+
onClick={() => setActiveVariant('list')}
|
|
699
|
+
className="cynx-timepicker-cell"
|
|
700
|
+
style={{
|
|
701
|
+
padding: '2px 8px',
|
|
702
|
+
borderRadius: 4,
|
|
703
|
+
border: 'none',
|
|
704
|
+
fontSize: '.68rem',
|
|
705
|
+
fontWeight: activeVariant === 'list' ? 700 : 500,
|
|
706
|
+
background: activeVariant === 'list' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
707
|
+
color: activeVariant === 'list' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
708
|
+
boxShadow: activeVariant === 'list' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
709
|
+
cursor: 'pointer',
|
|
710
|
+
display: 'flex',
|
|
711
|
+
alignItems: 'center',
|
|
712
|
+
gap: 3,
|
|
713
|
+
}}
|
|
714
|
+
>
|
|
715
|
+
<List size={11} /> Список (00-59)
|
|
716
|
+
</button>
|
|
717
|
+
</div>
|
|
718
|
+
</div>
|
|
719
|
+
)}
|
|
720
|
+
|
|
721
|
+
{/* Optional Format Switcher (24h / 12h) */}
|
|
722
|
+
{showFormatToggle && (
|
|
723
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
724
|
+
<span style={{ fontSize: '.68rem', fontWeight: 700, color: 'var(--fg, var(--t1))', textTransform: 'uppercase', letterSpacing: '.05em' }}>
|
|
725
|
+
Формат
|
|
726
|
+
</span>
|
|
727
|
+
|
|
728
|
+
<div style={{ display: 'inline-flex', background: 'var(--grey-1, var(--surface-hover))', padding: 2, borderRadius: 6, border: '1px solid var(--border-light, var(--border))' }}>
|
|
729
|
+
<button
|
|
730
|
+
type="button"
|
|
731
|
+
onClick={() => switchMode('24h')}
|
|
732
|
+
className="cynx-timepicker-cell"
|
|
733
|
+
style={{
|
|
734
|
+
padding: '2px 8px',
|
|
735
|
+
borderRadius: 4,
|
|
736
|
+
border: 'none',
|
|
737
|
+
fontSize: '.68rem',
|
|
738
|
+
fontWeight: mode === '24h' ? 700 : 500,
|
|
739
|
+
background: mode === '24h' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
740
|
+
color: mode === '24h' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
741
|
+
boxShadow: mode === '24h' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
742
|
+
cursor: 'pointer',
|
|
743
|
+
}}
|
|
744
|
+
>
|
|
745
|
+
24h
|
|
746
|
+
</button>
|
|
747
|
+
<button
|
|
748
|
+
type="button"
|
|
749
|
+
onClick={() => switchMode('12h')}
|
|
750
|
+
className="cynx-timepicker-cell"
|
|
751
|
+
style={{
|
|
752
|
+
padding: '2px 8px',
|
|
753
|
+
borderRadius: 4,
|
|
754
|
+
border: 'none',
|
|
755
|
+
fontSize: '.68rem',
|
|
756
|
+
fontWeight: mode === '12h' ? 700 : 500,
|
|
757
|
+
background: mode === '12h' ? 'var(--surface, var(--bg))' : 'transparent',
|
|
758
|
+
color: mode === '12h' ? 'var(--accent, var(--blue))' : 'var(--muted, var(--t2))',
|
|
759
|
+
boxShadow: mode === '12h' ? '0 1px 3px rgba(0,0,0,0.1)' : 'none',
|
|
760
|
+
cursor: 'pointer',
|
|
761
|
+
}}
|
|
762
|
+
>
|
|
763
|
+
12h AM/PM
|
|
764
|
+
</button>
|
|
765
|
+
</div>
|
|
766
|
+
</div>
|
|
767
|
+
)}
|
|
768
|
+
|
|
769
|
+
{/* Optional Timezone Selector Header */}
|
|
770
|
+
{showTimezoneSelect && (
|
|
771
|
+
<div style={{ marginBottom: 8 }}>
|
|
772
|
+
<button
|
|
773
|
+
type="button"
|
|
774
|
+
onClick={() => setShowTzPicker(prev => !prev)}
|
|
775
|
+
className="cynx-timepicker-cell"
|
|
776
|
+
style={{
|
|
777
|
+
display: 'flex',
|
|
778
|
+
alignItems: 'center',
|
|
779
|
+
justifyContent: 'space-between',
|
|
780
|
+
width: '100%',
|
|
781
|
+
padding: '4px 8px',
|
|
782
|
+
borderRadius: 6,
|
|
783
|
+
border: '1px solid var(--border-light, var(--border))',
|
|
784
|
+
background: 'var(--grey-1, var(--surface-hover))',
|
|
785
|
+
fontSize: '.68rem',
|
|
786
|
+
color: 'var(--fg, var(--t1))',
|
|
787
|
+
cursor: 'pointer',
|
|
788
|
+
fontWeight: 500,
|
|
789
|
+
}}
|
|
790
|
+
>
|
|
791
|
+
<span style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
792
|
+
<Globe size={12} color="var(--accent, var(--blue))" />
|
|
793
|
+
{COMMON_TIMEZONES.find(t => t.value === tz)?.label || tz}
|
|
794
|
+
</span>
|
|
795
|
+
<ChevronDown size={12} color="var(--muted, var(--t2))" />
|
|
796
|
+
</button>
|
|
797
|
+
|
|
798
|
+
{showTzPicker && (
|
|
799
|
+
<div style={{ marginTop: 4, background: 'var(--surface, var(--bg))', border: '1px solid var(--border-light, var(--border))', borderRadius: 6, boxShadow: 'var(--shadow)', padding: 4, display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
800
|
+
{COMMON_TIMEZONES.map(t => (
|
|
801
|
+
<button
|
|
802
|
+
key={t.value}
|
|
803
|
+
type="button"
|
|
804
|
+
onClick={() => { setTz(t.value); setShowTzPicker(false); }}
|
|
805
|
+
className="cynx-timepicker-cell"
|
|
806
|
+
style={{
|
|
807
|
+
padding: '4px 6px',
|
|
808
|
+
borderRadius: 4,
|
|
809
|
+
border: 'none',
|
|
810
|
+
textAlign: 'left',
|
|
811
|
+
fontSize: '.68rem',
|
|
812
|
+
background: tz === t.value ? 'var(--accent, var(--blue))' : 'transparent',
|
|
813
|
+
color: tz === t.value ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
814
|
+
cursor: 'pointer',
|
|
815
|
+
fontWeight: tz === t.value ? 600 : 400,
|
|
816
|
+
}}
|
|
817
|
+
>
|
|
818
|
+
{t.label}
|
|
819
|
+
</button>
|
|
820
|
+
))}
|
|
821
|
+
</div>
|
|
822
|
+
)}
|
|
823
|
+
</div>
|
|
824
|
+
)}
|
|
825
|
+
|
|
826
|
+
{/* Optional Quick Presets Bar */}
|
|
827
|
+
{showPresets && (
|
|
828
|
+
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap', marginBottom: 8, paddingBottom: 6, borderBottom: '1px solid var(--border-light, var(--border))' }}>
|
|
829
|
+
{(mode === '12h' ? presets12 : presets24).map(p => (
|
|
830
|
+
<button
|
|
831
|
+
key={p}
|
|
832
|
+
type="button"
|
|
833
|
+
onClick={() => {
|
|
834
|
+
const newP = parseTime(p, mode === '12h', showSeconds);
|
|
835
|
+
emitChange(newP);
|
|
836
|
+
}}
|
|
837
|
+
className="cynx-timepicker-cell"
|
|
838
|
+
style={{
|
|
839
|
+
padding: '3px 6px',
|
|
840
|
+
borderRadius: 4,
|
|
841
|
+
fontSize: '.68rem',
|
|
842
|
+
border: '1px solid var(--border-light, var(--border))',
|
|
843
|
+
background: inputValue === p ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
844
|
+
color: inputValue === p ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
845
|
+
cursor: 'pointer',
|
|
846
|
+
fontWeight: 500,
|
|
847
|
+
}}
|
|
848
|
+
>
|
|
849
|
+
{p}
|
|
850
|
+
</button>
|
|
851
|
+
))}
|
|
852
|
+
</div>
|
|
853
|
+
)}
|
|
854
|
+
|
|
855
|
+
{/* AM / PM Segment Selector (Only for 12h mode) */}
|
|
856
|
+
{mode === '12h' && (
|
|
857
|
+
<div style={{ display: 'flex', gap: 6, marginBottom: 8, justifyContent: 'center' }}>
|
|
858
|
+
<button
|
|
859
|
+
type="button"
|
|
860
|
+
onClick={() => toggleAmPm('AM')}
|
|
861
|
+
className="cynx-timepicker-cell"
|
|
862
|
+
style={{
|
|
863
|
+
flex: 1,
|
|
864
|
+
padding: '4px 0',
|
|
865
|
+
borderRadius: 6,
|
|
866
|
+
border: '1px solid var(--border-light, var(--border))',
|
|
867
|
+
fontSize: '.75rem',
|
|
868
|
+
fontWeight: parsed.ampm === 'AM' ? 700 : 500,
|
|
869
|
+
background: parsed.ampm === 'AM' ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
870
|
+
color: parsed.ampm === 'AM' ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
871
|
+
cursor: 'pointer',
|
|
872
|
+
textAlign: 'center',
|
|
873
|
+
}}
|
|
874
|
+
>
|
|
875
|
+
AM (Утро)
|
|
876
|
+
</button>
|
|
877
|
+
<button
|
|
878
|
+
type="button"
|
|
879
|
+
onClick={() => toggleAmPm('PM')}
|
|
880
|
+
className="cynx-timepicker-cell"
|
|
881
|
+
style={{
|
|
882
|
+
flex: 1,
|
|
883
|
+
padding: '4px 0',
|
|
884
|
+
borderRadius: 6,
|
|
885
|
+
border: '1px solid var(--border-light, var(--border))',
|
|
886
|
+
fontSize: '.75rem',
|
|
887
|
+
fontWeight: parsed.ampm === 'PM' ? 700 : 500,
|
|
888
|
+
background: parsed.ampm === 'PM' ? 'var(--accent, var(--blue))' : 'var(--grey-1, var(--surface-hover))',
|
|
889
|
+
color: parsed.ampm === 'PM' ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
890
|
+
cursor: 'pointer',
|
|
891
|
+
textAlign: 'center',
|
|
892
|
+
}}
|
|
893
|
+
>
|
|
894
|
+
PM (Вечер)
|
|
895
|
+
</button>
|
|
896
|
+
</div>
|
|
897
|
+
)}
|
|
898
|
+
|
|
899
|
+
{/* VARIANT 1: STEPPER MODE (Up/Down +/- Buttons) */}
|
|
900
|
+
{activeVariant === 'stepper' ? (
|
|
901
|
+
<div style={{ display: 'grid', gridTemplateColumns: showSeconds ? '1fr 1fr 1fr' : '1fr 1fr', gap: 10, padding: '4px 0' }}>
|
|
902
|
+
{/* Hours Stepper */}
|
|
903
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
904
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>
|
|
905
|
+
{mode === '12h' ? 'Час (1-12)' : 'Час (0-23)'}
|
|
906
|
+
</div>
|
|
907
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepHour(1)} title="+1 Час">
|
|
908
|
+
<ChevronUp size={14} />
|
|
909
|
+
</button>
|
|
910
|
+
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
911
|
+
{mode === '12h' ? parsed.h12 : parsed.h24}
|
|
912
|
+
</div>
|
|
913
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepHour(-1)} title="-1 Час">
|
|
914
|
+
<ChevronDown size={14} />
|
|
915
|
+
</button>
|
|
916
|
+
</div>
|
|
917
|
+
|
|
918
|
+
{/* Minutes Stepper */}
|
|
919
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
920
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>Мин (0-59)</div>
|
|
921
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepMinute(1)} title="+1 Мин">
|
|
922
|
+
<ChevronUp size={14} />
|
|
923
|
+
</button>
|
|
924
|
+
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
925
|
+
{parsed.m}
|
|
926
|
+
</div>
|
|
927
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepMinute(-1)} title="-1 Мин">
|
|
928
|
+
<ChevronDown size={14} />
|
|
929
|
+
</button>
|
|
930
|
+
</div>
|
|
931
|
+
|
|
932
|
+
{/* Seconds Stepper */}
|
|
933
|
+
{showSeconds && (
|
|
934
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
|
|
935
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))' }}>Сек (0-59)</div>
|
|
936
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepSecond(1)} title="+1 Сек">
|
|
937
|
+
<ChevronUp size={14} />
|
|
938
|
+
</button>
|
|
939
|
+
<div style={{ fontSize: '1.2rem', fontWeight: 700, fontVariantNumeric: 'tabular-nums', padding: '6px 0', color: 'var(--accent, var(--blue))' }}>
|
|
940
|
+
{parsed.s}
|
|
941
|
+
</div>
|
|
942
|
+
<button type="button" className="cynx-timepicker-stepper-btn" onClick={() => stepSecond(-1)} title="-1 Сек">
|
|
943
|
+
<ChevronDown size={14} />
|
|
944
|
+
</button>
|
|
945
|
+
</div>
|
|
946
|
+
)}
|
|
947
|
+
</div>
|
|
948
|
+
) : (
|
|
949
|
+
/* VARIANT 2: LIST MODE (Full List 00..59) */
|
|
950
|
+
<div style={{ display: 'grid', gridTemplateColumns: showSeconds ? '1fr 1fr 1fr' : '1fr 1fr', gap: 6 }}>
|
|
951
|
+
{/* Hours Column */}
|
|
952
|
+
<div>
|
|
953
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>
|
|
954
|
+
{mode === '12h' ? 'Час (1-12)' : 'Час (0-23)'}
|
|
955
|
+
</div>
|
|
956
|
+
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2, paddingRight: 2 }}>
|
|
957
|
+
{(mode === '12h' ? hours12List : hours24List).map(hNum => {
|
|
958
|
+
const isSelected = mode === '12h' ? parsed.h12 === pad(hNum) : parsed.h24 === pad(hNum);
|
|
959
|
+
return (
|
|
960
|
+
<button
|
|
961
|
+
key={hNum}
|
|
962
|
+
type="button"
|
|
963
|
+
onClick={() => (mode === '12h' ? selectH12(hNum) : selectH24(hNum))}
|
|
964
|
+
className="cynx-timepicker-cell"
|
|
965
|
+
style={{
|
|
966
|
+
padding: '3px 6px',
|
|
967
|
+
borderRadius: 4,
|
|
968
|
+
border: 'none',
|
|
969
|
+
textAlign: 'center',
|
|
970
|
+
fontSize: '.75rem',
|
|
971
|
+
cursor: 'pointer',
|
|
972
|
+
fontWeight: isSelected ? 700 : 400,
|
|
973
|
+
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
974
|
+
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
975
|
+
}}
|
|
976
|
+
>
|
|
977
|
+
{pad(hNum)}
|
|
978
|
+
</button>
|
|
979
|
+
);
|
|
980
|
+
})}
|
|
981
|
+
</div>
|
|
982
|
+
</div>
|
|
983
|
+
|
|
984
|
+
{/* Minutes Column: FULL LIST 00 to 59! */}
|
|
985
|
+
<div>
|
|
986
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>Мин (00-59)</div>
|
|
987
|
+
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2, paddingRight: 2 }}>
|
|
988
|
+
{fullMinutesList.map(mNum => {
|
|
989
|
+
const mStr = pad(mNum);
|
|
990
|
+
const isSelected = parsed.m === mStr;
|
|
991
|
+
return (
|
|
992
|
+
<button
|
|
993
|
+
key={mNum}
|
|
994
|
+
type="button"
|
|
995
|
+
onClick={() => selectMin(mNum)}
|
|
996
|
+
className="cynx-timepicker-cell"
|
|
997
|
+
style={{
|
|
998
|
+
padding: '3px 6px',
|
|
999
|
+
borderRadius: 4,
|
|
1000
|
+
border: 'none',
|
|
1001
|
+
textAlign: 'center',
|
|
1002
|
+
fontSize: '.75rem',
|
|
1003
|
+
cursor: 'pointer',
|
|
1004
|
+
fontWeight: isSelected ? 700 : 400,
|
|
1005
|
+
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
1006
|
+
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
1007
|
+
}}
|
|
1008
|
+
>
|
|
1009
|
+
{mStr}
|
|
1010
|
+
</button>
|
|
1011
|
+
);
|
|
1012
|
+
})}
|
|
1013
|
+
</div>
|
|
1014
|
+
</div>
|
|
1015
|
+
|
|
1016
|
+
{/* Seconds Column (if showSeconds): FULL LIST 00 to 59! */}
|
|
1017
|
+
{showSeconds && (
|
|
1018
|
+
<div>
|
|
1019
|
+
<div style={{ fontSize: '.65rem', fontWeight: 600, color: 'var(--muted, var(--t2))', marginBottom: 4, textAlign: 'center' }}>Сек (00-59)</div>
|
|
1020
|
+
<div style={{ maxHeight: 150, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
1021
|
+
{fullMinutesList.map(sNum => {
|
|
1022
|
+
const sStr = pad(sNum);
|
|
1023
|
+
const isSelected = parsed.s === sStr;
|
|
1024
|
+
return (
|
|
1025
|
+
<button
|
|
1026
|
+
key={sNum}
|
|
1027
|
+
type="button"
|
|
1028
|
+
onClick={() => selectSec(sNum)}
|
|
1029
|
+
className="cynx-timepicker-cell"
|
|
1030
|
+
style={{
|
|
1031
|
+
padding: '3px 6px',
|
|
1032
|
+
borderRadius: 4,
|
|
1033
|
+
border: 'none',
|
|
1034
|
+
textAlign: 'center',
|
|
1035
|
+
fontSize: '.75rem',
|
|
1036
|
+
cursor: 'pointer',
|
|
1037
|
+
fontWeight: isSelected ? 700 : 400,
|
|
1038
|
+
background: isSelected ? 'var(--accent, var(--blue))' : 'transparent',
|
|
1039
|
+
color: isSelected ? '#ffffff' : 'var(--fg, var(--t1))',
|
|
1040
|
+
}}
|
|
1041
|
+
>
|
|
1042
|
+
{sStr}
|
|
1043
|
+
</button>
|
|
1044
|
+
);
|
|
1045
|
+
})}
|
|
1046
|
+
</div>
|
|
1047
|
+
</div>
|
|
1048
|
+
)}
|
|
1049
|
+
</div>
|
|
1050
|
+
)}
|
|
1051
|
+
|
|
1052
|
+
{/* Footer Actions */}
|
|
1053
|
+
<div style={{ marginTop: 8, paddingTop: 6, borderTop: '1px solid var(--border-light, var(--border))', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
1054
|
+
<button
|
|
1055
|
+
type="button"
|
|
1056
|
+
onClick={clearTime}
|
|
1057
|
+
className="cynx-timepicker-cell"
|
|
1058
|
+
style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--danger)', fontSize: '.7rem', fontWeight: 500 }}
|
|
1059
|
+
>
|
|
1060
|
+
Сбросить
|
|
1061
|
+
</button>
|
|
1062
|
+
<button
|
|
1063
|
+
type="button"
|
|
1064
|
+
onClick={closePicker}
|
|
1065
|
+
className="cynx-timepicker-cell"
|
|
1066
|
+
style={{ padding: '3px 10px', borderRadius: 4, border: 'none', background: 'var(--accent, var(--blue))', color: '#ffffff', fontSize: '.7rem', cursor: 'pointer', fontWeight: 600, display: 'flex', alignItems: 'center', gap: 4 }}
|
|
1067
|
+
>
|
|
1068
|
+
<Check size={12} /> Готово
|
|
1069
|
+
</button>
|
|
1070
|
+
</div>
|
|
1071
|
+
</div>,
|
|
1072
|
+
document.body
|
|
1073
|
+
)}
|
|
1074
|
+
</div>
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
export default TimePicker;
|