@terreno/ui 0.23.1 → 0.25.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 (80) hide show
  1. package/dist/AIRequestExplorer.js +6 -1
  2. package/dist/AIRequestExplorer.js.map +1 -1
  3. package/dist/ActionSheet.d.ts +1 -0
  4. package/dist/ActionSheet.js +3 -0
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/AiSuggestionBox.d.ts +11 -0
  7. package/dist/AiSuggestionBox.js +50 -23
  8. package/dist/AiSuggestionBox.js.map +1 -1
  9. package/dist/Common.d.ts +25 -1
  10. package/dist/Common.js.map +1 -1
  11. package/dist/CustomSelectField.js +2 -2
  12. package/dist/CustomSelectField.js.map +1 -1
  13. package/dist/FilePickerButton.js +2 -1
  14. package/dist/FilePickerButton.js.map +1 -1
  15. package/dist/PickerSelect.d.ts +10 -2
  16. package/dist/PickerSelect.js +91 -17
  17. package/dist/PickerSelect.js.map +1 -1
  18. package/dist/SelectBadge.js +1 -1
  19. package/dist/SelectBadge.js.map +1 -1
  20. package/dist/SelectField.js +9 -9
  21. package/dist/SelectField.js.map +1 -1
  22. package/dist/WebDropdownMenu.d.ts +36 -5
  23. package/dist/WebDropdownMenu.js +211 -29
  24. package/dist/WebDropdownMenu.js.map +1 -1
  25. package/dist/createWebPortal.d.ts +7 -0
  26. package/dist/createWebPortal.js +3 -0
  27. package/dist/createWebPortal.js.map +1 -0
  28. package/dist/createWebPortal.native.d.ts +7 -0
  29. package/dist/createWebPortal.native.js +2 -0
  30. package/dist/createWebPortal.native.js.map +1 -0
  31. package/dist/fieldElements/FieldHelperText.js +1 -1
  32. package/dist/fieldElements/FieldHelperText.js.map +1 -1
  33. package/dist/icons/SparklesIcon.d.ts +7 -0
  34. package/dist/icons/SparklesIcon.js +32 -0
  35. package/dist/icons/SparklesIcon.js.map +1 -0
  36. package/dist/icons/index.d.ts +1 -0
  37. package/dist/icons/index.js +1 -0
  38. package/dist/icons/index.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/AIRequestExplorer.tsx +6 -1
  41. package/src/ActionSheet.test.tsx +198 -2
  42. package/src/ActionSheet.tsx +4 -0
  43. package/src/AiSuggestionBox.test.tsx +184 -15
  44. package/src/AiSuggestionBox.tsx +72 -55
  45. package/src/Common.ts +28 -1
  46. package/src/CustomSelectField.test.tsx +13 -3
  47. package/src/CustomSelectField.tsx +2 -0
  48. package/src/EmojiSelector.test.tsx +153 -0
  49. package/src/FilePickerButton.tsx +2 -1
  50. package/src/Modal.test.tsx +47 -0
  51. package/src/PickerSelect.test.tsx +253 -14
  52. package/src/PickerSelect.tsx +206 -49
  53. package/src/SelectBadge.tsx +1 -0
  54. package/src/SelectBadge.web.test.tsx +10 -0
  55. package/src/SelectField.tsx +19 -15
  56. package/src/WebDropdownMenu.test.tsx +449 -0
  57. package/src/WebDropdownMenu.tsx +405 -60
  58. package/src/__snapshots__/AddressField.test.tsx.snap +2088 -665
  59. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +489 -102
  60. package/src/__snapshots__/CustomSelectField.test.tsx.snap +2118 -1369
  61. package/src/__snapshots__/Field.test.tsx.snap +3787 -1806
  62. package/src/__snapshots__/HeightField.test.tsx.snap +3 -0
  63. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -7
  64. package/src/__snapshots__/SelectField.test.tsx.snap +1548 -1102
  65. package/src/__snapshots__/Slider.test.tsx.snap +3 -0
  66. package/src/__snapshots__/TextArea.test.tsx.snap +3 -0
  67. package/src/__snapshots__/TextField.test.tsx.snap +3 -0
  68. package/src/__snapshots__/TimezonePicker.test.tsx.snap +2499 -1353
  69. package/src/createWebPortal.native.ts +8 -0
  70. package/src/createWebPortal.test.tsx +13 -0
  71. package/src/createWebPortal.ts +10 -0
  72. package/src/fieldElements/FieldHelperText.tsx +4 -2
  73. package/src/fieldElements/__snapshots__/FieldHelperText.test.tsx.snap +3 -0
  74. package/src/icons/SparklesIcon.test.tsx +16 -0
  75. package/src/icons/SparklesIcon.tsx +38 -0
  76. package/src/icons/__snapshots__/SparklesIcon.test.tsx.snap +47 -0
  77. package/src/icons/index.ts +1 -0
  78. package/src/table/TableBadge.test.tsx +19 -11
  79. package/src/table/__snapshots__/TableBadge.test.tsx.snap +226 -175
  80. package/src/types/react-dom.d.ts +5 -0
