Created
February 11, 2018 14:10
-
-
Save yarnball/0600caaac71c3e0bc03cac60b1da9cf1 to your computer and use it in GitHub Desktop.
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
import React from "react" | |
import { render } from "react-dom" | |
class App extends React.Component { | |
state = { highlight: "", pos: "" } | |
getText = e => { | |
this.setState({ | |
highlight: window.getSelection().toString(), | |
pos: window.getSelection() | |
}) | |
} | |
render() { | |
const { highlight, pos } = this.state | |
return ( | |
<div> | |
<div onClick={this.getText}> I am a body of text</div> | |
<h4> Highlighted: </h4> | |
<div style={{ background: "yellow" }}> | |
TEXT: {highlight} | |
<br /> | |
POSITION: | |
{pos.anchorOffset} to | |
{pos.extentOffset} | |
</div> | |
</div> | |
) | |
} | |
} | |
render(<App />, document.getElementById("root")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment