@pingux/astro 1.1.0-alpha.7 → 1.1.1-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/CHANGELOG.md +71 -0
- package/lib/cjs/components/CodeView/CodeView.js +175 -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/FileInputField/FileItem.js +2 -1
- package/lib/cjs/components/List/List.js +3 -0
- package/lib/cjs/components/List/List.stories.js +7 -2
- 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/OverlayPanel/OverlayPanel.js +53 -6
- package/lib/cjs/components/OverlayPanel/OverlayPanel.stories.js +59 -47
- package/lib/cjs/components/OverlayPanel/OverlayPanel.test.js +84 -0
- package/lib/cjs/components/PopoverMenu/PopoverMenu.js +1 -3
- package/lib/cjs/components/Separator/Separator.js +1 -1
- package/lib/cjs/components/TextArea/TextArea.js +5 -1
- package/lib/cjs/components/TooltipTrigger/TooltipTrigger.js +10 -5
- package/lib/cjs/hooks/useOverlayPanelState/useOverlayPanelState.js +20 -1
- package/lib/cjs/hooks/useOverlayPanelState/useOverlayPanelState.test.js +7 -3
- 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 +29 -1
- package/lib/cjs/styles/variants/codeView.js +77 -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 +139 -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/FileInputField/FileItem.js +2 -1
- package/lib/components/List/List.js +2 -0
- package/lib/components/List/List.stories.js +6 -2
- 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/OverlayPanel/OverlayPanel.js +52 -8
- package/lib/components/OverlayPanel/OverlayPanel.stories.js +59 -49
- package/lib/components/OverlayPanel/OverlayPanel.test.js +73 -1
- package/lib/components/PopoverMenu/PopoverMenu.js +1 -3
- package/lib/components/Separator/Separator.js +1 -1
- package/lib/components/TextArea/TextArea.js +5 -1
- package/lib/components/TooltipTrigger/TooltipTrigger.js +10 -5
- package/lib/hooks/useOverlayPanelState/useOverlayPanelState.js +20 -1
- package/lib/hooks/useOverlayPanelState/useOverlayPanelState.test.js +7 -3
- 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 +29 -1
- package/lib/styles/variants/codeView.js +67 -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 -2
@@ -74,6 +74,33 @@ var defaultFocus = {
|
|
74
74
|
outline: 'none',
|
75
75
|
boxShadow: 'focus'
|
76
76
|
};
|
77
|
+
var navItemButton = {
|
78
|
+
textDecoration: 'none',
|
79
|
+
outline: 'none',
|
80
|
+
cursor: 'pointer',
|
81
|
+
borderRadius: 0,
|
82
|
+
backgroundColor: 'transparent',
|
83
|
+
paddingTop: '5px',
|
84
|
+
paddingBottom: '5px',
|
85
|
+
display: 'block',
|
86
|
+
color: 'neutral.95',
|
87
|
+
fontSize: 'sm',
|
88
|
+
fontWeight: 1,
|
89
|
+
flexGrow: '1',
|
90
|
+
width: '100%',
|
91
|
+
textAlign: 'left',
|
92
|
+
lineHeight: '16px',
|
93
|
+
whiteSpace: 'break-spaces',
|
94
|
+
overflowWrap: 'break-word',
|
95
|
+
maxWidth: '100%',
|
96
|
+
wordWrap: 'break-word',
|
97
|
+
wordBreak: 'break-word',
|
98
|
+
'&.is-focused': _objectSpread({}, defaultFocus),
|
99
|
+
'&.is-hovered': {
|
100
|
+
bg: 'accent.10',
|
101
|
+
boxShadow: 'inset 2px 0 0 0 white'
|
102
|
+
}
|
103
|
+
};
|
77
104
|
var iconButton = {
|
78
105
|
justifyContent: 'center',
|
79
106
|
appearance: 'none',
|
@@ -89,7 +116,7 @@ var iconButton = {
|
|
89
116
|
width: 'inherit',
|
90
117
|
height: 'inherit',
|
91
118
|
path: {
|
92
|
-
fill: 'neutral.
|
119
|
+
fill: 'neutral.40'
|
93
120
|
},
|
94
121
|
outline: 'none',
|
95
122
|
'&.is-focused': _objectSpread({}, defaultFocus),
|
@@ -538,6 +565,7 @@ var _default = {
|
|
538
565
|
text: text,
|
539
566
|
helpHint: helpHint,
|
540
567
|
modalCloseButton: modalCloseButton,
|
568
|
+
navItemButton: navItemButton,
|
541
569
|
applicationPortalPinned: applicationPortalPinned,
|
542
570
|
applicationPortal: applicationPortal,
|
543
571
|
square: square,
|
@@ -0,0 +1,77 @@
|
|
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
|
+
var wrapper = {
|
11
|
+
bg: 'accent.99',
|
12
|
+
border: '1px solid',
|
13
|
+
borderColor: 'accent.95',
|
14
|
+
width: 400,
|
15
|
+
height: 200,
|
16
|
+
my: 5,
|
17
|
+
overflow: 'auto',
|
18
|
+
alignItems: 'center',
|
19
|
+
'&.is-focused, &:focus': {
|
20
|
+
boxShadow: 'focus',
|
21
|
+
outline: 'none'
|
22
|
+
},
|
23
|
+
pre: {
|
24
|
+
backgroundColor: 'transparent',
|
25
|
+
m: 0,
|
26
|
+
p: 10,
|
27
|
+
pr: 0,
|
28
|
+
height: '100%',
|
29
|
+
width: '100%',
|
30
|
+
overflowX: 'hidden',
|
31
|
+
overflowY: 'auto',
|
32
|
+
fontFamily: 'standard',
|
33
|
+
fontSize: 'sm',
|
34
|
+
'& .token-line': {
|
35
|
+
display: 'block',
|
36
|
+
alignItems: 'center',
|
37
|
+
'& .token': {
|
38
|
+
whiteSpace: 'pre-wrap',
|
39
|
+
wordBreak: 'break-all'
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
'&.has-no-copy-button': {
|
44
|
+
pre: {
|
45
|
+
p: 10
|
46
|
+
}
|
47
|
+
},
|
48
|
+
'&.has-line-numbers': {
|
49
|
+
pre: {
|
50
|
+
p: '0 10px 0 0',
|
51
|
+
overflow: 'auto',
|
52
|
+
'& .token-line:first-of-type *': {
|
53
|
+
pt: 10
|
54
|
+
},
|
55
|
+
'& .token-line': {
|
56
|
+
display: 'flex',
|
57
|
+
'& .token': {
|
58
|
+
whiteSpace: 'pre'
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
var lineNo = {
|
65
|
+
display: 'table-cell',
|
66
|
+
userSelect: 'none',
|
67
|
+
p: 5,
|
68
|
+
m: '0 10px 0 0',
|
69
|
+
bg: 'accent.30',
|
70
|
+
minWidth: 26,
|
71
|
+
color: 'white'
|
72
|
+
};
|
73
|
+
var _default = {
|
74
|
+
wrapper: wrapper,
|
75
|
+
lineNo: lineNo
|
76
|
+
};
|
77
|
+
exports["default"] = _default;
|
@@ -1,13 +1,38 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
4
|
|
5
|
-
_Object$
|
5
|
+
var _Object$defineProperty2 = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty2(exports, "__esModule", {
|
6
8
|
value: true
|
7
9
|
});
|
8
10
|
|
9
11
|
exports["default"] = void 0;
|
10
|
-
|
12
|
+
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
|
14
|
+
|
15
|
+
var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-properties"));
|
16
|
+
|
17
|
+
var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"));
|
18
|
+
|
19
|
+
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
20
|
+
|
21
|
+
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"));
|
22
|
+
|
23
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
24
|
+
|
25
|
+
var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
|
26
|
+
|
27
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
28
|
+
|
29
|
+
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
30
|
+
|
31
|
+
function ownKeys(object, enumerableOnly) { var keys = (0, _keys["default"])(object); if (_getOwnPropertySymbols["default"]) { var symbols = (0, _getOwnPropertySymbols["default"])(object); if (enumerableOnly) symbols = (0, _filter["default"])(symbols).call(symbols, function (sym) { return (0, _getOwnPropertyDescriptor["default"])(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
32
|
+
|
33
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context; (0, _forEach["default"])(_context = ownKeys(Object(source), true)).call(_context, function (key) { (0, _defineProperty3["default"])(target, key, source[key]); }); } else if (_getOwnPropertyDescriptors["default"]) { (0, _defineProperties["default"])(target, (0, _getOwnPropertyDescriptors["default"])(source)); } else { var _context2; (0, _forEach["default"])(_context2 = ownKeys(Object(source))).call(_context2, function (key) { (0, _defineProperty2["default"])(target, key, (0, _getOwnPropertyDescriptor["default"])(source, key)); }); } } return target; }
|
34
|
+
|
35
|
+
var base = {
|
11
36
|
bg: 'neutral.80',
|
12
37
|
width: '100%',
|
13
38
|
height: '1px',
|
@@ -18,4 +43,22 @@ var _default = {
|
|
18
43
|
mx: '5px'
|
19
44
|
}
|
20
45
|
};
|
46
|
+
|
47
|
+
var navBarSeparator = _objectSpread(_objectSpread({}, base), {}, {
|
48
|
+
width: '100%',
|
49
|
+
backgroundColor: 'neutral.60'
|
50
|
+
});
|
51
|
+
|
52
|
+
var navBarSubtitleSeparator = _objectSpread(_objectSpread({}, base), {}, {
|
53
|
+
ml: '45px',
|
54
|
+
width: 'calc(100% - 75px)',
|
55
|
+
mb: '15px',
|
56
|
+
backgroundColor: 'neutral.60'
|
57
|
+
});
|
58
|
+
|
59
|
+
var _default = {
|
60
|
+
base: base,
|
61
|
+
navBarSeparator: navBarSeparator,
|
62
|
+
navBarSubtitleSeparator: navBarSubtitleSeparator
|
63
|
+
};
|
21
64
|
exports["default"] = _default;
|
@@ -139,6 +139,19 @@ var expandableRow = {
|
|
139
139
|
}
|
140
140
|
}
|
141
141
|
};
|
142
|
+
var navBarSubtitle = {
|
143
|
+
fontWeight: 3,
|
144
|
+
fontSize: '11px',
|
145
|
+
color: 'accent.80'
|
146
|
+
};
|
147
|
+
|
148
|
+
var navBarHeaderText = _objectSpread(_objectSpread({}, wordWrap), {}, {
|
149
|
+
whiteSpace: 'break-spaces',
|
150
|
+
lineHeight: '13px',
|
151
|
+
fontSize: '13px',
|
152
|
+
fontWeight: 1
|
153
|
+
});
|
154
|
+
|
142
155
|
var text = {
|
143
156
|
base: base,
|
144
157
|
bodyStrong: _objectSpread(_objectSpread({}, wordWrap), {}, {
|
@@ -202,6 +215,8 @@ var text = {
|
|
202
215
|
textOverflow: 'ellipsis'
|
203
216
|
}),
|
204
217
|
expandableRow: expandableRow,
|
218
|
+
navBarHeaderText: navBarHeaderText,
|
219
|
+
navBarSubtitle: navBarSubtitle,
|
205
220
|
placeholder: {
|
206
221
|
fontWeight: -1,
|
207
222
|
color: 'text.secondary',
|
@@ -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,139 @@
|
|
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 github from 'prism-react-renderer/themes/github';
|
26
|
+
import { useStatusClasses } from '../../hooks';
|
27
|
+
import { Box, CopyText } from '../..';
|
28
|
+
/**
|
29
|
+
* Component for code syntax highlighting.
|
30
|
+
* Built on top of [prism-react-renderer](https://github.com/FormidableLabs/prism-react-renderer).
|
31
|
+
*/
|
32
|
+
|
33
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
34
|
+
var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
35
|
+
var children = props.children,
|
36
|
+
outerClassName = props.className,
|
37
|
+
hasLineNumbers = props.hasLineNumbers,
|
38
|
+
hasNoCopyButton = props.hasNoCopyButton,
|
39
|
+
language = props.language,
|
40
|
+
others = _objectWithoutProperties(props, ["children", "className", "hasLineNumbers", "hasNoCopyButton", "language"]);
|
41
|
+
|
42
|
+
var _useFocusRing = useFocusRing(),
|
43
|
+
isFocusVisible = _useFocusRing.isFocusVisible,
|
44
|
+
focusProps = _useFocusRing.focusProps;
|
45
|
+
|
46
|
+
var _useHover = useHover(props),
|
47
|
+
hoverProps = _useHover.hoverProps,
|
48
|
+
isHovered = _useHover.isHovered;
|
49
|
+
|
50
|
+
var _useStatusClasses = useStatusClasses(outerClassName, {
|
51
|
+
isFocused: isFocusVisible,
|
52
|
+
isHovered: isHovered,
|
53
|
+
hasLineNumbers: hasLineNumbers,
|
54
|
+
hasNoCopyButton: hasNoCopyButton
|
55
|
+
}),
|
56
|
+
classNames = _useStatusClasses.classNames; // Get the width for the line number element depending on the total amount of lines
|
57
|
+
|
58
|
+
|
59
|
+
var getLineNoWidth = function getLineNoWidth(tokens) {
|
60
|
+
return tokens.length.toString().length * 12;
|
61
|
+
};
|
62
|
+
|
63
|
+
var content = ___EmotionJSX(Highlight, _extends({}, defaultProps, {
|
64
|
+
theme: github,
|
65
|
+
code: (children === null || children === void 0 ? void 0 : _trimInstanceProperty(children).call(children)) || '',
|
66
|
+
language: language
|
67
|
+
}), function (_ref) {
|
68
|
+
var className = _ref.className,
|
69
|
+
style = _ref.style,
|
70
|
+
tokens = _ref.tokens,
|
71
|
+
getLineProps = _ref.getLineProps,
|
72
|
+
getTokenProps = _ref.getTokenProps;
|
73
|
+
return ___EmotionJSX(Box, {
|
74
|
+
as: "pre",
|
75
|
+
className: className,
|
76
|
+
style: style
|
77
|
+
}, _mapInstanceProperty(tokens).call(tokens, function (line, i) {
|
78
|
+
return ___EmotionJSX(Box, _extends({
|
79
|
+
isRow: true
|
80
|
+
}, getLineProps({
|
81
|
+
line: line,
|
82
|
+
key: i
|
83
|
+
})), hasLineNumbers && ___EmotionJSX(Box, {
|
84
|
+
as: "span",
|
85
|
+
variant: "codeView.lineNo",
|
86
|
+
sx: {
|
87
|
+
minWidth: getLineNoWidth(tokens)
|
88
|
+
}
|
89
|
+
}, i + 1), _mapInstanceProperty(line).call(line, function (token, key) {
|
90
|
+
return ___EmotionJSX("span", getTokenProps({
|
91
|
+
token: token,
|
92
|
+
key: key
|
93
|
+
}));
|
94
|
+
}));
|
95
|
+
}));
|
96
|
+
});
|
97
|
+
|
98
|
+
if (hasNoCopyButton) {
|
99
|
+
return ___EmotionJSX(Box, _extends({
|
100
|
+
ref: ref,
|
101
|
+
variant: "codeView.wrapper",
|
102
|
+
tabIndex: 0,
|
103
|
+
className: classNames
|
104
|
+
}, mergeProps(focusProps, hoverProps, others)), content);
|
105
|
+
}
|
106
|
+
|
107
|
+
return ___EmotionJSX(CopyText, {
|
108
|
+
mode: "nonClickableContent",
|
109
|
+
textToCopy: children,
|
110
|
+
tooltipProps: {
|
111
|
+
offset: 15
|
112
|
+
},
|
113
|
+
wrapperProps: _objectSpread({
|
114
|
+
className: classNames,
|
115
|
+
variant: 'codeView.wrapper'
|
116
|
+
}, others)
|
117
|
+
}, content);
|
118
|
+
});
|
119
|
+
CodeView.propTypes = {
|
120
|
+
/** Whether the CodeView displays line numbers. */
|
121
|
+
hasLineNumbers: PropTypes.bool,
|
122
|
+
|
123
|
+
/** Whether the CodeView hides the copy button. */
|
124
|
+
hasNoCopyButton: PropTypes.bool,
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Which programming language the CodeView should use for highlighting. A list of default languages is listed [here](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).
|
128
|
+
*
|
129
|
+
*
|
130
|
+
* Additional languages may be added, see [this guidance](https://github.com/FormidableLabs/prism-react-renderer#faq) for more information.
|
131
|
+
*/
|
132
|
+
language: PropTypes.string
|
133
|
+
};
|
134
|
+
CodeView.defaultProps = {
|
135
|
+
language: 'json',
|
136
|
+
hasLineNumbers: false,
|
137
|
+
hasNoCopyButton: false
|
138
|
+
};
|
139
|
+
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: "jsx",
|
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';
|