Unverified Commit 3f150be1 authored by Benjamin Wheeler's avatar Benjamin Wheeler Committed by GitHub

Merge pull request #3266 from benjiwheeler/join-flow-info-responsive

use media queries to make info message responsive
parents 83bbe404 d8bafccc
const bindAll = require('lodash.bindall'); const bindAll = require('lodash.bindall');
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
const React = require('react'); const React = require('react');
const MediaQuery = require('react-responsive').default;
const frameless = require('../../lib/frameless');
require('./info-button.scss'); require('./info-button.scss');
...@@ -22,25 +25,38 @@ class InfoButton extends React.Component { ...@@ -22,25 +25,38 @@ class InfoButton extends React.Component {
this.setState({visible: true}); this.setState({visible: true});
} }
render () { render () {
const messageJsx = this.state.visible && (
<div className="info-button-message">
{this.props.message}
</div>
);
return ( return (
<div <React.Fragment>
className="info-button" <div
onClick={this.handleShowMessage} className="info-button"
onMouseOut={this.handleHideMessage} onClick={this.handleShowMessage}
onMouseOver={this.handleShowMessage} onMouseOut={this.handleHideMessage}
> onMouseOver={this.handleShowMessage}
{this.state.visible && ( >
<div className="info-button-message"> <MediaQuery minWidth={frameless.desktop}>
{this.props.message} {messageJsx}
</MediaQuery>
</div>
{/* for small screens, add additional position: relative element,
so info message can position itself relative to the width which
encloses info-button -- rather than relative to info-button itself */}
<MediaQuery maxWidth={frameless.desktop - 1}>
<div style={{position: 'relative'}}>
{messageJsx}
</div> </div>
)} </MediaQuery>
</div> </React.Fragment>
); );
} }
} }
InfoButton.propTypes = { InfoButton.propTypes = {
message: PropTypes.string message: PropTypes.string.isRequired
}; };
module.exports = InfoButton; module.exports = InfoButton;
...@@ -65,11 +65,12 @@ ...@@ -65,11 +65,12 @@
@media #{$intermediate-and-smaller} { @media #{$intermediate-and-smaller} {
.info-button-message { .info-button-message {
position: relative; position: absolute;
transform: none; transform: none;
margin: inherit; /* since we're positioning message relative to info-button's parent,
width: 100%; we need to center this element within its width. */
height: inherit; margin: 0 calc((100% - 16.5rem) / 2);;
top: .125rem;
&:before { &:before {
display: none; display: none;
......
// __mocks__/react-responsive.js
const MediaQuery = ({children}) => children;
export default MediaQuery;
...@@ -11,6 +11,15 @@ describe('InfoButton', () => { ...@@ -11,6 +11,15 @@ describe('InfoButton', () => {
); );
expect(component.find('div.info-button-message').exists()).toEqual(false); expect(component.find('div.info-button-message').exists()).toEqual(false);
}); });
test('mouseOver on info button makes info message visible', () => {
const component = mountWithIntl(
<InfoButton
message="Here is some info about something!"
/>
);
component.find('div.info-button').simulate('mouseOver');
expect(component.find('div.info-button-message').exists()).toEqual(true);
});
test('clicking on info button makes info message visible', () => { test('clicking on info button makes info message visible', () => {
const component = mountWithIntl( const component = mountWithIntl(
<InfoButton <InfoButton
...@@ -26,7 +35,7 @@ describe('InfoButton', () => { ...@@ -26,7 +35,7 @@ describe('InfoButton', () => {
message="Here is some info about something!" message="Here is some info about something!"
/> />
); );
component.find('div.info-button').simulate('click'); component.find('div.info-button').simulate('mouseOver');
expect(component.find('div.info-button-message').exists()).toEqual(true); expect(component.find('div.info-button-message').exists()).toEqual(true);
component.find('div.info-button').simulate('mouseOut'); component.find('div.info-button').simulate('mouseOut');
expect(component.find('div.info-button-message').exists()).toEqual(false); expect(component.find('div.info-button-message').exists()).toEqual(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment