Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add html handling in native types (#2949)
* add html handling in native types * add release strategy * add documentation
- Loading branch information
Showing
11 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
releases: | ||
react-dnd-documentation: patch | ||
react-dnd-examples-decorators: patch | ||
react-dnd-examples-hooks: patch | ||
react-dnd-html5-backend: patch |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const FILE = '__NATIVE_FILE__' | ||
export const URL = '__NATIVE_URL__' | ||
export const TEXT = '__NATIVE_TEXT__' | ||
export const HTML = '__NATIVE_HTML__' |
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,10 @@ | ||
--- | ||
path: '/examples/other/native-html' | ||
title: 'Native Html' | ||
--- | ||
|
||
Example demonstrating drag and drop of native html. | ||
Works great for dragging images from another tab or iframe. | ||
|
||
<view-source name="06-other/native-html" component="other-native-html"> | ||
</view-source> |
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
27 changes: 27 additions & 0 deletions
27
packages/examples-hooks/src/06-other/native-html/Container.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,27 @@ | ||
import React from 'react' | ||
import { useState, useCallback } from 'react' | ||
import { DropTargetMonitor } from 'react-dnd' | ||
import { TargetBox } from './TargetBox' | ||
import { HTMLContent } from './HTMLContent' | ||
|
||
export const Container: React.FC = () => { | ||
const [droppedHTML, setDroppedHTML] = useState<string>('') | ||
|
||
const handleHTMLDrop = useCallback( | ||
(item: any, monitor: DropTargetMonitor) => { | ||
if (monitor) { | ||
const html = monitor.getItem().html | ||
setDroppedHTML(html) | ||
} | ||
}, | ||
[], | ||
) | ||
|
||
return ( | ||
<> | ||
<iframe srcDoc={`<img src='https://react-dnd.github.io/react-dnd/favicon-32x32.png' />`} /> | ||
<TargetBox onDrop={handleHTMLDrop} /> | ||
<HTMLContent html={droppedHTML} /> | ||
</> | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/examples-hooks/src/06-other/native-html/HTMLContent.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,15 @@ | ||
import React from 'react' | ||
|
||
export interface HTMLContentProps { | ||
html: string | ||
} | ||
|
||
export const HTMLContent: React.FC<HTMLContentProps> = ({ html }) => { | ||
if (html.length === 0) { | ||
return <div>Nothing to display</div> | ||
} | ||
|
||
return <div> | ||
{html} | ||
</div> | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/examples-hooks/src/06-other/native-html/TargetBox.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,38 @@ | ||
import React from 'react' | ||
import { NativeTypes } from 'react-dnd-html5-backend' | ||
import { useDrop, DropTargetMonitor } from 'react-dnd' | ||
|
||
const style: React.CSSProperties = { | ||
border: '1px solid gray', | ||
height: '15rem', | ||
width: '15rem', | ||
padding: '2rem', | ||
textAlign: 'center', | ||
} | ||
|
||
export interface TargetBoxProps { | ||
onDrop: (props: TargetBoxProps, monitor: DropTargetMonitor) => void | ||
} | ||
|
||
export const TargetBox: React.FC<TargetBoxProps> = (props) => { | ||
const { onDrop } = props | ||
const [{ canDrop, isOver }, drop] = useDrop({ | ||
accept: [NativeTypes.HTML], | ||
drop(item, monitor) { | ||
if (onDrop) { | ||
onDrop(props, monitor) | ||
} | ||
}, | ||
collect: (monitor) => ({ | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}), | ||
}) | ||
|
||
const isActive = canDrop && isOver | ||
return ( | ||
<div ref={drop} style={style}> | ||
{isActive ? 'Release to drop' : 'Drag HTML here'} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export { Container as default } from './Container' |
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