Skip to content

Commit 3bc28cc

Browse files
committed
Added atoms image component
1 parent f0c93cd commit 3bc28cc

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/atoms/images/image.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Image } from "./image";
2+
import React from "react";
3+
import { text } from "@storybook/addon-knobs";
4+
5+
export default {
6+
component: Image,
7+
title: "Atoms | Images / Image",
8+
};
9+
10+
export const image = () => (
11+
<Image src={text("Src", "https://via.placeholder.com/350x150")} />
12+
);

src/atoms/images/image.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import { render } from "@testing-library/react";
3+
import { Image } from "./image";
4+
5+
describe("Image", () => {
6+
test("when default props, renders image", () => {
7+
// Arrange
8+
const expected = "https://via.placeholder.com/350x150";
9+
10+
// Act
11+
const { container } = render(<Image src={expected} />);
12+
13+
// Assert
14+
expect(container.firstChild.nodeName).toBe("IMG");
15+
});
16+
});

src/atoms/images/image.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as React from "react";
2+
3+
// -----------------------------------------------------------------------------------------
4+
// #region Interfaces
5+
// -----------------------------------------------------------------------------------------
6+
7+
export interface ImageProps {
8+
/**
9+
* Alt text to display for screenreaders or if the image does not load.
10+
*
11+
* @type {string}
12+
* @memberof ImageProps
13+
*/
14+
altText?: string;
15+
16+
/**
17+
* Optional class name to be applied to the img element.
18+
*
19+
* @type {string}
20+
* @memberof ImageProps
21+
*/
22+
cssClassName?: string;
23+
24+
/**
25+
* Path to the image to be rendered.
26+
*
27+
* @type {string}
28+
* @memberof ImageProps
29+
*/
30+
src: string;
31+
}
32+
33+
// #endregion Interfaces
34+
35+
// -----------------------------------------------------------------------------------------
36+
// #region Component
37+
// -----------------------------------------------------------------------------------------
38+
39+
const Image: React.FunctionComponent<ImageProps> = (props: ImageProps) => (
40+
<img alt={props.altText} className={props.cssClassName} src={props.src} />
41+
);
42+
43+
// #endregion Component
44+
45+
// -----------------------------------------------------------------------------------------
46+
// #region Exports
47+
// -----------------------------------------------------------------------------------------
48+
49+
export { Image };
50+
51+
// #endregion Exports

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ParagraphSizes } from "atoms/constants/paragraph-sizes";
21
// -----------------------------------------------------------------------------------------
32
// #region Atoms
43
// -----------------------------------------------------------------------------------------
@@ -7,6 +6,7 @@ export { Anchor } from "./atoms/anchors/anchor";
76
export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon";
87
export { Button } from "./atoms/buttons/button";
98
export { Icon } from "./atoms/icons/icon";
9+
export { Image } from "./atoms/images/image";
1010
export { ProgressBar } from "./atoms/progress-bar/progress-bar";
1111

1212
// Forms

0 commit comments

Comments
 (0)