@terreno/ui 57.18.0 → 57.19.2
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.
- package/CHANGELOG.md +1681 -0
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +2 -2
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +2 -2
- package/dist/BarChart.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +28 -6
- package/dist/Box.js.map +1 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/Card.js +3 -2
- package/dist/Card.js.map +1 -1
- package/dist/ChartCard.d.ts.map +1 -1
- package/dist/ChartCard.js +4 -2
- package/dist/ChartCard.js.map +1 -1
- package/dist/Common.d.ts +120 -7
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +2 -2
- package/dist/DonutChart.js.map +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +2 -2
- package/dist/LineChart.js.map +1 -1
- package/dist/Page.d.ts +1 -0
- package/dist/Page.d.ts.map +1 -1
- package/dist/Page.js +10 -1
- package/dist/Page.js.map +1 -1
- package/dist/Scorecard.d.ts.map +1 -1
- package/dist/Scorecard.js +5 -2
- package/dist/Scorecard.js.map +1 -1
- package/dist/Skeleton.d.ts +39 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +195 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +3 -2
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +1 -1
- package/dist/SplitPage.native.d.ts.map +1 -1
- package/dist/SplitPage.native.js +3 -2
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/SplitPageLoading.d.ts +14 -0
- package/dist/SplitPageLoading.d.ts.map +1 -0
- package/dist/SplitPageLoading.js +19 -0
- package/dist/SplitPageLoading.js.map +1 -0
- package/dist/Text.d.ts +3 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -0
- package/dist/Text.js.map +1 -1
- package/dist/charts/ChartFrame.d.ts +2 -2
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +9 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/withLoading.d.ts +20 -0
- package/dist/withLoading.d.ts.map +1 -0
- package/dist/withLoading.js +24 -0
- package/dist/withLoading.js.map +1 -0
- package/package.json +3 -2
- package/src/AreaChart.tsx +6 -0
- package/src/BarChart.tsx +6 -0
- package/src/Box.test.tsx +70 -0
- package/src/Box.tsx +33 -6
- package/src/Card.test.tsx +48 -0
- package/src/Card.tsx +11 -0
- package/src/ChartCard.test.tsx +30 -0
- package/src/ChartCard.tsx +18 -1
- package/src/Common.ts +129 -7
- package/src/DonutChart.tsx +6 -0
- package/src/LineChart.test.tsx +18 -0
- package/src/LineChart.tsx +6 -0
- package/src/Page.test.tsx +38 -0
- package/src/Page.tsx +38 -19
- package/src/Scorecard.test.tsx +11 -0
- package/src/Scorecard.tsx +21 -0
- package/src/Skeleton.test.tsx +262 -0
- package/src/Skeleton.tsx +430 -0
- package/src/SplitPage.native.tsx +13 -2
- package/src/SplitPage.tsx +18 -7
- package/src/SplitPageLoading.test.tsx +51 -0
- package/src/SplitPageLoading.tsx +53 -0
- package/src/Text.tsx +4 -1
- package/src/__snapshots__/Page.test.tsx.snap +28 -5
- package/src/__snapshots__/SplitPage.test.tsx.snap +16 -0
- package/src/charts/ChartFrame.tsx +19 -8
- package/src/index.tsx +2 -0
- package/src/withLoading.test.tsx +61 -0
- package/src/withLoading.tsx +50 -0
package/src/Common.ts
CHANGED
|
@@ -685,11 +685,122 @@ export interface AccessibilityProps {
|
|
|
685
685
|
|
|
686
686
|
/** Checked and disabled state a `Box` reports to screen readers. */
|
|
687
687
|
export interface BoxAccessibilityState {
|
|
688
|
+
/** Set automatically while `loading` is true; sent as `aria-busy` on web. */
|
|
689
|
+
busy?: boolean;
|
|
688
690
|
checked?: boolean;
|
|
689
691
|
disabled?: boolean;
|
|
690
692
|
}
|
|
691
693
|
|
|
692
|
-
|
|
694
|
+
/** How skeleton placeholders animate. `none` renders a static block. */
|
|
695
|
+
export type SkeletonAnimation = "pulse" | "shimmer" | "none";
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Shared loading contract. Box, Card, ChartCard, Scorecard, Page, SplitPage, and the charts
|
|
699
|
+
* accept it, and custom components can extend it and hand it to a `Box` or `withLoading`.
|
|
700
|
+
*/
|
|
701
|
+
export interface LoadingProps {
|
|
702
|
+
/** When true, renders `loadingComponent` in place of the children. */
|
|
703
|
+
loading?: boolean;
|
|
704
|
+
/**
|
|
705
|
+
* Placeholder rendered while `loading` is true, usually built from `Skeleton`, `SkeletonText`,
|
|
706
|
+
* `SkeletonCircle`, `SkeletonCard`, or `SkeletonList`. Each component documents its default.
|
|
707
|
+
*/
|
|
708
|
+
loadingComponent?: ReactNode;
|
|
709
|
+
/**
|
|
710
|
+
* Animation for skeletons inside `loadingComponent` that do not set their own `animation`.
|
|
711
|
+
* Falls back to `none` when the OS reduce-motion setting is on.
|
|
712
|
+
* @default "pulse"
|
|
713
|
+
*/
|
|
714
|
+
loadingAnimation?: SkeletonAnimation;
|
|
715
|
+
/**
|
|
716
|
+
* Screen reader label announced while loading.
|
|
717
|
+
* @default "Loading"
|
|
718
|
+
*/
|
|
719
|
+
loadingLabel?: string;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
export interface SkeletonProps extends WithTestID {
|
|
723
|
+
/**
|
|
724
|
+
* Overrides the nearest `SkeletonGroup` (or loading container) animation.
|
|
725
|
+
* @default "pulse"
|
|
726
|
+
*/
|
|
727
|
+
animation?: SkeletonAnimation;
|
|
728
|
+
/**
|
|
729
|
+
* Placeholder fill.
|
|
730
|
+
* @default "neutralExtraLight"
|
|
731
|
+
*/
|
|
732
|
+
color?: SurfaceColor;
|
|
733
|
+
/** @default 16 */
|
|
734
|
+
height?: NumberOrPercentage;
|
|
735
|
+
/** @default "sm" */
|
|
736
|
+
rounding?: Rounding | "circle";
|
|
737
|
+
/** @default "100%" */
|
|
738
|
+
width?: NumberOrPercentage;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export interface SkeletonTextProps extends WithTestID {
|
|
742
|
+
animation?: SkeletonAnimation;
|
|
743
|
+
/**
|
|
744
|
+
* Width of the final line, so a paragraph does not end flush.
|
|
745
|
+
* @default "60%"
|
|
746
|
+
*/
|
|
747
|
+
lastLineWidth?: NumberOrPercentage;
|
|
748
|
+
/** @default 3 */
|
|
749
|
+
lines?: number;
|
|
750
|
+
/**
|
|
751
|
+
* Matches the line height of `Text` at this size.
|
|
752
|
+
* @default "md"
|
|
753
|
+
*/
|
|
754
|
+
size?: TextSize;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
export interface SkeletonCircleProps extends WithTestID {
|
|
758
|
+
animation?: SkeletonAnimation;
|
|
759
|
+
/**
|
|
760
|
+
* Diameter in pixels.
|
|
761
|
+
* @default 40
|
|
762
|
+
*/
|
|
763
|
+
size?: number;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export interface SkeletonCardProps extends WithTestID {
|
|
767
|
+
animation?: SkeletonAnimation;
|
|
768
|
+
/** @default 2 */
|
|
769
|
+
lines?: number;
|
|
770
|
+
/**
|
|
771
|
+
* Height of the media block when `showMedia` is true.
|
|
772
|
+
* @default 160
|
|
773
|
+
*/
|
|
774
|
+
mediaHeight?: number;
|
|
775
|
+
/** @default true */
|
|
776
|
+
showAvatar?: boolean;
|
|
777
|
+
/** Adds a full-width media block above the text, like a display `Card` with an image. */
|
|
778
|
+
showMedia?: boolean;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export interface SkeletonListProps extends WithTestID {
|
|
782
|
+
animation?: SkeletonAnimation;
|
|
783
|
+
/**
|
|
784
|
+
* Text lines per row.
|
|
785
|
+
* @default 2
|
|
786
|
+
*/
|
|
787
|
+
lines?: number;
|
|
788
|
+
/** @default 3 */
|
|
789
|
+
rows?: number;
|
|
790
|
+
/** @default true */
|
|
791
|
+
showAvatar?: boolean;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
export interface SkeletonGroupProps {
|
|
795
|
+
/**
|
|
796
|
+
* Animation inherited by every skeleton inside the group. Skeletons in one group pulse in sync.
|
|
797
|
+
* @default "pulse"
|
|
798
|
+
*/
|
|
799
|
+
animation?: SkeletonAnimation;
|
|
800
|
+
children?: ReactNode;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
export interface BoxPropsBase extends WithTestID, LoadingProps {
|
|
693
804
|
/**
|
|
694
805
|
* Checked and disabled state for screen readers, sent as `accessibilityState` and as
|
|
695
806
|
* `aria-checked` / `aria-disabled`. On a clickable Box, `disabled: true` also stops presses.
|
|
@@ -1234,7 +1345,8 @@ export interface SplitPageListItem {
|
|
|
1234
1345
|
id: string;
|
|
1235
1346
|
}
|
|
1236
1347
|
|
|
1237
|
-
export interface SplitPageProps<TItem extends SplitPageListItem = SplitPageListItem>
|
|
1348
|
+
export interface SplitPageProps<TItem extends SplitPageListItem = SplitPageListItem>
|
|
1349
|
+
extends LoadingProps {
|
|
1238
1350
|
/**
|
|
1239
1351
|
* can accept either one React Child or any array of ReactChild. If this is not provided,
|
|
1240
1352
|
* renderContent must return one or many ReactChild.
|
|
@@ -2577,7 +2689,7 @@ export interface NumberPickerActionSheetProps {
|
|
|
2577
2689
|
actionSheetRef: React.RefObject<any>;
|
|
2578
2690
|
}
|
|
2579
2691
|
|
|
2580
|
-
export interface PageProps extends WithTestID {
|
|
2692
|
+
export interface PageProps extends WithTestID, LoadingProps {
|
|
2581
2693
|
// noExplicitAny: React Navigation type varies by navigation stack configuration
|
|
2582
2694
|
// biome-ignore lint/suspicious/noExplicitAny: React Navigation type varies by navigation stack configuration
|
|
2583
2695
|
navigation?: any;
|
|
@@ -2834,7 +2946,7 @@ export interface PaginationProps extends WithTestID {
|
|
|
2834
2946
|
totalPages: number;
|
|
2835
2947
|
}
|
|
2836
2948
|
|
|
2837
|
-
export interface LineChartProps extends WithTestID {
|
|
2949
|
+
export interface LineChartProps extends WithTestID, LoadingProps {
|
|
2838
2950
|
/** Summary announced for the whole chart. */
|
|
2839
2951
|
accessibilityLabel?: string;
|
|
2840
2952
|
/** Optional previous-period values drawn as a dotted overlay. */
|
|
@@ -2849,7 +2961,9 @@ export interface LineChartProps extends WithTestID {
|
|
|
2849
2961
|
height?: number;
|
|
2850
2962
|
/** Series name shown under the plot. */
|
|
2851
2963
|
legendLabel?: string;
|
|
2852
|
-
/**
|
|
2964
|
+
/**
|
|
2965
|
+
* When true, shows `loadingComponent` (default: a spinner) instead of the plot.
|
|
2966
|
+
*/
|
|
2853
2967
|
loading?: boolean;
|
|
2854
2968
|
/** Makes `periodLabel` pressable when provided. */
|
|
2855
2969
|
onPeriodPress?: () => void;
|
|
@@ -2874,7 +2988,11 @@ export interface SparklineChartProps extends WithTestID {
|
|
|
2874
2988
|
height?: number;
|
|
2875
2989
|
}
|
|
2876
2990
|
|
|
2877
|
-
|
|
2991
|
+
/**
|
|
2992
|
+
* While `loading`, the title row stays visible and the body shows `loadingComponent`
|
|
2993
|
+
* (default: a 160px `Skeleton`).
|
|
2994
|
+
*/
|
|
2995
|
+
export interface ChartCardProps extends WithTestID, LoadingProps {
|
|
2878
2996
|
children: React.ReactNode;
|
|
2879
2997
|
/** Optional context shown below the title row. */
|
|
2880
2998
|
filterSummary?: string;
|
|
@@ -2886,7 +3004,11 @@ export interface ChartCardProps extends WithTestID {
|
|
|
2886
3004
|
title: string;
|
|
2887
3005
|
}
|
|
2888
3006
|
|
|
2889
|
-
|
|
3007
|
+
/**
|
|
3008
|
+
* While `loading`, the title row stays visible and the value shows `loadingComponent`
|
|
3009
|
+
* (default: a heading-sized `Skeleton`).
|
|
3010
|
+
*/
|
|
3011
|
+
export interface ScorecardProps extends WithTestID, LoadingProps {
|
|
2890
3012
|
/** Optional previous-period sparkline values. */
|
|
2891
3013
|
comparisonData?: Array<{label: string; value: number}>;
|
|
2892
3014
|
/** Formats numeric values. String values render unchanged. */
|
package/src/DonutChart.tsx
CHANGED
|
@@ -55,6 +55,9 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
55
55
|
formatValue = String,
|
|
56
56
|
height = DEFAULT_SIZE,
|
|
57
57
|
loading = false,
|
|
58
|
+
loadingAnimation,
|
|
59
|
+
loadingComponent,
|
|
60
|
+
loadingLabel,
|
|
58
61
|
onPeriodPress,
|
|
59
62
|
periodLabel,
|
|
60
63
|
testID,
|
|
@@ -94,6 +97,9 @@ export const DonutChart: FC<DonutChartProps> = ({
|
|
|
94
97
|
emptyText={emptyText}
|
|
95
98
|
isEmpty={data.length === 0}
|
|
96
99
|
loading={loading}
|
|
100
|
+
loadingAnimation={loadingAnimation}
|
|
101
|
+
loadingComponent={loadingComponent}
|
|
102
|
+
loadingLabel={loadingLabel}
|
|
97
103
|
testID={testID}
|
|
98
104
|
tooltipText={tooltipText}
|
|
99
105
|
>
|
package/src/LineChart.test.tsx
CHANGED
|
@@ -3,8 +3,12 @@ import {act, fireEvent} from "@testing-library/react-native";
|
|
|
3
3
|
import {assert} from "chai";
|
|
4
4
|
|
|
5
5
|
import {LineChart} from "./LineChart";
|
|
6
|
+
import {Skeleton} from "./Skeleton";
|
|
6
7
|
import {renderWithTheme} from "./test-utils";
|
|
7
8
|
|
|
9
|
+
// Skeletons are hidden from assistive tech, so queries opt in to hidden elements.
|
|
10
|
+
const HIDDEN = {includeHiddenElements: true};
|
|
11
|
+
|
|
8
12
|
const POINTS = [
|
|
9
13
|
{label: "A", value: 0},
|
|
10
14
|
{label: "B", value: 50},
|
|
@@ -262,4 +266,18 @@ describe("LineChart", () => {
|
|
|
262
266
|
// from other files. A label is inert when it has no press handler.
|
|
263
267
|
expect(getByText("https://evil.example").props.onPress).toBeUndefined();
|
|
264
268
|
});
|
|
269
|
+
|
|
270
|
+
it("renders loadingComponent instead of the spinner while loading", () => {
|
|
271
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
272
|
+
<LineChart
|
|
273
|
+
data={POINTS}
|
|
274
|
+
loading
|
|
275
|
+
loadingComponent={<Skeleton height={120} testID="chart-skeleton" />}
|
|
276
|
+
testID="chart"
|
|
277
|
+
/>
|
|
278
|
+
);
|
|
279
|
+
assert.exists(getByTestId("chart-skeleton", HIDDEN));
|
|
280
|
+
assert.notExists(queryByTestId("chart.spinner"));
|
|
281
|
+
assert.isTrue(getByTestId("chart").props["aria-busy"]);
|
|
282
|
+
});
|
|
265
283
|
});
|
package/src/LineChart.tsx
CHANGED
|
@@ -56,6 +56,9 @@ export const LineChart: FC<LineChartProps> = ({
|
|
|
56
56
|
height = DEFAULT_HEIGHT,
|
|
57
57
|
legendLabel,
|
|
58
58
|
loading = false,
|
|
59
|
+
loadingAnimation,
|
|
60
|
+
loadingComponent,
|
|
61
|
+
loadingLabel,
|
|
59
62
|
onPeriodPress,
|
|
60
63
|
periodLabel,
|
|
61
64
|
series,
|
|
@@ -130,6 +133,9 @@ export const LineChart: FC<LineChartProps> = ({
|
|
|
130
133
|
legendItems={legendItems}
|
|
131
134
|
legendLabel={legendLabel}
|
|
132
135
|
loading={loading}
|
|
136
|
+
loadingAnimation={loadingAnimation}
|
|
137
|
+
loadingComponent={loadingComponent}
|
|
138
|
+
loadingLabel={loadingLabel}
|
|
133
139
|
testID={testID}
|
|
134
140
|
tooltipText={tooltipText}
|
|
135
141
|
>
|
package/src/Page.test.tsx
CHANGED
|
@@ -59,9 +59,13 @@ mock.module("expo-router", () => ({
|
|
|
59
59
|
}));
|
|
60
60
|
|
|
61
61
|
import {Page} from "./Page";
|
|
62
|
+
import {SkeletonList} from "./Skeleton";
|
|
62
63
|
import {Text} from "./Text";
|
|
63
64
|
import {renderWithTheme} from "./test-utils";
|
|
64
65
|
|
|
66
|
+
// Skeletons are hidden from assistive tech, so queries opt in to hidden elements.
|
|
67
|
+
const HIDDEN = {includeHiddenElements: true};
|
|
68
|
+
|
|
65
69
|
// Restore the global mocks set up by bunSetup.ts after this file finishes so
|
|
66
70
|
// that other test files (e.g. IconButton.test.tsx, ConsentFormScreen.test.tsx)
|
|
67
71
|
// are not affected by the overrides above.
|
|
@@ -327,4 +331,38 @@ describe("Page", () => {
|
|
|
327
331
|
// No crash; the optional-chained call handles the missing prop.
|
|
328
332
|
expect(getByText("Go")).toBeTruthy();
|
|
329
333
|
});
|
|
334
|
+
|
|
335
|
+
it("renders loadingComponent instead of the spinner when provided", () => {
|
|
336
|
+
const {getByTestId, queryByText} = renderWithTheme(
|
|
337
|
+
<Page
|
|
338
|
+
loading
|
|
339
|
+
loadingComponent={<SkeletonList testID="page-skeleton" />}
|
|
340
|
+
navigation={mockNavigation}
|
|
341
|
+
testID="page"
|
|
342
|
+
>
|
|
343
|
+
<Text>Content</Text>
|
|
344
|
+
</Page>
|
|
345
|
+
);
|
|
346
|
+
expect(getByTestId("page-skeleton", HIDDEN)).toBeTruthy();
|
|
347
|
+
expect(getByTestId("page-loading").props["aria-busy"]).toBe(true);
|
|
348
|
+
expect(queryByText("Content")).toBeNull();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("announces loadingLabel and is busy while showing the default spinner", () => {
|
|
352
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
353
|
+
<Page
|
|
354
|
+
loading
|
|
355
|
+
loadingLabel="Loading patients"
|
|
356
|
+
loadingText="Fetching..."
|
|
357
|
+
navigation={mockNavigation}
|
|
358
|
+
testID="page"
|
|
359
|
+
>
|
|
360
|
+
<Text>Content</Text>
|
|
361
|
+
</Page>
|
|
362
|
+
);
|
|
363
|
+
const region = getByTestId("page-loading");
|
|
364
|
+
expect(region.props["aria-busy"]).toBe(true);
|
|
365
|
+
expect(region.props.accessibilityLabel).toBe("Loading patients");
|
|
366
|
+
expect(getByText("Fetching...", HIDDEN)).toBeTruthy();
|
|
367
|
+
});
|
|
330
368
|
});
|
package/src/Page.tsx
CHANGED
|
@@ -79,6 +79,43 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
renderContent() {
|
|
83
|
+
// Without a loadingComponent, Page keeps its centered spinner and optional loadingText.
|
|
84
|
+
const spinner = (
|
|
85
|
+
<Box
|
|
86
|
+
alignItems="center"
|
|
87
|
+
direction="column"
|
|
88
|
+
display="flex"
|
|
89
|
+
flex="grow"
|
|
90
|
+
justifyContent="center"
|
|
91
|
+
marginTop={8}
|
|
92
|
+
>
|
|
93
|
+
<Spinner />
|
|
94
|
+
{Boolean(this.props.loadingText) && (
|
|
95
|
+
<Box marginTop={2}>
|
|
96
|
+
<Text color="secondaryDark">{this.props.loadingText}</Text>
|
|
97
|
+
</Box>
|
|
98
|
+
)}
|
|
99
|
+
</Box>
|
|
100
|
+
);
|
|
101
|
+
if (!this.props.loading) {
|
|
102
|
+
return this.props.children;
|
|
103
|
+
}
|
|
104
|
+
// Both paths render through a loading Box so the page announces loadingLabel and is busy.
|
|
105
|
+
return (
|
|
106
|
+
<Box
|
|
107
|
+
direction="column"
|
|
108
|
+
flex="grow"
|
|
109
|
+
loading
|
|
110
|
+
loadingAnimation={this.props.loadingAnimation}
|
|
111
|
+
loadingComponent={this.props.loadingComponent ?? spinner}
|
|
112
|
+
loadingLabel={this.props.loadingLabel}
|
|
113
|
+
testID={this.props.testID ? `${this.props.testID}-loading` : undefined}
|
|
114
|
+
width="100%"
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
82
119
|
renderBody() {
|
|
83
120
|
return (
|
|
84
121
|
<>
|
|
@@ -98,25 +135,7 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
98
135
|
width="100%"
|
|
99
136
|
>
|
|
100
137
|
{this.renderHeader()}
|
|
101
|
-
{this.
|
|
102
|
-
<Box
|
|
103
|
-
alignItems="center"
|
|
104
|
-
direction="column"
|
|
105
|
-
display="flex"
|
|
106
|
-
flex="grow"
|
|
107
|
-
justifyContent="center"
|
|
108
|
-
marginTop={8}
|
|
109
|
-
>
|
|
110
|
-
<Spinner />
|
|
111
|
-
{Boolean(this.props.loadingText) && (
|
|
112
|
-
<Box marginTop={2}>
|
|
113
|
-
<Text color="secondaryDark">{this.props.loadingText}</Text>
|
|
114
|
-
</Box>
|
|
115
|
-
)}
|
|
116
|
-
</Box>
|
|
117
|
-
) : (
|
|
118
|
-
this.props.children
|
|
119
|
-
)}
|
|
138
|
+
{this.renderContent()}
|
|
120
139
|
</Box>
|
|
121
140
|
{Boolean(this.props.footer) && (
|
|
122
141
|
<Box
|
package/src/Scorecard.test.tsx
CHANGED
|
@@ -62,4 +62,15 @@ describe("Scorecard", () => {
|
|
|
62
62
|
it("is available from the package root lazy boundary", () => {
|
|
63
63
|
assert.isFunction(RootScorecard);
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
it("keeps the title and hides the value while loading", () => {
|
|
67
|
+
const {getByText, queryByTestId} = renderWithTheme(
|
|
68
|
+
<Scorecard loading sparklineData={CURRENT} testID="score" title="Visits" value={42} />
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
assert.exists(getByText("Visits"));
|
|
72
|
+
assert.notExists(queryByTestId("score.value"));
|
|
73
|
+
assert.notExists(queryByTestId("score.sparkline"));
|
|
74
|
+
assert.exists(queryByTestId("score.loading"));
|
|
75
|
+
});
|
|
65
76
|
});
|
package/src/Scorecard.tsx
CHANGED
|
@@ -4,12 +4,20 @@ import {Box} from "./Box";
|
|
|
4
4
|
import {ChartCard} from "./ChartCard";
|
|
5
5
|
import type {ScorecardProps} from "./Common";
|
|
6
6
|
import {Heading} from "./Heading";
|
|
7
|
+
import {Skeleton} from "./Skeleton";
|
|
7
8
|
import {SparklineChart} from "./SparklineChart";
|
|
8
9
|
import {resolveTestID} from "./testing/resolveTestId";
|
|
9
10
|
|
|
11
|
+
const SCORECARD_VALUE_SKELETON_HEIGHT = 32;
|
|
12
|
+
const SCORECARD_SPARKLINE_SKELETON_HEIGHT = 48;
|
|
13
|
+
|
|
10
14
|
export const Scorecard: FC<ScorecardProps> = ({
|
|
11
15
|
comparisonData,
|
|
12
16
|
formatValue = String,
|
|
17
|
+
loading,
|
|
18
|
+
loadingAnimation,
|
|
19
|
+
loadingComponent,
|
|
20
|
+
loadingLabel,
|
|
13
21
|
onPeriodPress,
|
|
14
22
|
periodLabel,
|
|
15
23
|
sparklineData,
|
|
@@ -21,6 +29,19 @@ export const Scorecard: FC<ScorecardProps> = ({
|
|
|
21
29
|
|
|
22
30
|
return (
|
|
23
31
|
<ChartCard
|
|
32
|
+
loading={loading}
|
|
33
|
+
loadingAnimation={loadingAnimation}
|
|
34
|
+
loadingComponent={
|
|
35
|
+
loadingComponent ?? (
|
|
36
|
+
<Box gap={2} width="100%">
|
|
37
|
+
<Skeleton height={SCORECARD_VALUE_SKELETON_HEIGHT} width="50%" />
|
|
38
|
+
{sparklineData !== undefined && (
|
|
39
|
+
<Skeleton height={SCORECARD_SPARKLINE_SKELETON_HEIGHT} />
|
|
40
|
+
)}
|
|
41
|
+
</Box>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
loadingLabel={loadingLabel}
|
|
24
45
|
onPeriodPress={onPeriodPress}
|
|
25
46
|
periodLabel={periodLabel}
|
|
26
47
|
testID={testID}
|