@pingux/astro 2.52.0 → 2.53.0-alpha.0
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/lib/cjs/components/CopyText/CopyButton.d.ts +4 -0
- package/lib/cjs/components/CopyText/CopyButton.js +6 -7
- package/lib/cjs/components/CopyText/CopyText.d.ts +4 -0
- package/lib/cjs/components/CopyText/CopyText.js +15 -28
- package/lib/cjs/components/CopyText/CopyText.stories.d.ts +7 -0
- package/lib/cjs/components/CopyText/CopyText.stories.js +1 -1
- package/lib/cjs/components/CopyText/CopyText.styles.d.ts +57 -0
- package/lib/cjs/components/CopyText/CopyText.test.d.ts +1 -0
- package/lib/cjs/components/CopyText/CopyText.test.js +81 -79
- package/lib/cjs/components/CopyText/index.d.ts +1 -0
- package/lib/cjs/components/IconButton/IconButton.styles.d.ts +20 -1
- package/lib/cjs/types/copyText.d.ts +25 -0
- package/lib/cjs/types/copyText.js +6 -0
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +37 -26
- package/lib/components/CopyText/CopyButton.js +6 -7
- package/lib/components/CopyText/CopyText.js +15 -28
- package/lib/components/CopyText/CopyText.stories.js +1 -1
- package/lib/components/CopyText/CopyText.test.js +74 -73
- package/lib/types/copyText.js +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +1 -1
@@ -10,31 +10,30 @@ _Object$defineProperty(exports, "__esModule", {
|
|
10
10
|
});
|
11
11
|
exports["default"] = void 0;
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
13
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
13
14
|
var _react = _interopRequireWildcard(require("react"));
|
14
15
|
var _ContentCopyIcon = _interopRequireDefault(require("@pingux/mdi-react/ContentCopyIcon"));
|
15
|
-
var _lodash = require("lodash");
|
16
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
17
16
|
var _Icon = _interopRequireDefault(require("../Icon"));
|
18
17
|
var _IconButton = _interopRequireDefault(require("../IconButton"));
|
19
18
|
var _react2 = require("@emotion/react");
|
19
|
+
var _excluded = ["iconProps"];
|
20
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
22
22
|
var CopyButton = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
23
|
+
var iconProps = props.iconProps,
|
24
|
+
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
23
25
|
return (0, _react2.jsx)(_IconButton["default"], (0, _extends2["default"])({
|
24
26
|
ref: ref,
|
25
27
|
"aria-label": "copy to clipboard",
|
26
28
|
variant: "copyButton"
|
27
|
-
},
|
29
|
+
}, others), (0, _react2.jsx)(_Icon["default"], (0, _extends2["default"])({
|
28
30
|
icon: _ContentCopyIcon["default"],
|
29
31
|
size: "xs",
|
30
32
|
color: "text.secondary",
|
31
33
|
title: {
|
32
34
|
name: 'Content Copy Icon'
|
33
35
|
}
|
34
|
-
},
|
36
|
+
}, iconProps)));
|
35
37
|
});
|
36
|
-
CopyButton.propTypes = {
|
37
|
-
iconProps: _propTypes["default"].shape({})
|
38
|
-
};
|
39
38
|
var _default = CopyButton;
|
40
39
|
exports["default"] = _default;
|
@@ -17,7 +17,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
17
17
|
var _reactAria = require("react-aria");
|
18
18
|
var _interactions = require("@react-aria/interactions");
|
19
19
|
var _liveAnnouncer = require("@react-aria/live-announcer");
|
20
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
21
20
|
var _useCopyToClipboard = _interopRequireDefault(require("../../hooks/useCopyToClipboard"));
|
22
21
|
var _index = require("../../index");
|
23
22
|
var _CopyButton = _interopRequireDefault(require("./CopyButton"));
|
@@ -35,11 +34,6 @@ var TooltipWrapper = function TooltipWrapper(_ref) {
|
|
35
34
|
direction: "top"
|
36
35
|
}, others), children, (0, _react2.jsx)(_index.Tooltip, null, tooltip));
|
37
36
|
};
|
38
|
-
TooltipWrapper.propTypes = {
|
39
|
-
isOpen: _propTypes["default"].bool,
|
40
|
-
targetRef: _propTypes["default"].shape({}),
|
41
|
-
tooltip: _propTypes["default"].string
|
42
|
-
};
|
43
37
|
var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
44
38
|
var children = props.children,
|
45
39
|
textToCopy = props.textToCopy,
|
@@ -81,13 +75,13 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
81
75
|
var copyToClipboard = (0, _useCopyToClipboard["default"])(value, setIsCopied);
|
82
76
|
var onTextClick = function onTextClick() {
|
83
77
|
var selection = window.getSelection();
|
84
|
-
if (selection.toString() === '') {
|
78
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.toString()) === '') {
|
85
79
|
copyToClipboard();
|
86
80
|
}
|
87
81
|
};
|
88
82
|
|
89
83
|
/* Used for text copying */
|
90
|
-
var contentRef = (0, _react.useRef)();
|
84
|
+
var contentRef = (0, _react.useRef)(null);
|
91
85
|
var _usePress = (0, _interactions.usePress)({
|
92
86
|
ref: contentRef,
|
93
87
|
onClick: onTextClick
|
@@ -97,17 +91,19 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
97
91
|
delete pressProps.onPointerDown;
|
98
92
|
var content = mode === 'link' || mode === 'nonClickableContent' ? children : (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
|
99
93
|
ref: contentRef
|
100
|
-
}, (0, _reactAria.mergeProps)(focusProps, pressProps)
|
94
|
+
}, (0, _reactAria.mergeProps)(focusProps, pressProps), {
|
95
|
+
role: "presentation"
|
96
|
+
}), children);
|
101
97
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
102
98
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
103
|
-
var pressableRef = (0, _react.useRef)();
|
99
|
+
var pressableRef = (0, _react.useRef)(null);
|
104
100
|
var _usePress2 = (0, _interactions.usePress)({
|
105
101
|
ref: pressableRef
|
106
102
|
}),
|
107
103
|
pressableProps = _usePress2.pressProps;
|
108
104
|
delete pressableProps.onMouseDown;
|
109
105
|
delete pressableProps.onPointerDown;
|
110
|
-
var wrapperRef = (0, _react.useRef)();
|
106
|
+
var wrapperRef = (0, _react.useRef)(null);
|
111
107
|
if (mode === 'nonClickableContent') {
|
112
108
|
return (0, _react2.jsx)(TooltipWrapper, (0, _extends2["default"])({
|
113
109
|
isOpen: isTooltipOpen,
|
@@ -117,7 +113,9 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
117
113
|
ref: wrapperRef,
|
118
114
|
isRow: true,
|
119
115
|
tabIndex: 0
|
120
|
-
}, (0, _reactAria.mergeProps)(hoverProps, others), wrapperProps
|
116
|
+
}, (0, _reactAria.mergeProps)(hoverProps, others), wrapperProps, {
|
117
|
+
role: "presentation"
|
118
|
+
}), content, (0, _react2.jsx)(_CopyButton["default"], (0, _extends2["default"])({
|
121
119
|
onPress: copyToClipboard
|
122
120
|
}, focusProps, iconButtonProps))));
|
123
121
|
}
|
@@ -142,29 +140,18 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
142
140
|
}, (0, _reactAria.mergeProps)(hoverProps, pressableProps), {
|
143
141
|
sx: {
|
144
142
|
width: 'fit-content'
|
145
|
-
}
|
143
|
+
},
|
144
|
+
role: "presentation"
|
146
145
|
}), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
|
147
146
|
ref: ref,
|
148
147
|
isRow: true,
|
149
148
|
variant: "copyText.copy"
|
150
|
-
}, others
|
149
|
+
}, others, {
|
150
|
+
role: "presentation"
|
151
|
+
}), content, (0, _react2.jsx)(_CopyButton["default"], (0, _extends2["default"])({
|
151
152
|
onPress: copyToClipboard
|
152
153
|
}, focusProps, iconButtonProps)))));
|
153
154
|
});
|
154
|
-
CopyText.propTypes = {
|
155
|
-
/** The behavioral pattern to apply to the component. */
|
156
|
-
mode: _propTypes["default"].oneOf(['text', 'link', 'nonClickableContent']),
|
157
|
-
/** The text to be copied instead of the text inside the child component. */
|
158
|
-
textToCopy: _propTypes["default"].string,
|
159
|
-
/** The text to be displayed in the tooltip. */
|
160
|
-
tooltipText: _propTypes["default"].string,
|
161
|
-
/** Props to apply to the tooltip in nonClickableContent mode. */
|
162
|
-
tooltipProps: _propTypes["default"].shape({}),
|
163
|
-
/** Props to apply to the wrapper in nonClickableContent mode. */
|
164
|
-
wrapperProps: _propTypes["default"].shape({}),
|
165
|
-
/** Props to apply to the icon button */
|
166
|
-
iconButtonProps: _propTypes["default"].shape({})
|
167
|
-
};
|
168
155
|
CopyText.defaultProps = {
|
169
156
|
mode: 'text',
|
170
157
|
tooltipText: 'Copy to clipboard'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { StoryFn } from '@storybook/react';
|
2
|
+
import { CopyTextProps } from '../../index';
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
|
4
|
+
export default _default;
|
5
|
+
export declare const Default: StoryFn<CopyTextProps>;
|
6
|
+
export declare const WithLink: StoryFn<CopyTextProps>;
|
7
|
+
export declare const WithChangedCopiedValue: StoryFn<CopyTextProps>;
|
@@ -11,7 +11,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
var _storybookAddonDesigns = require("storybook-addon-designs");
|
12
12
|
var _storybookDocsLayout = _interopRequireDefault(require("../../../.storybook/storybookDocsLayout"));
|
13
13
|
var _index = require("../../index");
|
14
|
-
var _figmaLinks = require("../../utils/designUtils/figmaLinks
|
14
|
+
var _figmaLinks = require("../../utils/designUtils/figmaLinks");
|
15
15
|
var _CopyText = _interopRequireDefault(require("./CopyText.mdx"));
|
16
16
|
var _react2 = require("@emotion/react");
|
17
17
|
var _default = {
|
@@ -0,0 +1,57 @@
|
|
1
|
+
export declare const copyButton: {
|
2
|
+
mx: string;
|
3
|
+
outline: string;
|
4
|
+
height: string;
|
5
|
+
cursor: string;
|
6
|
+
width: string;
|
7
|
+
minWidth: string;
|
8
|
+
path: {
|
9
|
+
fill: string;
|
10
|
+
};
|
11
|
+
':focus': {
|
12
|
+
outline: string;
|
13
|
+
};
|
14
|
+
'&.is-focused': {
|
15
|
+
boxShadow: string;
|
16
|
+
outlineOffset: string;
|
17
|
+
outline: string;
|
18
|
+
outlineColor: string;
|
19
|
+
};
|
20
|
+
};
|
21
|
+
declare const _default: {
|
22
|
+
copy: {
|
23
|
+
alignItems: string;
|
24
|
+
wordBreak: string;
|
25
|
+
overflowWrap: string;
|
26
|
+
'& .is-focused': {
|
27
|
+
outline: string;
|
28
|
+
outlineColor: string;
|
29
|
+
outlineOffset: string;
|
30
|
+
borderRadius: string;
|
31
|
+
};
|
32
|
+
'& span': {
|
33
|
+
cursor: string;
|
34
|
+
};
|
35
|
+
};
|
36
|
+
copyButton: {
|
37
|
+
mx: string;
|
38
|
+
outline: string;
|
39
|
+
height: string;
|
40
|
+
cursor: string;
|
41
|
+
width: string;
|
42
|
+
minWidth: string;
|
43
|
+
path: {
|
44
|
+
fill: string;
|
45
|
+
};
|
46
|
+
':focus': {
|
47
|
+
outline: string;
|
48
|
+
};
|
49
|
+
'&.is-focused': {
|
50
|
+
boxShadow: string;
|
51
|
+
outlineOffset: string;
|
52
|
+
outline: string;
|
53
|
+
outlineColor: string;
|
54
|
+
};
|
55
|
+
};
|
56
|
+
};
|
57
|
+
export default _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -8,7 +8,7 @@ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-s
|
|
8
8
|
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
9
9
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
10
|
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
11
|
-
var _Object$
|
11
|
+
var _Object$defineProperty2 = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
12
12
|
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
13
13
|
var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
|
14
14
|
var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
|
@@ -17,25 +17,25 @@ var _Promise = require("@babel/runtime-corejs3/core-js-stable/promise");
|
|
17
17
|
var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
|
18
18
|
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
19
19
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
20
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
20
21
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
21
22
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
22
|
-
var
|
23
|
+
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
23
24
|
var _react = _interopRequireDefault(require("react"));
|
25
|
+
var _react2 = require("@testing-library/react");
|
24
26
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
25
27
|
var _ = require("../..");
|
26
28
|
var _testWrapper = require("../../utils/testUtils/testWrapper");
|
27
29
|
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
28
|
-
var
|
29
|
-
var
|
30
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context19; _forEachInstanceProperty(_context19 = ["next", "throw", "return"]).call(_context19, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context20; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context20 = this.tryEntries).call(_context20, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
30
|
+
var _CopyText = _interopRequireDefault(require("./CopyText"));
|
31
|
+
var _react3 = require("@emotion/react");
|
32
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty2 || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty2(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context17; _forEachInstanceProperty(_context17 = ["next", "throw", "return"]).call(_context17, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context18; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context18 = this.tryEntries).call(_context18, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
31
33
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context15, _context16; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context15 = ownKeys(Object(source), !0)).call(_context15, function (key) { (0, _defineProperty3["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context16 = ownKeys(Object(source))).call(_context16, function (key) { _Object$defineProperty2(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
33
35
|
var testId = 'test-copy-text';
|
34
36
|
var originalClipboard = _objectSpread({}, global.navigator.clipboard);
|
35
|
-
var originalExecCommand = global.document.execCommand;
|
36
37
|
var originalGetSelection = window.getSelection;
|
37
|
-
var defaultTest = function defaultTest() {
|
38
|
-
var getComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
38
|
+
var defaultTest = function defaultTest(getComponent) {
|
39
39
|
getComponent();
|
40
40
|
var container = _testWrapper.screen.getByTestId(testId);
|
41
41
|
expect(container).toBeInstanceOf(HTMLDivElement);
|
@@ -46,17 +46,27 @@ describe('CopyText', function () {
|
|
46
46
|
var mockClipboard = {
|
47
47
|
writeText: jest.fn()
|
48
48
|
};
|
49
|
-
|
49
|
+
(0, _defineProperty2["default"])(window, 'navigator', {
|
50
|
+
value: {
|
51
|
+
clipboard: mockClipboard
|
52
|
+
},
|
53
|
+
configurable: true
|
54
|
+
});
|
50
55
|
global.document.execCommand = jest.fn();
|
51
|
-
|
56
|
+
jest.spyOn(document, 'execCommand').mockReturnValue(true);
|
52
57
|
var mockGetSelection = jest.fn();
|
53
58
|
mockGetSelection.mockReturnValue('');
|
54
59
|
window.getSelection = mockGetSelection;
|
55
60
|
});
|
56
61
|
afterEach(function () {
|
57
62
|
jest.resetAllMocks();
|
58
|
-
|
59
|
-
|
63
|
+
(0, _defineProperty2["default"])(window, 'navigator', {
|
64
|
+
value: {
|
65
|
+
clipboard: originalClipboard
|
66
|
+
},
|
67
|
+
configurable: true
|
68
|
+
});
|
69
|
+
jest.spyOn(document, 'execCommand').mockReturnValue(true);
|
60
70
|
window.getSelection = originalGetSelection;
|
61
71
|
});
|
62
72
|
describe('Text mode', function () {
|
@@ -66,13 +76,13 @@ describe('CopyText', function () {
|
|
66
76
|
var textValue = 'Here is a value';
|
67
77
|
var getComponent = function getComponent() {
|
68
78
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
69
|
-
return (0, _testWrapper.render)((0,
|
79
|
+
return (0, _testWrapper.render)((0, _react3.jsx)(_CopyText["default"], (0, _extends2["default"])({}, defaultProps, props), (0, _react3.jsx)(_.Text, null, textValue)));
|
70
80
|
};
|
71
81
|
|
72
|
-
// Needs to be added to each
|
82
|
+
// Needs to be added to each component's test file
|
73
83
|
(0, _universalComponentTest.universalComponentTests)({
|
74
84
|
renderComponent: function renderComponent(props) {
|
75
|
-
return (0,
|
85
|
+
return (0, _react3.jsx)(_CopyText["default"], (0, _extends2["default"])({}, defaultProps, props), (0, _react3.jsx)(_.Text, null, textValue));
|
76
86
|
}
|
77
87
|
});
|
78
88
|
test('renders component in the default state', function () {
|
@@ -186,7 +196,10 @@ describe('CopyText', function () {
|
|
186
196
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
187
197
|
while (1) switch (_context8.prev = _context8.next) {
|
188
198
|
case 0:
|
189
|
-
|
199
|
+
(0, _defineProperty2["default"])(window.navigator, 'clipboard', {
|
200
|
+
value: undefined,
|
201
|
+
writable: true
|
202
|
+
});
|
190
203
|
getComponent();
|
191
204
|
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
192
205
|
_context8.next = 5;
|
@@ -215,11 +228,14 @@ describe('CopyText', function () {
|
|
215
228
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
216
229
|
while (1) switch (_context10.prev = _context10.next) {
|
217
230
|
case 0:
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
231
|
+
(0, _defineProperty2["default"])(window.navigator, 'clipboard', {
|
232
|
+
value: undefined,
|
233
|
+
writable: true
|
234
|
+
});
|
235
|
+
jest.spyOn(document, 'execCommand').mockReturnValue(false);
|
236
|
+
jest.spyOn(console, 'error').mockImplementation(function () {
|
237
|
+
return false;
|
238
|
+
}); // eslint-disable-line no-console
|
223
239
|
|
224
240
|
getComponent();
|
225
241
|
spy = jest.spyOn(console, 'error');
|
@@ -247,63 +263,46 @@ describe('CopyText', function () {
|
|
247
263
|
}
|
248
264
|
}, _callee10);
|
249
265
|
})));
|
250
|
-
test('after button click, the tooltip renders with the text "Copied!"', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
266
|
+
test('after button click, the tooltip renders with the text "Copied!"', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
251
267
|
var button;
|
252
|
-
return _regeneratorRuntime().wrap(function
|
253
|
-
while (1) switch (
|
268
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
269
|
+
while (1) switch (_context11.prev = _context11.next) {
|
254
270
|
case 0:
|
255
271
|
getComponent();
|
256
272
|
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
257
|
-
|
258
|
-
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
259
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
260
|
-
while (1) switch (_context11.prev = _context11.next) {
|
261
|
-
case 0:
|
262
|
-
return _context11.abrupt("return", _userEvent["default"].click(button));
|
263
|
-
case 1:
|
264
|
-
case "end":
|
265
|
-
return _context11.stop();
|
266
|
-
}
|
267
|
-
}, _callee11);
|
268
|
-
})));
|
269
|
-
case 4:
|
273
|
+
_testWrapper.fireEvent.click(button);
|
270
274
|
expect(_testWrapper.screen.queryByRole('tooltip')).toBeInTheDocument();
|
271
|
-
|
275
|
+
_context11.next = 6;
|
276
|
+
return (0, _react2.waitFor)(function () {
|
277
|
+
expect(_testWrapper.screen.queryByRole('tooltip')).toHaveTextContent('Copied!');
|
278
|
+
});
|
272
279
|
case 6:
|
273
280
|
case "end":
|
274
|
-
return
|
281
|
+
return _context11.stop();
|
275
282
|
}
|
276
|
-
},
|
283
|
+
}, _callee11);
|
277
284
|
})));
|
278
|
-
test('tooltip renders with the text "Copied!" hides after delay', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
285
|
+
test('tooltip renders with the text "Copied!" hides after delay', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
279
286
|
var button;
|
280
|
-
return _regeneratorRuntime().wrap(function
|
281
|
-
while (1) switch (
|
287
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
288
|
+
while (1) switch (_context12.prev = _context12.next) {
|
282
289
|
case 0:
|
283
290
|
getComponent();
|
284
291
|
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
285
|
-
|
286
|
-
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
287
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
288
|
-
while (1) switch (_context13.prev = _context13.next) {
|
289
|
-
case 0:
|
290
|
-
return _context13.abrupt("return", _userEvent["default"].click(button));
|
291
|
-
case 1:
|
292
|
-
case "end":
|
293
|
-
return _context13.stop();
|
294
|
-
}
|
295
|
-
}, _callee13);
|
296
|
-
})));
|
297
|
-
case 4:
|
292
|
+
_testWrapper.fireEvent.click(button);
|
298
293
|
expect(_testWrapper.screen.queryByRole('tooltip')).toBeInTheDocument();
|
299
|
-
|
300
|
-
|
294
|
+
_context12.next = 6;
|
295
|
+
return (0, _react2.waitFor)(function () {
|
296
|
+
expect(_testWrapper.screen.queryByRole('tooltip')).toHaveTextContent('Copied!');
|
297
|
+
});
|
298
|
+
case 6:
|
299
|
+
_context12.next = 8;
|
301
300
|
return (0, _testWrapper.waitForElementToBeRemoved)(_testWrapper.screen.queryByRole('tooltip'));
|
302
301
|
case 8:
|
303
302
|
case "end":
|
304
|
-
return
|
303
|
+
return _context12.stop();
|
305
304
|
}
|
306
|
-
},
|
305
|
+
}, _callee12);
|
307
306
|
})));
|
308
307
|
});
|
309
308
|
describe('Link mode', function () {
|
@@ -314,15 +313,15 @@ describe('CopyText', function () {
|
|
314
313
|
var linkValue = 'https://a.url.com';
|
315
314
|
var getComponent = function getComponent() {
|
316
315
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
317
|
-
return (0, _testWrapper.render)((0,
|
316
|
+
return (0, _testWrapper.render)((0, _react3.jsx)(_CopyText["default"], (0, _extends2["default"])({}, defaultProps, props), (0, _react3.jsx)(_.Link, {
|
318
317
|
href: linkValue
|
319
318
|
}, linkValue)));
|
320
319
|
};
|
321
320
|
|
322
|
-
// Needs to be added to each
|
321
|
+
// Needs to be added to each component's test file
|
323
322
|
(0, _universalComponentTest.universalComponentTests)({
|
324
323
|
renderComponent: function renderComponent(props) {
|
325
|
-
return (0,
|
324
|
+
return (0, _react3.jsx)(_CopyText["default"], (0, _extends2["default"])({}, defaultProps, props), (0, _react3.jsx)(_.Link, {
|
326
325
|
href: linkValue
|
327
326
|
}, linkValue));
|
328
327
|
}
|
@@ -350,33 +349,36 @@ describe('CopyText', function () {
|
|
350
349
|
expect(copyBtn).toHaveFocus();
|
351
350
|
expect(copyBtn).toHaveClass('is-focused');
|
352
351
|
});
|
353
|
-
test('click on copy button copies data to the clipboard', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
352
|
+
test('click on copy button copies data to the clipboard', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
354
353
|
var button;
|
355
|
-
return _regeneratorRuntime().wrap(function
|
356
|
-
while (1) switch (
|
354
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
355
|
+
while (1) switch (_context14.prev = _context14.next) {
|
357
356
|
case 0:
|
358
357
|
getComponent();
|
359
358
|
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
360
|
-
|
361
|
-
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
362
|
-
return _regeneratorRuntime().wrap(function
|
363
|
-
while (1) switch (
|
359
|
+
_context14.next = 4;
|
360
|
+
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
361
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
362
|
+
while (1) switch (_context13.prev = _context13.next) {
|
364
363
|
case 0:
|
365
|
-
return
|
364
|
+
return _context13.abrupt("return", _userEvent["default"].click(button));
|
366
365
|
case 1:
|
367
366
|
case "end":
|
368
|
-
return
|
367
|
+
return _context13.stop();
|
369
368
|
}
|
370
|
-
},
|
369
|
+
}, _callee13);
|
371
370
|
})));
|
372
371
|
case 4:
|
373
|
-
|
374
|
-
|
375
|
-
|
372
|
+
// If navigator.clipboard is available and in secure context
|
373
|
+
if (navigator.clipboard) {
|
374
|
+
expect(navigator.clipboard.writeText).toBeCalledTimes(1);
|
375
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(linkValue);
|
376
|
+
}
|
377
|
+
case 5:
|
376
378
|
case "end":
|
377
|
-
return
|
379
|
+
return _context14.stop();
|
378
380
|
}
|
379
|
-
},
|
381
|
+
}, _callee14);
|
380
382
|
})));
|
381
383
|
});
|
382
384
|
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './CopyText';
|
@@ -167,7 +167,26 @@ declare const _default: {
|
|
167
167
|
width: number;
|
168
168
|
mx: string;
|
169
169
|
};
|
170
|
-
copyButton:
|
170
|
+
copyButton: {
|
171
|
+
mx: string;
|
172
|
+
outline: string;
|
173
|
+
height: string;
|
174
|
+
cursor: string;
|
175
|
+
width: string;
|
176
|
+
minWidth: string;
|
177
|
+
path: {
|
178
|
+
fill: string;
|
179
|
+
};
|
180
|
+
':focus': {
|
181
|
+
outline: string;
|
182
|
+
};
|
183
|
+
'&.is-focused': {
|
184
|
+
boxShadow: string;
|
185
|
+
outlineOffset: string;
|
186
|
+
outline: string;
|
187
|
+
outlineColor: string;
|
188
|
+
};
|
189
|
+
};
|
171
190
|
datePicker: {
|
172
191
|
containedIcon: any;
|
173
192
|
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { RefObject } from 'react';
|
2
|
+
import { TestingAttributes } from './shared/test';
|
3
|
+
import { IconProps } from './icon';
|
4
|
+
import { IconButtonProps } from './iconButton';
|
5
|
+
import { FocusableElement, HoverProps } from './shared';
|
6
|
+
import { TooltipTriggerProps } from './tooltipTrigger';
|
7
|
+
export interface TooltipWrapperProps {
|
8
|
+
children?: React.ReactNode;
|
9
|
+
isOpen?: boolean;
|
10
|
+
tooltip?: string;
|
11
|
+
targetRef?: RefObject<HTMLDivElement | FocusableElement>;
|
12
|
+
}
|
13
|
+
export interface CopyTextProps extends HoverProps, TestingAttributes {
|
14
|
+
children?: React.ReactNode;
|
15
|
+
mode?: 'text' | 'link' | 'nonClickableContent';
|
16
|
+
textToCopy?: string;
|
17
|
+
tooltipText?: string;
|
18
|
+
tooltipProps?: TooltipTriggerProps;
|
19
|
+
wrapperProps?: TooltipWrapperProps;
|
20
|
+
iconButtonProps?: Omit<IconButtonProps, 'onPress'>;
|
21
|
+
}
|
22
|
+
export interface CopyButtonProps {
|
23
|
+
iconProps?: IconProps;
|
24
|
+
onPress?: () => void;
|
25
|
+
}
|