Use EuiImage when you need to place a static
- image into a page with an optional caption. It has the following
- props.
+ image into a page with an optional caption.
-
-
- size accepts{' '}
- s / m / l / xl / original / fullWidth. The
- latter will set the figure to stretch to 100% of its container.
-
-
- allowFullScreen when set to true will make the
- image clickable to a larger version.
-
-
- fullScreenIconColor allows you to change the
- color of the icon that floats above the image when it can be
- clicked to fullscreen. The default value of{' '}
- light is fine unless your image has a white
- background, in which case you should change it to{' '}
- dark.
-
-
- hasShadow when set to true (default) will apply
- a slight shadow below the image.
-
-
- caption will provide a caption to the image.
-
-
- alt Sepearate from the caption is a title on
- the alt tag itself. This one is required for accessibility.
-
Images can be sized by passing the size prop a
- value of s / m / l / xl / original / fullWidth.
- Note that this size is applied to the width of the image.
+ value of{' '}
+
+ s / m / l / xl / original / fullWidth / number / string
+
+ . This size sets the maximum length of the longest
+ edge of the image, whether that is height or width, and scales the it.
+ It will not increase the size of a smaller image or crop it.
),
demo: ,
diff --git a/src-docs/src/views/image/image_size.js b/src-docs/src/views/image/image_size.js
index abf8efde205..0212adadb0c 100644
--- a/src-docs/src/views/image/image_size.js
+++ b/src-docs/src/views/image/image_size.js
@@ -8,7 +8,7 @@ export default () => (
hasShadow
allowFullScreen
size={50}
- caption="Custom size( 50px )"
+ caption="Custom size (50)"
alt="Accessible image alt goes here"
url="https://source.unsplash.com/1000x1000/?Nature"
/>
diff --git a/src/components/image/__snapshots__/image.test.tsx.snap b/src/components/image/__snapshots__/image.test.tsx.snap
index b07c0799ac3..d4a9fffe4d5 100644
--- a/src/components/image/__snapshots__/image.test.tsx.snap
+++ b/src/components/image/__snapshots__/image.test.tsx.snap
@@ -49,7 +49,7 @@ exports[`EuiImage is rendered with custom size 1`] = `
class="euiImage__img"
data-test-subj="test subject string"
src="/cat.jpg"
- style="max-width:50px;max-height:50px;min-width:0;min-height:0;width:auto;height:auto"
+ style="max-width:50px;max-height:50px"
/>
`;
diff --git a/src/components/image/image.tsx b/src/components/image/image.tsx
index 742e8fb8e37..d304b228bab 100644
--- a/src/components/image/image.tsx
+++ b/src/components/image/image.tsx
@@ -32,13 +32,35 @@ const fullScreenIconColorMap: { [color in FullScreenIconColor]: string } = {
dark: 'default',
};
-interface EuiImageProps extends CommonProps, HTMLAttributes {
+interface EuiImageProps extends CommonProps, HTMLAttributes {
+ /**
+ * Sepearate from the caption is a title on the alt tag itself.
+ * This one is required for accessibility.
+ */
alt: string;
- size?: ImageSize | number;
+ /**
+ * Accepts `s` / `m` / `l` / `xl` / `original` / `fullWidth` / or a CSS size of `number` or `string`.
+ * `fullWidth` will set the figure to stretch to 100% of its container.
+ * All sizing values will max both the width or height, whichever is greater.
+ */
+ size?: ImageSize | number | string;
+ /**
+ * Changes the color of the icon that floats above the image when it can be clicked to fullscreen.
+ * The default value of `light` is fine unless your image has a white background, in which case you should change it to `dark`.
+ */
fullScreenIconColor?: FullScreenIconColor;
url: string;
+ /**
+ * Provides the visible caption to the image
+ */
caption?: string;
+ /**
+ * When set to `true` (default) will apply a slight shadow to the image
+ */
hasShadow?: boolean;
+ /**
+ * When set to `true` will make the image clickable to a larger version
+ */
allowFullScreen?: boolean;
}
@@ -81,11 +103,12 @@ export class EuiImage extends Component {
allowFullScreen,
fullScreenIconColor = 'light',
alt,
+ style,
...rest
} = this.props;
const { isFullScreenActive } = this.state;
- let customStyle = {};
+ const customStyle: React.CSSProperties = { ...style };
let classes = classNames(
'euiImage',
@@ -96,18 +119,12 @@ export class EuiImage extends Component {
className
);
- if (typeof size === 'string') {
- classes = `${classes} ${sizeToClassNameMap[size]}`;
+ if (typeof size === 'string' && SIZES.includes(size)) {
+ classes = `${classes} ${sizeToClassNameMap[size as ImageSize]}`;
} else {
classes = `${classes}`;
- customStyle = {
- maxWidth: size,
- maxHeight: size,
- minWidth: 0,
- minHeight: 0,
- width: 'auto',
- height: 'auto',
- };
+ customStyle.maxWidth = size;
+ customStyle.maxHeight = size;
}
let optionalCaption;
@@ -179,7 +196,7 @@ export class EuiImage extends Component {
src={url}
alt={alt}
className="euiImage__img"
- style={customStyle as React.CSSProperties}
+ style={customStyle}
{...rest}
/>
{allowFullScreenIcon}
@@ -194,7 +211,7 @@ export class EuiImage extends Component {
return (