Total Complexity | 2 |
Complexity/F | 0 |
Lines of Code | 53 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from "react"; |
||
2 | |||
3 | export enum IconStatus { |
||
4 | ASSESSMENT = "fas fa-question-circle", |
||
5 | COMPLETE = "fas fa-check-circle", |
||
6 | DEFAULT = "far fa-circle", |
||
7 | ERROR = "fas fa-exclamation-circle", |
||
8 | READY = "fas fa-check-circle", |
||
9 | RECEIVED = "fas fa-exclamation-circle", |
||
10 | } |
||
11 | |||
12 | interface StatusIconProps { |
||
13 | /* Clone string for color definition, i.e. "slow" or "c1". |
||
14 | Defaults are built-in based on status but can be overridden. */ |
||
15 | color?: string; |
||
16 | /* Clone font size setting, i.e. "small" or "h4". */ |
||
17 | size: string; |
||
18 | /* Enum for status, exported from component file. */ |
||
19 | status: IconStatus; |
||
20 | } |
||
21 | |||
22 | const StatusIcon: React.FC<StatusIconProps> = ({ |
||
23 | color, |
||
24 | size, |
||
25 | status, |
||
26 | }): React.ReactElement => { |
||
27 | let defaultColor: string; |
||
28 | if (color === undefined) { |
||
29 | switch (status) { |
||
30 | case IconStatus.COMPLETE: |
||
31 | case IconStatus.READY: |
||
32 | defaultColor = "go"; |
||
33 | break; |
||
34 | case IconStatus.ERROR: |
||
35 | defaultColor = "stop"; |
||
36 | break; |
||
37 | case IconStatus.ASSESSMENT: |
||
38 | defaultColor = "slow"; |
||
39 | break; |
||
40 | default: |
||
41 | defaultColor = "c1"; |
||
42 | } |
||
43 | } else { |
||
44 | defaultColor = color; |
||
45 | } |
||
46 | |||
47 | return ( |
||
48 | <i className={status} data-c-color={defaultColor} data-c-font-size={size} /> |
||
49 | ); |
||
50 | }; |
||
51 | |||
52 | export default StatusIcon; |
||
53 |