@terreno/ui 57.2.0 → 57.4.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 (383) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/README.md +17 -8
  3. package/dist/ActionSheet.d.ts +3 -3
  4. package/dist/ActionSheet.js +2 -2
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/AnnouncementBanner.d.ts +12 -0
  7. package/dist/AnnouncementBanner.js +61 -0
  8. package/dist/AnnouncementBanner.js.map +1 -0
  9. package/dist/AnnouncementNavigator.d.ts +11 -0
  10. package/dist/AnnouncementNavigator.js +189 -0
  11. package/dist/AnnouncementNavigator.js.map +1 -0
  12. package/dist/AnnouncementScreen.d.ts +12 -0
  13. package/dist/AnnouncementScreen.js +28 -0
  14. package/dist/AnnouncementScreen.js.map +1 -0
  15. package/dist/AreaChart.d.ts +5 -0
  16. package/dist/AreaChart.js +69 -0
  17. package/dist/AreaChart.js.map +1 -0
  18. package/dist/BarChart.d.ts +5 -0
  19. package/dist/BarChart.js +89 -0
  20. package/dist/BarChart.js.map +1 -0
  21. package/dist/Box.d.ts +1 -1
  22. package/dist/Box.js +219 -177
  23. package/dist/Box.js.map +1 -1
  24. package/dist/Button.js +116 -35
  25. package/dist/Button.js.map +1 -1
  26. package/dist/Common.d.ts +215 -9
  27. package/dist/Common.js.map +1 -1
  28. package/dist/ConsentFormScreen.js +46 -12
  29. package/dist/ConsentFormScreen.js.map +1 -1
  30. package/dist/ConsentNavigator.d.ts +5 -1
  31. package/dist/ConsentNavigator.js.map +1 -1
  32. package/dist/DashboardGrid.d.ts +4 -0
  33. package/dist/DashboardGrid.js +38 -0
  34. package/dist/DashboardGrid.js.map +1 -0
  35. package/dist/DataTable.d.ts +2 -2
  36. package/dist/DataTable.js +278 -47
  37. package/dist/DataTable.js.map +1 -1
  38. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  39. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  40. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  41. package/dist/DonutChart.d.ts +5 -0
  42. package/dist/DonutChart.js +84 -0
  43. package/dist/DonutChart.js.map +1 -0
  44. package/dist/EmojiSelector.d.ts +2 -46
  45. package/dist/EmojiSelector.js +46 -56
  46. package/dist/EmojiSelector.js.map +1 -1
  47. package/dist/Filter.js +12 -2
  48. package/dist/Filter.js.map +1 -1
  49. package/dist/GPTChat.d.ts +7 -1
  50. package/dist/GPTChat.js +28 -15
  51. package/dist/GPTChat.js.map +1 -1
  52. package/dist/Heading.d.ts +5 -2
  53. package/dist/Heading.js +6 -8
  54. package/dist/Heading.js.map +1 -1
  55. package/dist/Hyperlink.js.map +1 -1
  56. package/dist/Icon.d.ts +1 -2
  57. package/dist/Icon.js +4 -1
  58. package/dist/Icon.js.map +1 -1
  59. package/dist/LineChart.d.ts +5 -0
  60. package/dist/LineChart.js +68 -0
  61. package/dist/LineChart.js.map +1 -0
  62. package/dist/MarkdownEmbed.d.ts +6 -0
  63. package/dist/MarkdownEmbed.js +17 -0
  64. package/dist/MarkdownEmbed.js.map +1 -0
  65. package/dist/MarkdownView.d.ts +6 -3
  66. package/dist/MarkdownView.js +81 -44
  67. package/dist/MarkdownView.js.map +1 -1
  68. package/dist/MediaQuery.d.ts +5 -3
  69. package/dist/MediaQuery.js +9 -40
  70. package/dist/MediaQuery.js.map +1 -1
  71. package/dist/Modal.js +12 -10
  72. package/dist/Modal.js.map +1 -1
  73. package/dist/ModalSheet.d.ts +5 -1
  74. package/dist/ModalSheet.js +31 -13
  75. package/dist/ModalSheet.js.map +1 -1
  76. package/dist/MultiselectField.js +4 -9
  77. package/dist/MultiselectField.js.map +1 -1
  78. package/dist/NotificationBell.d.ts +16 -0
  79. package/dist/NotificationBell.js +15 -0
  80. package/dist/NotificationBell.js.map +1 -0
  81. package/dist/NotificationInbox.d.ts +21 -0
  82. package/dist/NotificationInbox.js +41 -0
  83. package/dist/NotificationInbox.js.map +1 -0
  84. package/dist/NotificationPreferences.d.ts +14 -0
  85. package/dist/NotificationPreferences.js +32 -0
  86. package/dist/NotificationPreferences.js.map +1 -0
  87. package/dist/OpenAPIContext.js +7 -6
  88. package/dist/OpenAPIContext.js.map +1 -1
  89. package/dist/Page.js +7 -1
  90. package/dist/Page.js.map +1 -1
  91. package/dist/PickerSelect.js +8 -1
  92. package/dist/PickerSelect.js.map +1 -1
  93. package/dist/Popover.d.ts +12 -0
  94. package/dist/Popover.js +37 -0
  95. package/dist/Popover.js.map +1 -0
  96. package/dist/PortalHost.js +10 -1
  97. package/dist/PortalHost.js.map +1 -1
  98. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  99. package/dist/ResponsiveBreakpoint.js +111 -0
  100. package/dist/ResponsiveBreakpoint.js.map +1 -0
  101. package/dist/SplitPage.d.ts +2 -2
  102. package/dist/SplitPage.js +7 -12
  103. package/dist/SplitPage.js.map +1 -1
  104. package/dist/SplitPage.native.d.ts +2 -2
  105. package/dist/SplitPage.native.js +1 -6
  106. package/dist/SplitPage.native.js.map +1 -1
  107. package/dist/TapToEdit.js +12 -10
  108. package/dist/TapToEdit.js.map +1 -1
  109. package/dist/TerrenoFontProvider.d.ts +7 -0
  110. package/dist/TerrenoFontProvider.js +27 -0
  111. package/dist/TerrenoFontProvider.js.map +1 -0
  112. package/dist/TerrenoProvider.js +4 -2
  113. package/dist/TerrenoProvider.js.map +1 -1
  114. package/dist/Text.d.ts +5 -2
  115. package/dist/Text.js +6 -11
  116. package/dist/Text.js.map +1 -1
  117. package/dist/TextField.js +83 -6
  118. package/dist/TextField.js.map +1 -1
  119. package/dist/TextFieldNumberActionSheet.js +9 -2
  120. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  121. package/dist/Theme.js +10 -8
  122. package/dist/Theme.js.map +1 -1
  123. package/dist/ToastNotifications.d.ts +4 -2
  124. package/dist/ToastNotifications.js.map +1 -1
  125. package/dist/Tooltip.d.ts +4 -3
  126. package/dist/Tooltip.js +14 -3
  127. package/dist/Tooltip.js.map +1 -1
  128. package/dist/Unifier.d.ts +26 -1
  129. package/dist/Unifier.js.map +1 -1
  130. package/dist/WebAddressAutocomplete.js +6 -1
  131. package/dist/WebAddressAutocomplete.js.map +1 -1
  132. package/dist/announcementBuildVersion.d.ts +6 -0
  133. package/dist/announcementBuildVersion.js +21 -0
  134. package/dist/announcementBuildVersion.js.map +1 -0
  135. package/dist/announcementFrequency.d.ts +42 -0
  136. package/dist/announcementFrequency.js +163 -0
  137. package/dist/announcementFrequency.js.map +1 -0
  138. package/dist/announcementPlatform.d.ts +2 -0
  139. package/dist/announcementPlatform.js +11 -0
  140. package/dist/announcementPlatform.js.map +1 -0
  141. package/dist/charts/ChartFrame.d.ts +12 -0
  142. package/dist/charts/ChartFrame.js +13 -0
  143. package/dist/charts/ChartFrame.js.map +1 -0
  144. package/dist/charts/bars.d.ts +18 -0
  145. package/dist/charts/bars.js +29 -0
  146. package/dist/charts/bars.js.map +1 -0
  147. package/dist/charts/layout.d.ts +47 -0
  148. package/dist/charts/layout.js +56 -0
  149. package/dist/charts/layout.js.map +1 -0
  150. package/dist/charts/paths.d.ts +31 -0
  151. package/dist/charts/paths.js +52 -0
  152. package/dist/charts/paths.js.map +1 -0
  153. package/dist/charts/scales.d.ts +6 -0
  154. package/dist/charts/scales.js +43 -0
  155. package/dist/charts/scales.js.map +1 -0
  156. package/dist/charts/theme.d.ts +9 -0
  157. package/dist/charts/theme.js +15 -0
  158. package/dist/charts/theme.js.map +1 -0
  159. package/dist/charts/types/chartTypes.d.ts +17 -0
  160. package/dist/charts/types/chartTypes.js +2 -0
  161. package/dist/charts/types/chartTypes.js.map +1 -0
  162. package/dist/dashboardGridLayout.d.ts +22 -0
  163. package/dist/dashboardGridLayout.js +33 -0
  164. package/dist/dashboardGridLayout.js.map +1 -0
  165. package/dist/dataTableFilters.d.ts +33 -0
  166. package/dist/dataTableFilters.js +221 -0
  167. package/dist/dataTableFilters.js.map +1 -0
  168. package/dist/dataTableListQuery.d.ts +42 -0
  169. package/dist/dataTableListQuery.js +161 -0
  170. package/dist/dataTableListQuery.js.map +1 -0
  171. package/dist/emojiCategories.d.ts +46 -0
  172. package/dist/emojiCategories.js +47 -0
  173. package/dist/emojiCategories.js.map +1 -0
  174. package/dist/index.d.ts +30 -13
  175. package/dist/index.js +12 -13
  176. package/dist/index.js.map +1 -1
  177. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  178. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  179. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  180. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +53 -0
  181. package/dist/lazyBoundaries/heavyOptionalExports.js +51 -0
  182. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  183. package/dist/login/LoginScreen.d.ts +1 -0
  184. package/dist/login/LoginScreen.js +4 -2
  185. package/dist/login/LoginScreen.js.map +1 -1
  186. package/dist/login/loginTypes.d.ts +2 -0
  187. package/dist/markdownEmbeds.d.ts +6 -0
  188. package/dist/markdownEmbeds.js +59 -0
  189. package/dist/markdownEmbeds.js.map +1 -0
  190. package/dist/testing/resolveTestId.js +2 -1
  191. package/dist/testing/resolveTestId.js.map +1 -1
  192. package/dist/testing/types.d.ts +3 -0
  193. package/dist/textFieldOscillationGuard.d.ts +25 -0
  194. package/dist/textFieldOscillationGuard.js +41 -0
  195. package/dist/textFieldOscillationGuard.js.map +1 -0
  196. package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
  197. package/dist/useAcknowledgeAnnouncement.js +94 -0
  198. package/dist/useAcknowledgeAnnouncement.js.map +1 -0
  199. package/dist/useAnnouncements.d.ts +73 -0
  200. package/dist/useAnnouncements.js +66 -0
  201. package/dist/useAnnouncements.js.map +1 -0
  202. package/package.json +46 -18
  203. package/src/AIRequestExplorer.test.tsx +141 -0
  204. package/src/ActionSheet.tsx +9 -7
  205. package/src/AnnouncementBanner.test.tsx +267 -0
  206. package/src/AnnouncementBanner.tsx +128 -0
  207. package/src/AnnouncementNavigator.test.tsx +759 -0
  208. package/src/AnnouncementNavigator.tsx +287 -0
  209. package/src/AnnouncementScreen.test.tsx +97 -0
  210. package/src/AnnouncementScreen.tsx +70 -0
  211. package/src/AreaChart.test.tsx +68 -0
  212. package/src/AreaChart.tsx +194 -0
  213. package/src/AttachmentPreview.test.tsx +80 -0
  214. package/src/BarChart.test.tsx +96 -0
  215. package/src/BarChart.tsx +208 -0
  216. package/src/Box.test.tsx +97 -10
  217. package/src/Box.tsx +263 -200
  218. package/src/Button.test.tsx +273 -0
  219. package/src/Button.tsx +163 -50
  220. package/src/Common.ts +219 -25
  221. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  222. package/src/ConsentFormScreen.test.tsx +145 -8
  223. package/src/ConsentFormScreen.tsx +74 -25
  224. package/src/ConsentNavigator.test.tsx +55 -0
  225. package/src/ConsentNavigator.tsx +13 -5
  226. package/src/DashboardGrid.test.tsx +75 -0
  227. package/src/DashboardGrid.tsx +69 -0
  228. package/src/DataTable.test.tsx +296 -1
  229. package/src/DataTable.tsx +623 -160
  230. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  231. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  232. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  233. package/src/DateTimeField.test.tsx +54 -0
  234. package/src/DonutChart.test.tsx +121 -0
  235. package/src/DonutChart.tsx +160 -0
  236. package/src/EmojiSelector.test.tsx +84 -42
  237. package/src/EmojiSelector.tsx +60 -57
  238. package/src/Field.test.tsx +18 -0
  239. package/src/FilePickerButton.test.tsx +167 -0
  240. package/src/Filter.test.tsx +25 -0
  241. package/src/Filter.tsx +38 -7
  242. package/src/FilterAccordion.test.tsx +37 -0
  243. package/src/FilterBoolean.test.tsx +96 -0
  244. package/src/FilterSelectMenu.test.tsx +23 -0
  245. package/src/GPTChat.test.tsx +803 -0
  246. package/src/GPTChat.tsx +177 -87
  247. package/src/GPTMemoryModal.test.tsx +67 -0
  248. package/src/Heading.tsx +8 -14
  249. package/src/HeightActionSheet.test.tsx +6 -9
  250. package/src/Hyperlink.tsx +5 -18
  251. package/src/Icon.tsx +6 -2
  252. package/src/LineChart.test.tsx +166 -0
  253. package/src/LineChart.tsx +190 -0
  254. package/src/MarkdownEditor.test.tsx +134 -0
  255. package/src/MarkdownEditorField.test.tsx +124 -0
  256. package/src/MarkdownEmbed.test.tsx +34 -0
  257. package/src/MarkdownEmbed.tsx +43 -0
  258. package/src/MarkdownView.test.tsx +112 -11
  259. package/src/MarkdownView.tsx +197 -150
  260. package/src/MediaQuery.ts +30 -34
  261. package/src/Modal.test.tsx +107 -14
  262. package/src/Modal.tsx +20 -8
  263. package/src/ModalSheet.test.tsx +121 -9
  264. package/src/ModalSheet.tsx +46 -11
  265. package/src/MultiselectField.test.tsx +21 -0
  266. package/src/MultiselectField.tsx +11 -13
  267. package/src/NotificationBell.test.tsx +91 -0
  268. package/src/NotificationBell.tsx +77 -0
  269. package/src/NotificationInbox.test.tsx +130 -0
  270. package/src/NotificationInbox.tsx +144 -0
  271. package/src/NotificationPreferences.test.tsx +25 -0
  272. package/src/NotificationPreferences.tsx +75 -0
  273. package/src/OpenAPIContext.tsx +36 -29
  274. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  275. package/src/P0RenderRegression.test.tsx +214 -0
  276. package/src/P1RenderRegression.test.tsx +141 -0
  277. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  278. package/src/Page.test.tsx +13 -0
  279. package/src/Page.tsx +25 -5
  280. package/src/PickerSelect.test.tsx +38 -0
  281. package/src/PickerSelect.tsx +7 -0
  282. package/src/Popover.test.tsx +151 -0
  283. package/src/Popover.tsx +211 -0
  284. package/src/PortalHost.tsx +12 -6
  285. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  286. package/src/ResponsiveBreakpoint.tsx +195 -0
  287. package/src/RootImportRegression.test.tsx +82 -0
  288. package/src/SplitPage.native.tsx +5 -9
  289. package/src/SplitPage.tsx +16 -19
  290. package/src/TapToEdit.test.tsx +45 -0
  291. package/src/TapToEdit.tsx +23 -18
  292. package/src/TerrenoFontProvider.test.tsx +38 -0
  293. package/src/TerrenoFontProvider.tsx +50 -0
  294. package/src/TerrenoProvider.tsx +6 -1
  295. package/src/Text.tsx +8 -21
  296. package/src/TextField.test.tsx +421 -0
  297. package/src/TextField.tsx +121 -4
  298. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  299. package/src/TextFieldNumberActionSheet.tsx +11 -2
  300. package/src/Theme.test.tsx +27 -0
  301. package/src/Theme.tsx +15 -10
  302. package/src/Toast.tsx +1 -1
  303. package/src/ToastNotifications.tsx +4 -4
  304. package/src/Tooltip.test.tsx +64 -0
  305. package/src/Tooltip.tsx +18 -4
  306. package/src/Unifier.ts +26 -3
  307. package/src/WebAddressAutocomplete.tsx +6 -2
  308. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  309. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  310. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  311. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  312. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  313. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  314. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  315. package/src/__snapshots__/Field.test.tsx.snap +29 -0
  316. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  317. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  318. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  319. package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
  320. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  321. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  322. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  323. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  324. package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
  325. package/src/__snapshots__/TextField.test.tsx.snap +5 -5
  326. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  327. package/src/announcementBuildVersion.test.ts +43 -0
  328. package/src/announcementBuildVersion.ts +21 -0
  329. package/src/announcementFrequency.test.ts +245 -0
  330. package/src/announcementFrequency.ts +246 -0
  331. package/src/announcementPlatform.test.ts +27 -0
  332. package/src/announcementPlatform.ts +13 -0
  333. package/src/benchmarks/importGraph.test.ts +71 -0
  334. package/src/benchmarks/importGraph.ts +136 -0
  335. package/src/benchmarks/importTiming.test.ts +42 -0
  336. package/src/benchmarks/importTiming.ts +86 -0
  337. package/src/bunSetup.ts +174 -32
  338. package/src/charts/ChartFrame.tsx +67 -0
  339. package/src/charts/bars.test.ts +56 -0
  340. package/src/charts/bars.ts +53 -0
  341. package/src/charts/layout.test.ts +80 -0
  342. package/src/charts/layout.ts +99 -0
  343. package/src/charts/paths.test.ts +79 -0
  344. package/src/charts/paths.ts +100 -0
  345. package/src/charts/scales.test.ts +59 -0
  346. package/src/charts/scales.ts +60 -0
  347. package/src/charts/theme.test.ts +22 -0
  348. package/src/charts/theme.ts +24 -0
  349. package/src/charts/types/chartTypes.ts +19 -0
  350. package/src/dashboardGridLayout.test.ts +90 -0
  351. package/src/dashboardGridLayout.ts +60 -0
  352. package/src/dataTableFilters.test.tsx +552 -0
  353. package/src/dataTableFilters.tsx +441 -0
  354. package/src/dataTableListQuery.test.ts +220 -0
  355. package/src/dataTableListQuery.ts +201 -0
  356. package/src/emojiCategories.test.ts +23 -0
  357. package/src/emojiCategories.ts +46 -0
  358. package/src/index.tsx +48 -14
  359. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  360. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  361. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  362. package/src/lazyBoundaries/heavyOptionalExports.tsx +134 -0
  363. package/src/login/LoginScreen.test.tsx +9 -2
  364. package/src/login/LoginScreen.tsx +6 -2
  365. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
  366. package/src/login/loginTypes.ts +2 -0
  367. package/src/markdownEmbeds.test.ts +53 -0
  368. package/src/markdownEmbeds.ts +62 -0
  369. package/src/pdfHtmlTemplate.test.ts +119 -0
  370. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
  371. package/src/table/TableDate.test.tsx +35 -1
  372. package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
  373. package/src/testing/resolveTestId.test.ts +3 -0
  374. package/src/testing/resolveTestId.ts +1 -0
  375. package/src/testing/types.ts +3 -0
  376. package/src/textFieldOscillationGuard.test.ts +63 -0
  377. package/src/textFieldOscillationGuard.ts +89 -0
  378. package/src/types/react-native-markdown-display.d.ts +6 -0
  379. package/src/types/react-native-swiper-flatlist.d.ts +5 -5
  380. package/src/useAcknowledgeAnnouncement.test.ts +223 -0
  381. package/src/useAcknowledgeAnnouncement.ts +166 -0
  382. package/src/useAnnouncements.test.ts +226 -0
  383. package/src/useAnnouncements.ts +150 -0
