UNPKG

epn-ui

Version:

Дизайн система кабинета ВМ

40 lines (37 loc) 2.01 kB
import { __awaiter, __generator } from '../../_virtual/_tslib.js'; import React from 'react'; import clsx from 'clsx'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCopy } from '@fortawesome/pro-regular-svg-icons/faCopy'; import TextInput from '../InputText/index.js'; import { copyTextToClipboard } from '../../utils/clipboard/index.js'; var CopyInput = function (_a) { var id = _a.id, value = _a.value, className = _a.className, _b = _a.readOnly, readOnly = _b === void 0 ? true : _b, placeholder = _a.placeholder, onFailed = _a.onFailed, onCompleted = _a.onCompleted, onClick = _a.onClick, link = _a.link, onComplete = _a.onComplete; var inputValue = link || value; var onCopyHandler = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!inputValue) { if (typeof onFailed === 'function') { onFailed(); } return [2]; } return [4, copyTextToClipboard(inputValue)]; case 1: _a.sent(); if (typeof onCompleted === 'function') { onCompleted(inputValue || ''); } if (typeof onComplete === 'function') { onComplete(inputValue || ''); } return [2]; } }); }); }; return (React.createElement(TextInput, { id: id || undefined, className: clsx('epn-copyinput', className), placeholder: placeholder, readOnly: readOnly, value: inputValue, onClick: onClick, suffix: React.createElement(FontAwesomeIcon, { className: "epn-copyinput--button", icon: faCopy, onClick: onCopyHandler }) })); }; var CopyInput$1 = CopyInput; export { CopyInput$1 as default };