-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathimage.tsx
49 lines (45 loc) · 1.16 KB
/
image.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { DEFAULT_IMG_URL } from "util/stringUtils";
import { CSSProperties, RefObject } from "react";
import styled, { css } from "styled-components";
interface ImageStyleType {
border: string;
radius: string;
}
const getStyle = (style: ImageStyleType) => {
return css`
border: 1px solid ${style.border};
border-radius: ${style.radius};
`;
};
const StyledImg = styled.img<{ $style: ImageStyleType | undefined }>`
${(props) => props.$style && getStyle(props.$style)}
`;
export function TacoImage(props: {
src: string;
onClick?: () => void;
width?: number | string;
height?: number | string;
className?: string;
style?: CSSProperties;
imgRef?: RefObject<HTMLImageElement>;
$style?: ImageStyleType;
}) {
const { width, height, src, onClick, className, style, $style } = props;
return (
<StyledImg
ref={props.imgRef}
referrerPolicy="same-origin"
className={className}
style={style}
width={width}
height={height}
draggable={false}
src={src}
$style={$style}
onClick={() => onClick && onClick()}
onError={(e) => {
e.currentTarget.src = DEFAULT_IMG_URL;
}}
/>
);
}