2020-10-20 21:50:53 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2020-10-20 21:52:56 +02:00
|
|
|
import React from 'react'
|
2020-10-20 21:50:53 +02:00
|
|
|
|
2020-10-31 17:30:56 +01:00
|
|
|
import IconButton from '../widgets/buttons/iconButton'
|
2020-11-19 23:50:17 +01:00
|
|
|
import CloseIcon from '../widgets/icons/close'
|
|
|
|
import OptionsIcon from '../widgets/icons/options'
|
|
|
|
import MenuWrapper from '../widgets/menuWrapper'
|
2020-10-25 19:23:23 +01:00
|
|
|
import './dialog.scss'
|
|
|
|
|
2020-10-15 19:46:32 +02:00
|
|
|
type Props = {
|
|
|
|
children: React.ReactNode
|
|
|
|
toolsMenu: React.ReactNode
|
2020-10-20 21:50:53 +02:00
|
|
|
onClose: () => void
|
2020-10-15 19:46:32 +02:00
|
|
|
}
|
|
|
|
|
2020-10-25 19:23:23 +01:00
|
|
|
export default class Dialog extends React.PureComponent<Props> {
|
|
|
|
public componentDidMount(): void {
|
|
|
|
document.addEventListener('keydown', this.keydownHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillUnmount(): void {
|
|
|
|
document.removeEventListener('keydown', this.keydownHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
private keydownHandler = (e: KeyboardEvent): void => {
|
2020-10-20 21:50:53 +02:00
|
|
|
if (e.target !== document.body) {
|
|
|
|
return
|
|
|
|
}
|
2020-10-15 19:46:32 +02:00
|
|
|
|
|
|
|
if (e.keyCode === 27) {
|
2020-11-19 23:50:17 +01:00
|
|
|
this.closeClicked()
|
2020-10-15 19:46:32 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 19:23:23 +01:00
|
|
|
public render(): JSX.Element {
|
2020-10-15 19:46:32 +02:00
|
|
|
const {toolsMenu} = this.props
|
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
return (
|
|
|
|
<div
|
2020-10-25 19:23:23 +01:00
|
|
|
className='Dialog dialog-back'
|
2020-10-20 21:50:53 +02:00
|
|
|
onMouseDown={(e) => {
|
|
|
|
if (e.target === e.currentTarget) {
|
2020-11-19 23:50:17 +01:00
|
|
|
this.closeClicked()
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
|
|
|
}}
|
2020-10-15 19:46:32 +02:00
|
|
|
>
|
2020-10-20 21:50:53 +02:00
|
|
|
<div className='dialog' >
|
2020-10-15 19:46:32 +02:00
|
|
|
{toolsMenu &&
|
2020-10-20 21:50:53 +02:00
|
|
|
<div className='toolbar'>
|
2020-11-19 23:50:17 +01:00
|
|
|
<IconButton
|
|
|
|
onClick={this.closeClicked}
|
|
|
|
icon={<CloseIcon/>}
|
|
|
|
title={'Close dialog'}
|
2020-12-02 18:28:52 +01:00
|
|
|
className='hideOnWidescreen'
|
2020-11-19 23:50:17 +01:00
|
|
|
/>
|
2020-10-20 21:50:53 +02:00
|
|
|
<div className='octo-spacer'/>
|
|
|
|
<MenuWrapper>
|
2020-10-31 17:30:56 +01:00
|
|
|
<IconButton icon={<OptionsIcon/>}/>
|
2020-10-20 21:50:53 +02:00
|
|
|
{toolsMenu}
|
|
|
|
</MenuWrapper>
|
|
|
|
</div>}
|
2020-10-15 19:46:32 +02:00
|
|
|
{this.props.children}
|
2020-10-25 19:23:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-15 19:46:32 +02:00
|
|
|
)
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
2020-11-19 23:50:17 +01:00
|
|
|
|
|
|
|
private closeClicked = () => {
|
|
|
|
this.props.onClose()
|
|
|
|
}
|
2020-10-15 19:46:32 +02:00
|
|
|
}
|