({ value, ...props }: { value?: number | null } & TextProps)
| 3 | import { isNumber } from "lodash-es"; |
| 4 | |
| 5 | const ColoredPercent = ({ value, ...props }: { value?: number | null } & TextProps) => { |
| 6 | const [passColor, neutralColor, failColor] = useToken("colors", [ |
| 7 | "green.600", |
| 8 | "gray.600", |
| 9 | "red.600", |
| 10 | ]); |
| 11 | |
| 12 | const scale = chroma.scale([failColor, neutralColor, passColor]).domain([0, 0.5, 1]); |
| 13 | |
| 14 | return isNumber(value) ? ( |
| 15 | <Text color={scale(value).hex()} fontWeight="bold" {...props}> |
| 16 | {(value * 100).toFixed(1)}% |
| 17 | </Text> |
| 18 | ) : null; |
| 19 | }; |
| 20 | |
| 21 | export default ColoredPercent; |
nothing calls this directly
no outgoing calls
no test coverage detected