@terreno/ui 57.8.0 → 57.10.1

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 (269) hide show
  1. package/README.md +2 -0
  2. package/dist/AreaChart.d.ts +1 -1
  3. package/dist/AreaChart.d.ts.map +1 -1
  4. package/dist/AreaChart.js +70 -22
  5. package/dist/AreaChart.js.map +1 -1
  6. package/dist/BarChart.d.ts.map +1 -1
  7. package/dist/BarChart.js +55 -13
  8. package/dist/BarChart.js.map +1 -1
  9. package/dist/Button.d.ts.map +1 -1
  10. package/dist/Button.js +19 -4
  11. package/dist/Button.js.map +1 -1
  12. package/dist/ChartCard.d.ts +5 -0
  13. package/dist/ChartCard.d.ts.map +1 -0
  14. package/dist/ChartCard.js +18 -0
  15. package/dist/ChartCard.js.map +1 -0
  16. package/dist/Common.d.ts +147 -6
  17. package/dist/Common.d.ts.map +1 -1
  18. package/dist/Common.js.map +1 -1
  19. package/dist/DashboardGrid.d.ts +6 -2
  20. package/dist/DashboardGrid.d.ts.map +1 -1
  21. package/dist/DashboardGrid.js +43 -10
  22. package/dist/DashboardGrid.js.map +1 -1
  23. package/dist/DateTimeField.d.ts.map +1 -1
  24. package/dist/DateTimeField.js +90 -17
  25. package/dist/DateTimeField.js.map +1 -1
  26. package/dist/DonutChart.d.ts.map +1 -1
  27. package/dist/DonutChart.js +20 -10
  28. package/dist/DonutChart.js.map +1 -1
  29. package/dist/DropdownMenuItem.d.ts +16 -0
  30. package/dist/DropdownMenuItem.d.ts.map +1 -0
  31. package/dist/DropdownMenuItem.js +11 -0
  32. package/dist/DropdownMenuItem.js.map +1 -0
  33. package/dist/FilePickerButton.d.ts +15 -1
  34. package/dist/FilePickerButton.d.ts.map +1 -1
  35. package/dist/FilePickerButton.js +90 -13
  36. package/dist/FilePickerButton.js.map +1 -1
  37. package/dist/GPTChat.d.ts +57 -1
  38. package/dist/GPTChat.d.ts.map +1 -1
  39. package/dist/GPTChat.js +301 -20
  40. package/dist/GPTChat.js.map +1 -1
  41. package/dist/HtmlFrame.d.ts +11 -0
  42. package/dist/HtmlFrame.d.ts.map +1 -0
  43. package/dist/HtmlFrame.js +29 -0
  44. package/dist/HtmlFrame.js.map +1 -0
  45. package/dist/LineChart.d.ts +1 -1
  46. package/dist/LineChart.d.ts.map +1 -1
  47. package/dist/LineChart.js +62 -21
  48. package/dist/LineChart.js.map +1 -1
  49. package/dist/Scorecard.d.ts +5 -0
  50. package/dist/Scorecard.d.ts.map +1 -0
  51. package/dist/Scorecard.js +11 -0
  52. package/dist/Scorecard.js.map +1 -0
  53. package/dist/SparklineChart.d.ts +5 -0
  54. package/dist/SparklineChart.d.ts.map +1 -0
  55. package/dist/SparklineChart.js +35 -0
  56. package/dist/SparklineChart.js.map +1 -0
  57. package/dist/Text.d.ts +1 -1
  58. package/dist/Text.d.ts.map +1 -1
  59. package/dist/Text.js +2 -2
  60. package/dist/Text.js.map +1 -1
  61. package/dist/TextField.d.ts.map +1 -1
  62. package/dist/TextField.js +12 -4
  63. package/dist/TextField.js.map +1 -1
  64. package/dist/ToastNotifications.d.ts.map +1 -1
  65. package/dist/ToastNotifications.js +29 -6
  66. package/dist/ToastNotifications.js.map +1 -1
  67. package/dist/WebDropdownMenu.d.ts +2 -1
  68. package/dist/WebDropdownMenu.d.ts.map +1 -1
  69. package/dist/WebDropdownMenu.js +2 -6
  70. package/dist/WebDropdownMenu.js.map +1 -1
  71. package/dist/asks/AskCard.d.ts +34 -0
  72. package/dist/asks/AskCard.d.ts.map +1 -0
  73. package/dist/asks/AskCard.js +91 -0
  74. package/dist/asks/AskCard.js.map +1 -0
  75. package/dist/asks/AskChoice.d.ts +11 -0
  76. package/dist/asks/AskChoice.d.ts.map +1 -0
  77. package/dist/asks/AskChoice.js +146 -0
  78. package/dist/asks/AskChoice.js.map +1 -0
  79. package/dist/asks/AskConfirm.d.ts +15 -0
  80. package/dist/asks/AskConfirm.d.ts.map +1 -0
  81. package/dist/asks/AskConfirm.js +17 -0
  82. package/dist/asks/AskConfirm.js.map +1 -0
  83. package/dist/asks/AskFiles.d.ts +18 -0
  84. package/dist/asks/AskFiles.d.ts.map +1 -0
  85. package/dist/asks/AskFiles.js +149 -0
  86. package/dist/asks/AskFiles.js.map +1 -0
  87. package/dist/asks/AskForm.d.ts +27 -0
  88. package/dist/asks/AskForm.d.ts.map +1 -0
  89. package/dist/asks/AskForm.js +146 -0
  90. package/dist/asks/AskForm.js.map +1 -0
  91. package/dist/asks/AskMarkdown.d.ts +25 -0
  92. package/dist/asks/AskMarkdown.d.ts.map +1 -0
  93. package/dist/asks/AskMarkdown.js +73 -0
  94. package/dist/asks/AskMarkdown.js.map +1 -0
  95. package/dist/asks/SimpleAskCard.d.ts +23 -0
  96. package/dist/asks/SimpleAskCard.d.ts.map +1 -0
  97. package/dist/asks/SimpleAskCard.js +32 -0
  98. package/dist/asks/SimpleAskCard.js.map +1 -0
  99. package/dist/asks/askControls.d.ts +33 -0
  100. package/dist/asks/askControls.d.ts.map +1 -0
  101. package/dist/asks/askControls.js +30 -0
  102. package/dist/asks/askControls.js.map +1 -0
  103. package/dist/asks/askFileRefs.d.ts +26 -0
  104. package/dist/asks/askFileRefs.d.ts.map +1 -0
  105. package/dist/asks/askFileRefs.js +75 -0
  106. package/dist/asks/askFileRefs.js.map +1 -0
  107. package/dist/asks/askFormDraft.d.ts +60 -0
  108. package/dist/asks/askFormDraft.d.ts.map +1 -0
  109. package/dist/asks/askFormDraft.js +224 -0
  110. package/dist/asks/askFormDraft.js.map +1 -0
  111. package/dist/asks/askSummary.d.ts +10 -0
  112. package/dist/asks/askSummary.d.ts.map +1 -0
  113. package/dist/asks/askSummary.js +138 -0
  114. package/dist/asks/askSummary.js.map +1 -0
  115. package/dist/asks/askTypes.d.ts +21 -0
  116. package/dist/asks/askTypes.d.ts.map +1 -0
  117. package/dist/asks/askTypes.js +2 -0
  118. package/dist/asks/askTypes.js.map +1 -0
  119. package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
  120. package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
  121. package/dist/asks/simpleCardButtonVariants.js +8 -0
  122. package/dist/asks/simpleCardButtonVariants.js.map +1 -0
  123. package/dist/blocks/BlocksError.d.ts +8 -0
  124. package/dist/blocks/BlocksError.d.ts.map +1 -0
  125. package/dist/blocks/BlocksError.js +14 -0
  126. package/dist/blocks/BlocksError.js.map +1 -0
  127. package/dist/blocks/BlocksView.d.ts +10 -0
  128. package/dist/blocks/BlocksView.d.ts.map +1 -0
  129. package/dist/blocks/BlocksView.js +90 -0
  130. package/dist/blocks/BlocksView.js.map +1 -0
  131. package/dist/blocks/blockRenderers.d.ts +25 -0
  132. package/dist/blocks/blockRenderers.d.ts.map +1 -0
  133. package/dist/blocks/blockRenderers.js +136 -0
  134. package/dist/blocks/blockRenderers.js.map +1 -0
  135. package/dist/blocks/datasetToPoints.d.ts +22 -0
  136. package/dist/blocks/datasetToPoints.d.ts.map +1 -0
  137. package/dist/blocks/datasetToPoints.js +28 -0
  138. package/dist/blocks/datasetToPoints.js.map +1 -0
  139. package/dist/blocks/useBlockSelections.d.ts +6 -0
  140. package/dist/blocks/useBlockSelections.d.ts.map +1 -0
  141. package/dist/blocks/useBlockSelections.js +10 -0
  142. package/dist/blocks/useBlockSelections.js.map +1 -0
  143. package/dist/blocks/useResolvedDatasets.d.ts +18 -0
  144. package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
  145. package/dist/blocks/useResolvedDatasets.js +59 -0
  146. package/dist/blocks/useResolvedDatasets.js.map +1 -0
  147. package/dist/blocks/useResolvedImages.d.ts +15 -0
  148. package/dist/blocks/useResolvedImages.d.ts.map +1 -0
  149. package/dist/blocks/useResolvedImages.js +66 -0
  150. package/dist/blocks/useResolvedImages.js.map +1 -0
  151. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  152. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  153. package/dist/charts/ChartFacadeContainer.js +10 -0
  154. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  155. package/dist/charts/ChartFrame.d.ts +4 -0
  156. package/dist/charts/ChartFrame.d.ts.map +1 -1
  157. package/dist/charts/ChartFrame.js +4 -2
  158. package/dist/charts/ChartFrame.js.map +1 -1
  159. package/dist/charts/layout.d.ts +9 -2
  160. package/dist/charts/layout.d.ts.map +1 -1
  161. package/dist/charts/layout.js +28 -6
  162. package/dist/charts/layout.js.map +1 -1
  163. package/dist/charts/scales.d.ts +3 -1
  164. package/dist/charts/scales.d.ts.map +1 -1
  165. package/dist/charts/scales.js +7 -7
  166. package/dist/charts/scales.js.map +1 -1
  167. package/dist/charts/series.d.ts +15 -0
  168. package/dist/charts/series.d.ts.map +1 -0
  169. package/dist/charts/series.js +19 -0
  170. package/dist/charts/series.js.map +1 -0
  171. package/dist/charts/types/chartTypes.d.ts +7 -0
  172. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  173. package/dist/dashboardGridLayout.d.ts +6 -0
  174. package/dist/dashboardGridLayout.d.ts.map +1 -1
  175. package/dist/dashboardGridLayout.js +19 -3
  176. package/dist/dashboardGridLayout.js.map +1 -1
  177. package/dist/index.d.ts +9 -1
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +4 -1
  180. package/dist/index.js.map +1 -1
  181. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
  182. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  183. package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
  184. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  185. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  186. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  187. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  188. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  189. package/package.json +2 -1
  190. package/src/AIRequestExplorer.test.tsx +2 -2
  191. package/src/AreaChart.test.tsx +81 -0
  192. package/src/AreaChart.tsx +171 -62
  193. package/src/BarChart.test.tsx +119 -0
  194. package/src/BarChart.tsx +94 -20
  195. package/src/Button.test.tsx +72 -0
  196. package/src/Button.tsx +34 -4
  197. package/src/ChartCard.test.tsx +79 -0
  198. package/src/ChartCard.tsx +80 -0
  199. package/src/Common.ts +136 -2
  200. package/src/DashboardGrid.test.tsx +98 -1
  201. package/src/DashboardGrid.tsx +71 -20
  202. package/src/DateTimeField.test.tsx +185 -2
  203. package/src/DateTimeField.tsx +106 -16
  204. package/src/DonutChart.test.tsx +78 -10
  205. package/src/DonutChart.tsx +87 -14
  206. package/src/DropdownMenuItem.tsx +48 -0
  207. package/src/FilePickerButton.test.tsx +116 -9
  208. package/src/FilePickerButton.tsx +177 -23
  209. package/src/GPTChat.test.tsx +891 -8
  210. package/src/GPTChat.tsx +713 -45
  211. package/src/HtmlFrame.tsx +60 -0
  212. package/src/LineChart.test.tsx +109 -10
  213. package/src/LineChart.tsx +154 -58
  214. package/src/Scorecard.test.tsx +65 -0
  215. package/src/Scorecard.tsx +45 -0
  216. package/src/SparklineChart.test.tsx +69 -0
  217. package/src/SparklineChart.tsx +85 -0
  218. package/src/Text.test.tsx +22 -0
  219. package/src/Text.tsx +10 -1
  220. package/src/TextField.test.tsx +16 -0
  221. package/src/TextField.tsx +13 -3
  222. package/src/ToastNotifications.tsx +33 -6
  223. package/src/ToastNotifications.webModal.test.tsx +285 -0
  224. package/src/WebDropdownMenu.tsx +3 -7
  225. package/src/asks/AskCard.test.tsx +1428 -0
  226. package/src/asks/AskCard.tsx +240 -0
  227. package/src/asks/AskChoice.tsx +368 -0
  228. package/src/asks/AskConfirm.tsx +42 -0
  229. package/src/asks/AskFiles.test.tsx +347 -0
  230. package/src/asks/AskFiles.tsx +246 -0
  231. package/src/asks/AskForm.tsx +334 -0
  232. package/src/asks/AskMarkdown.tsx +176 -0
  233. package/src/asks/SimpleAskCard.test.tsx +253 -0
  234. package/src/asks/SimpleAskCard.tsx +82 -0
  235. package/src/asks/askControls.tsx +98 -0
  236. package/src/asks/askFileRefs.test.ts +155 -0
  237. package/src/asks/askFileRefs.ts +98 -0
  238. package/src/asks/askFormDraft.test.ts +347 -0
  239. package/src/asks/askFormDraft.ts +309 -0
  240. package/src/asks/askSummary.test.ts +255 -0
  241. package/src/asks/askSummary.ts +160 -0
  242. package/src/asks/askTypes.ts +25 -0
  243. package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
  244. package/src/asks/simpleCardButtonVariants.ts +14 -0
  245. package/src/blocks/BlocksError.tsx +28 -0
  246. package/src/blocks/BlocksView.test.tsx +607 -0
  247. package/src/blocks/BlocksView.tsx +125 -0
  248. package/src/blocks/blockRenderers.tsx +288 -0
  249. package/src/blocks/datasetToPoints.test.ts +31 -0
  250. package/src/blocks/datasetToPoints.ts +48 -0
  251. package/src/blocks/useBlockSelections.ts +13 -0
  252. package/src/blocks/useResolvedDatasets.ts +78 -0
  253. package/src/blocks/useResolvedImages.ts +81 -0
  254. package/src/bunSetup.ts +1 -0
  255. package/src/charts/ChartFacadeContainer.tsx +35 -0
  256. package/src/charts/ChartFrame.tsx +39 -1
  257. package/src/charts/layout.test.ts +22 -1
  258. package/src/charts/layout.ts +37 -4
  259. package/src/charts/scales.test.ts +33 -0
  260. package/src/charts/scales.ts +10 -6
  261. package/src/charts/series.ts +43 -0
  262. package/src/charts/types/chartTypes.ts +8 -0
  263. package/src/dashboardGridLayout.test.ts +59 -1
  264. package/src/dashboardGridLayout.ts +30 -3
  265. package/src/index.tsx +13 -0
  266. package/src/isolated/HtmlFrame.isolated.tsx +54 -0
  267. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
  268. package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
  269. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -18,6 +18,13 @@ import {useTheme} from "./Theme";
