@terreno/ui 57.8.0 → 57.9.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 (134) hide show
  1. package/dist/AreaChart.d.ts +1 -1
  2. package/dist/AreaChart.d.ts.map +1 -1
  3. package/dist/AreaChart.js +70 -22
  4. package/dist/AreaChart.js.map +1 -1
  5. package/dist/BarChart.d.ts.map +1 -1
  6. package/dist/BarChart.js +55 -13
  7. package/dist/BarChart.js.map +1 -1
  8. package/dist/ChartCard.d.ts +5 -0
  9. package/dist/ChartCard.d.ts.map +1 -0
  10. package/dist/ChartCard.js +18 -0
  11. package/dist/ChartCard.js.map +1 -0
  12. package/dist/Common.d.ts +79 -5
  13. package/dist/Common.d.ts.map +1 -1
  14. package/dist/Common.js.map +1 -1
  15. package/dist/DashboardGrid.d.ts +6 -2
  16. package/dist/DashboardGrid.d.ts.map +1 -1
  17. package/dist/DashboardGrid.js +43 -10
  18. package/dist/DashboardGrid.js.map +1 -1
  19. package/dist/DonutChart.d.ts.map +1 -1
  20. package/dist/DonutChart.js +20 -10
  21. package/dist/DonutChart.js.map +1 -1
  22. package/dist/DropdownMenuItem.d.ts +16 -0
  23. package/dist/DropdownMenuItem.d.ts.map +1 -0
  24. package/dist/DropdownMenuItem.js +11 -0
  25. package/dist/DropdownMenuItem.js.map +1 -0
  26. package/dist/FilePickerButton.d.ts.map +1 -1
  27. package/dist/FilePickerButton.js +70 -10
  28. package/dist/FilePickerButton.js.map +1 -1
  29. package/dist/GPTChat.d.ts.map +1 -1
  30. package/dist/GPTChat.js +103 -14
  31. package/dist/GPTChat.js.map +1 -1
  32. package/dist/LineChart.d.ts +1 -1
  33. package/dist/LineChart.d.ts.map +1 -1
  34. package/dist/LineChart.js +62 -21
  35. package/dist/LineChart.js.map +1 -1
  36. package/dist/Scorecard.d.ts +5 -0
  37. package/dist/Scorecard.d.ts.map +1 -0
  38. package/dist/Scorecard.js +11 -0
  39. package/dist/Scorecard.js.map +1 -0
  40. package/dist/SparklineChart.d.ts +5 -0
  41. package/dist/SparklineChart.d.ts.map +1 -0
  42. package/dist/SparklineChart.js +35 -0
  43. package/dist/SparklineChart.js.map +1 -0
  44. package/dist/TextField.d.ts.map +1 -1
  45. package/dist/TextField.js +12 -4
  46. package/dist/TextField.js.map +1 -1
  47. package/dist/ToastNotifications.d.ts.map +1 -1
  48. package/dist/ToastNotifications.js +29 -6
  49. package/dist/ToastNotifications.js.map +1 -1
  50. package/dist/WebDropdownMenu.d.ts +2 -1
  51. package/dist/WebDropdownMenu.d.ts.map +1 -1
  52. package/dist/WebDropdownMenu.js +2 -6
  53. package/dist/WebDropdownMenu.js.map +1 -1
  54. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  55. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  56. package/dist/charts/ChartFacadeContainer.js +10 -0
  57. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  58. package/dist/charts/ChartFrame.d.ts +4 -0
  59. package/dist/charts/ChartFrame.d.ts.map +1 -1
  60. package/dist/charts/ChartFrame.js +4 -2
  61. package/dist/charts/ChartFrame.js.map +1 -1
  62. package/dist/charts/layout.d.ts +9 -2
  63. package/dist/charts/layout.d.ts.map +1 -1
  64. package/dist/charts/layout.js +28 -6
  65. package/dist/charts/layout.js.map +1 -1
  66. package/dist/charts/scales.d.ts +3 -1
  67. package/dist/charts/scales.d.ts.map +1 -1
  68. package/dist/charts/scales.js +7 -7
  69. package/dist/charts/scales.js.map +1 -1
  70. package/dist/charts/series.d.ts +15 -0
  71. package/dist/charts/series.d.ts.map +1 -0
  72. package/dist/charts/series.js +19 -0
  73. package/dist/charts/series.js.map +1 -0
  74. package/dist/charts/types/chartTypes.d.ts +7 -0
  75. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  76. package/dist/dashboardGridLayout.d.ts +6 -0
  77. package/dist/dashboardGridLayout.d.ts.map +1 -1
  78. package/dist/dashboardGridLayout.js +19 -3
  79. package/dist/dashboardGridLayout.js.map +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  85. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  86. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  87. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  88. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  89. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  90. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  91. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  92. package/package.json +1 -1
  93. package/src/AIRequestExplorer.test.tsx +2 -2
  94. package/src/AreaChart.test.tsx +81 -0
  95. package/src/AreaChart.tsx +171 -62
  96. package/src/BarChart.test.tsx +119 -0
  97. package/src/BarChart.tsx +94 -20
  98. package/src/ChartCard.test.tsx +79 -0
  99. package/src/ChartCard.tsx +80 -0
  100. package/src/Common.ts +69 -2
  101. package/src/DashboardGrid.test.tsx +98 -1
  102. package/src/DashboardGrid.tsx +71 -20
  103. package/src/DonutChart.test.tsx +73 -0
  104. package/src/DonutChart.tsx +87 -14
  105. package/src/DropdownMenuItem.tsx +48 -0
  106. package/src/FilePickerButton.test.tsx +60 -6
  107. package/src/FilePickerButton.tsx +116 -28
  108. package/src/GPTChat.test.tsx +133 -6
  109. package/src/GPTChat.tsx +196 -38
  110. package/src/LineChart.test.tsx +104 -0
  111. package/src/LineChart.tsx +154 -58
  112. package/src/Scorecard.test.tsx +65 -0
  113. package/src/Scorecard.tsx +45 -0
  114. package/src/SparklineChart.test.tsx +69 -0
  115. package/src/SparklineChart.tsx +85 -0
  116. package/src/TextField.test.tsx +16 -0
  117. package/src/TextField.tsx +13 -3
  118. package/src/ToastNotifications.tsx +33 -6
  119. package/src/ToastNotifications.webModal.test.tsx +285 -0
  120. package/src/WebDropdownMenu.tsx +3 -7
  121. package/src/bunSetup.ts +1 -0
  122. package/src/charts/ChartFacadeContainer.tsx +35 -0
  123. package/src/charts/ChartFrame.tsx +39 -1
  124. package/src/charts/layout.test.ts +22 -1
  125. package/src/charts/layout.ts +37 -4
  126. package/src/charts/scales.test.ts +33 -0
  127. package/src/charts/scales.ts +10 -6
  128. package/src/charts/series.ts +43 -0
  129. package/src/charts/types/chartTypes.ts +8 -0
  130. package/src/dashboardGridLayout.test.ts +59 -1
  131. package/src/dashboardGridLayout.ts +30 -3
  132. package/src/index.tsx +6 -0
  133. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  134. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -4,14 +4,14 @@ import type {ChartPlot, ChartPoint, ChartScales} from "./types/chartTypes";
