2023-06-28 01:12:17 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { Flex } from '@chakra-ui/react'
|
|
|
|
|
|
|
|
export const RainbowSkeleton = props => {
|
2023-06-29 23:41:06 +00:00
|
|
|
const [rainbowColours] = React.useState([
|
|
|
|
'#f34a4a',
|
|
|
|
'#ffbc48',
|
|
|
|
'#58ca70',
|
|
|
|
'#47b5e6',
|
|
|
|
'#a555e8'
|
|
|
|
])
|
2023-06-28 01:12:17 +00:00
|
|
|
|
|
|
|
const keyframes = React.useMemo(() => {
|
|
|
|
let keyframes = {}
|
|
|
|
rainbowColours.forEach((colour, idx) => {
|
2023-06-29 23:41:06 +00:00
|
|
|
keyframes[Math.round((idx * 100) / rainbowColours.length) + '%'] = {
|
|
|
|
backgroundColor: colour
|
|
|
|
}
|
2023-06-28 01:12:17 +00:00
|
|
|
})
|
2023-06-29 23:41:06 +00:00
|
|
|
keyframes['100%'] = { backgroundColor: rainbowColours[0] }
|
2023-06-28 01:12:17 +00:00
|
|
|
return keyframes
|
|
|
|
}, [rainbowColours])
|
|
|
|
|
|
|
|
if (props?.loaded) {
|
|
|
|
return props?.children
|
|
|
|
}
|
2023-06-29 23:41:06 +00:00
|
|
|
|
2023-06-28 01:12:17 +00:00
|
|
|
return (
|
|
|
|
<Flex
|
2023-06-29 23:41:06 +00:00
|
|
|
cursor='pointer'
|
|
|
|
w='10px'
|
|
|
|
h='8px'
|
|
|
|
borderRadius={'2px'}
|
|
|
|
bg={'rgba(0,0,0,0.1)'}
|
|
|
|
sx={{
|
|
|
|
'@keyframes placeholder-rainbow': keyframes,
|
|
|
|
'@keyframes placeholder-opacity': {
|
|
|
|
'0%': { opacity: 0.2 },
|
|
|
|
'100%': { opacity: 1 }
|
|
|
|
},
|
|
|
|
// add delay
|
|
|
|
animation: `placeholder-rainbow 3s infinite linear, placeholder-opacity 1.3s linear 0s infinite alternate none running}`
|
|
|
|
}}
|
2023-06-28 01:12:17 +00:00
|
|
|
{...props}
|
2023-06-29 23:41:06 +00:00
|
|
|
></Flex>
|
2023-06-28 01:12:17 +00:00
|
|
|
)
|
|
|
|
}
|