18
18
  import {TimezonePicker} from "./TimezonePicker";
19
19
  import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
20
20
 
21
+ /** The state each segment index edits, per field type. */
22
+ const SEGMENT_NAMES = {
23
+ date: ["month", "day", "year"],
24
+ datetime: ["month", "day", "year", "hour", "minute"],
25
+ time: ["hour", "minute"],
26
+ } as const;
27
+
21
28
  interface SeparatorProps {
22
29
  type: "date" | "time";
23
30
  }
@@ -418,6 +425,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
418
425
  title,
419
426
  value,
420
427
  onChange,
428
+ onEntryStatusChange,
421
429
  timezone: providedTimezone,
422
430
  onTimezoneChange,
423
431
  errorText,
@@ -436,6 +444,18 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
436
444
  const [year, setYear] = useState("");
437
445
  const [hour, setHour] = useState("");
438
446
  const [minute, setMinute] = useState("");
447
+ // Whether the minute's "00" came from the user clearing the segment rather than from a value.
448
+ const isMinuteClearedRef = useRef(false);
449
+ // The last value this field emitted, so a controlled parent passing it back is not taken as
450
+ // an external change.
451
+ const lastEmittedRef = useRef<string | undefined>(undefined);
452
+ const emitChange = useCallback(
453
+ (next: string): void => {
454
+ lastEmittedRef.current = next;
455
+ onChange(next);
456
+ },
457
+ [onChange]
458
+ );
439
459
  const [fieldErrors, setFieldErrors] = useState<Record<number, string | undefined>>({});
