@xsolla/xui-input-time 0.130.0-pr223.1776156979

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.
@@ -0,0 +1,936 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ InputTime: () => InputTime
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/InputTime.tsx
38
+ var import_react3 = __toESM(require("react"));
39
+
40
+ // ../primitives-native/src/Box.tsx
41
+ var import_react_native = require("react-native");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var Box = ({
44
+ children,
45
+ onPress,
46
+ onLayout,
47
+ onMoveShouldSetResponder,
48
+ onResponderGrant,
49
+ onResponderMove,
50
+ onResponderRelease,
51
+ onResponderTerminate,
52
+ backgroundColor,
53
+ borderColor,
54
+ borderWidth,
55
+ borderBottomWidth,
56
+ borderBottomColor,
57
+ borderTopWidth,
58
+ borderTopColor,
59
+ borderLeftWidth,
60
+ borderLeftColor,
61
+ borderRightWidth,
62
+ borderRightColor,
63
+ borderRadius,
64
+ borderStyle,
65
+ height,
66
+ padding,
67
+ paddingHorizontal,
68
+ paddingVertical,
69
+ margin,
70
+ marginTop,
71
+ marginBottom,
72
+ marginLeft,
73
+ marginRight,
74
+ flexDirection,
75
+ alignItems,
76
+ justifyContent,
77
+ position,
78
+ top,
79
+ bottom,
80
+ left,
81
+ right,
82
+ width,
83
+ minWidth,
84
+ minHeight,
85
+ maxWidth,
86
+ maxHeight,
87
+ flex,
88
+ overflow,
89
+ zIndex,
90
+ hoverStyle,
91
+ pressStyle,
92
+ style,
93
+ "data-testid": dataTestId,
94
+ testID,
95
+ as,
96
+ src,
97
+ alt,
98
+ ...rest
99
+ }) => {
100
+ const getContainerStyle = (pressed) => ({
101
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
102
+ borderColor,
103
+ borderWidth,
104
+ borderBottomWidth,
105
+ borderBottomColor,
106
+ borderTopWidth,
107
+ borderTopColor,
108
+ borderLeftWidth,
109
+ borderLeftColor,
110
+ borderRightWidth,
111
+ borderRightColor,
112
+ borderRadius,
113
+ borderStyle,
114
+ overflow,
115
+ zIndex,
116
+ height,
117
+ width,
118
+ minWidth,
119
+ minHeight,
120
+ maxWidth,
121
+ maxHeight,
122
+ padding,
123
+ paddingHorizontal,
124
+ paddingVertical,
125
+ margin,
126
+ marginTop,
127
+ marginBottom,
128
+ marginLeft,
129
+ marginRight,
130
+ flexDirection,
131
+ alignItems,
132
+ justifyContent,
133
+ position,
134
+ top,
135
+ bottom,
136
+ left,
137
+ right,
138
+ flex,
139
+ ...style
140
+ });
141
+ const finalTestID = dataTestId || testID;
142
+ const {
143
+ role,
144
+ tabIndex,
145
+ onKeyDown,
146
+ onKeyUp,
147
+ "aria-label": _ariaLabel,
148
+ "aria-labelledby": _ariaLabelledBy,
149
+ "aria-current": _ariaCurrent,
150
+ "aria-disabled": _ariaDisabled,
151
+ "aria-live": _ariaLive,
152
+ className,
153
+ "data-testid": _dataTestId,
154
+ ...nativeRest
155
+ } = rest;
156
+ if (as === "img" && src) {
157
+ const imageStyle = {
158
+ width,
159
+ height,
160
+ borderRadius,
161
+ position,
162
+ top,
163
+ bottom,
164
+ left,
165
+ right,
166
+ ...style
167
+ };
168
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
+ import_react_native.Image,
170
+ {
171
+ source: { uri: src },
172
+ style: imageStyle,
173
+ testID: finalTestID,
174
+ resizeMode: "cover",
175
+ ...nativeRest
176
+ }
177
+ );
178
+ }
179
+ if (onPress) {
180
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
181
+ import_react_native.Pressable,
182
+ {
183
+ onPress,
184
+ onLayout,
185
+ onMoveShouldSetResponder,
186
+ onResponderGrant,
187
+ onResponderMove,
188
+ onResponderRelease,
189
+ onResponderTerminate,
190
+ style: ({ pressed }) => getContainerStyle(pressed),
191
+ testID: finalTestID,
192
+ ...nativeRest,
193
+ children
194
+ }
195
+ );
196
+ }
197
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
198
+ import_react_native.View,
199
+ {
200
+ style: getContainerStyle(),
201
+ testID: finalTestID,
202
+ onLayout,
203
+ onMoveShouldSetResponder,
204
+ onResponderGrant,
205
+ onResponderMove,
206
+ onResponderRelease,
207
+ onResponderTerminate,
208
+ ...nativeRest,
209
+ children
210
+ }
211
+ );
212
+ };
213
+
214
+ // ../primitives-native/src/Text.tsx
215
+ var import_react_native2 = require("react-native");
216
+ var import_jsx_runtime2 = require("react/jsx-runtime");
217
+ var roleMap = {
218
+ alert: "alert",
219
+ heading: "header",
220
+ button: "button",
221
+ link: "link",
222
+ text: "text"
223
+ };
224
+ var parseNumericValue = (value) => {
225
+ if (value === void 0) return void 0;
226
+ if (typeof value === "number") return value;
227
+ const parsed = parseFloat(value);
228
+ return isNaN(parsed) ? void 0 : parsed;
229
+ };
230
+ var Text = ({
231
+ children,
232
+ color,
233
+ fontSize,
234
+ fontWeight,
235
+ fontFamily,
236
+ textAlign,
237
+ lineHeight,
238
+ numberOfLines,
239
+ id,
240
+ role,
241
+ style: styleProp,
242
+ ...props
243
+ }) => {
244
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
245
+ if (resolvedFontFamily === "Pilat Wide" || resolvedFontFamily === "Pilat Wide Bold" || resolvedFontFamily === "Aktiv Grotesk") {
246
+ resolvedFontFamily = void 0;
247
+ }
248
+ const incomingStyle = import_react_native2.StyleSheet.flatten(styleProp);
249
+ const baseStyle = {
250
+ color: color ?? incomingStyle?.color,
251
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
252
+ fontWeight,
253
+ fontFamily: resolvedFontFamily,
254
+ textDecorationLine: props.textDecoration,
255
+ textAlign: textAlign ?? incomingStyle?.textAlign,
256
+ lineHeight: parseNumericValue(lineHeight ?? incomingStyle?.lineHeight),
257
+ marginTop: parseNumericValue(
258
+ incomingStyle?.marginTop
259
+ ),
260
+ marginBottom: parseNumericValue(
261
+ incomingStyle?.marginBottom
262
+ )
263
+ };
264
+ const accessibilityRole = role ? roleMap[role] : void 0;
265
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
266
+ import_react_native2.Text,
267
+ {
268
+ style: baseStyle,
269
+ numberOfLines,
270
+ testID: id,
271
+ accessibilityRole,
272
+ children
273
+ }
274
+ );
275
+ };
276
+
277
+ // ../primitives-native/src/Input.tsx
278
+ var import_react = require("react");
279
+ var import_react_native3 = require("react-native");
280
+ var import_jsx_runtime3 = require("react/jsx-runtime");
281
+ var keyboardTypeMap = {
282
+ text: "default",
283
+ number: "numeric",
284
+ email: "email-address",
285
+ tel: "phone-pad",
286
+ url: "url",
287
+ decimal: "decimal-pad"
288
+ };
289
+ var inputModeToKeyboardType = {
290
+ none: "default",
291
+ text: "default",
292
+ decimal: "decimal-pad",
293
+ numeric: "number-pad",
294
+ tel: "phone-pad",
295
+ search: "default",
296
+ email: "email-address",
297
+ url: "url"
298
+ };
299
+ var autoCompleteToTextContentType = {
300
+ "one-time-code": "oneTimeCode",
301
+ email: "emailAddress",
302
+ username: "username",
303
+ password: "password",
304
+ "new-password": "newPassword",
305
+ tel: "telephoneNumber",
306
+ "postal-code": "postalCode",
307
+ name: "name"
308
+ };
309
+ var InputPrimitive = (0, import_react.forwardRef)(
310
+ ({
311
+ value,
312
+ placeholder,
313
+ onChange,
314
+ onChangeText,
315
+ onFocus,
316
+ onBlur,
317
+ onKeyDown,
318
+ disabled,
319
+ secureTextEntry,
320
+ style,
321
+ color,
322
+ fontSize,
323
+ placeholderTextColor,
324
+ maxLength,
325
+ type,
326
+ inputMode,
327
+ autoComplete,
328
+ id,
329
+ "aria-describedby": ariaDescribedBy,
330
+ "aria-label": ariaLabel,
331
+ "aria-disabled": ariaDisabled,
332
+ "data-testid": dataTestId
333
+ }, ref) => {
334
+ const handleChangeText = (text) => {
335
+ onChangeText?.(text);
336
+ if (onChange) {
337
+ const syntheticEvent = {
338
+ target: { value: text },
339
+ currentTarget: { value: text },
340
+ type: "change",
341
+ nativeEvent: { text },
342
+ preventDefault: () => {
343
+ },
344
+ stopPropagation: () => {
345
+ },
346
+ isTrusted: false
347
+ };
348
+ onChange(syntheticEvent);
349
+ }
350
+ };
351
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
352
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
353
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
354
+ import_react_native3.TextInput,
355
+ {
356
+ ref,
357
+ value,
358
+ placeholder,
359
+ onChangeText: handleChangeText,
360
+ onFocus,
361
+ onBlur,
362
+ onKeyPress: (e) => {
363
+ if (onKeyDown) {
364
+ onKeyDown({
365
+ key: e.nativeEvent.key,
366
+ preventDefault: () => {
367
+ }
368
+ });
369
+ }
370
+ },
371
+ editable: !disabled,
372
+ secureTextEntry: secureTextEntry || type === "password",
373
+ keyboardType,
374
+ textContentType,
375
+ style: [
376
+ {
377
+ color,
378
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
379
+ flex: 1,
380
+ padding: 0,
381
+ textAlign: style?.textAlign || "left"
382
+ },
383
+ style
384
+ ],
385
+ placeholderTextColor,
386
+ maxLength,
387
+ testID: dataTestId || id,
388
+ accessibilityLabel: ariaLabel,
389
+ accessibilityHint: ariaDescribedBy,
390
+ accessibilityState: {
391
+ disabled: disabled || ariaDisabled
392
+ },
393
+ accessible: true
394
+ }
395
+ );
396
+ }
397
+ );
398
+ InputPrimitive.displayName = "InputPrimitive";
399
+
400
+ // src/InputTime.tsx
401
+ var import_xui_core = require("@xsolla/xui-core");
402
+ var import_xui_icons_base = require("@xsolla/xui-icons-base");
403
+
404
+ // src/TimeSegment.tsx
405
+ var import_react2 = require("react");
406
+
407
+ // src/utils.ts
408
+ function clampValue(value, min, max) {
409
+ if (isNaN(value)) return min;
410
+ return Math.min(max, Math.max(min, value));
411
+ }
412
+ function clampHours(value, is12h) {
413
+ return is12h ? clampValue(value, 1, 12) : clampValue(value, 0, 23);
414
+ }
415
+ function clampMinutes(value) {
416
+ return clampValue(value, 0, 59);
417
+ }
418
+ function clampSeconds(value) {
419
+ return clampValue(value, 0, 59);
420
+ }
421
+ function formatSegment(value) {
422
+ if (value === void 0 || value === null) return "";
423
+ return value.toString().padStart(2, "0");
424
+ }
425
+ function parseSegmentInput(text) {
426
+ const num = parseInt(text, 10);
427
+ return isNaN(num) ? null : num;
428
+ }
429
+
430
+ // src/TimeSegment.tsx
431
+ var import_jsx_runtime4 = require("react/jsx-runtime");
432
+ var TimeSegment = (0, import_react2.forwardRef)(
433
+ ({
434
+ value,
435
+ onChange,
436
+ onAdvance,
437
+ onRetreat,
438
+ min,
439
+ max,
440
+ disabled = false,
441
+ placeholder = "--",
442
+ fontSize,
443
+ textColor,
444
+ placeholderColor,
445
+ focusColor,
446
+ "aria-label": ariaLabel,
447
+ testID
448
+ }, ref) => {
449
+ const inputRef = (0, import_react2.useRef)(null);
450
+ const [editBuffer, setEditBuffer] = (0, import_react2.useState)("");
451
+ const [isFocused, setIsFocused] = (0, import_react2.useState)(false);
452
+ const committedRef = (0, import_react2.useRef)(false);
453
+ const freshFocusRef = (0, import_react2.useRef)(false);
454
+ (0, import_react2.useImperativeHandle)(ref, () => ({
455
+ focus: () => inputRef.current?.focus?.()
456
+ }));
457
+ const displayValue = isFocused ? editBuffer : value !== null ? formatSegment(value) : "";
458
+ const commitValue = (0, import_react2.useCallback)(
459
+ (text) => {
460
+ const parsed = parseSegmentInput(text);
461
+ if (parsed !== null) {
462
+ const clamped = Math.min(max, Math.max(min, parsed));
463
+ onChange(clamped);
464
+ }
465
+ },
466
+ [onChange, min, max]
467
+ );
468
+ const handleFocus = () => {
469
+ setIsFocused(true);
470
+ setEditBuffer(value !== null ? formatSegment(value) : "");
471
+ committedRef.current = false;
472
+ freshFocusRef.current = true;
473
+ };
474
+ const handleBlur = () => {
475
+ setIsFocused(false);
476
+ if (!committedRef.current && editBuffer) {
477
+ commitValue(editBuffer);
478
+ }
479
+ committedRef.current = false;
480
+ setEditBuffer("");
481
+ };
482
+ const extractTypedDigit = (newText, oldText) => {
483
+ const newDigits = newText.replace(/\D/g, "");
484
+ const oldDigits = oldText.replace(/\D/g, "");
485
+ if (newDigits.length <= oldDigits.length) return "";
486
+ let remaining = newDigits;
487
+ for (const ch of oldDigits) {
488
+ const idx = remaining.indexOf(ch);
489
+ if (idx !== -1) {
490
+ remaining = remaining.slice(0, idx) + remaining.slice(idx + 1);
491
+ }
492
+ }
493
+ return remaining.charAt(0);
494
+ };
495
+ const handleChangeText = (text) => {
496
+ let digitsOnly = text.replace(/\D/g, "");
497
+ if (freshFocusRef.current || committedRef.current) {
498
+ const typed = extractTypedDigit(text, displayValue);
499
+ freshFocusRef.current = false;
500
+ committedRef.current = false;
501
+ if (!typed) return;
502
+ digitsOnly = typed;
503
+ } else {
504
+ digitsOnly = digitsOnly.slice(-2);
505
+ }
506
+ setEditBuffer(digitsOnly);
507
+ if (digitsOnly.length === 2) {
508
+ committedRef.current = true;
509
+ commitValue(digitsOnly);
510
+ onAdvance();
511
+ }
512
+ };
513
+ const handleKeyDown = (e) => {
514
+ const key = e.key || e.nativeEvent?.key;
515
+ if (key === "ArrowUp") {
516
+ e.preventDefault();
517
+ const current = value ?? min;
518
+ const next = current >= max ? min : current + 1;
519
+ onChange(next);
520
+ setEditBuffer(formatSegment(next));
521
+ committedRef.current = true;
522
+ } else if (key === "ArrowDown") {
523
+ e.preventDefault();
524
+ const current = value ?? min;
525
+ const next = current <= min ? max : current - 1;
526
+ onChange(next);
527
+ setEditBuffer(formatSegment(next));
528
+ committedRef.current = true;
529
+ } else if (key === "ArrowRight") {
530
+ onAdvance();
531
+ } else if (key === "ArrowLeft") {
532
+ onRetreat();
533
+ } else if (key === "Backspace" && editBuffer.length === 0) {
534
+ onChange(null);
535
+ onRetreat();
536
+ } else if (key === "Tab") {
537
+ if (editBuffer) {
538
+ commitValue(editBuffer);
539
+ }
540
+ } else if (key === "Enter") {
541
+ if (editBuffer) {
542
+ commitValue(editBuffer);
543
+ }
544
+ inputRef.current?.blur?.();
545
+ }
546
+ };
547
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
548
+ Box,
549
+ {
550
+ onPress: () => inputRef.current?.focus?.(),
551
+ width: fontSize * 1.5,
552
+ height: fontSize + 8,
553
+ justifyContent: "center",
554
+ alignItems: "center",
555
+ backgroundColor: isFocused ? focusColor : "transparent",
556
+ borderRadius: 4,
557
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
558
+ InputPrimitive,
559
+ {
560
+ ref: inputRef,
561
+ value: displayValue,
562
+ placeholder,
563
+ onChangeText: handleChangeText,
564
+ onFocus: handleFocus,
565
+ onBlur: handleBlur,
566
+ onKeyDown: handleKeyDown,
567
+ disabled,
568
+ inputMode: "numeric",
569
+ color: textColor,
570
+ fontSize,
571
+ placeholderTextColor: placeholderColor,
572
+ "aria-label": ariaLabel,
573
+ "data-testid": testID,
574
+ style: {
575
+ textAlign: "center",
576
+ width: "100%",
577
+ padding: 0,
578
+ border: "none",
579
+ outline: "none",
580
+ boxShadow: "none",
581
+ background: "transparent",
582
+ caretColor: "transparent"
583
+ }
584
+ }
585
+ )
586
+ }
587
+ );
588
+ }
589
+ );
590
+ TimeSegment.displayName = "TimeSegment";
591
+
592
+ // src/PeriodToggle.tsx
593
+ var import_jsx_runtime5 = require("react/jsx-runtime");
594
+ var PeriodToggle = ({
595
+ value,
596
+ onChange,
597
+ disabled = false,
598
+ fontSize,
599
+ textColor,
600
+ testID
601
+ }) => {
602
+ const toggle = () => {
603
+ if (!disabled) {
604
+ onChange(value === "am" ? "pm" : "am");
605
+ }
606
+ };
607
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
608
+ Box,
609
+ {
610
+ onPress: toggle,
611
+ cursor: disabled ? "default" : "pointer",
612
+ justifyContent: "center",
613
+ alignItems: "center",
614
+ paddingHorizontal: 4,
615
+ role: "button",
616
+ "aria-label": `Time period: ${value.toUpperCase()}. Click to toggle.`,
617
+ "data-testid": testID,
618
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: textColor, fontSize, fontWeight: "500", children: value })
619
+ }
620
+ );
621
+ };
622
+
623
+ // src/InputTime.tsx
624
+ var import_jsx_runtime6 = require("react/jsx-runtime");
625
+ var InputTime = ({
626
+ value,
627
+ onChange,
628
+ showSeconds = false,
629
+ showPeriod = false,
630
+ hourCycle = 24,
631
+ icon = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_xui_icons_base.Clock, {}),
632
+ size = "md",
633
+ disabled = false,
634
+ error,
635
+ "aria-label": ariaLabel,
636
+ testID
637
+ }) => {
638
+ const { theme } = (0, import_xui_core.useDesignSystem)();
639
+ const rawId = (0, import_xui_core.useId)();
640
+ const safeId = rawId.replace(/:/g, "");
641
+ const inputId = `input-time-${safeId}`;
642
+ const errorId = `${inputId}-error`;
643
+ const [internalState, setInternalState] = (0, import_react3.useState)(
644
+ "default"
645
+ );
646
+ const segmentRefs = (0, import_react3.useRef)([]);
647
+ const is12h = hourCycle === 12;
648
+ const [hours, setHours] = (0, import_react3.useState)(value?.hours ?? null);
649
+ const [minutes, setMinutes] = (0, import_react3.useState)(value?.minutes ?? null);
650
+ const [seconds, setSeconds] = (0, import_react3.useState)(value?.seconds ?? null);
651
+ const [period, setPeriod] = (0, import_react3.useState)(value?.period ?? "am");
652
+ (0, import_react3.useEffect)(() => {
653
+ if (value) {
654
+ setHours(value.hours);
655
+ setMinutes(value.minutes);
656
+ setSeconds(value.seconds ?? null);
657
+ setPeriod(value.period ?? "am");
658
+ } else if (value === null) {
659
+ setHours(null);
660
+ setMinutes(null);
661
+ setSeconds(null);
662
+ setPeriod("am");
663
+ }
664
+ }, [value]);
665
+ const emitChange = (0, import_react3.useCallback)(
666
+ (h, m, s, p) => {
667
+ if (h === null || m === null) {
668
+ onChange?.(null);
669
+ return;
670
+ }
671
+ const result = {
672
+ hours: clampHours(h, is12h),
673
+ minutes: clampMinutes(m)
674
+ };
675
+ if (showSeconds) {
676
+ result.seconds = s !== null ? clampSeconds(s) : 0;
677
+ }
678
+ if (showPeriod) {
679
+ result.period = p;
680
+ }
681
+ onChange?.(result);
682
+ },
683
+ [onChange, is12h, showSeconds, showPeriod]
684
+ );
685
+ const handleHoursChange = (v) => {
686
+ const clamped = v !== null ? clampHours(v, is12h) : null;
687
+ setHours(clamped);
688
+ emitChange(clamped, minutes, seconds, period);
689
+ };
690
+ const handleMinutesChange = (v) => {
691
+ const clamped = v !== null ? clampMinutes(v) : null;
692
+ setMinutes(clamped);
693
+ emitChange(hours, clamped, seconds, period);
694
+ };
695
+ const handleSecondsChange = (v) => {
696
+ const clamped = v !== null ? clampSeconds(v) : null;
697
+ setSeconds(clamped);
698
+ emitChange(hours, minutes, clamped, period);
699
+ };
700
+ const handlePeriodChange = (v) => {
701
+ setPeriod(v);
702
+ emitChange(hours, minutes, seconds, v);
703
+ };
704
+ const focusSegment = (index) => {
705
+ segmentRefs.current[index]?.focus?.();
706
+ };
707
+ const segmentCount = showSeconds ? 3 : 2;
708
+ const advanceFrom = (i) => () => {
709
+ if (i < segmentCount - 1) focusSegment(i + 1);
710
+ };
711
+ const retreatFrom = (i) => () => {
712
+ if (i > 0) focusSegment(i - 1);
713
+ };
714
+ const sizeStyles = theme.sizing.input(size);
715
+ const inputColors = theme.colors.control.input;
716
+ const isError = !!error;
717
+ const isFocus = internalState === "focus";
718
+ let backgroundColor = inputColors.bg;
719
+ let borderColor = inputColors.border;
720
+ let outlineColor;
721
+ if (disabled) {
722
+ backgroundColor = inputColors.bgDisable;
723
+ borderColor = inputColors.borderDisable;
724
+ } else if (isError) {
725
+ outlineColor = theme.colors.border.alert;
726
+ if (isFocus) {
727
+ backgroundColor = theme.colors.control.focus.bg;
728
+ }
729
+ } else if (isFocus) {
730
+ backgroundColor = theme.colors.control.focus.bg;
731
+ outlineColor = theme.colors.border.brand;
732
+ }
733
+ const textColor = disabled ? inputColors.textDisable : inputColors.text;
734
+ const placeholderColor = inputColors.placeholder;
735
+ const iconColor = inputColors.placeholder;
736
+ const paddingConfig = {
737
+ xl: { vertical: 12, horizontal: 12 },
738
+ lg: { vertical: 14, horizontal: 12 },
739
+ md: { vertical: 11, horizontal: 12 },
740
+ sm: { vertical: 7, horizontal: 10 },
741
+ xs: { vertical: 7, horizontal: 10 }
742
+ };
743
+ const borderRadiusConfig = {
744
+ xl: 8,
745
+ lg: 8,
746
+ md: 8,
747
+ sm: 4,
748
+ xs: 4
749
+ };
750
+ const iconSizeConfig = {
751
+ xl: 22,
752
+ lg: 20,
753
+ md: 18,
754
+ sm: 16,
755
+ xs: 14
756
+ };
757
+ const focusOutlineConfig = {
758
+ xl: { width: 1, offset: -1 },
759
+ lg: { width: 1, offset: -1 },
760
+ md: { width: 1, offset: -1 },
761
+ sm: { width: 1, offset: -1 },
762
+ xs: { width: 1, offset: -1 }
763
+ };
764
+ const padding = paddingConfig[size];
765
+ const borderRadius = borderRadiusConfig[size];
766
+ const iconSize = iconSizeConfig[size];
767
+ const focusOutline = focusOutlineConfig[size];
768
+ const handleContainerFocus = () => {
769
+ if (!disabled) setInternalState("focus");
770
+ };
771
+ const handleContainerBlur = () => {
772
+ if (!disabled) setInternalState("default");
773
+ };
774
+ const colonColor = disabled ? placeholderColor : textColor;
775
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
776
+ Box,
777
+ {
778
+ flexDirection: "column",
779
+ gap: sizeStyles.fieldGap,
780
+ width: "100%",
781
+ testID,
782
+ children: [
783
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
784
+ Box,
785
+ {
786
+ backgroundColor,
787
+ borderColor,
788
+ borderWidth: borderColor !== "transparent" ? 1 : 0,
789
+ borderRadius,
790
+ height: sizeStyles.height,
791
+ paddingVertical: padding.vertical,
792
+ paddingHorizontal: padding.horizontal,
793
+ flexDirection: "row",
794
+ alignItems: "center",
795
+ gap: 2,
796
+ position: "relative",
797
+ style: {
798
+ ...outlineColor ? {
799
+ outline: `${focusOutline.width}px solid ${outlineColor}`,
800
+ outlineOffset: `${focusOutline.offset}px`
801
+ } : {}
802
+ },
803
+ hoverStyle: !disabled && !isFocus && !isError ? {
804
+ backgroundColor: inputColors.bgHover,
805
+ borderColor: inputColors.borderHover
806
+ } : void 0,
807
+ onFocus: handleContainerFocus,
808
+ onBlur: handleContainerBlur,
809
+ role: "group",
810
+ "aria-label": ariaLabel || "Time input",
811
+ "aria-describedby": error ? errorId : void 0,
812
+ children: [
813
+ icon && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box, { marginRight: 6, alignItems: "center", justifyContent: "center", children: import_react3.default.isValidElement(icon) ? import_react3.default.cloneElement(icon, {
814
+ size: iconSize,
815
+ color: iconColor
816
+ }) : icon }),
817
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
818
+ TimeSegment,
819
+ {
820
+ ref: (el) => {
821
+ segmentRefs.current[0] = el;
822
+ },
823
+ value: hours,
824
+ onChange: handleHoursChange,
825
+ onAdvance: advanceFrom(0),
826
+ onRetreat: retreatFrom(0),
827
+ min: is12h ? 1 : 0,
828
+ max: is12h ? 12 : 23,
829
+ disabled,
830
+ placeholder: "--",
831
+ fontSize: sizeStyles.fontSize,
832
+ textColor,
833
+ placeholderColor,
834
+ focusColor: theme.colors.background.brand.primary,
835
+ "aria-label": "Hours",
836
+ testID: testID ? `${testID}-hours` : void 0
837
+ }
838
+ ),
839
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
840
+ Text,
841
+ {
842
+ color: colonColor,
843
+ fontSize: sizeStyles.fontSize,
844
+ fontWeight: "500",
845
+ children: ":"
846
+ }
847
+ ),
848
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
849
+ TimeSegment,
850
+ {
851
+ ref: (el) => {
852
+ segmentRefs.current[1] = el;
853
+ },
854
+ value: minutes,
855
+ onChange: handleMinutesChange,
856
+ onAdvance: advanceFrom(1),
857
+ onRetreat: retreatFrom(1),
858
+ min: 0,
859
+ max: 59,
860
+ disabled,
861
+ placeholder: "--",
862
+ fontSize: sizeStyles.fontSize,
863
+ textColor,
864
+ placeholderColor,
865
+ focusColor: theme.colors.background.brand.primary,
866
+ "aria-label": "Minutes",
867
+ testID: testID ? `${testID}-minutes` : void 0
868
+ }
869
+ ),
870
+ showSeconds && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
871
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
872
+ Text,
873
+ {
874
+ color: colonColor,
875
+ fontSize: sizeStyles.fontSize,
876
+ fontWeight: "500",
877
+ children: ":"
878
+ }
879
+ ),
880
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
881
+ TimeSegment,
882
+ {
883
+ ref: (el) => {
884
+ segmentRefs.current[2] = el;
885
+ },
886
+ value: seconds,
887
+ onChange: handleSecondsChange,
888
+ onAdvance: advanceFrom(2),
889
+ onRetreat: retreatFrom(2),
890
+ min: 0,
891
+ max: 59,
892
+ disabled,
893
+ placeholder: "--",
894
+ fontSize: sizeStyles.fontSize,
895
+ textColor,
896
+ placeholderColor,
897
+ focusColor: theme.colors.background.brand.primary,
898
+ "aria-label": "Seconds",
899
+ testID: testID ? `${testID}-seconds` : void 0
900
+ }
901
+ )
902
+ ] }),
903
+ showPeriod && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
904
+ PeriodToggle,
905
+ {
906
+ value: period,
907
+ onChange: handlePeriodChange,
908
+ disabled,
909
+ fontSize: sizeStyles.fontSize,
910
+ textColor,
911
+ testID: testID ? `${testID}-period` : void 0
912
+ }
913
+ )
914
+ ]
915
+ }
916
+ ),
917
+ error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
918
+ Text,
919
+ {
920
+ id: errorId,
921
+ role: "alert",
922
+ color: theme.colors.content.alert.primary,
923
+ fontSize: sizeStyles.fontSize - 2,
924
+ children: error
925
+ }
926
+ )
927
+ ]
928
+ }
929
+ );
930
+ };
931
+ InputTime.displayName = "InputTime";
932
+ // Annotate the CommonJS export names for ESM import in node:
933
+ 0 && (module.exports = {
934
+ InputTime
935
+ });
936
+ //# sourceMappingURL=index.js.map