focalboard/webapp/src/components/boardColumn.tsx

57 lines
1.6 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-08 18:21:27 +02:00
type Props = {
2020-10-20 21:50:53 +02:00
onDrop?: (e: React.DragEvent<HTMLDivElement>) => void
2020-10-28 18:46:36 +01:00
isDropZone?: boolean
2020-10-08 18:21:27 +02:00
}
type State = {
2020-10-20 21:50:53 +02:00
isDragOver?: boolean
2020-10-28 18:46:36 +01:00
dragPageX?: number
dragPageY?: number
2020-10-08 18:21:27 +02:00
}
class BoardColumn extends React.Component<Props, State> {
2020-10-20 21:50:53 +02:00
constructor(props: Props) {
super(props)
this.state = {}
}
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
render() {
2020-10-28 18:46:36 +01:00
let className = 'octo-board-column'
if (this.props.isDropZone && this.state.isDragOver) {
className += ' dragover'
}
2020-10-20 21:50:53 +02:00
const element =
(<div
2020-10-28 18:46:36 +01:00
className={className}
2020-10-20 21:50:53 +02:00
onDragOver={(e) => {
2020-10-24 03:29:38 +02:00
e.preventDefault()
2020-10-28 18:46:36 +01:00
this.setState({isDragOver: true, dragPageX: e.pageX, dragPageY: e.pageY})
2020-10-20 21:50:53 +02:00
}}
onDragEnter={(e) => {
2020-10-24 03:29:38 +02:00
e.preventDefault()
2020-10-28 18:46:36 +01:00
this.setState({isDragOver: true, dragPageX: e.pageX, dragPageY: e.pageY})
2020-10-20 21:50:53 +02:00
}}
onDragLeave={(e) => {
2020-10-24 03:29:38 +02:00
e.preventDefault()
2020-10-28 18:46:36 +01:00
this.setState({isDragOver: false, dragPageX: undefined, dragPageY: undefined})
2020-10-20 21:50:53 +02:00
}}
onDrop={(e) => {
2020-10-28 18:46:36 +01:00
this.setState({isDragOver: false, dragPageX: undefined, dragPageY: undefined})
if (this.props.isDropZone) {
this.props.onDrop(e)
}
2020-10-20 21:50:53 +02:00
}}
>
{this.props.children}
</div>)
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
return element
}
2020-10-08 18:21:27 +02:00
}
2020-10-20 21:50:53 +02:00
export {BoardColumn}