Skip to content

Commit 2e2fd9a

Browse files
committed
dynamically set the bg color of the request items in the request list
1 parent ffd15a4 commit 2e2fd9a

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/compounds/RequestItem/RequestItem.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import TextBox from '../../components/TextBox/TextBox'
66
import Title from '../../components/Title/Title'
77
import './request-item.scss'
88

9-
const RequestItem = React.forwardRef(({ index, request }, ref) => {
9+
const RequestItem = React.forwardRef(({ backgroundColor, index, request }, ref) => {
1010
const { createdAt, description, href, img, title, status, updatedAt } = request
11-
const { backgroundColor, text, textColor } = status
11+
const { text, textColor } = status
1212
const image = { ...img, height: 70, width: 70 }
13+
const bg = index % 2 === 0 ? `bg-${backgroundColor}` : `bg-${backgroundColor}-2`
1314

1415
return (
1516
<article
16-
className={`request-item p-3 d-flex flex-column flex-md-row justify-content-between gap-3 bg-light
17-
${index % 2 === 0 ? ' bg-light' : ' bg-light-2'}`}
17+
className={`request-item p-3 d-flex flex-column flex-md-row justify-content-between gap-3 ${bg}`}
1818
>
1919
<div className='d-flex flex-column flex-sm-row gap-3 request-item-details'>
2020
<Image {...image} addClass='align-self-md-center' />
@@ -25,9 +25,9 @@ const RequestItem = React.forwardRef(({ index, request }, ref) => {
2525
<TextBox text={description} />
2626
</div>
2727
</div>
28-
<div className='status bg-light-3 p-2 rounded mt-4 mt-md-0'>
28+
<div className={`status bg-${backgroundColor}-3 p-2 rounded mt-4 mt-md-0`}>
2929
<Badge
30-
backgroundColor={backgroundColor}
30+
backgroundColor={status.backgroundColor}
3131
text={text}
3232
textColor={textColor}
3333
addClass='mb-2'
@@ -50,11 +50,13 @@ export const requestPropTypes = {
5050
}
5151

5252
RequestItem.propTypes = {
53+
backgroundColor: PropTypes.string,
5354
index: PropTypes.number,
5455
request: PropTypes.shape(requestPropTypes).isRequired,
5556
}
5657

5758
RequestItem.defaultProps = {
59+
backgroundColor: 'light',
5860
index: null,
5961
}
6062

src/compounds/RequestList/RequestList.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ import PropTypes from 'prop-types'
44
import Title from '../../components/Title/Title'
55
import RequestItem, { requestPropTypes } from '../RequestItem/RequestItem'
66

7-
const RequestList = ({ requests }) => (
7+
const RequestList = ({ backgroundColor, requests }) => (
88
<>
99
<Title title='My Requests' size='medium' />
1010
<div className='rounded overflow-hidden mb-4'>
1111
{requests.map((req, index) => (
1212
<Link key={req.id} href={`${req.href}`} passHref legacyBehavior>
13-
<RequestItem request={req} index={index} />
13+
<RequestItem request={req} index={index} backgroundColor={backgroundColor} />
1414
</Link>
1515
))}
1616
</div>
1717
</>
1818
)
1919

2020
RequestList.propTypes = {
21+
backgroundColor: PropTypes.string,
2122
requests: PropTypes.arrayOf(PropTypes.shape(requestPropTypes)).isRequired,
2223
}
2324

25+
RequestList.defaultProps = {
26+
backgroundColor: 'light'
27+
}
28+
2429
export default RequestList

src/compounds/RequestList/RequestList.stories.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,37 @@ Default.args = {
4141
},
4242
],
4343
}
44+
45+
export const Alternate = Template.bind({})
46+
Alternate.args = {
47+
backgroundColor: 'secondary',
48+
requests: [
49+
{
50+
createdAt: 'September 9, 2022',
51+
description: 'Does the Company offer services related to Flow Cytometry?',
52+
href: '/request/F575C4',
53+
id: 1,
54+
img: defaultImage,
55+
status: {
56+
text: 'Vendor Review',
57+
},
58+
title: 'F575C4: Assay Depot Coffee Mug',
59+
updatedAt: 'September 9, 2022 at 9:21 am',
60+
},
61+
{
62+
createdAt: 'November 15, 2022',
63+
// eslint-disable-next-line max-len
64+
description: 'General Information When do you plan to work with this supplier? Urgently Name of supplier: Alisha Supplier web address: http://scientist.com Is this new supplier onboarding request related to any of the following areas: Research area: In Vivo Contact Information Supplier contact name: Alisha Evans Supplier email a...',
65+
href: '/request/706D8F',
66+
id: 2,
67+
img: defaultImage,
68+
status: {
69+
backgroundColor: '#DEAF17',
70+
text: 'Work In Progress',
71+
textColor: '#FFFFFF',
72+
},
73+
title: '706D8F: CRISPR',
74+
updatedAt: 'November 16, 2022 at 4:45 pm',
75+
},
76+
],
77+
}

0 commit comments

Comments
 (0)