Skip to content
This repository has been archived by the owner on Oct 25, 2018. It is now read-only.

Commit

Permalink
Replace JS driven Breakpoint component with one using media queries
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Apr 9, 2016
1 parent 96a8d03 commit 9a8d86b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
28 changes: 28 additions & 0 deletions components/Breakpoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react'
require('./breakpoints.css')

class Breakpoint extends Component {
render () {
const { mobile, children } = this.props
if (mobile) {
return (
<div className="breakpoint-min-width-700">
{children}
</div>
)
} else {
return (
<div className="breakpoint-max-width-700">
{children}
</div>
)
}
}
}

Breakpoint.propTypes = {
children: React.PropTypes.object,
mobile: React.PropTypes.bool,
}

export default Breakpoint
16 changes: 16 additions & 0 deletions components/breakpoints.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@media only screen and (min-width: 700px) {
.breakpoint-min-width-700 {
display: block;
}
.breakpoint-max-width-700 {
display: none;
}
}
@media only screen and (max-width: 700px) {
.breakpoint-min-width-700 {
display: none;
}
.breakpoint-max-width-700 {
display: block;
}
}
9 changes: 5 additions & 4 deletions pages/docs/_template.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Link } from 'react-router'
import { Breakpoint } from 'react-responsive-grid'
import Breakpoint from 'components/Breakpoint'
import find from 'lodash/find'
import { prefixLink } from 'gatsby-helpers'
import { config } from 'config'
Expand Down Expand Up @@ -58,10 +58,11 @@ module.exports = React.createClass({
</li>
)
})

return (
<div>
<Breakpoint minWidth={700}>
<Breakpoint
mobile
>
<div
style={{
overflowY: 'auto',
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = React.createClass({
{this.props.children}
</div>
</Breakpoint>
<Breakpoint maxWidth={700}>
<Breakpoint>
<strong>Topics:</strong>
{' '}
<select
Expand Down

0 comments on commit 9a8d86b

Please sign in to comment.