440
460
  const [localTimezone, setLocalTimezone] = useState(
441
461
  providedTimezone ?? DateTime.local().zoneName ?? "UTC"
@@ -574,10 +594,13 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
574
594
  const hourVal = override?.hour ?? hour;
575
595
  let date: DateTime;
576
596
  if (type === "datetime") {
577
- if (!monthVal || !dayVal || !yearVal || !hour || !minuteVal) {
597
+ if (!monthVal || !dayVal || !yearVal || !hourVal || !minuteVal) {
578
598
  return undefined;
579
599
  }
580
600
  let hourNum = parseInt(hourVal, 10);
601
+ if (Number.isNaN(hourNum)) {
602
+ return undefined;
603
+ }
581
604
  if (ampPmVal === "pm" && hourNum !== 12) {
582
605
  hourNum += 12;
583
606
  } else if (ampPmVal === "am" && hourNum === 12) {
@@ -616,10 +639,13 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
616
639
  }
617
640
  );
618
641
  } else {
619
- if (!hour || !minuteVal) {
642
+ if (!hourVal || !minuteVal) {
643
+ return undefined;
644
+ }
645
+ let hourNum = parseInt(hourVal, 10);
646
+ if (Number.isNaN(hourNum)) {
620
647
  return undefined;
621
648
  }
622
- let hourNum = parseInt(hour, 10);
623
649
  if (ampPmVal === "pm" && hourNum !== 12) {
624
650
  hourNum += 12;
625
651
  } else if (ampPmVal === "am" && hourNum === 12) {
@@ -647,6 +673,37 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
647
673
  [amPm, month, day, year, hour, minute, timezone, type]
648
674
  );
649
675
 
676
+ /**
677
+ * Tells `onEntryStatusChange` what the segments hold after a typed change: nothing, an entry
678
+ * that is unfinished or has a segment error, or a complete value. Clearing the minute segment
679
+ * resets it to "00", so a "00" minute counts as empty only when the user cleared it; the "00"
680
+ * of an on-the-hour value is still part of the entry.
681
+ */
682
+ const reportEntryStatus = useCallback(
683
+ (
684
+ override: {day?: string; hour?: string; minute?: string; month?: string; year?: string},
685
+ errors: Record<number, string | undefined>
686
+ ): void => {
687
+ if (!onEntryStatusChange) {
688
+ return;
689
+ }
690
+ const next = {day, hour, minute, month, year, ...override};
691
+ const dateParts = type === "time" ? [] : [next.month, next.day, next.year];
692
+ const timeParts = type === "date" ? [] : [next.hour];
693
+ const hasMinute =
694
+ type !== "date" &&
695
+ next.minute !== "" &&
696
+ !(next.minute === "00" && isMinuteClearedRef.current);
697
+ if (![...dateParts, ...timeParts].some(Boolean) && !hasMinute) {
698
+ onEntryStatusChange("empty");
699
+ return;
700
+ }
701
+ const hasError = Object.values(errors).some((error) => error !== undefined);
702
+ onEntryStatusChange(!hasError && getISOFromFields(override) ? "valid" : "invalid");
703
+ },
704
+ [onEntryStatusChange, day, hour, minute, month, year, type, getISOFromFields]
705
+ );
706
+
650
707
  /**
651
708
  * Handles text changes in any {@link DateTimeSegment} input.
652
709
  * Strips non-numeric characters, validates the value, updates local state,
@@ -665,14 +722,21 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
665
722
  // This lets users freely edit or clear the minute field without breaking the time format.
666
723
  const finalValue = numericValue === "" ? "00" : numericValue.slice(-2);
667
724
  const minuteNum = parseInt(finalValue, 10);
725
+ isMinuteClearedRef.current = numericValue === "";
668
726
 
669
727
  // Update the minute state so the UI reflects the latest input,
670
728
  // even if it's temporarily invalid
671
729
  // This allows the user to freely edit or clear the field.
672
730
  setMinute(finalValue);
673
731
 
732
+ const isValidMinute = !Number.isNaN(minuteNum) && minuteNum >= 0 && minuteNum <= 59;
733
+ reportEntryStatus(
734
+ {minute: finalValue},
735
+ {...fieldErrors, [index]: isValidMinute ? undefined : "Minute must be between 0 and 59"}
736
+ );
737
+
674
738
  // Only update ref and result if it's a valid minute value
675
- if (!Number.isNaN(minuteNum) && minuteNum >= 0 && minuteNum <= 59) {
739
+ if (isValidMinute) {
676
740
  pendingValueRef.current = {minute: finalValue};
677
741
  setFieldErrors((prev) => ({...prev, [index]: undefined}));
678
742
 
@@ -681,7 +745,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
681
745
  if (result) {
682
746
  const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
683
747
  if (result !== currentValueUTC) {
684
- onChange(result);
748
+ emitChange(result);
685
749
  }
686
750
  }
687
751
  } else {
@@ -700,6 +764,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
700
764
 
701
765
  const error = validateField(index, finalValue);
702
766
  setFieldErrors((prev) => ({...prev, [index]: error}));
767
+ const segmentName = SEGMENT_NAMES[type][index];
768
+ if (segmentName) {
769
+ reportEntryStatus({[segmentName]: finalValue}, {...fieldErrors, [index]: error});
770
+ }
703
771
 
704
772
  if (type === "date" || type === "datetime") {
705
773
  if (index === 0) {
@@ -744,7 +812,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
744
812
  if (result) {
745
813
  const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
746
814
  if (result !== currentValueUTC) {
747
- onChange(result);
815
+ emitChange(result);
748
816
  }
749
817
  }
750
818
  }
@@ -756,7 +824,19 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
756
824
  inputRefs.current[index + 1]?.focus();
757
825
  }
758
826
  },
759
- [type, getFieldConfigs, getISOFromFields, onChange, value, validateField, month, day, year]
827
+ [
828
+ type,
829
+ getFieldConfigs,
830
+ getISOFromFields,
831
+ emitChange,
832
+ value,
833
+ validateField,
834
+ month,
835
+ day,
836
+ year,
837
+ fieldErrors,
838
+ reportEntryStatus,
839
+ ]
760
840
  );
761
841
 
762
842
  /**
@@ -768,7 +848,8 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
768
848
  (inputDate: string) => {
769
849
  // Handle clear case - empty string should clear the field
770
850
  if (!inputDate || inputDate === "") {
771
- onChange("");
851
+ emitChange("");
852
+ onEntryStatusChange?.("empty");
772
853
  setShowDate(false);
773
854
  return;
774
855
  }
@@ -794,6 +875,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
794
875
  hourNum = hourNum === 0 ? 12 : hourNum;
795
876
  setHour(hourNum.toString().padStart(2, "0"));
796
877
  setMinute(parsedDate.minute.toString().padStart(2, "0"));
878
+ isMinuteClearedRef.current = false;
797
879
  }
798
880
 
799
881
  // Normalize emitted value to ISO (UTC for date-only)
@@ -804,10 +886,11 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
804
886
  .set({millisecond: 0, second: 0})
805
887
  .toISO()
806
888
  : parsedDate.set({millisecond: 0, second: 0}).toUTC().toISO();
807
- onChange(normalized ?? "");
889
+ emitChange(normalized ?? "");
890
+ onEntryStatusChange?.("valid");
808
891
  setShowDate(false);
809
892
  },
810
- [onChange, type]
893
+ [emitChange, onEntryStatusChange, type]
811
894
  );
812
895
 
813
896
  /**
@@ -820,13 +903,14 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
820
903
  // Compare in UTC to avoid timezone issues
821
904
  const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
822
905
  if (iso && iso !== currentValueUTC) {
823
- onChange(iso);
906
+ emitChange(iso);
824
907
  }
908
+ reportEntryStatus({...pendingValueRef.current}, fieldErrors);
825
909
 
826
910
  // Clear the pending value after processing
827
911
  pendingValueRef.current = undefined;
828
912
  },
829
- [getISOFromFields, onChange, value]
913
+ [getISOFromFields, emitChange, value, reportEntryStatus, fieldErrors]
830
914
  );
831
915
 
832
916
  // Handle external value changes
@@ -865,6 +949,12 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
865
949
  hourNum = hourNum === 0 ? 12 : hourNum;
866
950
  setHour(hourNum.toString().padStart(2, "0"));
867
951
  setMinute(parsedDate.minute.toString().padStart(2, "0"));
952
+ const lastEmitted = lastEmittedRef.current
953
+ ? DateTime.fromISO(lastEmittedRef.current)
954
+ : undefined;
955
+ if (!lastEmitted?.isValid || lastEmitted.toMillis() !== parsedDate.toMillis()) {
956
+ isMinuteClearedRef.current = false;
957
+ }
868
958
  }
869
959
  }, [value, type, timezone]);
870
960
 
@@ -936,10 +1026,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
936
1026
  const iso = getISOFromFields({amPm: newAmPm});
937
1027
  const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
938
1028
  if (iso && iso !== currentValueUTC) {
939
- onChange(iso);
1029
+ emitChange(iso);
940
1030
  }
941
1031
  },
942
- [getISOFromFields, value, onChange]
1032
+ [getISOFromFields, value, emitChange]
943
1033
  );
944
1034
 
945
1035
  /** Handles timezone changes from the TimezonePicker, recomputes and emits the ISO value. */
@@ -953,10 +1043,10 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
953
1043
  const iso = getISOFromFields({timezone: tz});
954
1044
  const currentValueUTC = value ? DateTime.fromISO(value).toUTC().toISO() : undefined;
955
1045
  if (iso && iso !== currentValueUTC) {
956
- onChange(iso);
1046
+ emitChange(iso);
957
1047
  }
958
1048
  },
959
- [getISOFromFields, value, onChange, onTimezoneChange]
1049
+ [getISOFromFields, value, emitChange, onTimezoneChange]
960
1050
  );
961
1051
 
962
1052
  const openActionSheet = useCallback((): void => {
@@ -1,6 +1,6 @@
1
- import {describe, expect, it, spyOn} from "bun:test";
1
+ import {describe, expect, it} from "bun:test";
2
2
  import {act, fireEvent} from "@testing-library/react-native";
3
- import {Linking} from "react-native";
3
+ import {assert} from "chai";
4
4
 
5
5
  import {DonutChart} from "./DonutChart";
6
6
  import {renderWithTheme} from "./test-utils";
@@ -11,6 +11,78 @@ const POINTS = [
11
11
  ];
12
12
 
13
13
  describe("DonutChart", () => {
14
+ it("renders center copy and default percent shares in the legend", () => {
15
+ const {getAllByText, getByTestId, getByText} = renderWithTheme(
16
+ <DonutChart centerTitle="Cost" centerValue="$1.15K" data={POINTS} testID="chart" />
17
+ );
18
+
19
+ assert.exists(getByText("$1.15K"));
20
+ assert.exists(getByText("Cost"));
21
+ assert.exists(getByTestId("chart.center"));
22
+ assert.exists(getByTestId("chart.center.value"));
23
+ assert.exists(getByTestId("chart.center.title"));
24
+ assert.equal(getByTestId("chart.share.0").props.children, "50%");
25
+ assert.lengthOf(getAllByText("50%"), 2);
26
+ });
27
+
28
+ it("supports custom share formatting and a single 100% slice", () => {
29
+ const {getByTestId, getByText} = renderWithTheme(
30
+ <DonutChart
31
+ centerTitle="Conversions"
32
+ centerValue="7.00"
33
+ data={[{label: "Mobile phones", value: 7}]}
34
+ formatShare={(value, total): string => `${value} of ${total}`}
35
+ testID="chart"
36
+ />
37
+ );
38
+
39
+ assert.isNotEmpty(getByTestId("chart.slice.0").props.d);
40
+ assert.exists(getByText("7 of 7"));
41
+ assert.exists(getByText("7.00"));
42
+ });
43
+
44
+ it("formats one full slice as 100% and zero totals as 0%", () => {
45
+ const full = renderWithTheme(
46
+ <DonutChart data={[{label: "Mobile phones", value: 7}]} testID="full-chart" />
47
+ );
48
+ assert.equal(full.getByTestId("full-chart.share.0").props.children, "100%");
49
+
50
+ const emptyTotal = renderWithTheme(
51
+ <DonutChart
52
+ data={[
53
+ {label: "A", value: 0},
54
+ {label: "B", value: -1},
55
+ ]}
56
+ testID="zero-chart"
57
+ />
58
+ );
59
+ assert.equal(emptyTotal.getByTestId("zero-chart.share.0").props.children, "0%");
60
+ assert.equal(emptyTotal.getByTestId("zero-chart.share.1").props.children, "0%");
61
+ });
62
+
63
+ it("renders chart-card header shortcuts and omits them without title", async (): Promise<void> => {
64
+ let pressCount = 0;
65
+ const titled = renderWithTheme(
66
+ <DonutChart
67
+ data={POINTS}
68
+ onPeriodPress={(): void => {
69
+ pressCount += 1;
70
+ }}
71
+ periodLabel="Last 30 days"
72
+ testID="chart"
73
+ title="Cost by Device"
74
+ />
75
+ );
76
+ assert.exists(titled.getByText("Cost by Device"));
77
+ assert.exists(titled.getByText("Last 30 days"));
78
+ fireEvent.press(titled.getByTestId("chart.card.period-clickable"));
79
+ await new Promise((resolve) => setTimeout(resolve, 0));
80
+ assert.equal(pressCount, 1);
81
+
82
+ const plain = renderWithTheme(<DonutChart data={POINTS} testID="plain-chart" />);
83
+ assert.notExists(plain.queryByTestId("plain-chart.card"));
84
+ });
85
+
14
86
  it("renders one mark testID per slice", () => {
15
87
  const {getByTestId, queryByTestId} = renderWithTheme(
16
88
  <DonutChart data={POINTS} testID="chart" />
@@ -105,17 +177,13 @@ describe("DonutChart", () => {
105
177
  expect(queryByTestId("chart.tooltip")).toBeNull();
106
178
  });
107
179
 
108
- it("does not open URLs from slice legend labels", async () => {
109
- const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
180
+ it("does not open URLs from slice legend labels", () => {
110
181
  const {getByText} = renderWithTheme(
111
182
  <DonutChart data={[{label: "https://evil.example", value: 10}]} />
112
183
  );
113
184
 
114
- await act(async () => {
115
- fireEvent.press(getByText("https://evil.example"));
116
- });
117
-
118
- expect(openURLSpy).not.toHaveBeenCalled();
119
- openURLSpy.mockRestore();
185
+ // The suite shares one Linking mock, so a spy on openURL also records calls
186
+ // from other files. A label is inert when it has no press handler.
187
+ expect(getByText("https://evil.example").props.onPress).toBeUndefined();
120
188
  });
121
189
  });
@@ -4,11 +4,13 @@ import {Path, Svg} from "react-native-svg";
4
4
 
5
5
  import {Box} from "./Box";
6
6
  import type {DonutChartProps, LayoutChangeEvent} from "./Common";
7
+ import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
7
8
  import {ChartFrame} from "./charts/ChartFrame";
8
9
  import {getDonutSize} from "./charts/layout";
9
10
  import {getDonutSliceAngles, getDonutSliceHitCenter, getDonutSlicePath} from "./charts/paths";
10
11
  import {getChartPaint} from "./charts/theme";
11
12
  import type {ChartPoint} from "./charts/types/chartTypes";
13
+ import {Heading} from "./Heading";
12
14
  import {Text} from "./Text";
13
15
  import {useTheme} from "./Theme";
14
16
  import {resolveTestID} from "./testing/resolveTestId";
@@ -16,6 +18,13 @@ import {resolveTestID} from "./testing/resolveTestId";
16
18
  const DEFAULT_SIZE = 220;
17
19
  const MARK_HIT_SIZE = 24;
18
20
 
21
+ const formatDefaultShare = (value: number, total: number): string => {
22
+ if (total <= 0) {
23
+ return "0%";
24
+ }
25
+ return `${Math.round((Math.max(value, 0) / total) * 100)}%`;
26
+ };
27
+
19
28
  const formatChartTooltip = ({
20
29
  formatValue,
21
30
  point,
@@ -38,12 +47,18 @@ const getSliceAngles = (
38
47
 
39
48
  export const DonutChart: FC<DonutChartProps> = ({
40
49
  accessibilityLabel,
50
+ centerTitle,
51
+ centerValue,
41
52
  data,
42
53
  emptyText = "No data",
54
+ formatShare = formatDefaultShare,
43
55
  formatValue = String,
44
56
  height = DEFAULT_SIZE,
45
57
  loading = false,
58
+ onPeriodPress,
59
+ periodLabel,
46
60
  testID,
61
+ title,
47
62
  }) => {
48
63
  const {theme} = useTheme();
49
64
  const paint = getChartPaint(theme);
@@ -66,13 +81,14 @@ export const DonutChart: FC<DonutChartProps> = ({
66
81
  const outerRadius = Math.max(size / 2 - 8, 1);
67
82
  const innerRadius = outerRadius * 0.55;
68
83
  const slices = getSliceAngles(data);
84
+ const total = data.reduce((sum, point) => sum + Math.max(point.value, 0), 0);
69
85
  const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
70
86
  const tooltipText = activePoint
71
87
  ? formatChartTooltip({formatValue, point: activePoint})
72
88
  : undefined;
73
89
  const summaryLabel = accessibilityLabel ?? "Donut chart";
74
90
 
75
- return (
91
+ const chart = (
76
92
  <ChartFrame
77
93
  accessibilityLabel={summaryLabel}
78
94
  emptyText={emptyText}
@@ -100,10 +116,39 @@ export const DonutChart: FC<DonutChartProps> = ({
100
116
  })}
101
117
  fill={slice.point.color ?? paint.slices[index % paint.slices.length]}
102
118
  key={`slice-${slice.point.label}`}
119
+ testID={resolveTestID(testID, `slice.${index}`)}
103
120
  transform={`translate(${center}, ${center})`}
104
121
  />
105
122
  ))}
106
123
  </Svg>
124
+ {centerValue || centerTitle ? (
125
+ <Box
126
+ alignItems="center"
127
+ dangerouslySetInlineStyle={{__style: {left: 0, top: 0}}}
128
+ height={size}
129
+ justifyContent="center"
130
+ position="absolute"
131
+ testID={resolveTestID(testID, "center")}
132
+ width={size}
133
+ >
134
+ {centerValue ? (
135
+ <Heading align="center" size="sm" testID={resolveTestID(testID, "center.value")}>
136
+ {centerValue}
137
+ </Heading>
138
+ ) : null}
139
+ {centerTitle ? (
140
+ <Text
141
+ align="center"
142
+ color="secondaryDark"
143
+ size="sm"
144
+ skipLinking
145
+ testID={resolveTestID(testID, "center.title")}
146
+ >
147
+ {centerTitle}
148
+ </Text>
149
+ ) : null}
150
+ </Box>
151
+ ) : null}
107
152
  {slices.map((slice, index) => {
108
153
  const onPress = (): void => {
109
154
  handleMarkPress(index);
@@ -134,19 +179,36 @@ export const DonutChart: FC<DonutChartProps> = ({
134
179
  </Box>
135
180
  <Box direction="column" gap={1} padding={2}>
136
181
  {data.map((point, index) => (
137
- <Box direction="row" gap={2} key={`legend-${point.label}`}>
138
- <Box
139
- dangerouslySetInlineStyle={{
140
- __style: {
141
- backgroundColor: point.color ?? paint.slices[index % paint.slices.length],
142
- height: 12,
143
- width: 12,
144
- },
145
- }}
146
- testID={resolveTestID(testID, `swatch.${index}`)}
147
- />
148
- <Text size="sm" skipLinking>
149
- {point.label}
182
+ <Box
183
+ direction="row"
184
+ gap={2}
185
+ justifyContent="between"
186
+ key={`legend-${point.label}`}
187
+ minWidth={0}
188
+ width="100%"
189
+ >
190
+ <Box alignItems="center" direction="row" gap={2} minWidth={0}>
191
+ <Box
192
+ dangerouslySetInlineStyle={{
193
+ __style: {
194
+ backgroundColor: point.color ?? paint.slices[index % paint.slices.length],
195
+ height: 12,
196
+ width: 12,
197
+ },
198
+ }}
199
+ testID={resolveTestID(testID, `swatch.${index}`)}
200
+ />
201
+ <Text size="sm" skipLinking truncate>
202
+ {point.label}
203
+ </Text>
204
+ </Box>
205
+ <Text
206
+ color="secondaryDark"
207
+ size="sm"
208
+ skipLinking
209
+ testID={resolveTestID(testID, `share.${index}`)}
210
+ >
211
+ {formatShare(point.value, total)}
150
212
  </Text>
151
213
  </Box>
152
214
  ))}
@@ -154,6 +216,17 @@ export const DonutChart: FC<DonutChartProps> = ({
154
216
  </Box>
155
217
  </ChartFrame>
156
218
  );
219
+
220
+ return (
221
+ <ChartFacadeContainer
222
+ onPeriodPress={onPeriodPress}
223
+ periodLabel={periodLabel}
224
+ testID={testID}
225
+ title={title}
226
+ >
227
+ {chart}
228
+ </ChartFacadeContainer>
229
+ );
157
230
  };
158
231
 
159
232
  export type {DonutChartProps} from "./Common";
@@ -0,0 +1,48 @@
1
+ import type React from "react";
2
+ import {Pressable} from "react-native";
3
+
4
+ import {Box} from "./Box";
5
+ import type {IconName, IconProps, TextColor} from "./Common";
6
+ import {Icon} from "./Icon";
7
+ import {Text} from "./Text";
8
+
9
+ export interface DropdownMenuItemProps {
10
+ accessibilityLabel?: string;
11
+ /** Text and icon color. Defaults to the dark secondary text color. */
12
+ color?: TextColor;
13
+ iconName: IconName;
14
+ /** Icon style. Defaults to the outlined `regular` glyph. */
15
+ iconType?: IconProps["type"];
16
+ label: string;
17
+ onClick: () => void;
18
+ testID?: string;
19
+ }
20
+
21
+ /** A single icon + label row for an action menu rendered inside a `DropdownPanel`. */
22
+ export const DropdownMenuItem = ({
23
+ accessibilityLabel,
24
+ color = "secondaryDark",
25
+ iconName,
26
+ iconType = "regular",
27
+ label,
28
+ onClick,
29
+ testID,
30
+ }: DropdownMenuItemProps): React.ReactElement => {
31
+ // A plain Pressable keeps onClick synchronous with the press, which web file pickers need.
32
+ return (
33
+ <Pressable
34
+ accessibilityHint={`Press to ${label.toLowerCase()}`}
35
+ accessibilityLabel={accessibilityLabel ?? label}
36
+ accessibilityRole="menuitem"
37
+ onPress={onClick}
38
+ testID={testID}
39
+ >
40
+ <Box alignItems="center" direction="row" gap={2} paddingX={2} paddingY={2} rounding="md">
41
+ <Icon color={color} iconName={iconName} size="sm" type={iconType} />
42
+ <Text color={color} size="sm">
43
+ {label}
44
+ </Text>
45
+ </Box>
46
+ </Pressable>
47
+ );
48
+ };