import * as Model from "../model"; import { Picture } from "./picture"; import * as React from "react"; export interface Props { image: Model.Image; onClose: () => void; width: number; } export class BigPicture extends React.PureComponent { static displayName = "BigPicture"; componentDidMount() { window.addEventListener("keyup", this._onEscape as any); document.body.classList.add("no-scroll"); } componentWillUnmount() { window.removeEventListener("keyup", this._onEscape as any); document.body.classList.remove("no-scroll"); } render() { const scaleWidth = this.props.image.width / this.props.width; const scaleHeight = this.props.image.height / (window.innerHeight - 80); const scale = Math.max(scaleWidth, scaleHeight); return (
{}} height={this.props.image.height / scale} width={this.props.image.width / scale} />
⬇ Download Close
); } private _keyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter") { this.props.onClose(); } }; private _onEscape = (e: React.KeyboardEvent) => { if (e.key === "Escape") { this.props.onClose(); } }; }