Skip to content

Commit

Permalink
Change to children
Browse files Browse the repository at this point in the history
  • Loading branch information
cesalberca committed Aug 1, 2024
1 parent 5d6af23 commit cdd870c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/core/components/scramble-list/scramble-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const ScrambleList: FC<Props> = ({ texts }) => {
exit={{ opacity: 0 }}
transition={{ duration: 0.5 }}
>
<ScrambleText text={texts[currentIndex]} onComplete={handleComplete} />
<ScrambleText fixedWidth onComplete={handleComplete}>
{texts[currentIndex]}
</ScrambleText>
</motion.div>
)
}
12 changes: 9 additions & 3 deletions src/core/components/scramble-text/scramble-text.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import React, { type FC, useState } from 'react'
import { type FC, useState, type PropsWithChildren, Children } from 'react'
import { motion } from 'framer-motion'
import { getRandomString } from '@/core/utils/get-random-string'
import { useInterval } from '@/core/hooks/use-interval'
Expand All @@ -11,13 +11,19 @@ const SHUFFLE_TIME = 50
const DELAY_TIME = 1000

interface Props {
text: string
repeat?: boolean
onComplete?: () => void
fixedWidth?: boolean
}

export const ScrambleText: FC<Props> = ({ text, onComplete, repeat = false, fixedWidth = false }) => {
export const ScrambleText: FC<PropsWithChildren<Props>> = ({
children,
onComplete,
repeat = false,
fixedWidth = false,
}) => {
const text = Children.toArray(children).join('')

const [stateText, setStateText] = useState(text)
const [position, setPosition] = useState(0)
const [stopInterval, setStopInterval] = useState(false)
Expand Down

0 comments on commit cdd870c

Please sign in to comment.