import React from "react"; import Box, { BoxProps } from "../box/box"; import { ResponsiveValue, PaletteColors } from "../../../theme"; import { pearl } from "../../../pearl"; import { BoxStyleProps } from "../../../theme/src/style-functions"; import { View } from "react-native"; import { useTheme } from "../../../hooks"; type BaseSkeletonProps = BoxProps & { /** * The color at the animation start */ startColor?: ResponsiveValue; /** * The color at the animation end */ endColor?: ResponsiveValue; /** * If `true`, it'll render its children with a fade transition * * @default false */ isLoaded?: boolean; /** * The animation speed in milliseconds * * @default 800 */ speed?: number; /** * The fadeIn duration in milliseconds. Requires `isLoaded` toggled to `true` in order to see the transition. * * @default 200 */ fadeDuration?: number; }; const BaseSkeleton = React.memo( React.forwardRef( ( { startColor, endColor, isLoaded = false, speed = 800, fadeDuration = 200, ...rest }: BaseSkeletonProps, ref: any ) => { const { colorMode } = useTheme(); const key = React.useMemo( () => `${colorMode}-${Math.random()}`, [isLoaded, colorMode, startColor, endColor, speed, fadeDuration, rest] ); if (isLoaded) { return ( {rest.children} ); } rest.children = {rest.children}; return ( ); } ) ); /** * A Skeleton component that is used to show placeholders is a loading state */ const Skeleton = pearl< BaseSkeletonProps, "atom", Record, BoxStyleProps >(BaseSkeleton, { componentName: "Skeleton", type: "atom", }); export type SkeletonProps = React.ComponentProps; Skeleton.displayName = "Skeleton"; export default Skeleton;