Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3032 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useState } from 'react';
2
import { Typography } from '@mui/material';
3
 
4
import { parse } from '@utils';
5
 
6
export default function FeedDescription({ description = '' }) {
7
  const [showMore, setShowMore] = useState(false);
8
 
9
  const stripText = description.replace(/<p>|<\/p>/g, '');
10
  const maxLength = 140;
11
  const truncatedText = stripText.slice(0, maxLength);
12
  const isTruncated = stripText.length > maxLength;
13
 
14
  const toggleShowMore = () => setShowMore((prevState) => !prevState);
15
 
16
  return (
17
    <Typography>
18
      {parse(showMore ? stripText : truncatedText)}
19
 
20
      {isTruncated && (
21
        <Typography
22
          onClick={toggleShowMore}
23
          variant='overline'
24
          color='primary'
25
          sx={{ cursor: 'pointer', display: 'inline-flex' }}
26
          aria-expanded={showMore}
27
        >
28
          {showMore ? ' Mostrar menos' : '... Mostrar más'}
29
        </Typography>
30
      )}
31
    </Typography>
32
  );
33
}