Skip to content

Commit 712b91a

Browse files
Dynamic image width and height and open URL in the same or on a new page (#208)
* Dynamic image width and height and open URL in the same or on a new page * Upgrade the version number Co-authored-by: Andrei VASILACHE <andrei.vasilache@assist.ro>
1 parent 6dfb2db commit 712b91a

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code4ro/taskforce-fe-components",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"private": false,
55
"sideEffects": false,
66
"dependencies": {

src/components/banner-image/baner-image.stories.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ export default { title: "Banner Image" };
55

66
export const Default = () => (
77
<BannerImage
8-
link="https://code4.ro"
9-
image={
10-
{src: "https://stirioficiale.ro/storage/imagine principala_ROVACCINARE.png"}
11-
}
8+
link={{ path: "https://code4.ro", shouldOpenLinkOnNewPage: false }}
9+
image={{
10+
src:
11+
"https://stirioficiale.ro/storage/imagine principala_ROVACCINARE.png"
12+
}}
1213
/>
1314
);
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33

4-
export const BannerImage = ({ image: {src, alt, title}, link }) => {
5-
return (
6-
<div>
7-
{link ?
8-
<a href={link} target="_blank" rel="noopener noreferrer">
9-
<img src={src} alt={alt} title={title}/>
10-
</a>
11-
:
12-
<img src={src} alt={alt} title={title}/>
13-
}
14-
</div>
4+
const handleClick = ({ path, shouldOpenLinkOnNewPage }) => {
5+
const windowInstance = window.open(
6+
path,
7+
shouldOpenLinkOnNewPage ? "_blank" : "_self"
158
);
9+
windowInstance.focus();
1610
};
1711

12+
export const BannerImage = ({
13+
image: { src, alt, title, width, height },
14+
link
15+
}) => (
16+
<div>
17+
<img
18+
src={src}
19+
alt={alt}
20+
title={title}
21+
width={width}
22+
height={height}
23+
{...(!!link && { onClick: () => handleClick(link) })}
24+
/>
25+
</div>
26+
);
27+
1828
BannerImage.propTypes = {
1929
image: PropTypes.shape({
2030
src: PropTypes.string.isRequired,
2131
alt: PropTypes.string,
22-
title: PropTypes.string
32+
title: PropTypes.string,
33+
width: PropTypes.number,
34+
height: PropTypes.number
2335
}).isRequired,
24-
link: PropTypes.string
36+
link: PropTypes.shape({
37+
path: PropTypes.string.isRequired,
38+
shouldOpenLinkOnNewPage: PropTypes.bool
39+
})
2540
};
2641

2742
BannerImage.defaultProps = {
2843
link: null
29-
}
30-
31-
44+
};

0 commit comments

Comments
 (0)