File tree Expand file tree Collapse file tree 15 files changed +228
-20
lines changed
examples-hooks/src/01-dustbin Expand file tree Collapse file tree 15 files changed +228
-20
lines changed Original file line number Diff line number Diff line change 105
105
"testMatch" : [
106
106
" <rootDir>/packages/**/__tests__/**/?(*.)(spec|test).(t|j)s(x|)"
107
107
],
108
+ "testPathIgnorePatterns" : [
109
+ " /packages/documentation/static/" ,
110
+ " /packages/documentation/public/"
111
+ ],
108
112
"transform" : {
109
113
"^.+\\ .(ts|tsx)$" : " ts-jest"
110
114
},
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
- import ItemTypes from '../single-target /ItemTypes'
2
+ import ItemTypes from './ItemTypes'
3
3
4
4
import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
5
5
const {
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
3
- import ItemTypes from '../single-target /ItemTypes'
3
+ import ItemTypes from './ItemTypes'
4
4
const {
5
5
useDrop,
6
6
} = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__
Original file line number Diff line number Diff line change
1
+ export default {
2
+ BOX : 'box' ,
3
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
3
+ import ItemTypes from './ItemTypes'
4
+ const {
5
+ useDrag,
6
+ } = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__
7
+
8
+ const style : React . CSSProperties = {
9
+ border : '1px dashed gray' ,
10
+ backgroundColor : 'white' ,
11
+ padding : '0.5rem 1rem' ,
12
+ marginRight : '1.5rem' ,
13
+ marginBottom : '1.5rem' ,
14
+ cursor : 'move' ,
15
+ float : 'left' ,
16
+ }
17
+
18
+ interface BoxProps {
19
+ name : string
20
+ }
21
+
22
+ const Box : React . FC < BoxProps > = ( { name } ) => {
23
+ const [ { isDragging } , drag ] = useDrag ( {
24
+ item : { name, type : ItemTypes . BOX } ,
25
+ end : ( dropResult ?: { name : string } ) => {
26
+ if ( dropResult ) {
27
+ alert ( `You dropped ${ name } into ${ dropResult . name } !` )
28
+ }
29
+ } ,
30
+ collect : monitor => ( {
31
+ isDragging : monitor . isDragging ( ) ,
32
+ } ) ,
33
+ } )
34
+ const opacity = isDragging ? 0.4 : 1
35
+
36
+ return (
37
+ < div ref = { drag } style = { { ...style , opacity } } >
38
+ { name }
39
+ </ div >
40
+ )
41
+ }
42
+
43
+ export default Box
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
3
+ import ItemTypes from './ItemTypes'
4
+
5
+ const {
6
+ useDrop,
7
+ } = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__
8
+
9
+ const style : React . CSSProperties = {
10
+ height : '12rem' ,
11
+ width : '12rem' ,
12
+ marginRight : '1.5rem' ,
13
+ marginBottom : '1.5rem' ,
14
+ color : 'white' ,
15
+ padding : '1rem' ,
16
+ textAlign : 'center' ,
17
+ fontSize : '1rem' ,
18
+ lineHeight : 'normal' ,
19
+ float : 'left' ,
20
+ }
21
+
22
+ const Dustbin : React . FC = ( ) => {
23
+ const [ { canDrop, isOver } , drop ] = useDrop ( {
24
+ accept : ItemTypes . BOX ,
25
+ drop : ( ) => ( { name : 'Dustbin' } ) ,
26
+ collect : monitor => ( {
27
+ isOver : monitor . isOver ( ) ,
28
+ canDrop : monitor . canDrop ( ) ,
29
+ } ) ,
30
+ } )
31
+
32
+ const isActive = canDrop && isOver
33
+ let backgroundColor = '#222'
34
+ if ( isActive ) {
35
+ backgroundColor = 'darkgreen'
36
+ } else if ( canDrop ) {
37
+ backgroundColor = 'darkkhaki'
38
+ }
39
+
40
+ return (
41
+ < div ref = { drop } style = { { ...style , backgroundColor } } >
42
+ { isActive ? 'Release to drop' : 'Drag a box here' }
43
+ </ div >
44
+ )
45
+ }
46
+
47
+ export default Dustbin
Original file line number Diff line number Diff line change
1
+ export default {
2
+ BOX : 'box' ,
3
+ }
Original file line number Diff line number Diff line change 6
6
DragDropContextProvider ,
7
7
} from 'react-dnd'
8
8
import HTML5Backend from 'react-dnd-html5-backend'
9
- import Dustbin from '../single-target/Dustbin'
10
- import Box from '../single-target/Box'
11
- import { isDebugMode } from '../../isDebugMode'
9
+ import Dustbin from './Dustbin'
10
+ import Box from './Box'
12
11
13
12
const {
14
13
default : Frame ,
@@ -18,11 +17,7 @@ const {
18
17
const FrameBindingContext : React . FC = ( { children } ) => (
19
18
< FrameContextConsumer >
20
19
{ ( { window } : any ) => (
21
- < DragDropContextProvider
22
- backend = { HTML5Backend }
23
- context = { window }
24
- debugMode = { isDebugMode ( ) }
25
- >
20
+ < DragDropContextProvider backend = { HTML5Backend } context = { window } >
26
21
{ children }
27
22
</ DragDropContextProvider >
28
23
) }
Original file line number Diff line number Diff line change 5
5
DragSourceConnector ,
6
6
DragSourceMonitor ,
7
7
} from 'react-dnd'
8
- import ItemTypes from '../single-target /ItemTypes'
8
+ import ItemTypes from './ItemTypes'
9
9
10
10
const style : React . CSSProperties = {
11
11
border : '1px dashed gray' ,
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { DropTarget , ConnectDropTarget } from 'react-dnd'
3
- import ItemTypes from '../single-target /ItemTypes'
3
+ import ItemTypes from './ItemTypes'
4
4
5
5
const style : React . CSSProperties = {
6
6
height : '12rem' ,
You can’t perform that action at this time.
0 commit comments