import React from "react"; import { connect } from "react-redux"; import PropTypes from "prop-types"; import classnames from "classnames"; import "../../../css/gen-window.css"; import { SET_FOCUSED_WINDOW, CLOSE_GEN_WINDOW, GEN_WINDOW_SIZE_CHANGED } from "../../actionTypes"; import { scrollVolume } from "../../actionCreators"; import { getWindowPixelSize } from "../../selectors"; import ResizeTarget from "../ResizeTarget"; const Text = ({ children }) => { const letters = children.split(""); return letters.map((letter, i) => (
)); }; const CHROME_WIDTH = 19; const CHROME_HEIGHT = 34; // Named export for testing export const GenWindow = ({ selected, children, close, title, setFocus, windowId, windowSize, genWindowSizeChanged, scrollVolume: handleWheel }) => { const { width, height } = getWindowPixelSize(windowSize); return (
setFocus(windowId)} onWheel={handleWheel} style={{ width, height }} >
{title}
close(windowId)} />
{children({ width: width - CHROME_WIDTH, height: height - CHROME_HEIGHT })}
genWindowSizeChanged(windowId, size)} id={"gen-resize-target"} />
); }; GenWindow.propTypes = { title: PropTypes.string.isRequired, windowId: PropTypes.string.isRequired, children: PropTypes.func.isRequired, close: PropTypes.func.isRequired, selected: PropTypes.bool.isRequired }; const mapStateToProps = (state, ownProps) => ({ selected: state.windows.focused === ownProps.windowId, windowSize: state.windows.genWindows[ownProps.windowId].size }); const mapDispatchToProps = { setFocus: windowId => ({ type: SET_FOCUSED_WINDOW, window: windowId }), close: windowId => ({ type: CLOSE_GEN_WINDOW, windowId }), scrollVolume, genWindowSizeChanged: (windowId, size) => ({ type: GEN_WINDOW_SIZE_CHANGED, windowId, size }) }; export default connect(mapStateToProps, mapDispatchToProps)(GenWindow);