flex-grow: 5;
font-family: monospace;
font-size: 12px;
+ position: relative;
}
.hextrapolate-field input {
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj48cGF0aCBmaWxsPSIjNDQ0IiBkPSJNMjAgOFYwSDZMMCA2djE4aDEydjhoMjBWOEgyMHpNNiAyLjgyOFY2SDIuODI4TDYgMi44Mjh6TTIgMjJWOGg2VjJoMTB2NmwtNiA2djhIMnptMTYtMTEuMTcyVjE0aC0zLjE3MkwxOCAxMC44Mjh6TTMwIDMwSDE0VjE2aDZ2LTZoMTB2MjB6Ii8+PC9zdmc+);
background-repeat: no-repeat;
background-size: 16px 16px;
+ cursor: pointer;
display: inline-block;
height: 16px;
margin-left: 8px;
position: relative;
text-indent: -10000px;
top: 4px;
+ user-select: none;
width: 16px;
}
+
+.hextrapolate-copy-status {
+ color: #0f0;
+ opacity: 0;
+ position: absolute;
+ top: 4px;
+ right: 4px;
+ transform: scale(1);
+ transition: transform .25s, opacity .25s;
+ user-select: none;
+}
+
+.hextrapolate-copy-success {
+ transform: scale(5);
+ opacity: .5;
+ transition: transform .5s, opacity .5s;
+}
import React from 'react';
import convert from './convert';
+import cx from 'classnames';
export type Value = {
base: number;
`base prop must be between 2..${DIGITS.length}`
);
}
+ this.state = {copySucceeded: false};
}
_isValid(value: string): boolean {
}
}
- _onCopy = () => {
+ _onCopy = event => {
+ event.preventDefault();
+ event.stopPropagation();
React.findDOMNode(this._input).select();
// May throw a SecurityError.
try {
- document.execCommand('copy');
+ this.setState({
+ copySucceeded: document.execCommand('copy'),
+ });
+ setTimeout(() => this.setState({copySucceeded: false}), 750);
} catch(error) { // eslint-disable-line no-empty
// Swallow.
+ this.setState({copySucceeded: false});
}
}
);
}
+ _copyStatus() {
+ const classNames = cx({
+ 'hextrapolate-copy-status': true,
+ 'hextrapolate-copy-success': this.state.copySucceeded,
+ });
+ return <span className={classNames}>✓</span>;
+ }
+
focus() {
React.findDOMNode(this._input).focus();
}
type="text"
value={fromValue(this.props.value, this.props.base)}
/>
+ {this._copyStatus()}
{this._copyLink()}
</span>
);