mirror of
https://github.com/fleetdm/fleet
synced 2026-05-18 22:49:19 +00:00
# Checklist for submitter If some of the following don't apply, delete the relevant line. - [ ] Manual QA for all new/changed functionality --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import React, { useMemo } from "react";
|
|
import classnames from "classnames";
|
|
|
|
import { IconNames, ICON_MAP } from "components/icons";
|
|
import { Colors } from "styles/var/colors";
|
|
import { IconSizes } from "styles/var/icon_sizes";
|
|
|
|
interface IIconProps {
|
|
name: IconNames;
|
|
color?: Colors;
|
|
className?: string;
|
|
size?: IconSizes;
|
|
}
|
|
|
|
const baseClass = "icon";
|
|
|
|
const Icon = ({ name, color, className, size }: IIconProps) => {
|
|
const classNames = classnames(baseClass, className);
|
|
|
|
// createPassedProps creates a props object that we pass to the specific icon
|
|
// for values that are not null or undefined
|
|
const props = useMemo(() => {
|
|
const createPassedProps = () => {
|
|
return Object.assign(
|
|
{},
|
|
color === undefined ? undefined : { color },
|
|
size === undefined ? undefined : { size }
|
|
);
|
|
};
|
|
|
|
return createPassedProps();
|
|
}, [color, size]);
|
|
|
|
const IconComponent = ICON_MAP[name];
|
|
|
|
return (
|
|
<div className={classNames} data-testid={`${name}-icon`}>
|
|
<IconComponent {...props} />
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Icon;
|