File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1- import { ParagraphSizes } from "atoms/constants/paragraph-sizes" ;
21// -----------------------------------------------------------------------------------------
32// #region Atoms
43// -----------------------------------------------------------------------------------------
@@ -7,6 +6,7 @@ export { Anchor } from "./atoms/anchors/anchor";
76export { AnchorWithIcon } from "./atoms/anchors/anchor-with-icon" ;
87export { Button } from "./atoms/buttons/button" ;
98export { Icon } from "./atoms/icons/icon" ;
9+ export { Image } from "./atoms/images/image" ;
1010export { ProgressBar } from "./atoms/progress-bar/progress-bar" ;
1111
1212// Forms
You can’t perform that action at this time.
0 commit comments