@terreno/ui 56.0.0-beta.0 → 56.0.0-beta.2

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/src/Box.test.tsx CHANGED
@@ -1,13 +1,18 @@
1
- // noExplicitAny: test mock typing
2
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
1
  import {describe, expect, it, mock, spyOn} from "bun:test";
4
2
  import {act, fireEvent} from "@testing-library/react-native";
5
3
  import React from "react";
4
+ import type {ScrollView} from "react-native";
6
5
 
7
6
  import {Box} from "./Box";
8
7
  import {Text} from "./Text";
9
8
  import {renderWithTheme} from "./test-utils";
10
9
 
10
+ /** Imperative handle exposed by Box's forwarded ref. */
11
+ interface BoxScrollHandle {
12
+ scrollTo: (y: number) => void;
13
+ scrollToEnd: () => void;
14
+ }
15
+
11
16
  describe("Box", () => {
12
17
  describe("basic rendering", () => {
13
18
  it("should render with default props", () => {
@@ -507,14 +512,15 @@ describe("Box", () => {
507
512
  // values: a ref object in style is cyclical (host instance points back at the
508
513
  // node) and gets dev-frozen, so React throws when detaching it on unmount.
509
514
  it("should keep behavior props out of the ScrollView style", () => {
510
- const scrollRef = React.createRef<any>();
515
+ const scrollRef = React.createRef<ScrollView>();
511
516
  const {root} = renderWithTheme(
512
517
  <Box onScroll={mock(() => {})} scroll scrollRef={scrollRef}>
513
518
  <Text>Scrollable</Text>
514
519
  </Box>
515
520
  );
516
521
 
517
- const scrollView = root.findByType("ScrollView" as any);
522
+ // RN Testing Library resolves host ScrollView by display name, not the JS class.
523
+ const scrollView = root.findByType("ScrollView");
518
524
  expect(scrollView.props.style).not.toHaveProperty("scrollRef");
519
525
  expect(scrollView.props.style).not.toHaveProperty("scroll");
520
526
  expect(scrollView.props.style).not.toHaveProperty("onScroll");
@@ -578,7 +584,7 @@ describe("Box", () => {
578
584
 
579
585
  describe("ref forwarding", () => {
580
586
  it("should expose scrollToEnd method", () => {
581
- const ref = React.createRef<any>();
587
+ const ref = React.createRef<BoxScrollHandle>();
582
588
  renderWithTheme(<Box ref={ref} scroll />);
583
589
 
584
590
  expect(ref.current).toBeTruthy();
@@ -586,7 +592,7 @@ describe("Box", () => {
586
592
  });
587
593
 
588
594
  it("should expose scrollTo method", () => {
589
- const ref = React.createRef<any>();
595
+ const ref = React.createRef<BoxScrollHandle>();
590
596
  renderWithTheme(<Box ref={ref} scroll />);
591
597
 
592
598
  expect(ref.current).toBeTruthy();
@@ -596,8 +602,10 @@ describe("Box", () => {
596
602
  it("scrollTo forwards to the underlying scroll ref after the delay", async () => {
597
603
  const scrollTo = mock(() => {});
598
604
  const scrollToEnd = mock(() => {});
599
- const scrollRef = {current: {scrollTo, scrollToEnd}} as any;
600
- const ref = React.createRef<any>();
605
+ const scrollRef = {
606
+ current: {scrollTo, scrollToEnd},
607
+ } as unknown as React.RefObject<ScrollView>;
608
+ const ref = React.createRef<BoxScrollHandle>();
601
609
  // Intentionally omit `scroll` so the ScrollView does not claim `scrollRef`
602
610
  // and overwrite `.current`; the imperative handle still reads it.
603
611
  renderWithTheme(
@@ -723,54 +731,54 @@ describe("Box", () => {
723
731
 
724
732
  describe("edge case warnings and fallbacks", () => {
725
733
  it("returns empty style when border prop is falsy", () => {
726
- const {root} = renderWithTheme(<Box border={undefined as any} />);
734
+ const {root} = renderWithTheme(<Box border={undefined} />);
727
735
  expect(root).toBeTruthy();
728
736
  });
729
737
 
730
738
  it("returns empty style when borderBottom prop is falsy", () => {
731
- const {root} = renderWithTheme(<Box borderBottom={undefined as any} />);
739
+ const {root} = renderWithTheme(<Box borderBottom={undefined} />);
732
740
  expect(root).toBeTruthy();
733
741
  });
734
742
 
735
743
  it("returns empty style when borderLeft prop is falsy", () => {
736
- const {root} = renderWithTheme(<Box borderLeft={undefined as any} />);
744
+ const {root} = renderWithTheme(<Box borderLeft={undefined} />);
737
745
  expect(root).toBeTruthy();
738
746
  });
739
747
 
740
748
  it("returns empty style when borderRight prop is falsy", () => {
741
- const {root} = renderWithTheme(<Box borderRight={undefined as any} />);
749
+ const {root} = renderWithTheme(<Box borderRight={undefined} />);
742
750
  expect(root).toBeTruthy();
743
751
  });
744
752
 
745
753
  it("returns empty style when borderTop prop is falsy", () => {
746
- const {root} = renderWithTheme(<Box borderTop={undefined as any} />);
754
+ const {root} = renderWithTheme(<Box borderTop={undefined} />);
747
755
  expect(root).toBeTruthy();
748
756
  });
749
757
 
750
758
  it("warns when invalid height value is provided", () => {
751
759
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
752
- renderWithTheme(<Box height={"abc" as any} />);
760
+ renderWithTheme(<Box height={"abc"} />);
753
761
  expect(warnSpy).toHaveBeenCalled();
754
762
  warnSpy.mockRestore();
755
763
  });
756
764
 
757
765
  it("warns when invalid maxHeight value is provided", () => {
758
766
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
759
- renderWithTheme(<Box maxHeight={"xyz" as any} />);
767
+ renderWithTheme(<Box maxHeight={"xyz"} />);
760
768
  expect(warnSpy).toHaveBeenCalled();
761
769
  warnSpy.mockRestore();
762
770
  });
763
771
 
764
772
  it("warns when invalid maxWidth value is provided", () => {
765
773
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
766
- renderWithTheme(<Box maxWidth={"abc" as any} />);
774
+ renderWithTheme(<Box maxWidth={"abc"} />);
767
775
  expect(warnSpy).toHaveBeenCalled();
768
776
  warnSpy.mockRestore();
769
777
  });
770
778
 
771
779
  it("warns when invalid minHeight value is provided", () => {
772
780
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
773
- renderWithTheme(<Box minHeight={"abc" as any} />);
781
+ renderWithTheme(<Box minHeight={"abc"} />);
774
782
  expect(warnSpy).toHaveBeenCalled();
775
783
  warnSpy.mockRestore();
776
784
  });
@@ -782,7 +790,7 @@ describe("Box", () => {
782
790
  });
783
791
 
784
792
  it("applies a valid minHeight value", () => {
785
- const {root} = renderWithTheme(<Box minHeight={"50%" as any} />);
793
+ const {root} = renderWithTheme(<Box minHeight={"50%"} />);
786
794
  const view = root.findByType("View");
787
795
  expect(view.props.style).toMatchObject({minHeight: "50%"});
788
796
  });
@@ -794,21 +802,21 @@ describe("Box", () => {
794
802
  });
795
803
 
796
804
  it("applies a valid minWidth value", () => {
797
- const {root} = renderWithTheme(<Box minWidth={"25%" as any} />);
805
+ const {root} = renderWithTheme(<Box minWidth={"25%"} />);
798
806
  const view = root.findByType("View");
799
807
  expect(view.props.style).toMatchObject({minWidth: "25%"});
800
808
  });
801
809
 
802
810
  it("warns when invalid minWidth value is provided", () => {
803
811
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
804
- renderWithTheme(<Box minWidth={"abc" as any} />);
812
+ renderWithTheme(<Box minWidth={"abc"} />);
805
813
  expect(warnSpy).toHaveBeenCalled();
806
814
  warnSpy.mockRestore();
807
815
  });
808
816
 
809
817
  it("warns when invalid width value is provided", () => {
810
818
  const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
811
- renderWithTheme(<Box width={"abc" as any} />);
819
+ renderWithTheme(<Box width={"abc"} />);
812
820
  expect(warnSpy).toHaveBeenCalled();
813
821
  warnSpy.mockRestore();
814
822
  });
@@ -911,7 +919,7 @@ describe("Box", () => {
911
919
  <Text>Scrollable</Text>
912
920
  </Box>
913
921
  );
914
- const scrollView = root.findByType("ScrollView" as any);
922
+ const scrollView = root.findByType("ScrollView");
915
923
  await act(async () => {
916
924
  scrollView.props.onScroll?.({nativeEvent: {contentOffset: {y: 100}}});
917
925
  });
@@ -938,7 +946,7 @@ describe("Box", () => {
938
946
  });
939
947
 
940
948
  it("exposes scrollTo and scrollToEnd through ref", () => {
941
- const ref = React.createRef<any>();
949
+ const ref = React.createRef<BoxScrollHandle>();
942
950
  renderWithTheme(
943
951
  <Box ref={ref} scroll>
944
952
  <Text>Content</Text>
package/src/Common.ts CHANGED
@@ -219,6 +219,7 @@ export interface TextThemeConfig {
219
219
  export interface SurfaceThemeConfig {
220
220
  base: keyof ThemePrimitiveColors;
221
221
  primary: keyof ThemePrimitiveColors;
222
+ secondaryExtraLight: keyof ThemePrimitiveColors;
222
223
  secondaryLight: keyof ThemePrimitiveColors;
223
224
  secondaryDark: keyof ThemePrimitiveColors;
224
225
  secondaryExtraDark: keyof ThemePrimitiveColors;
@@ -287,6 +288,7 @@ export interface TextTheme {
287
288
  export interface SurfaceTheme {
288
289
  base: string;
289
290
  primary: string;
291
+ secondaryExtraLight: string;
290
292
  secondaryLight: string;
291
293
  secondaryDark: string;
292
294
  secondaryExtraDark: string;
@@ -692,6 +694,51 @@ export type CardProps = BoxProps & {
692
694
  imageHeight?: number;
693
695
  };
694
696
 
697
+ export type EditableCardProps = BoxProps & {
698
+ /**
699
+ * The name of an icon shown before the title.
700
+ */
701
+ iconName?: IconName;
702
+
703
+ /**
704
+ * The title of the summarized information.
705
+ */
706
+ title?: string;
707
+
708
+ /**
709
+ * Props for a badge rendered next to the title.
710
+ */
711
+ badge?: BadgeProps;
712
+
713
+ /**
714
+ * The summarized information itself, displayed below the title.
715
+ */
716
+ description?: string;
717
+
718
+ /**
719
+ * Secondary text displayed below the description, in a muted style.
720
+ */
721
+ helperText?: string;
722
+
723
+ /**
724
+ * Callback invoked when the edit button is pressed. The edit button is only rendered when this
725
+ * is provided.
726
+ */
727
+ onEdit?: () => void | Promise<void>;
728
+
729
+ /**
730
+ * Accessibility label for the edit button.
731
+ * @default "Edit"
732
+ */
733
+ editAccessibilityLabel?: string;
734
+
735
+ /**
736
+ * If true, the card is highlighted to draw attention to it, e.g. for content that needs review.
737
+ * @default false
738
+ */
739
+ attention?: boolean;
740
+ };
741
+
695
742
  export interface ErrorBoundaryProps {
696
743
  onError?: (error: Error, stack: string) => void;
697
744
  children?: ReactNode;
@@ -351,6 +351,28 @@ describe("ConsentFormScreen", () => {
351
351
  expect(queryByTestId("consent-footer-checkboxes-hint")).toBeNull();
352
352
  });
353
353
 
354
+ it("toggles scrolling with the signature touch handlers on iOS", () => {
355
+ const form: ConsentFormPublic = {
356
+ ...baseForm,
357
+ captureSignature: true,
358
+ };
359
+ const {getByTestId} = renderWithTheme(
360
+ <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
361
+ );
362
+ const signature = getByTestId("consent-form-signature");
363
+ const scroll = getByTestId("consent-form-scroll-view");
364
+
365
+ act(() => {
366
+ fireEvent(signature, "touchStart");
367
+ });
368
+ expect(scroll.props.scrollEnabled).toBe(false);
369
+
370
+ act(() => {
371
+ fireEvent(signature, "touchEnd");
372
+ });
373
+ expect(scroll.props.scrollEnabled).toBe(true);
374
+ });
375
+
354
376
  it("exercises SignatureField onChange, onStart, and onEnd callbacks", () => {
355
377
  const form: ConsentFormPublic = {
356
378
  ...baseForm,
@@ -1,5 +1,3 @@
1
- // noExplicitAny: test mock typing
2
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
1
  import {describe, expect, it, mock} from "bun:test";
4
2
  import React from "react";
5
3
  import {Pressable} from "react-native";
@@ -186,7 +184,7 @@ describe("ConsentNavigator", () => {
186
184
  };
187
185
 
188
186
  const {getByText} = renderWithTheme(
189
- <ConsentNavigator api={api as any}>
187
+ <ConsentNavigator api={api}>
190
188
  <Text>App Content</Text>
191
189
  </ConsentNavigator>
192
190
  );
@@ -212,7 +210,7 @@ describe("ConsentNavigator", () => {
212
210
  };
213
211
 
214
212
  const {getByText} = renderWithTheme(
215
- <ConsentNavigator api={api as any}>
213
+ <ConsentNavigator api={api}>
216
214
  <Text>App Content</Text>
217
215
  </ConsentNavigator>
218
216
  );
@@ -239,7 +237,7 @@ describe("ConsentNavigator", () => {
239
237
  };
240
238
 
241
239
  const {getByTestId, getByText} = renderWithTheme(
242
- <ConsentNavigator api={api as any} onError={onError}>
240
+ <ConsentNavigator api={api} onError={onError}>
243
241
  <Text>App Content</Text>
244
242
  </ConsentNavigator>
245
243
  );
@@ -284,7 +282,7 @@ describe("ConsentNavigator", () => {
284
282
  };
285
283
 
286
284
  const {getByTestId} = renderWithTheme(
287
- <ConsentNavigator api={api as any}>
285
+ <ConsentNavigator api={api}>
288
286
  <Text>App Content</Text>
289
287
  </ConsentNavigator>
290
288
  );
@@ -321,7 +319,7 @@ describe("ConsentNavigator", () => {
321
319
  };
322
320
 
323
321
  const {getByTestId} = renderWithTheme(
324
- <ConsentNavigator api={api as any} onError={onError}>
322
+ <ConsentNavigator api={api} onError={onError}>
325
323
  <Text>App Content</Text>
326
324
  </ConsentNavigator>
327
325
  );
@@ -361,7 +359,7 @@ describe("ConsentNavigator", () => {
361
359
  };
362
360
 
363
361
  const {getByTestId} = renderWithTheme(
364
- <ConsentNavigator api={api as any}>
362
+ <ConsentNavigator api={api}>
365
363
  <Text>App Content</Text>
366
364
  </ConsentNavigator>
367
365
  );
@@ -11,7 +11,9 @@ import {
11
11
  mock,
12
12
  } from "bun:test";
13
13
  import {act, userEvent} from "@testing-library/react-native";
14
+ import {assert} from "chai";
14
15
  import {DateTime} from "luxon";
16
+ import type {ReactTestInstance} from "react-test-renderer";
15
17
 
16
18
  import {DateTimeField} from "./DateTimeField";
17
19
  import {renderWithTheme, setupComponentTest, teardownComponentTest} from "./test-utils";
@@ -1310,6 +1312,40 @@ describe("DateTimeField", () => {
1310
1312
  });
1311
1313
  });
1312
1314
 
1315
+ describe("TimezonePicker onChange", () => {
1316
+ it("forwards the picked timezone to onTimezoneChange and emits a new value", async () => {
1317
+ setDesktop();
1318
+ const mockTzChange = mock(() => {});
1319
+ const {UNSAFE_root} = renderWithTheme(
1320
+ <DateTimeField
1321
+ onChange={mockOnChange}
1322
+ onTimezoneChange={mockTzChange}
1323
+ timezone="America/New_York"
1324
+ type="time"
1325
+ value="2023-05-15T15:30:00.000Z"
1326
+ />
1327
+ );
1328
+
1329
+ // Select the rendered TimezonePicker itself rather than any ancestor that happens to
1330
+ // have an onTimezoneChange prop, so the component's own handler runs.
1331
+ const pickers = UNSAFE_root.findAll((node: ReactTestInstance) =>
1332
+ Boolean((node.props as {shortTimezone?: boolean}).shortTimezone)
1333
+ );
1334
+ assert.isAbove(pickers.length, 0);
1335
+ await act(async () => {
1336
+ pickers[0].props.onChange("America/Chicago");
1337
+ });
1338
+
1339
+ assert.isTrue(mockTzChange.mock.calls.some((call) => call[0] === "America/Chicago"));
1340
+ // The picked timezone is applied to the current segments and emitted.
1341
+ assert.isAbove(mockOnChange.mock.calls.length, 0);
1342
+ assert.equal(
1343
+ mockOnChange.mock.calls[mockOnChange.mock.calls.length - 1][0],
1344
+ "2023-05-15T16:30:00.000Z"
1345
+ );
1346
+ });
1347
+ });
1348
+
1313
1349
  describe("minute validation in validateField", () => {
1314
1350
  it("should validate minute field for datetime type via hour change triggering revalidation", async () => {
1315
1351
  setDesktop();
@@ -1332,4 +1368,18 @@ describe("DateTimeField", () => {
1332
1368
  expect(hourInput).toBeTruthy();
1333
1369
  });
1334
1370
  });
1371
+
1372
+ describe("timezone abbreviation", () => {
1373
+ it("falls back to the current time when there is no value and no complete segments", () => {
1374
+ setMobile();
1375
+ const {getByText} = renderWithTheme(
1376
+ <DateTimeField onChange={mockOnChange} timezone="America/New_York" type="time" value="" />
1377
+ );
1378
+
1379
+ const expectedAbbr = DateTime.now().setZone("America/New_York").offsetNameShort ?? "";
1380
+ assert.isNotEmpty(expectedAbbr);
1381
+ // With no value the placeholder is built from the current time in the given timezone.
1382
+ assert.isTrue(Boolean(getByText(`12:00 PM ${expectedAbbr}`)));
1383
+ });
1384
+ });
1335
1385
  });
@@ -3,6 +3,7 @@ import {DateTime} from "luxon";
3
3
  import React, {type FC, useCallback, useEffect, useMemo, useRef, useState} from "react";
4
4
  import {Pressable, TextInput, View} from "react-native";
5
5
 
6
+ import type {ActionSheet} from "./ActionSheet";
6
7
  import {Box} from "./Box";
7
8
  import type {DateTimeFieldProps} from "./Common";
8
9
  import {DateTimeActionSheet} from "./DateTimeActionSheet";
@@ -424,9 +425,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
424
425
  }): React.ReactElement => {
425
426
  const {theme} = useTheme();
426
427
  const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
427
- // noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
428
- // biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
429
- const dateActionSheetRef: React.RefObject<any> = React.createRef();
428
+ const dateActionSheetRef: React.RefObject<ActionSheet | null> = React.createRef();
430
429
  const [amPm, setAmPm] = useState<"am" | "pm">("am");
431
430
  const [showDate, setShowDate] = useState(false);
432
431
  const [month, setMonth] = useState("");
@@ -532,6 +531,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
532
531
  }
533
532
  }
534
533
 
534
+ // Minutes are not validated here: handleFieldChange validates them before this is reached.
535
535
  if (type === "time" || type === "datetime") {
536
536
  if (fieldIndex === (type === "time" ? 0 : 3)) {
537
537
  // Hour
@@ -539,12 +539,6 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
539
539
  if (Number.isNaN(hourNum) || hourNum < 1 || hourNum > 12) {
540
540
  return "Hour must be between 1 and 12";
541
541
  }
542
- } else if (fieldIndex === (type === "time" ? 1 : 4)) {
543
- // Minute
544
- const minuteNum = parseInt(fieldValue, 10);
545
- if (Number.isNaN(minuteNum) || minuteNum < 0 || minuteNum > 59) {
546
- return "Minute must be between 0 and 59";
547
- }
548
542
  }
549
543
  }
550
544
 
@@ -691,11 +685,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
691
685
  setFieldErrors((prev) => ({...prev, [index]: "Minute must be between 0 and 59"}));
692
686
  }
693
687
 
694
- // Auto-advance to next field if current field is full
695
- const configs = getFieldConfigs();
696
- if (finalValue.length === config.maxLength && index < configs.length - 1) {
697
- inputRefs.current[index + 1]?.focus();
698
- }
688
+ // The minute segment is always last, so there is nothing to advance focus to.
699
689
  return;
700
690
  }
701
691
 
@@ -811,11 +801,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
811
801
  .set({millisecond: 0, second: 0})
812
802
  .toISO()
813
803
  : parsedDate.set({millisecond: 0, second: 0}).toUTC().toISO();
814
- if (!normalized) {
815
- console.warn("Invalid date passed to DateTimeField", parsedDate);
816
- return;
817
- }
818
- onChange(normalized);
804
+ onChange(normalized ?? "");
819
805
  setShowDate(false);
820
806
  },
821
807
  [onChange, type]