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

Eui image focus states #2287

Merged
merged 15 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 12 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 hover and focus states when `allowFullScreen` is true in `EuiImage`([#2287](https://github.com/elastic/eui/pull/2287))
- Added missing `compressed` styling to `EuiSwitch` ([#2327](https://github.com/elastic/eui/pull/2327))

## [`14.0.0`](https://github.com/elastic/eui/tree/v14.0.0)
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>
`;
65 changes: 54 additions & 11 deletions src/components/image/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,40 @@
}
}

&.euiImage--allowFullScreen:hover {
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
.euiImage__img {
cursor: pointer;
&.euiImage--allowFullScreen {
&:focus .euiImage__img {
outline: 2px solid $euiFocusRingColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

Much better 🎉

}

.euiImage__icon {
&:hover .euiImage__icon {
visibility: visible;
opacity: 1;
fill-opacity: 1;
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
}

&:hover .euiImage__caption,
&:focus .euiImage__caption {
text-decoration: underline;
}

&:not(.euiImage--hasShadow):hover,
&:not(.euiImage--hasShadow):focus {
.euiImage__img {
@include euiBottomShadowMedium;
}
}

&.euiImage--hasShadow:hover,
&.euiImage--hasShadow:focus {
.euiImage__img {
@include euiBottomShadow;
}
}

.euiImage__img {
cursor: pointer;

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

Expand Down Expand Up @@ -62,31 +88,48 @@

.euiImage__icon {
visibility: hidden;
opacity: 0;
fill-opacity: 0;
position: absolute;
right: $euiSize;
top: $euiSize;
transition: opacity $euiAnimSpeedSlow $euiAnimSlightResistance ;
transition: fill-opacity $euiAnimSpeedSlow $euiAnimSlightResistance;
cursor: pointer;
}

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

.euiImageFullScreen__img {
.euiImage-isFullScreen__icon {
position: absolute;
right: $euiSize;
top: $euiSize;
}

.euiImage-isFullScreen__img {
max-height: 80vh;
max-width: 80vw;
cursor: pointer;
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
}

&:hover .euiImageFullScreen__img {
&:hover .euiImage-isFullScreen__img {
@include euiBottomShadow;
cursor: pointer;
}
}

&:focus .euiImage-isFullScreen__img {
outline: 2px solid $euiFocusRingColor;
}

&:hover .euiImage__caption,
&:focus-within .euiImage__caption {
text-decoration: underline;
}
}

@keyframes euiImageFullScreen {
0% {
Expand Down
103 changes: 54 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,62 @@ export class EuiImage extends Component {
);
}

let optionalIcon;
const allowFullScreeIcon = (
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
<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"
className="euiImage-isFullScreen"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<figure
ref={node => {
this.figure = node;
}}>
<img src={url} className="euiImage-isFullScreen__img" alt={alt} />
{optionalCaption}

<EuiIcon
type="cross"
color={fullScreenIconColorMap[fullScreenIconColor]}
className="euiImage-isFullScreen__icon"
/>
</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}
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
{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();
});
});