Rev 2893 | Rev 2895 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useState, useCallback } from 'react'
import { Typography } from '@mui/material'
import { parse } from '@utils'
export default function FeedDescription({ description = '' }) {
const [showMore, setShowMore] = useState(false)
const maxLength = 300
const parsedText = useCallback(parse(description ?? ''), [description])
const truncatedText = parsedText.slice(0, maxLength)
const isTruncated = parsedText.length > maxLength
const toggleShowMore = useCallback(
() => setShowMore((prevState) => !prevState),
[]
)
return (
<Typography onClick={toggleShowMore}>
{showMore ? parsedText : truncatedText}
{isTruncated && (
<Typography
onClick={toggleShowMore}
variant='body2'
color='primary'
sx={{ cursor: 'pointer' }}
aria-expanded={showMore}
>
{showMore ? ' Mostrar menos' : '... Mostrar más'}
</Typography>
)}
</Typography>
)
}