@astryxdesign/core 0.7.8-canary.b35fe83 → 0.7.8-canary.b87922f

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.
Files changed (46) hide show
  1. package/dist/DateInput/PickerWheel.d.ts +1 -1
  2. package/dist/DateInput/PickerWheel.d.ts.map +1 -1
  3. package/dist/DateInput/PickerWheel.js +28 -4
  4. package/dist/DateInput/Wheel.d.ts +2 -2
  5. package/dist/DateInput/Wheel.d.ts.map +1 -1
  6. package/dist/DateInput/Wheel.js +20 -4
  7. package/dist/DateInput/datePickerTouch.d.ts +13 -0
  8. package/dist/DateInput/datePickerTouch.d.ts.map +1 -0
  9. package/dist/DateInput/datePickerTouch.js +14 -0
  10. package/dist/DateInput/wheelOptions.d.ts +22 -2
  11. package/dist/DateInput/wheelOptions.d.ts.map +1 -1
  12. package/dist/DateInput/wheelOptions.js +14 -2
  13. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  14. package/dist/DateTimeInput/TouchDateTimeField.js +62 -119
  15. package/dist/TimeInput/TimeWheels.d.ts +32 -0
  16. package/dist/TimeInput/TimeWheels.d.ts.map +1 -0
  17. package/dist/TimeInput/TimeWheels.js +144 -0
  18. package/dist/TimeInput/TouchTimeField.d.ts.map +1 -1
  19. package/dist/TimeInput/TouchTimeField.js +63 -118
  20. package/dist/TimeInput/timeWheelRules.d.ts +124 -0
  21. package/dist/TimeInput/timeWheelRules.d.ts.map +1 -0
  22. package/dist/TimeInput/timeWheelRules.js +277 -0
  23. package/dist/gestures/GestureHost.d.ts.map +1 -1
  24. package/dist/gestures/GestureHost.js +3 -0
  25. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts +8 -0
  26. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.d.ts.map +1 -0
  27. package/dist/i18n/generated-english/TimeInput/TimeWheels.generated.js +17 -0
  28. package/dist/utils/selectionLock.d.ts +10 -1
  29. package/dist/utils/selectionLock.d.ts.map +1 -1
  30. package/dist/utils/selectionLock.js +31 -5
  31. package/dist/utils/timeParser.d.ts +2 -1
  32. package/dist/utils/timeParser.d.ts.map +1 -1
  33. package/dist/utils/timeParser.js +29 -3
  34. package/package.json +4 -4
  35. package/src/DateInput/PickerWheel.tsx +37 -2
  36. package/src/DateInput/Wheel.tsx +30 -2
  37. package/src/DateInput/datePickerTouch.ts +15 -0
  38. package/src/DateInput/wheelOptions.ts +31 -2
  39. package/src/DateTimeInput/TouchDateTimeField.tsx +94 -178
  40. package/src/TimeInput/TimeWheels.tsx +218 -0
  41. package/src/TimeInput/TouchTimeField.tsx +93 -157
  42. package/src/TimeInput/timeWheelRules.ts +352 -0
  43. package/src/gestures/GestureHost.ts +5 -4
  44. package/src/i18n/generated-english/TimeInput/TimeWheels.generated.ts +18 -0
  45. package/src/utils/selectionLock.ts +40 -6
  46. package/src/utils/timeParser.ts +40 -3
@@ -12,7 +12,7 @@ import { type WheelProps } from './wheelOptions.js';
12
12
  * <PickerWheel label="Month" options={monthOptions} value={month} onChange={setMonth} />
