Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added href prop to `EuiTab` and converted to TypeScript ([#2275](https://github.com/elastic/eui/pull/2275))
- Added hover and focus states when allowFullScreen is true in `EuiImage`([#2287](https://github.com/elastic/eui/pull/2287))
Comment thread
elizabetdev marked this conversation as resolved.
Outdated

**Bug fixes**

Expand Down
23 changes: 22 additions & 1 deletion src/components/image/__snapshots__/image.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
// 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
alt="alt"
class="euiImage__img"
/>
</figure>
`;

exports[`EuiImage is rendered and allows full screen 1`] = `
<button
class="euiImage euiImage--large euiImage--allowFullScreen testClass1 testClass2"
type="button"
>
<figure
aria-label="aria-label"
class="euiImage euiImage--large testClass1 testClass2"
data-test-subj="test subject string"
>
<img
alt="alt"
class="euiImage__img"
/>
<svg
class="euiIcon euiIcon--medium euiIcon--ghost euiIcon-isLoading euiImage__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</figure>
</button>
`;
19 changes: 18 additions & 1 deletion src/components/image/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@
}
}

&.euiImage--allowFullScreen:hover {
Comment thread
elizabetdev marked this conversation as resolved.
&.euiImage--allowFullScreen {
&:not(.euiImage--hasShadow):hover,
&:not(.euiImage--hasShadow):focus {
.euiImage__img {
@include euiSlightShadowHover;
}
}

&.euiImage--hasShadow:hover,
&.euiImage--hasShadow:focus {
.euiImage__img {
@include euiBottomShadow($color: $euiShadowColor, $opacity: .2);
}
}

.euiImage__img {
cursor: pointer;

// transition the shadow
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
}

.euiImage__icon {
Expand Down
97 changes: 48 additions & 49 deletions src/components/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class EuiImage extends Component {
super(props);

this.state = {
isFullScreen: false,
isFullScreenActive: false,
};
}

Expand All @@ -45,13 +45,13 @@ export class EuiImage extends Component {

closeFullScreen = () => {
this.setState({
isFullScreen: false,
isFullScreenActive: false,
});
};

openFullScreen = () => {
this.setState({
isFullScreen: true,
isFullScreenActive: true,
});
};

Expand All @@ -68,6 +68,8 @@ export class EuiImage extends Component {
...rest
} = this.props;

const { isFullScreenActive } = this.state;

const classes = classNames(
'euiImage',
sizeToClassNameMap[size],
Expand All @@ -85,59 +87,56 @@ export class EuiImage extends Component {
);
}

let optionalIcon;
const allowFullScreeIcon = (
Comment thread
thompsongl marked this conversation as resolved.
Outdated
<EuiIcon
type="fullScreen"
color={fullScreenIconColorMap[fullScreenIconColor]}
className="euiImage__icon"
/>
);

if (allowFullScreen) {
optionalIcon = (
<EuiIcon
type="fullScreen"
color={fullScreenIconColorMap[fullScreenIconColor]}
className="euiImage__icon"
/>
);
}
const fullScreenDisplay = (
<EuiOverlayMask onClick={this.closeFullScreen}>
<EuiFocusTrap clickOutsideDisables={true}>
<button
type="button"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<figure
ref={node => {
this.figure = node;
}}
className="euiImageFullScreen">
Comment thread
elizabetdev marked this conversation as resolved.
Outdated
<img src={url} className="euiImageFullScreen__img" alt={alt} />
Comment thread
elizabetdev marked this conversation as resolved.
Outdated
{optionalCaption}
</figure>
</button>
</EuiFocusTrap>
</EuiOverlayMask>
);

let fullScreenDisplay;

if (this.state.isFullScreen) {
fullScreenDisplay = (
<EuiOverlayMask onClick={this.closeFullScreen}>
<EuiFocusTrap clickOutsideDisables={true}>
<button
type="button"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<figure
ref={node => {
this.figure = node;
}}
className="euiImageFullScreen">
<img src={url} className="euiImageFullScreen__img" alt={alt} />
{optionalCaption}
</figure>
</button>
</EuiFocusTrap>
</EuiOverlayMask>
if (allowFullScreen) {
return (
<button
type="button"
onClick={allowFullScreen ? this.openFullScreen : undefined}
className={classes}>
<figure {...rest}>
<img src={url} className="euiImage__img" alt={alt} />
{optionalCaption}
{allowFullScreeIcon}
Comment thread
thompsongl marked this conversation as resolved.
Outdated
{isFullScreenActive && fullScreenDisplay}
</figure>
</button>
);
}

return (
<button
type="button"
onClick={allowFullScreen ? this.openFullScreen : undefined}>
} else {
return (
<figure className={classes} {...rest}>
<img src={url} className="euiImage__img" alt={alt} />
{optionalCaption}

{/*
If the below fullScreen image renders, it actually attaches to the body because of
EuiOverlayMask's React portal usage.
*/}
{optionalIcon}
{fullScreenDisplay}
</figure>
</button>
);
);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/image/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ describe('EuiImage', () => {

expect(component).toMatchSnapshot();
});

test('is rendered and allows full screen', () => {
const component = render(
<EuiImage alt="alt" size="l" allowFullScreen {...requiredProps} />
);

expect(component).toMatchSnapshot();
});
});