p5.js-web-editor/client/modules/IDE/components/CopyableInput.jsx

64 lines
1.5 KiB
React
Raw Normal View History

2017-10-30 19:38:41 +01:00
import React, { PropTypes } from 'react';
import Clipboard from 'clipboard';
class CopyableInput extends React.Component {
2017-10-30 22:24:43 +01:00
constructor(props) {
super(props);
this.onMouseLeaveHandler = this.onMouseLeaveHandler.bind(this);
}
2017-10-30 19:38:41 +01:00
componentDidMount() {
this.clipboard = new Clipboard(this.input, {
target: () => this.input
});
2017-10-30 22:24:43 +01:00
this.clipboard.on('success', (e) => {
this.tooltip.classList.add('tooltipped');
this.tooltip.classList.add('tooltipped-n');
});
2017-10-30 19:38:41 +01:00
}
componentWillUnmount() {
this.clipboard.destroy();
}
2017-10-30 22:24:43 +01:00
onMouseLeaveHandler() {
this.tooltip.classList.remove('tooltipped');
this.tooltip.classList.remove('tooltipped-n');
}
2017-10-30 19:38:41 +01:00
render() {
const {
label,
value
} = this.props;
return (
<div className="copyable-input">
<label className="copyable-input__label" htmlFor="copyable-input__value">{label}</label>
2017-10-30 22:24:43 +01:00
<div
2017-10-30 22:38:30 +01:00
className="copyable-input__value-container tooltipped-no-delay"
2017-10-30 22:24:43 +01:00
aria-label="Copied to Clipboard!"
ref={(element) => { this.tooltip = element; }}
onMouseLeave={this.onMouseLeaveHandler}
>
2017-10-30 19:38:41 +01:00
<input
type="text"
className="copyable-input__value"
id="copyable-input__value"
value={value}
ref={(element) => { this.input = element; }}
2017-10-30 22:24:43 +01:00
readOnly
2017-10-30 19:38:41 +01:00
/>
</div>
</div>
);
}
}
CopyableInput.propTypes = {
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired
};
export default CopyableInput;