From 93f3f5af3dc4fdc45b8ae4a3d0ea1e3e878d73bf Mon Sep 17 00:00:00 2001 From: omergulen Date: Mon, 18 May 2020 22:42:24 +0300 Subject: [PATCH] App :: Add copy to clipboard button on code view --- src/App.js | 31 +++++++++++++++++++++++++++++++ src/index.css | 9 ++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index ee6f4cb..87dc031 100644 --- a/src/App.js +++ b/src/App.js @@ -50,6 +50,20 @@ const tabletIcon = ( ); +const clipboardIcon = ( + + + + +); + const viewList = [ { icon: desktopIcon, @@ -87,6 +101,7 @@ class App extends Component { this.changeView = this.changeView.bind(this); this.toggleSidebar = this.toggleSidebar.bind(this); this.toggleView = this.toggleView.bind(this); + this.copyToClipboard = this.copyToClipboard.bind(this); this.markupRef = React.createRef(); this.textareaRef = React.createRef(); } @@ -188,6 +203,16 @@ class App extends Component { this.setState({ sidebar: !this.state.sidebar }); } + copyToClipboard() { + const code = this.beautifyHTML(this.state.markup); + var input = document.createElement('textarea'); + input.innerHTML = code; + document.body.appendChild(input); + input.select(); + document.execCommand('copy'); + document.body.removeChild(input); +} + render() { const { darkMode, theme, blockName, blockType, sidebar, view } = this.state; return ( @@ -198,6 +223,12 @@ class App extends Component {
+ {this.state.codeView ? ( + ) : '' + }