Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3032 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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