@@ -1,5 +1,7 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
2
  import {act, fireEvent, renderHook} from "@testing-library/react-native";
3
+ import type {ComponentProps} from "react";
4
+ import {Dimensions} from "react-native";
3
5
 
4
6
  import {renderWithTheme} from "./test-utils";
5
7
  import {useWebDropdownAnchor, WebDropdownMenu} from "./WebDropdownMenu";
@@ -164,6 +166,453 @@ describe("WebDropdownMenu", () => {
164
166
  expect(hoveredStyle.backgroundColor).toBeDefined();
165
167
  expect(pressedStyle.backgroundColor).toBeDefined();
166
168
  });
169
+
170
+ it("renders option helper text under the label", () => {
171
+ const optsWithHelper = [
172
+ {helperText: "Extra detail", label: "Alpha", value: "a"},
173
+ {label: "Beta", value: "b"},
174
+ ];
175
+ const {getByText} = renderWithTheme(
176
+ <WebDropdownMenu
177
+ anchor={anchor}
178
+ onClose={() => {}}
179
+ onSelect={() => {}}
180
+ options={optsWithHelper}
181
+ searchable={false}
182
+ visible
183
+ />
184
+ );
185
+ expect(getByText("Extra detail")).toBeTruthy();
186
+ expect(getByText("Alpha")).toBeTruthy();
187
+ });
188
+
189
+ it("filters options by helper text in the menu search", async () => {
190
+ const optsWithHelper = [
191
+ {helperText: "red berry", label: "Apple", value: "apple"},
192
+ {label: "Banana", value: "banana"},
193
+ ];
194
+ const {getByText, getByTestId, queryByText} = renderWithTheme(
195
+ <WebDropdownMenu
196
+ anchor={anchor}
197
+ onClose={() => {}}
198
+ onSelect={() => {}}
199
+ options={optsWithHelper}
200
+ visible
201
+ />
202
+ );
203
+ await act(async () => {
204
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "berry");
205
+ });
206
+ expect(getByText("Apple")).toBeTruthy();
207
+ expect(queryByText("Banana")).toBeNull();
208
+ });
209
+ });
210
+
211
+ describe("WebDropdownMenu positioning", () => {
212
+ const options = [
213
+ {label: "Option A", value: "a"},
214
+ {label: "Option B", value: "b"},
215
+ ];
216
+
217
+ it("positions the menu above the trigger when near the bottom of the screen", () => {
218
+ // Window height is mocked to 812. Place the trigger near the bottom so
219
+ // there is not enough room (< 300px) below it.
220
+ const bottomAnchor = {height: 40, width: 200, x: 16, y: 750};
221
+ const {getByTestId} = renderWithTheme(
222
+ <WebDropdownMenu
223
+ anchor={bottomAnchor}
224
+ onClose={() => {}}
225
+ onSelect={() => {}}
226
+ options={options}
227
+ searchable={false}
228
+ visible
229
+ />
230
+ );
231
+ const menu = getByTestId("web_dropdown_menu");
232
+ const style = Array.isArray(menu.props.style)
233
+ ? Object.assign({}, ...menu.props.style)
234
+ : menu.props.style;
235
+ // Menu should open above: bottom-anchored so it sits flush above the trigger.
236
+ expect(style.bottom).toBe(812 - bottomAnchor.y + 4);
237
+ expect(style.top).toBeUndefined();
238
+ });
239
+
240
+ it("positions the menu below the trigger when there is room below", () => {
241
+ const topAnchor = {height: 40, width: 200, x: 16, y: 32};
242
+ const {getByTestId} = renderWithTheme(
243
+ <WebDropdownMenu
244
+ anchor={topAnchor}
245
+ onClose={() => {}}
246
+ onSelect={() => {}}
247
+ options={options}
248
+ searchable={false}
249
+ visible
250
+ />
251
+ );
252
+ const menu = getByTestId("web_dropdown_menu");
253
+ const style = Array.isArray(menu.props.style)
254
+ ? Object.assign({}, ...menu.props.style)
255
+ : menu.props.style;
256
+ expect(style.top).toBe(topAnchor.y + topAnchor.height + 4);
257
+ expect(style.bottom).toBeUndefined();
258
+ expect(style.maxHeight).toBe(300);
259
+ });
260
+
261
+ it("clamps maxHeight to available space when opening above", () => {
262
+ const originalGet = Dimensions.get;
263
+ Dimensions.get = () => ({fontScale: 1, height: 400, scale: 1, width: 375});
264
+ try {
265
+ // windowHeight=400, anchor y=200 + height=40 + gap=4 => spaceBelow=156.
266
+ // Opens above because 156 < 300 and 200 > 156.
267
+ const midAnchor = {height: 40, width: 200, x: 16, y: 200};
268
+ const {getByTestId} = renderWithTheme(
269
+ <WebDropdownMenu
270
+ anchor={midAnchor}
271
+ onClose={() => {}}
272
+ onSelect={() => {}}
273
+ options={options}
274
+ searchable={false}
275
+ visible
276
+ />
277
+ );
278
+ const menu = getByTestId("web_dropdown_menu");
279
+ const style = Array.isArray(menu.props.style)
280
+ ? Object.assign({}, ...menu.props.style)
281
+ : menu.props.style;
282
+ expect(style.bottom).toBe(400 - midAnchor.y + 4);
283
+ expect(style.top).toBeUndefined();
284
+ expect(style.maxHeight).toBe(midAnchor.y - 4);
285
+ } finally {
286
+ Dimensions.get = originalGet;
287
+ }
288
+ });
289
+ });
290
+
291
+ describe("WebDropdownMenu searchable", () => {
292
+ const anchor = {height: 40, width: 200, x: 16, y: 32};
293
+ const options = [
294
+ {label: "Apple", value: "apple"},
295
+ {label: "Banana", value: "banana"},
296
+ {label: "Cherry", value: "cherry"},
297
+ {label: "Avocado", value: "avocado"},
298
+ ];
299
+
300
+ it("renders a search input by default (searchable defaults to true)", () => {
301
+ const {getByTestId} = renderWithTheme(
302
+ <WebDropdownMenu
303
+ anchor={anchor}
304
+ onClose={() => {}}
305
+ onSelect={() => {}}
306
+ options={options}
307
+ visible
308
+ />
309
+ );
310
+ expect(getByTestId("web_dropdown_search")).toBeTruthy();
311
+ });
312
+
313
+ it("does not render a search input when searchable is false", () => {
314
+ const {queryByTestId} = renderWithTheme(
315
+ <WebDropdownMenu
316
+ anchor={anchor}
317
+ onClose={() => {}}
318
+ onSelect={() => {}}
319
+ options={options}
320
+ searchable={false}
321
+ visible
322
+ />
323
+ );
324
+ expect(queryByTestId("web_dropdown_search")).toBeNull();
325
+ });
326
+
327
+ it("filters options by label when the user types in the search input", () => {
328
+ const {getByTestId, queryByTestId} = renderWithTheme(
329
+ <WebDropdownMenu
330
+ anchor={anchor}
331
+ onClose={() => {}}
332
+ onSelect={() => {}}
333
+ options={options}
334
+ searchable
335
+ visible
336
+ />
337
+ );
338
+
339
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "a");
340
+ expect(getByTestId("web_dropdown_option_apple")).toBeTruthy();
341
+ expect(getByTestId("web_dropdown_option_banana")).toBeTruthy();
342
+ expect(getByTestId("web_dropdown_option_avocado")).toBeTruthy();
343
+ expect(queryByTestId("web_dropdown_option_cherry")).toBeNull();
344
+ });
345
+
346
+ it("shows 'No matching options' when filter matches nothing", () => {
347
+ const {getByTestId, queryByTestId} = renderWithTheme(
348
+ <WebDropdownMenu
349
+ anchor={anchor}
350
+ onClose={() => {}}
351
+ onSelect={() => {}}
352
+ options={options}
353
+ searchable
354
+ visible
355
+ />
356
+ );
357
+
358
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "zzz");
359
+ expect(getByTestId("web_dropdown_no_results")).toBeTruthy();
360
+ expect(queryByTestId("web_dropdown_option_apple")).toBeNull();
361
+ });
362
+
363
+ it("reports the original index when selecting a filtered option", () => {
364
+ const onSelect = mock(() => {});
365
+ const {getByTestId} = renderWithTheme(
366
+ <WebDropdownMenu
367
+ anchor={anchor}
368
+ onClose={() => {}}
369
+ onSelect={onSelect}
370
+ options={options}
371
+ searchable
372
+ visible
373
+ />
374
+ );
375
+
376
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "cherry");
377
+ fireEvent.press(getByTestId("web_dropdown_option_cherry"));
378
+ expect(onSelect).toHaveBeenCalledTimes(1);
379
+ expect(onSelect.mock.calls[0]).toEqual(["cherry", 2]);
380
+ });
381
+
382
+ it("performs case-insensitive filtering", () => {
383
+ const {getByTestId, queryByTestId} = renderWithTheme(
384
+ <WebDropdownMenu
385
+ anchor={anchor}
386
+ onClose={() => {}}
387
+ onSelect={() => {}}
388
+ options={options}
389
+ searchable
390
+ visible
391
+ />
392
+ );
393
+
394
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "BANANA");
395
+ expect(getByTestId("web_dropdown_option_banana")).toBeTruthy();
396
+ expect(queryByTestId("web_dropdown_option_apple")).toBeNull();
397
+ });
398
+
399
+ it("shows all options when search input is empty", () => {
400
+ const {getByTestId} = renderWithTheme(
401
+ <WebDropdownMenu
402
+ anchor={anchor}
403
+ onClose={() => {}}
404
+ onSelect={() => {}}
405
+ options={options}
406
+ searchable
407
+ visible
408
+ />
409
+ );
410
+
411
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "ban");
412
+ fireEvent.changeText(getByTestId("web_dropdown_search"), "");
413
+ expect(getByTestId("web_dropdown_option_apple")).toBeTruthy();
414
+ expect(getByTestId("web_dropdown_option_banana")).toBeTruthy();
415
+ expect(getByTestId("web_dropdown_option_cherry")).toBeTruthy();
416
+ expect(getByTestId("web_dropdown_option_avocado")).toBeTruthy();
417
+ });
418
+
419
+ it("shows empty state when options are empty and showEmptyStateWhenNoOptions is true", () => {
420
+ const {getByTestId, queryByTestId} = renderWithTheme(
421
+ <WebDropdownMenu
422
+ anchor={anchor}
423
+ onClose={() => {}}
424
+ onSelect={() => {}}
425
+ options={[]}
426
+ searchable={false}
427
+ showEmptyStateWhenNoOptions
428
+ visible
429
+ />
430
+ );
431
+ expect(getByTestId("web_dropdown_no_results")).toBeTruthy();
432
+ expect(queryByTestId("web_dropdown_search")).toBeNull();
433
+ });
434
+ });
435
+
436
+ describe("WebDropdownMenu keepTriggerFocus portal overlay", () => {
437
+ const PlatformModule = require("react-native").Platform;
438
+ const anchor = {height: 40, width: 200, x: 16, y: 32};
439
+ const options = [
440
+ {label: "Option A", value: "a"},
441
+ {label: "Option B", value: "b"},
442
+ ];
443
+
444
+ let savedOS: string;
445
+ let hadDocument = false;
446
+ let savedDocument: Document | undefined;
447
+ let keyupListeners: Array<(event: KeyboardEvent) => void> = [];
448
+
449
+ const ensureWebDocument = (): void => {
450
+ hadDocument = "document" in globalThis;
451
+ savedDocument = (globalThis as {document?: Document}).document;
452
+ keyupListeners = [];
453
+
454
+ if (typeof (globalThis as {HTMLElement?: typeof HTMLElement}).HTMLElement === "undefined") {
455
+ (globalThis as {HTMLElement: typeof HTMLElement}).HTMLElement =
456
+ class HTMLElement {} as typeof HTMLElement;
457
+ }
458
+
459
+ const activeElement = new (globalThis as {HTMLElement: typeof HTMLElement}).HTMLElement();
460
+ (activeElement as HTMLElement & {blur: () => void}).blur = () => {};
461
+
462
+ const body = {appendChild: () => {}, removeChild: () => {}};
463
+
464
+ (globalThis as {document: Document}).document = {
465
+ activeElement,
466
+ addEventListener: (type: string, listener: (event: KeyboardEvent) => void) => {
467
+ if (type === "keyup") {
468
+ keyupListeners.push(listener);
469
+ }
470
+ },
471
+ body: body as HTMLElement,
472
+ removeEventListener: (type: string, listener: (event: KeyboardEvent) => void) => {
473
+ if (type === "keyup") {
474
+ keyupListeners = keyupListeners.filter((registered) => registered !== listener);
475
+ }
476
+ },
477
+ } as unknown as Document;
478
+ };
479
+
480
+ const restoreWebDocument = (): void => {
481
+ if (hadDocument) {
482
+ (globalThis as {document: Document}).document = savedDocument as Document;
483
+ } else {
484
+ delete (globalThis as {document?: Document}).document;
485
+ }
486
+ keyupListeners = [];
487
+ };
488
+
489
+ const dispatchEscapeKey = (): void => {
490
+ const event = {key: "Escape", stopPropagation: mock(() => {})} as KeyboardEvent;
491
+ for (const listener of keyupListeners) {
492
+ listener(event);
493
+ }
494
+ };
495
+
496
+ const renderKeepFocusMenu = (
497
+ props: Partial<ComponentProps<typeof WebDropdownMenu>> = {}
498
+ ): ReturnType<typeof renderWithTheme> => {
499
+ return renderWithTheme(
500
+ <WebDropdownMenu
501
+ anchor={anchor}
502
+ keepTriggerFocus
503
+ onClose={() => {}}
504
+ onSelect={() => {}}
505
+ options={options}
506
+ searchable={false}
507
+ visible
508
+ {...props}
509
+ />
510
+ );
511
+ };
512
+
513
+ it("renders fixed-position overlay instead of Modal when keepTriggerFocus is true on web", () => {
514
+ ensureWebDocument();
515
+ savedOS = PlatformModule.OS;
516
+ try {
517
+ PlatformModule.OS = "web";
518
+ const {getByTestId, queryByTestId, root} = renderKeepFocusMenu();
519
+ expect(getByTestId("web_dropdown_backdrop")).toBeTruthy();
520
+ expect(getByTestId("web_dropdown_menu")).toBeTruthy();
521
+ expect(queryByTestId("web_dropdown_modal")).toBeNull();
522
+
523
+ const menu = getByTestId("web_dropdown_menu");
524
+ const style = Array.isArray(menu.props.style)
525
+ ? Object.assign({}, ...menu.props.style)
526
+ : menu.props.style;
527
+ expect(style.position).toBe("fixed");
528
+ expect(style.left).toBe(anchor.x);
529
+
530
+ const modals = root.findAll((node) => node.type === "Modal");
531
+ expect(modals.length).toBe(0);
532
+ } finally {
533
+ PlatformModule.OS = savedOS;
534
+ restoreWebDocument();
535
+ }
536
+ });
537
+
538
+ it("renders a placeholder view when keepTriggerFocus menu is closed on web", () => {
539
+ ensureWebDocument();
540
+ savedOS = PlatformModule.OS;
541
+ try {
542
+ PlatformModule.OS = "web";
543
+ const {getByTestId, root} = renderKeepFocusMenu({visible: false});
544
+ const placeholder = getByTestId("web_dropdown_modal");
545
+ expect(placeholder.props.visible).toBeUndefined();
546
+
547
+ const modals = root.findAll((node) => node.type === "Modal");
548
+ expect(modals.length).toBe(0);
549
+ } finally {
550
+ PlatformModule.OS = savedOS;
551
+ restoreWebDocument();
552
+ }
553
+ });
554
+
555
+ it("invokes onClose when the portal backdrop is pressed on web", () => {
556
+ ensureWebDocument();
557
+ savedOS = PlatformModule.OS;
558
+ try {
559
+ PlatformModule.OS = "web";
560
+ const onClose = mock(() => {});
561
+ const {getByTestId} = renderKeepFocusMenu({onClose});
562
+ fireEvent.press(getByTestId("web_dropdown_backdrop"));
563
+ expect(onClose).toHaveBeenCalledTimes(1);
564
+ } finally {
565
+ PlatformModule.OS = savedOS;
566
+ restoreWebDocument();
567
+ }
568
+ });
569
+
570
+ it("invokes onClose when Escape is pressed in keepTriggerFocus mode on web", () => {
571
+ ensureWebDocument();
572
+ savedOS = PlatformModule.OS;
573
+ try {
574
+ PlatformModule.OS = "web";
575
+ const onClose = mock(() => {});
576
+ renderKeepFocusMenu({onClose});
577
+ act(() => {
578
+ dispatchEscapeKey();
579
+ });
580
+ expect(onClose).toHaveBeenCalledTimes(1);
581
+ } finally {
582
+ PlatformModule.OS = savedOS;
583
+ restoreWebDocument();
584
+ }
585
+ });
586
+ });
587
+
588
+ describe("WebDropdownMenu centered presentation", () => {
589
+ const anchor = {height: 40, width: 200, x: 16, y: 32};
590
+ const options = [
591
+ {label: "Option A", value: "a"},
592
+ {label: "Option B", value: "b"},
593
+ ];
594
+
595
+ it("renders a centered dialog without anchor-based left/top positioning", () => {
596
+ const {getByTestId} = renderWithTheme(
597
+ <WebDropdownMenu
598
+ anchor={anchor}
599
+ onClose={() => {}}
600
+ onSelect={() => {}}
601
+ options={options}
602
+ presentation="centered"
603
+ searchable={false}
604
+ visible
605
+ />
606
+ );
607
+ const menu = getByTestId("web_dropdown_menu");
608
+ const style = Array.isArray(menu.props.style)
609
+ ? Object.assign({}, ...menu.props.style)
610
+ : menu.props.style;
611
+ expect(style.borderRadius).toBe(8);
612
+ expect(style.left).toBeUndefined();
613
+ expect(style.top).toBeUndefined();
614
+ expect(style.maxHeight).toBe(Math.round(812 * 0.55));
615
+ });
167
616
  });
168
617
 
169
618
  describe("useWebDropdownAnchor", () => {