@terreno/ui 57.18.0 → 57.20.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.
- package/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +2074 -0
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.js.map +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +2 -2
- package/dist/AreaChart.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +3 -1
- package/dist/Avatar.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 +66 -8
- package/dist/Box.js.map +1 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/Card.js +5 -4
- 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 +240 -14
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js +13 -4
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +5 -3
- package/dist/DateTimeField.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/Field.d.ts.map +1 -1
- package/dist/Field.js +2 -0
- package/dist/Field.js.map +1 -1
- package/dist/FormContainer.d.ts +68 -0
- package/dist/FormContainer.d.ts.map +1 -0
- package/dist/FormContainer.js +79 -0
- package/dist/FormContainer.js.map +1 -0
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +2 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +5 -2
- package/dist/Heading.js.map +1 -1
- package/dist/Icon.d.ts +4 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +43 -2
- package/dist/Icon.js.map +1 -1
- package/dist/LabeledCheckBox.d.ts +22 -0
- package/dist/LabeledCheckBox.d.ts.map +1 -0
- package/dist/LabeledCheckBox.js +30 -0
- package/dist/LabeledCheckBox.js.map +1 -0
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +2 -2
- package/dist/LineChart.js.map +1 -1
- package/dist/ListDetailLayout.d.ts +36 -0
- package/dist/ListDetailLayout.d.ts.map +1 -0
- package/dist/ListDetailLayout.js +153 -0
- package/dist/ListDetailLayout.js.map +1 -0
- package/dist/MarkdownEditor.d.ts.map +1 -1
- package/dist/MarkdownEditor.js +2 -1
- package/dist/MarkdownEditor.js.map +1 -1
- package/dist/MediaQuery.d.ts +1 -1
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +1 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OtpField.d.ts +60 -0
- package/dist/OtpField.d.ts.map +1 -0
- package/dist/OtpField.js +154 -0
- package/dist/OtpField.js.map +1 -0
- 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/ProvisionalConsentSigner.d.ts +21 -0
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
- package/dist/ProvisionalConsentSigner.js +199 -0
- package/dist/ProvisionalConsentSigner.js.map +1 -0
- package/dist/ResponsiveBreakpoint.d.ts +5 -0
- package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
- package/dist/ResponsiveBreakpoint.js +7 -0
- package/dist/ResponsiveBreakpoint.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/SocialLoginButton.d.ts +10 -0
- package/dist/SocialLoginButton.d.ts.map +1 -1
- package/dist/SocialLoginButton.js +26 -8
- package/dist/SocialLoginButton.js.map +1 -1
- package/dist/SplitPage.d.ts +12 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +14 -7
- 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 +6 -3
- 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/SyncStatusBanner.d.ts +7 -1
- package/dist/SyncStatusBanner.d.ts.map +1 -1
- package/dist/SyncStatusBanner.js +20 -4
- package/dist/SyncStatusBanner.js.map +1 -1
- 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/TextField.d.ts.map +1 -1
- package/dist/TextField.js +44 -10
- package/dist/TextField.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/fieldElements/FieldError.d.ts.map +1 -1
- package/dist/fieldElements/FieldError.js +1 -1
- package/dist/fieldElements/FieldError.js.map +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/login/LastUsedBadge.d.ts +14 -0
- package/dist/login/LastUsedBadge.d.ts.map +1 -0
- package/dist/login/LastUsedBadge.js +23 -0
- package/dist/login/LastUsedBadge.js.map +1 -0
- package/dist/login/LoginAccountCard.d.ts +38 -0
- package/dist/login/LoginAccountCard.d.ts.map +1 -0
- package/dist/login/LoginAccountCard.js +72 -0
- package/dist/login/LoginAccountCard.js.map +1 -0
- package/dist/login/LoginAccountList.d.ts +33 -0
- package/dist/login/LoginAccountList.d.ts.map +1 -0
- package/dist/login/LoginAccountList.js +30 -0
- package/dist/login/LoginAccountList.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +4 -4
- package/dist/login/LoginScreen.d.ts.map +1 -1
- package/dist/login/LoginScreen.js +294 -13
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/OutlinePill.d.ts +28 -0
- package/dist/login/OutlinePill.d.ts.map +1 -0
- package/dist/login/OutlinePill.js +48 -0
- package/dist/login/OutlinePill.js.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.js +139 -0
- package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
- package/dist/login/loginMethods.d.ts +27 -0
- package/dist/login/loginMethods.d.ts.map +1 -0
- package/dist/login/loginMethods.js +37 -0
- package/dist/login/loginMethods.js.map +1 -0
- package/dist/login/loginTypes.d.ts +202 -5
- package/dist/login/loginTypes.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +17 -0
- package/dist/pdfHtmlTemplate.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.js +78 -0
- package/dist/pdfHtmlTemplate.js.map +1 -1
- package/dist/security/AccountSecurityScreen.d.ts +10 -0
- package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
- package/dist/security/AccountSecurityScreen.js +50 -0
- package/dist/security/AccountSecurityScreen.js.map +1 -0
- package/dist/security/LinkedAccountsCard.d.ts +32 -0
- package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
- package/dist/security/LinkedAccountsCard.js +145 -0
- package/dist/security/LinkedAccountsCard.js.map +1 -0
- package/dist/security/PasskeysCard.d.ts +39 -0
- package/dist/security/PasskeysCard.d.ts.map +1 -0
- package/dist/security/PasskeysCard.js +168 -0
- package/dist/security/PasskeysCard.js.map +1 -0
- package/dist/security/PasswordCard.d.ts +32 -0
- package/dist/security/PasswordCard.d.ts.map +1 -0
- package/dist/security/PasswordCard.js +198 -0
- package/dist/security/PasswordCard.js.map +1 -0
- package/dist/security/SessionsCard.d.ts +39 -0
- package/dist/security/SessionsCard.d.ts.map +1 -0
- package/dist/security/SessionsCard.js +168 -0
- package/dist/security/SessionsCard.js.map +1 -0
- package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
- package/dist/security/TwoFactorSettingsCard.js +458 -0
- package/dist/security/TwoFactorSettingsCard.js.map +1 -0
- package/dist/security/securityMethods.d.ts +40 -0
- package/dist/security/securityMethods.d.ts.map +1 -0
- package/dist/security/securityMethods.js +66 -0
- package/dist/security/securityMethods.js.map +1 -0
- package/dist/security/securityTypes.d.ts +467 -0
- package/dist/security/securityTypes.d.ts.map +1 -0
- package/dist/security/securityTypes.js +2 -0
- package/dist/security/securityTypes.js.map +1 -0
- package/dist/security/userAgent.d.ts +26 -0
- package/dist/security/userAgent.d.ts.map +1 -0
- package/dist/security/userAgent.js +80 -0
- package/dist/security/userAgent.js.map +1 -0
- package/dist/signUp/OAuthButtons.d.ts +28 -5
- package/dist/signUp/OAuthButtons.d.ts.map +1 -1
- package/dist/signUp/OAuthButtons.js +44 -5
- package/dist/signUp/OAuthButtons.js.map +1 -1
- package/dist/signUp/SignUpScreen.d.ts.map +1 -1
- package/dist/signUp/SignUpScreen.js +50 -5
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/signUp/signUpTypes.d.ts +21 -1
- package/dist/signUp/signUpTypes.d.ts.map +1 -1
- package/dist/useConsentForms.d.ts +9 -0
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +18 -0
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +124 -0
- package/dist/useProvisionalConsent.d.ts.map +1 -0
- package/dist/useProvisionalConsent.js +79 -0
- package/dist/useProvisionalConsent.js.map +1 -0
- 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 +4 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/AreaChart.test.tsx +15 -0
- package/src/AreaChart.tsx +6 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/BarChart.test.tsx +15 -0
- package/src/BarChart.tsx +6 -0
- package/src/Box.test.tsx +131 -1
- package/src/Box.tsx +77 -8
- package/src/Card.test.tsx +48 -0
- package/src/Card.tsx +13 -2
- package/src/ChartCard.test.tsx +30 -0
- package/src/ChartCard.tsx +18 -1
- package/src/Common.ts +263 -14
- package/src/ConsentFormScreen.test.tsx +84 -0
- package/src/ConsentFormScreen.tsx +28 -4
- package/src/DateTimeField.tsx +5 -3
- package/src/DonutChart.test.tsx +15 -0
- package/src/DonutChart.tsx +6 -0
- package/src/Field.tsx +2 -0
- package/src/FilePickerButton.test.tsx +35 -0
- package/src/FormContainer.test.tsx +242 -0
- package/src/FormContainer.tsx +177 -0
- package/src/GPTChat.test.tsx +16 -0
- package/src/GPTChat.tsx +8 -2
- package/src/Heading.test.tsx +14 -0
- package/src/Heading.tsx +6 -1
- package/src/Icon.test.tsx +52 -1
- package/src/Icon.tsx +92 -3
- package/src/IconButton.test.tsx +85 -0
- package/src/LabeledCheckBox.test.tsx +45 -0
- package/src/LabeledCheckBox.tsx +89 -0
- package/src/LineChart.test.tsx +18 -0
- package/src/LineChart.tsx +6 -0
- package/src/ListDetailLayout.tsx +247 -0
- package/src/MarkdownEditor.tsx +2 -1
- package/src/MediaQuery.ts +1 -0
- package/src/OtpField.test.tsx +280 -0
- package/src/OtpField.tsx +307 -0
- package/src/Page.test.tsx +38 -0
- package/src/Page.tsx +38 -19
- package/src/ProvisionalConsentSigner.test.tsx +625 -0
- package/src/ProvisionalConsentSigner.tsx +423 -0
- package/src/ResponsiveBreakpoint.test.tsx +7 -0
- package/src/ResponsiveBreakpoint.tsx +14 -0
- package/src/RootImportRegression.test.tsx +3 -0
- 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/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +16 -3
- package/src/SplitPage.tsx +29 -12
- package/src/SplitPageLoading.test.tsx +51 -0
- package/src/SplitPageLoading.tsx +53 -0
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- package/src/Text.tsx +4 -1
- package/src/TextField.test.tsx +150 -0
- package/src/TextField.tsx +66 -8
- package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
- package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
- package/src/__snapshots__/Field.test.tsx.snap +37 -0
- package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
- package/src/__snapshots__/Page.test.tsx.snap +28 -5
- package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
- package/src/__snapshots__/Slider.test.tsx.snap +1 -0
- package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
- package/src/__snapshots__/SplitPage.test.tsx.snap +16 -0
- package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
- package/src/__snapshots__/TextField.test.tsx.snap +19 -2
- package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
- package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
- package/src/bunSetup.ts +13 -1
- package/src/charts/ChartFrame.tsx +19 -8
- package/src/fieldElements/FieldError.tsx +1 -0
- package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
- package/src/index.tsx +44 -1
- package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
- package/src/login/LastUsedBadge.tsx +40 -0
- package/src/login/LoginAccountCard.tsx +205 -0
- package/src/login/LoginAccountList.tsx +115 -0
- package/src/login/LoginScreen.test.tsx +837 -1
- package/src/login/LoginScreen.tsx +674 -91
- package/src/login/OutlinePill.tsx +110 -0
- package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
- package/src/login/TwoFactorChallengeScreen.tsx +307 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
- package/src/login/loginMethods.test.ts +53 -0
- package/src/login/loginMethods.ts +60 -0
- package/src/login/loginTypes.ts +208 -5
- package/src/pdfHtmlTemplate.test.ts +243 -4
- package/src/pdfHtmlTemplate.ts +93 -0
- package/src/security/AccountSecurityScreen.test.tsx +262 -0
- package/src/security/AccountSecurityScreen.tsx +156 -0
- package/src/security/LinkedAccountsCard.test.tsx +371 -0
- package/src/security/LinkedAccountsCard.tsx +297 -0
- package/src/security/PasskeysCard.test.tsx +378 -0
- package/src/security/PasskeysCard.tsx +371 -0
- package/src/security/PasswordCard.test.tsx +445 -0
- package/src/security/PasswordCard.tsx +342 -0
- package/src/security/SessionsCard.test.tsx +349 -0
- package/src/security/SessionsCard.tsx +362 -0
- package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
- package/src/security/TwoFactorSettingsCard.tsx +872 -0
- package/src/security/securityMethods.test.ts +101 -0
- package/src/security/securityMethods.ts +104 -0
- package/src/security/securityTypes.ts +480 -0
- package/src/security/userAgent.test.ts +119 -0
- package/src/security/userAgent.ts +102 -0
- package/src/signUp/OAuthButtons.test.tsx +27 -0
- package/src/signUp/OAuthButtons.tsx +153 -19
- package/src/signUp/SignUpScreen.test.tsx +170 -1
- package/src/signUp/SignUpScreen.tsx +87 -25
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
- package/src/signUp/signUpTypes.ts +23 -1
- package/src/useConsentForms.test.ts +37 -1
- package/src/useConsentForms.ts +25 -0
- package/src/useProvisionalConsent.test.ts +256 -0
- package/src/useProvisionalConsent.ts +218 -0
- package/src/withLoading.test.tsx +61 -0
- package/src/withLoading.tsx +50 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, spyOn} from "bun:test";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {LinearGradient} from "expo-linear-gradient";
|
|
4
|
+
import {AccessibilityInfo, Animated, View} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
resolveLoadingContent,
|
|
8
|
+
Skeleton,
|
|
9
|
+
SkeletonCard,
|
|
10
|
+
SkeletonCircle,
|
|
11
|
+
SkeletonGroup,
|
|
12
|
+
SkeletonList,
|
|
13
|
+
SkeletonText,
|
|
14
|
+
} from "./Skeleton";
|
|
15
|
+
import {getTextFontSize, Text} from "./Text";
|
|
16
|
+
import {renderWithTheme} from "./test-utils";
|
|
17
|
+
|
|
18
|
+
// Skeletons are hidden from assistive tech, so queries opt in to hidden elements.
|
|
19
|
+
const HIDDEN = {includeHiddenElements: true};
|
|
20
|
+
|
|
21
|
+
interface MockFn {
|
|
22
|
+
mock: {calls: unknown[][]};
|
|
23
|
+
mockClear: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const loopMock = Animated.loop as unknown as MockFn;
|
|
27
|
+
|
|
28
|
+
const flushReducedMotion = async (): Promise<void> => {
|
|
29
|
+
await act(async () => {
|
|
30
|
+
await Promise.resolve();
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("Skeleton", () => {
|
|
35
|
+
// Earlier renders may still be waiting on the reduce-motion answer; settle them before counting.
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
await flushReducedMotion();
|
|
38
|
+
loopMock.mockClear();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("renders a block with default size and is hidden from screen readers", () => {
|
|
42
|
+
const {getByTestId} = renderWithTheme(<Skeleton testID="block" />);
|
|
43
|
+
const block = getByTestId("block", HIDDEN);
|
|
44
|
+
expect(block.props.style).toMatchObject({height: 16, width: "100%"});
|
|
45
|
+
expect(block.props["aria-hidden"]).toBe(true);
|
|
46
|
+
expect(block.props.importantForAccessibility).toBe("no-hide-descendants");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("applies width, height, and circle rounding", () => {
|
|
50
|
+
const {getByTestId} = renderWithTheme(
|
|
51
|
+
<Skeleton height={48} rounding="circle" testID="block" width={48} />
|
|
52
|
+
);
|
|
53
|
+
expect(getByTestId("block", HIDDEN).props.style).toMatchObject({
|
|
54
|
+
borderRadius: 24,
|
|
55
|
+
height: 48,
|
|
56
|
+
width: 48,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("pulses by default", async () => {
|
|
61
|
+
renderWithTheme(<Skeleton />);
|
|
62
|
+
await flushReducedMotion();
|
|
63
|
+
expect(loopMock.mock.calls.length).toBe(1);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("holds still until the reduce-motion setting is known", async () => {
|
|
67
|
+
const {getByTestId} = renderWithTheme(<Skeleton testID="block" />);
|
|
68
|
+
expect(loopMock.mock.calls.length).toBe(0);
|
|
69
|
+
expect(getByTestId("block", HIDDEN).props.style.opacity).toBeUndefined();
|
|
70
|
+
await flushReducedMotion();
|
|
71
|
+
expect(loopMock.mock.calls.length).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("does not animate with animation none", async () => {
|
|
75
|
+
const {getByTestId} = renderWithTheme(<Skeleton animation="none" testID="block" />);
|
|
76
|
+
await flushReducedMotion();
|
|
77
|
+
expect(loopMock.mock.calls.length).toBe(0);
|
|
78
|
+
expect(getByTestId("block", HIDDEN).props.style.opacity).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("renders a shimmer highlight once the block has a width", async () => {
|
|
82
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
83
|
+
<Skeleton animation="shimmer" testID="block" />
|
|
84
|
+
);
|
|
85
|
+
await flushReducedMotion();
|
|
86
|
+
const overlay = getByTestId("block.shimmer", HIDDEN);
|
|
87
|
+
expect(overlay.children.length).toBe(0);
|
|
88
|
+
fireEvent(overlay, "layout", {nativeEvent: {layout: {height: 16, width: 200}}});
|
|
89
|
+
expect(queryByTestId("block.shimmer", HIDDEN)?.children.length).toBe(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("fades the shimmer to transparent white so Android does not draw a dark band", async () => {
|
|
93
|
+
const {getByTestId, UNSAFE_getByType} = renderWithTheme(
|
|
94
|
+
<Skeleton animation="shimmer" testID="block" />
|
|
95
|
+
);
|
|
96
|
+
await flushReducedMotion();
|
|
97
|
+
fireEvent(getByTestId("block.shimmer", HIDDEN), "layout", {
|
|
98
|
+
nativeEvent: {layout: {height: 16, width: 200}},
|
|
99
|
+
});
|
|
100
|
+
const [start, , end] = UNSAFE_getByType(LinearGradient).props.colors;
|
|
101
|
+
expect(start).toBe("rgba(255,255,255,0)");
|
|
102
|
+
expect(end).toBe("rgba(255,255,255,0)");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("reduced motion", () => {
|
|
106
|
+
let reduceMotionSpy: ReturnType<typeof spyOn>;
|
|
107
|
+
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
reduceMotionSpy = spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockImplementation(() =>
|
|
110
|
+
Promise.resolve(true)
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
afterEach(() => {
|
|
115
|
+
reduceMotionSpy.mockImplementation(() => Promise.resolve(false));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("stops animating when the OS asks for reduced motion", async () => {
|
|
119
|
+
const {getByTestId} = renderWithTheme(<Skeleton animation="shimmer" testID="block" />);
|
|
120
|
+
await flushReducedMotion();
|
|
121
|
+
expect(getByTestId("block", HIDDEN).props.style.opacity).toBeUndefined();
|
|
122
|
+
expect(() => getByTestId("block.shimmer", HIDDEN)).toThrow();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("SkeletonGroup", () => {
|
|
128
|
+
// Earlier renders may still be waiting on the reduce-motion answer; settle them before counting.
|
|
129
|
+
beforeEach(async () => {
|
|
130
|
+
await flushReducedMotion();
|
|
131
|
+
loopMock.mockClear();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("drives every skeleton inside it from one timeline", async () => {
|
|
135
|
+
renderWithTheme(
|
|
136
|
+
<SkeletonGroup>
|
|
137
|
+
<Skeleton />
|
|
138
|
+
<Skeleton />
|
|
139
|
+
<Skeleton />
|
|
140
|
+
</SkeletonGroup>
|
|
141
|
+
);
|
|
142
|
+
await flushReducedMotion();
|
|
143
|
+
expect(loopMock.mock.calls.length).toBe(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("passes its animation down to skeletons that do not set one", async () => {
|
|
147
|
+
const {getByTestId} = renderWithTheme(
|
|
148
|
+
<SkeletonGroup animation="none">
|
|
149
|
+
<Skeleton testID="block" />
|
|
150
|
+
</SkeletonGroup>
|
|
151
|
+
);
|
|
152
|
+
await flushReducedMotion();
|
|
153
|
+
expect(loopMock.mock.calls.length).toBe(0);
|
|
154
|
+
expect(getByTestId("block", HIDDEN).props.style.opacity).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("lets a skeleton override the group animation", async () => {
|
|
158
|
+
const {getByTestId} = renderWithTheme(
|
|
159
|
+
<SkeletonGroup animation="none">
|
|
160
|
+
<Skeleton animation="shimmer" testID="block" />
|
|
161
|
+
</SkeletonGroup>
|
|
162
|
+
);
|
|
163
|
+
await flushReducedMotion();
|
|
164
|
+
expect(getByTestId("block.shimmer", HIDDEN)).toBeTruthy();
|
|
165
|
+
expect(loopMock.mock.calls.length).toBe(1);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("SkeletonText", () => {
|
|
170
|
+
it("renders three lines with a shorter last line by default", () => {
|
|
171
|
+
const {getByTestId} = renderWithTheme(<SkeletonText testID="text" />);
|
|
172
|
+
expect(getByTestId("text.line.0", HIDDEN).props.style.width).toBe("100%");
|
|
173
|
+
expect(getByTestId("text.line.1", HIDDEN).props.style.width).toBe("100%");
|
|
174
|
+
expect(getByTestId("text.line.2", HIDDEN).props.style.width).toBe("60%");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("renders a single full-width line when lines is 1", () => {
|
|
178
|
+
const {getByTestId, queryByTestId} = renderWithTheme(<SkeletonText lines={1} testID="text" />);
|
|
179
|
+
expect(getByTestId("text.line.0", HIDDEN).props.style.width).toBe("100%");
|
|
180
|
+
expect(queryByTestId("text.line.1", HIDDEN)).toBeNull();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("sizes lines to the matching Text size", () => {
|
|
184
|
+
const {getByTestId} = renderWithTheme(<SkeletonText lines={1} size="xl" testID="text" />);
|
|
185
|
+
expect(getByTestId("text.line.0", HIDDEN).props.style.height).toBe(getTextFontSize("xl"));
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("SkeletonCircle", () => {
|
|
190
|
+
it("renders a circle of the given size", () => {
|
|
191
|
+
const {getByTestId} = renderWithTheme(<SkeletonCircle size={64} testID="avatar" />);
|
|
192
|
+
expect(getByTestId("avatar", HIDDEN).props.style).toMatchObject({
|
|
193
|
+
borderRadius: 32,
|
|
194
|
+
height: 64,
|
|
195
|
+
width: 64,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("SkeletonCard", () => {
|
|
201
|
+
it("renders an avatar, title, and text without media by default", () => {
|
|
202
|
+
const {getByTestId, queryByTestId} = renderWithTheme(<SkeletonCard testID="card" />);
|
|
203
|
+
expect(getByTestId("card.body.avatar", HIDDEN)).toBeTruthy();
|
|
204
|
+
expect(getByTestId("card.body.title", HIDDEN)).toBeTruthy();
|
|
205
|
+
expect(getByTestId("card.body.text.line.1", HIDDEN)).toBeTruthy();
|
|
206
|
+
expect(queryByTestId("card.media", HIDDEN)).toBeNull();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("renders a media block and hides the avatar when asked", () => {
|
|
210
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
211
|
+
<SkeletonCard mediaHeight={120} showAvatar={false} showMedia testID="card" />
|
|
212
|
+
);
|
|
213
|
+
expect(getByTestId("card.media", HIDDEN).props.style.height).toBe(120);
|
|
214
|
+
expect(queryByTestId("card.body.avatar", HIDDEN)).toBeNull();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("SkeletonList", () => {
|
|
219
|
+
it("renders the requested number of rows", () => {
|
|
220
|
+
const {getByTestId, queryByTestId} = renderWithTheme(<SkeletonList rows={2} testID="list" />);
|
|
221
|
+
expect(getByTestId("list.row.0", HIDDEN)).toBeTruthy();
|
|
222
|
+
expect(getByTestId("list.row.1", HIDDEN)).toBeTruthy();
|
|
223
|
+
expect(queryByTestId("list.row.2", HIDDEN)).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("resolveLoadingContent", () => {
|
|
228
|
+
it("returns children when not loading", () => {
|
|
229
|
+
const {getByText} = renderWithTheme(
|
|
230
|
+
<View>{resolveLoadingContent({children: <Text>Loaded</Text>, loading: false})}</View>
|
|
231
|
+
);
|
|
232
|
+
expect(getByText("Loaded")).toBeTruthy();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("returns the loading component when loading", () => {
|
|
236
|
+
const {getByTestId, queryByText} = renderWithTheme(
|
|
237
|
+
<View>
|
|
238
|
+
{resolveLoadingContent({
|
|
239
|
+
children: <Text>Loaded</Text>,
|
|
240
|
+
loading: true,
|
|
241
|
+
loadingComponent: <Skeleton testID="placeholder" />,
|
|
242
|
+
})}
|
|
243
|
+
</View>
|
|
244
|
+
);
|
|
245
|
+
expect(getByTestId("placeholder", HIDDEN)).toBeTruthy();
|
|
246
|
+
expect(queryByText("Loaded")).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("prefers the caller's loading component over the container default", () => {
|
|
250
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
251
|
+
<View>
|
|
252
|
+
{resolveLoadingContent({
|
|
253
|
+
defaultLoadingComponent: <Skeleton testID="default" />,
|
|
254
|
+
loading: true,
|
|
255
|
+
loadingComponent: <Skeleton testID="custom" />,
|
|
256
|
+
})}
|
|
257
|
+
</View>
|
|
258
|
+
);
|
|
259
|
+
expect(getByTestId("custom", HIDDEN)).toBeTruthy();
|
|
260
|
+
expect(queryByTestId("default", HIDDEN)).toBeNull();
|
|
261
|
+
});
|
|
262
|
+
});
|
package/src/Skeleton.tsx
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import {LinearGradient} from "expo-linear-gradient";
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
type FC,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from "react";
|
|
12
|
+
import {
|
|
13
|
+
AccessibilityInfo,
|
|
14
|
+
Animated,
|
|
15
|
+
type LayoutChangeEvent,
|
|
16
|
+
Platform,
|
|
17
|
+
StyleSheet,
|
|
18
|
+
View,
|
|
19
|
+
type ViewStyle,
|
|
20
|
+
} from "react-native";
|
|
21
|
+
|
|
22
|
+
import type {
|
|
23
|
+
LoadingProps,
|
|
24
|
+
SkeletonAnimation,
|
|
25
|
+
SkeletonCardProps,
|
|
26
|
+
SkeletonCircleProps,
|
|
27
|
+
SkeletonGroupProps,
|
|
28
|
+
SkeletonListProps,
|
|
29
|
+
SkeletonProps,
|
|
30
|
+
SkeletonTextProps,
|
|
31
|
+
} from "./Common";
|
|
32
|
+
import {getRounding, getSpacing} from "./Common";
|
|
33
|
+
// Primitives render plain Views rather than Box: Box renders these for its loading state, so
|
|
34
|
+
// importing Box here would create a cycle.
|
|
35
|
+
import {getTextFontSize} from "./Text";
|
|
36
|
+
import {useTheme} from "./Theme";
|
|
37
|
+
import {resolveTestID, toTestProps} from "./testing/resolveTestId";
|
|
38
|
+
|
|
39
|
+
const DEFAULT_ANIMATION: SkeletonAnimation = "pulse";
|
|
40
|
+
const PULSE_HALF_CYCLE_MS = 800;
|
|
41
|
+
const SHIMMER_CYCLE_MS = 1200;
|
|
42
|
+
const PULSE_MIN_OPACITY = 0.45;
|
|
43
|
+
const DEFAULT_LOADING_LABEL = "Loading";
|
|
44
|
+
|
|
45
|
+
// react-native-web drops pointerEvents from inline styles, so the overlay style lives here.
|
|
46
|
+
const styles = StyleSheet.create({
|
|
47
|
+
shimmerOverlay: {
|
|
48
|
+
bottom: 0,
|
|
49
|
+
left: 0,
|
|
50
|
+
pointerEvents: "none",
|
|
51
|
+
position: "absolute",
|
|
52
|
+
right: 0,
|
|
53
|
+
top: 0,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Skeletons are decoration: the loading container announces the busy state, so each block hides
|
|
58
|
+
// itself from assistive tech instead of reading as a pile of empty views.
|
|
59
|
+
const HIDDEN_FROM_ACCESSIBILITY = {
|
|
60
|
+
accessibilityElementsHidden: true,
|
|
61
|
+
"aria-hidden": true,
|
|
62
|
+
importantForAccessibility: "no-hide-descendants" as const,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
interface SkeletonGroupContextValue {
|
|
66
|
+
animation: SkeletonAnimation;
|
|
67
|
+
progress: Animated.Value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const SkeletonGroupContext = createContext<SkeletonGroupContextValue | undefined>(undefined);
|
|
71
|
+
|
|
72
|
+
// Web can read prefers-reduced-motion synchronously. Native has no synchronous API, so skeletons
|
|
73
|
+
// hold still until AccessibilityInfo answers rather than animating before the answer arrives.
|
|
74
|
+
const getInitialReducedMotion = (): boolean => {
|
|
75
|
+
if (Platform.OS === "web" && typeof window !== "undefined" && window.matchMedia) {
|
|
76
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const useReducedMotion = (): boolean => {
|
|
82
|
+
const [isReducedMotion, setIsReducedMotion] = useState(getInitialReducedMotion);
|
|
83
|
+
|
|
84
|
+
// Follow the OS reduce-motion setting so skeletons stop animating when the user asks for less motion.
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
let isMounted = true;
|
|
87
|
+
// Promise.resolve tolerates platforms and test doubles that return a plain value.
|
|
88
|
+
void Promise.resolve(AccessibilityInfo.isReduceMotionEnabled?.()).then((isEnabled) => {
|
|
89
|
+
if (isMounted) {
|
|
90
|
+
setIsReducedMotion(Boolean(isEnabled));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const subscription = AccessibilityInfo.addEventListener?.("reduceMotionChanged", (isEnabled) =>
|
|
94
|
+
setIsReducedMotion(Boolean(isEnabled))
|
|
95
|
+
);
|
|
96
|
+
return () => {
|
|
97
|
+
isMounted = false;
|
|
98
|
+
subscription?.remove?.();
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
return isReducedMotion;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const buildLoop = (
|
|
106
|
+
progress: Animated.Value,
|
|
107
|
+
animation: SkeletonAnimation
|
|
108
|
+
): Animated.CompositeAnimation => {
|
|
109
|
+
const useNativeDriver = Platform.OS !== "web";
|
|
110
|
+
if (animation === "shimmer") {
|
|
111
|
+
return Animated.loop(
|
|
112
|
+
Animated.timing(progress, {duration: SHIMMER_CYCLE_MS, toValue: 1, useNativeDriver})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return Animated.loop(
|
|
116
|
+
Animated.sequence([
|
|
117
|
+
Animated.timing(progress, {duration: PULSE_HALF_CYCLE_MS, toValue: 1, useNativeDriver}),
|
|
118
|
+
Animated.timing(progress, {duration: PULSE_HALF_CYCLE_MS, toValue: 0, useNativeDriver}),
|
|
119
|
+
])
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const useAnimationLoop = ({
|
|
124
|
+
animation,
|
|
125
|
+
isEnabled,
|
|
126
|
+
progress,
|
|
127
|
+
}: {
|
|
128
|
+
animation: SkeletonAnimation;
|
|
129
|
+
isEnabled: boolean;
|
|
130
|
+
progress: Animated.Value;
|
|
131
|
+
}): void => {
|
|
132
|
+
// Run one looping timeline per group (or per ungrouped skeleton) and stop it on unmount.
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (!isEnabled || animation === "none") {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
progress.setValue(0);
|
|
138
|
+
const loop = buildLoop(progress, animation);
|
|
139
|
+
loop.start();
|
|
140
|
+
return () => loop.stop();
|
|
141
|
+
}, [animation, isEnabled, progress]);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const useSkeletonMotion = (
|
|
145
|
+
animationProp: SkeletonAnimation | undefined
|
|
146
|
+
): {animation: SkeletonAnimation; progress: Animated.Value} => {
|
|
147
|
+
const group = useContext(SkeletonGroupContext);
|
|
148
|
+
const isReducedMotion = useReducedMotion();
|
|
149
|
+
const localProgress = useRef(new Animated.Value(0)).current;
|
|
150
|
+
const requested = animationProp ?? group?.animation ?? DEFAULT_ANIMATION;
|
|
151
|
+
const animation = isReducedMotion ? "none" : requested;
|
|
152
|
+
const isSharingGroupTimeline = group !== undefined && group.animation === animation;
|
|
153
|
+
|
|
154
|
+
useAnimationLoop({animation, isEnabled: !isSharingGroupTimeline, progress: localProgress});
|
|
155
|
+
|
|
156
|
+
return {animation, progress: isSharingGroupTimeline ? group.progress : localProgress};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Sets the animation for every skeleton inside it and drives them from one timeline, so a
|
|
161
|
+
* screen of placeholders pulses together. Box and the other loading containers add one for you.
|
|
162
|
+
*/
|
|
163
|
+
export const SkeletonGroup: FC<SkeletonGroupProps> = ({animation, children}) => {
|
|
164
|
+
const isReducedMotion = useReducedMotion();
|
|
165
|
+
const progress = useRef(new Animated.Value(0)).current;
|
|
166
|
+
const resolvedAnimation = isReducedMotion ? "none" : (animation ?? DEFAULT_ANIMATION);
|
|
167
|
+
|
|
168
|
+
useAnimationLoop({animation: resolvedAnimation, isEnabled: true, progress});
|
|
169
|
+
|
|
170
|
+
const value = useMemo(
|
|
171
|
+
() => ({animation: resolvedAnimation, progress}),
|
|
172
|
+
[resolvedAnimation, progress]
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return <SkeletonGroupContext.Provider value={value}>{children}</SkeletonGroupContext.Provider>;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const ShimmerHighlight: FC<{progress: Animated.Value; testID?: string}> = ({progress, testID}) => {
|
|
179
|
+
const {colorScheme} = useTheme();
|
|
180
|
+
const [width, setWidth] = useState(0);
|
|
181
|
+
const highlight = colorScheme === "dark" ? "rgba(255,255,255,0.12)" : "rgba(255,255,255,0.6)";
|
|
182
|
+
// Fade to transparent white, not "transparent": Android reads that as transparent black and the
|
|
183
|
+
// gradient would pass through a dark band.
|
|
184
|
+
const edge = "rgba(255,255,255,0)";
|
|
185
|
+
|
|
186
|
+
const onLayout = (event: LayoutChangeEvent): void => {
|
|
187
|
+
setWidth(event.nativeEvent.layout.width);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const translateX = progress.interpolate({inputRange: [0, 1], outputRange: [-width, width]});
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<View onLayout={onLayout} style={styles.shimmerOverlay} {...toTestProps(testID)}>
|
|
194
|
+
{width > 0 && (
|
|
195
|
+
<Animated.View style={{height: "100%", transform: [{translateX}], width}}>
|
|
196
|
+
<LinearGradient
|
|
197
|
+
colors={[edge, highlight, edge]}
|
|
198
|
+
end={{x: 1, y: 0.5}}
|
|
199
|
+
start={{x: 0, y: 0.5}}
|
|
200
|
+
style={{height: "100%", width: "100%"}}
|
|
201
|
+
/>
|
|
202
|
+
</Animated.View>
|
|
203
|
+
)}
|
|
204
|
+
</View>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A placeholder block in the shape of content that is still loading. Compose blocks to sketch
|
|
210
|
+
* any layout; `SkeletonText`, `SkeletonCircle`, `SkeletonCard`, and `SkeletonList` cover the
|
|
211
|
+
* common shapes.
|
|
212
|
+
*/
|
|
213
|
+
export const Skeleton: FC<SkeletonProps> = ({
|
|
214
|
+
animation: animationProp,
|
|
215
|
+
color = "neutralExtraLight",
|
|
216
|
+
height = 16,
|
|
217
|
+
rounding = "sm",
|
|
218
|
+
testID,
|
|
219
|
+
width = "100%",
|
|
220
|
+
}) => {
|
|
221
|
+
const {theme} = useTheme();
|
|
222
|
+
const {animation, progress} = useSkeletonMotion(animationProp);
|
|
223
|
+
|
|
224
|
+
let borderRadius: number | string | undefined;
|
|
225
|
+
if (rounding === "circle") {
|
|
226
|
+
borderRadius = typeof height === "number" ? height / 2 : 9999;
|
|
227
|
+
} else {
|
|
228
|
+
borderRadius = getRounding(rounding);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const style = {
|
|
232
|
+
backgroundColor: theme.surface[color],
|
|
233
|
+
borderRadius,
|
|
234
|
+
height,
|
|
235
|
+
overflow: "hidden",
|
|
236
|
+
width,
|
|
237
|
+
...(animation === "pulse"
|
|
238
|
+
? {
|
|
239
|
+
opacity: progress.interpolate({
|
|
240
|
+
inputRange: [0, 1],
|
|
241
|
+
outputRange: [1, PULSE_MIN_OPACITY],
|
|
242
|
+
}),
|
|
243
|
+
}
|
|
244
|
+
: {}),
|
|
245
|
+
} as Animated.WithAnimatedObject<ViewStyle>;
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<Animated.View {...HIDDEN_FROM_ACCESSIBILITY} style={style} {...toTestProps(testID)}>
|
|
249
|
+
{animation === "shimmer" && (
|
|
250
|
+
<ShimmerHighlight progress={progress} testID={resolveTestID(testID, "shimmer")} />
|
|
251
|
+
)}
|
|
252
|
+
</Animated.View>
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/** Lines of placeholder text sized to match `Text` at the same `size`. */
|
|
257
|
+
export const SkeletonText: FC<SkeletonTextProps> = ({
|
|
258
|
+
animation,
|
|
259
|
+
lastLineWidth = "60%",
|
|
260
|
+
lines = 3,
|
|
261
|
+
size = "md",
|
|
262
|
+
testID,
|
|
263
|
+
}) => {
|
|
264
|
+
const fontSize = getTextFontSize(size);
|
|
265
|
+
const lineCount = Math.max(1, Math.floor(lines));
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<View
|
|
269
|
+
{...HIDDEN_FROM_ACCESSIBILITY}
|
|
270
|
+
style={{gap: Math.round(fontSize / 2), width: "100%"}}
|
|
271
|
+
{...toTestProps(testID)}
|
|
272
|
+
>
|
|
273
|
+
{Array.from({length: lineCount}, (_unused, index) => (
|
|
274
|
+
<Skeleton
|
|
275
|
+
animation={animation}
|
|
276
|
+
height={fontSize}
|
|
277
|
+
key={index}
|
|
278
|
+
testID={resolveTestID(testID, `line.${index}`)}
|
|
279
|
+
width={lineCount > 1 && index === lineCount - 1 ? lastLineWidth : "100%"}
|
|
280
|
+
/>
|
|
281
|
+
))}
|
|
282
|
+
</View>
|
|
283
|
+
);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/** A round placeholder for avatars and icons. */
|
|
287
|
+
export const SkeletonCircle: FC<SkeletonCircleProps> = ({animation, size = 40, testID}) => {
|
|
288
|
+
return (
|
|
289
|
+
<Skeleton animation={animation} height={size} rounding="circle" testID={testID} width={size} />
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const SkeletonRow: FC<{
|
|
294
|
+
animation?: SkeletonAnimation;
|
|
295
|
+
lines: number;
|
|
296
|
+
showAvatar: boolean;
|
|
297
|
+
testID?: string;
|
|
298
|
+
}> = ({animation, lines, showAvatar, testID}) => {
|
|
299
|
+
return (
|
|
300
|
+
<View
|
|
301
|
+
style={{alignItems: "flex-start", flexDirection: "row", gap: getSpacing(3), width: "100%"}}
|
|
302
|
+
{...toTestProps(testID)}
|
|
303
|
+
>
|
|
304
|
+
{showAvatar && (
|
|
305
|
+
<SkeletonCircle animation={animation} testID={resolveTestID(testID, "avatar")} />
|
|
306
|
+
)}
|
|
307
|
+
<View style={{flex: 1, gap: getSpacing(2), minWidth: 0}}>
|
|
308
|
+
<Skeleton
|
|
309
|
+
animation={animation}
|
|
310
|
+
height={getTextFontSize("lg")}
|
|
311
|
+
testID={resolveTestID(testID, "title")}
|
|
312
|
+
width="40%"
|
|
313
|
+
/>
|
|
314
|
+
{lines > 0 && (
|
|
315
|
+
<SkeletonText
|
|
316
|
+
animation={animation}
|
|
317
|
+
lines={lines}
|
|
318
|
+
testID={resolveTestID(testID, "text")}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
</View>
|
|
322
|
+
</View>
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
/** A card-shaped placeholder: optional media, optional avatar, a title bar, and text lines. */
|
|
327
|
+
export const SkeletonCard: FC<SkeletonCardProps> = ({
|
|
328
|
+
animation,
|
|
329
|
+
lines = 2,
|
|
330
|
+
mediaHeight = 160,
|
|
331
|
+
showAvatar = true,
|
|
332
|
+
showMedia = false,
|
|
333
|
+
testID,
|
|
334
|
+
}) => {
|
|
335
|
+
return (
|
|
336
|
+
<View
|
|
337
|
+
{...HIDDEN_FROM_ACCESSIBILITY}
|
|
338
|
+
style={{gap: getSpacing(4), width: "100%"}}
|
|
339
|
+
{...toTestProps(testID)}
|
|
340
|
+
>
|
|
341
|
+
{showMedia && (
|
|
342
|
+
<Skeleton
|
|
343
|
+
animation={animation}
|
|
344
|
+
height={mediaHeight}
|
|
345
|
+
rounding="md"
|
|
346
|
+
testID={resolveTestID(testID, "media")}
|
|
347
|
+
/>
|
|
348
|
+
)}
|
|
349
|
+
<SkeletonRow
|
|
350
|
+
animation={animation}
|
|
351
|
+
lines={lines}
|
|
352
|
+
showAvatar={showAvatar}
|
|
353
|
+
testID={resolveTestID(testID, "body")}
|
|
354
|
+
/>
|
|
355
|
+
</View>
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/** Repeated list-row placeholders, for lists and tables that are still fetching. */
|
|
360
|
+
export const SkeletonList: FC<SkeletonListProps> = ({
|
|
361
|
+
animation,
|
|
362
|
+
lines = 2,
|
|
363
|
+
rows = 3,
|
|
364
|
+
showAvatar = true,
|
|
365
|
+
testID,
|
|
366
|
+
}) => {
|
|
367
|
+
const rowCount = Math.max(1, Math.floor(rows));
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<View
|
|
371
|
+
{...HIDDEN_FROM_ACCESSIBILITY}
|
|
372
|
+
style={{gap: getSpacing(4), width: "100%"}}
|
|
373
|
+
{...toTestProps(testID)}
|
|
374
|
+
>
|
|
375
|
+
{Array.from({length: rowCount}, (_unused, index) => (
|
|
376
|
+
<SkeletonRow
|
|
377
|
+
animation={animation}
|
|
378
|
+
key={index}
|
|
379
|
+
lines={lines}
|
|
380
|
+
showAvatar={showAvatar}
|
|
381
|
+
testID={resolveTestID(testID, `row.${index}`)}
|
|
382
|
+
/>
|
|
383
|
+
))}
|
|
384
|
+
</View>
|
|
385
|
+
);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* What a loading container renders: its children when not loading, otherwise its
|
|
390
|
+
* `loadingComponent` (or the container's own default) inside a `SkeletonGroup`. Components that
|
|
391
|
+
* accept `LoadingProps` use this so they all treat loading the same way.
|
|
392
|
+
*/
|
|
393
|
+
export const resolveLoadingContent = ({
|
|
394
|
+
children,
|
|
395
|
+
defaultLoadingComponent,
|
|
396
|
+
loading,
|
|
397
|
+
loadingAnimation,
|
|
398
|
+
loadingComponent,
|
|
399
|
+
}: LoadingProps & {
|
|
400
|
+
children?: ReactNode;
|
|
401
|
+
defaultLoadingComponent?: ReactNode;
|
|
402
|
+
}): ReactNode => {
|
|
403
|
+
if (!loading) {
|
|
404
|
+
return children;
|
|
405
|
+
}
|
|
406
|
+
return (
|
|
407
|
+
<SkeletonGroup animation={loadingAnimation}>
|
|
408
|
+
{loadingComponent ?? defaultLoadingComponent ?? <SkeletonText />}
|
|
409
|
+
</SkeletonGroup>
|
|
410
|
+
);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/** Accessibility props a loading container sets so screen readers hear one busy announcement. */
|
|
414
|
+
export const getLoadingAccessibilityProps = ({
|
|
415
|
+
loading,
|
|
416
|
+
loadingLabel,
|
|
417
|
+
}: Pick<LoadingProps, "loading" | "loadingLabel">): {
|
|
418
|
+
"aria-busy"?: boolean;
|
|
419
|
+
accessibilityLabel?: string;
|
|
420
|
+
accessibilityState?: {busy: boolean};
|
|
421
|
+
} => {
|
|
422
|
+
if (!loading) {
|
|
423
|
+
return {};
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
accessibilityLabel: loadingLabel ?? DEFAULT_LOADING_LABEL,
|
|
427
|
+
accessibilityState: {busy: true},
|
|
428
|
+
"aria-busy": true,
|
|
429
|
+
};
|
|
430
|
+
};
|