wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
32 lines • 1.26 kB
JavaScript
import { __extends } from "tslib";
import * as React from 'react';
import copy from 'copy-to-clipboard';
import TextButton from '../TextButton';
var CopyButton = /** @class */ (function (_super) {
__extends(CopyButton, _super);
function CopyButton(props) {
var _this = _super.call(this, props) || this;
_this.timeout = null;
_this.onCopy = function () {
if (!_this.state.notification) {
copy(_this.props.source);
_this.setState({ notification: true }, function () {
_this.timeout = setTimeout(function () { return _this.setState({ notification: false }); }, 3000);
});
}
};
_this.state = {
notification: false,
};
return _this;
}
CopyButton.prototype.componentWillUnmount = function () {
clearTimeout(this.timeout);
};
CopyButton.prototype.render = function () {
return (React.createElement(TextButton, { className: this.props.className, onClick: this.onCopy, prefixIcon: this.props.prefixIcon }, this.state.notification ? 'Copied to clipboard!' : 'Copy'));
};
return CopyButton;
}(React.Component));
export { CopyButton };
//# sourceMappingURL=index.js.map