|
1 | 1 | import React from 'react'
|
2 | 2 | import PropTypes from 'prop-types'
|
3 | 3 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
4 |
| -import './status-bar.scss' |
5 | 4 |
|
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> |
23 | 39 | </div>
|
24 |
| - </div> |
25 |
| -) |
| 40 | + ) |
| 41 | +} |
26 | 42 |
|
27 | 43 | StatusBar.propTypes = {
|
28 |
| - statusArray: PropTypes.arrayOf(PropTypes.shape({})).isRequired, |
29 |
| - apiRequestStatus: PropTypes.string.isRequired, |
30 | 44 | 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, |
31 | 50 | }
|
32 | 51 |
|
33 | 52 | StatusBar.defaultProps = {
|
34 | 53 | addClass: '',
|
| 54 | + backgroundColor: 'light', |
35 | 55 | }
|
36 | 56 |
|
37 | 57 | export default StatusBar
|
0 commit comments