Skip to content

Commit 7f34bb6

Browse files
committed
add href to image
1 parent d3d701d commit 7f34bb6

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

package-lock.json

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@typescript-eslint/eslint-plugin": "^5.54.0",
3434
"react": "^18.2.0",
3535
"react-dom": "^18.2.0",
36+
"react-router-dom": "^6.8.2",
3637
"semantic-release": "^20.1.1",
3738
"typescript": "^4.9.5",
3839
"eslint": "^8.35.0",
@@ -44,7 +45,8 @@
4445
},
4546
"peerDependencies": {
4647
"react": "^18.2.0",
47-
"react-dom": "^18.2.0"
48+
"react-dom": "^18.2.0",
49+
"react-router-dom": "^6.8.2"
4850
},
4951
"release": {
5052
"branches": [

src/components/Image.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import React from 'react';
22
import { Box, BoxProps } from '@mui/material';
3+
import { useNavigate } from 'react-router-dom';
34

45
export interface ImageProps {
56
alt: string
67
src: string
8+
href?: string
79
boxProps?: BoxProps
810
}
911

10-
const Image: React.FC<ImageProps> = ({ alt, src, boxProps = {} }) => {
11-
const { sx, ...otherProps } = boxProps;
12+
const Image: React.FC<ImageProps> = ({
13+
alt, src, href, boxProps = {}
14+
}) => {
15+
let {
16+
sx,
17+
onClick,
18+
style = {},
19+
...otherProps
20+
} = boxProps;
21+
22+
if (href !== undefined) {
23+
const navigate = useNavigate();
24+
onClick = () => navigate(href);
25+
style.cursor = 'pointer';
26+
}
1227

1328
return (
1429
<Box
1530
component='img'
1631
alt={alt}
1732
src={src}
33+
onClick={onClick}
34+
style={style}
1835
sx={{
1936
width: '100%',
2037
...sx

0 commit comments

Comments
 (0)