@pingux/astro 1.13.0 → 1.14.0-alpha.2
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/CopyText.js +43 -9
- package/lib/cjs/components/CopyText/CopyText.test.js +9 -0
- package/lib/cjs/hooks/useAriaLabelWarning/useAriaLabelWarning.js +9 -10
- package/lib/cjs/hooks/useAriaLabelWarning/useAriaLabelWarning.test.js +1 -1
- package/lib/cjs/hooks/useDevelopmentWarning/index.js +18 -0
- package/lib/cjs/hooks/useDevelopmentWarning/useDevelopmentWarning.js +28 -0
- package/lib/cjs/hooks/useDevelopmentWarning/useDevelopmentWarning.test.js +43 -0
- package/lib/cjs/recipes/AttributeMappingReadOnlyField.stories.js +165 -0
- package/lib/cjs/styles/variants/boxes.js +3 -1
- package/lib/components/CopyText/CopyText.js +45 -11
- package/lib/components/CopyText/CopyText.test.js +9 -0
- package/lib/hooks/useAriaLabelWarning/useAriaLabelWarning.js +7 -10
- package/lib/hooks/useAriaLabelWarning/useAriaLabelWarning.test.js +1 -1
- package/lib/hooks/useDevelopmentWarning/index.js +1 -0
- package/lib/hooks/useDevelopmentWarning/useDevelopmentWarning.js +17 -0
- package/lib/hooks/useDevelopmentWarning/useDevelopmentWarning.test.js +37 -0
- package/lib/recipes/AttributeMappingReadOnlyField.stories.js +145 -0
- package/lib/styles/variants/boxes.js +3 -1
- package/package.json +1 -1
- package/NOTICE.html +0 -4311
@@ -114,14 +114,41 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
114
114
|
return undefined;
|
115
115
|
}, [isCopied]);
|
116
116
|
var copyToClipboard = (0, _useCopyToClipboard["default"])(value, setIsCopied);
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
|
118
|
+
var onTextClick = function onTextClick() {
|
119
|
+
var selection = window.getSelection();
|
120
|
+
|
121
|
+
if (selection.toString() === '') {
|
122
|
+
copyToClipboard();
|
123
|
+
}
|
124
|
+
};
|
125
|
+
/* Used for text copying */
|
126
|
+
|
127
|
+
|
128
|
+
var contentRef = (0, _react.useRef)();
|
129
|
+
|
130
|
+
var _usePress = (0, _interactions.usePress)({
|
131
|
+
ref: contentRef,
|
132
|
+
onClick: onTextClick
|
133
|
+
}),
|
134
|
+
pressProps = _usePress.pressProps;
|
135
|
+
|
136
|
+
delete pressProps.onMouseDown;
|
137
|
+
delete pressProps.onPointerDown;
|
138
|
+
var content = mode === 'link' || mode === 'nonClickableContent' ? children : (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
|
139
|
+
ref: contentRef
|
140
|
+
}, (0, _utils.mergeProps)(focusProps, pressProps)), children);
|
123
141
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
124
142
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
143
|
+
var pressableRef = (0, _react.useRef)();
|
144
|
+
|
145
|
+
var _usePress2 = (0, _interactions.usePress)({
|
146
|
+
ref: pressableRef
|
147
|
+
}),
|
148
|
+
pressableProps = _usePress2.pressProps;
|
149
|
+
|
150
|
+
delete pressableProps.onMouseDown;
|
151
|
+
delete pressableProps.onPointerDown;
|
125
152
|
var wrapperRef = (0, _react.useRef)();
|
126
153
|
|
127
154
|
if (mode === 'nonClickableContent') {
|
@@ -153,12 +180,19 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
153
180
|
|
154
181
|
return (0, _react2.jsx)(TooltipWrapper, {
|
155
182
|
isOpen: isTooltipOpen,
|
156
|
-
tooltip: tooltip
|
157
|
-
|
183
|
+
tooltip: tooltip,
|
184
|
+
targetRef: pressableRef
|
185
|
+
}, (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
|
186
|
+
ref: pressableRef
|
187
|
+
}, (0, _utils.mergeProps)(hoverProps, pressableProps), {
|
188
|
+
sx: {
|
189
|
+
width: 'min-content'
|
190
|
+
}
|
191
|
+
}), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
|
158
192
|
ref: ref,
|
159
193
|
isRow: true,
|
160
194
|
variant: "boxes.copy"
|
161
|
-
},
|
195
|
+
}, others), content, (0, _react2.jsx)(_CopyButton["default"], (0, _extends2["default"])({
|
162
196
|
onPress: copyToClipboard
|
163
197
|
}, focusProps)))));
|
164
198
|
});
|
@@ -49,6 +49,7 @@ var testId = 'test-copy-text';
|
|
49
49
|
var originalClipboard = _objectSpread({}, global.navigator.clipboard);
|
50
50
|
|
51
51
|
var originalExecCommand = global.document.execCommand;
|
52
|
+
var originalGetSelection = window.getSelection;
|
52
53
|
|
53
54
|
var defaultTest = function defaultTest() {
|
54
55
|
var getComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
@@ -107,11 +108,15 @@ describe('Text mode', function () {
|
|
107
108
|
global.navigator.clipboard = mockClipboard;
|
108
109
|
global.document.execCommand = jest.fn();
|
109
110
|
global.document.execCommand.mockReturnValue(true);
|
111
|
+
var mockGetSelection = jest.fn();
|
112
|
+
mockGetSelection.mockReturnValue('');
|
113
|
+
window.getSelection = mockGetSelection;
|
110
114
|
});
|
111
115
|
afterEach(function () {
|
112
116
|
jest.resetAllMocks();
|
113
117
|
global.navigator.clipboard = originalClipboard;
|
114
118
|
global.document.execCommand = originalExecCommand;
|
119
|
+
window.getSelection = originalGetSelection;
|
115
120
|
});
|
116
121
|
test('click on text copies data to the clipboard', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
117
122
|
var button;
|
@@ -433,10 +438,14 @@ describe('Link mode', function () {
|
|
433
438
|
writeText: jest.fn()
|
434
439
|
};
|
435
440
|
global.navigator.clipboard = mockClipboard;
|
441
|
+
var mockGetSelection = jest.fn();
|
442
|
+
mockGetSelection.mockReturnValue('');
|
443
|
+
window.getSelection = mockGetSelection;
|
436
444
|
});
|
437
445
|
afterEach(function () {
|
438
446
|
jest.resetAllMocks();
|
439
447
|
global.navigator.clipboard = originalClipboard;
|
448
|
+
window.getSelection = originalGetSelection;
|
440
449
|
});
|
441
450
|
test('click on copy button copies data to the clipboard', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16() {
|
442
451
|
var button;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
3
5
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
6
|
|
5
7
|
_Object$defineProperty(exports, "__esModule", {
|
@@ -8,22 +10,19 @@ _Object$defineProperty(exports, "__esModule", {
|
|
8
10
|
|
9
11
|
exports["default"] = void 0;
|
10
12
|
|
11
|
-
var
|
13
|
+
var _useDevelopmentWarning = _interopRequireDefault(require("../useDevelopmentWarning"));
|
12
14
|
|
13
15
|
/**
|
14
16
|
* Provides a development-only console warning when a component
|
15
17
|
* that needs an aria-label is mounted without one.
|
16
|
-
*
|
17
|
-
* e.g. "\`Component\` requires an aria-label."
|
18
18
|
*/
|
19
19
|
var useAriaLabelWarning = function useAriaLabelWarning(component, ariaLabel) {
|
20
|
-
var
|
21
|
-
(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}, []);
|
20
|
+
var shouldTrigger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
21
|
+
var message = "".concat(component, " has an undefined aria-label. If the surrounding content sufficiently labels this component instance, you may disable this warning by setting the prop to `null`. Otherwise, please provide an appropriate aria-label. See more info here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label");
|
22
|
+
(0, _useDevelopmentWarning["default"])({
|
23
|
+
message: message,
|
24
|
+
shouldTrigger: shouldTrigger && ariaLabel === undefined
|
25
|
+
});
|
27
26
|
};
|
28
27
|
|
29
28
|
var _default = useAriaLabelWarning;
|
@@ -28,7 +28,7 @@ test('default useAriaLabelWarning', function () {
|
|
28
28
|
expect(spy).toHaveBeenCalledTimes(1);
|
29
29
|
});
|
30
30
|
test('useAriaLabelWarning with string', function () {
|
31
|
-
var compound = "".concat(component, "
|
31
|
+
var compound = "".concat(component, " has an undefined aria-label. If the surrounding content sufficiently labels this component instance, you may disable this warning by setting the prop to `null`. Otherwise, please provide an appropriate aria-label. See more info here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label");
|
32
32
|
var spy = jest.spyOn(console, 'warn');
|
33
33
|
expect(spy).not.toHaveBeenCalled();
|
34
34
|
(0, _reactHooks.renderHook)(function () {
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
|
11
|
+
_Object$defineProperty(exports, "default", {
|
12
|
+
enumerable: true,
|
13
|
+
get: function get() {
|
14
|
+
return _useDevelopmentWarning["default"];
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
var _useDevelopmentWarning = _interopRequireDefault(require("./useDevelopmentWarning"));
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
|
9
|
+
exports["default"] = void 0;
|
10
|
+
|
11
|
+
var _react = require("react");
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Provides a development-only console warning.
|
15
|
+
*/
|
16
|
+
var useDevelopmentWarning = function useDevelopmentWarning(_ref) {
|
17
|
+
var message = _ref.message,
|
18
|
+
shouldTrigger = _ref.shouldTrigger;
|
19
|
+
(0, _react.useMemo)(function () {
|
20
|
+
if (process.env.NODE_ENV === 'development' && shouldTrigger) {
|
21
|
+
// eslint-disable-next-line no-console
|
22
|
+
console.warn("".concat(message), '\n', '\n', 'NOTE: This is a development-only warning and will not display in production.');
|
23
|
+
}
|
24
|
+
}, [message, shouldTrigger]);
|
25
|
+
};
|
26
|
+
|
27
|
+
var _default = useDevelopmentWarning;
|
28
|
+
exports["default"] = _default;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _reactHooks = require("@testing-library/react-hooks");
|
6
|
+
|
7
|
+
var _useDevelopmentWarning = _interopRequireDefault(require("./useDevelopmentWarning"));
|
8
|
+
|
9
|
+
var message = 'This is test message';
|
10
|
+
beforeEach(function () {
|
11
|
+
process.env.NODE_ENV = 'development';
|
12
|
+
|
13
|
+
global.console.warn = function () {
|
14
|
+
return jest.mock();
|
15
|
+
}; // eslint-disable-line no-console
|
16
|
+
|
17
|
+
});
|
18
|
+
afterEach(function () {
|
19
|
+
process.env.NODE_ENV = 'test';
|
20
|
+
jest.restoreAllMocks();
|
21
|
+
});
|
22
|
+
test('useDevelopmentWarning with message and trigger false', function () {
|
23
|
+
var spy = jest.spyOn(console, 'warn');
|
24
|
+
expect(spy).not.toHaveBeenCalled();
|
25
|
+
(0, _reactHooks.renderHook)(function () {
|
26
|
+
return (0, _useDevelopmentWarning["default"])({
|
27
|
+
message: message,
|
28
|
+
shouldTrigger: false
|
29
|
+
});
|
30
|
+
});
|
31
|
+
expect(spy).not.toHaveBeenCalled();
|
32
|
+
});
|
33
|
+
test('useDevelopmentWarning with message and trigger true', function () {
|
34
|
+
var spy = jest.spyOn(console, 'warn');
|
35
|
+
expect(spy).not.toHaveBeenCalled();
|
36
|
+
(0, _reactHooks.renderHook)(function () {
|
37
|
+
return (0, _useDevelopmentWarning["default"])({
|
38
|
+
message: message,
|
39
|
+
shouldTrigger: true
|
40
|
+
});
|
41
|
+
});
|
42
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(message), expect.any(String), expect.any(String), expect.any(String));
|
43
|
+
});
|
@@ -0,0 +1,165 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
|
11
|
+
exports["default"] = exports.Default = void 0;
|
12
|
+
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
14
|
+
|
15
|
+
var _CreateIcon = _interopRequireDefault(require("mdi-react/CreateIcon"));
|
16
|
+
|
17
|
+
var _index = require("../index");
|
18
|
+
|
19
|
+
var _react2 = require("@emotion/react");
|
20
|
+
|
21
|
+
var _default = {
|
22
|
+
title: 'Recipes/AttributeMappingReadOnlyField'
|
23
|
+
};
|
24
|
+
exports["default"] = _default;
|
25
|
+
|
26
|
+
var Default = function Default() {
|
27
|
+
var Row = function Row(props) {
|
28
|
+
var withChip = props.withChip,
|
29
|
+
withTooltip = props.withTooltip,
|
30
|
+
leftValue = props.leftValue,
|
31
|
+
rightValue = props.rightValue;
|
32
|
+
return (0, _react2.jsx)(_index.Box, {
|
33
|
+
isRow: true,
|
34
|
+
alignItems: "center",
|
35
|
+
mt: "10px"
|
36
|
+
}, (0, _react2.jsx)(_index.TextField, {
|
37
|
+
isReadOnly: true,
|
38
|
+
value: leftValue,
|
39
|
+
labelProps: {
|
40
|
+
mb: 0
|
41
|
+
},
|
42
|
+
controlProps: {
|
43
|
+
variant: 'input.small',
|
44
|
+
'aria-label': "input ".concat(leftValue),
|
45
|
+
sx: {
|
46
|
+
width: '165px'
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}), (0, _react2.jsx)(_index.Separator, {
|
50
|
+
sx: {
|
51
|
+
width: '21px',
|
52
|
+
ml: '2px',
|
53
|
+
mr: '2px'
|
54
|
+
}
|
55
|
+
}), (0, _react2.jsx)(_index.TextField, {
|
56
|
+
isReadOnly: true,
|
57
|
+
value: rightValue,
|
58
|
+
labelProps: {
|
59
|
+
mb: 0
|
60
|
+
},
|
61
|
+
controlProps: {
|
62
|
+
variant: 'input.small',
|
63
|
+
'aria-label': "input ".concat(rightValue),
|
64
|
+
sx: {
|
65
|
+
width: '165px'
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}), withChip && (0, _react2.jsx)(_index.Chip, {
|
69
|
+
label: "Required",
|
70
|
+
sx: {
|
71
|
+
width: '65px',
|
72
|
+
height: '22px',
|
73
|
+
alignSelf: 'center',
|
74
|
+
minWidth: 'fit-content',
|
75
|
+
border: '1px solid',
|
76
|
+
borderColor: 'neutral.80',
|
77
|
+
backgroundColor: 'white !important',
|
78
|
+
ml: 8,
|
79
|
+
'& span': {
|
80
|
+
fontSize: 'sm',
|
81
|
+
lineHeight: 1,
|
82
|
+
color: '#253746'
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}), withTooltip && (0, _react2.jsx)(_index.Box, {
|
86
|
+
ml: "5px",
|
87
|
+
height: "15px",
|
88
|
+
width: "15px"
|
89
|
+
}, (0, _react2.jsx)(_index.HelpHint, {
|
90
|
+
tooltipProps: {
|
91
|
+
direction: 'bottom'
|
92
|
+
}
|
93
|
+
}, "Population set to default")));
|
94
|
+
};
|
95
|
+
|
96
|
+
return (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Box, {
|
97
|
+
isRow: true,
|
98
|
+
alignItems: "center",
|
99
|
+
mb: "15px"
|
100
|
+
}, (0, _react2.jsx)(_index.Text, {
|
101
|
+
sx: {
|
102
|
+
fontSize: 'lg',
|
103
|
+
lineHeight: '21px',
|
104
|
+
fontWeight: 3,
|
105
|
+
color: 'text.primary'
|
106
|
+
}
|
107
|
+
}, "Attribute Mapping"), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.IconButton, {
|
108
|
+
ml: "5px",
|
109
|
+
variant: "inverted",
|
110
|
+
"aria-label": "edit header button"
|
111
|
+
}, (0, _react2.jsx)(_index.Icon, {
|
112
|
+
icon: _CreateIcon["default"],
|
113
|
+
size: 18
|
114
|
+
})))), (0, _react2.jsx)(_index.Box, {
|
115
|
+
backgroundColor: "accent.99",
|
116
|
+
width: "450px",
|
117
|
+
padding: "10px 10px 25px 10px"
|
118
|
+
}, (0, _react2.jsx)(_index.Box, {
|
119
|
+
isRow: true,
|
120
|
+
sx: {
|
121
|
+
width: '100%'
|
122
|
+
}
|
123
|
+
}, (0, _react2.jsx)(_index.Box, {
|
124
|
+
sx: {
|
125
|
+
width: 'calc(50% - 22px)'
|
126
|
+
}
|
127
|
+
}, (0, _react2.jsx)(_index.Text, {
|
128
|
+
sx: {
|
129
|
+
fontWeight: 3,
|
130
|
+
fontSize: 'md',
|
131
|
+
lineHeight: '18px',
|
132
|
+
mb: '5px'
|
133
|
+
}
|
134
|
+
}, "PingOne")), (0, _react2.jsx)(_index.Box, {
|
135
|
+
sx: {
|
136
|
+
width: 'calc(50% - 22px)'
|
137
|
+
}
|
138
|
+
}, (0, _react2.jsx)(_index.Text, {
|
139
|
+
sx: {
|
140
|
+
fontWeight: 3,
|
141
|
+
fontSize: 'md',
|
142
|
+
lineHeight: '18px',
|
143
|
+
mb: '5px'
|
144
|
+
}
|
145
|
+
}, "Google Suites"))), (0, _react2.jsx)(_index.Separator, null), (0, _react2.jsx)(Row, {
|
146
|
+
withChip: true,
|
147
|
+
leftValue: "UserId",
|
148
|
+
rightValue: "mdorey"
|
149
|
+
}), (0, _react2.jsx)(Row, {
|
150
|
+
leftValue: "givenName",
|
151
|
+
rightValue: "firstName"
|
152
|
+
}), (0, _react2.jsx)(Row, {
|
153
|
+
leftValue: "familyName",
|
154
|
+
rightValue: "lastName"
|
155
|
+
}), (0, _react2.jsx)(Row, {
|
156
|
+
withTooltip: true,
|
157
|
+
leftValue: "population",
|
158
|
+
rightValue: "population"
|
159
|
+
}), (0, _react2.jsx)(Row, {
|
160
|
+
leftValue: "password",
|
161
|
+
rightValue: "password"
|
162
|
+
})));
|
163
|
+
};
|
164
|
+
|
165
|
+
exports.Default = Default;
|
@@ -172,12 +172,14 @@ var textFieldInContainerSlot = {
|
|
172
172
|
var copy = {
|
173
173
|
alignItems: 'center',
|
174
174
|
width: 'max-content',
|
175
|
-
cursor: 'pointer',
|
176
175
|
'& .is-focused': {
|
177
176
|
outline: '1px solid',
|
178
177
|
outlineColor: 'active',
|
179
178
|
outlineOffset: '4px',
|
180
179
|
borderRadius: '4px'
|
180
|
+
},
|
181
|
+
'& span': {
|
182
|
+
cursor: 'text'
|
181
183
|
}
|
182
184
|
};
|
183
185
|
var topShadowScrollbox = {
|
@@ -7,10 +7,10 @@ var _excluded = ["children", "tooltip"],
|
|
7
7
|
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
8
8
|
import PropTypes from 'prop-types';
|
9
9
|
import { useFocusRing } from '@react-aria/focus';
|
10
|
-
import {
|
10
|
+
import { useHover, usePress } from '@react-aria/interactions';
|
11
11
|
import { mergeProps } from '@react-aria/utils';
|
12
12
|
import { announce } from '@react-aria/live-announcer';
|
13
|
-
import { Box,
|
13
|
+
import { Box, Tooltip, TooltipTrigger } from '../../index';
|
14
14
|
import CopyButton from './CopyButton';
|
15
15
|
import useCopyToClipboard from '../../hooks/useCopyToClipboard';
|
16
16
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
@@ -82,14 +82,41 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
82
82
|
return undefined;
|
83
83
|
}, [isCopied]);
|
84
84
|
var copyToClipboard = useCopyToClipboard(value, setIsCopied);
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
|
86
|
+
var onTextClick = function onTextClick() {
|
87
|
+
var selection = window.getSelection();
|
88
|
+
|
89
|
+
if (selection.toString() === '') {
|
90
|
+
copyToClipboard();
|
91
|
+
}
|
92
|
+
};
|
93
|
+
/* Used for text copying */
|
94
|
+
|
95
|
+
|
96
|
+
var contentRef = useRef();
|
97
|
+
|
98
|
+
var _usePress = usePress({
|
99
|
+
ref: contentRef,
|
100
|
+
onClick: onTextClick
|
101
|
+
}),
|
102
|
+
pressProps = _usePress.pressProps;
|
103
|
+
|
104
|
+
delete pressProps.onMouseDown;
|
105
|
+
delete pressProps.onPointerDown;
|
106
|
+
var content = mode === 'link' || mode === 'nonClickableContent' ? children : ___EmotionJSX(Box, _extends({
|
107
|
+
ref: contentRef
|
108
|
+
}, mergeProps(focusProps, pressProps)), children);
|
91
109
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
92
110
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
111
|
+
var pressableRef = useRef();
|
112
|
+
|
113
|
+
var _usePress2 = usePress({
|
114
|
+
ref: pressableRef
|
115
|
+
}),
|
116
|
+
pressableProps = _usePress2.pressProps;
|
117
|
+
|
118
|
+
delete pressableProps.onMouseDown;
|
119
|
+
delete pressableProps.onPointerDown;
|
93
120
|
var wrapperRef = useRef();
|
94
121
|
|
95
122
|
if (mode === 'nonClickableContent') {
|
@@ -121,12 +148,19 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
121
148
|
|
122
149
|
return ___EmotionJSX(TooltipWrapper, {
|
123
150
|
isOpen: isTooltipOpen,
|
124
|
-
tooltip: tooltip
|
125
|
-
|
151
|
+
tooltip: tooltip,
|
152
|
+
targetRef: pressableRef
|
153
|
+
}, ___EmotionJSX(Box, _extends({
|
154
|
+
ref: pressableRef
|
155
|
+
}, mergeProps(hoverProps, pressableProps), {
|
156
|
+
sx: {
|
157
|
+
width: 'min-content'
|
158
|
+
}
|
159
|
+
}), ___EmotionJSX(Box, _extends({
|
126
160
|
ref: ref,
|
127
161
|
isRow: true,
|
128
162
|
variant: "boxes.copy"
|
129
|
-
},
|
163
|
+
}, others), content, ___EmotionJSX(CopyButton, _extends({
|
130
164
|
onPress: copyToClipboard
|
131
165
|
}, focusProps)))));
|
132
166
|
});
|
@@ -27,6 +27,7 @@ var testId = 'test-copy-text';
|
|
27
27
|
var originalClipboard = _objectSpread({}, global.navigator.clipboard);
|
28
28
|
|
29
29
|
var originalExecCommand = global.document.execCommand;
|
30
|
+
var originalGetSelection = window.getSelection;
|
30
31
|
|
31
32
|
var defaultTest = function defaultTest() {
|
32
33
|
var getComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
@@ -75,11 +76,15 @@ describe('Text mode', function () {
|
|
75
76
|
global.navigator.clipboard = mockClipboard;
|
76
77
|
global.document.execCommand = jest.fn();
|
77
78
|
global.document.execCommand.mockReturnValue(true);
|
79
|
+
var mockGetSelection = jest.fn();
|
80
|
+
mockGetSelection.mockReturnValue('');
|
81
|
+
window.getSelection = mockGetSelection;
|
78
82
|
});
|
79
83
|
afterEach(function () {
|
80
84
|
jest.resetAllMocks();
|
81
85
|
global.navigator.clipboard = originalClipboard;
|
82
86
|
global.document.execCommand = originalExecCommand;
|
87
|
+
window.getSelection = originalGetSelection;
|
83
88
|
});
|
84
89
|
test('click on text copies data to the clipboard', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
85
90
|
var button;
|
@@ -388,10 +393,14 @@ describe('Link mode', function () {
|
|
388
393
|
writeText: jest.fn()
|
389
394
|
};
|
390
395
|
global.navigator.clipboard = mockClipboard;
|
396
|
+
var mockGetSelection = jest.fn();
|
397
|
+
mockGetSelection.mockReturnValue('');
|
398
|
+
window.getSelection = mockGetSelection;
|
391
399
|
});
|
392
400
|
afterEach(function () {
|
393
401
|
jest.resetAllMocks();
|
394
402
|
global.navigator.clipboard = originalClipboard;
|
403
|
+
window.getSelection = originalGetSelection;
|
395
404
|
});
|
396
405
|
test('click on copy button copies data to the clipboard', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
|
397
406
|
var button;
|
@@ -1,19 +1,16 @@
|
|
1
|
-
import
|
1
|
+
import useDevelopmentWarning from '../useDevelopmentWarning';
|
2
2
|
/**
|
3
3
|
* Provides a development-only console warning when a component
|
4
4
|
* that needs an aria-label is mounted without one.
|
5
|
-
*
|
6
|
-
* e.g. "\`Component\` requires an aria-label."
|
7
5
|
*/
|
8
6
|
|
9
7
|
var useAriaLabelWarning = function useAriaLabelWarning(component, ariaLabel) {
|
10
|
-
var
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}, []);
|
8
|
+
var shouldTrigger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
9
|
+
var message = "".concat(component, " has an undefined aria-label. If the surrounding content sufficiently labels this component instance, you may disable this warning by setting the prop to `null`. Otherwise, please provide an appropriate aria-label. See more info here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label");
|
10
|
+
useDevelopmentWarning({
|
11
|
+
message: message,
|
12
|
+
shouldTrigger: shouldTrigger && ariaLabel === undefined
|
13
|
+
});
|
17
14
|
};
|
18
15
|
|
19
16
|
export default useAriaLabelWarning;
|
@@ -22,7 +22,7 @@ test('default useAriaLabelWarning', function () {
|
|
22
22
|
expect(spy).toHaveBeenCalledTimes(1);
|
23
23
|
});
|
24
24
|
test('useAriaLabelWarning with string', function () {
|
25
|
-
var compound = "".concat(component, "
|
25
|
+
var compound = "".concat(component, " has an undefined aria-label. If the surrounding content sufficiently labels this component instance, you may disable this warning by setting the prop to `null`. Otherwise, please provide an appropriate aria-label. See more info here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label");
|
26
26
|
var spy = jest.spyOn(console, 'warn');
|
27
27
|
expect(spy).not.toHaveBeenCalled();
|
28
28
|
renderHook(function () {
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useDevelopmentWarning';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { useMemo } from 'react';
|
2
|
+
/**
|
3
|
+
* Provides a development-only console warning.
|
4
|
+
*/
|
5
|
+
|
6
|
+
var useDevelopmentWarning = function useDevelopmentWarning(_ref) {
|
7
|
+
var message = _ref.message,
|
8
|
+
shouldTrigger = _ref.shouldTrigger;
|
9
|
+
useMemo(function () {
|
10
|
+
if (process.env.NODE_ENV === 'development' && shouldTrigger) {
|
11
|
+
// eslint-disable-next-line no-console
|
12
|
+
console.warn("".concat(message), '\n', '\n', 'NOTE: This is a development-only warning and will not display in production.');
|
13
|
+
}
|
14
|
+
}, [message, shouldTrigger]);
|
15
|
+
};
|
16
|
+
|
17
|
+
export default useDevelopmentWarning;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks';
|
2
|
+
import useDevelopmentWarning from './useDevelopmentWarning';
|
3
|
+
var message = 'This is test message';
|
4
|
+
beforeEach(function () {
|
5
|
+
process.env.NODE_ENV = 'development';
|
6
|
+
|
7
|
+
global.console.warn = function () {
|
8
|
+
return jest.mock();
|
9
|
+
}; // eslint-disable-line no-console
|
10
|
+
|
11
|
+
});
|
12
|
+
afterEach(function () {
|
13
|
+
process.env.NODE_ENV = 'test';
|
14
|
+
jest.restoreAllMocks();
|
15
|
+
});
|
16
|
+
test('useDevelopmentWarning with message and trigger false', function () {
|
17
|
+
var spy = jest.spyOn(console, 'warn');
|
18
|
+
expect(spy).not.toHaveBeenCalled();
|
19
|
+
renderHook(function () {
|
20
|
+
return useDevelopmentWarning({
|
21
|
+
message: message,
|
22
|
+
shouldTrigger: false
|
23
|
+
});
|
24
|
+
});
|
25
|
+
expect(spy).not.toHaveBeenCalled();
|
26
|
+
});
|
27
|
+
test('useDevelopmentWarning with message and trigger true', function () {
|
28
|
+
var spy = jest.spyOn(console, 'warn');
|
29
|
+
expect(spy).not.toHaveBeenCalled();
|
30
|
+
renderHook(function () {
|
31
|
+
return useDevelopmentWarning({
|
32
|
+
message: message,
|
33
|
+
shouldTrigger: true
|
34
|
+
});
|
35
|
+
});
|
36
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.stringMatching(message), expect.any(String), expect.any(String), expect.any(String));
|
37
|
+
});
|