4
4
 
5
5
  const EMPTY_Y_DOMAIN: [number, number] = [0, 1];
6
6
 
7
- const getYDomain = (points: ChartPoint[]): [number, number] => {
7
+ const getYDomain = (points: ChartPoint[], includeZero: boolean): [number, number] => {
8
8
  if (points.length === 0) {
9
9
  return EMPTY_Y_DOMAIN;
10
10
  }
11
11
 
12
12
  const values = points.map((point) => point.value);
13
- const min = Math.min(0, ...values);
14
- const max = Math.max(0, ...values);
13
+ const min = includeZero ? Math.min(0, ...values) : Math.min(...values);
14
+ const max = includeZero ? Math.max(0, ...values) : Math.max(...values);
15
15
  if (min === max) {
16
16
  return [min, min + 1];
17
17
  }
@@ -24,24 +24,28 @@ export const getYTickValues = (points: ChartPoint[]): number[] => {
24
24
  return [];
25
25
  }
26
26
 
27
- const [min, max] = getYDomain(points);
27
+ const [min, max] = getYDomain(points, true);
28
28
  const mid = min + (max - min) / 2;
29
29
  return [min, mid, max];
30
30
  };
31
31
 
32
32
  export const createCartesianScales = ({
33
+ includeZero = true,
33
34
  plot,
34
35
  points,
36
+ xLabels,
35
37
  }: {
38
+ includeZero?: boolean;
36
39
  plot: ChartPlot;
37
40
  points: ChartPoint[];
41
+ xLabels?: string[];
38
42
  }): ChartScales => {
39
43
  const bottom = plot.top + plot.height;
40
- const labels = points.map((point) => point.label);
44
+ const labels = xLabels ?? points.map((point) => point.label);
41
45
  const xScale = scaleBand<string>()
42
46
  .domain(labels)
43
47
  .range([plot.left, plot.left + plot.width]);
44
- const yScale = scaleLinear().domain(getYDomain(points)).range([bottom, plot.top]);
48
+ const yScale = scaleLinear().domain(getYDomain(points, includeZero)).range([bottom, plot.top]);
45
49
  const bandwidth = labels.length === 0 ? 0 : xScale.bandwidth();
46
50
 
47
51
  const xStart = (label: string): number => {
@@ -0,0 +1,43 @@
1
+ import type {ChartPoint, ChartSeries} from "./types/chartTypes";
2
+
3
+ export const resolveChartSeries = ({
4
+ data,
5
+ legendLabel,
6
+ series,
7
+ }: {
8
+ data: ChartPoint[];
9
+ legendLabel?: string;
10
+ series?: ChartSeries[];
11
+ }): ChartSeries[] => {
12
+ if (series && series.length > 0) {
13
+ return series;
14
+ }
15
+
16
+ return [{data, id: "default", label: legendLabel ?? ""}];
17
+ };
18
+
19
+ export const getAllSeriesPoints = ({
20
+ comparisonData = [],
21
+ series,
22
+ }: {
23
+ comparisonData?: ChartPoint[];
24
+ series: ChartSeries[];
25
+ }): ChartPoint[] => {
26
+ return [...series.flatMap((entry) => entry.data), ...comparisonData];
27
+ };
28
+
29
+ export const getAxisPoints = ({
30
+ comparisonData = [],
31
+ series,
32
+ }: {
33
+ comparisonData?: ChartPoint[];
34
+ series: ChartSeries[];
35
+ }): ChartPoint[] => {
36
+ const pointsByLabel = new Map<string, ChartPoint>();
37
+ for (const point of getAllSeriesPoints({comparisonData, series})) {
38
+ if (!pointsByLabel.has(point.label)) {
39
+ pointsByLabel.set(point.label, point);
40
+ }
41
+ }
42
+ return [...pointsByLabel.values()];
43
+ };
@@ -4,6 +4,14 @@ export interface ChartPoint {
4
4
  value: number;
5
5
  }
6
6
 
7
+ export interface ChartSeries {
8
+ color?: string;
9
+ data: ChartPoint[];
10
+ id: string;
11
+ label: string;
12
+ stroke?: "solid" | "dotted";
13
+ }
14
+
7
15
  export interface ChartPlot {
8
16
  height: number;
9
17
  left: number;
@@ -1,7 +1,12 @@
1
1
  import {afterEach, describe, expect, it} from "bun:test";
2
+ import {assert} from "chai";
2
3
  import {Platform} from "react-native";
3
4
 
4
- import {getDashboardCellBoxStyle, getDashboardCellWidth} from "./dashboardGridLayout";
5
+ import {
6
+ getDashboardCellBoxStyle,
7
+ getDashboardCellWidth,
8
+ getDashboardSpanCellBoxStyle,
9
+ } from "./dashboardGridLayout";
5
10
 
6
11
  const originalOS = Platform.OS;
7
12
 
@@ -64,6 +69,59 @@ describe("getDashboardCellBoxStyle", () => {
64
69
  ).toBe("calc((100% - 32px) / 3)");
65
70
  });
66
71
 
72
+ it("adds the internal gap when a measured cell spans two columns", () => {
73
+ assert.deepInclude(
74
+ getDashboardSpanCellBoxStyle({
75
+ columnCount: 4,
76
+ gapPx: 16,
77
+ rowWidth: 332,
78
+ span: 2,
79
+ }),
80
+ {width: 156}
81
+ );
82
+ });
83
+
84
+ it("clamps measured spans to the available columns", () => {
85
+ const fullSpan = getDashboardSpanCellBoxStyle({
86
+ columnCount: 4,
87
+ gapPx: 16,
88
+ rowWidth: 332,
89
+ span: 8,
90
+ });
91
+ assert.equal(fullSpan.width, 328);
92
+
93
+ const minimumSpan = getDashboardSpanCellBoxStyle({
94
+ columnCount: 4,
95
+ gapPx: 16,
96
+ rowWidth: 332,
97
+ span: 0,
98
+ });
99
+ assert.equal(minimumSpan.width, 70);
100
+ });
101
+
102
+ it("uses responsive web calc widths before measurement", () => {
103
+ Platform.OS = "web";
104
+
105
+ assert.equal(
106
+ getDashboardSpanCellBoxStyle({
107
+ columnCount: 4,
108
+ gapPx: 16,
109
+ rowWidth: 0,
110
+ span: 2,
111
+ }).width,
112
+ "calc(((100% - 48px) / 4) * 2 + 16px)"
113
+ );
114
+ assert.equal(
115
+ getDashboardSpanCellBoxStyle({
116
+ columnCount: 4,
117
+ gapPx: 16,
118
+ rowWidth: 0,
119
+ span: 4,
120
+ }).width,
121
+ "100%"
122
+ );
123
+ });
124
+
67
125
  it("falls back to a full-width cell on native, which has no calc", () => {
68
126
  Platform.OS = "ios";
69
127
 
@@ -47,14 +47,41 @@ export const getDashboardCellBoxStyle = ({
47
47
  gapPx: number;
48
48
  rowWidth: number;
49
49
  }): DashboardCellStyle => {
50
+ return getDashboardSpanCellBoxStyle({columnCount, gapPx, rowWidth, span: 1});
51
+ };
52
+
53
+ export const getDashboardSpanCellBoxStyle = ({
54
+ columnCount,
55
+ gapPx,
56
+ rowWidth,
57
+ span,
58
+ }: {
59
+ columnCount: number;
60
+ gapPx: number;
61
+ rowWidth: number;
62
+ span: number;
63
+ }): DashboardCellStyle => {
64
+ const safeColumnCount = Math.max(columnCount, 1);
65
+ const safeSpan = Math.min(Math.max(Math.floor(span), 1), safeColumnCount);
50
66
  if (rowWidth > 0) {
51
- const width = getDashboardCellWidth({columnCount, gapPx, rowWidth});
67
+ const baseWidth = getDashboardCellWidth({
68
+ columnCount: safeColumnCount,
69
+ gapPx,
70
+ rowWidth,
71
+ });
72
+ const width = baseWidth * safeSpan + gapPx * (safeSpan - 1);
52
73
  return {flexGrow: 0, flexShrink: 0, maxWidth: width, width};
53
74
  }
54
- if (columnCount <= 1 || Platform.OS !== "web") {
75
+ if (safeSpan === safeColumnCount || Platform.OS !== "web") {
55
76
  return {flexGrow: 0, flexShrink: 0, maxWidth: "100%", width: "100%"};
56
77
  }
57
78
 
58
- const width = `calc((100% - ${gapPx * (columnCount - 1)}px) / ${columnCount})`;
79
+ const gapTotal = gapPx * (safeColumnCount - 1);
80
+ if (safeSpan === 1) {
81
+ const width = `calc((100% - ${gapTotal}px) / ${safeColumnCount})`;
82
+ return {flexGrow: 0, flexShrink: 0, maxWidth: width, width};
83
+ }
84
+ const internalGaps = gapPx * (safeSpan - 1);
85
+ const width = `calc(((100% - ${gapTotal}px) / ${safeColumnCount}) * ${safeSpan} + ${internalGaps}px)`;
59
86
  return {flexGrow: 0, flexShrink: 0, maxWidth: width, width};
60
87
  };
package/src/index.tsx CHANGED
@@ -22,6 +22,7 @@ export * from "./BooleanField";
22
22
  export * from "./Box";
23
23
  export * from "./Button";
24
24
  export * from "./Card";
25
+ export type * from "./ChartCard";
25
26
  export * from "./CheckBox";
26
27
  export * from "./Common";
27
28
  export type * from "./ConflictSheet";
@@ -73,6 +74,7 @@ export {
73
74
  AreaChart,
74
75
  AttachmentPreview,
75
76
  BarChart,
77
+ ChartCard,
76
78
  ConflictSheet,
77
79
  ConsentFormScreen,
78
80
  ConsentNavigator,
@@ -84,6 +86,8 @@ export {
84
86
  LineChart,
85
87
  MarkdownEditor,
86
88
  MarkdownEditorField,
89
+ Scorecard,
90
+ SparklineChart,
87
91
  UpgradeRequiredScreen,
88
92
  } from "./lazyBoundaries/heavyOptionalExports";
89
93
  export * from "./login/LoginScreen";
@@ -112,6 +116,7 @@ export * from "./PortalHost";
112
116
  export * from "./pdfHtmlTemplate";
113
117
  export * from "./Radio";
114
118
  export * from "./RadioField";
119
+ export type * from "./Scorecard";
115
120
  export * from "./ScrollView";
116
121
  export * from "./SectionDivider";
117
122
  export * from "./SegmentedControl";
@@ -124,6 +129,7 @@ export * from "./SignatureCaptureField";
124
129
  export * from "./SignatureField";
125
130
  export * from "./Slider";
126
131
  export * from "./SocialLoginButton";
132
+ export type * from "./SparklineChart";
127
133
  export * from "./Spinner";
128
134
  export * from "./SplitPage";
129
135
  export * from "./SyncStatusBanner";
@@ -3,6 +3,7 @@ import type {AiSuggestionBox as AiSuggestionBoxComponent} from "../AiSuggestionB
3
3
  import type {AreaChart as AreaChartComponent} from "../AreaChart";
4
4
  import type {AttachmentPreview as AttachmentPreviewComponent} from "../AttachmentPreview";
5
5
  import type {BarChart as BarChartComponent} from "../BarChart";
6
+ import type {ChartCard as ChartCardComponent} from "../ChartCard";
6
7
  import type {ConflictSheet as ConflictSheetComponent} from "../ConflictSheet";
7
8
  import type {ConsentFormScreen as ConsentFormScreenComponent} from "../ConsentFormScreen";
8
9
  import type {ConsentNavigator as ConsentNavigatorComponent} from "../ConsentNavigator";
@@ -15,6 +16,8 @@ import type {GPTMemoryModal as GPTMemoryModalComponent} from "../GPTMemoryModal"
15
16
  import type {LineChart as LineChartComponent} from "../LineChart";
16
17
  import type {MarkdownEditor as MarkdownEditorComponent} from "../MarkdownEditor";
17
18
  import type {MarkdownEditorField as MarkdownEditorFieldComponent} from "../MarkdownEditorField";
19
+ import type {Scorecard as ScorecardComponent} from "../Scorecard";
20
+ import type {SparklineChart as SparklineChartComponent} from "../SparklineChart";
18
21
  import type {UpgradeRequiredScreen as UpgradeRequiredScreenComponent} from "../UpgradeRequiredScreen";
19
22
  import {createLazyComponentExport, createLazyNamedExport} from "./createLazyComponentExport";
20
23
 
@@ -24,6 +27,7 @@ export const heavyOptionalModuleFactories = {
24
27
  AreaChart: () => import("../AreaChart"),
25
28
  AttachmentPreview: () => import("../AttachmentPreview"),
26
29
  BarChart: () => import("../BarChart"),
30
+ ChartCard: () => import("../ChartCard"),
27
31
  ConflictSheet: () => import("../ConflictSheet"),
28
32
  ConsentFormScreen: () => import("../ConsentFormScreen"),
29
33
  ConsentNavigator: () => import("../ConsentNavigator"),
@@ -35,6 +39,8 @@ export const heavyOptionalModuleFactories = {
35
39
  LineChart: () => import("../LineChart"),
36
40
  MarkdownEditor: () => import("../MarkdownEditor"),
37
41
  MarkdownEditorField: () => import("../MarkdownEditorField"),
42
+ Scorecard: () => import("../Scorecard"),
43
+ SparklineChart: () => import("../SparklineChart"),
38
44
  UpgradeRequiredScreen: () => import("../UpgradeRequiredScreen"),
39
45
  } as const;
40
46
 
@@ -74,6 +80,11 @@ export const BarChart = createLazyNamedExport(
74
80
  "BarChart"
75
81
  ) as unknown as typeof BarChartComponent;
76
82
 
83
+ export const ChartCard = createLazyNamedExport(
84
+ heavyOptionalModuleFactories.ChartCard,
85
+ "ChartCard"
86
+ ) as unknown as typeof ChartCardComponent;
87
+
77
88
  export const ConflictSheet = createLazyNamedExport(
78
89
  heavyOptionalModuleFactories.ConflictSheet,
79
90
  "ConflictSheet"
@@ -128,6 +139,16 @@ export const MarkdownEditorField = createLazyNamedExport(
128
139
  "MarkdownEditorField"
129
140
  ) as unknown as typeof MarkdownEditorFieldComponent;
130
141
 
142
+ export const Scorecard = createLazyNamedExport(
143
+ heavyOptionalModuleFactories.Scorecard,
144
+ "Scorecard"
145
+ ) as unknown as typeof ScorecardComponent;
146
+
147
+ export const SparklineChart = createLazyNamedExport(
148
+ heavyOptionalModuleFactories.SparklineChart,
149
+ "SparklineChart"
150
+ ) as unknown as typeof SparklineChartComponent;
151
+
131
152
  export const UpgradeRequiredScreen = createLazyNamedExport(
132
153
  heavyOptionalModuleFactories.UpgradeRequiredScreen,
133
154
  "UpgradeRequiredScreen"
@@ -0,0 +1,11 @@
1
+ /**
2
+ * DOM node web overlays attach to so they escape ancestor stacking contexts.
3
+ * Returns null when there is no document, or when `document.body` is not an element,
4
+ * so callers render inline instead of calling `createPortal`.
5
+ */
6
+ export const resolveDocumentBodyPortalTarget = (): HTMLElement | null => {
7
+ if (typeof document === "undefined" || typeof HTMLElement === "undefined") {
8
+ return null;
9
+ }
10
+ return document.body instanceof HTMLElement ? document.body : null;
11
+ };