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

Issue #941 #943

Merged
merged 3 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions docs/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@
"displayName": "Banner",
"methods": [
{
"name": "handleMeasure",
"name": "setMedia",
"docblock": null,
"modifiers": [],
"params": [
{
"name": "dimensions",
"name": "matches",
"type": null
}
],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"mobile-detect": "^1.3.6",
"radium": "^0.19.0",
"react-event-listener": "^0.4.5",
"react-measure": "^1.4.5",
"react-onclickoutside": "^6.6.3",
"recompose": "^0.22.0",
"tlds": "^1.182.0"
Expand Down
31 changes: 16 additions & 15 deletions src/banner/component.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Measure from 'react-measure';
import styles from './styles';
import getStyles from './get-styles';
import Media from '../media';
import Button from '../button';
import IconClose from '../icons/icon-close';
import colors from '../settings/colors';
Expand Down Expand Up @@ -42,20 +42,18 @@ class Banner extends Component {
this.state = {
type: 'desktop'
};

this.handleMeasure = this.handleMeasure.bind(this);
}

handleMeasure(dimensions) {
setMedia = (matches) => {
const { type } = this.state;

if (dimensions.width < 728 && type === 'desktop') {
if (!matches.small && type === 'desktop') {
this.setState({
type: 'mobile'
});
}

if (dimensions.width > 728 && type === 'mobile') {
if (matches.small && type === 'mobile') {
this.setState({
type: 'desktop'
});
Expand All @@ -70,17 +68,20 @@ class Banner extends Component {
return null;
}

const query = {
small: '(min-width: 728px)'
};

return (
<Measure onMeasure={this.handleMeasure}>
<section style={styles.wrapper}>
<section style={getStyles.root(type, style)}>
{content[type]}
<Button iconButton onClick={hideBanner} style={styles.button}>
<IconClose color={colors.white} />
</Button>
</section>
<section style={styles.wrapper}>
<section style={getStyles.root(type, style)}>
{content[type]}
<Button iconButton onClick={hideBanner} style={styles.button}>
<IconClose color={colors.white} />
</Button>
</section>
</Measure>
<Media query={query} onChange={this.setMedia} />
</section>
);
}
}
Expand Down