13
13
  * ```
14
14
  */
15
- export declare function PickerWheel({ label, options, value, onChange, isActive, }: WheelProps): import("react").JSX.Element;
15
+ export declare function PickerWheel({ label, options, value, onChange, isActive, ref, }: WheelProps): import("react").JSX.Element;
16
16
  export declare namespace PickerWheel {
17
17
  var displayName: string;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PickerWheel.d.ts","sourceRoot":"","sources":["../../src/DateInput/PickerWheel.tsx"],"names":[],"mappings":"AAmDA,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AA2HxB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAe,GAChB,EAAE,UAAU,+BA8gBZ;yBAphBe,WAAW"}
1
+ {"version":3,"file":"PickerWheel.d.ts","sourceRoot":"","sources":["../../src/DateInput/PickerWheel.tsx"],"names":[],"mappings":"AA2DA,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AA2HxB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAe,EACf,GAAG,GACJ,EAAE,UAAU,+BAuiBZ;yBA9iBe,WAAW"}
@@ -4,7 +4,8 @@
4
4
 
5
5
  /**
6
6
  * @file PickerWheel.tsx
7
- * @input Wheel's props (wheelOptions.ts): options, value and change callback
7
+ * @input Wheel's props (wheelOptions.ts): options, value and change callback;
8
+ * optionally a ref for programmatic turns
8
9
  * @output PickerWheel: one picker column that moves like UIPickerView
9
10
  * @position Internal component; the Wheel under a finger (Wheel.tsx picks it)
10
11
  *
@@ -14,7 +15,7 @@
14
15
  * SYNC: When modified, update PickerWheel.test.tsx, Wheel.tsx,
15
16
  * DateInputTouch.test.tsx, DateInput.doc.mjs and TimeInput.doc.mjs.
16
17
  */
17
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
18
+ import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
18
19
  import * as stylex from '@stylexjs/stylex';
19
20
  import { scrollTypeOf } from "../gestures/GestureHost.js";
20
21
  import { PanGestureRecognizer } from "../gestures/PanGestureRecognizer.js";
@@ -36,7 +37,7 @@ import { useOwnScrollGesture } from "./useOwnScrollGesture.js";
36
37
  import { useWheelListbox } from "./useWheelListbox.js";
37
38
  import { createWheelStrip } from "./wheelStrip.js";
38
39
  import { dragOffset, nearestIndex, offsetBounds, planRelease, spinCurve } from "./wheelPhysics.js";
39
- import { endIndex, nearestEnabledIndex, steppedIndex, WHEEL_ROW_HEIGHT } from "./wheelOptions.js";
40
+ import { canSpinTo, endIndex, nearestEnabledIndex, steppedIndex, WHEEL_ROW_HEIGHT } from "./wheelOptions.js";
40
41
 
41
42
  /** Row pitch, px: the touch column keeps the scrolling column's pitch. */
42
43
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -130,7 +131,8 @@ export function PickerWheel({
130
131
  options,
131
132
  value,
132
133
  onChange,
133
- isActive = true
134
+ isActive = true,
135
+ ref
134
136
  }) {
135
137
  const columnRef = useRef(null);
136
138
  const rowsRef = useRef(null);
@@ -468,6 +470,28 @@ export function PickerWheel({
468
470
  isEnabled: isActive,
469
471
  isPointerKept: true
470
472
  });
473
+
474
+ // A spin turns only onto an enabled row (canSpinTo). So its arrival commits
475
+ // that row, and nothing turns on past it. It reports the row it was asked
476
+ // for, as the scrolling column does.
477
+ const spinTo = useCallback(async index => new Promise(resolve => {
478
+ if (!canSpinTo(latestRef.current.options, index)) {
479
+ resolve(false);
480
+ return;
481
+ }
482
+ const offset = motion.offset();
483
+ move(turnCurve(columnRef.current, offset, index * ROW_HEIGHT), {
484
+ onEnd: (outcome, end) => {
485
+ if (outcome === 'arrived') {
486
+ arrive(end);
487
+ }
488
+ resolve(outcome === 'arrived');
489
+ }
490
+ });
491
+ }), [motion, move, arrive]);
492
+ useImperativeHandle(ref, () => ({
493
+ spinTo
494
+ }), [spinTo]);
471
495
  const turnToPosition = useCallback((position, offset) => {
472
496
  const current = latestRef.current;
473
497
  const option = current.options[position];
@@ -1,5 +1,5 @@
1
1
  import { type WheelProps } from './wheelOptions.js';
2
- export { nearestEnabledIndex, type WheelOption, type WheelProps, } from './wheelOptions.js';
2
+ export { nearestEnabledIndex, type WheelHandle, type WheelOption, type WheelProps, } from './wheelOptions.js';
3
3
  /**
4
4
  * One picker column: UIPickerView's motion with flat rows under a finger, the
5
5
  * snap-scrolling column under a fine pointer.
@@ -31,7 +31,7 @@ export declare namespace Wheel {
31
31
  * />
32
32
  * ```
33
33
  */
