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 3 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
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 {
elizabetdev marked this conversation as resolved.
Show resolved Hide 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 = (
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"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
<figure
ref={node => {
this.figure = node;
}}
className="euiImageFullScreen">
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
<img src={url} className="euiImageFullScreen__img" alt={alt} />
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
{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}
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();
});
});