From 380548112f1ca83b85091bb851886fc32701d725 Mon Sep 17 00:00:00 2001 From: NikolayRechkin Date: Thu, 26 Sep 2019 16:27:42 +0300 Subject: [PATCH] web: components: added displayType property to avatar editor --- .../src/components/avatar-editor/index.js | 127 ++++++++++++++---- .../sub-components/avatar-editor-body.js | 12 +- 2 files changed, 107 insertions(+), 32 deletions(-) diff --git a/web/ASC.Web.Components/src/components/avatar-editor/index.js b/web/ASC.Web.Components/src/components/avatar-editor/index.js index 06d7c6370e..7a34141046 100644 --- a/web/ASC.Web.Components/src/components/avatar-editor/index.js +++ b/web/ASC.Web.Components/src/components/avatar-editor/index.js @@ -1,8 +1,25 @@ -import React, { memo } from 'react' +import React from 'react' import PropTypes from 'prop-types' import ModalDialog from '../modal-dialog' import Button from '../button' import AvatarEditorBody from './sub-components/avatar-editor-body' +import Aside from "../layout/sub-components/aside"; +import IconButton from '../icon-button' +import styled from 'styled-components' +import { desktop } from '../../utils/device'; +import throttle from 'lodash/throttle'; + +const Header = styled.div` + margin-bottom: 10px; +`; + +const StyledAside = styled(Aside)` + padding: 10px; + + .aside-save-button{ + margin-top: 10px; + } +`; class AvatarEditor extends React.Component { constructor(props) { @@ -14,7 +31,9 @@ class AvatarEditor extends React.Component { x: 0, y: 0, width: 0, - height:0 + height: 0, + + displayType: this.props.displayType !== 'auto' ? this.props.displayType : window.innerWidth <= desktop.match(/\d+/)[0] ? 'aside' : 'modal' } this.onClose = this.onClose.bind(this); @@ -24,19 +43,29 @@ class AvatarEditor extends React.Component { this.onLoadFile = this.onLoadFile.bind(this); this.onPositionChange = this.onPositionChange.bind(this); - this.onDeleteImage = this.onDeleteImage.bind(this) - + this.onDeleteImage = this.onDeleteImage.bind(this); + this.throttledResize = throttle(this.resize, 300); + } - onImageChange(file){ - if(typeof this.props.onImageChange === 'function') this.props.onImageChange(file); + resize = () => { + if (this.props.displayType === "auto") { + const type = window.innerWidth <= desktop.match(/\d+/)[0] ? 'aside' : 'modal'; + if (type !== this.state.displayType) + this.setState({ + displayType: type + }); + } } - onDeleteImage(){ + onImageChange(file) { + if (typeof this.props.onImageChange === 'function') this.props.onImageChange(file); + } + onDeleteImage() { this.setState({ isContainsFile: false }) - if(typeof this.props.onDeleteImage === 'function') this.props.onDeleteImage(); + if (typeof this.props.onDeleteImage === 'function') this.props.onDeleteImage(); } - onPositionChange(data){ + onPositionChange(data) { this.setState(data); } onLoadFileError(error) { @@ -53,10 +82,10 @@ class AvatarEditor extends React.Component { } } onLoadFile(file) { - if(typeof this.props.onLoadFile === 'function') this.props.onLoadFile(file); + if (typeof this.props.onLoadFile === 'function') this.props.onLoadFile(file); this.setState({ isContainsFile: true }); } - + onSaveButtonClick() { this.props.onSave(this.state.isContainsFile, { x: this.state.x, @@ -76,12 +105,59 @@ class AvatarEditor extends React.Component { this.setState({ visible: this.props.visible }); } } + componentDidMount() { + window.addEventListener('resize', this.throttledResize); + } + componentWillUnmount() { + window.removeEventListener('resize', this.throttledResize); + } render() { + return ( - + } + footerContent={[ +