-
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.
Prepare Hooks API for Initial Release (#1251)
* refactor: split up useMonitorSubscription into two hooks * fix: resolve two-backend issue When the DragDropProvider is removed from the DOM, it was not emitting a message to the DragDropManager so that it could handle refcounts properly and break-down the HTML5Backend. This change adds a useEffect hook invocation to fire off an event that will cause the DnDManager to destroy the backend. * refactor: update the react peer dependency of React-Dnd * refactor: clean up monitor modules
- Loading branch information
1 parent
5a4005b
commit 7f78a8b
Showing
19 changed files
with
202 additions
and
181 deletions.
There are no files selected for viewing
51 changes: 25 additions & 26 deletions
51
packages/documentation-examples/src/00 Chessboard/Board.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 |
---|---|---|
@@ -1,47 +1,46 @@ | ||
import * as React from 'react' | ||
import { BoardSquare } from './BoardSquare' | ||
import { Knight } from './Knight' | ||
|
||
export interface BoardProps { | ||
knightPosition: [number, number] | ||
} | ||
|
||
export default class Board extends React.Component<BoardProps> { | ||
public render() { | ||
const squares = [] | ||
for (let i = 0; i < 64; i += 1) { | ||
squares.push(this.renderSquare(i)) | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}} | ||
> | ||
{squares} | ||
</div> | ||
) | ||
} | ||
|
||
private renderSquare(i: number) { | ||
const Board: React.FC<BoardProps> = ({ | ||
knightPosition: [knightX, knightY], | ||
}) => { | ||
function renderSquare(i: number) { | ||
const x = i % 8 | ||
const y = Math.floor(i / 8) | ||
|
||
return ( | ||
<div key={i} style={{ width: '12.5%', height: '12.5%' }}> | ||
<BoardSquare x={x} y={y}> | ||
{this.renderPiece(x, y)} | ||
{renderPiece(x, y)} | ||
</BoardSquare> | ||
</div> | ||
) | ||
} | ||
|
||
private renderPiece(x: number, y: number) { | ||
const [knightX, knightY] = this.props.knightPosition | ||
function renderPiece(x: number, y: number) { | ||
const isKnightHere = x === knightX && y === knightY | ||
return isKnightHere ? <Knight /> : null | ||
} | ||
|
||
const squares = [] | ||
for (let i = 0; i < 64; i += 1) { | ||
squares.push(renderSquare(i)) | ||
} | ||
return ( | ||
<div | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
}} | ||
> | ||
{squares} | ||
</div> | ||
) | ||
} | ||
export default Board |
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,17 @@ | ||
import * as React from 'react' | ||
import { DragDropManager } from 'dnd-core' | ||
|
||
/** | ||
* The React context type | ||
*/ | ||
export interface DragDropContext<BC> { | ||
dragDropManager: DragDropManager<BC> | undefined | ||
} | ||
|
||
/** | ||
* Create the React Context | ||
*/ | ||
export const context = React.createContext<DragDropContext<any>>({ | ||
dragDropManager: undefined, | ||
}) | ||
export const { Consumer, Provider } = context |
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
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
Oops, something went wrong.