import React, { useState } from
'react'
;
import {
ChakraProvider, Box, Stack, Skeleton,
SkeletonCircle, SkeletonText, Button,
Heading
} from
'@chakra-ui/react'
;
const useRemoteData = () => {
const loading =
true
;
const data = { title:
'GFG'
};
const error =
false
;
return
{ data, loading, error };
};
function
App() {
const [is_Loaded, set_is_Loaded] = useState(
false
);
const { data, loading, error } = useRemoteData();
return
(
<ChakraProvider>
<Box p={4} textAlign=
"center"
maxW=
"600px"
m=
"auto"
>
<Heading as=
"h1"
size=
"xl"
mb={2} color=
"green.500"
>
GeeksforGeeks
</Heading>
<Heading as=
"h3"
size=
"md"
mb={4}>
Chakra UI Feedback Skeleton
</Heading>
<Box mb={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Stack of Skeletons
</Heading>
<Stack spacing={2}>
<Skeleton height=
"20px"
isLoaded={is_Loaded} />
<Skeleton height=
"20px"
isLoaded={is_Loaded} />
<Skeleton height=
"20px"
isLoaded={is_Loaded} />
</Stack>
</Box>
<Box fontSize=
"lg"
mt={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Wrapped Content
with
Skeleton
</Heading>
<Skeleton isLoaded={is_Loaded}>
<Box>
<div>Contents wrapped</div>
<div>Won't be visible</div>
</Box>
</Skeleton>
</Box>
<Box mt={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Card Component
with
Skeleton
</Heading>
{error ? (
<Box color=
"red.500"
fontSize=
"lg"
fontWeight=
"bold"
>
Error
</Box>
) : (
<Box>
<Skeleton isLoaded={!loading}>
<Box fontSize=
"xl"
fontWeight=
"bold"
>
{data.title}
</Box>
</Skeleton>
</Box>
)}
</Box>
<Box mt={6} p={4} boxShadow=
"lg"
bg=
"white"
>
<Heading as=
"h2"
size=
"md"
mb={2}>
Circle and Text Skeleton
</Heading>
<SkeletonCircle size=
"10"
isLoaded={is_Loaded} />
<SkeletonText mt=
"4"
noOfLines={4}
spacing=
"4"
skeletonHeight=
"2"
isLoaded={is_Loaded} />
</Box>
<Box mt={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Change Skeleton color
</Heading>
<Skeleton startColor=
"pink.500"
endColor=
"orange.500"
height=
"20px"
isLoaded={is_Loaded} />
</Box>
<Box mt={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Skip Skeleton when content is loaded
</Heading>
<Skeleton isLoaded={is_Loaded}>
<span>Chakra UI is cool</span>
</Skeleton>
</Box>
<Stack spacing={4} mt={6}>
<Heading as=
"h2"
size=
"md"
mb={2}>
Fade Duration
with
isLoaded
</Heading>
<Skeleton height=
"40px"
isLoaded={is_Loaded}>
<Box fontSize=
"lg"
fontWeight=
"bold"
>
Hello GeeksforGeeks!
</Box>
</Skeleton>
<Skeleton
height=
"40px"
isLoaded={is_Loaded}
bg=
"green.500"
color=
"white"
fadeDuration={1}
>
<Box fontSize=
"lg"
fontWeight=
"bold"
>
Hello React!
</Box>
</Skeleton>
<Skeleton
height=
"40px"
isLoaded={is_Loaded}
fadeDuration={4}
bg=
"blue.500"
color=
"white"
>
<Box fontSize=
"lg"
fontWeight=
"bold"
>
Hello GFG!
</Box>
</Skeleton>
</Stack>
<Box mt={6} textAlign=
"center"
>
<Button onClick={
() => set_is_Loaded((v) => !v)
}>
Toggle Skeleton
</Button>
</Box>
</Box>
</ChakraProvider>
);
}
export
default
App;