Skip to content

Commit f15906f

Browse files
authored
Merge pull request #225 from scientist-softserv/iphenovista71-add-truncated-length-to-cardbody
add truncatedLength as an option to card body
2 parents 29abe00 + 7de0610 commit f15906f

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/compounds/Item/CardBody.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button, Card, Collapse } from 'react-bootstrap'
44
import NextLink from '../../components/NextLink/NextLink'
55
import LinkedButton from '../LinkedButton/LinkedButton'
66

7-
const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, withButtonLink, withTitleLink }) => {
7+
const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, truncateAt, withButtonLink, withTitleLink }) => {
88
const { id, description, name, snippet } = item
99
const [open, setOpen] = useState(false)
1010

@@ -32,7 +32,7 @@ const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated,
3232
<div className='fw-light'>{markdownDescriptionExtended}</div>
3333
</Collapse>
3434
</div>
35-
{description?.length > 300 && (
35+
{description?.length > truncateAt && (
3636
<Button variant="link" onClick={() => setOpen(!open)} className="p-0 mt-3">
3737
{open ? ' Show less' : ' Read more'}
3838
</Button>
@@ -86,6 +86,7 @@ CardBody.propTypes = {
8686
PropTypes.string,
8787
PropTypes.elementType,
8888
]),
89+
truncateAt: PropTypes.number,
8990
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
9091
titleLink: PropTypes.string,
9192
withButtonLink: PropTypes.bool,
@@ -100,6 +101,7 @@ CardBody.defaultProps = {
100101
},
101102
markdownDescriptionTruncated: '',
102103
markdownDescriptionExtended: '',
104+
truncateAt: 300,
103105
orientation: 'vertical',
104106
titleLink: '',
105107
withButtonLink: false,

src/compounds/Item/Item.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import ItemLoading from './ItemLoading'
88
import NextLink from '../../components/NextLink/NextLink'
99
import './item.scss'
1010

11-
const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, withButtonLink,
12-
withTitleLink, width }) => {
11+
const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, truncateAt,
12+
withButtonLink, withTitleLink, width }) => {
1313
if (isLoading) {
1414
return (
1515
<>
@@ -49,6 +49,7 @@ const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownD
4949
markdownDescriptionExtended={markdownDescriptionExtended}
5050
orientation={orientation}
5151
titleLink={link}
52+
truncateAt={truncateAt}
5253
withButtonLink={withButtonLink}
5354
withTitleLink={withTitleLink}
5455
/>
@@ -69,6 +70,7 @@ const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownD
6970
item={item}
7071
markdownDescriptionTruncated={markdownDescriptionTruncated}
7172
markdownDescriptionExtended={markdownDescriptionExtended}
73+
truncateAt={truncateAt}
7274
orientation={orientation}
7375
titleLink={link}
7476
withButtonLink={withButtonLink}

src/compounds/Item/Item.stories.jsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,42 @@ Default.args = {
2525
},
2626
name: 'Microbiological Sterility Testing',
2727
slug: 'microbiological-sterility-testing',
28+
snippet: ''
2829
},
2930
titleLink: '/',
3031
orientation: 'vertical',
3132
style: {},
3233
withButtonLink: false,
3334
withTitleLink: false,
35+
markdownDescriptionTruncated: null,
36+
markdownDescriptionExtended: null
37+
}
38+
39+
export const Horizontal = Template.bind({})
40+
Horizontal.args = {
41+
buttonLink: '/',
42+
buttonProps: {
43+
backgroundColor: '#A9A9A9',
44+
label: 'Request this item',
45+
},
46+
item: {
47+
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.',
48+
id: 1,
49+
img: {
50+
src: item,
51+
alt: 'Several rows of test tubes with a liquid being put into one.',
52+
},
53+
name: 'Microbiological Sterility Testing',
54+
slug: 'microbiological-sterility-testing',
55+
},
56+
titleLink: '/',
57+
orientation: 'horizontal',
58+
style: {},
59+
withButtonLink: false,
60+
withTitleLink: false,
3461
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.',
35-
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.'
62+
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.',
63+
truncateAt: 300
3664
}
3765

3866
export const isLoading = Template.bind({})

0 commit comments

Comments
 (0)