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

41 wiersze
1.2 KiB
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. */
className?: string
/** Number to display a counter over the icon. */
count?: number
/** Optional max to cap count (ie: N+) */
countMax?: number
/** Tooltip text for the icon. */
alt?: string
/** URL to the svg icon. */
src: string
/** Width and height of the icon in pixels. */
size?: number
2023-05-12 15:51:00 +00:00
/** Override the data-testid */
'data-testid'?: string
2022-03-21 18:09:01 +00:00
}
/** Renders and SVG icon with optional counter. */
const Icon: React.FC<IIcon> = ({ src, alt, count, size, countMax, ...filteredProps }): JSX.Element => (
2023-05-12 15:51:00 +00:00
<div
className='relative flex shrink-0 flex-col'
data-testid={filteredProps['data-testid'] || 'icon'}
>
2022-04-04 19:05:15 +00:00
{count ? (
<span className='absolute -right-3 -top-2 flex h-5 min-w-[20px] shrink-0 items-center justify-center whitespace-nowrap break-words'>
<Counter count={count} countMax={countMax} />
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;