focalboard/webapp/src/components/boardColumn.tsx

58 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-11-13 02:24:24 +01:00
onDrop: (e: React.DragEvent<HTMLDivElement>) => void
isDropZone: boolean
2020-10-08 18:21:27 +02:00
}
type State = {
2020-11-13 02:24:24 +01:00
isDragOver: boolean
2020-10-08 18:21:27 +02:00
}
2020-11-13 02:24:24 +01:00
class BoardColumn extends React.PureComponent<Props, State> {
state = {
isDragOver: false,
2020-10-20 21:50:53 +02:00
}
2020-10-08 18:21:27 +02:00
2020-11-13 02:24:24 +01:00
render(): JSX.Element {
2020-10-28 18:46:36 +01:00
let className = 'octo-board-column'
if (this.props.isDropZone && this.state.isDragOver) {
className += ' dragover'
}
2020-11-13 02:24:24 +01: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-11-09 19:02:54 +01:00
if (!this.state.isDragOver) {
this.setState({isDragOver: true})
}
2020-10-20 21:50:53 +02:00
}}
onDragEnter={(e) => {
2020-10-24 03:29:38 +02:00
e.preventDefault()
2020-11-09 19:02:54 +01:00
if (!this.state.isDragOver) {
this.setState({isDragOver: true})
}
2020-10-20 21:50:53 +02:00
}}
onDragLeave={(e) => {
2020-10-24 03:29:38 +02:00
e.preventDefault()
2020-11-09 19:02:54 +01:00
this.setState({isDragOver: false})
2020-10-20 21:50:53 +02:00
}}
onDrop={(e) => {
2020-11-09 19:02:54 +01:00
this.setState({isDragOver: false})
2020-10-28 18:46:36 +01:00
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}