diff --git a/src/compounds/Item/CardBody.jsx b/src/compounds/Item/CardBody.jsx index 2c44d04..0346b90 100644 --- a/src/compounds/Item/CardBody.jsx +++ b/src/compounds/Item/CardBody.jsx @@ -1,13 +1,22 @@ -import React from 'react' +import React, { useState } from 'react' import PropTypes from 'prop-types' -import { Card } from 'react-bootstrap' +import { Button, Card, Collapse } from 'react-bootstrap' import NextLink from '../../components/NextLink/NextLink' import LinkedButton from '../LinkedButton/LinkedButton' const CardBody = ({ buttonLink, buttonProps, item, orientation, titleLink, withButtonLink, withTitleLink }) => { - const { id, description, name } = item + const { id, description = '', name } = item + const [open, setOpen] = useState(false) + const truncateDescription = (desc, maxLength, isOpen) => { + if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length }; + const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' '); + const ellipsis = isOpen ? '' : '...'; + return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex }; + } + + const { truncated, cutOffIndex } = truncateDescription(description, 300, open) return (
@@ -25,9 +34,19 @@ const CardBody = ({ buttonLink, buttonProps, item, )} {description && ( - - {description} - + <> +
+ {truncated} + +
{description.slice(cutOffIndex).trimStart()}
+
+
+ {description.length > 300 && ( + + )} + )}
{(withButtonLink) && ( diff --git a/src/compounds/Item/item.scss b/src/compounds/Item/item.scss index 76b02d0..598a261 100644 --- a/src/compounds/Item/item.scss +++ b/src/compounds/Item/item.scss @@ -12,3 +12,7 @@ opacity: .8; } +.mh-300 { + max-height: 300px; +} +