mirror of https://github.com/embarklabs/embark.git
create CopyButton component to wrap arround CopyToClipboard
This commit is contained in:
parent
261b4eddf3
commit
bd4f4726b3
|
@ -1,7 +1,6 @@
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
|
||||||
InputGroup,
|
InputGroup,
|
||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
|
@ -13,7 +12,7 @@ import {
|
||||||
InputGroupAddon,
|
InputGroupAddon,
|
||||||
Label
|
Label
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
import {CopyToClipboard} from 'react-copy-to-clipboard';
|
import CopyButton from './CopyButton';
|
||||||
|
|
||||||
import { calculateUnits } from '../services/unitConverter';
|
import { calculateUnits } from '../services/unitConverter';
|
||||||
|
|
||||||
|
@ -50,9 +49,7 @@ class Converter extends React.Component {
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<Input id={unit.name} placeholder={unit.name} value={unit.value} onChange={e => this.handleOnChange(e, unit.key)} />
|
<Input id={unit.name} placeholder={unit.name} value={unit.value} onChange={e => this.handleOnChange(e, unit.key)} />
|
||||||
<InputGroupAddon addonType="append">
|
<InputGroupAddon addonType="append">
|
||||||
<CopyToClipboard text={unit.value} title="Copy value to clipboard">
|
<CopyButton text={unit.value} title="Copy value to clipboard" size={2}/>
|
||||||
<Button color="primary"><i className="fa fa-copy"></i></Button>
|
|
||||||
</CopyToClipboard>
|
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
.copy-to-clipboard {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import {Badge} from "reactstrap";
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import {CopyToClipboard} from 'react-copy-to-clipboard';
|
||||||
|
|
||||||
|
import './CopyButton.css';
|
||||||
|
|
||||||
|
const CopyButton = ({text, onCopy, title, size}) => (
|
||||||
|
<CopyToClipboard text={text}
|
||||||
|
onCopy={onCopy}
|
||||||
|
title={title}>
|
||||||
|
<Badge className={classNames('copy-to-clipboard', 'p-' + (size ? size : 3))}
|
||||||
|
color="primary"><i className="fa fa-copy"/></Badge>
|
||||||
|
</CopyToClipboard>
|
||||||
|
);
|
||||||
|
|
||||||
|
CopyButton.propTypes = {
|
||||||
|
text: PropTypes.string.isRequired,
|
||||||
|
onCopy: PropTypes.func,
|
||||||
|
title: PropTypes.string,
|
||||||
|
size: PropTypes.number
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CopyButton;
|
|
@ -1,7 +1,7 @@
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {Card, CardBody, CardHeader, CardTitle, Row, Col, Input, Badge} from 'reactstrap';
|
import {Card, CardBody, CardHeader, CardTitle, Row, Col, Input, Badge} from 'reactstrap';
|
||||||
import {CopyToClipboard} from 'react-copy-to-clipboard';
|
import CopyButton from './CopyButton';
|
||||||
|
|
||||||
const COLORS = {
|
const COLORS = {
|
||||||
good: 'success',
|
good: 'success',
|
||||||
|
@ -95,11 +95,9 @@ class GasStation extends Component {
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>
|
<CardTitle>
|
||||||
Gas Price Estimator
|
Gas Price Estimator
|
||||||
<CopyToClipboard text={currentGasStep.gasPrice / this.PRICE_UNIT_DIVIDER}
|
<CopyButton text={currentGasStep.gasPrice / this.PRICE_UNIT_DIVIDER}
|
||||||
onCopy={() => this.setState({copied: true})}
|
onCopy={() => this.setState({copied: true})}
|
||||||
title="Copy gas price to clipboard">
|
title="Copy gas price to clipboard"/>
|
||||||
<Badge className="p-3" color="primary"><i className="fa fa-copy"/></Badge>
|
|
||||||
</CopyToClipboard>
|
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.relative {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue