From 27199a1c01c004a84dfee10f720278a16798be83 Mon Sep 17 00:00:00 2001 From: Jeff Carbonella Date: Sun, 2 Oct 2016 01:41:32 -0400 Subject: [PATCH] feat(ComponentExample): add copy JSX button (#574) --- .../Components/ComponentDoc/ComponentExample.js | 16 ++++++++++++++++ package.json | 1 + 2 files changed, 17 insertions(+) diff --git a/docs/app/Components/ComponentDoc/ComponentExample.js b/docs/app/Components/ComponentDoc/ComponentExample.js index a6646b9a54..cc4c9686d0 100644 --- a/docs/app/Components/ComponentDoc/ComponentExample.js +++ b/docs/app/Components/ComponentDoc/ComponentExample.js @@ -3,6 +3,7 @@ import _ from 'lodash' import React, { Component, createElement, isValidElement, PropTypes } from 'react' import { renderToStaticMarkup } from 'react-dom/server' import { html } from 'js-beautify' +import copyToClipboard from 'copy-to-clipboard' import { exampleContext } from 'docs/app/utils' import { Label, Divider, Grid, Icon, Header } from 'src' @@ -80,6 +81,12 @@ export default class ComponentExample extends Component { }) } + copyToClipboard = () => { + const { sourceCode } = this.state + copyToClipboard(sourceCode) + alert('Copied to clipboard!') + } + resetEditor = () => { const sourceCode = this.getOriginalSourceCode() this.setState({ sourceCode }) @@ -193,6 +200,15 @@ export default class ComponentExample extends Component { return ( +