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