-
Notifications
You must be signed in to change notification settings - Fork 75
/
AllowDrag.js
46 lines (41 loc) · 1.08 KB
/
AllowDrag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Chessboard from '../Chessboard';
/* eslint react/display-name: 0 */
/* eslint react/prop-types: 0 */
class AllowDrag extends Component {
static propTypes = { children: PropTypes.func };
allowDrag = ({ piece }) => {
if (piece === 'wB' || piece === 'spare-wB') {
return false;
}
return true;
};
render() {
return this.props.children({ allowDrag: this.allowDrag });
}
}
export default function AllowDragFeature() {
return (
<div>
<AllowDrag>
{({ allowDrag }) => (
<Chessboard
id="allowDrag"
orientation="black"
calcWidth={({ screenWidth }) => (screenWidth < 500 ? 350 : 480)}
position="start"
boardStyle={{
borderRadius: '5px',
boxShadow: `0 5px 15px rgba(0, 0, 0, 0.5)`
}}
dropOffBoard="trash"
sparePieces={true}
allowDrag={allowDrag}
draggable={true}
/>
)}
</AllowDrag>
</div>
);
}