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

allow EuiImage to set custom width #3012

Merged
merged 26 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd10148
allow EuiImage to set custom width
anishagg17 Mar 9, 2020
3b1522e
Update CHANGELOG.md
anishagg17 Mar 9, 2020
21bb0ef
Merge branch 'master' into test2
anishagg17 Mar 10, 2020
119f8b9
Merge branch 'master' into test2
anishagg17 Mar 11, 2020
f5c334c
Merge branch 'master' into test2
anishagg17 Mar 12, 2020
f4247c7
greater of height or width gets size ,lesser is set to auto
anishagg17 Mar 14, 2020
ba123dd
checked for both heaight and width
anishagg17 Mar 16, 2020
d4bf580
Merge branch 'master' into test2
anishagg17 Mar 16, 2020
01cedb4
Merge branch 'master' into test2
anishagg17 Mar 17, 2020
33cdb73
removed uneccessary className
anishagg17 Mar 17, 2020
7e60550
Merge branch 'test2' of https://github.com/anishagg17/eui into test2
anishagg17 Mar 17, 2020
bfa8665
Merge branch 'master' into test2
cchaos Mar 17, 2020
a7a510f
used maxWidth,maxHeight
anishagg17 Mar 18, 2020
3d66262
removed class
anishagg17 Mar 18, 2020
d54ab10
Merge branch 'test2' of https://github.com/anishagg17/eui into test2
anishagg17 Mar 18, 2020
5dd124a
added test for custom size
anishagg17 Mar 18, 2020
f5a263c
Pushing some extra help (#3)
cchaos Mar 18, 2020
f86d126
maintain the aspect ratio
anishagg17 Mar 18, 2020
fbb0bd7
Update src/components/image/image.tsx
anishagg17 Mar 19, 2020
174ed01
Update CHANGELOG.md
anishagg17 Mar 19, 2020
d8f6fcc
Update src-docs/src/views/image/image_example.js
anishagg17 Mar 19, 2020
84b2c92
Update src-docs/src/views/image/image_example.js
anishagg17 Mar 19, 2020
f8a2521
Update src/components/image/image.tsx
anishagg17 Mar 19, 2020
280a1f5
updated snap
anishagg17 Mar 19, 2020
a1d309f
Merge branch 'master' into test2
cchaos Mar 19, 2020
0c565aa
fixed prettier
anishagg17 Mar 19, 2020
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)

- Allow `EuiImage` to set custom width ([#3012](https://github.com/elastic/eui/pull/3012))
- Added `EuiDataGrid`'s default sort order property ([#2987](https://github.com/elastic/eui/pull/2987))
- Fixed `EuiDataGrid`'s pagination visibility when changing rows per page ([#2978](https://github.com/elastic/eui/pull/2978))
- Added `highlightAll` prop to `EuiHighlight` to highlight all matches ([#2957](https://github.com/elastic/eui/pull/2957))
Expand Down
9 changes: 9 additions & 0 deletions src-docs/src/views/image/image_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { EuiImage, EuiSpacer } from '../../../../src/components';

export default () => (
<div>
<EuiImage
hasShadow
allowFullScreen
size={50}
caption="Custom Height( 50px )"
alt="Accessible image alt goes here"
url="https://source.unsplash.com/1000x1000/?Nature"
/>
<EuiSpacer />
<EuiImage
size="s"
hasShadow
Expand Down
10 changes: 10 additions & 0 deletions src/components/image/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
}
}

.euiImage--restrictHeight-custom{
width: auto;
margin-left: auto;
margin-right: auto;
img{
width: auto;
}
}

@keyframes euiImageFullScreen {
0% {
opacity: 0;
Expand All @@ -135,3 +144,4 @@
transform: translateY(0);
}
}

30 changes: 25 additions & 5 deletions src/components/image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const fullScreenIconColorMap: { [color in FullScreenIconColor]: string } = {

interface EuiImageProps extends CommonProps, HTMLAttributes<HTMLElement> {
alt: string;
size?: ImageSize;
size?: ImageSize | number;
fullScreenIconColor?: FullScreenIconColor;
url: string;
caption?: string;
Expand Down Expand Up @@ -86,16 +86,24 @@ export class EuiImage extends Component<EuiImageProps, State> {

const { isFullScreenActive } = this.state;

const classes = classNames(
let newStyle: React.CSSProperties | undefined;

let classes = classNames(
'euiImage',
sizeToClassNameMap[size],
{
'euiImage--hasShadow': hasShadow,
'euiImage--allowFullScreen': allowFullScreen,
},
className
);

if (typeof size === 'string') {
classes = `${classes} ${sizeToClassNameMap[size]}`;
} else {
classes = `${classes} euiImage--restrictHeight-custom`;
newStyle = { maxHeight: size };
}

let optionalCaption;
if (caption) {
optionalCaption = (
Expand Down Expand Up @@ -162,7 +170,13 @@ export class EuiImage extends Component<EuiImageProps, State> {
aria-label={openImage}
className="euiImage__button"
onClick={this.openFullScreen}>
<img src={url} alt={alt} className="euiImage__img" {...rest} />
<img
src={url}
alt={alt}
className="euiImage__img"
style={newStyle}
{...rest}
/>
{allowFullScreenIcon}
{isFullScreenActive && fullScreenDisplay}
</button>
Expand All @@ -174,7 +188,13 @@ export class EuiImage extends Component<EuiImageProps, State> {
} else {
return (
<figure className={classes} role="figure" aria-label={caption}>
<img src={url} className="euiImage__img" alt={alt} {...rest} />
<img
style={newStyle}
src={url}
className="euiImage__img"
alt={alt}
{...rest}
/>
{optionalCaption}
</figure>
);
Expand Down