@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.
package/web/index.mjs ADDED
@@ -0,0 +1,856 @@
1
+ // src/InputTime.tsx
2
+ import React4, { useRef as useRef2, useState as useState2, useEffect, useCallback as useCallback2 } from "react";
3
+
4
+ // ../primitives-web/src/Box.tsx
5
+ import React from "react";
6
+ import styled from "styled-components";
7
+ import { jsx } from "react/jsx-runtime";
8
+ var StyledBox = styled.div`
9
+ display: flex;
10
+ box-sizing: border-box;
11
+ background-color: ${(props) => props.backgroundColor || "transparent"};
12
+ border-color: ${(props) => props.borderColor || "transparent"};
13
+ border-width: ${(props) => typeof props.borderWidth === "number" ? `${props.borderWidth}px` : props.borderWidth || 0};
14
+
15
+ ${(props) => props.borderBottomWidth !== void 0 && `
16
+ border-bottom-width: ${typeof props.borderBottomWidth === "number" ? `${props.borderBottomWidth}px` : props.borderBottomWidth};
17
+ border-bottom-color: ${props.borderBottomColor || props.borderColor || "transparent"};
18
+ border-bottom-style: solid;
19
+ `}
20
+ ${(props) => props.borderTopWidth !== void 0 && `
21
+ border-top-width: ${typeof props.borderTopWidth === "number" ? `${props.borderTopWidth}px` : props.borderTopWidth};
22
+ border-top-color: ${props.borderTopColor || props.borderColor || "transparent"};
23
+ border-top-style: solid;
24
+ `}
25
+ ${(props) => props.borderLeftWidth !== void 0 && `
26
+ border-left-width: ${typeof props.borderLeftWidth === "number" ? `${props.borderLeftWidth}px` : props.borderLeftWidth};
27
+ border-left-color: ${props.borderLeftColor || props.borderColor || "transparent"};
28
+ border-left-style: solid;
29
+ `}
30
+ ${(props) => props.borderRightWidth !== void 0 && `
31
+ border-right-width: ${typeof props.borderRightWidth === "number" ? `${props.borderRightWidth}px` : props.borderRightWidth};
32
+ border-right-color: ${props.borderRightColor || props.borderColor || "transparent"};
33
+ border-right-style: solid;
34
+ `}
35
+
36
+ border-style: ${(props) => props.borderStyle || (props.borderWidth || props.borderBottomWidth || props.borderTopWidth || props.borderLeftWidth || props.borderRightWidth ? "solid" : "none")};
37
+ border-radius: ${(props) => typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius || 0};
38
+ height: ${(props) => typeof props.height === "number" ? `${props.height}px` : props.height || "auto"};
39
+ width: ${(props) => typeof props.width === "number" ? `${props.width}px` : props.width || "auto"};
40
+ min-width: ${(props) => typeof props.minWidth === "number" ? `${props.minWidth}px` : props.minWidth || "auto"};
41
+ min-height: ${(props) => typeof props.minHeight === "number" ? `${props.minHeight}px` : props.minHeight || "auto"};
42
+ max-width: ${(props) => typeof props.maxWidth === "number" ? `${props.maxWidth}px` : props.maxWidth || "none"};
43
+ max-height: ${(props) => typeof props.maxHeight === "number" ? `${props.maxHeight}px` : props.maxHeight || "none"};
44
+
45
+ padding: ${(props) => typeof props.padding === "number" ? `${props.padding}px` : props.padding || 0};
46
+ ${(props) => props.paddingHorizontal && `
47
+ padding-left: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
48
+ padding-right: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
49
+ `}
50
+ ${(props) => props.paddingVertical && `
51
+ padding-top: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
52
+ padding-bottom: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
53
+ `}
54
+ ${(props) => props.paddingTop !== void 0 && `padding-top: ${typeof props.paddingTop === "number" ? `${props.paddingTop}px` : props.paddingTop};`}
55
+ ${(props) => props.paddingBottom !== void 0 && `padding-bottom: ${typeof props.paddingBottom === "number" ? `${props.paddingBottom}px` : props.paddingBottom};`}
56
+ ${(props) => props.paddingLeft !== void 0 && `padding-left: ${typeof props.paddingLeft === "number" ? `${props.paddingLeft}px` : props.paddingLeft};`}
57
+ ${(props) => props.paddingRight !== void 0 && `padding-right: ${typeof props.paddingRight === "number" ? `${props.paddingRight}px` : props.paddingRight};`}
58
+
59
+ margin: ${(props) => typeof props.margin === "number" ? `${props.margin}px` : props.margin || 0};
60
+ ${(props) => props.marginTop !== void 0 && `margin-top: ${typeof props.marginTop === "number" ? `${props.marginTop}px` : props.marginTop};`}
61
+ ${(props) => props.marginBottom !== void 0 && `margin-bottom: ${typeof props.marginBottom === "number" ? `${props.marginBottom}px` : props.marginBottom};`}
62
+ ${(props) => props.marginLeft !== void 0 && `margin-left: ${typeof props.marginLeft === "number" ? `${props.marginLeft}px` : props.marginLeft};`}
63
+ ${(props) => props.marginRight !== void 0 && `margin-right: ${typeof props.marginRight === "number" ? `${props.marginRight}px` : props.marginRight};`}
64
+
65
+ flex-direction: ${(props) => props.flexDirection || "column"};
66
+ flex-wrap: ${(props) => props.flexWrap || "nowrap"};
67
+ align-items: ${(props) => props.alignItems || "stretch"};
68
+ justify-content: ${(props) => props.justifyContent || "flex-start"};
69
+ cursor: ${(props) => props.cursor ? props.cursor : props.onClick || props.onPress ? "pointer" : "inherit"};
70
+ position: ${(props) => props.position || "static"};
71
+ top: ${(props) => typeof props.top === "number" ? `${props.top}px` : props.top};
72
+ bottom: ${(props) => typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom};
73
+ left: ${(props) => typeof props.left === "number" ? `${props.left}px` : props.left};
74
+ right: ${(props) => typeof props.right === "number" ? `${props.right}px` : props.right};
75
+ flex: ${(props) => props.flex};
76
+ flex-shrink: ${(props) => props.flexShrink ?? 1};
77
+ gap: ${(props) => typeof props.gap === "number" ? `${props.gap}px` : props.gap || 0};
78
+ align-self: ${(props) => props.alignSelf || "auto"};
79
+ overflow: ${(props) => props.overflow || "visible"};
80
+ overflow-x: ${(props) => props.overflowX || "visible"};
81
+ overflow-y: ${(props) => props.overflowY || "visible"};
82
+ z-index: ${(props) => props.zIndex};
83
+ opacity: ${(props) => props.disabled ? 0.5 : 1};
84
+ pointer-events: ${(props) => props.disabled ? "none" : "auto"};
85
+
86
+ &:hover {
87
+ ${(props) => props.hoverStyle?.backgroundColor && `background-color: ${props.hoverStyle.backgroundColor};`}
88
+ ${(props) => props.hoverStyle?.borderColor && `border-color: ${props.hoverStyle.borderColor};`}
89
+ }
90
+
91
+ &:active {
92
+ ${(props) => props.pressStyle?.backgroundColor && `background-color: ${props.pressStyle.backgroundColor};`}
93
+ }
94
+ `;
95
+ var Box = React.forwardRef(
96
+ ({
97
+ children,
98
+ onPress,
99
+ onKeyDown,
100
+ onKeyUp,
101
+ role,
102
+ "aria-label": ariaLabel,
103
+ "aria-labelledby": ariaLabelledBy,
104
+ "aria-current": ariaCurrent,
105
+ "aria-disabled": ariaDisabled,
106
+ "aria-live": ariaLive,
107
+ "aria-busy": ariaBusy,
108
+ "aria-describedby": ariaDescribedBy,
109
+ "aria-expanded": ariaExpanded,
110
+ "aria-haspopup": ariaHasPopup,
111
+ "aria-pressed": ariaPressed,
112
+ "aria-controls": ariaControls,
113
+ tabIndex,
114
+ as,
115
+ src,
116
+ alt,
117
+ type,
118
+ disabled,
119
+ id,
120
+ ...props
121
+ }, ref) => {
122
+ if (as === "img" && src) {
123
+ return /* @__PURE__ */ jsx(
124
+ "img",
125
+ {
126
+ src,
127
+ alt: alt || "",
128
+ style: {
129
+ display: "block",
130
+ objectFit: "cover",
131
+ width: typeof props.width === "number" ? `${props.width}px` : props.width,
132
+ height: typeof props.height === "number" ? `${props.height}px` : props.height,
133
+ borderRadius: typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius,
134
+ position: props.position,
135
+ top: typeof props.top === "number" ? `${props.top}px` : props.top,
136
+ left: typeof props.left === "number" ? `${props.left}px` : props.left,
137
+ right: typeof props.right === "number" ? `${props.right}px` : props.right,
138
+ bottom: typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom
139
+ }
140
+ }
141
+ );
142
+ }
143
+ return /* @__PURE__ */ jsx(
144
+ StyledBox,
145
+ {
146
+ ref,
147
+ as,
148
+ id,
149
+ type: as === "button" ? type || "button" : void 0,
150
+ disabled: as === "button" ? disabled : void 0,
151
+ onClick: onPress,
152
+ onKeyDown,
153
+ onKeyUp,
154
+ role,
155
+ "aria-label": ariaLabel,
156
+ "aria-labelledby": ariaLabelledBy,
157
+ "aria-current": ariaCurrent,
158
+ "aria-disabled": ariaDisabled,
159
+ "aria-busy": ariaBusy,
160
+ "aria-describedby": ariaDescribedBy,
161
+ "aria-expanded": ariaExpanded,
162
+ "aria-haspopup": ariaHasPopup,
163
+ "aria-pressed": ariaPressed,
164
+ "aria-controls": ariaControls,
165
+ "aria-live": ariaLive,
166
+ tabIndex: tabIndex !== void 0 ? tabIndex : void 0,
167
+ ...props,
168
+ children
169
+ }
170
+ );
171
+ }
172
+ );
173
+ Box.displayName = "Box";
174
+
175
+ // ../primitives-web/src/Text.tsx
176
+ import styled2 from "styled-components";
177
+ import { jsx as jsx2 } from "react/jsx-runtime";
178
+ var StyledText = styled2.span`
179
+ color: ${(props) => props.color || "inherit"};
180
+ font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
181
+ font-weight: ${(props) => props.fontWeight || "normal"};
182
+ font-family: ${(props) => props.fontFamily || '"Aktiv Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'};
183
+ line-height: ${(props) => typeof props.lineHeight === "number" ? `${props.lineHeight}px` : props.lineHeight || "inherit"};
184
+ white-space: ${(props) => props.whiteSpace || "normal"};
185
+ text-align: ${(props) => props.textAlign || "inherit"};
186
+ text-decoration: ${(props) => props.textDecoration || "none"};
187
+ `;
188
+ var Text = ({
189
+ style,
190
+ className,
191
+ id,
192
+ role,
193
+ numberOfLines: _numberOfLines,
194
+ ...props
195
+ }) => {
196
+ return /* @__PURE__ */ jsx2(
197
+ StyledText,
198
+ {
199
+ ...props,
200
+ style,
201
+ className,
202
+ id,
203
+ role
204
+ }
205
+ );
206
+ };
207
+
208
+ // ../primitives-web/src/Input.tsx
209
+ import { forwardRef } from "react";
210
+ import styled3 from "styled-components";
211
+ import { jsx as jsx3 } from "react/jsx-runtime";
212
+ var StyledInput = styled3.input`
213
+ background: transparent;
214
+ border: none;
215
+ outline: none;
216
+ width: 100%;
217
+ height: 100%;
218
+ padding: 0;
219
+ margin: 0;
220
+ color: ${(props) => props.color || "inherit"};
221
+ font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
222
+ font-family: inherit;
223
+ text-align: inherit;
224
+
225
+ &::placeholder {
226
+ color: ${(props) => props.placeholderTextColor || "rgba(255, 255, 255, 0.5)"};
227
+ }
228
+
229
+ &:disabled {
230
+ cursor: not-allowed;
231
+ }
232
+
233
+ /* Override browser autofill background */
234
+ &:-webkit-autofill,
235
+ &:-webkit-autofill:hover,
236
+ &:-webkit-autofill:focus,
237
+ &:-webkit-autofill:active {
238
+ -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
239
+ -webkit-background-clip: text !important;
240
+ -webkit-text-fill-color: ${(props) => props.color || "inherit"} !important;
241
+ }
242
+ `;
243
+ var InputPrimitive = forwardRef(
244
+ ({
245
+ value,
246
+ placeholder,
247
+ onChange,
248
+ onChangeText,
249
+ onFocus,
250
+ onBlur,
251
+ onKeyDown,
252
+ disabled,
253
+ secureTextEntry,
254
+ style,
255
+ color,
256
+ fontSize,
257
+ placeholderTextColor,
258
+ maxLength,
259
+ name,
260
+ type,
261
+ inputMode,
262
+ autoComplete,
263
+ id,
264
+ "aria-invalid": ariaInvalid,
265
+ "aria-describedby": ariaDescribedBy,
266
+ "aria-labelledby": ariaLabelledBy,
267
+ "aria-label": ariaLabel,
268
+ "aria-disabled": ariaDisabled,
269
+ "data-testid": dataTestId,
270
+ ...rest
271
+ }, ref) => {
272
+ const handleChange = (e) => {
273
+ if (onChange) {
274
+ onChange(e);
275
+ }
276
+ if (onChangeText) {
277
+ onChangeText(e.target.value);
278
+ }
279
+ };
280
+ const inputValue = value !== void 0 ? value : "";
281
+ return /* @__PURE__ */ jsx3(
282
+ StyledInput,
283
+ {
284
+ ref,
285
+ id,
286
+ value: inputValue,
287
+ name,
288
+ placeholder,
289
+ onChange: handleChange,
290
+ onFocus,
291
+ onBlur,
292
+ onKeyDown,
293
+ disabled,
294
+ type: secureTextEntry ? "password" : type || "text",
295
+ inputMode,
296
+ autoComplete,
297
+ style,
298
+ color,
299
+ fontSize,
300
+ placeholderTextColor,
301
+ maxLength,
302
+ "aria-invalid": ariaInvalid,
303
+ "aria-describedby": ariaDescribedBy,
304
+ "aria-labelledby": ariaLabelledBy,
305
+ "aria-label": ariaLabel,
306
+ "aria-disabled": ariaDisabled,
307
+ "data-testid": dataTestId,
308
+ ...rest
309
+ }
310
+ );
311
+ }
312
+ );
313
+ InputPrimitive.displayName = "InputPrimitive";
314
+
315
+ // src/InputTime.tsx
316
+ import { useDesignSystem, useId } from "@xsolla/xui-core";
317
+ import { Clock } from "@xsolla/xui-icons-base";
318
+
319
+ // src/TimeSegment.tsx
320
+ import {
321
+ useRef,
322
+ useState,
323
+ useCallback,
324
+ forwardRef as forwardRef2,
325
+ useImperativeHandle
326
+ } from "react";
327
+
328
+ // src/utils.ts
329
+ function clampValue(value, min, max) {
330
+ if (isNaN(value)) return min;
331
+ return Math.min(max, Math.max(min, value));
332
+ }
333
+ function clampHours(value, is12h) {
334
+ return is12h ? clampValue(value, 1, 12) : clampValue(value, 0, 23);
335
+ }
336
+ function clampMinutes(value) {
337
+ return clampValue(value, 0, 59);
338
+ }
339
+ function clampSeconds(value) {
340
+ return clampValue(value, 0, 59);
341
+ }
342
+ function formatSegment(value) {
343
+ if (value === void 0 || value === null) return "";
344
+ return value.toString().padStart(2, "0");
345
+ }
346
+ function parseSegmentInput(text) {
347
+ const num = parseInt(text, 10);
348
+ return isNaN(num) ? null : num;
349
+ }
350
+
351
+ // src/TimeSegment.tsx
352
+ import { jsx as jsx4 } from "react/jsx-runtime";
353
+ var TimeSegment = forwardRef2(
354
+ ({
355
+ value,
356
+ onChange,
357
+ onAdvance,
358
+ onRetreat,
359
+ min,
360
+ max,
361
+ disabled = false,
362
+ placeholder = "--",
363
+ fontSize,
364
+ textColor,
365
+ placeholderColor,
366
+ focusColor,
367
+ "aria-label": ariaLabel,
368
+ testID
369
+ }, ref) => {
370
+ const inputRef = useRef(null);
371
+ const [editBuffer, setEditBuffer] = useState("");
372
+ const [isFocused, setIsFocused] = useState(false);
373
+ const committedRef = useRef(false);
374
+ const freshFocusRef = useRef(false);
375
+ useImperativeHandle(ref, () => ({
376
+ focus: () => inputRef.current?.focus?.()
377
+ }));
378
+ const displayValue = isFocused ? editBuffer : value !== null ? formatSegment(value) : "";
379
+ const commitValue = useCallback(
380
+ (text) => {
381
+ const parsed = parseSegmentInput(text);
382
+ if (parsed !== null) {
383
+ const clamped = Math.min(max, Math.max(min, parsed));
384
+ onChange(clamped);
385
+ }
386
+ },
387
+ [onChange, min, max]
388
+ );
389
+ const handleFocus = () => {
390
+ setIsFocused(true);
391
+ setEditBuffer(value !== null ? formatSegment(value) : "");
392
+ committedRef.current = false;
393
+ freshFocusRef.current = true;
394
+ };
395
+ const handleBlur = () => {
396
+ setIsFocused(false);
397
+ if (!committedRef.current && editBuffer) {
398
+ commitValue(editBuffer);
399
+ }
400
+ committedRef.current = false;
401
+ setEditBuffer("");
402
+ };
403
+ const extractTypedDigit = (newText, oldText) => {
404
+ const newDigits = newText.replace(/\D/g, "");
405
+ const oldDigits = oldText.replace(/\D/g, "");
406
+ if (newDigits.length <= oldDigits.length) return "";
407
+ let remaining = newDigits;
408
+ for (const ch of oldDigits) {
409
+ const idx = remaining.indexOf(ch);
410
+ if (idx !== -1) {
411
+ remaining = remaining.slice(0, idx) + remaining.slice(idx + 1);
412
+ }
413
+ }
414
+ return remaining.charAt(0);
415
+ };
416
+ const handleChangeText = (text) => {
417
+ let digitsOnly = text.replace(/\D/g, "");
418
+ if (freshFocusRef.current || committedRef.current) {
419
+ const typed = extractTypedDigit(text, displayValue);
420
+ freshFocusRef.current = false;
421
+ committedRef.current = false;
422
+ if (!typed) return;
423
+ digitsOnly = typed;
424
+ } else {
425
+ digitsOnly = digitsOnly.slice(-2);
426
+ }
427
+ setEditBuffer(digitsOnly);
428
+ if (digitsOnly.length === 2) {
429
+ committedRef.current = true;
430
+ commitValue(digitsOnly);
431
+ onAdvance();
432
+ }
433
+ };
434
+ const handleKeyDown = (e) => {
435
+ const key = e.key || e.nativeEvent?.key;
436
+ if (key === "ArrowUp") {
437
+ e.preventDefault();
438
+ const current = value ?? min;
439
+ const next = current >= max ? min : current + 1;
440
+ onChange(next);
441
+ setEditBuffer(formatSegment(next));
442
+ committedRef.current = true;
443
+ } else if (key === "ArrowDown") {
444
+ e.preventDefault();
445
+ const current = value ?? min;
446
+ const next = current <= min ? max : current - 1;
447
+ onChange(next);
448
+ setEditBuffer(formatSegment(next));
449
+ committedRef.current = true;
450
+ } else if (key === "ArrowRight") {
451
+ onAdvance();
452
+ } else if (key === "ArrowLeft") {
453
+ onRetreat();
454
+ } else if (key === "Backspace" && editBuffer.length === 0) {
455
+ onChange(null);
456
+ onRetreat();
457
+ } else if (key === "Tab") {
458
+ if (editBuffer) {
459
+ commitValue(editBuffer);
460
+ }
461
+ } else if (key === "Enter") {
462
+ if (editBuffer) {
463
+ commitValue(editBuffer);
464
+ }
465
+ inputRef.current?.blur?.();
466
+ }
467
+ };
468
+ return /* @__PURE__ */ jsx4(
469
+ Box,
470
+ {
471
+ onPress: () => inputRef.current?.focus?.(),
472
+ width: fontSize * 1.5,
473
+ height: fontSize + 8,
474
+ justifyContent: "center",
475
+ alignItems: "center",
476
+ backgroundColor: isFocused ? focusColor : "transparent",
477
+ borderRadius: 4,
478
+ children: /* @__PURE__ */ jsx4(
479
+ InputPrimitive,
480
+ {
481
+ ref: inputRef,
482
+ value: displayValue,
483
+ placeholder,
484
+ onChangeText: handleChangeText,
485
+ onFocus: handleFocus,
486
+ onBlur: handleBlur,
487
+ onKeyDown: handleKeyDown,
488
+ disabled,
489
+ inputMode: "numeric",
490
+ color: textColor,
491
+ fontSize,
492
+ placeholderTextColor: placeholderColor,
493
+ "aria-label": ariaLabel,
494
+ "data-testid": testID,
495
+ style: {
496
+ textAlign: "center",
497
+ width: "100%",
498
+ padding: 0,
499
+ border: "none",
500
+ outline: "none",
501
+ boxShadow: "none",
502
+ background: "transparent",
503
+ caretColor: "transparent"
504
+ }
505
+ }
506
+ )
507
+ }
508
+ );
509
+ }
510
+ );
511
+ TimeSegment.displayName = "TimeSegment";
512
+
513
+ // src/PeriodToggle.tsx
514
+ import { jsx as jsx5 } from "react/jsx-runtime";
515
+ var PeriodToggle = ({
516
+ value,
517
+ onChange,
518
+ disabled = false,
519
+ fontSize,
520
+ textColor,
521
+ testID
522
+ }) => {
523
+ const toggle = () => {
524
+ if (!disabled) {
525
+ onChange(value === "am" ? "pm" : "am");
526
+ }
527
+ };
528
+ return /* @__PURE__ */ jsx5(
529
+ Box,
530
+ {
531
+ onPress: toggle,
532
+ cursor: disabled ? "default" : "pointer",
533
+ justifyContent: "center",
534
+ alignItems: "center",
535
+ paddingHorizontal: 4,
536
+ role: "button",
537
+ "aria-label": `Time period: ${value.toUpperCase()}. Click to toggle.`,
538
+ "data-testid": testID,
539
+ children: /* @__PURE__ */ jsx5(Text, { color: textColor, fontSize, fontWeight: "500", children: value })
540
+ }
541
+ );
542
+ };
543
+
544
+ // src/InputTime.tsx
545
+ import { Fragment, jsx as jsx6, jsxs } from "react/jsx-runtime";
546
+ var InputTime = ({
547
+ value,
548
+ onChange,
549
+ showSeconds = false,
550
+ showPeriod = false,
551
+ hourCycle = 24,
552
+ icon = /* @__PURE__ */ jsx6(Clock, {}),
553
+ size = "md",
554
+ disabled = false,
555
+ error,
556
+ "aria-label": ariaLabel,
557
+ testID
558
+ }) => {
559
+ const { theme } = useDesignSystem();
560
+ const rawId = useId();
561
+ const safeId = rawId.replace(/:/g, "");
562
+ const inputId = `input-time-${safeId}`;
563
+ const errorId = `${inputId}-error`;
564
+ const [internalState, setInternalState] = useState2(
565
+ "default"
566
+ );
567
+ const segmentRefs = useRef2([]);
568
+ const is12h = hourCycle === 12;
569
+ const [hours, setHours] = useState2(value?.hours ?? null);
570
+ const [minutes, setMinutes] = useState2(value?.minutes ?? null);
571
+ const [seconds, setSeconds] = useState2(value?.seconds ?? null);
572
+ const [period, setPeriod] = useState2(value?.period ?? "am");
573
+ useEffect(() => {
574
+ if (value) {
575
+ setHours(value.hours);
576
+ setMinutes(value.minutes);
577
+ setSeconds(value.seconds ?? null);
578
+ setPeriod(value.period ?? "am");
579
+ } else if (value === null) {
580
+ setHours(null);
581
+ setMinutes(null);
582
+ setSeconds(null);
583
+ setPeriod("am");
584
+ }
585
+ }, [value]);
586
+ const emitChange = useCallback2(
587
+ (h, m, s, p) => {
588
+ if (h === null || m === null) {
589
+ onChange?.(null);
590
+ return;
591
+ }
592
+ const result = {
593
+ hours: clampHours(h, is12h),
594
+ minutes: clampMinutes(m)
595
+ };
596
+ if (showSeconds) {
597
+ result.seconds = s !== null ? clampSeconds(s) : 0;
598
+ }
599
+ if (showPeriod) {
600
+ result.period = p;
601
+ }
602
+ onChange?.(result);
603
+ },
604
+ [onChange, is12h, showSeconds, showPeriod]
605
+ );
606
+ const handleHoursChange = (v) => {
607
+ const clamped = v !== null ? clampHours(v, is12h) : null;
608
+ setHours(clamped);
609
+ emitChange(clamped, minutes, seconds, period);
610
+ };
611
+ const handleMinutesChange = (v) => {
612
+ const clamped = v !== null ? clampMinutes(v) : null;
613
+ setMinutes(clamped);
614
+ emitChange(hours, clamped, seconds, period);
615
+ };
616
+ const handleSecondsChange = (v) => {
617
+ const clamped = v !== null ? clampSeconds(v) : null;
618
+ setSeconds(clamped);
619
+ emitChange(hours, minutes, clamped, period);
620
+ };
621
+ const handlePeriodChange = (v) => {
622
+ setPeriod(v);
623
+ emitChange(hours, minutes, seconds, v);
624
+ };
625
+ const focusSegment = (index) => {
626
+ segmentRefs.current[index]?.focus?.();
627
+ };
628
+ const segmentCount = showSeconds ? 3 : 2;
629
+ const advanceFrom = (i) => () => {
630
+ if (i < segmentCount - 1) focusSegment(i + 1);
631
+ };
632
+ const retreatFrom = (i) => () => {
633
+ if (i > 0) focusSegment(i - 1);
634
+ };
635
+ const sizeStyles = theme.sizing.input(size);
636
+ const inputColors = theme.colors.control.input;
637
+ const isError = !!error;
638
+ const isFocus = internalState === "focus";
639
+ let backgroundColor = inputColors.bg;
640
+ let borderColor = inputColors.border;
641
+ let outlineColor;
642
+ if (disabled) {
643
+ backgroundColor = inputColors.bgDisable;
644
+ borderColor = inputColors.borderDisable;
645
+ } else if (isError) {
646
+ outlineColor = theme.colors.border.alert;
647
+ if (isFocus) {
648
+ backgroundColor = theme.colors.control.focus.bg;
649
+ }
650
+ } else if (isFocus) {
651
+ backgroundColor = theme.colors.control.focus.bg;
652
+ outlineColor = theme.colors.border.brand;
653
+ }
654
+ const textColor = disabled ? inputColors.textDisable : inputColors.text;
655
+ const placeholderColor = inputColors.placeholder;
656
+ const iconColor = inputColors.placeholder;
657
+ const paddingConfig = {
658
+ xl: { vertical: 12, horizontal: 12 },
659
+ lg: { vertical: 14, horizontal: 12 },
660
+ md: { vertical: 11, horizontal: 12 },
661
+ sm: { vertical: 7, horizontal: 10 },
662
+ xs: { vertical: 7, horizontal: 10 }
663
+ };
664
+ const borderRadiusConfig = {
665
+ xl: 8,
666
+ lg: 8,
667
+ md: 8,
668
+ sm: 4,
669
+ xs: 4
670
+ };
671
+ const iconSizeConfig = {
672
+ xl: 22,
673
+ lg: 20,
674
+ md: 18,
675
+ sm: 16,
676
+ xs: 14
677
+ };
678
+ const focusOutlineConfig = {
679
+ xl: { width: 1, offset: -1 },
680
+ lg: { width: 1, offset: -1 },
681
+ md: { width: 1, offset: -1 },
682
+ sm: { width: 1, offset: -1 },
683
+ xs: { width: 1, offset: -1 }
684
+ };
685
+ const padding = paddingConfig[size];
686
+ const borderRadius = borderRadiusConfig[size];
687
+ const iconSize = iconSizeConfig[size];
688
+ const focusOutline = focusOutlineConfig[size];
689
+ const handleContainerFocus = () => {
690
+ if (!disabled) setInternalState("focus");
691
+ };
692
+ const handleContainerBlur = () => {
693
+ if (!disabled) setInternalState("default");
694
+ };
695
+ const colonColor = disabled ? placeholderColor : textColor;
696
+ return /* @__PURE__ */ jsxs(
697
+ Box,
698
+ {
699
+ flexDirection: "column",
700
+ gap: sizeStyles.fieldGap,
701
+ width: "100%",
702
+ testID,
703
+ children: [
704
+ /* @__PURE__ */ jsxs(
705
+ Box,
706
+ {
707
+ backgroundColor,
708
+ borderColor,
709
+ borderWidth: borderColor !== "transparent" ? 1 : 0,
710
+ borderRadius,
711
+ height: sizeStyles.height,
712
+ paddingVertical: padding.vertical,
713
+ paddingHorizontal: padding.horizontal,
714
+ flexDirection: "row",
715
+ alignItems: "center",
716
+ gap: 2,
717
+ position: "relative",
718
+ style: {
719
+ ...outlineColor ? {
720
+ outline: `${focusOutline.width}px solid ${outlineColor}`,
721
+ outlineOffset: `${focusOutline.offset}px`
722
+ } : {}
723
+ },
724
+ hoverStyle: !disabled && !isFocus && !isError ? {
725
+ backgroundColor: inputColors.bgHover,
726
+ borderColor: inputColors.borderHover
727
+ } : void 0,
728
+ onFocus: handleContainerFocus,
729
+ onBlur: handleContainerBlur,
730
+ role: "group",
731
+ "aria-label": ariaLabel || "Time input",
732
+ "aria-describedby": error ? errorId : void 0,
733
+ children: [
734
+ icon && /* @__PURE__ */ jsx6(Box, { marginRight: 6, alignItems: "center", justifyContent: "center", children: React4.isValidElement(icon) ? React4.cloneElement(icon, {
735
+ size: iconSize,
736
+ color: iconColor
737
+ }) : icon }),
738
+ /* @__PURE__ */ jsx6(
739
+ TimeSegment,
740
+ {
741
+ ref: (el) => {
742
+ segmentRefs.current[0] = el;
743
+ },
744
+ value: hours,
745
+ onChange: handleHoursChange,
746
+ onAdvance: advanceFrom(0),
747
+ onRetreat: retreatFrom(0),
748
+ min: is12h ? 1 : 0,
749
+ max: is12h ? 12 : 23,
750
+ disabled,
751
+ placeholder: "--",
752
+ fontSize: sizeStyles.fontSize,
753
+ textColor,
754
+ placeholderColor,
755
+ focusColor: theme.colors.background.brand.primary,
756
+ "aria-label": "Hours",
757
+ testID: testID ? `${testID}-hours` : void 0
758
+ }
759
+ ),
760
+ /* @__PURE__ */ jsx6(
761
+ Text,
762
+ {
763
+ color: colonColor,
764
+ fontSize: sizeStyles.fontSize,
765
+ fontWeight: "500",
766
+ children: ":"
767
+ }
768
+ ),
769
+ /* @__PURE__ */ jsx6(
770
+ TimeSegment,
771
+ {
772
+ ref: (el) => {
773
+ segmentRefs.current[1] = el;
774
+ },
775
+ value: minutes,
776
+ onChange: handleMinutesChange,
777
+ onAdvance: advanceFrom(1),
778
+ onRetreat: retreatFrom(1),
779
+ min: 0,
780
+ max: 59,
781
+ disabled,
782
+ placeholder: "--",
783
+ fontSize: sizeStyles.fontSize,
784
+ textColor,
785
+ placeholderColor,
786
+ focusColor: theme.colors.background.brand.primary,
787
+ "aria-label": "Minutes",
788
+ testID: testID ? `${testID}-minutes` : void 0
789
+ }
790
+ ),
791
+ showSeconds && /* @__PURE__ */ jsxs(Fragment, { children: [
792
+ /* @__PURE__ */ jsx6(
793
+ Text,
794
+ {
795
+ color: colonColor,
796
+ fontSize: sizeStyles.fontSize,
797
+ fontWeight: "500",
798
+ children: ":"
799
+ }
800
+ ),
801
+ /* @__PURE__ */ jsx6(
802
+ TimeSegment,
803
+ {
804
+ ref: (el) => {
805
+ segmentRefs.current[2] = el;
806
+ },
807
+ value: seconds,
808
+ onChange: handleSecondsChange,
809
+ onAdvance: advanceFrom(2),
810
+ onRetreat: retreatFrom(2),
811
+ min: 0,
812
+ max: 59,
813
+ disabled,
814
+ placeholder: "--",
815
+ fontSize: sizeStyles.fontSize,
816
+ textColor,
817
+ placeholderColor,
818
+ focusColor: theme.colors.background.brand.primary,
819
+ "aria-label": "Seconds",
820
+ testID: testID ? `${testID}-seconds` : void 0
821
+ }
822
+ )
823
+ ] }),
824
+ showPeriod && /* @__PURE__ */ jsx6(
825
+ PeriodToggle,
826
+ {
827
+ value: period,
828
+ onChange: handlePeriodChange,
829
+ disabled,
830
+ fontSize: sizeStyles.fontSize,
831
+ textColor,
832
+ testID: testID ? `${testID}-period` : void 0
833
+ }
834
+ )
835
+ ]
836
+ }
837
+ ),
838
+ error && /* @__PURE__ */ jsx6(
839
+ Text,
840
+ {
841
+ id: errorId,
842
+ role: "alert",
843
+ color: theme.colors.content.alert.primary,
844
+ fontSize: sizeStyles.fontSize - 2,
845
+ children: error
846
+ }
847
+ )
848
+ ]
849
+ }
850
+ );
851
+ };
852
+ InputTime.displayName = "InputTime";
853
+ export {
854
+ InputTime
855
+ };
856
+ //# sourceMappingURL=index.mjs.map