|
| 1 | +/** |
| 2 | + * RAG Status Icon Component |
| 3 | + * |
| 4 | + * Displays a Red/Amber/Green status as an SVG circle with a white letter. |
| 5 | + * Designed to match the size of SPC icons for visual consistency. |
| 6 | + */ |
| 7 | +import React from "react"; |
| 8 | + |
| 9 | +export type RAGStatus = "Red" | "Amber" | "Green" | undefined | null; |
| 10 | + |
| 11 | +export interface RAGStatusIconProps { |
| 12 | + /** The RAG status to display */ |
| 13 | + status: RAGStatus; |
| 14 | + /** Size in pixels (default: 64 to match SPC icons) */ |
| 15 | + size?: number; |
| 16 | + /** Optional className */ |
| 17 | + className?: string; |
| 18 | +} |
| 19 | + |
| 20 | +const STATUS_COLORS: Record<string, string> = { |
| 21 | + Red: "#d5281b", // NHS Red |
| 22 | + Amber: "#ffb81c", // NHS Warm Yellow (Amber) |
| 23 | + Green: "#007f3b", // NHS Green |
| 24 | +}; |
| 25 | + |
| 26 | +const STATUS_LETTERS: Record<string, string> = { |
| 27 | + Red: "R", |
| 28 | + Amber: "A", |
| 29 | + Green: "G", |
| 30 | +}; |
| 31 | + |
| 32 | +export const RAGStatusIcon: React.FC<RAGStatusIconProps> = ({ |
| 33 | + status, |
| 34 | + size = 64, |
| 35 | + className, |
| 36 | +}) => { |
| 37 | + // If no valid status, show a neutral placeholder |
| 38 | + if (!status || !STATUS_COLORS[status]) { |
| 39 | + return ( |
| 40 | + <svg |
| 41 | + width={size} |
| 42 | + height={size} |
| 43 | + viewBox="0 0 64 64" |
| 44 | + className={className} |
| 45 | + aria-label="No status" |
| 46 | + role="img" |
| 47 | + > |
| 48 | + <circle |
| 49 | + cx="32" |
| 50 | + cy="32" |
| 51 | + r="28" |
| 52 | + fill="#aeb7bd" |
| 53 | + stroke="#768692" |
| 54 | + strokeWidth="2" |
| 55 | + /> |
| 56 | + <text |
| 57 | + x="32" |
| 58 | + y="32" |
| 59 | + textAnchor="middle" |
| 60 | + dominantBaseline="central" |
| 61 | + fill="white" |
| 62 | + fontSize="28" |
| 63 | + fontWeight="bold" |
| 64 | + fontFamily="Arial, sans-serif" |
| 65 | + > |
| 66 | + – |
| 67 | + </text> |
| 68 | + </svg> |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + const color = STATUS_COLORS[status]; |
| 73 | + const letter = STATUS_LETTERS[status]; |
| 74 | + |
| 75 | + return ( |
| 76 | + <svg |
| 77 | + width={size} |
| 78 | + height={size} |
| 79 | + viewBox="0 0 64 64" |
| 80 | + className={className} |
| 81 | + aria-label={`Status: ${status}`} |
| 82 | + role="img" |
| 83 | + > |
| 84 | + <circle |
| 85 | + cx="32" |
| 86 | + cy="32" |
| 87 | + r="28" |
| 88 | + fill={color} |
| 89 | + stroke={color} |
| 90 | + strokeWidth="2" |
| 91 | + /> |
| 92 | + <text |
| 93 | + x="32" |
| 94 | + y="32" |
| 95 | + textAnchor="middle" |
| 96 | + dominantBaseline="central" |
| 97 | + fill="white" |
| 98 | + fontSize="28" |
| 99 | + fontWeight="bold" |
| 100 | + fontFamily="Arial, sans-serif" |
| 101 | + > |
| 102 | + {letter} |
| 103 | + </text> |
| 104 | + </svg> |
| 105 | + ); |
| 106 | +}; |
| 107 | + |
| 108 | +export default RAGStatusIcon; |
0 commit comments