2023-08-14 01:34:50 +00:00
|
|
|
import React from "react"
|
|
|
|
import { Box } from "@chakra-ui/react"
|
2023-06-27 01:18:08 +00:00
|
|
|
|
2023-08-14 01:34:50 +00:00
|
|
|
import { RainbowText } from "./rainbowText"
|
|
|
|
|
|
|
|
export const TextAnimation1 = (props) => {
|
2023-06-27 01:18:08 +00:00
|
|
|
const texts = React.useMemo(() => {
|
2023-11-08 06:27:12 +00:00
|
|
|
if (props?.texts?.length) {
|
|
|
|
return props?.texts
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:18:08 +00:00
|
|
|
return [
|
2023-08-14 01:34:50 +00:00
|
|
|
"thingtime",
|
|
|
|
"vibrant",
|
|
|
|
"infinite",
|
|
|
|
"creative",
|
|
|
|
"powerful",
|
|
|
|
"magical",
|
|
|
|
"inspiring",
|
|
|
|
"love",
|
2023-06-28 07:53:34 +00:00
|
|
|
// 'tt'
|
2023-06-27 01:18:08 +00:00
|
|
|
]
|
2023-11-08 06:27:12 +00:00
|
|
|
}, [props?.texts])
|
2023-06-27 01:18:08 +00:00
|
|
|
|
|
|
|
const [titleText, setTitleText] = React.useState(texts[0])
|
|
|
|
|
2023-06-28 07:53:34 +00:00
|
|
|
const [usedTexts, setUsedTexts] = React.useState(["thingtime"])
|
|
|
|
|
|
|
|
const state = React.useRef({})
|
|
|
|
|
2023-06-27 01:18:08 +00:00
|
|
|
React.useEffect(() => {
|
2023-06-28 07:53:34 +00:00
|
|
|
state.current = { titleText, texts, usedTexts }
|
|
|
|
}, [titleText, texts, usedTexts])
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2023-08-14 01:34:50 +00:00
|
|
|
const newTimeout =
|
|
|
|
Math.random() * 1500 + 2500 + (titleText === "thingtime" ? 750 : 0)
|
2023-06-27 08:09:21 +00:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2023-06-28 07:53:34 +00:00
|
|
|
// choose an unused text or pick texts[0]
|
|
|
|
const usedTexts = state.current.usedTexts
|
2023-08-14 01:34:50 +00:00
|
|
|
const unusedTexts = texts.filter((text) => !usedTexts.includes(text))
|
2023-06-28 07:53:34 +00:00
|
|
|
// pick a random unused text
|
|
|
|
const randomIdx = Math.floor(Math.random() * unusedTexts.length)
|
|
|
|
const newText = unusedTexts.length > 0 ? unusedTexts[randomIdx] : texts[0]
|
|
|
|
if (!unusedTexts.length) {
|
|
|
|
setUsedTexts(["thingtime"])
|
|
|
|
} else {
|
|
|
|
setUsedTexts([...usedTexts, newText])
|
|
|
|
}
|
2023-06-27 01:18:08 +00:00
|
|
|
setTitleText(newText)
|
2023-06-27 08:09:21 +00:00
|
|
|
}, newTimeout)
|
2023-06-28 07:53:34 +00:00
|
|
|
}, [titleText])
|
2023-06-27 01:18:08 +00:00
|
|
|
|
2023-11-08 06:27:12 +00:00
|
|
|
return <RainbowText ce={props?.ce}>{titleText}</RainbowText>
|
2023-06-27 01:18:08 +00:00
|
|
|
}
|