@scaleflex/ui-tw 0.0.151 → 0.0.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/button/components/copy-button.js +15 -54
- package/button/components/copy-to-clipboard-button.d.ts +1 -0
- package/button/components/copy-to-clipboard-button.js +17 -53
- package/copyable-text/copyable-text.component.js +17 -56
- package/package.json +2 -2
- package/utils/copy-to-clipboard.d.ts +10 -0
- package/utils/copy-to-clipboard.js +65 -0
- package/utils/use-copy-to-clipboard.d.ts +13 -0
- package/utils/use-copy-to-clipboard.js +68 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
3
|
var _excluded = ["textToCopy", "copiedMessage", "tooltipDuration", "onCopy", "children", "disabled"];
|
|
6
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
4
|
import { Button } from '@scaleflex/ui-tw/button';
|
|
8
5
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
9
|
-
import
|
|
6
|
+
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
7
|
+
import React from 'react';
|
|
10
8
|
export function CopyButton(_ref) {
|
|
11
9
|
var textToCopy = _ref.textToCopy,
|
|
12
10
|
_ref$copiedMessage = _ref.copiedMessage,
|
|
@@ -17,62 +15,25 @@ export function CopyButton(_ref) {
|
|
|
17
15
|
children = _ref.children,
|
|
18
16
|
disabled = _ref.disabled,
|
|
19
17
|
buttonProps = _objectWithoutProperties(_ref, _excluded);
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tooltipVariant =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
30
|
-
open = _useState6[0],
|
|
31
|
-
setOpen = _useState6[1];
|
|
32
|
-
var handleCopy = /*#__PURE__*/function () {
|
|
33
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
34
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
|
-
while (1) switch (_context.prev = _context.next) {
|
|
36
|
-
case 0:
|
|
37
|
-
_context.prev = 0;
|
|
38
|
-
_context.next = 3;
|
|
39
|
-
return navigator.clipboard.writeText(textToCopy);
|
|
40
|
-
case 3:
|
|
41
|
-
setTooltipText(copiedMessage);
|
|
42
|
-
setTooltipVariant('success');
|
|
43
|
-
setOpen(true);
|
|
44
|
-
onCopy === null || onCopy === void 0 || onCopy();
|
|
45
|
-
setTimeout(function () {
|
|
46
|
-
setOpen(false);
|
|
47
|
-
}, tooltipDuration - 500);
|
|
48
|
-
setTimeout(function () {
|
|
49
|
-
setTooltipText('');
|
|
50
|
-
setTooltipVariant('default');
|
|
51
|
-
}, tooltipDuration);
|
|
52
|
-
_context.next = 14;
|
|
53
|
-
break;
|
|
54
|
-
case 11:
|
|
55
|
-
_context.prev = 11;
|
|
56
|
-
_context.t0 = _context["catch"](0);
|
|
57
|
-
console.error('Failed to copy', _context.t0);
|
|
58
|
-
case 14:
|
|
59
|
-
case "end":
|
|
60
|
-
return _context.stop();
|
|
61
|
-
}
|
|
62
|
-
}, _callee, null, [[0, 11]]);
|
|
63
|
-
}));
|
|
64
|
-
return function handleCopy() {
|
|
65
|
-
return _ref2.apply(this, arguments);
|
|
66
|
-
};
|
|
67
|
-
}();
|
|
18
|
+
var _useCopyToClipboard = useCopyToClipboard({
|
|
19
|
+
copiedMessage: copiedMessage,
|
|
20
|
+
tooltipDuration: tooltipDuration,
|
|
21
|
+
onCopy: onCopy
|
|
22
|
+
}),
|
|
23
|
+
tooltipText = _useCopyToClipboard.tooltipText,
|
|
24
|
+
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
25
|
+
open = _useCopyToClipboard.open,
|
|
26
|
+
handleCopy = _useCopyToClipboard.handleCopy;
|
|
68
27
|
return /*#__PURE__*/React.createElement(WithTooltip, {
|
|
69
28
|
content: tooltipText,
|
|
70
29
|
variant: tooltipVariant,
|
|
71
|
-
open: open
|
|
30
|
+
open: open || undefined
|
|
72
31
|
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
73
32
|
"data-slot": "copy-button",
|
|
74
33
|
type: "button",
|
|
75
|
-
onClick:
|
|
34
|
+
onClick: function onClick() {
|
|
35
|
+
return handleCopy(textToCopy);
|
|
36
|
+
},
|
|
76
37
|
disabled: disabled || !textToCopy
|
|
77
38
|
}, buttonProps), children));
|
|
78
39
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
1
|
import { Button, ButtonSize } from '@scaleflex/ui-tw/button';
|
|
5
2
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
3
|
+
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
6
4
|
import { Copy } from 'lucide-react';
|
|
7
|
-
import React
|
|
5
|
+
import React from 'react';
|
|
8
6
|
|
|
9
7
|
/** @deprecated Use CopyIcon instead */
|
|
10
8
|
|
|
@@ -16,64 +14,30 @@ export function CopyIcon(props) {
|
|
|
16
14
|
initialTooltip = _props$initialTooltip === void 0 ? 'Copy to clipboard' : _props$initialTooltip,
|
|
17
15
|
_props$copiedTooltip = props.copiedTooltip,
|
|
18
16
|
copiedTooltip = _props$copiedTooltip === void 0 ? 'Copied!' : _props$copiedTooltip,
|
|
17
|
+
_props$tooltipDuratio = props.tooltipDuration,
|
|
18
|
+
tooltipDuration = _props$tooltipDuratio === void 0 ? 2000 : _props$tooltipDuratio,
|
|
19
19
|
_props$disabled = props.disabled,
|
|
20
20
|
disabled = _props$disabled === void 0 ? false : _props$disabled;
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
tooltipVariant =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
31
|
-
open = _useState6[0],
|
|
32
|
-
setOpen = _useState6[1];
|
|
33
|
-
var handleCopy = /*#__PURE__*/function () {
|
|
34
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
35
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
36
|
-
while (1) switch (_context.prev = _context.next) {
|
|
37
|
-
case 0:
|
|
38
|
-
_context.prev = 0;
|
|
39
|
-
_context.next = 3;
|
|
40
|
-
return navigator.clipboard.writeText(text);
|
|
41
|
-
case 3:
|
|
42
|
-
setTooltipText(copiedTooltip);
|
|
43
|
-
setTooltipVariant('success');
|
|
44
|
-
setOpen(true);
|
|
45
|
-
setTimeout(function () {
|
|
46
|
-
setOpen(false);
|
|
47
|
-
}, 1500);
|
|
48
|
-
setTimeout(function () {
|
|
49
|
-
setTooltipText(initialTooltip);
|
|
50
|
-
setTooltipVariant('default');
|
|
51
|
-
}, 2000);
|
|
52
|
-
_context.next = 13;
|
|
53
|
-
break;
|
|
54
|
-
case 10:
|
|
55
|
-
_context.prev = 10;
|
|
56
|
-
_context.t0 = _context["catch"](0);
|
|
57
|
-
console.error('Failed to copy', _context.t0);
|
|
58
|
-
case 13:
|
|
59
|
-
case "end":
|
|
60
|
-
return _context.stop();
|
|
61
|
-
}
|
|
62
|
-
}, _callee, null, [[0, 10]]);
|
|
63
|
-
}));
|
|
64
|
-
return function handleCopy() {
|
|
65
|
-
return _ref.apply(this, arguments);
|
|
66
|
-
};
|
|
67
|
-
}();
|
|
21
|
+
var _useCopyToClipboard = useCopyToClipboard({
|
|
22
|
+
copiedMessage: copiedTooltip,
|
|
23
|
+
tooltipDuration: tooltipDuration,
|
|
24
|
+
initialTooltipText: initialTooltip
|
|
25
|
+
}),
|
|
26
|
+
tooltipText = _useCopyToClipboard.tooltipText,
|
|
27
|
+
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
28
|
+
open = _useCopyToClipboard.open,
|
|
29
|
+
handleCopy = _useCopyToClipboard.handleCopy;
|
|
68
30
|
return /*#__PURE__*/React.createElement(WithTooltip, {
|
|
69
31
|
content: tooltipText,
|
|
70
32
|
variant: tooltipVariant,
|
|
71
|
-
open: open
|
|
33
|
+
open: open || undefined
|
|
72
34
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
73
35
|
type: "button",
|
|
74
36
|
variant: "ghost-secondary",
|
|
75
37
|
size: size,
|
|
76
|
-
onClick:
|
|
38
|
+
onClick: function onClick() {
|
|
39
|
+
return handleCopy(text);
|
|
40
|
+
},
|
|
77
41
|
disabled: disabled || !text
|
|
78
42
|
}, /*#__PURE__*/React.createElement(Copy, null)));
|
|
79
43
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
3
|
var _excluded = ["value", "textToCopy", "copiedMessage", "tooltipDuration", "onCopy", "className"];
|
|
6
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
4
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
8
5
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
6
|
+
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
9
7
|
import { Copy } from 'lucide-react';
|
|
10
|
-
import React
|
|
8
|
+
import React from 'react';
|
|
11
9
|
function CopyableText(_ref) {
|
|
12
10
|
var value = _ref.value,
|
|
13
11
|
textToCopy = _ref.textToCopy,
|
|
@@ -18,66 +16,29 @@ function CopyableText(_ref) {
|
|
|
18
16
|
onCopy = _ref.onCopy,
|
|
19
17
|
className = _ref.className,
|
|
20
18
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
open = _useState6[0],
|
|
32
|
-
setOpen = _useState6[1];
|
|
33
|
-
var handleCopy = /*#__PURE__*/function () {
|
|
34
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
35
|
-
var text;
|
|
36
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
|
-
while (1) switch (_context.prev = _context.next) {
|
|
38
|
-
case 0:
|
|
39
|
-
_context.prev = 0;
|
|
40
|
-
text = textToCopy !== null && textToCopy !== void 0 ? textToCopy : typeof value === 'string' ? value : '';
|
|
41
|
-
_context.next = 4;
|
|
42
|
-
return navigator.clipboard.writeText(text);
|
|
43
|
-
case 4:
|
|
44
|
-
setTooltipText(copiedMessage);
|
|
45
|
-
setTooltipVariant('success');
|
|
46
|
-
setOpen(true);
|
|
47
|
-
onCopy === null || onCopy === void 0 || onCopy();
|
|
48
|
-
setTimeout(function () {
|
|
49
|
-
setOpen(false);
|
|
50
|
-
}, tooltipDuration - 500);
|
|
51
|
-
setTimeout(function () {
|
|
52
|
-
setTooltipText('');
|
|
53
|
-
setTooltipVariant('default');
|
|
54
|
-
}, tooltipDuration);
|
|
55
|
-
_context.next = 15;
|
|
56
|
-
break;
|
|
57
|
-
case 12:
|
|
58
|
-
_context.prev = 12;
|
|
59
|
-
_context.t0 = _context["catch"](0);
|
|
60
|
-
console.error('Failed to copy', _context.t0);
|
|
61
|
-
case 15:
|
|
62
|
-
case "end":
|
|
63
|
-
return _context.stop();
|
|
64
|
-
}
|
|
65
|
-
}, _callee, null, [[0, 12]]);
|
|
66
|
-
}));
|
|
67
|
-
return function handleCopy() {
|
|
68
|
-
return _ref2.apply(this, arguments);
|
|
69
|
-
};
|
|
70
|
-
}();
|
|
19
|
+
var effectiveText = textToCopy !== null && textToCopy !== void 0 ? textToCopy : typeof value === 'string' ? value : '';
|
|
20
|
+
var _useCopyToClipboard = useCopyToClipboard({
|
|
21
|
+
copiedMessage: copiedMessage,
|
|
22
|
+
tooltipDuration: tooltipDuration,
|
|
23
|
+
onCopy: onCopy
|
|
24
|
+
}),
|
|
25
|
+
tooltipText = _useCopyToClipboard.tooltipText,
|
|
26
|
+
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
27
|
+
open = _useCopyToClipboard.open,
|
|
28
|
+
handleCopy = _useCopyToClipboard.handleCopy;
|
|
71
29
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
72
30
|
"data-slot": "copyable-text",
|
|
73
31
|
className: cn('group inline-flex items-center', className)
|
|
74
32
|
}, props), /*#__PURE__*/React.createElement("span", null, value), /*#__PURE__*/React.createElement(WithTooltip, {
|
|
75
33
|
content: tooltipText,
|
|
76
34
|
variant: tooltipVariant,
|
|
77
|
-
open: open
|
|
35
|
+
open: open || undefined
|
|
78
36
|
}, /*#__PURE__*/React.createElement("button", {
|
|
79
37
|
type: "button",
|
|
80
|
-
onClick:
|
|
38
|
+
onClick: function onClick() {
|
|
39
|
+
return handleCopy(effectiveText);
|
|
40
|
+
},
|
|
41
|
+
disabled: !effectiveText,
|
|
81
42
|
className: "text-muted-foreground hover:text-foreground cursor-pointer pl-0.5 opacity-0 transition-opacity group-hover:opacity-100"
|
|
82
43
|
}, /*#__PURE__*/React.createElement(Copy, {
|
|
83
44
|
className: "size-3.5"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.152",
|
|
4
4
|
"author": "scaleflex",
|
|
5
5
|
"repository": "github:scaleflex/ui",
|
|
6
6
|
"homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@radix-ui/react-switch": "^1.0.1",
|
|
30
30
|
"@radix-ui/react-tabs": "^1.1.13",
|
|
31
31
|
"@radix-ui/react-tooltip": "^1.2.6",
|
|
32
|
-
"@scaleflex/icons-tw": "^0.0.
|
|
32
|
+
"@scaleflex/icons-tw": "^0.0.152",
|
|
33
33
|
"@tanstack/react-table": "^8.21.3",
|
|
34
34
|
"@types/lodash.merge": "^4.6.9",
|
|
35
35
|
"class-variance-authority": "^0.7.1",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies text to the clipboard with a fallback for environments where the
|
|
3
|
+
* Clipboard API is unavailable (iframes without `clipboard-write` permissions,
|
|
4
|
+
* HTTP contexts, older browsers).
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` on success, `false` on failure. Note: the `execCommand`
|
|
7
|
+
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
8
|
+
* on it for critical confirmations.
|
|
9
|
+
*/
|
|
10
|
+
export declare function copyToClipboard(text: string): Promise<boolean>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
/**
|
|
4
|
+
* Copies text to the clipboard with a fallback for environments where the
|
|
5
|
+
* Clipboard API is unavailable (iframes without `clipboard-write` permissions,
|
|
6
|
+
* HTTP contexts, older browsers).
|
|
7
|
+
*
|
|
8
|
+
* @returns `true` on success, `false` on failure. Note: the `execCommand`
|
|
9
|
+
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
10
|
+
* on it for critical confirmations.
|
|
11
|
+
*/
|
|
12
|
+
export function copyToClipboard(_x) {
|
|
13
|
+
return _copyToClipboard.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
function _copyToClipboard() {
|
|
16
|
+
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
17
|
+
var _navigator$clipboard;
|
|
18
|
+
var textarea;
|
|
19
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
if (!(typeof navigator !== 'undefined' && (_navigator$clipboard = navigator.clipboard) !== null && _navigator$clipboard !== void 0 && _navigator$clipboard.writeText)) {
|
|
23
|
+
_context.next = 9;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
_context.prev = 1;
|
|
27
|
+
_context.next = 4;
|
|
28
|
+
return navigator.clipboard.writeText(text);
|
|
29
|
+
case 4:
|
|
30
|
+
return _context.abrupt("return", true);
|
|
31
|
+
case 7:
|
|
32
|
+
_context.prev = 7;
|
|
33
|
+
_context.t0 = _context["catch"](1);
|
|
34
|
+
case 9:
|
|
35
|
+
if (!(typeof document === 'undefined')) {
|
|
36
|
+
_context.next = 11;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return _context.abrupt("return", false);
|
|
40
|
+
case 11:
|
|
41
|
+
// Fallback for iframes, HTTP contexts, older browsers
|
|
42
|
+
textarea = document.createElement('textarea');
|
|
43
|
+
textarea.value = text;
|
|
44
|
+
textarea.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none';
|
|
45
|
+
document.body.appendChild(textarea);
|
|
46
|
+
_context.prev = 15;
|
|
47
|
+
textarea.focus();
|
|
48
|
+
textarea.select();
|
|
49
|
+
return _context.abrupt("return", document.execCommand('copy'));
|
|
50
|
+
case 21:
|
|
51
|
+
_context.prev = 21;
|
|
52
|
+
_context.t1 = _context["catch"](15);
|
|
53
|
+
return _context.abrupt("return", false);
|
|
54
|
+
case 24:
|
|
55
|
+
_context.prev = 24;
|
|
56
|
+
document.body.removeChild(textarea);
|
|
57
|
+
return _context.finish(24);
|
|
58
|
+
case 27:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee, null, [[1, 7], [15, 21, 24, 27]]);
|
|
63
|
+
}));
|
|
64
|
+
return _copyToClipboard.apply(this, arguments);
|
|
65
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface UseCopyToClipboardOptions {
|
|
2
|
+
copiedMessage?: string;
|
|
3
|
+
tooltipDuration?: number;
|
|
4
|
+
initialTooltipText?: string;
|
|
5
|
+
onCopy?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function useCopyToClipboard({ copiedMessage, tooltipDuration, initialTooltipText, onCopy, }?: UseCopyToClipboardOptions): {
|
|
8
|
+
tooltipText: string;
|
|
9
|
+
tooltipVariant: "default" | "success";
|
|
10
|
+
open: boolean;
|
|
11
|
+
handleCopy: (text: string) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import { copyToClipboard } from '@scaleflex/ui-tw/utils/copy-to-clipboard';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
export function useCopyToClipboard() {
|
|
7
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
8
|
+
_ref$copiedMessage = _ref.copiedMessage,
|
|
9
|
+
copiedMessage = _ref$copiedMessage === void 0 ? 'Copied!' : _ref$copiedMessage,
|
|
10
|
+
_ref$tooltipDuration = _ref.tooltipDuration,
|
|
11
|
+
tooltipDuration = _ref$tooltipDuration === void 0 ? 2000 : _ref$tooltipDuration,
|
|
12
|
+
_ref$initialTooltipTe = _ref.initialTooltipText,
|
|
13
|
+
initialTooltipText = _ref$initialTooltipTe === void 0 ? '' : _ref$initialTooltipTe,
|
|
14
|
+
onCopy = _ref.onCopy;
|
|
15
|
+
var _useState = useState(initialTooltipText),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
tooltipText = _useState2[0],
|
|
18
|
+
setTooltipText = _useState2[1];
|
|
19
|
+
var _useState3 = useState('default'),
|
|
20
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
21
|
+
tooltipVariant = _useState4[0],
|
|
22
|
+
setTooltipVariant = _useState4[1];
|
|
23
|
+
var _useState5 = useState(false),
|
|
24
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
25
|
+
open = _useState6[0],
|
|
26
|
+
setOpen = _useState6[1];
|
|
27
|
+
var handleCopy = /*#__PURE__*/function () {
|
|
28
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
29
|
+
var success;
|
|
30
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
31
|
+
while (1) switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
_context.next = 2;
|
|
34
|
+
return copyToClipboard(text);
|
|
35
|
+
case 2:
|
|
36
|
+
success = _context.sent;
|
|
37
|
+
if (success) {
|
|
38
|
+
setTooltipText(copiedMessage);
|
|
39
|
+
setTooltipVariant('success');
|
|
40
|
+
setOpen(true);
|
|
41
|
+
onCopy === null || onCopy === void 0 || onCopy();
|
|
42
|
+
setTimeout(function () {
|
|
43
|
+
setOpen(false);
|
|
44
|
+
}, tooltipDuration - 500);
|
|
45
|
+
setTimeout(function () {
|
|
46
|
+
setTooltipText(initialTooltipText);
|
|
47
|
+
setTooltipVariant('default');
|
|
48
|
+
}, tooltipDuration);
|
|
49
|
+
} else {
|
|
50
|
+
console.error('Failed to copy');
|
|
51
|
+
}
|
|
52
|
+
case 4:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
}));
|
|
58
|
+
return function handleCopy(_x) {
|
|
59
|
+
return _ref2.apply(this, arguments);
|
|
60
|
+
};
|
|
61
|
+
}();
|
|
62
|
+
return {
|
|
63
|
+
tooltipText: tooltipText,
|
|
64
|
+
tooltipVariant: tooltipVariant,
|
|
65
|
+
open: open,
|
|
66
|
+
handleCopy: handleCopy
|
|
67
|
+
};
|
|
68
|
+
}
|