'use strict';
const React = require("react");
const createReactClass = require("create-react-class");
const classnames = require("classnames");
const renderIf = require("../util/render-if");
function cancelEvent(event) {
/* NOTE: This is used on mousedown events for controls like the CloseButton, to ensure that a click-and-drag on a titlebar control cannot start a window drag operation. */
event.stopPropagation();
}
function relativePosition(event, bounds) {
let relativeX = event.clientX - bounds.x;
let relativeY = event.clientY - bounds.y;
return {
x: relativeX,
y: relativeY
};
}
function CloseButton({onClick}) {
return (
✖
);
}
let TitleBar = createReactClass({
displayName: "TitleBar",
setRef: function (ref) {
this.setState({
ref: ref
});
},
handleMouseDown: function (event) {
let bounds = this.state.ref.getBoundingClientRect();
let relativeX = event.clientX - bounds.x;
let relativeY = event.clientY - bounds.y;
this.props.onMouseDown(event, relativeX, relativeY);
},
render: function () {
return (
{this.props.title}
{this.props.extraButtons}
);
}
});
function Resizer({onMouseDown}) {
let [ref, setRef] = React.useState(null);
function onMouseDown_(event) {
let {x, y} = relativePosition(event, ref.getBoundingClientRect());
onMouseDown(event, x, y);
event.stopPropagation();
}
return (
);
}
module.exports = function Window({elementRef, style, window: window_, onMouseDown, onTitleMouseDown, onClose, onResizerMouseDown}) {
return (
{window_.contents}
{renderIf(window_.resizable,
)}
);
};