soapbox/app/soapbox/components/ui/icon/icon.tsx

34 wiersze
909 B
TypeScript
Czysty Zwykły widok Historia

2022-03-21 18:09:01 +00:00
import React from 'react';
2022-04-28 21:29:15 +00:00
import Counter from '../counter/counter';
import SvgIcon from './svg-icon';
2022-03-21 18:09:01 +00:00
2022-04-12 13:50:39 +00:00
interface IIcon extends Pick<React.SVGAttributes<SVGAElement>, 'strokeWidth'> {
/** Class name for the <svg> element. */
2022-03-21 18:09:01 +00:00
className?: string,
/** Number to display a counter over the icon. */
2022-03-21 18:09:01 +00:00
count?: number,
/** Tooltip text for the icon. */
2022-03-21 18:09:01 +00:00
alt?: string,
/** URL to the svg icon. */
2022-03-21 18:09:01 +00:00
src: string,
/** Width and height of the icon in pixels. */
size?: number,
2022-03-21 18:09:01 +00:00
}
/** Renders and SVG icon with optional counter. */
const Icon: React.FC<IIcon> = ({ src, alt, count, size, ...filteredProps }): JSX.Element => (
2022-04-05 14:42:19 +00:00
<div className='relative' data-testid='icon'>
2022-04-04 19:05:15 +00:00
{count ? (
2022-04-28 21:29:15 +00:00
<span className='absolute -top-2 -right-3'>
<Counter count={count} />
2022-04-04 19:05:15 +00:00
</span>
) : null}
2022-03-21 18:09:01 +00:00
<SvgIcon src={src} size={size} alt={alt} {...filteredProps} />
2022-04-04 19:05:15 +00:00
</div>
);
2022-03-21 18:09:01 +00:00
export default Icon;