Skip to content

Commit ddcc621

Browse files
committed
set the status bar colors using js instead of scss
1 parent 8f26317 commit ddcc621

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed
Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,57 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
4-
import './status-bar.scss'
54

6-
const StatusBar = ({ statusArray, apiRequestStatus, addClass }) => (
7-
<div className={`container ${addClass}`}>
8-
<div className='row border bg-light'>
9-
{statusArray.map((statusObject, index) => {
10-
const { statusLabel, statusIcon } = statusObject
11-
return (
12-
<div
13-
className={`status-bar-column col-3 py-2 gap-2 d-flex justify-content-center align-items-center
14-
${index !== statusArray.length - 1 ? 'border-end' : ''}
15-
${statusLabel === apiRequestStatus ? 'active' : ''}`}
16-
key={statusLabel}
17-
>
18-
<FontAwesomeIcon icon={statusIcon} />
19-
{statusLabel}
20-
</div>
21-
)
22-
})}
5+
const StatusBar = ({ backgroundColor, statusArray, apiRequestStatus, addClass }) => {
6+
const activeIndex = statusArray.findIndex(obj => obj.statusLabel === apiRequestStatus)
7+
const labelBgColor = (index) => {
8+
if ((index < activeIndex) || (activeIndex === statusArray.length -1)) {
9+
return `bg-${backgroundColor}-3`
10+
} else if (index === activeIndex) {
11+
return `bg-${backgroundColor}`
12+
} else {
13+
return `bg-${backgroundColor}-7`
14+
}
15+
}
16+
17+
return (
18+
<div className={`container ${addClass}`}>
19+
<div className='row border'>
20+
{statusArray.map((statusObject, index) => {
21+
const { statusLabel, statusIcon } = statusObject
22+
// --bs-border-color: #dee2e6;
23+
const border = index !== statusArray.length - 1 ? 'border-end' : ''
24+
25+
console.log({ activeIndex, index, label: labelBgColor(index)})
26+
27+
return (
28+
<div
29+
className={`status-bar-column col-3 py-2 gap-2 d-flex justify-content-center align-items-center
30+
${border} ${labelBgColor(index)}`}
31+
key={statusLabel}
32+
>
33+
<FontAwesomeIcon icon={statusIcon} />
34+
{statusLabel}
35+
</div>
36+
)
37+
})}
38+
</div>
2339
</div>
24-
</div>
25-
)
40+
)
41+
}
2642

2743
StatusBar.propTypes = {
28-
statusArray: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
29-
apiRequestStatus: PropTypes.string.isRequired,
3044
addClass: PropTypes.string,
45+
apiRequestStatus: PropTypes.string.isRequired,
46+
// the webstore is currently configured to only accept 'light' or 'secondary' as the backgroundColor options.
47+
// we are not limiting the prop type to only those two strings because the webstore options may expand in the future.
48+
backgroundColor: PropTypes.string,
49+
statusArray: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
3150
}
3251

3352
StatusBar.defaultProps = {
3453
addClass: '',
54+
backgroundColor: 'light',
3555
}
3656

3757
export default StatusBar

src/components/StatusBar/StatusBar.stories.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@ export const SupplierReview = Template.bind({})
1313
SupplierReview.args = {
1414
statusArray,
1515
apiRequestStatus: 'Supplier Review',
16+
backgroundColor: 'light',
1617
}
1718

1819
export const SOWSelection = Template.bind({})
1920
SOWSelection.args = {
2021
statusArray,
2122
apiRequestStatus: 'SOW Selection',
23+
backgroundColor: 'light',
2224
}
2325

2426
export const WorkStarted = Template.bind({})
2527
WorkStarted.args = {
2628
statusArray,
2729
apiRequestStatus: 'Work Started',
30+
backgroundColor: 'light',
2831
}
2932

3033
export const WorkCompleted = Template.bind({})
3134
WorkCompleted.args = {
3235
statusArray,
3336
apiRequestStatus: 'Work Completed',
37+
backgroundColor: 'light',
3438
}

src/components/StatusBar/status-bar.scss

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)