@scaleflex/ui-tw 0.0.155 → 0.0.157
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 +8 -2
- package/button/components/copy-to-clipboard-button.js +8 -2
- package/package.json +2 -2
- package/tooltip/tooltip.component.js +1 -1
- package/utils/copy-to-clipboard.d.ts +1 -1
- package/utils/copy-to-clipboard.js +19 -15
- package/utils/use-copy-to-clipboard.d.ts +2 -1
- package/utils/use-copy-to-clipboard.js +3 -2
|
@@ -4,7 +4,7 @@ var _excluded = ["textToCopy", "copiedMessage", "tooltipDuration", "onCopy", "ch
|
|
|
4
4
|
import { Button } from '@scaleflex/ui-tw/button';
|
|
5
5
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
6
6
|
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
7
|
-
import React from 'react';
|
|
7
|
+
import React, { useRef } from 'react';
|
|
8
8
|
export function CopyButton(_ref) {
|
|
9
9
|
var textToCopy = _ref.textToCopy,
|
|
10
10
|
_ref$copiedMessage = _ref.copiedMessage,
|
|
@@ -15,10 +15,15 @@ export function CopyButton(_ref) {
|
|
|
15
15
|
children = _ref.children,
|
|
16
16
|
disabled = _ref.disabled,
|
|
17
17
|
buttonProps = _objectWithoutProperties(_ref, _excluded);
|
|
18
|
+
var buttonRef = useRef(null);
|
|
18
19
|
var _useCopyToClipboard = useCopyToClipboard({
|
|
19
20
|
copiedMessage: copiedMessage,
|
|
20
21
|
tooltipDuration: tooltipDuration,
|
|
21
|
-
onCopy: onCopy
|
|
22
|
+
onCopy: onCopy,
|
|
23
|
+
getContainer: function getContainer() {
|
|
24
|
+
var _buttonRef$current;
|
|
25
|
+
return (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.parentElement;
|
|
26
|
+
}
|
|
22
27
|
}),
|
|
23
28
|
tooltipText = _useCopyToClipboard.tooltipText,
|
|
24
29
|
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
@@ -29,6 +34,7 @@ export function CopyButton(_ref) {
|
|
|
29
34
|
variant: tooltipVariant,
|
|
30
35
|
open: open || undefined
|
|
31
36
|
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
37
|
+
ref: buttonRef,
|
|
32
38
|
"data-slot": "copy-button",
|
|
33
39
|
type: "button",
|
|
34
40
|
onClick: function onClick() {
|
|
@@ -2,7 +2,7 @@ import { Button, ButtonSize } from '@scaleflex/ui-tw/button';
|
|
|
2
2
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
3
3
|
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
4
4
|
import { Copy } from 'lucide-react';
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
/** @deprecated Use CopyIcon instead */
|
|
8
8
|
|
|
@@ -18,10 +18,15 @@ export function CopyIcon(props) {
|
|
|
18
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 buttonRef = useRef(null);
|
|
21
22
|
var _useCopyToClipboard = useCopyToClipboard({
|
|
22
23
|
copiedMessage: copiedTooltip,
|
|
23
24
|
tooltipDuration: tooltipDuration,
|
|
24
|
-
initialTooltipText: initialTooltip
|
|
25
|
+
initialTooltipText: initialTooltip,
|
|
26
|
+
getContainer: function getContainer() {
|
|
27
|
+
var _buttonRef$current;
|
|
28
|
+
return (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.parentElement;
|
|
29
|
+
}
|
|
25
30
|
}),
|
|
26
31
|
tooltipText = _useCopyToClipboard.tooltipText,
|
|
27
32
|
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
@@ -32,6 +37,7 @@ export function CopyIcon(props) {
|
|
|
32
37
|
variant: tooltipVariant,
|
|
33
38
|
open: open || undefined
|
|
34
39
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
40
|
+
ref: buttonRef,
|
|
35
41
|
type: "button",
|
|
36
42
|
variant: "ghost-secondary",
|
|
37
43
|
size: size,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.157",
|
|
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.157",
|
|
33
33
|
"@tanstack/react-table": "^8.21.3",
|
|
34
34
|
"@types/lodash.merge": "^4.6.9",
|
|
35
35
|
"class-variance-authority": "^0.7.1",
|
|
@@ -52,7 +52,7 @@ function TooltipContent(_ref4) {
|
|
|
52
52
|
"data-slot": "tooltip-content",
|
|
53
53
|
sideOffset: sideOffset,
|
|
54
54
|
collisionPadding: collisionPadding,
|
|
55
|
-
className: cn('animate-in fade-in-0 zoom-in-95 text-md shadow-shadow z-1999 w-fit max-w-lg origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-2 shadow-sm', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', tooltipVariants({
|
|
55
|
+
className: cn('animate-in fade-in-0 zoom-in-95 text-md shadow-shadow z-1999 w-fit max-w-lg origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-2 break-words shadow-sm', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', tooltipVariants({
|
|
56
56
|
variant: variant
|
|
57
57
|
}), className)
|
|
58
58
|
}, props), children));
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
8
8
|
* on it for critical confirmations.
|
|
9
9
|
*/
|
|
10
|
-
export declare function copyToClipboard(text: string): Promise<boolean>;
|
|
10
|
+
export declare function copyToClipboard(text: string, container?: HTMLElement | null): Promise<boolean>;
|
|
@@ -9,13 +9,13 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
9
9
|
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
10
10
|
* on it for critical confirmations.
|
|
11
11
|
*/
|
|
12
|
-
export function copyToClipboard(_x) {
|
|
12
|
+
export function copyToClipboard(_x, _x2) {
|
|
13
13
|
return _copyToClipboard.apply(this, arguments);
|
|
14
14
|
}
|
|
15
15
|
function _copyToClipboard() {
|
|
16
|
-
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
16
|
+
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, container) {
|
|
17
17
|
var _self, _navigator$clipboard;
|
|
18
|
-
var isSecureContext, textarea;
|
|
18
|
+
var isSecureContext, root, textarea, _window$getSelection;
|
|
19
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
20
|
while (1) switch (_context.prev = _context.next) {
|
|
21
21
|
case 0:
|
|
@@ -39,28 +39,32 @@ function _copyToClipboard() {
|
|
|
39
39
|
}
|
|
40
40
|
return _context.abrupt("return", false);
|
|
41
41
|
case 12:
|
|
42
|
-
// Fallback for iframes, HTTP contexts, older browsers
|
|
42
|
+
// Fallback for iframes, HTTP contexts, older browsers.
|
|
43
|
+
// Appending inside `container` (e.g. the trigger button's parent) keeps the textarea
|
|
44
|
+
// within any focus-trap scope (e.g. Radix Dialog) so focus() and execCommand work correctly.
|
|
45
|
+
root = container !== null && container !== void 0 ? container : document.body;
|
|
43
46
|
textarea = document.createElement('textarea');
|
|
44
47
|
textarea.value = text;
|
|
45
48
|
textarea.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none';
|
|
46
|
-
|
|
47
|
-
_context.prev =
|
|
49
|
+
root.appendChild(textarea);
|
|
50
|
+
_context.prev = 17;
|
|
51
|
+
(_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 || _window$getSelection.removeAllRanges();
|
|
48
52
|
textarea.focus();
|
|
49
53
|
textarea.select();
|
|
50
54
|
return _context.abrupt("return", document.execCommand('copy'));
|
|
51
|
-
case
|
|
52
|
-
_context.prev =
|
|
53
|
-
_context.t1 = _context["catch"](
|
|
55
|
+
case 24:
|
|
56
|
+
_context.prev = 24;
|
|
57
|
+
_context.t1 = _context["catch"](17);
|
|
54
58
|
return _context.abrupt("return", false);
|
|
55
|
-
case
|
|
56
|
-
_context.prev =
|
|
57
|
-
|
|
58
|
-
return _context.finish(
|
|
59
|
-
case
|
|
59
|
+
case 27:
|
|
60
|
+
_context.prev = 27;
|
|
61
|
+
root.removeChild(textarea);
|
|
62
|
+
return _context.finish(27);
|
|
63
|
+
case 30:
|
|
60
64
|
case "end":
|
|
61
65
|
return _context.stop();
|
|
62
66
|
}
|
|
63
|
-
}, _callee, null, [[2, 8], [
|
|
67
|
+
}, _callee, null, [[2, 8], [17, 24, 27, 30]]);
|
|
64
68
|
}));
|
|
65
69
|
return _copyToClipboard.apply(this, arguments);
|
|
66
70
|
}
|
|
@@ -3,8 +3,9 @@ interface UseCopyToClipboardOptions {
|
|
|
3
3
|
tooltipDuration?: number;
|
|
4
4
|
initialTooltipText?: string;
|
|
5
5
|
onCopy?: () => void;
|
|
6
|
+
getContainer?: () => HTMLElement | null | undefined;
|
|
6
7
|
}
|
|
7
|
-
export declare function useCopyToClipboard({ copiedMessage, tooltipDuration, initialTooltipText, onCopy, }?: UseCopyToClipboardOptions): {
|
|
8
|
+
export declare function useCopyToClipboard({ copiedMessage, tooltipDuration, initialTooltipText, onCopy, getContainer, }?: UseCopyToClipboardOptions): {
|
|
8
9
|
tooltipText: string;
|
|
9
10
|
tooltipVariant: "default" | "success";
|
|
10
11
|
open: boolean;
|
|
@@ -11,7 +11,8 @@ export function useCopyToClipboard() {
|
|
|
11
11
|
tooltipDuration = _ref$tooltipDuration === void 0 ? 2000 : _ref$tooltipDuration,
|
|
12
12
|
_ref$initialTooltipTe = _ref.initialTooltipText,
|
|
13
13
|
initialTooltipText = _ref$initialTooltipTe === void 0 ? '' : _ref$initialTooltipTe,
|
|
14
|
-
onCopy = _ref.onCopy
|
|
14
|
+
onCopy = _ref.onCopy,
|
|
15
|
+
getContainer = _ref.getContainer;
|
|
15
16
|
var _useState = useState(initialTooltipText),
|
|
16
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
17
18
|
tooltipText = _useState2[0],
|
|
@@ -31,7 +32,7 @@ export function useCopyToClipboard() {
|
|
|
31
32
|
while (1) switch (_context.prev = _context.next) {
|
|
32
33
|
case 0:
|
|
33
34
|
_context.next = 2;
|
|
34
|
-
return copyToClipboard(text);
|
|
35
|
+
return copyToClipboard(text, getContainer === null || getContainer === void 0 ? void 0 : getContainer());
|
|
35
36
|
case 2:
|
|
36
37
|
success = _context.sent;
|
|
37
38
|
if (success) {
|