-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from breeny/release-0.1.1
Release 0.1.1
- Loading branch information
Showing
6 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
node_modules/ | ||
es/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
import React from 'react'; | ||
import breakpoints from './breakpoints'; | ||
|
||
var Breakpoint = function (_React$Component) { | ||
_inherits(Breakpoint, _React$Component); | ||
|
||
function Breakpoint() { | ||
var _temp, _this, _ret; | ||
|
||
_classCallCheck(this, Breakpoint); | ||
|
||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
|
||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = { | ||
breakpoint: breakpoints.getBreakpoints()[0] | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
|
||
Breakpoint.prototype.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
|
||
this.queries = []; | ||
breakpoints.getBreakpoints().forEach(function (breakpoint) { | ||
var mq = window.matchMedia(breakpoint.query); | ||
|
||
if (mq.matches) { | ||
_this2.setState({ | ||
breakpoint: breakpoint | ||
}); | ||
} | ||
|
||
var listener = function listener(mql) { | ||
if (mql.matches) { | ||
_this2.setState({ | ||
breakpoint: breakpoint | ||
}); | ||
} | ||
}; | ||
|
||
mq.addListener(listener); | ||
|
||
_this2.queries.push({ | ||
query: mq, | ||
listener: listener | ||
}); | ||
}); | ||
}; | ||
|
||
Breakpoint.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.queries.forEach(function (bp) { | ||
bp.query.removeListener(bp.listener); | ||
}); | ||
}; | ||
|
||
Breakpoint.prototype.render = function render() { | ||
var breakpoint = this.state.breakpoint; | ||
|
||
if (this.props[breakpoint.name]) { | ||
return this.props[breakpoint.name](); | ||
} | ||
|
||
if (this.props.render) { | ||
return this.props.render(breakpoint.name); | ||
} | ||
|
||
if (this.props.children) { | ||
return this.props.children(breakpoint.name); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
return Breakpoint; | ||
}(React.Component); | ||
|
||
export default Breakpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
import defaultBreakpoints from './default_breakpoints.json'; | ||
|
||
var Breakpoints = function () { | ||
function Breakpoints() { | ||
_classCallCheck(this, Breakpoints); | ||
|
||
this.generateMediaQueries(defaultBreakpoints); | ||
} | ||
|
||
Breakpoints.prototype.generateMediaQueries = function generateMediaQueries(breakpoints) { | ||
var queries = breakpoints.map(function (breakpoint) { | ||
|
||
var query = ''; | ||
if (breakpoint.minWidth) { | ||
query += '(min-width: ' + breakpoint.minWidth + 'px)'; | ||
} | ||
|
||
if (query && breakpoint.maxWidth) { | ||
query += ' and '; | ||
} | ||
|
||
if (breakpoint.maxWidth) { | ||
query += '(max-width: ' + breakpoint.maxWidth + 'px)'; | ||
} | ||
|
||
return { | ||
name: breakpoint.name, | ||
query: query | ||
}; | ||
}); | ||
|
||
this.breakpoints = queries; | ||
}; | ||
|
||
Breakpoints.prototype.configureBreakpoints = function configureBreakpoints(breakpoints) { | ||
this.generateMediaQueries(breakpoints); | ||
}; | ||
|
||
Breakpoints.prototype.getBreakpoints = function getBreakpoints() { | ||
return this.breakpoints; | ||
}; | ||
|
||
return Breakpoints; | ||
}(); | ||
|
||
var breakpoints = new Breakpoints(); | ||
export default breakpoints; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import breakpoints from './breakpoints'; | ||
|
||
var configure = function configure(newBreakpoints) { | ||
breakpoints.configureBreakpoints(newBreakpoints); | ||
}; | ||
|
||
export { default } from './Breakpoint'; | ||
|
||
export { configure }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters