focalboard/webapp/src/components/dialog.tsx

68 lines
1.8 KiB
TypeScript
Raw Normal View History

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-20 21:52:56 +02:00
import MenuWrapper from '../widgets/menuWrapper'
import OptionsIcon from '../widgets/icons/options'
import IconButton from '../widgets/buttons/iconButton'
import './dialog.scss'
type Props = {
children: React.ReactNode
toolsMenu: React.ReactNode
2020-10-20 21:50:53 +02:00
onClose: () => void
}
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 close(): void {
this.props.onClose()
}
private keydownHandler = (e: KeyboardEvent): void => {
2020-10-20 21:50:53 +02:00
if (e.target !== document.body) {
return
}
if (e.keyCode === 27) {
this.close()
e.stopPropagation()
}
}
public render(): JSX.Element {
const {toolsMenu} = this.props
2020-10-20 21:50:53 +02:00
return (
<div
className='Dialog dialog-back'
2020-10-20 21:50:53 +02:00
onMouseDown={(e) => {
if (e.target === e.currentTarget) {
this.close()
}
}}
>
2020-10-20 21:50:53 +02:00
<div className='dialog' >
{toolsMenu &&
2020-10-20 21:50:53 +02:00
<div className='toolbar'>
<div className='octo-spacer'/>
<MenuWrapper>
<IconButton icon={<OptionsIcon/>}/>
2020-10-20 21:50:53 +02:00
{toolsMenu}
</MenuWrapper>
</div>}
{this.props.children}
</div>
</div>
)
2020-10-20 21:50:53 +02:00
}
}