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