-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: remove example cross-referencing
- Loading branch information
1 parent
ba4ec05
commit ec096a5
Showing
15 changed files
with
228 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/examples-hooks/src/01-dustbin/copy-or-move/Dustbin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/examples-hooks/src/01-dustbin/copy-or-move/ItemTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
BOX: 'box', | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/examples-hooks/src/01-dustbin/single-target-in-iframe/Box.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd' | ||
import ItemTypes from './ItemTypes' | ||
const { | ||
useDrag, | ||
} = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ | ||
|
||
const style: React.CSSProperties = { | ||
border: '1px dashed gray', | ||
backgroundColor: 'white', | ||
padding: '0.5rem 1rem', | ||
marginRight: '1.5rem', | ||
marginBottom: '1.5rem', | ||
cursor: 'move', | ||
float: 'left', | ||
} | ||
|
||
interface BoxProps { | ||
name: string | ||
} | ||
|
||
const Box: React.FC<BoxProps> = ({ name }) => { | ||
const [{ isDragging }, drag] = useDrag({ | ||
item: { name, type: ItemTypes.BOX }, | ||
end: (dropResult?: { name: string }) => { | ||
if (dropResult) { | ||
alert(`You dropped ${name} into ${dropResult.name}!`) | ||
} | ||
}, | ||
collect: monitor => ({ | ||
isDragging: monitor.isDragging(), | ||
}), | ||
}) | ||
const opacity = isDragging ? 0.4 : 1 | ||
|
||
return ( | ||
<div ref={drag} style={{ ...style, opacity }}> | ||
{name} | ||
</div> | ||
) | ||
} | ||
|
||
export default Box |
47 changes: 47 additions & 0 deletions
47
packages/examples-hooks/src/01-dustbin/single-target-in-iframe/Dustbin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react' | ||
import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd' | ||
import ItemTypes from './ItemTypes' | ||
|
||
const { | ||
useDrop, | ||
} = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ | ||
|
||
const style: React.CSSProperties = { | ||
height: '12rem', | ||
width: '12rem', | ||
marginRight: '1.5rem', | ||
marginBottom: '1.5rem', | ||
color: 'white', | ||
padding: '1rem', | ||
textAlign: 'center', | ||
fontSize: '1rem', | ||
lineHeight: 'normal', | ||
float: 'left', | ||
} | ||
|
||
const Dustbin: React.FC = () => { | ||
const [{ canDrop, isOver }, drop] = useDrop({ | ||
accept: ItemTypes.BOX, | ||
drop: () => ({ name: 'Dustbin' }), | ||
collect: monitor => ({ | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}), | ||
}) | ||
|
||
const isActive = canDrop && isOver | ||
let backgroundColor = '#222' | ||
if (isActive) { | ||
backgroundColor = 'darkgreen' | ||
} else if (canDrop) { | ||
backgroundColor = 'darkkhaki' | ||
} | ||
|
||
return ( | ||
<div ref={drop} style={{ ...style, backgroundColor }}> | ||
{isActive ? 'Release to drop' : 'Drag a box here'} | ||
</div> | ||
) | ||
} | ||
|
||
export default Dustbin |
3 changes: 3 additions & 0 deletions
3
packages/examples-hooks/src/01-dustbin/single-target-in-iframe/ItemTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
BOX: 'box', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
BOX: 'box', | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/examples/src/01-dustbin/single-target-in-iframe/Box.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react' | ||
import { | ||
DragSource, | ||
DragSourceMonitor, | ||
ConnectDragSource, | ||
DragSourceConnector, | ||
} from 'react-dnd' | ||
import ItemTypes from './ItemTypes' | ||
|
||
const style: React.CSSProperties = { | ||
border: '1px dashed gray', | ||
backgroundColor: 'white', | ||
padding: '0.5rem 1rem', | ||
marginRight: '1.5rem', | ||
marginBottom: '1.5rem', | ||
cursor: 'move', | ||
float: 'left', | ||
} | ||
|
||
export interface BoxProps { | ||
name: string | ||
|
||
// Collected Props | ||
isDragging: boolean | ||
connectDragSource: ConnectDragSource | ||
} | ||
const Box: React.FC<BoxProps> = ({ name, isDragging, connectDragSource }) => { | ||
const opacity = isDragging ? 0.4 : 1 | ||
return ( | ||
<div ref={connectDragSource} style={{ ...style, opacity }}> | ||
{name} | ||
</div> | ||
) | ||
} | ||
|
||
export default DragSource( | ||
ItemTypes.BOX, | ||
{ | ||
beginDrag: (props: BoxProps) => ({ name: props.name }), | ||
endDrag(props: BoxProps, monitor: DragSourceMonitor) { | ||
const item = monitor.getItem() | ||
const dropResult = monitor.getDropResult() | ||
|
||
if (dropResult) { | ||
alert(`You dropped ${item.name} into ${dropResult.name}!`) | ||
} | ||
}, | ||
}, | ||
(connect: DragSourceConnector, monitor: DragSourceMonitor) => ({ | ||
connectDragSource: connect.dragSource(), | ||
isDragging: monitor.isDragging(), | ||
}), | ||
)(Box) |
59 changes: 59 additions & 0 deletions
59
packages/examples/src/01-dustbin/single-target-in-iframe/Dustbin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react' | ||
import { | ||
DropTarget, | ||
ConnectDropTarget, | ||
DropTargetMonitor, | ||
DropTargetConnector, | ||
} from 'react-dnd' | ||
import ItemTypes from './ItemTypes' | ||
|
||
const style: React.CSSProperties = { | ||
height: '12rem', | ||
width: '12rem', | ||
marginRight: '1.5rem', | ||
marginBottom: '1.5rem', | ||
color: 'white', | ||
padding: '1rem', | ||
textAlign: 'center', | ||
fontSize: '1rem', | ||
lineHeight: 'normal', | ||
float: 'left', | ||
} | ||
|
||
export interface DustbinProps { | ||
canDrop: boolean | ||
isOver: boolean | ||
connectDropTarget: ConnectDropTarget | ||
} | ||
|
||
const Dustbin: React.FC<DustbinProps> = ({ | ||
canDrop, | ||
isOver, | ||
connectDropTarget, | ||
}) => { | ||
const isActive = canDrop && isOver | ||
let backgroundColor = '#222' | ||
if (isActive) { | ||
backgroundColor = 'darkgreen' | ||
} else if (canDrop) { | ||
backgroundColor = 'darkkhaki' | ||
} | ||
|
||
return ( | ||
<div ref={connectDropTarget} style={{ ...style, backgroundColor }}> | ||
{isActive ? 'Release to drop' : 'Drag a box here'} | ||
</div> | ||
) | ||
} | ||
|
||
export default DropTarget( | ||
ItemTypes.BOX, | ||
{ | ||
drop: () => ({ name: 'Dustbin' }), | ||
}, | ||
(connect: DropTargetConnector, monitor: DropTargetMonitor) => ({ | ||
connectDropTarget: connect.dropTarget(), | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}), | ||
)(Dustbin) |
3 changes: 3 additions & 0 deletions
3
packages/examples/src/01-dustbin/single-target-in-iframe/ItemTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
BOX: 'box', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters