@pingux/astro 1.1.0-alpha.11 → 1.1.0-alpha.15
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/CHANGELOG.md +11 -0
- package/lib/cjs/components/CodeView/CodeView.js +165 -0
- package/lib/cjs/components/CodeView/CodeView.stories.js +93 -0
- package/lib/cjs/components/CodeView/CodeView.test.js +211 -0
- package/lib/cjs/components/CodeView/index.js +18 -0
- package/lib/cjs/components/CopyText/CopyText.js +34 -11
- package/lib/cjs/components/NavBar/NavBar.js +38 -0
- package/lib/cjs/components/NavBar/NavBar.stories.js +679 -0
- package/lib/cjs/components/NavBar/NavBar.test.js +116 -0
- package/lib/cjs/components/NavBar/index.js +18 -0
- package/lib/cjs/components/NavBarSection/NavBarItemBody.js +56 -0
- package/lib/cjs/components/NavBarSection/NavBarItemHeader.js +47 -0
- package/lib/cjs/components/NavBarSection/NavBarSection.js +82 -0
- package/lib/cjs/components/NavBarSection/index.js +18 -0
- package/lib/cjs/components/Separator/Separator.js +1 -1
- package/lib/cjs/components/TooltipTrigger/TooltipTrigger.js +10 -5
- package/lib/cjs/index.js +84 -30
- package/lib/cjs/styles/variants/accordion.js +32 -1
- package/lib/cjs/styles/variants/boxes.js +24 -1
- package/lib/cjs/styles/variants/buttons.js +28 -0
- package/lib/cjs/styles/variants/codeView.js +80 -0
- package/lib/cjs/styles/variants/link.js +1 -1
- package/lib/cjs/styles/variants/separator.js +46 -3
- package/lib/cjs/styles/variants/text.js +15 -0
- package/lib/cjs/styles/variants/variants.js +3 -0
- package/lib/components/CodeView/CodeView.js +130 -0
- package/lib/components/CodeView/CodeView.stories.js +67 -0
- package/lib/components/CodeView/CodeView.test.js +171 -0
- package/lib/components/CodeView/index.js +1 -0
- package/lib/components/CopyText/CopyText.js +35 -11
- package/lib/components/NavBar/NavBar.js +24 -0
- package/lib/components/NavBar/NavBar.stories.js +650 -0
- package/lib/components/NavBar/NavBar.test.js +92 -0
- package/lib/components/NavBar/index.js +1 -0
- package/lib/components/NavBarSection/NavBarItemBody.js +37 -0
- package/lib/components/NavBarSection/NavBarItemHeader.js +31 -0
- package/lib/components/NavBarSection/NavBarSection.js +65 -0
- package/lib/components/NavBarSection/index.js +1 -0
- package/lib/components/Separator/Separator.js +1 -1
- package/lib/components/TooltipTrigger/TooltipTrigger.js +10 -5
- package/lib/index.js +5 -0
- package/lib/styles/variants/accordion.js +32 -1
- package/lib/styles/variants/boxes.js +24 -1
- package/lib/styles/variants/buttons.js +28 -0
- package/lib/styles/variants/codeView.js +68 -0
- package/lib/styles/variants/link.js +1 -1
- package/lib/styles/variants/separator.js +33 -1
- package/lib/styles/variants/text.js +15 -0
- package/lib/styles/variants/variants.js +2 -0
- package/package.json +3 -1
@@ -34,6 +34,8 @@ var _accordion = _interopRequireDefault(require("./accordion"));
|
|
34
34
|
|
35
35
|
var _boxes = _interopRequireDefault(require("./boxes"));
|
36
36
|
|
37
|
+
var _codeView = _interopRequireDefault(require("./codeView"));
|
38
|
+
|
37
39
|
var _images = _interopRequireDefault(require("./images"));
|
38
40
|
|
39
41
|
var _imageUpload = _interopRequireDefault(require("./imageUpload"));
|
@@ -77,6 +79,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
77
79
|
var _default = _objectSpread(_objectSpread({
|
78
80
|
accordion: _accordion["default"],
|
79
81
|
boxes: _boxes["default"],
|
82
|
+
codeView: _codeView["default"],
|
80
83
|
images: _images["default"],
|
81
84
|
imageUpload: _imageUpload["default"],
|
82
85
|
loader: _loader["default"],
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
12
|
+
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
|
13
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
14
|
+
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
16
|
+
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context; _forEachInstanceProperty(_context = ownKeys(Object(source), true)).call(_context, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
18
|
+
|
19
|
+
import React, { forwardRef } from 'react';
|
20
|
+
import PropTypes from 'prop-types';
|
21
|
+
import { useFocusRing } from '@react-aria/focus';
|
22
|
+
import { useHover } from '@react-aria/interactions';
|
23
|
+
import { mergeProps } from '@react-aria/utils';
|
24
|
+
import Highlight, { defaultProps } from 'prism-react-renderer';
|
25
|
+
import { useStatusClasses } from '../../hooks';
|
26
|
+
import { Box, CopyText } from '../..';
|
27
|
+
/**
|
28
|
+
* A text block that shows syntax highlighting code sample.
|
29
|
+
* Built on top of the [prism-react-renderer](https://github.com/FormidableLabs/prism-react-renderer).
|
30
|
+
*
|
31
|
+
* A list of all supported languages that can be passed to `language` prop is [here](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).
|
32
|
+
*/
|
33
|
+
|
34
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
35
|
+
var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
36
|
+
var children = props.children,
|
37
|
+
outerClassName = props.className,
|
38
|
+
hasLineNumbers = props.hasLineNumbers,
|
39
|
+
hasNoCopyButton = props.hasNoCopyButton,
|
40
|
+
language = props.language,
|
41
|
+
others = _objectWithoutProperties(props, ["children", "className", "hasLineNumbers", "hasNoCopyButton", "language"]);
|
42
|
+
|
43
|
+
var _useFocusRing = useFocusRing(),
|
44
|
+
isFocusVisible = _useFocusRing.isFocusVisible,
|
45
|
+
focusProps = _useFocusRing.focusProps;
|
46
|
+
|
47
|
+
var _useHover = useHover(props),
|
48
|
+
hoverProps = _useHover.hoverProps,
|
49
|
+
isHovered = _useHover.isHovered;
|
50
|
+
|
51
|
+
var _useStatusClasses = useStatusClasses(outerClassName, {
|
52
|
+
isFocused: isFocusVisible,
|
53
|
+
isHovered: isHovered,
|
54
|
+
hasLineNumbers: hasLineNumbers,
|
55
|
+
hasNoCopyButton: hasNoCopyButton
|
56
|
+
}),
|
57
|
+
classNames = _useStatusClasses.classNames; // Get the width for the line number element depending on the total amount of lines
|
58
|
+
|
59
|
+
|
60
|
+
var getLineNoWidth = function getLineNoWidth(tokens) {
|
61
|
+
return tokens.length.toString().length * 12;
|
62
|
+
};
|
63
|
+
|
64
|
+
var content = ___EmotionJSX(Highlight, _extends({}, defaultProps, {
|
65
|
+
theme: undefined,
|
66
|
+
code: (children === null || children === void 0 ? void 0 : _trimInstanceProperty(children).call(children)) || '',
|
67
|
+
language: language
|
68
|
+
}), function (_ref) {
|
69
|
+
var className = _ref.className,
|
70
|
+
style = _ref.style,
|
71
|
+
tokens = _ref.tokens,
|
72
|
+
getLineProps = _ref.getLineProps,
|
73
|
+
getTokenProps = _ref.getTokenProps;
|
74
|
+
return ___EmotionJSX(Box, {
|
75
|
+
as: "pre",
|
76
|
+
className: className,
|
77
|
+
style: style
|
78
|
+
}, _mapInstanceProperty(tokens).call(tokens, function (line, i) {
|
79
|
+
return ___EmotionJSX(Box, _extends({
|
80
|
+
isRow: true
|
81
|
+
}, getLineProps({
|
82
|
+
line: line,
|
83
|
+
key: i
|
84
|
+
})), hasLineNumbers && ___EmotionJSX(Box, {
|
85
|
+
as: "span",
|
86
|
+
variant: "codeView.lineNo",
|
87
|
+
sx: {
|
88
|
+
minWidth: getLineNoWidth(tokens)
|
89
|
+
}
|
90
|
+
}, i + 1), _mapInstanceProperty(line).call(line, function (token, key) {
|
91
|
+
return ___EmotionJSX("span", getTokenProps({
|
92
|
+
token: token,
|
93
|
+
key: key
|
94
|
+
}));
|
95
|
+
}));
|
96
|
+
}));
|
97
|
+
});
|
98
|
+
|
99
|
+
if (hasNoCopyButton) {
|
100
|
+
return ___EmotionJSX(Box, _extends({
|
101
|
+
ref: ref,
|
102
|
+
variant: "codeView.wrapper",
|
103
|
+
tabIndex: 0,
|
104
|
+
className: classNames
|
105
|
+
}, mergeProps(focusProps, hoverProps, others)), content);
|
106
|
+
}
|
107
|
+
|
108
|
+
return ___EmotionJSX(CopyText, {
|
109
|
+
mode: "nonClickableContent",
|
110
|
+
textToCopy: children,
|
111
|
+
tooltipProps: {
|
112
|
+
offset: 15
|
113
|
+
},
|
114
|
+
wrapperProps: _objectSpread({
|
115
|
+
className: classNames,
|
116
|
+
variant: 'codeView.wrapper'
|
117
|
+
}, others)
|
118
|
+
}, content);
|
119
|
+
});
|
120
|
+
CodeView.propTypes = {
|
121
|
+
hasLineNumbers: PropTypes.bool,
|
122
|
+
hasNoCopyButton: PropTypes.bool,
|
123
|
+
language: PropTypes.string
|
124
|
+
};
|
125
|
+
CodeView.defaultProps = {
|
126
|
+
language: 'json',
|
127
|
+
hasLineNumbers: false,
|
128
|
+
hasNoCopyButton: false
|
129
|
+
};
|
130
|
+
export default CodeView;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import CodeView from './CodeView';
|
3
|
+
import { Text } from '../..';
|
4
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
5
|
+
var code = "{\n \"_links\": {\n \"self\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad\"\n },\n \"password\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/password\"\n },\n \"password.set\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/password\"\n },\n \"password.reset\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/password\"\n },\n \"password.check\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/password\"\n },\n \"password.recover\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/password\"\n },\n \"account.sendVerificationCode\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad\"\n },\n \"linkedAccounts\": {\n \"href\": \"https://api.pingone.com/v1/environments/94e3268d-847d-47aa-a45e-1ef8dd8f4df0/users/5a5d4c0c-8383-4796-9cdc-16b5a22f45ad/linkedAccounts\"\n }\n },\n \"id\": \"5a5d4c0c-8383-4796-9cdc-16b5a22f45ad\",\n \"environment\": {\n \"id\": \"94e3268d-847d-47aa-a45e-1ef8dd8f4df0\"\n },\n \"account\": {\n \"canAuthenticate\": true,\n \"status\": \"OK\"\n },\n \"createdAt\": \"2021-09-03T15:01:43.555Z\",\n \"email\": \"allegraweldon@pingidentity.com\",\n \"enabled\": true,\n \"identityProvider\": {\n \"type\": \"PING_ONE\"\n },\n \"lifecycle\": {\n \"status\": \"ACCOUNT_OK\"\n },\n \"mfaEnabled\": false,\n \"population\": {\n \"id\": \"c1adbc29-f188-4ea6-a015-49bddd74bc84\"\n },\n \"updatedAt\": \"2021-09-03T15:01:43.555Z\",\n \"username\": \"allegraweldon@pingidentity.com\",\n \"verifyStatus\": \"NOT_INITIATED\"\n}";
|
6
|
+
export default {
|
7
|
+
title: 'CodeView',
|
8
|
+
component: CodeView,
|
9
|
+
argTypes: {
|
10
|
+
children: {
|
11
|
+
defaultValue: code,
|
12
|
+
table: {
|
13
|
+
type: {}
|
14
|
+
},
|
15
|
+
control: {
|
16
|
+
type: 'text'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
parameters: {
|
21
|
+
a11y: {
|
22
|
+
config: {
|
23
|
+
rules: [
|
24
|
+
/* Turned off since rule conflicts with the way how `prism-react-renderer` works
|
25
|
+
* and design specs */
|
26
|
+
{
|
27
|
+
id: 'scrollable-region-focusable',
|
28
|
+
enabled: false,
|
29
|
+
selector: '.prism-code'
|
30
|
+
}]
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
};
|
35
|
+
export var Default = function Default(args) {
|
36
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Text, {
|
37
|
+
sx: {
|
38
|
+
fontWeight: 2
|
39
|
+
}
|
40
|
+
}, "JSON"), ___EmotionJSX(CodeView, args));
|
41
|
+
};
|
42
|
+
export var WithLineNumbers = function WithLineNumbers() {
|
43
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Text, {
|
44
|
+
sx: {
|
45
|
+
fontWeight: 2
|
46
|
+
}
|
47
|
+
}, "JSON"), ___EmotionJSX(CodeView, {
|
48
|
+
hasLineNumbers: true
|
49
|
+
}, code));
|
50
|
+
};
|
51
|
+
WithLineNumbers.story = {
|
52
|
+
parameters: {
|
53
|
+
docs: {
|
54
|
+
storyDescription: 'Please note that with adding line numbers, line wrapping does not work.'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
export var WithCustomSize = function WithCustomSize() {
|
59
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(CodeView, {
|
60
|
+
language: "javascript",
|
61
|
+
sx: {
|
62
|
+
width: '100%',
|
63
|
+
height: 300
|
64
|
+
},
|
65
|
+
hasNoCopyButton: true
|
66
|
+
}, "\nexport const ChipWithIcon = () => (\n <>\n <Chip label=\"Chip with Icon Button\" bg=\"navy\">\n <IconButton aria-label=\"Clear Chip with Icon Button\" variant=\"inverted\">\n <Icon icon={Clear} ml=\"xs\" size=\"14px\" />\n </IconButton>\n </Chip>\n\n <div style={{ padding: '5px' }} />\n\n <Chip label=\"Chip with Icon Button\">\n <IconButton aria-label=\"Clear Chip with Icon Button\" variant=\"inverted\">\n <Icon icon={Earth} ml=\"xs\" size=\"14px\" />\n </IconButton>\n </Chip>\n\n <div style={{ padding: '5px' }} />\n\n <Chip label=\"Chip with Icon\" bg=\"green\">\n <Icon icon={ContentCopy} ml=\"xs\" size=\"14px\" color=\"white\" />\n </Chip>\n </>\n);\n "));
|
67
|
+
};
|
@@ -0,0 +1,171 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
10
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
11
|
+
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
|
12
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
13
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
14
|
+
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
16
|
+
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source), true)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context6; _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
18
|
+
|
19
|
+
import React from 'react';
|
20
|
+
import userEvent from '@testing-library/user-event';
|
21
|
+
import axeTest from '../../utils/testUtils/testAxe';
|
22
|
+
import { act, fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
23
|
+
import { CodeView } from '../..';
|
24
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
25
|
+
var testId = 'test-code-sample';
|
26
|
+
|
27
|
+
var originalClipboard = _objectSpread({}, global.navigator.clipboard);
|
28
|
+
|
29
|
+
var originalExecCommand = global.document.execCommand;
|
30
|
+
var defaultProps = {
|
31
|
+
'data-testid': testId
|
32
|
+
};
|
33
|
+
var textValue = "\nexport const Default = args => (\n <>\n <Text sx={{ fontWeight: 2 }}>JSON</Text>\n <CodeView {...args} />\n </>\n);\n";
|
34
|
+
|
35
|
+
var getComponent = function getComponent() {
|
36
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37
|
+
return render(___EmotionJSX(CodeView, _extends({}, defaultProps, props), textValue));
|
38
|
+
}; // Need to be added to each test file to test accessibility using axe.
|
39
|
+
|
40
|
+
|
41
|
+
axeTest(getComponent);
|
42
|
+
test('renders component in the default state', function () {
|
43
|
+
getComponent();
|
44
|
+
var container = screen.getByTestId(testId);
|
45
|
+
expect(container).toBeInstanceOf(HTMLDivElement);
|
46
|
+
expect(container).toBeInTheDocument();
|
47
|
+
});
|
48
|
+
test('tooltip renders on hover', function () {
|
49
|
+
getComponent();
|
50
|
+
var container = screen.getByTestId(testId);
|
51
|
+
fireEvent.mouseMove(container);
|
52
|
+
fireEvent.mouseEnter(container);
|
53
|
+
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
|
54
|
+
expect(screen.queryByRole('tooltip')).toHaveTextContent('Copy to clipboard');
|
55
|
+
});
|
56
|
+
test('content and copy button are focused via keyboard', function () {
|
57
|
+
getComponent();
|
58
|
+
var container = screen.getByTestId(testId);
|
59
|
+
expect(container).not.toHaveFocus();
|
60
|
+
userEvent.tab();
|
61
|
+
expect(container).toHaveFocus();
|
62
|
+
var copyBtn = screen.getByLabelText('copy');
|
63
|
+
expect(copyBtn).not.toHaveFocus();
|
64
|
+
userEvent.tab();
|
65
|
+
expect(copyBtn).toHaveFocus();
|
66
|
+
expect(copyBtn).toHaveClass('is-focused');
|
67
|
+
});
|
68
|
+
test('doesn\'t render copy button and tooltip with prop hasNoCopyButton', function () {
|
69
|
+
getComponent({
|
70
|
+
hasNoCopyButton: true
|
71
|
+
});
|
72
|
+
var container = screen.getByTestId(testId);
|
73
|
+
fireEvent.mouseMove(container);
|
74
|
+
fireEvent.mouseEnter(container);
|
75
|
+
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
76
|
+
expect(screen.queryByLabelText('copy')).not.toBeInTheDocument();
|
77
|
+
});
|
78
|
+
test('renders line numbers with prop hasLineNumbers', function () {
|
79
|
+
var linesLength = (_trimInstanceProperty(textValue).call(textValue).split('\n').length - 1).toString();
|
80
|
+
getComponent();
|
81
|
+
expect(screen.queryByText('1')).not.toBeInTheDocument();
|
82
|
+
expect(screen.queryByText(linesLength)).not.toBeInTheDocument();
|
83
|
+
getComponent({
|
84
|
+
hasLineNumbers: true
|
85
|
+
});
|
86
|
+
expect(screen.queryByText('1')).toBeInTheDocument();
|
87
|
+
expect(screen.queryByText(linesLength)).toBeInTheDocument();
|
88
|
+
});
|
89
|
+
beforeEach(function () {
|
90
|
+
var mockClipboard = {
|
91
|
+
writeText: jest.fn()
|
92
|
+
};
|
93
|
+
global.navigator.clipboard = mockClipboard;
|
94
|
+
global.document.execCommand = jest.fn();
|
95
|
+
global.document.execCommand.mockReturnValue(true);
|
96
|
+
});
|
97
|
+
afterEach(function () {
|
98
|
+
jest.resetAllMocks();
|
99
|
+
global.navigator.clipboard = originalClipboard;
|
100
|
+
global.document.execCommand = originalExecCommand;
|
101
|
+
});
|
102
|
+
test('click on copy button copies data to the clipboard', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
103
|
+
var button;
|
104
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
105
|
+
while (1) {
|
106
|
+
switch (_context2.prev = _context2.next) {
|
107
|
+
case 0:
|
108
|
+
getComponent();
|
109
|
+
button = screen.getByLabelText('copy');
|
110
|
+
_context2.next = 4;
|
111
|
+
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
112
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
113
|
+
while (1) {
|
114
|
+
switch (_context.prev = _context.next) {
|
115
|
+
case 0:
|
116
|
+
return _context.abrupt("return", userEvent.click(button));
|
117
|
+
|
118
|
+
case 1:
|
119
|
+
case "end":
|
120
|
+
return _context.stop();
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}, _callee);
|
124
|
+
})));
|
125
|
+
|
126
|
+
case 4:
|
127
|
+
expect(navigator.clipboard.writeText).toBeCalledTimes(1);
|
128
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(textValue);
|
129
|
+
|
130
|
+
case 6:
|
131
|
+
case "end":
|
132
|
+
return _context2.stop();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}, _callee2);
|
136
|
+
})));
|
137
|
+
test('after button click, the tooltip renders with the text "Copied!"', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
138
|
+
var button;
|
139
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
140
|
+
while (1) {
|
141
|
+
switch (_context4.prev = _context4.next) {
|
142
|
+
case 0:
|
143
|
+
getComponent();
|
144
|
+
button = screen.getByLabelText('copy');
|
145
|
+
_context4.next = 4;
|
146
|
+
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
147
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
148
|
+
while (1) {
|
149
|
+
switch (_context3.prev = _context3.next) {
|
150
|
+
case 0:
|
151
|
+
return _context3.abrupt("return", userEvent.click(button));
|
152
|
+
|
153
|
+
case 1:
|
154
|
+
case "end":
|
155
|
+
return _context3.stop();
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}, _callee3);
|
159
|
+
})));
|
160
|
+
|
161
|
+
case 4:
|
162
|
+
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
|
163
|
+
expect(screen.queryByRole('tooltip')).toHaveTextContent('Copied!');
|
164
|
+
|
165
|
+
case 6:
|
166
|
+
case "end":
|
167
|
+
return _context4.stop();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}, _callee4);
|
171
|
+
})));
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './CodeView';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
1
|
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
3
2
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
3
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
4
4
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
5
|
-
import React, { forwardRef, useEffect, useState } from 'react';
|
5
|
+
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
6
6
|
import PropTypes from 'prop-types';
|
7
7
|
import { useFocusRing } from '@react-aria/focus';
|
8
8
|
import { Pressable, useHover } from '@react-aria/interactions';
|
@@ -14,19 +14,20 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
14
14
|
|
15
15
|
var TooltipWrapper = function TooltipWrapper(_ref) {
|
16
16
|
var children = _ref.children,
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
tooltip = _ref.tooltip,
|
18
|
+
others = _objectWithoutProperties(_ref, ["children", "tooltip"]);
|
19
|
+
|
20
|
+
return ___EmotionJSX(TooltipTrigger, _extends({
|
20
21
|
key: tooltip,
|
21
22
|
direction: "top",
|
22
23
|
isNotFlippable: true,
|
23
|
-
isOpen: isOpen,
|
24
24
|
offset: 5
|
25
|
-
}, children, ___EmotionJSX(Tooltip, null, tooltip));
|
25
|
+
}, others), children, ___EmotionJSX(Tooltip, null, tooltip));
|
26
26
|
};
|
27
27
|
|
28
28
|
TooltipWrapper.propTypes = {
|
29
29
|
isOpen: PropTypes.bool,
|
30
|
+
targetRef: PropTypes.shape({}),
|
30
31
|
tooltip: PropTypes.string
|
31
32
|
};
|
32
33
|
/**
|
@@ -38,7 +39,9 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
38
39
|
textToCopy = props.textToCopy,
|
39
40
|
tooltipText = props.tooltipText,
|
40
41
|
mode = props.mode,
|
41
|
-
|
42
|
+
tooltipProps = props.tooltipProps,
|
43
|
+
wrapperProps = props.wrapperProps,
|
44
|
+
others = _objectWithoutProperties(props, ["children", "textToCopy", "tooltipText", "mode", "tooltipProps", "wrapperProps"]);
|
42
45
|
|
43
46
|
var value = textToCopy || (mode === 'link' ? children.props.href : children.props.children);
|
44
47
|
|
@@ -75,13 +78,28 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
75
78
|
return undefined;
|
76
79
|
}, [isCopied]);
|
77
80
|
var copyToClipboard = useCopyToClipboard(value, setIsCopied);
|
78
|
-
var content = mode === 'link' ? children : ___EmotionJSX(Button, _extends({
|
81
|
+
var content = mode === 'link' || mode === 'nonClickableContent' ? children : ___EmotionJSX(Button, _extends({
|
79
82
|
variant: "quiet",
|
80
83
|
onPress: copyToClipboard,
|
81
84
|
"aria-label": "copy-content"
|
82
85
|
}, focusProps), children);
|
83
86
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
84
87
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
88
|
+
var wrapperRef = useRef();
|
89
|
+
|
90
|
+
if (mode === 'nonClickableContent') {
|
91
|
+
return ___EmotionJSX(TooltipWrapper, _extends({
|
92
|
+
isOpen: isTooltipOpen,
|
93
|
+
tooltip: tooltip,
|
94
|
+
targetRef: wrapperRef
|
95
|
+
}, tooltipProps), ___EmotionJSX(Box, _extends({
|
96
|
+
ref: wrapperRef,
|
97
|
+
isRow: true,
|
98
|
+
tabIndex: 0
|
99
|
+
}, mergeProps(hoverProps, others), wrapperProps), content, ___EmotionJSX(CopyButton, _extends({
|
100
|
+
onPress: copyToClipboard
|
101
|
+
}, focusProps))));
|
102
|
+
}
|
85
103
|
|
86
104
|
if (mode === 'link') {
|
87
105
|
return ___EmotionJSX(Box, _extends({
|
@@ -109,13 +127,19 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
109
127
|
});
|
110
128
|
CopyText.propTypes = {
|
111
129
|
/** The behavioral pattern to apply to the component. */
|
112
|
-
mode: PropTypes.oneOf(['text', 'link']),
|
130
|
+
mode: PropTypes.oneOf(['text', 'link', 'nonClickableContent']),
|
113
131
|
|
114
132
|
/** The text to be copied instead of the text inside the child component. */
|
115
133
|
textToCopy: PropTypes.string,
|
116
134
|
|
117
135
|
/** The text to be displayed in the tooltip. */
|
118
|
-
tooltipText: PropTypes.string
|
136
|
+
tooltipText: PropTypes.string,
|
137
|
+
|
138
|
+
/** Props to apply to the tooltip in nonClickableContent mode. */
|
139
|
+
tooltipProps: PropTypes.shape({}),
|
140
|
+
|
141
|
+
/** Props to apply to the wrapper in nonClickableContent mode. */
|
142
|
+
wrapperProps: PropTypes.shape({})
|
119
143
|
};
|
120
144
|
CopyText.defaultProps = {
|
121
145
|
mode: 'text',
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import Box from '../Box/Box';
|
3
|
+
/**
|
4
|
+
* Composed component that spreads children.
|
5
|
+
*
|
6
|
+
* This component is built to have the NavBarSection component passed into it.
|
7
|
+
*
|
8
|
+
* NavBarSection is an iterative component that
|
9
|
+
* will build an AccordionGridGroup using
|
10
|
+
* the array of objects that is passed into it.
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
|
14
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
15
|
+
|
16
|
+
var NavBar = function NavBar(props) {
|
17
|
+
return ___EmotionJSX(Box, {
|
18
|
+
variant: "boxes.navBar",
|
19
|
+
role: "navigation",
|
20
|
+
as: "nav"
|
21
|
+
}, props.children);
|
22
|
+
};
|
23
|
+
|
24
|
+
export default NavBar;
|