fleet/frontend/components/Icon/Icon.tsx
Marko Lisica 8162d052bf
Icons improvements (making frontend consistent with Figma component library) (#14185)
# 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>
2023-10-31 16:06:38 +00:00

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;