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 105105 "testMatch" : [
106106 " <rootDir>/packages/**/__tests__/**/?(*.)(spec|test).(t|j)s(x|)"
107107 ],
108+ "testPathIgnorePatterns" : [
109+ " /packages/documentation/static/" ,
110+ " /packages/documentation/public/"
111+ ],
108112 "transform" : {
109113 "^.+\\ .(ts|tsx)$" : " ts-jest"
110114 },
Original file line number Diff line number Diff line change 11import React from 'react'
2- import ItemTypes from '../single-target /ItemTypes'
2+ import ItemTypes from './ItemTypes'
33
44import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
55const {
Original file line number Diff line number Diff line change 11import React from 'react'
22import { __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'
44const {
55 useDrop,
66} = __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 66 DragDropContextProvider ,
77} from 'react-dnd'
88import 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'
1211
1312const {
1413 default : Frame ,
@@ -18,11 +17,7 @@ const {
1817const FrameBindingContext : React . FC = ( { children } ) => (
1918 < FrameContextConsumer >
2019 { ( { window } : any ) => (
21- < DragDropContextProvider
22- backend = { HTML5Backend }
23- context = { window }
24- debugMode = { isDebugMode ( ) }
25- >
20+ < DragDropContextProvider backend = { HTML5Backend } context = { window } >
2621 { children }
2722 </ DragDropContextProvider >
2823 ) }
Original file line number Diff line number Diff line change 55 DragSourceConnector ,
66 DragSourceMonitor ,
77} from 'react-dnd'
8- import ItemTypes from '../single-target /ItemTypes'
8+ import ItemTypes from './ItemTypes'
99
1010const style : React . CSSProperties = {
1111 border : '1px dashed gray' ,
Original file line number Diff line number Diff line change 11import React from 'react'
22import { DropTarget , ConnectDropTarget } from 'react-dnd'
3- import ItemTypes from '../single-target /ItemTypes'
3+ import ItemTypes from './ItemTypes'
44
55const style : React . CSSProperties = {
66 height : '12rem' ,
You can’t perform that action at this time.
0 commit comments