@@ -1,16 +1,36 @@
1
1
  import {describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
+ import {assert} from "chai";
3
4
 
4
5
  import {Button} from "./Button";
6
+ import type {ButtonProps} from "./Common";
5
7
  import {isMobileDevice} from "./MediaQuery";
6
8
  import * as ThemeModule from "./Theme";
7
9
  import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
10
+ import {Unifier} from "./Unifier";
8
11
  import * as Utilities from "./Utilities";
9
12
 
13
+ const ACTIVE_BUTTON_VARIANTS: {
14
+ backgroundColor: string;
15
+ variant: NonNullable<ButtonProps["variant"]>;
16
+ }[] = [
17
+ {backgroundColor: "#2B6072", variant: "primary"},
18
+ {backgroundColor: "#0E9DCD", variant: "secondary"},
19
+ {backgroundColor: "#0E9DCD", variant: "muted"},
20
+ {backgroundColor: "#0E9DCD", variant: "outline"},
21
+ {backgroundColor: "#BD1111", variant: "destructive"},
22
+ {backgroundColor: "#0E9DCD", variant: "ghost"},
23
+ ];
24
+
10
25
  interface PressableTestProps {
11
26
  onPress: () => Promise<void>;
12
27
  }
13
28
 
29
+ interface CancelablePress {
30
+ (): void;
31
+ cancel: () => void;
32
+ }
33
+
14
34
  describe("Button", () => {
15
35
  it("renders correctly with default props", () => {
16
36
  const {toJSON} = renderWithTheme(<Button onClick={() => {}} text="Click me" />);
@@ -29,6 +49,13 @@ describe("Button", () => {
29
49
  expect(getByTestId("test-button")).toBeTruthy();
30
50
  });
31
51
 
52
+ it("supports an accessible name distinct from visible text", () => {
53
+ const {getByTestId} = renderWithTheme(
54
+ <Button accessibilityLabel="Filter Name" onClick={() => {}} testID="filter-button" text="" />
55
+ );
56
+ expect(getByTestId("filter-button").props.accessibilityLabel).toBe("Filter Name");
57
+ });
58
+
32
59
  // Variant tests
33
60
  it("renders primary variant", () => {
34
61
  const {toJSON} = renderWithTheme(
@@ -63,6 +90,52 @@ describe("Button", () => {
63
90
  expect(toJSON()).toMatchSnapshot();
64
91
  });
65
92
 
93
+ for (const {backgroundColor, variant} of ACTIVE_BUTTON_VARIANTS) {
94
+ it(`renders ${variant} variant in active state`, () => {
95
+ const {getByTestId, getByText} = renderWithTheme(
96
+ <Button
97
+ onClick={() => {}}
98
+ state="active"
99
+ testID={`${variant}-active`}
100
+ text={`${variant} active`}
101
+ variant={variant}
102
+ />
103
+ );
104
+
105
+ expect(getByTestId(`${variant}-active`)).toHaveStyle({backgroundColor});
106
+ expect(getByText(`${variant} active`)).toHaveStyle({color: "#FFFFFF"});
107
+ });
108
+ }
109
+
110
+ it("removes the outline border in active state", () => {
111
+ const {getByTestId} = renderWithTheme(
112
+ <Button
113
+ onClick={() => {}}
114
+ state="active"
115
+ testID="outline-active"
116
+ text="Outline active"
117
+ variant="outline"
118
+ />
119
+ );
120
+
121
+ expect(getByTestId("outline-active").props.style.borderColor).toBeUndefined();
122
+ expect(getByTestId("outline-active").props.style.borderWidth).toBeUndefined();
123
+ });
124
+
125
+ it("keeps disabled styling when state is active", () => {
126
+ const {getByTestId} = renderWithTheme(
127
+ <Button
128
+ disabled
129
+ onClick={() => {}}
130
+ state="active"
131
+ testID="disabled-active"
132
+ text="Disabled active"
133
+ />
134
+ );
135
+
136
+ expect(getByTestId("disabled-active")).toHaveStyle({backgroundColor: "#9A9A9A"});
137
+ });
138
+
66
139
  it("defaults to scale press animation", () => {
67
140
  const tree = renderWithTheme(<Button onClick={() => {}} text="Default animation" />).toJSON();
68
141
  expect(Array.isArray(tree)).toBe(false);
@@ -153,6 +226,104 @@ describe("Button", () => {
153
226
  expect(handleClick).toHaveBeenCalledTimes(1);
154
227
  });
155
228
 
229
+ it("skips equivalent parent updates and redraws changed props", () => {
230
+ const handleClick = mock(() => Promise.resolve());
231
+ const mobileDeviceMock = isMobileDevice as ReturnType<typeof mock>;
232
+ mobileDeviceMock.mockClear();
233
+ const {rerender} = renderWithTheme(<Button onClick={handleClick} text="Stable" />);
234
+ const initialRenderCalls = mobileDeviceMock.mock.calls.length;
235
+
236
+ rerender(<Button onClick={handleClick} text="Stable" />);
237
+ assert.equal(mobileDeviceMock.mock.calls.length, initialRenderCalls);
238
+
239
+ rerender(<Button onClick={handleClick} text="Changed" />);
240
+ assert.equal(mobileDeviceMock.mock.calls.length, initialRenderCalls + 1);
241
+ });
242
+
243
+ it("prevents another press while an async handler remains pending", async () => {
244
+ let resolveClick: (() => void) | undefined;
245
+ const handleClick = mock(
246
+ () =>
247
+ new Promise<void>((resolve) => {
248
+ resolveClick = resolve;
249
+ })
250
+ );
251
+ const {getByTestId} = renderWithTheme(
252
+ <Button onClick={handleClick} testID="delayed-button" text="Delayed" />
253
+ );
254
+ const button = getByTestId("delayed-button");
255
+
256
+ await act(async () => {
257
+ fireEvent.press(button);
258
+ await new Promise((resolve) => setTimeout(resolve, 600));
259
+ fireEvent.press(button);
260
+ });
261
+
262
+ assert.lengthOf(handleClick.mock.calls, 1);
263
+
264
+ await act(async () => {
265
+ resolveClick?.();
266
+ await Promise.resolve();
267
+ });
268
+ });
269
+
270
+ it("cancels the debounced press handler on unmount", () => {
271
+ const {getByTestId, unmount} = renderWithTheme(
272
+ <Button onClick={() => {}} testID="cleanup-button" text="Cleanup" />
273
+ );
274
+ const onPress = getByTestId("cleanup-button").props.onPress as CancelablePress;
275
+ const cancelSpy = spyOn(onPress, "cancel");
276
+
277
+ unmount();
278
+
279
+ assert.lengthOf(cancelSpy.mock.calls, 1);
280
+ });
281
+
282
+ it("does not start an action when unmounted during async press setup", async () => {
283
+ let resolveHaptic: (() => void) | undefined;
284
+ const hapticSpy = spyOn(Unifier.utils, "haptic").mockImplementation(
285
+ () =>
286
+ new Promise<void>((resolve) => {
287
+ resolveHaptic = resolve;
288
+ })
289
+ );
290
+ const handleClick = mock(() => Promise.resolve());
291
+ const {getByTestId, unmount} = renderWithTheme(
292
+ <Button onClick={handleClick} testID="unmount-button" text="Unmount" />
293
+ );
294
+
295
+ fireEvent.press(getByTestId("unmount-button"));
296
+ unmount();
297
+ await act(async () => {
298
+ resolveHaptic?.();
299
+ await Promise.resolve();
300
+ });
301
+
302
+ assert.lengthOf(handleClick.mock.calls, 0);
303
+ hapticSpy.mockRestore();
304
+ });
305
+
306
+ it("keeps the confirmation modal path absent for plain buttons", async () => {
307
+ const handleClick = mock(() => Promise.resolve());
308
+ const {getByText, queryByText} = renderWithTheme(
309
+ <Button
310
+ confirmationText="Plain buttons never show this"
311
+ modalTitle="Unused confirmation"
312
+ onClick={handleClick}
313
+ text="Plain"
314
+ />
315
+ );
316
+
317
+ await act(async () => {
318
+ fireEvent.press(getByText("Plain"));
319
+ await Promise.resolve();
320
+ });
321
+
322
+ assert.isNull(queryByText("Unused confirmation"));
323
+ assert.isNull(queryByText("Plain buttons never show this"));
324
+ assert.lengthOf(handleClick.mock.calls, 1);
325
+ });
326
+
156
327
  // Confirmation modal tests
157
328
  it("renders with confirmation modal props", () => {
158
329
  const {toJSON} = renderWithTheme(
@@ -264,6 +435,108 @@ describe("Button", () => {
264
435
  expect(handleClick).not.toHaveBeenCalled();
265
436
  });
266
437
 
438
+ it("reopens the confirmation modal immediately after Cancel", async () => {
439
+ const handleClick = mock(() => Promise.resolve());
440
+ const {getByText, queryByText} = renderWithTheme(
441
+ <Button
442
+ confirmationText="Confirm action?"
443
+ modalTitle="Reopen Title"
444
+ onClick={handleClick}
445
+ text="Press Me"
446
+ withConfirmation
447
+ />
448
+ );
449
+
450
+ await act(async () => {
451
+ fireEvent.press(getByText("Press Me"));
452
+ await Promise.resolve();
453
+ });
454
+ await waitFor(() => {
455
+ expect(queryByText("Reopen Title")).toBeTruthy();
456
+ });
457
+
458
+ await act(async () => {
459
+ fireEvent.press(getByText("Cancel"));
460
+ await Promise.resolve();
461
+ });
462
+ await waitFor(() => {
463
+ assert.isNull(queryByText("Reopen Title"));
464
+ });
465
+
466
+ // Re-press well inside the 500ms press debounce window.
467
+ await act(async () => {
468
+ fireEvent.press(getByText("Press Me"));
469
+ await Promise.resolve();
470
+ });
471
+ await waitFor(() => {
472
+ expect(queryByText("Reopen Title")).toBeTruthy();
473
+ });
474
+ assert.lengthOf(handleClick.mock.calls, 0);
475
+ });
476
+
477
+ it("reopens the confirmation modal immediately after Confirm", async () => {
478
+ const handleClick = mock(() => Promise.resolve());
479
+ const {getByText, queryByText} = renderWithTheme(
480
+ <Button
481
+ confirmationText="Confirm action?"
482
+ modalTitle="Confirm Reopen"
483
+ onClick={handleClick}
484
+ text="Press Me"
485
+ withConfirmation
486
+ />
487
+ );
488
+
489
+ await act(async () => {
490
+ fireEvent.press(getByText("Press Me"));
491
+ await Promise.resolve();
492
+ });
493
+ await waitFor(() => {
494
+ expect(queryByText("Confirm Reopen")).toBeTruthy();
495
+ });
496
+
497
+ await act(async () => {
498
+ fireEvent.press(getByText("Confirm"));
499
+ await Promise.resolve();
500
+ });
501
+ await waitFor(() => {
502
+ assert.isNull(queryByText("Confirm Reopen"));
503
+ });
504
+ assert.lengthOf(handleClick.mock.calls, 1);
505
+
506
+ await act(async () => {
507
+ fireEvent.press(getByText("Press Me"));
508
+ await Promise.resolve();
509
+ });
510
+ await waitFor(() => {
511
+ expect(queryByText("Confirm Reopen")).toBeTruthy();
512
+ });
513
+ });
514
+
515
+ it("still debounces repeated presses that do not open the modal", async () => {
516
+ const handleClick = mock(() => Promise.resolve());
517
+ const hapticSpy = spyOn(Unifier.utils, "haptic");
518
+ const {getByText} = renderWithTheme(
519
+ <Button
520
+ confirmationText="Confirm action?"
521
+ modalTitle="Debounced Title"
522
+ onClick={handleClick}
523
+ text="Press Me"
524
+ withConfirmation
525
+ />
526
+ );
527
+
528
+ const hapticCallsBefore = hapticSpy.mock.calls.length;
529
+ await act(async () => {
530
+ fireEvent.press(getByText("Press Me"));
531
+ fireEvent.press(getByText("Press Me"));
532
+ fireEvent.press(getByText("Press Me"));
533
+ await Promise.resolve();
534
+ });
535
+
536
+ assert.equal(hapticSpy.mock.calls.length - hapticCallsBefore, 1);
537
+ hapticSpy.mockRestore();
538
+ });
539
+
267
540
  it("renders with tooltip on desktop (wrapped in Tooltip)", () => {
268
541
  const {toJSON} = renderWithTheme(
269
542
  <Button onClick={() => {}} text="Hover me" tooltipText="Tooltip text" />
package/src/Button.tsx CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  PressableWithoutFeedback,
8
8
  } from "pressto";
9
9
  import type React from "react";
10
- import {lazy, Suspense, useCallback, useMemo, useState} from "react";
10
+ import {lazy, memo, Suspense, useCallback, useEffect, useMemo, useRef, useState} from "react";
11
11
  import {ActivityIndicator, Pressable, type PressableProps, Text, View} from "react-native";
12
12
 
13
13
  import {Box} from "./Box";
@@ -35,25 +35,67 @@ const PRESSABLE_BY_ANIMATION: Record<
35
35
 
36
36
  type ButtonPressableProps = CustomPressableProps & PressableProps;
37
37
 
38
- const ButtonComponent: React.FC<ButtonProps> = ({
39
- confirmationText = "Are you sure you want to continue?",
38
+ interface ButtonVisualProps extends Omit<ButtonProps, "onClick"> {
39
+ children?: React.ReactNode;
40
+ isLoading: boolean;
41
+ onPress: () => void;
42
+ }
43
+
44
+ interface DebouncedPress {
45
+ endPressCooldown: () => void;
46
+ onPress: () => void;
47
+ }
48
+
49
+ const useDebouncedPress = (handlePress: () => Promise<void>): DebouncedPress => {
50
+ const debouncedHandlePress = useMemo(
51
+ () => debounce(handlePress, 500, {leading: true, trailing: false}),
52
+ [handlePress]
53
+ );
54
+
55
+ // Cancel retained debounce timers when the callback changes or the button unmounts.
56
+ useEffect((): (() => void) => {
57
+ return (): void => {
58
+ debouncedHandlePress.cancel();
59
+ };
60
+ }, [debouncedHandlePress]);
61
+
62
+ const endPressCooldown = useCallback((): void => {
63
+ debouncedHandlePress.cancel();
64
+ }, [debouncedHandlePress]);
65
+
66
+ return {endPressCooldown, onPress: debouncedHandlePress};
67
+ };
68
+
69
+ const useMountedRef = (): React.RefObject<boolean> => {
70
+ const isMountedRef = useRef(true);
71
+
72
+ // Prevent async press completions from updating state after the button unmounts.
73
+ useEffect((): (() => void) => {
74
+ return (): void => {
75
+ isMountedRef.current = false;
76
+ };
77
+ }, []);
78
+
79
+ return isMountedRef;
80
+ };
81
+
82
+ const ButtonVisual: React.FC<ButtonVisualProps> = ({
83
+ accessibilityLabel,
84
+ children,
40
85
  disabled = false,
41
86
  fullWidth = false,
42
87
  iconName,
43
88
  iconPosition = "left",
44
- loading: propsLoading,
45
- modalTitle = "Confirm",
46
- modalSubTitle,
89
+ isLoading,
90
+ onPress,
47
91
  pressAnimation = DEFAULT_BUTTON_PRESS_ANIMATION,
48
92
  size = "default",
93
+ state = "default",
49
94
  testID,
50
95
  text,
51
96
  variant = "primary",
52
97
  withConfirmation = false,
53
- onClick,
54
98
  }) => {
55
- const [loading, setLoading] = useState(propsLoading);
56
- const [showConfirmation, setShowConfirmation] = useState(false);
57
99
  const {theme} = useTheme();
58
100
  const CustomIcon = useCustomIcon(iconName);
59
101
 
@@ -85,44 +127,32 @@ const ButtonComponent: React.FC<ButtonProps> = ({
85
127
  textColor = theme.surface.secondaryDark;
86
128
  }
87
129
 
130
+ if (!disabled && state === "active") {
131
+ if (variant === "primary") {
132
+ bgColor = theme.surface.secondaryDark;
133
+ } else if (variant === "destructive") {
134
+ bgColor = theme.surface.error;
135
+ } else {
136
+ bgColor = theme.surface.primary;
137
+ }
138
+ bColor = undefined;
139
+ bWidth = undefined;
140
+ textColor = theme.surface.base;
141
+ }
142
+
88
143
  return {
89
144
  backgroundColor: bgColor,
90
145
  borderColor: bColor,
91
146
  borderWidth: bWidth,
92
147
  color: textColor,
93
148
  };
94
- }, [disabled, variant, theme]);
95
-
96
- const handlePress = useCallback(async (): Promise<void> => {
97
- await Unifier.utils.haptic();
98
- setLoading(true);
99
-
100
- try {
101
- // If a confirmation is required, and the confirmation modal is not currently open,
102
- // open it.
103
- if (withConfirmation && !showConfirmation) {
104
- setShowConfirmation(true);
105
- } else if (!withConfirmation && onClick) {
106
- // If a confirmation is not required, perform the action.
107
- await onClick();
108
- }
109
- } catch (error) {
110
- setLoading(false);
111
- throw error;
112
- }
113
- setLoading(false);
114
- }, [onClick, showConfirmation, withConfirmation]);
115
-
116
- const debouncedHandlePress = useMemo(
117
- () => debounce(handlePress, 500, {leading: true, trailing: false}),
118
- [handlePress]
119
- );
149
+ }, [disabled, state, variant, theme]);
120
150
 
121
151
  if (!theme) {
122
152
  return null;
123
153
  }
124
154
 
125
- const isPressDisabled = disabled || Boolean(loading);
155
+ const isPressDisabled = disabled || isLoading;
126
156
  const PressableComponent = (
127
157
  isPressDisabled ? Pressable : PRESSABLE_BY_ANIMATION[pressAnimation]
128
158
  ) as React.ComponentType<ButtonPressableProps>;
@@ -133,11 +163,11 @@ const ButtonComponent: React.FC<ButtonProps> = ({
133
163
  accessibilityHint={
134
164
  withConfirmation ? "Opens a confirmation dialog" : "Press to perform action"
135
165
  }
136
- accessibilityLabel={text}
166
+ accessibilityLabel={accessibilityLabel ?? text}
137
167
  accessibilityRole="button"
138
168
  accessibilityState={{disabled: isPressDisabled}}
139
169
  {...pressableInteractionProps}
140
- onPress={debouncedHandlePress}
170
+ onPress={onPress}
141
171
  style={{
142
172
  alignItems: "center",
143
173
  alignSelf: fullWidth ? "stretch" : "flex-start",
@@ -173,22 +203,96 @@ const ButtonComponent: React.FC<ButtonProps> = ({
173
203
  )}
174
204
  <Text style={{color, fontSize: size === "sm" ? 14 : 16, fontWeight: "700"}}>{text}</Text>
175
205
  </View>
176
- {Boolean(loading) && (
206
+ {isLoading && (
177
207
  <Box marginLeft={2}>
178
208
  <ActivityIndicator color={color} size="small" />
179
209
  </Box>
180
210
  )}
181
211
  </View>
182
- {withConfirmation && showConfirmation && (
212
+ {children}
213
+ </PressableComponent>
214
+ );
215
+ };
216
+
217
+ const PlainButton: React.FC<ButtonProps> = (props) => {
218
+ const {loading = false, onClick} = props;
219
+ const {
220
+ confirmationText: _confirmationText,
221
+ modalSubTitle: _modalSubTitle,
222
+ modalTitle: _modalTitle,
223
+ onClick: _onClick,
224
+ withConfirmation: _withConfirmation,
225
+ ...visualProps
226
+ } = props;
227
+ const [isHandlingPress, setIsHandlingPress] = useState(false);
228
+ const isMountedRef = useMountedRef();
229
+ const handlePress = useCallback(async (): Promise<void> => {
230
+ await Unifier.utils.haptic();
231
+ if (!isMountedRef.current) {
232
+ return;
233
+ }
234
+ setIsHandlingPress(true);
235
+
236
+ try {
237
+ await onClick();
238
+ } catch (error) {
239
+ if (isMountedRef.current) {
240
+ setIsHandlingPress(false);
241
+ }
242
+ throw error;
243
+ }
244
+ if (isMountedRef.current) {
245
+ setIsHandlingPress(false);
246
+ }
247
+ }, [isMountedRef, onClick]);
248
+ const {onPress} = useDebouncedPress(handlePress);
249
+
250
+ return <ButtonVisual {...visualProps} isLoading={loading || isHandlingPress} onPress={onPress} />;
251
+ };
252
+
253
+ const ConfirmationButton: React.FC<ButtonProps> = ({
254
+ confirmationText = "Are you sure you want to continue?",
255
+ loading = false,
256
+ modalSubTitle,
257
+ modalTitle = "Confirm",
258
+ onClick,
259
+ ...props
260
+ }) => {
261
+ const [showConfirmation, setShowConfirmation] = useState(false);
262
+ const isMountedRef = useMountedRef();
263
+ const handlePress = useCallback(async (): Promise<void> => {
264
+ await Unifier.utils.haptic();
265
+ if (!isMountedRef.current) {
266
+ return;
267
+ }
268
+ setShowConfirmation(true);
269
+ }, [isMountedRef]);
270
+ const {endPressCooldown, onPress} = useDebouncedPress(handlePress);
271
+ // The press debounce only guards opening the modal, so closing it must clear the
272
+ // cooldown or a quick reopen after Cancel, dismiss, or Confirm would be swallowed.
273
+ const handleDismiss = useCallback((): void => {
274
+ endPressCooldown();
275
+ if (isMountedRef.current) {
276
+ setShowConfirmation(false);
277
+ }
278
+ }, [endPressCooldown, isMountedRef]);
279
+ const handleConfirm = useCallback(async (): Promise<void> => {
280
+ await onClick();
281
+ endPressCooldown();
282
+ if (isMountedRef.current) {
283
+ setShowConfirmation(false);
284
+ }
285
+ }, [endPressCooldown, isMountedRef, onClick]);
286
+
287
+ return (
288
+ <ButtonVisual {...props} isLoading={loading} onPress={onPress} withConfirmation>
289
+ {showConfirmation && (
183
290
  <Suspense fallback={null}>
184
291
  <LazyModal
185
- onDismiss={() => setShowConfirmation(false)}
186
- primaryButtonOnClick={async (): Promise<void> => {
187
- await onClick();
188
- setShowConfirmation(false);
189
- }}
292
+ onDismiss={handleDismiss}
293
+ primaryButtonOnClick={handleConfirm}
190
294
  primaryButtonText="Confirm"
191
- secondaryButtonOnClick={() => setShowConfirmation(false)}
295
+ secondaryButtonOnClick={handleDismiss}
192
296
  secondaryButtonText="Cancel"
193
297
  subtitle={modalSubTitle}
194
298
  text={confirmationText}
@@ -197,13 +301,18 @@ const ButtonComponent: React.FC<ButtonProps> = ({
197
301
  />
198
302
  </Suspense>
199
303
  )}
200
- </PressableComponent>
304
+ </ButtonVisual>
201
305
  );
202
306
  };
203
307
 
204
- export const Button: React.FC<ButtonProps> = (props) => {
308
+ const ButtonRender: React.FC<ButtonProps> = (props) => {
205
309
  const {tooltipText, tooltipIdealPosition, tooltipIncludeArrow = false} = props;
206
310
  const isMobileOrNative = isMobileDevice() || isNative();
311
+ const button = props.withConfirmation ? (
312
+ <ConfirmationButton {...props} />
313
+ ) : (
314
+ <PlainButton {...props} />
315
+ );
207
316
 
208
317
  if (tooltipText && !isMobileOrNative) {
209
318
  return (
@@ -212,10 +321,14 @@ export const Button: React.FC<ButtonProps> = (props) => {
212
321
  includeArrow={tooltipIncludeArrow}
213
322
  text={tooltipText}
214
323
  >
215
- <ButtonComponent {...props} />
324
+ {button}
216
325
  </Tooltip>
217
326
  );
218
327
  }
219
328
 
220
- return <ButtonComponent {...props} />;
329
+ return button;
221
330
  };
331
+
332
+ const MemoizedButton = memo(ButtonRender);
333
+
334
+ export const Button: React.FC<ButtonProps> = MemoizedButton;