@terreno/ui 0.23.0 → 0.24.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/dist/AiSuggestionBox.d.ts +11 -0
  2. package/dist/AiSuggestionBox.js +50 -23
  3. package/dist/AiSuggestionBox.js.map +1 -1
  4. package/dist/Button.js +4 -3
  5. package/dist/Button.js.map +1 -1
  6. package/dist/Common.d.ts +15 -2
  7. package/dist/Common.js.map +1 -1
  8. package/dist/IconButton.js +8 -4
  9. package/dist/IconButton.js.map +1 -1
  10. package/dist/icons/SparklesIcon.d.ts +7 -0
  11. package/dist/icons/SparklesIcon.js +32 -0
  12. package/dist/icons/SparklesIcon.js.map +1 -0
  13. package/dist/icons/index.d.ts +1 -0
  14. package/dist/icons/index.js +1 -0
  15. package/dist/icons/index.js.map +1 -1
  16. package/package.json +2 -2
  17. package/src/ActionSheet.test.tsx +96 -0
  18. package/src/AiSuggestionBox.test.tsx +184 -15
  19. package/src/AiSuggestionBox.tsx +72 -55
  20. package/src/Button.test.tsx +31 -1
  21. package/src/Button.tsx +5 -4
  22. package/src/Common.ts +16 -2
  23. package/src/ErrorBoundary.test.tsx +3 -4
  24. package/src/IconButton.test.tsx +14 -0
  25. package/src/IconButton.tsx +9 -4
  26. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +489 -102
  27. package/src/__snapshots__/Button.test.tsx.snap +18 -1
  28. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +2 -0
  29. package/src/__snapshots__/ErrorPage.test.tsx.snap +1 -0
  30. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +2 -0
  31. package/src/__snapshots__/HeightField.test.tsx.snap +5 -0
  32. package/src/__snapshots__/IconButton.test.tsx.snap +4 -0
  33. package/src/__snapshots__/InfoModalIcon.test.tsx.snap +4 -0
  34. package/src/__snapshots__/Modal.test.tsx.snap +3 -0
  35. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +2 -0
  36. package/src/__snapshots__/Page.test.tsx.snap +1 -0
  37. package/src/icons/SparklesIcon.test.tsx +16 -0
  38. package/src/icons/SparklesIcon.tsx +38 -0
  39. package/src/icons/__snapshots__/SparklesIcon.test.tsx.snap +47 -0
  40. package/src/icons/index.ts +1 -0
  41. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +3 -0
  42. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +2 -0
  43. package/src/testing/resolveTestId.test.ts +101 -0
@@ -1,9 +1,22 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
- import {fireEvent} from "@testing-library/react-native";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import type {ReactTestInstance} from "react-test-renderer";
3
4
 
5
+ import {AiSuggestionBox} from "./AiSuggestionBox";
4
6
  import {TextArea} from "./TextArea";
5
7
  import {renderWithTheme} from "./test-utils";
6
8
 
