2022-03-21 11:09:01 -07:00
|
|
|
import React from 'react';
|
2022-04-07 11:47:06 -07:00
|
|
|
|
2022-04-28 14:29:15 -07:00
|
|
|
import Counter from '../counter/counter';
|
|
|
|
|
2022-04-07 11:47:06 -07:00
|
|
|
import SvgIcon from './svg-icon';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-04-12 06:50:39 -07:00
|
|
|
interface IIcon extends Pick<React.SVGAttributes<SVGAElement>, 'strokeWidth'> {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Class name for the <svg> element. */
|
2023-02-15 13:26:27 -08:00
|
|
|
className?: string
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Number to display a counter over the icon. */
|
2023-02-15 13:26:27 -08:00
|
|
|
count?: number
|
2022-11-03 09:48:17 -07:00
|
|
|
/** Optional max to cap count (ie: N+) */
|
2023-02-15 13:26:27 -08:00
|
|
|
countMax?: number
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Tooltip text for the icon. */
|
2023-02-15 13:26:27 -08:00
|
|
|
alt?: string
|
2022-04-30 21:39:58 -07:00
|
|
|
/** URL to the svg icon. */
|
2023-02-15 13:26:27 -08:00
|
|
|
src: string
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Width and height of the icon in pixels. */
|
2023-02-15 13:26:27 -08:00
|
|
|
size?: number
|
2023-05-12 08:51:00 -07:00
|
|
|
/** Override the data-testid */
|
|
|
|
'data-testid'?: string
|
2022-03-21 11:09:01 -07:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Renders and SVG icon with optional counter. */
|
2022-11-03 09:48:17 -07:00
|
|
|
const Icon: React.FC<IIcon> = ({ src, alt, count, size, countMax, ...filteredProps }): JSX.Element => (
|
2023-05-12 08:51:00 -07:00
|
|
|
<div
|
|
|
|
className='relative flex shrink-0 flex-col'
|
|
|
|
data-testid={filteredProps['data-testid'] || 'icon'}
|
|
|
|
>
|
2022-04-04 12:05:15 -07:00
|
|
|
{count ? (
|
2023-04-01 11:37:34 -07:00
|
|
|
<span className='absolute -right-3 -top-2 flex h-5 min-w-[20px] shrink-0 items-center justify-center whitespace-nowrap break-words'>
|
2022-11-03 09:48:17 -07:00
|
|
|
<Counter count={count} countMax={countMax} />
|
2022-04-04 12:05:15 -07:00
|
|
|
</span>
|
|
|
|
) : null}
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-04-07 11:47:06 -07:00
|
|
|
<SvgIcon src={src} size={size} alt={alt} {...filteredProps} />
|
2022-04-04 12:05:15 -07:00
|
|
|
</div>
|
|
|
|
);
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
export default Icon;
|