UNPKG

wix-storybook-utils

Version:

Utilities for automated component documentation within Storybook

35 lines 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CopyButton = void 0; var tslib_1 = require("tslib"); var React = tslib_1.__importStar(require("react")); var copy_to_clipboard_1 = tslib_1.__importDefault(require("copy-to-clipboard")); var TextButton_1 = tslib_1.__importDefault(require("../TextButton")); var CopyButton = /** @class */ (function (_super) { tslib_1.__extends(CopyButton, _super); function CopyButton(props) { var _this = _super.call(this, props) || this; _this.timeout = null; _this.onCopy = function () { if (!_this.state.notification) { (0, copy_to_clipboard_1.default)(_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_1.default, { className: this.props.className, onClick: this.onCopy, prefixIcon: this.props.prefixIcon }, this.state.notification ? 'Copied to clipboard!' : 'Copy')); }; return CopyButton; }(React.Component)); exports.CopyButton = CopyButton; //# sourceMappingURL=index.js.map