34
- export declare function ScrollWheel({ label, options, value, onChange, isActive, }: WheelProps): import("react").JSX.Element;
34
+ export declare function ScrollWheel({ label, options, value, onChange, isActive, ref, }: WheelProps): import("react").JSX.Element;
35
35
  export declare namespace ScrollWheel {
36
36
  var displayName: string;
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Wheel.d.ts","sourceRoot":"","sources":["../../src/DateInput/Wheel.tsx"],"names":[],"mappings":"AAoDA,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAC;AAoMxB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BAKtC;yBALe,KAAK;;;AASrB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAe,GAChB,EAAE,UAAU,+BAmUZ;yBAzUe,WAAW"}
1
+ {"version":3,"file":"Wheel.d.ts","sourceRoot":"","sources":["../../src/DateInput/Wheel.tsx"],"names":[],"mappings":"AA2DA,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAC;AAoMxB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,+BAKtC;yBALe,KAAK;;;AASrB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAe,EACf,GAAG,GACJ,EAAE,UAAU,+BAqVZ;yBA5Ve,WAAW"}
@@ -4,7 +4,8 @@
4
4
 
5
5
  /**
6
6
  * @file Wheel.tsx
7
- * @input Option list, selected value and change callback
7
+ * @input Option list, selected value and change callback; a ref for
8
+ * programmatic turns
8
9
  * @output Exports Wheel (one picker column), ScrollWheel (the scrolling
9
10
  * column) and the shared types of wheelOptions.ts
10
11
  * @position Internal component; consumed by MonthYearWheels.tsx,
@@ -26,7 +27,7 @@
26
27
  * - /packages/core/src/DateInput/DateInput.doc.mjs
27
28
  * - /packages/core/src/DateInput/DateInputTouch.test.tsx
28
29
  */
29
- import { useCallback, useEffect, useRef, useState } from 'react';
30
+ import { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
30
31
  import * as stylex from '@stylexjs/stylex';
31
32
  import "../theme/tokens.stylex.js";
32
33
  import { colorVars, radiusVars, fontWeightVars, typeScaleVars, spacingVars, durationVars } from "../theme/tokens.stylex.js";
@@ -40,7 +41,7 @@ import { useOwnScrollGesture } from "./useOwnScrollGesture.js";
40
41
  import { usePointerDragScroll } from "./usePointerDragScroll.js";
41
42
  import { useScrollSettle } from "./useScrollSettle.js";
42
43
  import { useWheelListbox } from "./useWheelListbox.js";
43
- import { endIndex, nearestEnabledIndex, steppedIndex } from "./wheelOptions.js";
44
+ import { canSpinTo, endIndex, nearestEnabledIndex, steppedIndex } from "./wheelOptions.js";
44
45
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
45
46
  export { nearestEnabledIndex } from "./wheelOptions.js";
46
47
  const ITEM_BLOCK_SIZE = dateInputTouchSizes.wheelItemSize;
@@ -130,8 +131,23 @@ export function ScrollWheel({
130
131
  options,
131
132
  value,
132
133
  onChange,
133
- isActive = true
134
+ isActive = true,
135
+ ref
134
136
  }) {
137
+ // A spin commits the row at once. The new value then scrolls the column
138
+ // there, as any new value does.
139
+ useImperativeHandle(ref, () => ({
140
+ spinTo: async index => {
141
+ if (!canSpinTo(options, index)) {
142
+ return false;
143
+ }
144
+ const option = options[index];
145
+ if (option.value !== value) {
146
+ onChange(option.value);
147
+ }
148
+ return true;
149
+ }
150
+ }), [options, value, onChange]);
135
151
  const scrollerRef = useRef(null);
136
152
  const selectedIndex = Math.max(0, options.findIndex(option => option.value === value));
137
153
  // Which row is under the band right now. Tracks the finger during a scroll;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file datePickerTouch.ts
3
+ * @input The date and time pickers' touch-only pieces
4
+ * @output Re-exports what the date and time sheets use only under a finger:
5
+ * TimeWheels
6
+ * @position The pickers' touch layer. The sheets import touch behaviour from
7
+ * here only, so a desktop build can replace this one module.
8
+ *
9
+ * SYNC: When modified, update TouchTimeField.tsx and TouchDateTimeField.tsx.
10
+ */
11
+ export { TimeWheels } from '../TimeInput/TimeWheels.js';
12
+ export type { TimeWheelsProps } from '../TimeInput/TimeWheels.js';
13
+ //# sourceMappingURL=datePickerTouch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datePickerTouch.d.ts","sourceRoot":"","sources":["../../src/DateInput/datePickerTouch.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC;AACnD,YAAY,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file datePickerTouch.ts
5
+ * @input The date and time pickers' touch-only pieces
6
+ * @output Re-exports what the date and time sheets use only under a finger:
7
+ * TimeWheels
8
+ * @position The pickers' touch layer. The sheets import touch behaviour from
9
+ * here only, so a desktop build can replace this one module.
10
+ *
11
+ * SYNC: When modified, update TouchTimeField.tsx and TouchDateTimeField.tsx.
12
+ */
13
+
14
+ export { TimeWheels } from "../TimeInput/TimeWheels.js";
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @file wheelOptions.ts
3
3
  * @input Nothing; types, the row height and pure functions
4
- * @output WheelOption, WheelProps, WHEEL_ROW_HEIGHT, nearestEnabledIndex,
5
- * steppedIndex and endIndex: what both wheels share
4
+ * @output WheelOption, WheelProps, WheelHandle, WHEEL_ROW_HEIGHT, canSpinTo,
5
+ * nearestEnabledIndex, steppedIndex and endIndex: what both wheels share
6
6
  * @position Internal; read by Wheel.tsx (which re-exports all of it) and
7
7
  * PickerWheel.tsx
8
8
  *
@@ -10,6 +10,7 @@
10
10
  * - /packages/core/src/DateInput/Wheel.tsx
11
11
  * - /packages/core/src/DateInput/PickerWheel.tsx
12
12
  */
13
+ import type { Ref } from 'react';
13
14
  /**
14
15
  * The row height, px (`dateInputTouchSizes.wheelItemSize`): the pitch of both
15
16
  * columns' rows, and the unit of the touch wheel's offset.
@@ -32,6 +33,18 @@ export interface WheelOption {
32
33
  */
33
34
  order?: number;
34
35
  }
36
+ /** What a Wheel's `ref` exposes. */
37
+ export interface WheelHandle {
38
+ /**
39
+ * Turn the wheel onto `index` (an index into `options`) on the tap spin, then
40
+ * commit it as a rest would. Resolves true once that row is the committed
41
+ * one, false if a finger or another turn interrupted it or the wheel went
42
+ * away first. An index outside `options` or a disabled row resolves false at
43
+ * once, and nothing turns. Under a fine pointer the row commits at once. The
44
+ * column then scrolls to it as for any new value, on the same rule.
45
+ */
46
+ spinTo(index: number): Promise<boolean>;
47
+ }
35
48
  export interface WheelProps {
36
49
  /** Accessible name for the column, e.g. "Month". */
37
50
  label: string;
@@ -48,7 +61,14 @@ export interface WheelProps {
48
61
  * motion.
49
62
  */
50
63
  isActive?: boolean;
64
+ /** Programmatic turns: `spinTo(index)`. */
65
+ ref?: Ref<WheelHandle>;
51
66
  }
67
+ /**
68
+ * Whether `spinTo(index)` may turn onto `index`: an enabled row of `options`.
69
+ * The touch wheel and the scrolling column answer a spin by the same rule.
70
+ */
71
+ export declare function canSpinTo(options: ReadonlyArray<WheelOption>, index: number): boolean;
52
72
  /**
53
73
  * The enabled row nearest `index`: `index` itself when it is enabled,
54
74
  * otherwise the closest enabled row on either side. A tie goes to the side of
@@ -1 +1 @@
1
- {"version":3,"file":"wheelOptions.d.ts","sourceRoot":"","sources":["../../src/DateInput/wheelOptions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,KAAK,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  * @input Nothing; types, the row height and pure functions
6
- * @output WheelOption, WheelProps, WHEEL_ROW_HEIGHT, nearestEnabledIndex,
7
- * steppedIndex and endIndex: what both wheels share
6
+ * @output WheelOption, WheelProps, WheelHandle, WHEEL_ROW_HEIGHT, canSpinTo,
7
+ * nearestEnabledIndex, steppedIndex and endIndex: what both wheels share
8
8
  * @position Internal; read by Wheel.tsx (which re-exports all of it) and
9
9
  * PickerWheel.tsx
10
10
  *
@@ -18,6 +18,18 @@
18
18
  * columns' rows, and the unit of the touch wheel's offset.
19
19
  */
20
20
  export const WHEEL_ROW_HEIGHT = 28;
21
+
22
+ /** What a Wheel's `ref` exposes. */
23
+
24
+ /**
25
+ * Whether `spinTo(index)` may turn onto `index`: an enabled row of `options`.
26
+ * The touch wheel and the scrolling column answer a spin by the same rule.
27
+ */
28
+ export function canSpinTo(options, index) {
29
+ const option = options[index];
30
+ return option != null && !option.isDisabled;
31
+ }
32
+
21
33
  /**
22
34
  * The enabled row nearest `index`: `index` itself when it is enabled,
23
35
  * otherwise the closest enabled row on either side. A tie goes to the side of
@@ -1 +1 @@
1
- {"version":3,"file":"TouchDateTimeField.d.ts","sourceRoot":"","sources":["../../src/DateTimeInput/TouchDateTimeField.tsx"],"names":[],"mappings":"AA6GA,OAAO,KAAK,EAAC,kBAAkB,EAAoB,MAAM,iBAAiB,CAAC;AAoV3E,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,aAAqB,EACrB,WAAW,EACX,UAAkB,EAClB,UAAkB,EAClB,UAAkB,EAClB,eAAe,EACf,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,SAAiB,EACjB,GAAG,EACH,GAAG,EACH,eAAe,EACf,UAAkB,EAClB,UAAkB,EAElB,aAAa,EAAE,cAAc,EAC7B,kBAAkB,EAAE,mBAAmB,EACvC,QAAgB,EAChB,WAAW,EAAE,oBAAoB,EACjC,eAAe,EAAE,wBAAwB,EACzC,SAAS,EACT,IAAI,EAAE,QAAQ,EACd,MAAM,EACN,YAAY,EAEZ,cAAc,EAAE,eAAe,EAC/B,YAAY,EAAE,gBAAoB,EAClC,KAAK,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,GAAG,EACH,GAAG,SAAS,EACb,EAAE,kBAAkB,+BAy/BpB;yBAhiCe,kBAAkB"}
1
+ {"version":3,"file":"TouchDateTimeField.d.ts","sourceRoot":"","sources":["../../src/DateTimeInput/TouchDateTimeField.tsx"],"names":[],"mappings":"AAuHA,OAAO,KAAK,EAAC,kBAAkB,EAAoB,MAAM,iBAAiB,CAAC;AA6S3E,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,aAAqB,EACrB,WAAW,EACX,UAAkB,EAClB,UAAkB,EAClB,UAAkB,EAClB,eAAe,EACf,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,SAAiB,EACjB,GAAG,EACH,GAAG,EACH,eAAe,EACf,UAAkB,EAClB,UAAkB,EAElB,aAAa,EAAE,cAAc,EAC7B,kBAAkB,EAAE,mBAAmB,EACvC,QAAgB,EAChB,WAAW,EAAE,oBAAoB,EACjC,eAAe,EAAE,wBAAwB,EACzC,SAAS,EACT,IAAI,EAAE,QAAQ,EACd,MAAM,EACN,YAAY,EAEZ,cAAc,EAAE,eAAe,EAC/B,YAAY,EAAE,gBAAoB,EAClC,KAAK,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,GAAG,EACH,GAAG,SAAS,EACb,EAAE,kBAAkB,+BAk8BpB;yBAz+Be,kBAAkB"}
@@ -4,7 +4,7 @@
4
4
 
5
5
  /**
6
6
  * @file TouchDateTimeField.tsx
7
- * @input Uses React, Field, BottomSheet, SegmentedControl, DateInput month picker primitives, Wheel, StyleX intrinsic flex layout
7
+ * @input Uses React, Field, BottomSheet, SegmentedControl, DateInput month picker primitives, Wheel and the pickers' touch layer (TimeWheels), the touch presentation, StyleX intrinsic flex layout
8
8
  * @output Exports TouchDateTimeField — the coarse-pointer surface behind DateTimeInput
9
9
  * @position Internal component; consumed by DateTimeInput.tsx
10
10
  *
@@ -46,7 +46,7 @@ import { themeProps } from "../utils/themeProps.js";
46
46
  import { normalizeDayOfWeek } from "../utils/dateTypes.js";
47
47
  import { formatLocaleTime } from "../utils/timeFormat.js";
48
48
  import { getWeekdayHeaders } from "../Calendar/getWeekdayHeaderNames.js";
49
- import { formatISOTime, isImeKeyEvent, isRenderable, isTimeInRange, clampTime, mergeProps, parseISOTime } from "../utils/index.js";
49
+ import { formatISOTime, isImeKeyEvent, isRenderable, clampTime, mergeProps, parseISOTime } from "../utils/index.js";
50
50
  import { chainEventHandlers } from "../utils/chainEventHandlers.js";
51
51
  import { joinAriaIDs } from "../utils/inputAria.js";
52
52
  import { DATE_FORMAT_LONG, plainDateFormat, plainDateFromISO, plainDateToday } from "../utils/plainDate.js";
@@ -54,13 +54,16 @@ import { plainDateFormatStandaloneMonthYear } from "../utils/plainDate.js";
54
54
  import { MonthScroller } from "../DateInput/MonthScroller.js";
55
55
  import { MonthYearWheels } from "../DateInput/MonthYearWheels.js";
56
56
  import { Wheel } from "../DateInput/Wheel.js";
57
+ import { TimeWheels } from "../DateInput/datePickerTouch.js";
58
+ import { hour12From24, hour24From12, hourRowsInHalf, meridiemRows, minuteRows, secondRows, wheelBounds } from "../TimeInput/timeWheelRules.js";
59
+ import { useTouchPresentation } from "../utils/touchPresentation.js";
57
60
  import "../DateInput/tokens.stylex.js";
58
61
  import { dateInputTouchGeometry, dateInputTouchSizes } from "../DateInput/tokens.stylex.js";
59
62
  import { DEFAULT_MONTH_REACH, clampIndex, fromMonthIndex, monthIndexOf } from "../DateInput/monthGeometry.js";
60
63
  import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
61
64
  import { InternationalizationContext } from "../i18n/InternationalizationContext.js";
62
65
  import english from "../i18n/generated-english/DateTimeInput/TouchDateTimeField.generated.js";
63
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
66
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
64
67
  registerEnglishFallback(english);
65
68
  function splitDateTime(dt) {
66
69
  if (!dt) {
@@ -201,30 +204,6 @@ function normalizeISOTime(time, hasSeconds) {
201
204
  const parsed = parseISOTime(time);
202
205
  return parsed ? formatISOTime(parsed, hasSeconds) : undefined;
203
206
  }
204
- function timeToSeconds(time) {
205
- if (time === undefined) {
206
- return null;
207
- }
208
- const parsed = parseISOTime(time);
209
- return parsed == null ? null : parsed.hour * 3600 + parsed.minute * 60 + parsed.second;
210
- }
211
- function twoDigits(value) {
212
- return String(value).padStart(2, '0');
213
- }
214
- function hour12From24(hour) {
215
- return hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;
216
- }
217
- function hour24From12(hour, meridiem) {
218
- if (meridiem === 0) {
219
- return hour === 12 ? 0 : hour;
220
- }
221
- return hour === 12 ? 12 : hour + 12;
222
- }
223
- function rangeOverlaps(startSecond, endSecond, min, max) {
224
- const minSecond = timeToSeconds(min);
225
- const maxSecond = timeToSeconds(max);
226
- return (minSecond == null || endSecond >= minSecond) && (maxSecond == null || startSecond <= maxSecond);
227
- }
228
207
  export function TouchDateTimeField({
229
208
  label,
230
209
  isLabelHidden = false,
@@ -348,6 +327,9 @@ export function TouchDateTimeField({
348
327
  useBusyAnnouncement(isBusy, t('@astryx.spinner.loading'), isSheetOpen ? sheetBodyRef : dateInputRef);
349
328
  const [activePanel, setActivePanel] = useState('date');
350
329
  const [isWheelOpen, setIsWheelOpen] = useState(false);
330
+ const {
331
+ isTouch
332
+ } = useTouchPresentation();
351
333
  const [draftTime, setDraftTime] = useState(() => normalizeISOTime(splitDateTime(value).time, hasSeconds));
352
334
  const today = useMemo(() => plainDateToday(), []);
353
335
  const selectedDate = useMemo(() => parseValidISODate(valueParts.date), [valueParts.date]);
@@ -519,63 +501,14 @@ export function TouchDateTimeField({
519
501
  }, hasSeconds);
520
502
  }, [hasSeconds, hourFormat, parsedWheelTime]);
521
503
  const timeBounds = timeBoundsForDate(valueParts.date);
522
- const hourOptions = useMemo(() => {
523
- if (hourFormat === '24h') {
524
- return Array.from({
525
- length: 24
526
- }, (_, hour) => ({
527
- value: hour,
528
- label: twoDigits(hour),
529
- isDisabled: !rangeOverlaps(hour * 3600, hour * 3600 + 3599, timeBounds.min, timeBounds.max)
530
- }));
531
- }
532
- const meridiem = parsedWheelTime.hour < 12 ? 0 : 1;
533
- // In 12-hour mode the hour column is interpreted inside the active AM/PM
534
- // half, so disabled rows describe reachability within that half only.
535
- return Array.from({
536
- length: 12
537
- }, (_, index) => {
538
- const hour = index + 1;
539
- const hour24 = hour24From12(hour, meridiem);
540
- return {
541
- value: hour,
542
- label: String(hour),
543
- // Keys step in time order: 12 PM comes before 1 PM.
544
- order: hour24,
545
- isDisabled: !rangeOverlaps(hour24 * 3600, hour24 * 3600 + 3599, timeBounds.min, timeBounds.max)
546
- };
547
- });
548
- }, [hourFormat, parsedWheelTime.hour, timeBounds.min, timeBounds.max]);
549
- const minuteOptions = useMemo(() => Array.from({
550
- length: 60
551
- }, (_, minute) => {
552
- const start = parsedWheelTime.hour * 3600 + minute * 60;
553
- return {
554
- value: minute,
555
- label: twoDigits(minute),
556
- isDisabled: !rangeOverlaps(start, start + (hasSeconds ? 59 : 0), timeBounds.min, timeBounds.max)
557
- };
558
- }), [hasSeconds, parsedWheelTime.hour, timeBounds.min, timeBounds.max]);
559
- const secondOptions = useMemo(() => Array.from({
560
- length: 60
561
- }, (_, second) => ({
562
- value: second,
563
- label: twoDigits(second),
564
- isDisabled: !isTimeInRange(formatISOTime({
565
- hour: parsedWheelTime.hour,
566
- minute: parsedWheelTime.minute,
567
- second
568
- }, true), timeBounds.min, timeBounds.max)
569
- })), [parsedWheelTime.hour, parsedWheelTime.minute, timeBounds.min, timeBounds.max]);
570
- const meridiemOptions = useMemo(() => [{
571
- value: 0,
572
- label: t('@astryx.dateTimeInput.meridiemAM'),
573
- isDisabled: !rangeOverlaps(0, 11 * 3600 + 3599, timeBounds.min, timeBounds.max)
574
- }, {
575
- value: 1,
576
- label: t('@astryx.dateTimeInput.meridiemPM'),
577
- isDisabled: !rangeOverlaps(12 * 3600, 23 * 3600 + 3599, timeBounds.min, timeBounds.max)
578
- }], [t, timeBounds.min, timeBounds.max]);
504
+ const bounds = useMemo(() => wheelBounds(timeBounds.min, timeBounds.max), [timeBounds.min, timeBounds.max]);
505
+ const hourOptions = useMemo(() => hourRowsInHalf(parsedWheelTime.hour, hourFormat, bounds), [bounds, hourFormat, parsedWheelTime.hour]);
506
+ const minuteOptions = useMemo(() => minuteRows(parsedWheelTime.hour, hasSeconds, bounds), [bounds, hasSeconds, parsedWheelTime.hour]);
507
+ const secondOptions = useMemo(() => secondRows(parsedWheelTime.hour, parsedWheelTime.minute, bounds), [bounds, parsedWheelTime.hour, parsedWheelTime.minute]);
508
+ const meridiemOptions = useMemo(() => meridiemRows({
509
+ am: t('@astryx.dateTimeInput.meridiemAM'),
510
+ pm: t('@astryx.dateTimeInput.meridiemPM')
511
+ }, bounds), [bounds, t]);
579
512
  const handleVisibleMonthChange = useCallback(next => {
580
513
  if (activePanel === 'date' && !isWheelOpen) {
581
514
  setMonthIndex(next);
@@ -853,45 +786,55 @@ export function TouchDateTimeField({
853
786
  className: "x15r89dc x78zum5 xh8yej3 xeuugli xdt5ytf x1txdalj xlshs6z xg01cxk x47corl"
854
787
  }
855
788
  }[!!(activePanel !== 'time') << 0],
856
- children: [/*#__PURE__*/_jsxs("div", {
789
+ children: [/*#__PURE__*/_jsx("div", {
857
790
  ...{
858
791
  className: "x78zum5 xh8yej3 xeuugli xm8gem x1txdalj"
859
792
  },
860
- children: [/*#__PURE__*/_jsx(Wheel, {
861
- label: t('@astryx.dateTimeInput.hourWheel'),
862
- options: hourOptions,
863
- value: hourFormat === '24h' ? parsedWheelTime.hour : hour12From24(parsedWheelTime.hour),
864
- isActive: activePanel === 'time',
865
- onChange: hour => commitWheelTime(hourFormat === '24h' ? composeWheelTime({
866
- hour24: hour
867
- }) : composeWheelTime({
868
- hour12: hour
869
- }))
870
- }), /*#__PURE__*/_jsx(Wheel, {
871
- label: t('@astryx.dateTimeInput.minuteWheel'),
872
- options: minuteOptions,
873
- value: parsedWheelTime.minute,
793
+ children: isTouch ? /*#__PURE__*/_jsx(TimeWheels, {
794
+ time: parsedWheelTime,
795
+ hourFormat: hourFormat,
796
+ hasSeconds: hasSeconds,
797
+ min: timeBounds.min,
798
+ max: timeBounds.max,
874
799
  isActive: activePanel === 'time',
875
- onChange: minute => commitWheelTime(composeWheelTime({
876
- minute
877
- }))
878
- }), hasSeconds && /*#__PURE__*/_jsx(Wheel, {
879
- label: t('@astryx.dateTimeInput.secondWheel'),
880
- options: secondOptions,
881
- value: parsedWheelTime.second,
882
- isActive: activePanel === 'time',
883
- onChange: second => commitWheelTime(composeWheelTime({
884
- second
885
- }))
886
- }), hourFormat === '12h' && /*#__PURE__*/_jsx(Wheel, {
887
- label: t('@astryx.dateTimeInput.meridiemWheel'),
888
- options: meridiemOptions,
889
- value: parsedWheelTime.hour < 12 ? 0 : 1,
890
- isActive: activePanel === 'time',
891
- onChange: meridiem => commitWheelTime(composeWheelTime({
892
- meridiem
893
- }))
894
- })]
800
+ onCommit: time => commitWheelTime(formatISOTime(time, hasSeconds))
801
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
802
+ children: [/*#__PURE__*/_jsx(Wheel, {
803
+ label: t('@astryx.dateTimeInput.hourWheel'),
804
+ options: hourOptions,
805
+ value: hourFormat === '24h' ? parsedWheelTime.hour : hour12From24(parsedWheelTime.hour),
806
+ isActive: activePanel === 'time',
807
+ onChange: hour => commitWheelTime(hourFormat === '24h' ? composeWheelTime({
808
+ hour24: hour
809
+ }) : composeWheelTime({
810
+ hour12: hour
811
+ }))
812
+ }), /*#__PURE__*/_jsx(Wheel, {
813
+ label: t('@astryx.dateTimeInput.minuteWheel'),
814
+ options: minuteOptions,
815
+ value: parsedWheelTime.minute,
816
+ isActive: activePanel === 'time',
817
+ onChange: minute => commitWheelTime(composeWheelTime({
818
+ minute
819
+ }))
820
+ }), hasSeconds && /*#__PURE__*/_jsx(Wheel, {
821
+ label: t('@astryx.dateTimeInput.secondWheel'),
822
+ options: secondOptions,
823
+ value: parsedWheelTime.second,
824
+ isActive: activePanel === 'time',
825
+ onChange: second => commitWheelTime(composeWheelTime({
826
+ second
827
+ }))
828
+ }), hourFormat === '12h' && /*#__PURE__*/_jsx(Wheel, {
829
+ label: t('@astryx.dateTimeInput.meridiemWheel'),
830
+ options: meridiemOptions,
831
+ value: parsedWheelTime.hour < 12 ? 0 : 1,
832
+ isActive: activePanel === 'time',
833
+ onChange: meridiem => commitWheelTime(composeWheelTime({
834
+ meridiem
835
+ }))
836
+ })]
837
+ })
895
838
  }), /*#__PURE__*/_jsx("div", {
896
839
  ...{
897
840
  className: "x78zum5 xr1yuqi xfsso4q"
@@ -0,0 +1,32 @@
1
+ import type { ISOTimeString } from '../utils/timeParser.js';
2
+ import { type TimeParts } from './timeWheelRules.js';
3
+ export interface TimeWheelsProps {
4
+ /** The time the wheels show. */
5
+ time: TimeParts;
6
+ /** 12-hour (with an AM/PM column) or 24-hour time. */
7
+ hourFormat: '12h' | '24h';
8
+ /** Whether a seconds column shows. */
9
+ hasSeconds: boolean;
10
+ /** Earliest time that may commit. */
11
+ min?: ISOTimeString;
12
+ /** Latest time that may commit. */
13
+ max?: ISOTimeString;
14
+ /** False while the wheels are hidden. */
15
+ isActive: boolean;
16
+ /** Called with the committed time, already inside the bounds. */
17
+ onCommit: (time: TimeParts) => void;
18
+ }
19
+ /**
20
+ * UIDatePicker's time wheels.
21
+ *
22
+ * @example
23
+ * ```
24
+ * <TimeWheels time={{hour: 11, minute: 58, second: 0}} hourFormat="12h"
25
+ * hasSeconds={false} isActive onCommit={setTime} />
26
+ * ```
27
+ */
28
+ export declare function TimeWheels({ time, hourFormat, hasSeconds, min, max, isActive, onCommit, }: TimeWheelsProps): import("react").JSX.Element;
29
+ export declare namespace TimeWheels {
30
+ var displayName: string;
31
+ }
32
+ //# sourceMappingURL=TimeWheels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeWheels.d.ts","sourceRoot":"","sources":["../../src/TimeInput/TimeWheels.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAaL,KAAK,SAAS,EAEf,MAAM,kBAAkB,CAAC;AAS1B,MAAM,WAAW,eAAe;IAC9B,gCAAgC;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,sDAAsD;IACtD,UAAU,EAAE,KAAK,GAAG,KAAK,CAAC;IAC1B,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,qCAAqC;IACrC,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,mCAAmC;IACnC,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,iEAAiE;IACjE,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACrC;AAMD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,GACT,EAAE,eAAe,+BAoIjB;yBA5Ie,UAAU"}