Add 'Copy to Clipboard' icon in Accounts Header (#2167) (#2716)

This commit is contained in:
Nicolas Gotchac 2016-10-19 12:24:22 +01:00 committed by Gav Wood
parent cf170418d5
commit dd89ecea43

View File

@ -15,6 +15,11 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
import IconButton from 'material-ui/IconButton';
import Snackbar from 'material-ui/Snackbar';
import CopyIcon from 'material-ui/svg-icons/content/content-copy';
import { lightWhite, fullWhite, lightBlack } from 'material-ui/styles/colors';
import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags } from '../../../ui'; import { Balance, Container, ContainerTitle, IdentityIcon, IdentityName, Tags } from '../../../ui';
@ -32,7 +37,8 @@ export default class Header extends Component {
} }
state = { state = {
name: null name: null,
addressCopied: false
} }
componentWillMount () { componentWillMount () {
@ -45,6 +51,7 @@ export default class Header extends Component {
render () { render () {
const { account, balance } = this.props; const { account, balance } = this.props;
const { addressCopied } = this.state;
const { address, meta, uuid } = account; const { address, meta, uuid } = account;
if (!account) { if (!account) {
@ -62,6 +69,35 @@ export default class Header extends Component {
<div className={ styles.floatleft }> <div className={ styles.floatleft }>
<ContainerTitle title={ <IdentityName address={ address } unknown /> } /> <ContainerTitle title={ <IdentityName address={ address } unknown /> } />
<div className={ styles.addressline }> <div className={ styles.addressline }>
<Snackbar
open={ addressCopied }
message={ `Address ${address} copied to clipboard` }
autoHideDuration={ 4000 }
onRequestClose={ this.handleCopyAddressClose }
bodyStyle={ {
backgroundColor: lightBlack
} }
/>
<CopyToClipboard
onCopy={ this.handleCopyAddress }
text={ address } >
<IconButton
tooltip='Copy address to clipboard'
tooltipPosition='top-center'
style={ {
width: 32,
height: 16,
padding: 0
} }
iconStyle={ {
width: 16,
height: 16
} }>
<CopyIcon
color={ addressCopied ? lightWhite : fullWhite }
/>
</IconButton>
</CopyToClipboard>
{ address } { address }
</div> </div>
{ uuidText } { uuidText }
@ -111,6 +147,14 @@ export default class Header extends Component {
}); });
} }
handleCopyAddress = () => {
this.setState({ addressCopied: true });
}
handleCopyAddressClose = () => {
this.setState({ addressCopied: false });
}
setName () { setName () {
const { account } = this.props; const { account } = this.props;