backpack-ui
Version:
Lonely Planet's Components
133 lines (103 loc) • 3.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _reactPortal = require("react-portal");
var _reactPortal2 = _interopRequireDefault(_reactPortal);
var _radium = require("radium");
var _radium2 = _interopRequireDefault(_radium);
var _settings = require("../../../settings.json");
var _settings2 = _interopRequireDefault(_settings);
var _color = require("../../utils/color");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = {
portal: {
base: {
height: 0,
width: 0
}
},
overlay: {
base: {
bottom: 0,
left: 0,
position: "fixed",
right: 0,
top: 0,
transitionProperty: "opacity"
},
hidden: {
opacity: 0
},
visible: {
opacity: 1
}
}
};
function Overlay(_ref) {
var animationDuration = _ref.animationDuration;
var attached = _ref.attached;
var color = _ref.color;
var onClick = _ref.onClick;
var visible = _ref.visible;
var zIndex = _ref.zIndex;
return _react2.default.createElement(
_reactPortal2.default,
{
className: "Overlay-portal",
key: "overlay",
isOpened: attached || visible,
style: styles.portal.base
},
_react2.default.createElement("div", {
className: "Overlay",
onClick: onClick,
style: [styles.overlay.base, color && { backgroundColor: color }, animationDuration && { transitionDuration: animationDuration + "ms" }, zIndex && { zIndex: zIndex }, visible ? styles.overlay.visible : styles.overlay.hidden]
})
);
}
Overlay.propTypes = {
/**
* How long the animation should last, in ms
*/
animationDuration: _react.PropTypes.number,
/**
* Whether or not the overlay has been attached to the DOM. This prop differs
* from `visible` in that the overlay must be attached _before_ the overlay
* is actually visible. This allows the animation to have time to run. To
* create this offset, you'll need to use a setTimeout in the component in
* which the overlay is called to stagger the state change. If no animation
* is needed, then omit this prop and the value from `visible` will be used.
*/
attached: _react.PropTypes.bool,
/**
* The color over the overlay; this prop assumes no opacity so you'll need to
* pass in the correct value via `rgba`.
*/
color: _react.PropTypes.string,
/**
* A method to run when the overlay is clicked, usually to close the overlay
* and the component in which it was called from.
*/
onClick: _react.PropTypes.func,
/**
* Whether or not the overlay is actually visible, not necessarily attached to
* the DOM.
*/
visible: _react.PropTypes.bool.isRequired,
/**
* Used to control where the overlay should be placed on the z-axis
*/
zIndex: _react.PropTypes.number
};
Overlay.defaultProps = {
animationDuration: parseInt(_settings2.default.timing.default.replace("ms", ""), 10),
attached: false,
color: "rgba(" + (0, _color.rgb)(_settings2.default.color.black) + ", .4)",
onClick: null,
visible: false,
zIndex: _settings2.default.zIndex.modal - 2
};
exports.default = (0, _radium2.default)(Overlay);