@terreno/ui 0.29.0 → 0.31.0

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 (43) hide show
  1. package/LICENSE +21 -203
  2. package/dist/AiSuggestionBox.js +7 -12
  3. package/dist/AiSuggestionBox.js.map +1 -1
  4. package/dist/Common.d.ts +65 -0
  5. package/dist/Common.js.map +1 -1
  6. package/dist/EditableCard.d.ts +3 -0
  7. package/dist/EditableCard.js +23 -0
  8. package/dist/EditableCard.js.map +1 -0
  9. package/dist/Theme.js +1 -0
  10. package/dist/Theme.js.map +1 -1
  11. package/dist/ThumbsUpDownFeedback.d.ts +8 -0
  12. package/dist/ThumbsUpDownFeedback.js +60 -0
  13. package/dist/ThumbsUpDownFeedback.js.map +1 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/package.json +3 -2
  18. package/src/ActionSheet.test.tsx +80 -37
  19. package/src/AiSuggestionBox.test.tsx +2 -2
  20. package/src/AiSuggestionBox.tsx +17 -48
  21. package/src/Common.ts +75 -0
  22. package/src/ConsentHistory.test.tsx +224 -0
  23. package/src/ConsentNavigator.test.tsx +6 -8
  24. package/src/DataTable.test.tsx +15 -21
  25. package/src/DateTimeField.test.tsx +36 -0
  26. package/src/DraggableList.test.tsx +377 -0
  27. package/src/EditableCard.test.tsx +69 -0
  28. package/src/EditableCard.tsx +73 -0
  29. package/src/PickerSelect.test.tsx +23 -12
  30. package/src/SidebarNavigation.test.tsx +339 -0
  31. package/src/SignatureCaptureField.test.tsx +30 -0
  32. package/src/TapToEdit.test.tsx +8 -14
  33. package/src/Theme.tsx +1 -0
  34. package/src/ThumbsUpDownFeedback.test.tsx +100 -0
  35. package/src/ThumbsUpDownFeedback.tsx +118 -0
  36. package/src/Tooltip.test.tsx +1 -0
  37. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +108 -30
  38. package/src/__snapshots__/Card.test.tsx.snap +1 -0
  39. package/src/__snapshots__/EditableCard.test.tsx.snap +242 -0
  40. package/src/__snapshots__/SignatureCaptureField.test.tsx.snap +45 -0
  41. package/src/bunSetup.ts +11 -2
  42. package/src/generateConsentHistoryPdf.test.ts +253 -0
  43. package/src/index.tsx +2 -0
@@ -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 {act} from "@testing-library/react-native";
5
3
 
@@ -8,6 +6,8 @@ import {DataTable} from "./DataTable";
8
6
  import {Text} from "./Text";
9
7
  import {renderWithTheme} from "./test-utils";
10
8
 
