diff --git a/src/compounds/Item/CardBody.jsx b/src/compounds/Item/CardBody.jsx index e02c93d..6815261 100644 --- a/src/compounds/Item/CardBody.jsx +++ b/src/compounds/Item/CardBody.jsx @@ -4,19 +4,10 @@ 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 CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, withButtonLink, withTitleLink }) => { + const { id, description, name, snippet } = 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 (
@@ -33,21 +24,25 @@ const CardBody = ({ buttonLink, buttonProps, item, name )} - {description && ( - <> -
- {truncated} - -
{description.slice(cutOffIndex).trimStart()}
-
-
- {description.length > 300 && ( - + {orientation === 'horizontal' ? ( + <> +
+ {markdownDescriptionTruncated} + +
{markdownDescriptionExtended}
+
+
+ {description?.length > 300 && ( + + )} + + ) : ( +
+ {snippet} +
)} - - )}
{(withButtonLink) && (
@@ -83,6 +78,14 @@ CardBody.propTypes = { name: PropTypes.string.isRequired, slug: PropTypes.string, }), + markdownDescriptionTruncated: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.elementType, + ]), + markdownDescriptionExtended: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.elementType, + ]), orientation: PropTypes.oneOf(['horizontal', 'vertical']), titleLink: PropTypes.string, withButtonLink: PropTypes.bool, @@ -95,6 +98,8 @@ CardBody.defaultProps = { item: { description: '', }, + markdownDescriptionTruncated: '', + markdownDescriptionExtended: '', orientation: 'vertical', titleLink: '', withButtonLink: false, diff --git a/src/compounds/Item/Item.jsx b/src/compounds/Item/Item.jsx index 035096c..65ee165 100644 --- a/src/compounds/Item/Item.jsx +++ b/src/compounds/Item/Item.jsx @@ -8,7 +8,7 @@ import ItemLoading from './ItemLoading' import NextLink from '../../components/NextLink/NextLink' import './item.scss' -const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, titleLink, withButtonLink, +const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, withButtonLink, withTitleLink, width }) => { if (isLoading) { return ( @@ -45,6 +45,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit buttonLink={link} buttonProps={buttonProps} item={item} + markdownDescriptionTruncated={markdownDescriptionTruncated} + markdownDescriptionExtended={markdownDescriptionExtended} orientation={orientation} titleLink={link} withButtonLink={withButtonLink} @@ -65,6 +67,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit buttonLink={link} buttonProps={buttonProps} item={item} + markdownDescriptionTruncated={markdownDescriptionTruncated} + markdownDescriptionExtended={markdownDescriptionExtended} orientation={orientation} titleLink={link} withButtonLink={withButtonLink} diff --git a/src/compounds/Item/Item.stories.jsx b/src/compounds/Item/Item.stories.jsx index 90d6910..53cb3a9 100644 --- a/src/compounds/Item/Item.stories.jsx +++ b/src/compounds/Item/Item.stories.jsx @@ -31,6 +31,8 @@ Default.args = { style: {}, withButtonLink: false, withTitleLink: false, + markdownDescriptionTruncated: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', + markdownDescriptionExtended: ' Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.' } export const isLoading = Template.bind({})