Skip to content

Commit

Permalink
feat(ComponentExample): add copy JSX button (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Oct 2, 2016
1 parent bceb7ef commit 27199a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/app/Components/ComponentDoc/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -193,6 +200,15 @@ export default class ComponentExample extends Component {
return (
<Grid.Column style={style}>
<Divider horizontal>
<Label
as='a'
basic
horizontal
color={error ? 'red' : 'green'}
icon='copy'
content={error ? 'See Error' : 'JSX'}
onClick={this.copyToClipboard}
/>
<Label
as='a'
basic
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"chai": "^3.3.0",
"chai-enzyme": "^0.5.0",
"connect-history-api-fallback": "^1.2.0",
"copy-to-clipboard": "^3.0.5",
"cross-env": "^2.0.0",
"css-loader": "^0.23.1",
"del": "^2.2.2",
Expand Down

0 comments on commit 27199a1

Please sign in to comment.