Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image component #262

Merged
merged 13 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- Added `<EuiImage>` component to allow for image sizing and zooms. [(#262)](https://github.com/elastic/eui/pull/262)
- Updated `<EuiOverlayMask>` to append `<div>` to body. [(#254)](https://github.com/elastic/eui/pull/254)

**Bug fixes**
Expand Down
4 changes: 4 additions & 0 deletions src-docs/src/services/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ import { HorizontalRuleExample }
import { IconExample }
from '../../views/icon/icon_example';

import { ImageExample }
from '../../views/image/image_example';

import { KeyPadMenuExample }
from '../../views/key_pad_menu/key_pad_menu_example';

Expand Down Expand Up @@ -208,6 +211,7 @@ const components = [
HealthExample,
HorizontalRuleExample,
IconExample,
ImageExample,
KeyPadMenuExample,
LinkExample,
LoadingExample,
Expand Down
16 changes: 16 additions & 0 deletions src-docs/src/views/image/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

import {
EuiImage,
} from '../../../../src/components';

export default () => (
<EuiImage
size="l"
hasShadow
allowFullScreen
caption="Click me to see full screen"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
);
78 changes: 78 additions & 0 deletions src-docs/src/views/image/image_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react';

import { renderToHtml } from '../../services';

import {
GuideSectionTypes,
} from '../../components';

import {
EuiCode,
} from '../../../../src/components';

import Image from './image';
const imageSource = require('!!raw-loader!./image');
const imageHtml = renderToHtml(Image);

import ImageSizes from './image_size';
const imageSizesSource = require('!!raw-loader!./image_size');
const imageSizesHtml = renderToHtml(ImageSizes);

export const ImageExample = {
title: 'Image',
sections: [
{
title: 'Image',
source: [{
type: GuideSectionTypes.JS,
code: imageSource,
}, {
type: GuideSectionTypes.HTML,
code: imageHtml,
}],
text: (
<div>
<p>
Use <EuiCode>EuiImage</EuiCode> when you need to place a static image
into a page with an optional caption. It has the following props.
</p>
<ul>
<li>
<EuiCode>size</EuiCode> accepts <EuiCode>s / m / l / xl / original / fullWidth</EuiCode>.
The later will set the figure to stretch to 100% of its container.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp: "later" -> "latter"

</li>
<li>
<EuiCode>allowFullScreen</EuiCode> when set to true (default) will make the image
clicakable to a larger version.
</li>
<li>
<EuiCode>hasShadow</EuiCode> when set to true (default) will apply
a slight shadow below the image.
</li>
<li>
<EuiCode>caption</EuiCode> will provide a caption to the image.
</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title is a prop as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

</ul>
</div>
),
demo: <Image />,
},
{
title: 'Images can be sized',
source: [{
type: GuideSectionTypes.JS,
code: imageSizesSource,
}, {
type: GuideSectionTypes.HTML,
code: imageSizesHtml,
}],
text: (
<p>
Images can be sized by passing the <EuiCode>size</EuiCode> prop a value
of <EuiCode>s / m / l / original / fullWidth</EuiCode>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 'xl' to this list as well

</p>
),
demo: <ImageSizes />,
},
],
};
63 changes: 63 additions & 0 deletions src-docs/src/views/image/image_size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';

import {
EuiImage,
EuiSpacer,
} from '../../../../src/components';

export default () => (
<div>
<EuiImage
size="s"
hasShadow
allowFullScreen
caption="Small"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
<EuiSpacer />
<EuiImage
size="m"
hasShadow
allowFullScreen
caption="Medium"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
<EuiSpacer />
<EuiImage
size="l"
hasShadow
allowFullScreen
caption="Large"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
<EuiSpacer />
<EuiImage
size="xl"
hasShadow
allowFullScreen
caption="Extra large"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
<EuiSpacer />
<EuiImage
hasShadow
allowFullScreen
caption="Original"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
<EuiSpacer />
<EuiImage
hasShadow
allowFullScreen
size="fullWidth"
caption="Full width"
title="Accessible image title goes here"
url="https://i.imgur.com/4qx7HhE.jpg"
/>
</div>
);
14 changes: 14 additions & 0 deletions src/components/image/__snapshots__/image.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiImage is rendered 1`] = `
<figure
aria-label="aria-label"
class="euiImage euiImage--large testClass1 testClass2"
data-test-subj="test subject string"
>
<img
class="euiImage__img"
title="title"
/>
</figure>
`;
78 changes: 78 additions & 0 deletions src/components/image/_image.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Main <figure> that wraps images.
.euiImage {
display: inline-block;
max-width: 100%;


&.euiImage--hasShadow {
.euiImage__img {
@include euiBottomShadowMedium;
}
}

&.euiImage--allowFullScreen:hover {
.euiImage__img {
cursor: pointer;
}
}

// These sizes are mostly suggestions. Don't look too hard for meaning in their values.
&.euiImage--small {
width: convertToRem(120px);
}

&.euiImage--medium {
width: convertToRem(200px);
}

&.euiImage--large {
width: convertToRem(360px);
}

&.euiImage--xlarge {
width: convertToRem(600px);
}

&.euiImage--fullWidth {
width: 100%;
}
}

// The image itself is full width within the container.
.euiImage__img {
width: 100%;
}

.euiImage__caption {
text-align: center;
@include euiFontSizeS;
}

// The FullScreen image that optionally pops up on click.
.euiImageFullScreen {
max-height: 80vh;
max-width: 80vw;
animation: euiImageFullScreen $euiAnimSpeedExtraSlow $euiAnimSlightBounce;

.euiImageFullScreen__img {
max-height: 80vh;
max-width: 80vw;
cursor: pointer;
}

&:hover .euiImageFullScreen__img {
cursor: pointer;
}
}


@keyframes euiImageFullScreen {
0% {
opacity: 0;
transform: translateY($euiSizeXL * 2);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
1 change: 1 addition & 0 deletions src/components/image/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'image';
Loading