9
+ type MoreContentComponent = NonNullable<DataTableProps["moreContentComponent"]>;
10
+
11
11
  describe("DataTable", () => {
12
12
  const sampleColumns = [
13
13
  {columnType: "text", title: "Name", width: 150},
@@ -112,13 +112,9 @@ describe("DataTable", () => {
112
112
  });
113
113
 
114
114
  it("renders with more content component", () => {
115
- const MoreContent = ({rowIndex}: {rowIndex: number}) => <Text>Row {rowIndex} details</Text>;
115
+ const MoreContent: MoreContentComponent = ({rowIndex}) => <Text>Row {rowIndex} details</Text>;
116
116
  const {toJSON} = renderWithTheme(
117
- <DataTable
118
- columns={sampleColumns}
119
- data={sampleData}
120
- moreContentComponent={MoreContent as unknown as DataTableProps["moreContentComponent"]}
121
- />
117
+ <DataTable columns={sampleColumns} data={sampleData} moreContentComponent={MoreContent} />
122
118
  );
123
119
  expect(toJSON()).toMatchSnapshot();
124
120
  });
@@ -266,7 +262,7 @@ describe("DataTable", () => {
266
262
  });
267
263
 
268
264
  it("renders with custom column component map", () => {
269
- const CustomComponent = ({cellData}: {cellData: {value: unknown}}) => (
265
+ const CustomComponent: DataTableCustomComponentMap[string] = ({cellData}) => (
270
266
  <Text>Custom: {String(cellData.value)}</Text>
271
267
  );
272
268
  const customColumns = [{columnType: "custom", title: "Custom Col", width: 150}];
@@ -274,7 +270,7 @@ describe("DataTable", () => {
274
270
  const {getByText} = renderWithTheme(
275
271
  <DataTable
276
272
  columns={customColumns}
277
- customColumnComponentMap={{custom: CustomComponent as any}}
273
+ customColumnComponentMap={{custom: CustomComponent}}
278
274
  data={customData}
279
275
  />
280
276
  );
@@ -300,16 +296,16 @@ describe("DataTable", () => {
300
296
  });
301
297
 
302
298
  it("renders with moreContentExtraData", () => {
303
- const MoreContent = ({rowIndex, extraInfo}: {rowIndex: number; extraInfo?: string}) => (
299
+ const MoreContent: MoreContentComponent = ({rowIndex, extraInfo}) => (
304
300
  <Text>
305
- Row {rowIndex}: {extraInfo}
301
+ Row {rowIndex}: {String(extraInfo)}
306
302
  </Text>
307
303
  );
308
304
  const {toJSON} = renderWithTheme(
309
305
  <DataTable
310
306
  columns={sampleColumns}
311
307
  data={sampleData}
312
- moreContentComponent={MoreContent as any}
308
+ moreContentComponent={MoreContent}
313
309
  moreContentExtraData={[{extraInfo: "info1"}, {extraInfo: "info2"}, {extraInfo: "info3"}]}
314
310
  />
315
311
  );
@@ -317,13 +313,11 @@ describe("DataTable", () => {
317
313
  });
318
314
 
319
315
  it("opens and dismisses more content modal via MoreButtonCell press", async () => {
320
- const MoreContent = ({rowIndex}: {rowIndex: number}) => <Text>Detail for row {rowIndex}</Text>;
316
+ const MoreContent: MoreContentComponent = ({rowIndex}) => (
317
+ <Text>Detail for row {rowIndex}</Text>
318
+ );
321
319
  const {UNSAFE_getAllByType} = renderWithTheme(
322
- <DataTable
323
- columns={sampleColumns}
324
- data={sampleData}
325
- moreContentComponent={MoreContent as any}
326
- />
320
+ <DataTable columns={sampleColumns} data={sampleData} moreContentComponent={MoreContent} />
327
321
  );
328
322
 
329
323
  const {Pressable: PressableComp} = require("react-native");
@@ -352,7 +346,7 @@ describe("DataTable", () => {
352
346
  });
353
347
 
354
348
  it("renders with customColumnComponentMap", () => {
355
- const CustomCell = ({cellData}: {cellData: {value: unknown}; column: unknown}) => (
349
+ const CustomCell: DataTableCustomComponentMap[string] = ({cellData}) => (
356
350
  <Text>Custom: {String(cellData.value)}</Text>
357
351
  );
358
352
  const customColumns = [
@@ -363,7 +357,7 @@ describe("DataTable", () => {
363
357
  const {getByText} = renderWithTheme(
364
358
  <DataTable
365
359
  columns={customColumns}
366
- customColumnComponentMap={{custom: CustomCell} as DataTableCustomComponentMap}
360
+ customColumnComponentMap={{custom: CustomCell}}
367
361
  data={customData}
368
362
  />
369
363
  );
@@ -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();
@@ -0,0 +1,377 @@
1
+ import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
+ import {act, render} from "@testing-library/react-native";
3
+ import React from "react";
4
+ import {Platform, Text as RNText, View} from "react-native";
5
+ import {Gesture} from "react-native-gesture-handler";
6
+ import * as Reanimated from "react-native-reanimated";
7
+
8
+ import {DraggableList, DragItem} from "./DraggableList";
9
+
10
+ interface PanEvent {
11
+ translationY: number;
12
+ }
13
+
14
+ interface CapturedGesture {
15
+ onBegin?: () => void;
16
+ onChange?: (event: PanEvent) => void;
17
+ onFinalize?: () => void;
18
+ }
19
+
20
+ let capturedGestures: CapturedGesture[] = [];
21
+
22
+ /** Replaces Gesture.Pan with a chainable stub that records the registered handlers. */
23
+ const capturePanGestures = () => {
24
+ return spyOn(Gesture, "Pan").mockImplementation(() => {
25
+ const captured: CapturedGesture = {};
26
+ capturedGestures.push(captured);
27
+ const chainable = {
28
+ onBegin: (handler: () => void) => {
29
+ captured.onBegin = handler;
30
+ return chainable;
31
+ },
32
+ onChange: (handler: (event: PanEvent) => void) => {
33
+ captured.onChange = handler;
34
+ return chainable;
35
+ },
36
+ onFinalize: (handler: () => void) => {
37
+ captured.onFinalize = handler;
38
+ return chainable;
39
+ },
40
+ };
41
+ return chainable as unknown as ReturnType<typeof Gesture.Pan>;
42
+ });
43
+ };
44
+
45
+ const renderItem = ({item}: {item: string}): React.ReactElement => <RNText>{item}</RNText>;
46
+
47
+ describe("DraggableList", () => {
48
+ let panSpy: ReturnType<typeof capturePanGestures>;
49
+
50
+ beforeEach(() => {
51
+ capturedGestures = [];
52
+ panSpy = capturePanGestures();
53
+ });
54
+
55
+ afterEach(() => {
56
+ panSpy.mockRestore();
57
+ });
58
+
59
+ it("renders one draggable item per id", () => {
60
+ const {getByText} = render(
61
+ <DraggableList
62
+ callbackNewDataIds={() => {}}
63
+ dataIDs={["a", "b", "c"]}
64
+ renderItem={renderItem}
65
+ />
66
+ );
67
+
68
+ expect(getByText("a")).toBeTruthy();
69
+ expect(getByText("b")).toBeTruthy();
70
+ expect(getByText("c")).toBeTruthy();
71
+ });
72
+
73
+ it("falls back to the deprecated data prop", () => {
74
+ const {getByText} = render(
75
+ <DraggableList callbackNewDataIds={() => {}} data={["one", "two"]} renderItem={renderItem} />
76
+ );
77
+
78
+ expect(getByText("one")).toBeTruthy();
79
+ expect(getByText("two")).toBeTruthy();
80
+ });
81
+
82
+ it("renders an empty list when no ids are provided", () => {
83
+ const {toJSON} = render(
84
+ <DraggableList callbackNewDataIds={() => {}} renderItem={renderItem} />
85
+ );
86
+
87
+ expect(toJSON()).toBeTruthy();
88
+ expect(capturedGestures).toHaveLength(0);
89
+ });
90
+
91
+ it("renders a custom grip element", () => {
92
+ const {getByText} = render(
93
+ <DraggableList
94
+ callbackNewDataIds={() => {}}
95
+ dataIDs={["a"]}
96
+ renderGrip={<RNText>grip</RNText>}
97
+ renderItem={renderItem}
98
+ />
99
+ );
100
+
101
+ expect(getByText("grip")).toBeTruthy();
102
+ });
103
+
104
+ it("renders a grip render function", () => {
105
+ const {getByText} = render(
106
+ <DraggableList
107
+ callbackNewDataIds={() => {}}
108
+ dataIDs={["a"]}
109
+ renderGrip={() => <RNText>grip-fn</RNText>}
110
+ renderItem={renderItem}
111
+ />
112
+ );
113
+
114
+ expect(getByText("grip-fn")).toBeTruthy();
115
+ });
116
+
117
+ it("throws when the data prop is not an array", () => {
118
+ expect(() =>
119
+ render(
120
+ <DraggableList
121
+ callbackNewDataIds={() => {}}
122
+ dataIDs={"nope" as unknown as string[]}
123
+ renderItem={renderItem}
124
+ />
125
+ )
126
+ ).toThrow(/should be \[\]/);
127
+ });
128
+
129
+ it("throws when renderItem is missing", () => {
130
+ expect(() =>
131
+ render(
132
+ <DraggableList
133
+ callbackNewDataIds={() => {}}
134
+ dataIDs={["a"]}
135
+ renderItem={undefined as unknown as typeof renderItem}
136
+ />
137
+ )
138
+ ).toThrow(/"renderItem" prop is missing/);
139
+ });
140
+
141
+ it("throws when callbackNewDataIds is missing", () => {
142
+ expect(() =>
143
+ render(
144
+ <DraggableList
145
+ callbackNewDataIds={undefined as unknown as (ids: string[]) => void}
146
+ dataIDs={["a"]}
147
+ renderItem={renderItem}
148
+ />
149
+ )
150
+ ).toThrow(/"callbackNewDataIds" prop is missing/);
151
+ });
152
+
153
+ it("throws when callbackNewDataIds is not a function", () => {
154
+ expect(() =>
155
+ render(
156
+ <DraggableList
157
+ callbackNewDataIds={"nope" as unknown as (ids: string[]) => void}
158
+ dataIDs={["a"]}
159
+ renderItem={renderItem}
160
+ />
161
+ )
162
+ ).toThrow(/should be function type/);
163
+ });
164
+
165
+ it("updates positions when the ids change", () => {
166
+ const {getByText, rerender} = render(
167
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
168
+ );
169
+
170
+ rerender(
171
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["b", "a"]} renderItem={renderItem} />
172
+ );
173
+
174
+ expect(getByText("a")).toBeTruthy();
175
+ expect(getByText("b")).toBeTruthy();
176
+ });
177
+
178
+ describe("drag gestures", () => {
179
+ it("vibrates when the drag begins", () => {
180
+ const passVibration = mock(() => {});
181
+ render(
182
+ <DraggableList
183
+ callbackNewDataIds={() => {}}
184
+ dataIDs={["a", "b"]}
185
+ passVibration={passVibration}
186
+ renderItem={renderItem}
187
+ />
188
+ );
189
+
190
+ act(() => {
191
+ capturedGestures[0]?.onBegin?.();
192
+ });
193
+
194
+ expect(passVibration).toHaveBeenCalled();
195
+ });
196
+
197
+ it("begins the drag without a vibration callback", () => {
198
+ render(
199
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
200
+ );
201
+
202
+ expect(() =>
203
+ act(() => {
204
+ capturedGestures[0]?.onBegin?.();
205
+ })
206
+ ).not.toThrow();
207
+ });
208
+
209
+ it("reorders items and vibrates when dragged past another item", () => {
210
+ const passVibration = mock(() => {});
211
+ render(
212
+ <DraggableList
213
+ callbackNewDataIds={() => {}}
214
+ dataIDs={["a", "b", "c"]}
215
+ itemHeight={50}
216
+ itemsGap={5}
217
+ passVibration={passVibration}
218
+ renderItem={renderItem}
219
+ />
220
+ );
221
+
222
+ act(() => {
223
+ capturedGestures[0]?.onBegin?.();
224
+ capturedGestures[0]?.onChange?.({translationY: 120});
225
+ });
226
+
227
+ // Once for the drag start, once for crossing into a new position.
228
+ expect(passVibration.mock.calls.length).toBeGreaterThan(1);
229
+ });
230
+
231
+ it("does not reorder when the item stays in place", () => {
232
+ const passVibration = mock(() => {});
233
+ render(
234
+ <DraggableList
235
+ callbackNewDataIds={() => {}}
236
+ dataIDs={["a", "b", "c"]}
237
+ passVibration={passVibration}
238
+ renderItem={renderItem}
239
+ />
240
+ );
241
+
242
+ act(() => {
243
+ capturedGestures[0]?.onChange?.({translationY: 1});
244
+ });
245
+
246
+ expect(passVibration).not.toHaveBeenCalled();
247
+ });
248
+
249
+ it("clamps the new position to the end of the list", () => {
250
+ const callbackNewDataIds = mock(() => {});
251
+ render(
252
+ <DraggableList
253
+ callbackNewDataIds={callbackNewDataIds}
254
+ dataIDs={["a", "b", "c"]}
255
+ renderItem={renderItem}
256
+ />
257
+ );
258
+
259
+ act(() => {
260
+ capturedGestures[0]?.onChange?.({translationY: 10000});
261
+ capturedGestures[0]?.onFinalize?.();
262
+ });
263
+
264
+ expect(callbackNewDataIds).toHaveBeenCalledWith(["c", "b", "a"]);
265
+ });
266
+
267
+ it("reports the new order once per unique arrangement", () => {
268
+ const callbackNewDataIds = mock(() => {});
269
+ render(
270
+ <DraggableList
271
+ callbackNewDataIds={callbackNewDataIds}
272
+ dataIDs={["a", "b"]}
273
+ renderItem={renderItem}
274
+ />
275
+ );
276
+
277
+ act(() => {
278
+ capturedGestures[0]?.onFinalize?.();
279
+ capturedGestures[0]?.onFinalize?.();
280
+ });
281
+
282
+ expect(callbackNewDataIds).toHaveBeenCalledTimes(1);
283
+ expect(callbackNewDataIds).toHaveBeenCalledWith(["a", "b"]);
284
+ });
285
+ });
286
+
287
+ describe("animated styles", () => {
288
+ const originalOS = Platform.OS;
289
+
290
+ afterEach(() => {
291
+ Platform.OS = originalOS;
292
+ });
293
+
294
+ it("omits shadows on Android", () => {
295
+ Platform.OS = "android";
296
+ const {getByText} = render(
297
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["a"]} renderItem={renderItem} />
298
+ );
299
+
300
+ expect(getByText("a")).toBeTruthy();
301
+ });
302
+
303
+ it("adds shadow styles on iOS", () => {
304
+ Platform.OS = "ios";
305
+ const {getByText} = render(
306
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["a"]} renderItem={renderItem} />
307
+ );
308
+
309
+ expect(getByText("a")).toBeTruthy();
310
+ });
311
+ });
312
+
313
+ it("mirrors the shared positions into state", () => {
314
+ let invocations = 0;
315
+ const reactionSpy = spyOn(Reanimated, "useAnimatedReaction").mockImplementation(((
316
+ prepare: () => unknown,
317
+ react: (current: unknown, previous: unknown) => void
318
+ ) => {
319
+ invocations += 1;
320
+ // Only run the first registered reaction (the list-level one) so the
321
+ // render-phase state update settles instead of looping.
322
+ if (invocations === 1) {
323
+ react(prepare(), undefined);
324
+ }
325
+ }) as unknown as typeof Reanimated.useAnimatedReaction);
326
+
327
+ const {getByText} = render(
328
+ <DraggableList callbackNewDataIds={() => {}} dataIDs={["a", "b"]} renderItem={renderItem} />
329
+ );
330
+
331
+ expect(getByText("a")).toBeTruthy();
332
+ reactionSpy.mockRestore();
333
+ });
334
+
335
+ describe("DragItem", () => {
336
+ const baseProps = {
337
+ index: 0,
338
+ item: "a",
339
+ itemBorderRadius: 8,
340
+ itemHeight: 50,
341
+ itemsCount: 1,
342
+ itemsGap: 5,
343
+ plainPosition: 0,
344
+ positions: {value: {a: 0}},
345
+ renderItem,
346
+ scrollY: {value: 0},
347
+ };
348
+
349
+ it("syncs its offset when the shared positions change", () => {
350
+ const reactionSpy = spyOn(Reanimated, "useAnimatedReaction").mockImplementation(((
351
+ prepare: () => unknown,
352
+ react: (current: unknown, previous: unknown) => void
353
+ ) => {
354
+ react(prepare(), undefined);
355
+ }) as unknown as typeof Reanimated.useAnimatedReaction);
356
+
357
+ const {getByText} = render(
358
+ <View>
359
+ <DragItem {...baseProps} item="b" itemsCount={2} positions={{value: {a: 0, b: 1}}} />
360
+ </View>
361
+ );
362
+
363
+ expect(getByText("b")).toBeTruthy();
364
+ reactionSpy.mockRestore();
365
+ });
366
+
367
+ it("falls back to a zero offset when the computed offset is not a number", () => {
368
+ const {getByText} = render(
369
+ <View>
370
+ <DragItem {...baseProps} itemHeight={Number.NaN} />
371
+ </View>
372
+ );
373
+
374
+ expect(getByText("a")).toBeTruthy();
375
+ });
376
+ });
377
+ });
@@ -0,0 +1,69 @@
1
+ import {describe, expect, it} from "bun:test";
2
+ import type {ReactTestRendererJSON} from "react-test-renderer";
3
+
4
+ import {EditableCard} from "./EditableCard";
5
+ import {Text} from "./Text";
6
+ import {renderWithTheme} from "./test-utils";
7
+
8
+ describe("EditableCard", () => {
9
+ it("renders correctly with all props", () => {
10
+ const {toJSON} = renderWithTheme(
11
+ <EditableCard
12
+ badge={{iconName: "check", secondary: true, status: "success", value: "Verified"}}
13
+ description="123 Main Street"
14
+ helperText="Last updated 2 days ago"
15
+ iconName="location-dot"
16
+ onEdit={() => {}}
17
+ title="Home Address"
18
+ />
19
+ );
20
+ expect(toJSON()).toMatchSnapshot();
21
+ });
22
+
23
+ it("renders title, description and helper text", () => {
24
+ const {getByText} = renderWithTheme(
25
+ <EditableCard
26
+ description="123 Main Street"
27
+ helperText="Last updated 2 days ago"
28
+ title="Home Address"
29
+ />
30
+ );
31
+ expect(getByText("Home Address")).toBeTruthy();
32
+ expect(getByText("123 Main Street")).toBeTruthy();
33
+ expect(getByText("Last updated 2 days ago")).toBeTruthy();
34
+ });
35
+
36
+ it("renders the badge", () => {
37
+ const {getByText} = renderWithTheme(
38
+ <EditableCard
39
+ badge={{secondary: true, status: "success", value: "Verified"}}
40
+ title="Home Address"
41
+ />
42
+ );
43
+ expect(getByText("Verified")).toBeTruthy();
44
+ });
45
+
46
+ it("uses the attention surface when attention is set", () => {
47
+ const {toJSON} = renderWithTheme(
48
+ <EditableCard attention description="123 Main Street" title="Home Address" />
49
+ );
50
+ const rendered = toJSON() as ReactTestRendererJSON;
51
+ expect(rendered.props.style).toMatchObject({backgroundColor: "#F2F9FA"});
52
+ });
53
+
54
+ it("renders children below the text content", () => {
55
+ const {getByText} = renderWithTheme(
56
+ <EditableCard title="Home Address">
57
+ <Text>Extra content</Text>
58
+ </EditableCard>
59
+ );
60
+ expect(getByText("Extra content")).toBeTruthy();
61
+ });
62
+
63
+ it("renders with testID", () => {
64
+ const {getByTestId} = renderWithTheme(
65
+ <EditableCard testID="editable-card" title="Home Address" />
66
+ );
67
+ expect(getByTestId("editable-card")).toBeTruthy();
68
+ });
69
+ });
@@ -0,0 +1,73 @@
1
+ import type React from "react";
2
+
3
+ import {Badge} from "./Badge";
4
+ import {Box} from "./Box";
5
+ import {Card} from "./Card";
6
+ import type {EditableCardProps} from "./Common";
7
+ import {Icon} from "./Icon";
8
+ import {IconButton} from "./IconButton";
9
+ import {Text} from "./Text";
10
+
11
+ export const EditableCard = ({
12
+ children,
13
+ attention = false,
14
+ badge,
15
+ color,
16
+ description,
17
+ editAccessibilityLabel = "Edit",
18
+ helperText,
19
+ iconName,
20
+ onEdit,
21
+ padding = 3,
22
+ title,
23
+ ...rest
24
+ }: EditableCardProps): React.ReactElement => {
25
+ return (
26
+ <Card
27
+ borderLeft="default"
28
+ borderRight="default"
29
+ color={color ?? (attention ? "secondaryExtraLight" : "base")}
30
+ direction="row"
31
+ gap={2}
32
+ padding={padding}
33
+ rounding="md"
34
+ width="100%"
35
+ {...rest}
36
+ >
37
+ {Boolean(iconName) && (
38
+ <Box paddingY={1}>
39
+ <Icon iconName={iconName!} size="md" />
40
+ </Box>
41
+ )}
42
+ <Box direction="column" flex="grow" gap={1} minWidth={0}>
43
+ {(Boolean(title) || Boolean(badge)) && (
44
+ <Box alignItems="center" direction="row" gap={2}>
45
+ {Boolean(title) && (
46
+ <Box flex="shrink" minWidth={0}>
47
+ <Text bold size="md" truncate>
48
+ {title}
49
+ </Text>
50
+ </Box>
51
+ )}
52
+ {Boolean(badge) && <Badge {...badge!} />}
53
+ </Box>
54
+ )}
55
+ {Boolean(description) && <Text size="md">{description}</Text>}
56
+ {Boolean(helperText) && (
57
+ <Text color="secondaryLight" size="sm">
58
+ {helperText}
59
+ </Text>
60
+ )}
61
+ {children}
62
+ </Box>
63
+ {Boolean(onEdit) && (
64
+ <IconButton
65
+ accessibilityLabel={editAccessibilityLabel}
66
+ iconName="pencil"
67
+ onClick={onEdit!}
68
+ variant="ghost"
69
+ />
70
+ )}
71
+ </Card>
72
+ );
73
+ };