@terreno/ui 0.22.2 → 0.23.1
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/README.md +27 -0
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.js.map +1 -1
- package/dist/BooleanField.js +6 -4
- package/dist/BooleanField.js.map +1 -1
- package/dist/Box.js +3 -2
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +4 -3
- package/dist/Button.js.map +1 -1
- package/dist/CheckBox.js +2 -2
- package/dist/CheckBox.js.map +1 -1
- package/dist/Common.d.ts +44 -56
- package/dist/Common.js +1 -0
- package/dist/Common.js.map +1 -1
- package/dist/CustomSelectField.js +5 -3
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DataTable.js +18 -12
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeField.js +5 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/IconButton.js +8 -4
- package/dist/IconButton.js.map +1 -1
- package/dist/Link.js +2 -2
- package/dist/Link.js.map +1 -1
- package/dist/MarkdownEditor.js +14 -2
- package/dist/MarkdownEditor.js.map +1 -1
- package/dist/MarkdownEditorField.js +18 -4
- package/dist/MarkdownEditorField.js.map +1 -1
- package/dist/Modal.js +10 -6
- package/dist/Modal.js.map +1 -1
- package/dist/MultiselectField.js +5 -3
- package/dist/MultiselectField.js.map +1 -1
- package/dist/Page.js +1 -1
- package/dist/Page.js.map +1 -1
- package/dist/Pagination.js +2 -2
- package/dist/Pagination.js.map +1 -1
- package/dist/SegmentedControl.js +5 -3
- package/dist/SegmentedControl.js.map +1 -1
- package/dist/SelectField.js +5 -3
- package/dist/SelectField.js.map +1 -1
- package/dist/SocialLoginButton.js +2 -1
- package/dist/SocialLoginButton.js.map +1 -1
- package/dist/Spinner.js +3 -2
- package/dist/Spinner.js.map +1 -1
- package/dist/TextField.js +6 -4
- package/dist/TextField.js.map +1 -1
- package/dist/fieldElements/FieldError.d.ts +1 -0
- package/dist/fieldElements/FieldError.js +3 -2
- package/dist/fieldElements/FieldError.js.map +1 -1
- package/dist/fieldElements/FieldHelperText.d.ts +1 -0
- package/dist/fieldElements/FieldHelperText.js +3 -2
- package/dist/fieldElements/FieldHelperText.js.map +1 -1
- package/dist/fieldElements/FieldTitle.d.ts +1 -0
- package/dist/fieldElements/FieldTitle.js +4 -3
- package/dist/fieldElements/FieldTitle.js.map +1 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/resolveTestId.d.ts +39 -0
- package/dist/testing/resolveTestId.js +97 -0
- package/dist/testing/resolveTestId.js.map +1 -0
- package/dist/testing/types.d.ts +59 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/package.json +2 -2
- package/src/Accordion.tsx +3 -1
- package/src/BooleanField.tsx +13 -3
- package/src/Box.tsx +3 -2
- package/src/Button.test.tsx +31 -1
- package/src/Button.tsx +5 -4
- package/src/CheckBox.tsx +7 -1
- package/src/Common.ts +66 -58
- package/src/CustomSelectField.tsx +8 -1
- package/src/DataTable.tsx +40 -3
- package/src/DateTimeField.tsx +10 -3
- package/src/ErrorBoundary.test.tsx +3 -4
- package/src/IconButton.test.tsx +14 -0
- package/src/IconButton.tsx +9 -4
- package/src/Link.tsx +2 -1
- package/src/MarkdownEditor.tsx +52 -27
- package/src/MarkdownEditorField.tsx +37 -16
- package/src/Modal.tsx +13 -0
- package/src/MultiselectField.tsx +8 -3
- package/src/Page.tsx +1 -0
- package/src/Pagination.tsx +2 -1
- package/src/SegmentedControl.tsx +15 -2
- package/src/SelectField.tsx +8 -3
- package/src/SocialLoginButton.tsx +2 -1
- package/src/Spinner.tsx +3 -2
- package/src/TextField.tsx +8 -5
- package/src/__snapshots__/AddressField.test.tsx.snap +4 -0
- package/src/__snapshots__/BooleanField.test.tsx.snap +4 -0
- package/src/__snapshots__/Button.test.tsx.snap +18 -1
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +2 -0
- package/src/__snapshots__/ErrorPage.test.tsx.snap +1 -0
- package/src/__snapshots__/Field.test.tsx.snap +8 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +2 -0
- package/src/__snapshots__/HeightField.test.tsx.snap +5 -0
- package/src/__snapshots__/IconButton.test.tsx.snap +4 -0
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +4 -0
- package/src/__snapshots__/Link.test.tsx.snap +1 -0
- package/src/__snapshots__/Modal.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +2 -0
- package/src/__snapshots__/Page.test.tsx.snap +22 -0
- package/src/__snapshots__/SegmentedControl.test.tsx.snap +4 -0
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +1 -0
- package/src/fieldElements/FieldError.tsx +7 -2
- package/src/fieldElements/FieldHelperText.tsx +4 -2
- package/src/fieldElements/FieldTitle.tsx +4 -1
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +7 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +7 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/resolveTestId.test.ts +231 -0
- package/src/testing/resolveTestId.ts +142 -0
- package/src/testing/types.ts +67 -0
package/src/DataTable.tsx
CHANGED
|
@@ -27,6 +27,11 @@ import {Pagination} from "./Pagination";
|
|
|
27
27
|
import {Text} from "./Text";
|
|
28
28
|
import {useTheme} from "./Theme";
|
|
29
29
|
import {TableTitle} from "./table/TableTitle";
|
|
30
|
+
import {
|
|
31
|
+
resolveDataTableRowTestID,
|
|
32
|
+
resolveDataTableTestIDsFromProps,
|
|
33
|
+
toTestProps,
|
|
34
|
+
} from "./testing/resolveTestId";
|
|
30
35
|
|
|
31
36
|
// TODO: Add permanent horizontal scroll bar so users with only a mouse can scroll left/right
|
|
32
37
|
// easily.
|
|
@@ -119,6 +124,7 @@ interface DataTableRowProps {
|
|
|
119
124
|
alternateRowBackground: boolean;
|
|
120
125
|
customColumnComponentMap?: DataTableCustomComponentMap;
|
|
121
126
|
rowHeight: number;
|
|
127
|
+
testID?: string;
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
const DataTableRow: FC<DataTableRowProps> = ({
|
|
@@ -130,6 +136,7 @@ const DataTableRow: FC<DataTableRowProps> = ({
|
|
|
130
136
|
alternateRowBackground,
|
|
131
137
|
customColumnComponentMap,
|
|
132
138
|
rowHeight,
|
|
139
|
+
testID,
|
|
133
140
|
}) => {
|
|
134
141
|
const {theme} = useTheme();
|
|
135
142
|
const backgroundColor =
|
|
@@ -143,6 +150,7 @@ const DataTableRow: FC<DataTableRowProps> = ({
|
|
|
143
150
|
flexDirection: "row",
|
|
144
151
|
height: rowHeight,
|
|
145
152
|
}}
|
|
153
|
+
{...toTestProps(testID)}
|
|
146
154
|
>
|
|
147
155
|
{rowData.map((cell, colIndex) => (
|
|
148
156
|
<DataTableCell
|
|
@@ -313,6 +321,7 @@ interface DataTableHeaderProps {
|
|
|
313
321
|
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>, isHeader: boolean) => void;
|
|
314
322
|
rowHeight: number;
|
|
315
323
|
headerHeight?: number;
|
|
324
|
+
testID?: string;
|
|
316
325
|
}
|
|
317
326
|
|
|
318
327
|
const DataTableHeader: FC<DataTableHeaderProps> = ({
|
|
@@ -326,11 +335,12 @@ const DataTableHeader: FC<DataTableHeaderProps> = ({
|
|
|
326
335
|
onScroll,
|
|
327
336
|
rowHeight,
|
|
328
337
|
headerHeight,
|
|
338
|
+
testID,
|
|
329
339
|
}) => {
|
|
330
340
|
const {theme} = useTheme();
|
|
331
341
|
|
|
332
342
|
return (
|
|
333
|
-
<View style={{flexDirection: "row", position: "relative"}}>
|
|
343
|
+
<View style={{flexDirection: "row", position: "relative"}} testID={testID}>
|
|
334
344
|
{/* Fixed-width container for "more" content button if present */}
|
|
335
345
|
{hasMoreContent && (
|
|
336
346
|
<View
|
|
@@ -422,6 +432,8 @@ interface DataTableContentProps {
|
|
|
422
432
|
moreContentSize?: "sm" | "md" | "lg";
|
|
423
433
|
customColumnComponentMap?: DataTableCustomComponentMap;
|
|
424
434
|
rowHeight: number;
|
|
435
|
+
rowTestIdBase?: string;
|
|
436
|
+
getRowTestID?: (row: DataTableCellData[], rowIndex: number) => string | number;
|
|
425
437
|
}
|
|
426
438
|
|
|
427
439
|
const DataTableContent: FC<DataTableContentProps> = ({
|
|
@@ -437,10 +449,17 @@ const DataTableContent: FC<DataTableContentProps> = ({
|
|
|
437
449
|
moreContentExtraData,
|
|
438
450
|
moreContentSize = "md",
|
|
439
451
|
rowHeight,
|
|
452
|
+
rowTestIdBase,
|
|
453
|
+
getRowTestID,
|
|
440
454
|
}) => {
|
|
441
455
|
const [modalRow, setModalRow] = useState<number | null>(null);
|
|
442
456
|
const {theme} = useTheme();
|
|
443
457
|
|
|
458
|
+
const resolveRowTestId = (row: DataTableCellData[], rowIndex: number): string | undefined => {
|
|
459
|
+
const rowKey = getRowTestID ? getRowTestID(row, rowIndex) : rowIndex;
|
|
460
|
+
return resolveDataTableRowTestID(rowTestIdBase, rowKey);
|
|
461
|
+
};
|
|
462
|
+
|
|
444
463
|
return (
|
|
445
464
|
<>
|
|
446
465
|
<ScrollView style={{flex: 1}}>
|
|
@@ -496,6 +515,7 @@ const DataTableContent: FC<DataTableContentProps> = ({
|
|
|
496
515
|
rowData={row.slice(0, pinnedColumns)}
|
|
497
516
|
rowHeight={rowHeight}
|
|
498
517
|
rowIndex={rowIndex}
|
|
518
|
+
testID={pinnedColumns > 0 ? resolveRowTestId(row, rowIndex) : undefined}
|
|
499
519
|
/>
|
|
500
520
|
))}
|
|
501
521
|
</View>
|
|
@@ -527,6 +547,7 @@ const DataTableContent: FC<DataTableContentProps> = ({
|
|
|
527
547
|
rowData={row.slice(pinnedColumns)}
|
|
528
548
|
rowHeight={rowHeight}
|
|
529
549
|
rowIndex={rowIndex}
|
|
550
|
+
testID={pinnedColumns === 0 ? resolveRowTestId(row, rowIndex) : undefined}
|
|
530
551
|
/>
|
|
531
552
|
))}
|
|
532
553
|
</View>
|
|
@@ -568,8 +589,12 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
568
589
|
rowHeight = 54,
|
|
569
590
|
headerHeight,
|
|
570
591
|
defaultTextSize = "md",
|
|
592
|
+
testID,
|
|
593
|
+
testIDs,
|
|
594
|
+
getRowTestID,
|
|
571
595
|
}) => {
|
|
572
596
|
const {theme} = useTheme();
|
|
597
|
+
const tableTestIDs = resolveDataTableTestIDsFromProps({testID, testIDs});
|
|
573
598
|
const headerScrollRef = useRef<ScrollView>(null);
|
|
574
599
|
const bodyScrollRef = useRef<ScrollView>(null);
|
|
575
600
|
|
|
@@ -622,7 +647,10 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
622
647
|
}, [data, defaultTextSize]);
|
|
623
648
|
|
|
624
649
|
return (
|
|
625
|
-
<View
|
|
650
|
+
<View
|
|
651
|
+
style={{display: "flex", flexDirection: "column", height: "100%"}}
|
|
652
|
+
testID={tableTestIDs.root}
|
|
653
|
+
>
|
|
626
654
|
<View
|
|
627
655
|
style={{
|
|
628
656
|
borderColor: theme.border.default,
|
|
@@ -631,6 +659,7 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
631
659
|
height: "100%",
|
|
632
660
|
minHeight: 0,
|
|
633
661
|
}}
|
|
662
|
+
testID={tableTestIDs.body}
|
|
634
663
|
>
|
|
635
664
|
<DataTableHeader
|
|
636
665
|
columns={columns}
|
|
@@ -643,6 +672,7 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
643
672
|
pinnedColumns={pinnedColumns}
|
|
644
673
|
rowHeight={rowHeight}
|
|
645
674
|
sortColumn={sortColumn}
|
|
675
|
+
testID={tableTestIDs.header}
|
|
646
676
|
/>
|
|
647
677
|
|
|
648
678
|
<View style={{flex: 1, minHeight: 0}}>
|
|
@@ -653,11 +683,13 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
653
683
|
columnWidths={columnWidths}
|
|
654
684
|
customColumnComponentMap={customColumnComponentMap}
|
|
655
685
|
data={processedData}
|
|
686
|
+
getRowTestID={getRowTestID}
|
|
656
687
|
moreContentComponent={moreContentComponent}
|
|
657
688
|
moreContentExtraData={moreContentExtraData}
|
|
658
689
|
onScroll={handleScroll}
|
|
659
690
|
pinnedColumns={pinnedColumns}
|
|
660
691
|
rowHeight={rowHeight}
|
|
692
|
+
rowTestIdBase={tableTestIDs.row}
|
|
661
693
|
/>
|
|
662
694
|
</View>
|
|
663
695
|
</View>
|
|
@@ -670,7 +702,12 @@ export const DataTable: FC<DataTableProps> = ({
|
|
|
670
702
|
padding: 16,
|
|
671
703
|
}}
|
|
672
704
|
>
|
|
673
|
-
<Pagination
|
|
705
|
+
<Pagination
|
|
706
|
+
page={page}
|
|
707
|
+
setPage={setPage!}
|
|
708
|
+
testID={tableTestIDs.pagination}
|
|
709
|
+
totalPages={totalPages}
|
|
710
|
+
/>
|
|
674
711
|
</View>
|
|
675
712
|
)}
|
|
676
713
|
</View>
|
package/src/DateTimeField.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {SelectField} from "./SelectField";
|
|
|
13
13
|
import {Text} from "./Text";
|
|
14
14
|
import {useTheme} from "./Theme";
|
|
15
15
|
import {TimezonePicker} from "./TimezonePicker";
|
|
16
|
+
import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
|
|
16
17
|
|
|
17
18
|
interface SeparatorProps {
|
|
18
19
|
type: "date" | "time";
|
|
@@ -416,8 +417,11 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
416
417
|
errorText,
|
|
417
418
|
disabled,
|
|
418
419
|
helperText,
|
|
420
|
+
testID,
|
|
421
|
+
testIDs,
|
|
419
422
|
}): React.ReactElement => {
|
|
420
423
|
const {theme} = useTheme();
|
|
424
|
+
const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
|
|
421
425
|
// 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
|
|
422
426
|
const dateActionSheetRef: React.RefObject<any> = React.createRef();
|
|
423
427
|
const [amPm, setAmPm] = useState<"am" | "pm">("am");
|
|
@@ -969,8 +973,8 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
969
973
|
|
|
970
974
|
return (
|
|
971
975
|
<>
|
|
972
|
-
{Boolean(title) && <FieldTitle text={title as string} />}
|
|
973
|
-
{Boolean(errorText) && <FieldError text={errorText as string} />}
|
|
976
|
+
{Boolean(title) && <FieldTitle testID={fieldTestIDs.label} text={title as string} />}
|
|
977
|
+
{Boolean(errorText) && <FieldError testID={fieldTestIDs.error} text={errorText as string} />}
|
|
974
978
|
|
|
975
979
|
{isMobileTimeOnly && (
|
|
976
980
|
<MobileTimeDisplay
|
|
@@ -1004,6 +1008,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
1004
1008
|
minWidth: isMobileDatetime ? 200 : minimumWidth,
|
|
1005
1009
|
paddingHorizontal: 6,
|
|
1006
1010
|
}}
|
|
1011
|
+
testID={fieldTestIDs.input}
|
|
1007
1012
|
>
|
|
1008
1013
|
{showDateSection && (
|
|
1009
1014
|
<DateRowWithIcon
|
|
@@ -1055,7 +1060,9 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
1055
1060
|
visible={showDate}
|
|
1056
1061
|
/>
|
|
1057
1062
|
)}
|
|
1058
|
-
{Boolean(helperText) &&
|
|
1063
|
+
{Boolean(helperText) && (
|
|
1064
|
+
<FieldHelperText testID={fieldTestIDs.helper} text={helperText as string} />
|
|
1065
|
+
)}
|
|
1059
1066
|
</>
|
|
1060
1067
|
);
|
|
1061
1068
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {afterAll, beforeAll, describe, expect, it, mock, spyOn} from "bun:test";
|
|
3
2
|
import React from "react";
|
|
4
3
|
|
|
@@ -54,14 +53,14 @@ describe("ErrorBoundary", () => {
|
|
|
54
53
|
});
|
|
55
54
|
|
|
56
55
|
it("calls onError when componentDidCatch receives an error", () => {
|
|
57
|
-
const onError = mock(() => {});
|
|
56
|
+
const onError = mock<(error: Error, stack: string) => void>(() => {});
|
|
58
57
|
const boundary = new ErrorBoundary({children: null, onError});
|
|
59
58
|
const error = new Error("caught");
|
|
60
59
|
|
|
61
60
|
boundary.componentDidCatch(error, {componentStack: "stack trace"});
|
|
62
61
|
|
|
63
62
|
expect(onError).toHaveBeenCalledTimes(1);
|
|
64
|
-
expect(
|
|
63
|
+
expect(onError.mock.calls[0]).toEqual([error, "stack trace"]);
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
it("does not throw when componentDidCatch is called without onError", () => {
|
|
@@ -78,7 +77,7 @@ describe("ErrorBoundary", () => {
|
|
|
78
77
|
boundary.resetError();
|
|
79
78
|
|
|
80
79
|
expect(setStateSpy).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(
|
|
80
|
+
expect(setStateSpy.mock.calls[0][0]).toEqual({error: undefined});
|
|
82
81
|
setStateSpy.mockRestore();
|
|
83
82
|
});
|
|
84
83
|
|
package/src/IconButton.test.tsx
CHANGED
|
@@ -143,6 +143,20 @@ describe("IconButton", () => {
|
|
|
143
143
|
expect(toJSON()).toMatchSnapshot();
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
+
it("renders ghost variant", () => {
|
|
147
|
+
const {toJSON} = renderWithTheme(
|
|
148
|
+
<IconButton accessibilityLabel="Test" iconName="check" onClick={() => {}} variant="ghost" />
|
|
149
|
+
);
|
|
150
|
+
expect(toJSON()).toMatchSnapshot();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("renders sm size", () => {
|
|
154
|
+
const {toJSON} = renderWithTheme(
|
|
155
|
+
<IconButton accessibilityLabel="Test" iconName="check" onClick={() => {}} size="sm" />
|
|
156
|
+
);
|
|
157
|
+
expect(toJSON()).toMatchSnapshot();
|
|
158
|
+
});
|
|
159
|
+
|
|
146
160
|
describe("custom icons", () => {
|
|
147
161
|
// IconButton renders `null` under the bun/react-test-renderer harness (all of
|
|
148
162
|
// its snapshots are null), so we verify the custom-icon code path renders
|
package/src/IconButton.tsx
CHANGED
|
@@ -56,6 +56,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
56
56
|
indicator,
|
|
57
57
|
indicatorText,
|
|
58
58
|
loading: propsLoading = false,
|
|
59
|
+
size = "default",
|
|
59
60
|
testID,
|
|
60
61
|
variant = "primary",
|
|
61
62
|
withConfirmation = false,
|
|
@@ -93,6 +94,9 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
93
94
|
} else if (variant === "destructive") {
|
|
94
95
|
backgroundColor = theme.text.inverted;
|
|
95
96
|
color = theme.text.error;
|
|
97
|
+
} else if (variant === "ghost") {
|
|
98
|
+
backgroundColor = "transparent";
|
|
99
|
+
color = theme.surface.secondaryDark;
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
const indicatorColor = indicator ? theme.surface[indicator] : undefined;
|
|
@@ -134,23 +138,24 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
134
138
|
alignItems: "center",
|
|
135
139
|
backgroundColor,
|
|
136
140
|
borderRadius: theme.radius.rounded,
|
|
137
|
-
height: 32,
|
|
141
|
+
height: size === "sm" ? 28 : 32,
|
|
138
142
|
justifyContent: "center",
|
|
139
|
-
width: 32,
|
|
143
|
+
width: size === "sm" ? 28 : 32,
|
|
140
144
|
}}
|
|
141
145
|
testID={testID}
|
|
142
146
|
>
|
|
143
147
|
{loading ? (
|
|
144
148
|
<ActivityIndicator color={color} size="small" />
|
|
145
149
|
) : CustomIcon ? (
|
|
146
|
-
<CustomIcon color={color} size={variant === "navigation" ? 20 : 16} />
|
|
150
|
+
<CustomIcon color={color} size={size === "sm" ? 12 : variant === "navigation" ? 20 : 16} />
|
|
147
151
|
) : (
|
|
148
152
|
<FontAwesome6
|
|
149
153
|
color={color}
|
|
150
154
|
name={iconName}
|
|
151
155
|
selectable={undefined}
|
|
152
|
-
size={variant === "navigation" ? 20 : 16}
|
|
156
|
+
size={size === "sm" ? 12 : variant === "navigation" ? 20 : 16}
|
|
153
157
|
solid
|
|
158
|
+
style={{textAlign: "center"}}
|
|
154
159
|
/>
|
|
155
160
|
)}
|
|
156
161
|
{Boolean(indicator) && (
|
package/src/Link.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import {Linking, Pressable} from "react-native";
|
|
|
4
4
|
import type {LinkProps} from "./Common";
|
|
5
5
|
import {Text} from "./Text";
|
|
6
6
|
|
|
7
|
-
export const Link: React.FC<LinkProps> = ({text, href, onClick}) => {
|
|
7
|
+
export const Link: React.FC<LinkProps> = ({text, href, onClick, testID}) => {
|
|
8
8
|
if (!href && !onClick) {
|
|
9
9
|
console.error("Link component requires either href or onClick prop");
|
|
10
10
|
return null;
|
|
@@ -22,6 +22,7 @@ export const Link: React.FC<LinkProps> = ({text, href, onClick}) => {
|
|
|
22
22
|
void Linking.openURL(href);
|
|
23
23
|
}
|
|
24
24
|
}}
|
|
25
|
+
testID={testID}
|
|
25
26
|
>
|
|
26
27
|
<Text color="link" skipLinking underline>
|
|
27
28
|
{text}
|
package/src/MarkdownEditor.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, {useMemo} from "react";
|
|
2
2
|
import {ScrollView, useWindowDimensions} from "react-native";
|
|
3
3
|
import {Box} from "./Box";
|
|
4
4
|
import {Heading} from "./Heading";
|
|
@@ -15,6 +15,11 @@ interface MarkdownEditorProps {
|
|
|
15
15
|
maxHeight?: number;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const DEFAULT_MAX_HEIGHT = 500;
|
|
19
|
+
const MIN_PANE_HEIGHT = 200;
|
|
20
|
+
const TEXT_FIELD_ROW_HEIGHT = 40;
|
|
21
|
+
const TEXT_FIELD_CHROME_HEIGHT = 20;
|
|
22
|
+
|
|
18
23
|
export const MarkdownEditor: React.FC<MarkdownEditorProps> = ({
|
|
19
24
|
value,
|
|
20
25
|
onChange,
|
|
@@ -22,43 +27,63 @@ export const MarkdownEditor: React.FC<MarkdownEditorProps> = ({
|
|
|
22
27
|
title,
|
|
23
28
|
disabled,
|
|
24
29
|
testID,
|
|
25
|
-
maxHeight =
|
|
30
|
+
maxHeight = DEFAULT_MAX_HEIGHT,
|
|
26
31
|
}) => {
|
|
27
32
|
const {width} = useWindowDimensions();
|
|
28
33
|
const isDesktop = width >= 768;
|
|
29
34
|
|
|
35
|
+
const paneContainerStyle = {
|
|
36
|
+
flex: 1,
|
|
37
|
+
height: maxHeight,
|
|
38
|
+
maxHeight,
|
|
39
|
+
minHeight: MIN_PANE_HEIGHT,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const editorRows = useMemo(
|
|
43
|
+
() => Math.max(3, Math.floor((maxHeight - TEXT_FIELD_CHROME_HEIGHT) / TEXT_FIELD_ROW_HEIGHT)),
|
|
44
|
+
[maxHeight]
|
|
45
|
+
);
|
|
46
|
+
|
|
30
47
|
return (
|
|
31
48
|
<Box direction="column" gap={2} testID={testID}>
|
|
32
49
|
{Boolean(title) && <Heading size="sm">{title}</Heading>}
|
|
33
|
-
<Box direction={isDesktop ? "row" : "column"} gap={3}>
|
|
34
|
-
<Box dangerouslySetInlineStyle={{__style: {flexBasis: 0}}} flex="grow">
|
|
50
|
+
<Box alignItems="stretch" direction={isDesktop ? "row" : "column"} gap={3}>
|
|
51
|
+
<Box dangerouslySetInlineStyle={{__style: {flexBasis: 0}}} direction="column" flex="grow">
|
|
35
52
|
<Heading size="sm">Edit</Heading>
|
|
36
|
-
<Box
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
<Box
|
|
54
|
+
dangerouslySetInlineStyle={{__style: paneContainerStyle}}
|
|
55
|
+
marginTop={1}
|
|
56
|
+
overflow="hidden"
|
|
57
|
+
>
|
|
58
|
+
<Box height="100%" overflow="hidden">
|
|
59
|
+
<TextField
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
multiline
|
|
62
|
+
onChange={onChange}
|
|
63
|
+
placeholder={placeholder}
|
|
64
|
+
rows={editorRows}
|
|
65
|
+
testID={testID ? `${testID}-input` : undefined}
|
|
66
|
+
value={value}
|
|
67
|
+
/>
|
|
68
|
+
</Box>
|
|
47
69
|
</Box>
|
|
48
70
|
</Box>
|
|
49
|
-
<Box dangerouslySetInlineStyle={{__style: {flexBasis: 0}}} flex="grow">
|
|
71
|
+
<Box dangerouslySetInlineStyle={{__style: {flexBasis: 0}}} direction="column" flex="grow">
|
|
50
72
|
<Heading size="sm">Preview</Heading>
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
<Box
|
|
74
|
+
border="default"
|
|
75
|
+
dangerouslySetInlineStyle={{__style: paneContainerStyle}}
|
|
76
|
+
marginTop={1}
|
|
77
|
+
overflow="hidden"
|
|
78
|
+
rounding="sm"
|
|
79
|
+
testID={testID ? `${testID}-preview` : undefined}
|
|
80
|
+
>
|
|
81
|
+
<ScrollView style={{flex: 1, height: maxHeight, maxHeight}}>
|
|
82
|
+
<Box padding={3}>
|
|
83
|
+
<MarkdownView>{value || " "}</MarkdownView>
|
|
84
|
+
</Box>
|
|
85
|
+
</ScrollView>
|
|
86
|
+
</Box>
|
|
62
87
|
</Box>
|
|
63
88
|
</Box>
|
|
64
89
|
</Box>
|
|
@@ -36,6 +36,10 @@ const TOOLBAR_BUTTONS: ToolbarButton[] = [
|
|
|
36
36
|
{insert: (v) => `${v}[text](url)`, label: "🔗"},
|
|
37
37
|
];
|
|
38
38
|
|
|
39
|
+
const DEFAULT_MAX_HEIGHT = 500;
|
|
40
|
+
const MIN_PANE_HEIGHT = 200;
|
|
41
|
+
const TOOLBAR_MIN_HEIGHT = 34;
|
|
42
|
+
|
|
39
43
|
export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
40
44
|
title,
|
|
41
45
|
value = "",
|
|
@@ -45,7 +49,7 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
45
49
|
errorText,
|
|
46
50
|
helperText,
|
|
47
51
|
testID,
|
|
48
|
-
maxHeight =
|
|
52
|
+
maxHeight = DEFAULT_MAX_HEIGHT,
|
|
49
53
|
}) => {
|
|
50
54
|
const {theme} = useTheme();
|
|
51
55
|
const isWeb = Platform.OS === "web";
|
|
@@ -56,18 +60,28 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
56
60
|
[isWeb]
|
|
57
61
|
);
|
|
58
62
|
|
|
63
|
+
const paneContainerStyle = {
|
|
64
|
+
flex: 1,
|
|
65
|
+
height: maxHeight,
|
|
66
|
+
maxHeight,
|
|
67
|
+
minHeight: MIN_PANE_HEIGHT,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const editorAreaMinHeight = Math.max(MIN_PANE_HEIGHT - TOOLBAR_MIN_HEIGHT, 120);
|
|
71
|
+
|
|
59
72
|
return (
|
|
60
73
|
<View testID={testID}>
|
|
61
74
|
{Boolean(title) && <FieldTitle text={title!} />}
|
|
62
75
|
<Box
|
|
76
|
+
alignItems="stretch"
|
|
63
77
|
border={errorText ? "error" : "default"}
|
|
64
78
|
direction={isWeb ? "row" : "column"}
|
|
65
79
|
gap={0}
|
|
66
80
|
overflow="hidden"
|
|
67
81
|
rounding="md"
|
|
68
82
|
>
|
|
69
|
-
<View style={{
|
|
70
|
-
<
|
|
83
|
+
<View style={{...paneContainerStyle, flexDirection: "column"}}>
|
|
84
|
+
<View style={{flex: 1, minHeight: editorAreaMinHeight}}>
|
|
71
85
|
<TextInput
|
|
72
86
|
editable={!disabled}
|
|
73
87
|
multiline
|
|
@@ -75,6 +89,7 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
75
89
|
placeholder={placeholder ?? "Enter markdown..."}
|
|
76
90
|
placeholderTextColor={theme.text.secondaryDark}
|
|
77
91
|
ref={inputRef}
|
|
92
|
+
scrollEnabled
|
|
78
93
|
style={{
|
|
79
94
|
backgroundColor: theme.surface.base,
|
|
80
95
|
borderBottomWidth: isWeb ? 0 : 1,
|
|
@@ -84,14 +99,16 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
84
99
|
flex: 1,
|
|
85
100
|
fontFamily: monoFont,
|
|
86
101
|
fontSize: 14,
|
|
87
|
-
|
|
102
|
+
height: "100%",
|
|
103
|
+
minHeight: editorAreaMinHeight,
|
|
88
104
|
padding: 12,
|
|
89
105
|
textAlignVertical: "top",
|
|
106
|
+
width: "100%",
|
|
90
107
|
}}
|
|
91
108
|
testID={testID ? `${testID}-input` : undefined}
|
|
92
109
|
value={value}
|
|
93
110
|
/>
|
|
94
|
-
</
|
|
111
|
+
</View>
|
|
95
112
|
{!disabled && (
|
|
96
113
|
<View
|
|
97
114
|
style={{
|
|
@@ -99,8 +116,10 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
99
116
|
borderColor: theme.border.default,
|
|
100
117
|
borderTopWidth: 1,
|
|
101
118
|
flexDirection: "row",
|
|
119
|
+
flexShrink: 0,
|
|
102
120
|
flexWrap: "wrap",
|
|
103
121
|
gap: 2,
|
|
122
|
+
minHeight: TOOLBAR_MIN_HEIGHT,
|
|
104
123
|
paddingHorizontal: 4,
|
|
105
124
|
paddingVertical: 3,
|
|
106
125
|
}}
|
|
@@ -139,17 +158,19 @@ export const MarkdownEditorField: React.FC<MarkdownEditorFieldProps> = ({
|
|
|
139
158
|
</View>
|
|
140
159
|
)}
|
|
141
160
|
</View>
|
|
142
|
-
<
|
|
143
|
-
<
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
<View style={paneContainerStyle}>
|
|
162
|
+
<ScrollView style={{flex: 1, height: maxHeight, maxHeight}}>
|
|
163
|
+
<Box color="base" padding={3} style={{minHeight: MIN_PANE_HEIGHT}}>
|
|
164
|
+
{value ? (
|
|
165
|
+
<MarkdownView>{value}</MarkdownView>
|
|
166
|
+
) : (
|
|
167
|
+
<Text color="secondaryDark" size="sm">
|
|
168
|
+
Preview
|
|
169
|
+
</Text>
|
|
170
|
+
)}
|
|
171
|
+
</Box>
|
|
172
|
+
</ScrollView>
|
|
173
|
+
</View>
|
|
153
174
|
</Box>
|
|
154
175
|
{Boolean(errorText) && <FieldError text={errorText!} />}
|
|
155
176
|
{Boolean(helperText) && <FieldHelperText text={helperText!} />}
|
package/src/Modal.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import {Icon} from "./Icon";
|
|
|
18
18
|
import {isMobileDevice} from "./MediaQuery";
|
|
19
19
|
import {Text} from "./Text";
|
|
20
20
|
import {useTheme} from "./Theme";
|
|
21
|
+
import {resolveModalTestIDsFromProps, toTestProps} from "./testing/resolveTestId";
|
|
21
22
|
import {isNative} from "./Utilities";
|
|
22
23
|
|
|
23
24
|
const getModalSize = (size: "sm" | "md" | "lg"): DimensionValue => {
|
|
@@ -47,6 +48,7 @@ const ModalContent: FC<{
|
|
|
47
48
|
sizePx: DimensionValue;
|
|
48
49
|
theme: TerrenoTheme;
|
|
49
50
|
isMobile: boolean;
|
|
51
|
+
modalTestIDs: ReturnType<typeof resolveModalTestIDsFromProps>;
|
|
50
52
|
}> = ({
|
|
51
53
|
children,
|
|
52
54
|
title,
|
|
@@ -61,6 +63,7 @@ const ModalContent: FC<{
|
|
|
61
63
|
sizePx,
|
|
62
64
|
theme,
|
|
63
65
|
isMobile,
|
|
66
|
+
modalTestIDs,
|
|
64
67
|
}) => {
|
|
65
68
|
return (
|
|
66
69
|
<View
|
|
@@ -81,6 +84,7 @@ const ModalContent: FC<{
|
|
|
81
84
|
margin: "auto",
|
|
82
85
|
}),
|
|
83
86
|
}}
|
|
87
|
+
{...toTestProps(modalTestIDs.root)}
|
|
84
88
|
>
|
|
85
89
|
<View style={{alignSelf: "flex-end", position: "relative"}}>
|
|
86
90
|
<Pressable
|
|
@@ -98,6 +102,7 @@ const ModalContent: FC<{
|
|
|
98
102
|
right: -8,
|
|
99
103
|
top: -8,
|
|
100
104
|
}}
|
|
105
|
+
{...toTestProps(modalTestIDs.dismiss)}
|
|
101
106
|
>
|
|
102
107
|
<Icon iconName="x" size="sm" />
|
|
103
108
|
</Pressable>
|
|
@@ -108,6 +113,7 @@ const ModalContent: FC<{
|
|
|
108
113
|
aria-label={title}
|
|
109
114
|
aria-role="header"
|
|
110
115
|
style={{alignSelf: "flex-start"}}
|
|
116
|
+
{...toTestProps(modalTestIDs.title)}
|
|
111
117
|
>
|
|
112
118
|
<Heading size="lg">{title}</Heading>
|
|
113
119
|
</View>
|
|
@@ -154,6 +160,7 @@ const ModalContent: FC<{
|
|
|
154
160
|
<View style={{marginRight: primaryButtonText ? 20 : 0}}>
|
|
155
161
|
<Button
|
|
156
162
|
onClick={secondaryButtonOnClick!}
|
|
163
|
+
testID={modalTestIDs.secondaryButton}
|
|
157
164
|
text={secondaryButtonText as string}
|
|
158
165
|
variant="muted"
|
|
159
166
|
/>
|
|
@@ -163,6 +170,7 @@ const ModalContent: FC<{
|
|
|
163
170
|
<Button
|
|
164
171
|
disabled={primaryButtonDisabled}
|
|
165
172
|
onClick={primaryButtonOnClick!}
|
|
173
|
+
testID={modalTestIDs.primaryButton}
|
|
166
174
|
text={primaryButtonText as string}
|
|
167
175
|
/>
|
|
168
176
|
)}
|
|
@@ -179,6 +187,8 @@ export const Modal: FC<ModalProps> = ({
|
|
|
179
187
|
secondaryButtonText,
|
|
180
188
|
size = "sm",
|
|
181
189
|
subtitle,
|
|
190
|
+
testID,
|
|
191
|
+
testIDs,
|
|
182
192
|
text,
|
|
183
193
|
title,
|
|
184
194
|
visible,
|
|
@@ -188,6 +198,7 @@ export const Modal: FC<ModalProps> = ({
|
|
|
188
198
|
}: ModalProps) => {
|
|
189
199
|
const actionSheetRef = useRef<ActionSheetRef>(null);
|
|
190
200
|
const {theme} = useTheme();
|
|
201
|
+
const modalTestIDs = resolveModalTestIDsFromProps({testID, testIDs});
|
|
191
202
|
|
|
192
203
|
const handleDismiss = () => {
|
|
193
204
|
if (visible && onDismiss) {
|
|
@@ -240,7 +251,9 @@ export const Modal: FC<ModalProps> = ({
|
|
|
240
251
|
const sizePx = getModalSize(size);
|
|
241
252
|
|
|
242
253
|
const modalContentProps = {
|
|
254
|
+
children,
|
|
243
255
|
isMobile,
|
|
256
|
+
modalTestIDs,
|
|
244
257
|
onDismiss: handleDismiss,
|
|
245
258
|
persistOnBackgroundClick,
|
|
246
259
|
primaryButtonDisabled,
|