2023-05-01 07:51:00 +09:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2023-10-25 02:45:08 +09:00
|
|
|
import { ReactComponent as CheckBoxOutlineBlankIcon } from '@material-symbols/svg-600/outlined/check_box_outline_blank.svg';
|
|
|
|
|
|
|
|
interface SVGPropsWithTitle extends React.SVGProps<SVGSVGElement> {
|
|
|
|
title?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type IconProp = React.FC<SVGPropsWithTitle>;
|
|
|
|
|
|
|
|
interface Props extends React.SVGProps<SVGSVGElement> {
|
2023-05-01 07:51:00 +09:00
|
|
|
children?: never;
|
2023-10-25 02:45:08 +09:00
|
|
|
id: string;
|
|
|
|
icon: IconProp;
|
|
|
|
title?: string;
|
2023-05-10 19:59:29 +09:00
|
|
|
}
|
|
|
|
|
2023-05-10 06:41:18 +09:00
|
|
|
export const Icon: React.FC<Props> = ({
|
|
|
|
id,
|
2023-10-25 02:45:08 +09:00
|
|
|
icon: IconComponent,
|
2023-05-10 06:41:18 +09:00
|
|
|
className,
|
2023-10-25 02:45:08 +09:00
|
|
|
title: titleProp,
|
2023-05-10 06:41:18 +09:00
|
|
|
...other
|
2023-10-25 02:45:08 +09:00
|
|
|
}) => {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
if (!IconComponent) {
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
throw new Error(`<Icon id="${id}"> is missing an "icon" prop.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
IconComponent = CheckBoxOutlineBlankIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ariaHidden = titleProp ? undefined : true;
|
|
|
|
const role = !ariaHidden ? 'img' : undefined;
|
|
|
|
|
|
|
|
// Set the title to an empty string to remove the built-in SVG one if any
|
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
|
|
const title = titleProp || '';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<IconComponent
|
|
|
|
className={classNames('icon', `icon-${id}`, className)}
|
|
|
|
title={title}
|
|
|
|
aria-hidden={ariaHidden}
|
|
|
|
role={role}
|
|
|
|
{...other}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|