@canonical/react-components 0.45.0 → 0.47.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/dist/components/CodeSnippet/CodeSnippetBlock.d.ts +1 -1
- package/dist/components/CodeSnippet/CodeSnippetBlock.js +10 -1
- package/dist/components/ContextualMenu/ContextualMenu.d.ts +7 -3
- package/dist/components/ContextualMenu/ContextualMenu.js +3 -1
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +2 -1
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +21 -7
- package/package.json +3 -7
|
@@ -35,7 +35,16 @@ function CodeSnippetBlock(_ref) {
|
|
|
35
35
|
className += "--numbered";
|
|
36
36
|
|
|
37
37
|
// wrap code lines in spans (and preserve the whitespace)
|
|
38
|
-
var lines
|
|
38
|
+
var lines;
|
|
39
|
+
if (Array.isArray(code)) {
|
|
40
|
+
lines = code;
|
|
41
|
+
} else if (typeof code === "string") {
|
|
42
|
+
lines = code.split(/\r?\n/);
|
|
43
|
+
} else {
|
|
44
|
+
// If the code is not able to be split over multiple lines, then display
|
|
45
|
+
// a single line number.
|
|
46
|
+
lines = [code];
|
|
47
|
+
}
|
|
39
48
|
numberedCode = lines.map(function (line, i) {
|
|
40
49
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
41
50
|
key: "p-code-snippet__line-".concat(i)
|
|
@@ -13,7 +13,7 @@ export declare enum Label {
|
|
|
13
13
|
*/
|
|
14
14
|
export type Props<L> = PropsWithSpread<{
|
|
15
15
|
/**
|
|
16
|
-
* Whether the menu should adjust to fit
|
|
16
|
+
* Whether the menu should adjust its horizontal position to fit on the screen.
|
|
17
17
|
*/
|
|
18
18
|
autoAdjust?: boolean;
|
|
19
19
|
/**
|
|
@@ -57,13 +57,17 @@ export type Props<L> = PropsWithSpread<{
|
|
|
57
57
|
*/
|
|
58
58
|
onToggleMenu?: (isOpen: boolean) => void | null;
|
|
59
59
|
/**
|
|
60
|
-
* The position of the menu.
|
|
60
|
+
* The horizontal position of the menu.
|
|
61
61
|
*/
|
|
62
62
|
position?: Position | null;
|
|
63
63
|
/**
|
|
64
64
|
* An element to make the menu relative to.
|
|
65
65
|
*/
|
|
66
66
|
positionNode?: HTMLElement | null;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the dropdown should scroll if it is too long to fit on the screen.
|
|
69
|
+
*/
|
|
70
|
+
scrollOverflow?: boolean;
|
|
67
71
|
/**
|
|
68
72
|
* The appearance of the toggle button.
|
|
69
73
|
*/
|
|
@@ -115,5 +119,5 @@ export type Props<L> = PropsWithSpread<{
|
|
|
115
119
|
* @param [toggleLabelFirst=true] - Whether the toggle lable or icon should appear first.
|
|
116
120
|
* @param [visible=false] - Whether the menu should be visible.
|
|
117
121
|
*/
|
|
118
|
-
declare const ContextualMenu: <L>({ autoAdjust, children, className, closeOnEsc, closeOnOutsideClick, constrainPanelWidth, dropdownClassName, dropdownProps, hasToggleIcon, links, onToggleMenu, position, positionNode, toggleAppearance, toggleClassName, toggleDisabled, toggleLabel, toggleLabelFirst, toggleProps, visible, ...wrapperProps }: Props<L>) => JSX.Element;
|
|
122
|
+
declare const ContextualMenu: <L>({ autoAdjust, children, className, closeOnEsc, closeOnOutsideClick, constrainPanelWidth, dropdownClassName, dropdownProps, hasToggleIcon, links, onToggleMenu, position, positionNode, scrollOverflow, toggleAppearance, toggleClassName, toggleDisabled, toggleLabel, toggleLabelFirst, toggleProps, visible, ...wrapperProps }: Props<L>) => JSX.Element;
|
|
119
123
|
export default ContextualMenu;
|
|
@@ -12,7 +12,7 @@ var _hooks = require("../../hooks");
|
|
|
12
12
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
13
13
|
var _ContextualMenuDropdown = _interopRequireDefault(require("./ContextualMenuDropdown"));
|
|
14
14
|
var _useId = require("../../hooks/useId");
|
|
15
|
-
var _excluded = ["autoAdjust", "children", "className", "closeOnEsc", "closeOnOutsideClick", "constrainPanelWidth", "dropdownClassName", "dropdownProps", "hasToggleIcon", "links", "onToggleMenu", "position", "positionNode", "toggleAppearance", "toggleClassName", "toggleDisabled", "toggleLabel", "toggleLabelFirst", "toggleProps", "visible"];
|
|
15
|
+
var _excluded = ["autoAdjust", "children", "className", "closeOnEsc", "closeOnOutsideClick", "constrainPanelWidth", "dropdownClassName", "dropdownProps", "hasToggleIcon", "links", "onToggleMenu", "position", "positionNode", "scrollOverflow", "toggleAppearance", "toggleClassName", "toggleDisabled", "toggleLabel", "toggleLabelFirst", "toggleProps", "visible"];
|
|
16
16
|
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); }
|
|
17
17
|
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; }
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -103,6 +103,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
103
103
|
_ref$position = _ref.position,
|
|
104
104
|
position = _ref$position === void 0 ? "right" : _ref$position,
|
|
105
105
|
positionNode = _ref.positionNode,
|
|
106
|
+
scrollOverflow = _ref.scrollOverflow,
|
|
106
107
|
toggleAppearance = _ref.toggleAppearance,
|
|
107
108
|
toggleClassName = _ref.toggleClassName,
|
|
108
109
|
toggleDisabled = _ref.toggleDisabled,
|
|
@@ -238,6 +239,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
238
239
|
position: position,
|
|
239
240
|
positionCoords: positionCoords,
|
|
240
241
|
positionNode: getPositionNode(wrapper.current, positionNode),
|
|
242
|
+
scrollOverflow: scrollOverflow,
|
|
241
243
|
setAdjustedPosition: setAdjustedPosition,
|
|
242
244
|
wrapperClass: wrapperClass
|
|
243
245
|
}, dropdownProps))));
|
|
@@ -28,6 +28,7 @@ export type Props<L = null> = {
|
|
|
28
28
|
position?: Position;
|
|
29
29
|
positionCoords?: ClientRect;
|
|
30
30
|
positionNode?: HTMLElement;
|
|
31
|
+
scrollOverflow?: boolean;
|
|
31
32
|
setAdjustedPosition?: (position: Position) => void;
|
|
32
33
|
wrapperClass?: string;
|
|
33
34
|
} & HTMLProps<HTMLSpanElement>;
|
|
@@ -38,5 +39,5 @@ export type Props<L = null> = {
|
|
|
38
39
|
* @return The new position.
|
|
39
40
|
*/
|
|
40
41
|
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
|
|
41
|
-
declare const ContextualMenuDropdown: <L>({ adjustedPosition, autoAdjust, closePortal, constrainPanelWidth, dropdownClassName, dropdownContent, id, isOpen, links, position, positionCoords, positionNode, setAdjustedPosition, wrapperClass, ...props }: Props<L>) => JSX.Element;
|
|
42
|
+
declare const ContextualMenuDropdown: <L>({ adjustedPosition, autoAdjust, closePortal, constrainPanelWidth, dropdownClassName, dropdownContent, id, isOpen, links, position, positionCoords, positionNode, scrollOverflow, setAdjustedPosition, wrapperClass, ...props }: Props<L>) => JSX.Element;
|
|
42
43
|
export default ContextualMenuDropdown;
|
|
@@ -9,7 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _hooks = require("../../../hooks");
|
|
10
10
|
var _Button = _interopRequireDefault(require("../../Button"));
|
|
11
11
|
var _excluded = ["children", "className", "onClick"],
|
|
12
|
-
_excluded2 = ["adjustedPosition", "autoAdjust", "closePortal", "constrainPanelWidth", "dropdownClassName", "dropdownContent", "id", "isOpen", "links", "position", "positionCoords", "positionNode", "setAdjustedPosition", "wrapperClass"];
|
|
12
|
+
_excluded2 = ["adjustedPosition", "autoAdjust", "closePortal", "constrainPanelWidth", "dropdownClassName", "dropdownContent", "id", "isOpen", "links", "position", "positionCoords", "positionNode", "scrollOverflow", "setAdjustedPosition", "wrapperClass"];
|
|
13
13
|
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); }
|
|
14
14
|
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; }
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -144,6 +144,7 @@ var ContextualMenuDropdown = function ContextualMenuDropdown(_ref) {
|
|
|
144
144
|
position = _ref.position,
|
|
145
145
|
positionCoords = _ref.positionCoords,
|
|
146
146
|
positionNode = _ref.positionNode,
|
|
147
|
+
scrollOverflow = _ref.scrollOverflow,
|
|
147
148
|
setAdjustedPosition = _ref.setAdjustedPosition,
|
|
148
149
|
wrapperClass = _ref.wrapperClass,
|
|
149
150
|
props = _objectWithoutProperties(_ref, _excluded2);
|
|
@@ -152,6 +153,10 @@ var ContextualMenuDropdown = function ContextualMenuDropdown(_ref) {
|
|
|
152
153
|
_useState2 = _slicedToArray(_useState, 2),
|
|
153
154
|
positionStyle = _useState2[0],
|
|
154
155
|
setPositionStyle = _useState2[1];
|
|
156
|
+
var _useState3 = (0, _react.useState)(),
|
|
157
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
158
|
+
maxHeight = _useState4[0],
|
|
159
|
+
setMaxHeight = _useState4[1];
|
|
155
160
|
|
|
156
161
|
// Update the styles to position the menu.
|
|
157
162
|
var updatePositionStyle = (0, _react.useCallback)(function () {
|
|
@@ -160,11 +165,16 @@ var ContextualMenuDropdown = function ContextualMenuDropdown(_ref) {
|
|
|
160
165
|
|
|
161
166
|
// Update the position when the window fitment info changes.
|
|
162
167
|
var onUpdateWindowFitment = (0, _react.useCallback)(function (fitsWindow) {
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
if (autoAdjust) {
|
|
169
|
+
setAdjustedPosition(adjustForWindow(position, fitsWindow));
|
|
170
|
+
}
|
|
171
|
+
if (scrollOverflow) {
|
|
172
|
+
setMaxHeight(fitsWindow.fromBottom.spaceBelow - 16);
|
|
173
|
+
}
|
|
174
|
+
}, [autoAdjust, position, scrollOverflow, setAdjustedPosition]);
|
|
165
175
|
|
|
166
|
-
// Handle adjusting the position of the dropdown so that it remains on screen.
|
|
167
|
-
(0, _hooks.useWindowFitment)(dropdown.current, positionNode, onUpdateWindowFitment, 0, isOpen && autoAdjust);
|
|
176
|
+
// Handle adjusting the horizontal position and scrolling of the dropdown so that it remains on screen.
|
|
177
|
+
(0, _hooks.useWindowFitment)(dropdown.current, positionNode, onUpdateWindowFitment, 0, isOpen && (autoAdjust || scrollOverflow));
|
|
168
178
|
|
|
169
179
|
// Update the styles when the position changes.
|
|
170
180
|
(0, _react.useEffect)(function () {
|
|
@@ -179,11 +189,15 @@ var ContextualMenuDropdown = function ContextualMenuDropdown(_ref) {
|
|
|
179
189
|
"aria-hidden": isOpen ? "false" : "true",
|
|
180
190
|
"aria-label": Label.Dropdown,
|
|
181
191
|
ref: dropdown,
|
|
182
|
-
style: constrainPanelWidth && positionStyle !== null && positionStyle !== void 0 && positionStyle.width ? {
|
|
192
|
+
style: _objectSpread(_objectSpread({}, constrainPanelWidth && positionStyle !== null && positionStyle !== void 0 && positionStyle.width ? {
|
|
183
193
|
width: positionStyle.width,
|
|
184
194
|
minWidth: 0,
|
|
185
195
|
maxWidth: "none"
|
|
186
|
-
} :
|
|
196
|
+
} : {}), scrollOverflow ? {
|
|
197
|
+
maxHeight: maxHeight,
|
|
198
|
+
minHeight: "2rem",
|
|
199
|
+
overflowX: "auto"
|
|
200
|
+
} : {})
|
|
187
201
|
}, dropdownContent ? typeof dropdownContent === "function" ? dropdownContent(closePortal) : dropdownContent : links.map(function (item, i) {
|
|
188
202
|
if (Array.isArray(item)) {
|
|
189
203
|
return /*#__PURE__*/_react.default.createElement("span", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"author": "Huw Wilkins <huw.wilkins@canonical.com>",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"ts-jest": "27.1.5",
|
|
80
80
|
"tsc-alias": "1.8.6",
|
|
81
81
|
"typescript": "4.9.5",
|
|
82
|
-
"vanilla-framework": "4.
|
|
82
|
+
"vanilla-framework": "4.2.0",
|
|
83
83
|
"wait-on": "5.3.0",
|
|
84
84
|
"webpack": "5.88.0"
|
|
85
85
|
},
|
|
@@ -130,11 +130,7 @@
|
|
|
130
130
|
"unlink-packages": "yarn unlink && cd node_modules/react && yarn unlink && cd ../react-dom && yarn unlink",
|
|
131
131
|
"cypress:test": "wait-on http://localhost:${PORT:-9009} && cypress run --env port=${PORT:-9009}",
|
|
132
132
|
"cypress:run": "cypress run --env port=${PORT:-9009}",
|
|
133
|
-
"cypress:open": "cypress open --env port=${PORT:-9009}"
|
|
134
|
-
"prepare-release:major": "./prepare-release major",
|
|
135
|
-
"prepare-release:minor": "./prepare-release minor",
|
|
136
|
-
"prepare-release:patch": "./prepare-release patch",
|
|
137
|
-
"prepare-release": "yarn run prepare-release:minor"
|
|
133
|
+
"cypress:open": "cypress open --env port=${PORT:-9009}"
|
|
138
134
|
},
|
|
139
135
|
"eslintConfig": {
|
|
140
136
|
"extends": "react-app"
|