index.community/frontend/src/components/atoms/InstanceType.tsx

28 lines
890 B
TypeScript
Raw Normal View History

2019-07-24 16:25:20 +00:00
import { Icon } from "@blueprintjs/core";
import { IconNames } from "@blueprintjs/icons";
import React from "react";
import { QUALITATIVE_COLOR_SCHEME } from "../../constants";
import { typeColorScheme } from "../../types";
import { getTypeDisplayString } from "../../util";
2019-07-24 16:25:20 +00:00
2020-05-19 13:45:27 +00:00
interface InstanceTypeProps {
2019-07-24 16:25:20 +00:00
type: string;
colorAfterName?: boolean;
}
/**
* By default, renders the color followed by the name of the instance type.
* You can change this by passing `colorAfterName={true}`.
*/
2020-05-19 13:45:27 +00:00
const InstanceType: React.FC<InstanceTypeProps> = ({ type, colorAfterName }) => {
2019-07-24 16:25:20 +00:00
const idx = typeColorScheme.values.indexOf(type);
2020-05-19 13:45:27 +00:00
const name = ` ${getTypeDisplayString(type)}`;
2019-07-24 16:25:20 +00:00
return (
<>
{!!colorAfterName && name}
<Icon icon={IconNames.SYMBOL_CIRCLE} color={QUALITATIVE_COLOR_SCHEME[idx]} />
{!colorAfterName && name}
</>
);
};
export default InstanceType;