@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
@@ -0,0 +1,80 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import {
4
+ CHART_Y_AXIS_MAX_WIDTH,
5
+ getChartAxisWidth,
6
+ getChartPlot,
7
+ getDonutSize,
8
+ getPlotHeight,
9
+ getXTickStyle,
10
+ getYTickStyle,
11
+ } from "./layout";
12
+
13
+ describe("chart layout", () => {
14
+ it("takes the tick and tooltip rows out of the requested height", () => {
15
+ expect(getPlotHeight({hasLegend: false, height: 200})).toBe(164);
16
+ });
17
+
18
+ it("also reserves the legend row when the chart has one", () => {
19
+ expect(getPlotHeight({hasLegend: true, height: 200})).toBe(146);
20
+ });
21
+
22
+ it("keeps a drawable plot when the requested height is smaller than the rows", () => {
23
+ expect(getPlotHeight({hasLegend: true, height: 20})).toBe(40);
24
+ });
25
+
26
+ it("fits a donut inside the height left by tooltip and padded, gapped legend rows", () => {
27
+ expect(getDonutSize({chartWidth: 400, height: 220, legendRowCount: 3})).toBe(124);
28
+ });
29
+
30
+ it("keeps a donut square when the container is narrower than the height", () => {
31
+ expect(getDonutSize({chartWidth: 90, height: 220, legendRowCount: 1})).toBe(90);
32
+ });
33
+
34
+ it("caps the value axis gutter on a wide chart", () => {
35
+ expect(getChartAxisWidth(300)).toBe(CHART_Y_AXIS_MAX_WIDTH);
36
+ });
37
+
38
+ it("shrinks the value axis gutter so a narrow chart keeps a plot", () => {
39
+ expect(getChartAxisWidth(100)).toBe(30);
40
+ expect(getChartAxisWidth(0)).toBe(0);
41
+ });
42
+
43
+ it("insets the plot inside the measured chart width minus the axis gutter", () => {
44
+ expect(getChartPlot({chartWidth: 300, height: 200})).toEqual({
45
+ height: 184,
46
+ left: 8,
47
+ top: 8,
48
+ width: 244,
49
+ });
50
+ });
51
+
52
+ it("keeps a positive plot box when the container is narrower than the insets", () => {
53
+ const plot = getChartPlot({chartWidth: 0, height: 0});
54
+
55
+ expect(plot.width).toBe(1);
56
+ expect(plot.height).toBe(1);
57
+ });
58
+
59
+ it("centers an x tick slot on its band center", () => {
60
+ expect(getXTickStyle({bandwidth: 60, xCenter: 100})).toEqual({
61
+ left: 70,
62
+ position: "absolute",
63
+ top: 0,
64
+ width: 60,
65
+ });
66
+ });
67
+
68
+ it("keeps an x tick slot positive when there are no bands", () => {
69
+ expect(getXTickStyle({bandwidth: 0, xCenter: 10}).width).toBe(1);
70
+ });
71
+
72
+ it("centers a y tick label on its value and spans the axis gutter", () => {
73
+ expect(getYTickStyle({axisWidth: 40, y: 50})).toEqual({
74
+ left: 0,
75
+ position: "absolute",
76
+ top: 43,
77
+ width: 40,
78
+ });
79
+ });
80
+ });
@@ -0,0 +1,99 @@
1
+ import type {ChartPlot} from "./types/chartTypes";
2
+
3
+ export const CHART_Y_AXIS_MAX_WIDTH = 40;
4
+ export const CHART_X_AXIS_HEIGHT = 18;
5
+ export const CHART_FOOTER_ROW_HEIGHT = 18;
6
+
7
+ const Y_AXIS_WIDTH_RATIO = 0.3;
8
+ const PLOT_INSET = 8;
9
+ const Y_TICK_HALF_HEIGHT = 7;
10
+ const MIN_PLOT_HEIGHT = 40;
11
+ const MIN_DONUT_SIZE = 40;
12
+ const DONUT_LEGEND_PADDING = 8;
13
+ const DONUT_LEGEND_ROW_GAP = 4;
14
+
15
+ export interface ChartTickStyle {
16
+ [key: string]: unknown;
17
+ left: number;
18
+ position: "absolute";
19
+ top: number;
20
+ width: number;
21
+ }
22
+
23
+ /**
24
+ * Value labels take a share of a narrow chart instead of a fixed gutter, so a chart in a small
25
+ * card keeps a usable plot instead of spending most of its width on the axis.
26
+ */
27
+ export const getChartAxisWidth = (chartWidth: number): number => {
28
+ if (chartWidth <= 0) {
29
+ return 0;
30
+ }
31
+ return Math.min(CHART_Y_AXIS_MAX_WIDTH, Math.floor(chartWidth * Y_AXIS_WIDTH_RATIO));
32
+ };
33
+
34
+ /**
35
+ * `height` is the whole chart, not just the drawing, so a chart dropped into a fixed-height slot
36
+ * fits it. The tick row and the tooltip row come out of that budget; the tooltip row is reserved
37
+ * whether or not a tooltip is showing, so hovering never reflows the page.
38
+ */
39
+ export const getPlotHeight = ({
40
+ hasLegend,
41
+ height,
42
+ }: {
43
+ hasLegend: boolean;
44
+ height: number;
45
+ }): number => {
46
+ const footer = CHART_X_AXIS_HEIGHT + CHART_FOOTER_ROW_HEIGHT * (hasLegend ? 2 : 1);
47
+ return Math.max(height - footer, MIN_PLOT_HEIGHT);
48
+ };
49
+
50
+ export const getDonutSize = ({
51
+ chartWidth,
52
+ height,
53
+ legendRowCount,
54
+ }: {
55
+ chartWidth: number;
56
+ height: number;
57
+ legendRowCount: number;
58
+ }): number => {
59
+ const legendGaps = Math.max(legendRowCount - 1, 0) * DONUT_LEGEND_ROW_GAP;
60
+ const legendHeight =
61
+ legendRowCount * CHART_FOOTER_ROW_HEIGHT + DONUT_LEGEND_PADDING * 2 + legendGaps;
62
+ const footer = CHART_FOOTER_ROW_HEIGHT + legendHeight;
63
+ return Math.max(Math.min(chartWidth, height - footer), MIN_DONUT_SIZE);
64
+ };
65
+
66
+ export const getChartPlot = ({
67
+ chartWidth,
68
+ height,
69
+ }: {
70
+ chartWidth: number;
71
+ height: number;
72
+ }): ChartPlot => {
73
+ return {
74
+ height: Math.max(height - PLOT_INSET * 2, 1),
75
+ left: PLOT_INSET,
76
+ top: PLOT_INSET,
77
+ width: Math.max(chartWidth - getChartAxisWidth(chartWidth) - PLOT_INSET * 2, 1),
78
+ };
79
+ };
80
+
81
+ /**
82
+ * X tick labels are absolutely positioned on their band center. Laying them out in a flow row
83
+ * instead would let a long label set the chart's min-content width and push the plot past its
84
+ * container.
85
+ */
86
+ export const getXTickStyle = ({
87
+ bandwidth,
88
+ xCenter,
89
+ }: {
90
+ bandwidth: number;
91
+ xCenter: number;
92
+ }): ChartTickStyle => {
93
+ const width = Math.max(bandwidth, 1);
94
+ return {left: xCenter - width / 2, position: "absolute", top: 0, width};
95
+ };
96
+
97
+ export const getYTickStyle = ({axisWidth, y}: {axisWidth: number; y: number}): ChartTickStyle => {
98
+ return {left: 0, position: "absolute", top: y - Y_TICK_HALF_HEIGHT, width: axisWidth};
99
+ };
@@ -0,0 +1,79 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import {
4
+ getAreaPath,
5
+ getDonutSliceAngles,
6
+ getDonutSliceHitCenter,
7
+ getDonutSlicePath,
8
+ getLinePath,
9
+ } from "./paths";
10
+ import {createCartesianScales} from "./scales";
11
+ import type {ChartPoint} from "./types/chartTypes";
12
+
13
+ const FIXTURE_POINTS: ChartPoint[] = [
14
+ {label: "A", value: 0},
15
+ {label: "B", value: 50},
16
+ {label: "C", value: 100},
17
+ ];
18
+
19
+ const PLOT = {height: 100, left: 10, top: 0, width: 90};
20
+
21
+ describe("chart paths", () => {
22
+ it("builds a linear line path through the fixture centers", () => {
23
+ const scales = createCartesianScales({plot: PLOT, points: FIXTURE_POINTS});
24
+ const path = getLinePath({points: FIXTURE_POINTS, scales});
25
+
26
+ expect(path).toBe("M25,100L55,50L85,0");
27
+ });
28
+
29
+ it("builds an area path that includes the plot baseline", () => {
30
+ const scales = createCartesianScales({plot: PLOT, points: FIXTURE_POINTS});
31
+ const path = getAreaPath({baselineY: PLOT.top + PLOT.height, points: FIXTURE_POINTS, scales});
32
+
33
+ expect(path).toContain("M25,100");
34
+ expect(path).toContain("L55,50");
35
+ expect(path).toContain("L85,0");
36
+ expect(path).toContain("L85,100");
37
+ });
38
+
39
+ it("returns empty strings for empty point lists", () => {
40
+ const scales = createCartesianScales({plot: PLOT, points: []});
41
+
42
+ expect(getLinePath({points: [], scales})).toBe("");
43
+ expect(getAreaPath({baselineY: 100, points: [], scales})).toBe("");
44
+ expect(getDonutSlicePath({endAngle: 0, innerRadius: 10, outerRadius: 20, startAngle: 0})).toBe(
45
+ ""
46
+ );
47
+ });
48
+
49
+ it("builds a nonempty donut slice for a half-circle", () => {
50
+ const path = getDonutSlicePath({
51
+ endAngle: Math.PI,
52
+ innerRadius: 20,
53
+ outerRadius: 40,
54
+ startAngle: 0,
55
+ });
56
+
57
+ expect(path.startsWith("M")).toBe(true);
58
+ expect(path.length).toBeGreaterThan(10);
59
+ });
60
+
61
+ it("starts donut slices at d3-shape 0 (12 o'clock), not -π/2", () => {
62
+ const [first, second] = getDonutSliceAngles([{value: 50}, {value: 50}]);
63
+
64
+ expect(first?.start).toBe(0);
65
+ expect(first?.end).toBe(Math.PI);
66
+ expect(second?.start).toBe(Math.PI);
67
+ expect(second?.end).toBe(Math.PI * 2);
68
+ });
69
+
70
+ it("places equal-slice hit centers on the same side as d3-shape paint", () => {
71
+ const firstMid = Math.PI / 2;
72
+ const secondMid = (3 * Math.PI) / 2;
73
+ const first = getDonutSliceHitCenter({center: 100, hitRadius: 40, midAngle: firstMid});
74
+ const second = getDonutSliceHitCenter({center: 100, hitRadius: 40, midAngle: secondMid});
75
+
76
+ expect(first).toEqual({x: 140, y: 100});
77
+ expect(second).toEqual({x: 60, y: 100});
78
+ });
79
+ });
@@ -0,0 +1,100 @@
1
+ import {arc, area, line} from "d3-shape";
2
+
3
+ import type {ChartPoint, ChartScales} from "./types/chartTypes";
4
+
5
+ export const getLinePath = ({
6
+ points,
7
+ scales,
8
+ }: {
9
+ points: ChartPoint[];
10
+ scales: ChartScales;
11
+ }): string => {
12
+ if (points.length === 0) {
13
+ return "";
14
+ }
15
+
16
+ const path = line<ChartPoint>()
17
+ .x((point) => scales.xCenter(point.label))
18
+ .y((point) => scales.y(point.value))(points);
19
+
20
+ return path ?? "";
21
+ };
22
+
23
+ export const getAreaPath = ({
24
+ baselineY,
25
+ points,
26
+ scales,
27
+ }: {
28
+ baselineY: number;
29
+ points: ChartPoint[];
30
+ scales: ChartScales;
31
+ }): string => {
32
+ if (points.length === 0) {
33
+ return "";
34
+ }
35
+
36
+ const path = area<ChartPoint>()
37
+ .x((point) => scales.xCenter(point.label))
38
+ .y0(baselineY)
39
+ .y1((point) => scales.y(point.value))(points);
40
+
41
+ return path ?? "";
42
+ };
43
+
44
+ export const getDonutSlicePath = ({
45
+ endAngle,
46
+ innerRadius,
47
+ outerRadius,
48
+ startAngle,
49
+ }: {
50
+ endAngle: number;
51
+ innerRadius: number;
52
+ outerRadius: number;
53
+ startAngle: number;
54
+ }): string => {
55
+ if (startAngle === endAngle || outerRadius <= 0) {
56
+ return "";
57
+ }
58
+
59
+ const path = arc()({
60
+ endAngle,
61
+ innerRadius,
62
+ outerRadius,
63
+ startAngle,
64
+ });
65
+
66
+ return path ?? "";
67
+ };
68
+
69
+ const TAU = Math.PI * 2;
70
+
71
+ export const getDonutSliceAngles = (
72
+ data: {value: number}[]
73
+ ): Array<{end: number; start: number}> => {
74
+ const total = data.reduce((sum, point) => sum + Math.max(point.value, 0), 0);
75
+ let cursor = 0;
76
+
77
+ return data.map((point) => {
78
+ const sweep = total === 0 ? 0 : (Math.max(point.value, 0) / total) * TAU;
79
+ const start = cursor;
80
+ cursor += sweep;
81
+ return {end: cursor, start};
82
+ });
83
+ };
84
+
85
+ /** d3-shape `arc` treats 0 as 12 o'clock by subtracting π/2 before cos/sin. */
86
+ export const getDonutSliceHitCenter = ({
87
+ center,
88
+ hitRadius,
89
+ midAngle,
90
+ }: {
91
+ center: number;
92
+ hitRadius: number;
93
+ midAngle: number;
94
+ }): {x: number; y: number} => {
95
+ const paintAngle = midAngle - Math.PI / 2;
96
+ return {
97
+ x: center + Math.cos(paintAngle) * hitRadius,
98
+ y: center + Math.sin(paintAngle) * hitRadius,
99
+ };
100
+ };
@@ -0,0 +1,59 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import {createCartesianScales, getYTickValues} from "./scales";
4
+ import type {ChartPoint} from "./types/chartTypes";
5
+
6
+ const FIXTURE_POINTS: ChartPoint[] = [
7
+ {label: "A", value: 0},
8
+ {label: "B", value: 50},
9
+ {label: "C", value: 100},
10
+ ];
11
+
12
+ const PLOT = {height: 100, left: 10, top: 0, width: 90};
13
+
14
+ describe("createCartesianScales", () => {
15
+ it("maps equal bands and inverted y for a 90x100 plot", () => {
16
+ const scales = createCartesianScales({plot: PLOT, points: FIXTURE_POINTS});
17
+
18
+ expect(scales.bandwidth).toBe(30);
19
+ expect(scales.xStart("A")).toBe(10);
20
+ expect(scales.xStart("B")).toBe(40);
21
+ expect(scales.xStart("C")).toBe(70);
22
+ expect(scales.xCenter("A")).toBe(25);
23
+ expect(scales.xCenter("B")).toBe(55);
24
+ expect(scales.xCenter("C")).toBe(85);
25
+ expect(scales.y(0)).toBe(100);
26
+ expect(scales.y(100)).toBe(0);
27
+ expect(scales.y(50)).toBe(50);
28
+ });
29
+
30
+ it("returns three ticks from the y domain including zero", () => {
31
+ expect(getYTickValues(FIXTURE_POINTS)).toEqual([0, 50, 100]);
32
+ });
33
+
34
+ it("anchors all-negative values at zero so bars can grow downward", () => {
35
+ const points: ChartPoint[] = [
36
+ {label: "A", value: -10},
37
+ {label: "B", value: -5},
38
+ ];
39
+ const scales = createCartesianScales({plot: PLOT, points});
40
+
41
+ expect(getYTickValues(points)).toEqual([-10, -5, 0]);
42
+ expect(scales.y(0)).toBe(PLOT.top);
43
+ expect(scales.y(-10)).toBe(PLOT.top + PLOT.height);
44
+ expect(scales.y(-5)).toBe(PLOT.top + PLOT.height / 2);
45
+ });
46
+
47
+ it("returns no ticks for empty points", () => {
48
+ expect(getYTickValues([])).toEqual([]);
49
+ });
50
+
51
+ it("does not throw on empty points", () => {
52
+ const scales = createCartesianScales({plot: PLOT, points: []});
53
+
54
+ expect(scales.bandwidth).toBe(0);
55
+ expect(scales.xStart("A")).toBe(PLOT.left);
56
+ expect(scales.xCenter("A")).toBe(PLOT.left);
57
+ expect(scales.y(0)).toBe(PLOT.top + PLOT.height);
58
+ });
59
+ });
@@ -0,0 +1,60 @@
1
+ import {scaleBand, scaleLinear} from "d3-scale";
2
+
3
+ import type {ChartPlot, ChartPoint, ChartScales} from "./types/chartTypes";
4
+
5
+ const EMPTY_Y_DOMAIN: [number, number] = [0, 1];
6
+
7
+ const getYDomain = (points: ChartPoint[]): [number, number] => {
8
+ if (points.length === 0) {
9
+ return EMPTY_Y_DOMAIN;
10
+ }
11
+
12
+ const values = points.map((point) => point.value);
13
+ const min = Math.min(0, ...values);
14
+ const max = Math.max(0, ...values);
15
+ if (min === max) {
16
+ return [min, min + 1];
17
+ }
18
+
19
+ return [min, max];
20
+ };
21
+
22
+ export const getYTickValues = (points: ChartPoint[]): number[] => {
23
+ if (points.length === 0) {
24
+ return [];
25
+ }
26
+
27
+ const [min, max] = getYDomain(points);
28
+ const mid = min + (max - min) / 2;
29
+ return [min, mid, max];
30
+ };
31
+
32
+ export const createCartesianScales = ({
33
+ plot,
34
+ points,
35
+ }: {
36
+ plot: ChartPlot;
37
+ points: ChartPoint[];
38
+ }): ChartScales => {
39
+ const bottom = plot.top + plot.height;
40
+ const labels = points.map((point) => point.label);
41
+ const xScale = scaleBand<string>()
42
+ .domain(labels)
43
+ .range([plot.left, plot.left + plot.width]);
44
+ const yScale = scaleLinear().domain(getYDomain(points)).range([bottom, plot.top]);
45
+ const bandwidth = labels.length === 0 ? 0 : xScale.bandwidth();
46
+
47
+ const xStart = (label: string): number => {
48
+ return xScale(label) ?? plot.left;
49
+ };
50
+
51
+ const xCenter = (label: string): number => {
52
+ return xStart(label) + bandwidth / 2;
53
+ };
54
+
55
+ const y = (value: number): number => {
56
+ return yScale(value);
57
+ };
58
+
59
+ return {bandwidth, xCenter, xStart, y};
60
+ };
@@ -0,0 +1,22 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import type {TerrenoTheme} from "../Common";
4
+ import {getChartPaint} from "./theme";
5
+
6
+ const THEME = {
7
+ border: {default: "#CDCDCD"},
8
+ surface: {error: "#BD1111", primary: "#0E9DCD", secondaryDark: "#2B6072"},
9
+ text: {accent: "#956A00", secondaryDark: "#543C00"},
10
+ } as unknown as TerrenoTheme;
11
+
12
+ describe("getChartPaint", () => {
13
+ it("maps theme tokens onto series, slices, grid, and axis paints", () => {
14
+ const paint = getChartPaint(THEME);
15
+
16
+ expect(paint.series).toBe("#0E9DCD");
17
+ expect(paint.seriesFill).toBe("#0E9DCD");
18
+ expect(paint.slices).toEqual(["#0E9DCD", "#2B6072", "#956A00", "#BD1111"]);
19
+ expect(paint.grid).toBe("#CDCDCD");
20
+ expect(paint.axis).toBe("#543C00");
21
+ });
22
+ });
@@ -0,0 +1,24 @@
1
+ import type {TerrenoTheme} from "../Common";
2
+
3
+ export interface ChartPaint {
4
+ axis: string;
5
+ grid: string;
6
+ series: string;
7
+ seriesFill: string;
8
+ slices: string[];
9
+ }
10
+
11
+ export const getChartPaint = (theme: TerrenoTheme): ChartPaint => {
12
+ return {
13
+ axis: theme.text.secondaryDark,
14
+ grid: theme.border.default,
15
+ series: theme.surface.primary,
16
+ seriesFill: theme.surface.primary,
17
+ slices: [
18
+ theme.surface.primary,
19
+ theme.surface.secondaryDark,
20
+ theme.text.accent,
21
+ theme.surface.error,
22
+ ],
23
+ };
24
+ };
@@ -0,0 +1,19 @@
1
+ export interface ChartPoint {
2
+ color?: string;
3
+ label: string;
4
+ value: number;
5
+ }
6
+
7
+ export interface ChartPlot {
8
+ height: number;
9
+ left: number;
10
+ top: number;
11
+ width: number;
12
+ }
13
+
14
+ export interface ChartScales {
15
+ bandwidth: number;
16
+ xCenter: (label: string) => number;
17
+ xStart: (label: string) => number;
18
+ y: (value: number) => number;
19
+ }
@@ -0,0 +1,90 @@
1
+ import {afterEach, describe, expect, it} from "bun:test";
2
+ import {Platform} from "react-native";
3
+
4
+ import {getDashboardCellBoxStyle, getDashboardCellWidth} from "./dashboardGridLayout";
5
+
6
+ const originalOS = Platform.OS;
7
+
8
+ afterEach(() => {
9
+ Platform.OS = originalOS;
10
+ });
11
+
12
+ describe("getDashboardCellWidth", () => {
13
+ it("subtracts inter-column gap so three cells fit the row", () => {
14
+ expect(
15
+ getDashboardCellWidth({
16
+ columnCount: 3,
17
+ gapPx: 16,
18
+ rowWidth: 333,
19
+ })
20
+ ).toBe(100);
21
+ });
22
+
23
+ it("leaves a pixel of slack when the columns would exactly consume the measured row", () => {
24
+ const columnCount = 3;
25
+ const gapPx = 16;
26
+ const rowWidth = 332;
27
+ const width = getDashboardCellWidth({columnCount, gapPx, rowWidth});
28
+
29
+ expect(width).toBe(99);
30
+ expect(width * columnCount + gapPx * (columnCount - 1)).toBeLessThan(rowWidth);
31
+ });
32
+
33
+ it("floors fractional widths so the row still fits every column", () => {
34
+ const columnCount = 3;
35
+ const gapPx = 16;
36
+ const rowWidth = 334;
37
+ const width = getDashboardCellWidth({columnCount, gapPx, rowWidth});
38
+
39
+ expect(width).toBe(100);
40
+ expect(width * columnCount + gapPx * (columnCount - 1)).toBeLessThan(rowWidth);
41
+ });
42
+
43
+ it("uses the full row width for a single column", () => {
44
+ expect(
45
+ getDashboardCellWidth({
46
+ columnCount: 1,
47
+ gapPx: 16,
48
+ rowWidth: 320,
49
+ })
50
+ ).toBe(320);
51
+ });
52
+ });
53
+
54
+ describe("getDashboardCellBoxStyle", () => {
55
+ it("uses calc that subtracts gap before the row is measured on web", () => {
56
+ Platform.OS = "web";
57
+
58
+ expect(
59
+ getDashboardCellBoxStyle({
60
+ columnCount: 3,
61
+ gapPx: 16,
62
+ rowWidth: 0,
63
+ }).width
64
+ ).toBe("calc((100% - 32px) / 3)");
65
+ });
66
+
67
+ it("falls back to a full-width cell on native, which has no calc", () => {
68
+ Platform.OS = "ios";
69
+
70
+ expect(
71
+ getDashboardCellBoxStyle({
72
+ columnCount: 3,
73
+ gapPx: 16,
74
+ rowWidth: 0,
75
+ }).width
76
+ ).toBe("100%");
77
+ });
78
+
79
+ it("pins whole-pixel widths once the row is measured", () => {
80
+ Platform.OS = "web";
81
+
82
+ expect(
83
+ getDashboardCellBoxStyle({
84
+ columnCount: 3,
85
+ gapPx: 16,
86
+ rowWidth: 333,
87
+ })
88
+ ).toEqual({flexGrow: 0, flexShrink: 0, maxWidth: 100, width: 100});
89
+ });
90
+ });
@@ -0,0 +1,60 @@
1
+ import {Platform} from "react-native";
2
+
3
+ export interface DashboardCellStyle {
4
+ [key: string]: unknown;
5
+ flexGrow: 0;
6
+ flexShrink: 0;
7
+ maxWidth: number | string;
8
+ width: number | string;
9
+ }
10
+
11
+ export const getDashboardCellWidth = ({
12
+ columnCount,
13
+ gapPx,
14
+ rowWidth,
15
+ }: {
16
+ columnCount: number;
17
+ gapPx: number;
18
+ rowWidth: number;
19
+ }): number => {
20
+ if (rowWidth <= 0) {
21
+ return 0;
22
+ }
23
+ if (columnCount <= 1) {
24
+ return Math.floor(rowWidth);
25
+ }
26
+
27
+ // Floor to whole pixels so columnCount cells plus their gaps can never exceed rowWidth once
28
+ // the browser or Yoga snaps subpixel values, which would wrap the last tile. An exact fit is
29
+ // still unsafe: onLayout rounds a fractional row up, so give the row a pixel of slack.
30
+ const gapTotal = gapPx * (columnCount - 1);
31
+ const width = Math.floor((rowWidth - gapTotal) / columnCount);
32
+ const fitsWithSlack = width * columnCount + gapTotal < rowWidth;
33
+ return Math.max(fitsWithSlack ? width : width - 1, 0);
34
+ };
35
+
36
+ /**
37
+ * Style for one grid cell. Measured rows use whole-pixel widths. Before the first `onLayout`,
38
+ * web falls back to a `calc()` width that subtracts the same gap; native has no `calc`, so cells
39
+ * fill the row for that one frame instead of collapsing to zero.
40
+ */
41
+ export const getDashboardCellBoxStyle = ({
42
+ columnCount,
43
+ gapPx,
44
+ rowWidth,
45
+ }: {
46
+ columnCount: number;
47
+ gapPx: number;
48
+ rowWidth: number;
49
+ }): DashboardCellStyle => {
50
+ if (rowWidth > 0) {
51
+ const width = getDashboardCellWidth({columnCount, gapPx, rowWidth});
52
+ return {flexGrow: 0, flexShrink: 0, maxWidth: width, width};
53
+ }
54
+ if (columnCount <= 1 || Platform.OS !== "web") {
55
+ return {flexGrow: 0, flexShrink: 0, maxWidth: "100%", width: "100%"};
56
+ }
57
+
58
+ const width = `calc((100% - ${gapPx * (columnCount - 1)}px) / ${columnCount})`;
59
+ return {flexGrow: 0, flexShrink: 0, maxWidth: width, width};
60
+ };