9
+ /**
10
+ * Presses a Button-backed element and waits out the press handler's async haptic +
11
+ * leading-edge debounce so the onClick side effects have applied before asserting.
12
+ */
13
+ const pressButton = async (element: ReactTestInstance): Promise<void> => {
14
+ await act(async () => {
15
+ fireEvent.press(element);
16
+ await new Promise((resolve) => setTimeout(resolve, 100));
17
+ });
18
+ };
19
+
7
20
  describe("AiSuggestionBox in TextArea", () => {
8
21
  describe("not-started state", () => {
9
22
  it("should render default not-started text", () => {
@@ -100,7 +113,7 @@ describe("AiSuggestionBox in TextArea", () => {
100
113
  expect(getByText("Add to note")).toBeTruthy();
101
114
  });
102
115
 
103
- it("should call onAdd when Add to note is pressed", () => {
116
+ it("should call onAdd when Add to note is pressed", async () => {
104
117
  const mockOnAdd = mock(() => {});
105
118
  const {getByLabelText} = renderWithTheme(
106
119
  <TextArea
@@ -115,11 +128,11 @@ describe("AiSuggestionBox in TextArea", () => {
115
128
  />
116
129
  );
117
130
 
118
- fireEvent.press(getByLabelText("Add to note"));
131
+ await pressButton(getByLabelText("Add to note"));
119
132
  expect(mockOnAdd).toHaveBeenCalledTimes(1);
120
133
  });
121
134
 
122
- it("should collapse when Hide is pressed", () => {
135
+ it("should collapse when Hide is pressed", async () => {
123
136
  const {getByLabelText, getByText, queryByText} = renderWithTheme(
124
137
  <TextArea
125
138
  aiSuggestion={{
@@ -135,14 +148,14 @@ describe("AiSuggestionBox in TextArea", () => {
135
148
 
136
149
  expect(getByText("Suggestion text")).toBeTruthy();
137
150
 
138
- fireEvent.press(getByLabelText("Hide suggestion"));
151
+ await pressButton(getByLabelText("Hide"));
139
152
 
140
153
  expect(queryByText("Suggestion text")).toBeNull();
141
154
  expect(getByText("AI-generated note (hidden)")).toBeTruthy();
142
155
  expect(getByText("Show")).toBeTruthy();
143
156
  });
144
157
 
145
- it("should expand when Show is pressed after collapsing", () => {
158
+ it("should expand when Show is pressed after collapsing", async () => {
146
159
  const {getByLabelText, getByText} = renderWithTheme(
147
160
  <TextArea
148
161
  aiSuggestion={{
@@ -156,15 +169,15 @@ describe("AiSuggestionBox in TextArea", () => {
156
169
  />
157
170
  );
158
171
 
159
- fireEvent.press(getByLabelText("Hide suggestion"));
172
+ await pressButton(getByLabelText("Hide"));
160
173
  expect(getByText("AI-generated note (hidden)")).toBeTruthy();
161
174
 
162
- fireEvent.press(getByLabelText("Show suggestion"));
175
+ await pressButton(getByLabelText("Show"));
163
176
  expect(getByText("Suggestion text")).toBeTruthy();
164
177
  expect(getByText("AI-generated note")).toBeTruthy();
165
178
  });
166
179
 
167
- it("should call onHide when Hide is pressed", () => {
180
+ it("should call onHide when Hide is pressed", async () => {
168
181
  const mockOnHide = mock(() => {});
169
182
  const {getByLabelText} = renderWithTheme(
170
183
  <TextArea
@@ -180,11 +193,11 @@ describe("AiSuggestionBox in TextArea", () => {
180
193
  />
181
194
  );
182
195
 
183
- fireEvent.press(getByLabelText("Hide suggestion"));
196
+ await pressButton(getByLabelText("Hide"));
184
197
  expect(mockOnHide).toHaveBeenCalledTimes(1);
185
198
  });
186
199
 
187
- it("should call onShow when Show is pressed", () => {
200
+ it("should call onShow when Show is pressed", async () => {
188
201
  const mockOnShow = mock(() => {});
189
202
  const {getByLabelText} = renderWithTheme(
190
203
  <TextArea
@@ -200,15 +213,57 @@ describe("AiSuggestionBox in TextArea", () => {
200
213
  />
201
214
  );
202
215
 
203
- fireEvent.press(getByLabelText("Hide suggestion"));
204
- fireEvent.press(getByLabelText("Show suggestion"));
216
+ await pressButton(getByLabelText("Hide"));
217
+ await pressButton(getByLabelText("Show"));
218
+ expect(mockOnShow).toHaveBeenCalledTimes(1);
219
+ });
220
+ });
221
+
222
+ describe("hidden state", () => {
223
+ it("should render collapsed with the hidden heading", () => {
224
+ const {getByText, queryByText} = renderWithTheme(
225
+ <TextArea
226
+ aiSuggestion={{
227
+ onAdd: () => {},
228
+ status: "hidden",
229
+ text: "Hidden suggestion",
230
+ }}
231
+ onChange={() => {}}
232
+ value=""
233
+ />
234
+ );
235
+
236
+ expect(getByText("AI-generated note (hidden)")).toBeTruthy();
237
+ expect(getByText("Show")).toBeTruthy();
238
+ expect(queryByText("Hidden suggestion")).toBeNull();
239
+ });
240
+
241
+ it("should call onShow and expand when Show is pressed", async () => {
242
+ const mockOnShow = mock(() => {});
243
+ const {getByLabelText, getByText} = renderWithTheme(
244
+ <TextArea
245
+ aiSuggestion={{
246
+ onAdd: () => {},
247
+ onShow: mockOnShow,
248
+ status: "hidden",
249
+ text: "Hidden suggestion",
250
+ }}
251
+ onChange={() => {}}
252
+ testID="test"
253
+ value=""
254
+ />
255
+ );
256
+
257
+ await pressButton(getByLabelText("Show"));
258
+
205
259
  expect(mockOnShow).toHaveBeenCalledTimes(1);
260
+ expect(getByText("Hidden suggestion")).toBeTruthy();
206
261
  });
207
262
  });
208
263
 
209
264
  describe("added state", () => {
210
- it("should render added heading", () => {
211
- const {getByText} = renderWithTheme(
265
+ it("should render collapsed with the added heading", () => {
266
+ const {getByText, queryByText} = renderWithTheme(
212
267
  <TextArea
213
268
  aiSuggestion={{
214
269
  onAdd: () => {},
@@ -221,7 +276,104 @@ describe("AiSuggestionBox in TextArea", () => {
221
276
  );
222
277
 
223
278
  expect(getByText("AI-generated note added!")).toBeTruthy();
279
+ expect(getByText("Show")).toBeTruthy();
280
+ expect(queryByText("Added suggestion")).toBeNull();
281
+ });
282
+
283
+ it("should expand locally on Show without persisting, keeping Add to note available", async () => {
284
+ const mockOnShow = mock(() => {});
285
+ const {getByLabelText, getByText} = renderWithTheme(
286
+ <TextArea
287
+ aiSuggestion={{
288
+ onAdd: () => {},
289
+ onShow: mockOnShow,
290
+ status: "added",
291
+ text: "Added suggestion",
292
+ }}
293
+ onChange={() => {}}
294
+ testID="test"
295
+ value=""
296
+ />
297
+ );
298
+
299
+ await pressButton(getByLabelText("Show"));
300
+
301
+ // Expanding an added suggestion must not call onShow — that would reset the
302
+ // persisted acceptance record.
303
+ expect(mockOnShow).not.toHaveBeenCalled();
224
304
  expect(getByText("Added suggestion")).toBeTruthy();
305
+ expect(getByText("Add to note")).toBeTruthy();
306
+ });
307
+
308
+ it("should collapse locally on Hide without persisting", async () => {
309
+ const mockOnHide = mock(() => {});
310
+ const {getByLabelText, getByText} = renderWithTheme(
311
+ <TextArea
312
+ aiSuggestion={{
313
+ onAdd: () => {},
314
+ onHide: mockOnHide,
315
+ status: "added",
316
+ text: "Added suggestion",
317
+ }}
318
+ onChange={() => {}}
319
+ testID="test"
320
+ value=""
321
+ />
322
+ );
323
+
324
+ await pressButton(getByLabelText("Show"));
325
+ await pressButton(getByLabelText("Hide"));
326
+
327
+ expect(mockOnHide).not.toHaveBeenCalled();
328
+ expect(getByText("AI-generated note added!")).toBeTruthy();
329
+ });
330
+ });
331
+
332
+ describe("collapse behavior across status transitions", () => {
333
+ it("should collapse when the status transitions from ready to added", () => {
334
+ const {getByText, queryByText, rerender} = renderWithTheme(
335
+ <AiSuggestionBox onAdd={() => {}} status="ready" text="Suggestion text" />
336
+ );
337
+
338
+ expect(getByText("Suggestion text")).toBeTruthy();
339
+
340
+ rerender(<AiSuggestionBox onAdd={() => {}} status="added" text="Suggestion text" />);
341
+
342
+ expect(getByText("AI-generated note added!")).toBeTruthy();
343
+ expect(queryByText("Suggestion text")).toBeNull();
344
+ });
345
+
346
+ it("should keep the box expanded when a stale hide lands after a newer Show click", async () => {
347
+ const mockOnHide = mock(() => {});
348
+ const mockOnShow = mock(() => {});
349
+ const suggestion = {
350
+ onAdd: () => {},
351
+ onHide: mockOnHide,
352
+ onShow: mockOnShow,
353
+ text: "Suggestion text",
354
+ };
355
+ const {getByLabelText, getByText, queryByText, rerender} = renderWithTheme(
356
+ <AiSuggestionBox status="ready" {...suggestion} />
357
+ );
358
+
359
+ await pressButton(getByLabelText("Hide"));
360
+ expect(mockOnHide).toHaveBeenCalledTimes(1);
361
+
362
+ await pressButton(getByLabelText("Show"));
363
+ // A Show clicked while the hide is still in flight must persist the un-hide too,
364
+ // so the backend converges on the user's latest choice.
365
+ expect(mockOnShow).toHaveBeenCalledTimes(1);
366
+ expect(getByText("Suggestion text")).toBeTruthy();
367
+
368
+ // The earlier hide's refetch lands after the newer Show click — the box must not
369
+ // snap back to collapsed.
370
+ rerender(<AiSuggestionBox status="hidden" {...suggestion} />);
371
+ expect(getByText("Suggestion text")).toBeTruthy();
372
+ expect(queryByText("AI-generated note (hidden)")).toBeNull();
373
+
374
+ // The show mutation then lands and the box stays expanded.
375
+ rerender(<AiSuggestionBox status="ready" {...suggestion} />);
376
+ expect(getByText("Suggestion text")).toBeTruthy();
225
377
  });
226
378
  });
227
379
 
@@ -353,6 +505,23 @@ describe("AiSuggestionBox in TextArea", () => {
353
505
  expect(component.toJSON()).toMatchSnapshot();
354
506
  });
355
507
 
508
+ it("should match snapshot for hidden state", () => {
509
+ const component = renderWithTheme(
510
+ <TextArea
511
+ aiSuggestion={{
512
+ feedback: null,
513
+ onAdd: () => {},
514
+ status: "hidden",
515
+ text: "AI-generated suggestion text.",
516
+ }}
517
+ onChange={() => {}}
518
+ testID="test"
519
+ value=""
520
+ />
521
+ );
522
+ expect(component.toJSON()).toMatchSnapshot();
523
+ });
524
+
356
525
  it("should match snapshot for added state", () => {
357
526
  const component = renderWithTheme(
358
527
  <TextArea
@@ -1,8 +1,10 @@
1
1
  import {type FC, useCallback, useEffect, useState} from "react";
2
2
  import {Pressable, View} from "react-native";
3
3
 
4
+ import {Button} from "./Button";
4
5
  import type {AiSuggestionProps} from "./Common";
5
6
  import {Icon} from "./Icon";
7
+ import {SparklesIcon} from "./icons";
6
8
  import {Text} from "./Text";
7
9
  import {useTheme} from "./Theme";
8
10
 
@@ -10,6 +12,17 @@ export interface AiSuggestionBoxProps extends AiSuggestionProps {
10
12
  testID?: string;
11
13
  }
12
14
 
15
+ /**
16
+ * Inline AI suggestion box rendered inside TextField/TextArea via the `aiSuggestion` prop.
17
+ *
18
+ * Expansion is derived from the persisted `status` (`ready` expands; `hidden` and `added`
19
+ * condense into the collapsed header row), but an explicit user Show/Hide toggle always
20
+ * wins — including while a hide/show mutation is still in flight — so a quick
21
+ * Hide-then-Show never snaps back to collapsed when the earlier hide's refetch lands.
22
+ * Hide/Show on a non-`added` suggestion also invoke `onHide`/`onShow` so consumers can
23
+ * persist the choice; toggling an `added` suggestion is purely local so the acceptance
24
+ * record is never reset. "Add to note" stays available after a first add for re-adds.
25
+ */
13
26
  export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
14
27
  status,
15
28
  text,
@@ -23,15 +36,26 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
23
36
  testID,
24
37
  }) => {
25
38
  const {theme} = useTheme();
26
- const [expanded, setExpanded] = useState(true);
27
-
28
- // Re-expand when a new suggestion arrives or is added
39
+ // The user's last explicit Show/Hide choice. While set, it overrides the
40
+ // status-derived default so in-flight hide/show mutations can't undo a newer click.
41
+ const [expandedIntent, setExpandedIntent] = useState<boolean | null>(null);
42
+
43
+ // Reconcile the local intent with persisted status transitions. Accepting a suggestion
44
+ // (`added`) always condenses the box, and once the persisted status agrees with the
45
+ // user's intent the override is dropped so later transitions (e.g. a regenerated
46
+ // suggestion flipping back to `ready`) use their status defaults. An intent that
47
+ // disagrees with the incoming status is kept — that status is a stale in-flight
48
+ // hide/show landing after a newer click, and must not undo it.
29
49
  useEffect(() => {
30
- if (status === "ready" || status === "added") {
31
- setExpanded(true);
32
- }
50
+ setExpandedIntent((current) => {
51
+ if (current === null || status === "added") {
52
+ return null;
53
+ }
54
+ return current === (status === "ready") ? null : current;
55
+ });
33
56
  }, [status]);
34
57
 
58
+ const expanded = expandedIntent ?? status === "ready";
35
59
  const isAdded = status === "added";
36
60
 
37
61
  const backgroundColor = isAdded
@@ -68,14 +92,24 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
68
92
  : "AI-generated note (hidden)";
69
93
 
70
94
  const handleHide = useCallback(() => {
71
- setExpanded(false);
72
- onHide?.();
73
- }, [onHide]);
95
+ setExpandedIntent(false);
96
+ // Persist the hide for any non-`added` suggestion — even when the status still reads
97
+ // `hidden` locally (an un-hide may be in flight). Hiding an `added` suggestion is a
98
+ // purely local collapse so the acceptance record stays intact.
99
+ if (status !== "added") {
100
+ onHide?.();
101
+ }
102
+ }, [status, onHide]);
74
103
 
75
104
  const handleShow = useCallback(() => {
76
- setExpanded(true);
77
- onShow?.();
78
- }, [onShow]);
105
+ setExpandedIntent(true);
106
+ // Persist the un-hide for any non-`added` suggestion — even when the status still
107
+ // reads `ready` locally (a hide may be in flight, and this Show must override it).
108
+ // Expanding an `added` suggestion must not reset its status.
109
+ if (status !== "added") {
110
+ onShow?.();
111
+ }
112
+ }, [status, onShow]);
79
113
 
80
114
  const handleThumbsUp = useCallback(() => {
81
115
  if (!onFeedback) {
@@ -106,7 +140,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
106
140
  <Icon
107
141
  color={feedback === "like" ? "secondaryDark" : "secondaryLight"}
108
142
  iconName="thumbs-up"
109
- size="xs"
143
+ size="md"
110
144
  type={feedback === "like" ? "solid" : "regular"}
111
145
  />
112
146
  </Pressable>
@@ -120,7 +154,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
120
154
  <Icon
121
155
  color={feedback === "dislike" ? "secondaryDark" : "secondaryLight"}
122
156
  iconName="thumbs-down"
123
- size="xs"
157
+ size="md"
124
158
  type={feedback === "dislike" ? "solid" : "regular"}
125
159
  />
126
160
  </Pressable>
@@ -131,7 +165,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
131
165
  return (
132
166
  <View style={containerStyle} testID={testID}>
133
167
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
134
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
168
+ <SparklesIcon fill={theme.text.secondaryDark} />
135
169
  <View style={{flex: 1}}>
136
170
  <Text color="secondaryDark" size="sm">
137
171
  {headingText}
@@ -146,24 +180,20 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
146
180
  return (
147
181
  <View style={{...containerStyle, flexDirection: "column"}} testID={testID}>
148
182
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
149
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
183
+ <SparklesIcon fill={theme.text.secondaryDark} />
150
184
  <View style={{flex: 1}}>
151
185
  <Text color="secondaryDark" size="sm">
152
186
  {headingText}
153
187
  </Text>
154
188
  </View>
155
189
  <View style={{alignItems: "center", flexDirection: "row", gap: 4}}>
156
- <Pressable
157
- accessibilityLabel="Show suggestion"
158
- accessibilityRole="button"
159
- onPress={handleShow}
160
- style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
190
+ <Button
191
+ onClick={handleShow}
192
+ size="sm"
161
193
  testID={testID ? `${testID}-show` : undefined}
162
- >
163
- <Text bold color="secondaryDark" size="sm">
164
- Show
165
- </Text>
166
- </Pressable>
194
+ text="Show"
195
+ variant="ghost"
196
+ />
167
197
  {renderFeedback()}
168
198
  </View>
169
199
  </View>
@@ -174,7 +204,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
174
204
  return (
175
205
  <View style={{...containerStyle, alignItems: "flex-end"}} testID={testID}>
176
206
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
177
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
207
+ <SparklesIcon fill={theme.text.secondaryDark} />
178
208
  <View style={{flex: 1}}>
179
209
  <Text color="secondaryDark" size="sm">
180
210
  {headingText}
@@ -198,35 +228,22 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
198
228
  width: "100%",
199
229
  }}
200
230
  >
201
- <Pressable
202
- accessibilityLabel="Hide suggestion"
203
- accessibilityRole="button"
204
- onPress={handleHide}
205
- style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
231
+ <Button
232
+ onClick={handleHide}
233
+ size="sm"
206
234
  testID={testID ? `${testID}-hide` : undefined}
207
- >
208
- <Text bold color="secondaryDark" size="sm">
209
- Hide
210
- </Text>
211
- </Pressable>
212
- <Pressable
213
- accessibilityLabel="Add to note"
214
- accessibilityRole="button"
215
- onPress={onAdd}
216
- style={{
217
- alignItems: "center",
218
- backgroundColor: theme.surface.secondaryDark,
219
- borderRadius: 360,
220
- height: 28,
221
- justifyContent: "center",
222
- paddingHorizontal: 16,
223
- }}
224
- testID={testID ? `${testID}-add` : undefined}
225
- >
226
- <Text bold color="inverted" size="sm">
227
- Add to note
228
- </Text>
229
- </Pressable>
235
+ text="Hide"
236
+ variant="ghost"
237
+ />
238
+ {Boolean(onAdd) && (
239
+ <Button
240
+ onClick={onAdd!}
241
+ size="sm"
242
+ testID={testID ? `${testID}-add` : undefined}
243
+ text="Add to note"
244
+ variant="secondary"
245
+ />
246
+ )}
230
247
  </View>
231
248
  </View>
232
249
  );
@@ -1,8 +1,10 @@
1
- import {describe, expect, it, mock} from "bun:test";
1
+ import {describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
 
4
4
  import {Button} from "./Button";
5
+ import {isMobileDevice} from "./MediaQuery";
5
6
  import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
7
+ import * as Utilities from "./Utilities";
6
8
 
7
9
  describe("Button", () => {
8
10
  it("renders correctly with default props", () => {
@@ -334,4 +336,32 @@ describe("Button", () => {
334
336
  const tree = renderWithTheme(<Button onClick={() => {}} size="sm" text="Small" />).toJSON();
335
337
  expect(tree).toBeTruthy();
336
338
  });
339
+
340
+ it("does not render tooltip wrapper when isMobileDevice is true", () => {
341
+ const nativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
342
+ (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => true);
343
+
344
+ const {getByText, toJSON} = renderWithTheme(
345
+ <Button onClick={() => {}} text="No Tooltip" tooltipText="Should not wrap" />
346
+ );
347
+
348
+ expect(getByText("No Tooltip")).toBeTruthy();
349
+ const tree = JSON.stringify(toJSON());
350
+ expect(tree).not.toContain("Should not wrap");
351
+ nativeSpy.mockRestore();
352
+ (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);
353
+ });
354
+
355
+ it("renders tooltip wrapper when tooltipText is provided and not native", () => {
356
+ const nativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
357
+ (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);
358
+
359
+ const {getByText} = renderWithTheme(
360
+ <Button onClick={() => {}} text="With Tooltip" tooltipText="Helpful tip" />
361
+ );
362
+
363
+ expect(getByText("With Tooltip")).toBeTruthy();
364
+ nativeSpy.mockRestore();
365
+ (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);
366
+ });
337
367
  });
package/src/Button.tsx CHANGED
@@ -81,7 +81,7 @@ const ButtonComponent: React.FC<ButtonProps> = ({
81
81
  } else if (variant === "destructive") {
82
82
  bgColor = theme.surface.error;
83
83
  } else if (variant === "ghost") {
84
- bgColor = theme.surface.base;
84
+ bgColor = "transparent";
85
85
  textColor = theme.surface.secondaryDark;
86
86
  }
87
87
 
@@ -146,9 +146,10 @@ const ButtonComponent: React.FC<ButtonProps> = ({
146
146
  borderRadius: theme.radius.rounded,
147
147
  borderWidth,
148
148
  flexDirection: "column",
149
+ height: size === "sm" ? 28 : undefined,
149
150
  justifyContent: "center",
150
151
  paddingHorizontal: size === "sm" ? 16 : 20,
151
- paddingVertical: 8 - (borderWidth ?? 0),
152
+ paddingVertical: size === "sm" ? 0 : 8 - (borderWidth ?? 0),
152
153
  width: fullWidth ? "100%" : "auto",
153
154
  }}
154
155
  testID={testID}
@@ -164,9 +165,9 @@ const ButtonComponent: React.FC<ButtonProps> = ({
164
165
  }}
165
166
  >
166
167
  {CustomIcon ? (
167
- <CustomIcon color={color ?? theme.text.inverted} size={16} />
168
+ <CustomIcon color={color ?? theme.text.inverted} size={size === "sm" ? 12 : 16} />
168
169
  ) : (
169
- <FontAwesome6 color={color} name={iconName} size={16} solid />
170
+ <FontAwesome6 color={color} name={iconName} size={size === "sm" ? 12 : 16} solid />
170
171
  )}
171
172
  </View>
172
173
  )}
package/src/Common.ts CHANGED
@@ -762,10 +762,18 @@ export interface ErrorTextProps {
762
762
  }
763
763
 
764
764
  export interface AiSuggestionProps {
765
- status: "not-started" | "generating" | "ready" | "added";
765
+ /**
766
+ * Persisted suggestion state. `ready` renders expanded; `hidden` and `added` render
767
+ * condensed into the collapsed header row (re-expandable with "Show") so a hidden or
768
+ * accepted suggestion never disappears entirely.
769
+ */
770
+ status: "not-started" | "generating" | "ready" | "added" | "hidden";
766
771
  text?: string;
772
+ /** Adds the suggestion text to the note. Stays available after adding for re-adds. */
767
773
  onAdd?: () => void;
774
+ /** Persists a hide. Called for any non-`added` status when the user presses "Hide". */
768
775
  onHide?: () => void;
776
+ /** Persists an un-hide. Called for any non-`added` status when the user presses "Show". */
769
777
  onShow?: () => void;
770
778
  onFeedback?: (feedback: "like" | "dislike" | null) => void;
771
779
  feedback?: "like" | "dislike" | null;
@@ -1937,6 +1945,12 @@ export interface IconButtonProps extends WithTestID {
1937
1945
  */
1938
1946
  loading?: boolean;
1939
1947
 
1948
+ /**
1949
+ * The size of the button.
1950
+ * @default "default"
1951
+ */
1952
+ size?: "default" | "sm";
1953
+
1940
1954
  /**
1941
1955
  * The ideal position of the tooltip.
1942
1956
  */
@@ -1957,7 +1971,7 @@ export interface IconButtonProps extends WithTestID {
1957
1971
  * The variant of the button, which determines its style.
1958
1972
  * @default "primary"
1959
1973
  */
1960
- variant?: "primary" | "secondary" | "muted" | "destructive" | "navigation";
1974
+ variant?: "primary" | "secondary" | "muted" | "destructive" | "navigation" | "ghost";
1961
1975
 
1962
1976
  /**
1963
1977
  * If true, a confirmation modal will be shown before the onClick action.
@@ -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((onError as any).mock.calls[0]).toEqual([error, "stack trace"]);
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((setStateSpy as any).mock.calls[0][0]).toEqual({error: undefined});
80
+ expect(setStateSpy.mock.calls[0][0]).toEqual({error: undefined});
82
81
  setStateSpy.mockRestore();
83
82
  });
84
83
 
@@ -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