Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/compounds/Item/CardBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Card, Collapse } from 'react-bootstrap'
import NextLink from '../../components/NextLink/NextLink'
import LinkedButton from '../LinkedButton/LinkedButton'

const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, withButtonLink, withTitleLink }) => {
const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, truncatedLength, orientation, titleLink, withButtonLink, withTitleLink }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about changing this variable name to truncateAt? feels a little more semantic.

also, can you move this to after "titleLink"? the variables are alphabetized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summer called it cutOffIndex. Do you think it makes sense to use that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like truncateAt is even more semantic than cutOffIndex...but I'm fine with either.

const { id, description, name, snippet } = item
const [open, setOpen] = useState(false)

Expand All @@ -26,13 +26,13 @@ const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated,
</Card.Title>
{orientation === 'horizontal' ? (
<>
<div className='fw-light mh-300 overflow-auto mt-3'>
<div className='fw-light mh-300 overflow-auto mt-3 testing'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div className='fw-light mh-300 overflow-auto mt-3 testing'>
<div className='fw-light mh-300 overflow-auto mt-3'>

{markdownDescriptionTruncated}
<Collapse in={open}>
<div className='fw-light'>{markdownDescriptionExtended}</div>
</Collapse>
</div>
{description?.length > 300 && (
{description?.length > truncatedLength && (
<Button variant="link" onClick={() => setOpen(!open)} className="p-0 mt-3">
{open ? ' Show less' : ' Read more'}
</Button>
Expand Down Expand Up @@ -86,6 +86,7 @@ CardBody.propTypes = {
PropTypes.string,
PropTypes.elementType,
]),
truncatedLength: PropTypes.number,
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
titleLink: PropTypes.string,
withButtonLink: PropTypes.bool,
Expand All @@ -100,6 +101,7 @@ CardBody.defaultProps = {
},
markdownDescriptionTruncated: '',
markdownDescriptionExtended: '',
truncatedLength: 300,
orientation: 'vertical',
titleLink: '',
withButtonLink: false,
Expand Down
6 changes: 4 additions & 2 deletions src/compounds/Item/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import ItemLoading from './ItemLoading'
import NextLink from '../../components/NextLink/NextLink'
import './item.scss'

const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, withButtonLink,
withTitleLink, width }) => {
const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, truncatedLength, href, isLoading, item, orientation, titleLink,
withButtonLink, withTitleLink, width }) => {
if (isLoading) {
return (
<>
Expand Down Expand Up @@ -49,6 +49,7 @@ const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownD
markdownDescriptionExtended={markdownDescriptionExtended}
orientation={orientation}
titleLink={link}
truncatedLength={truncatedLength}
withButtonLink={withButtonLink}
withTitleLink={withTitleLink}
/>
Expand All @@ -69,6 +70,7 @@ const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownD
item={item}
markdownDescriptionTruncated={markdownDescriptionTruncated}
markdownDescriptionExtended={markdownDescriptionExtended}
truncatedLength={truncatedLength}
orientation={orientation}
titleLink={link}
withButtonLink={withButtonLink}
Expand Down
30 changes: 29 additions & 1 deletion src/compounds/Item/Item.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,42 @@ Default.args = {
},
name: 'Microbiological Sterility Testing',
slug: 'microbiological-sterility-testing',
snippet: ''
},
titleLink: '/',
orientation: 'vertical',
style: {},
withButtonLink: false,
withTitleLink: false,
markdownDescriptionTruncated: null,
markdownDescriptionExtended: null
}

export const Horizontal = Template.bind({})
Horizontal.args = {
buttonLink: '/',
buttonProps: {
backgroundColor: '#A9A9A9',
label: 'Request this item',
},
item: {
description: '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. 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.',
id: 1,
img: {
src: item,
alt: 'Several rows of test tubes with a liquid being put into one.',
},
name: 'Microbiological Sterility Testing',
slug: 'microbiological-sterility-testing',
},
titleLink: '/',
orientation: 'horizontal',
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.'
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.',
truncatedLength: 300
}

export const isLoading = Template.bind({})
Expand Down