@canonical/react-components 0.34.2 → 0.35.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.
|
@@ -28,6 +28,10 @@ export declare type Props = {
|
|
|
28
28
|
* Help text to show below the field.
|
|
29
29
|
*/
|
|
30
30
|
help?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Optional class(es) to pass to the help text element.
|
|
33
|
+
*/
|
|
34
|
+
helpClassName?: ReactNode;
|
|
31
35
|
/**
|
|
32
36
|
* An id to give to the help element.
|
|
33
37
|
*/
|
|
@@ -69,5 +73,5 @@ export declare type Props = {
|
|
|
69
73
|
*/
|
|
70
74
|
validationId?: string;
|
|
71
75
|
};
|
|
72
|
-
declare const Field: ({ caution, children, className, error, forId, help, helpId, isSelect, isTickElement, label, labelClassName, labelFirst, required, stacked, success, validationId, }: Props) => JSX.Element;
|
|
76
|
+
declare const Field: ({ caution, children, className, error, forId, help, helpClassName, helpId, isSelect, isTickElement, label, labelClassName, labelFirst, required, stacked, success, validationId, }: Props) => JSX.Element;
|
|
73
77
|
export default Field;
|
|
@@ -18,9 +18,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
var generateHelpText = function generateHelpText(_ref) {
|
|
19
19
|
var help = _ref.help,
|
|
20
20
|
helpId = _ref.helpId,
|
|
21
|
+
helpClassName = _ref.helpClassName,
|
|
21
22
|
isTickElement = _ref.isTickElement;
|
|
22
23
|
return help ? /*#__PURE__*/_react.default.createElement("p", {
|
|
23
|
-
className: (0, _classnames.default)("p-form-help-text", {
|
|
24
|
+
className: (0, _classnames.default)("p-form-help-text", helpClassName, {
|
|
24
25
|
"is-tick-element": isTickElement
|
|
25
26
|
}),
|
|
26
27
|
id: helpId
|
|
@@ -65,6 +66,7 @@ var generateContent = function generateContent(_ref2) {
|
|
|
65
66
|
labelFirst = _ref2.labelFirst,
|
|
66
67
|
labelNode = _ref2.labelNode,
|
|
67
68
|
help = _ref2.help,
|
|
69
|
+
helpClassName = _ref2.helpClassName,
|
|
68
70
|
error = _ref2.error,
|
|
69
71
|
caution = _ref2.caution,
|
|
70
72
|
success = _ref2.success,
|
|
@@ -78,6 +80,7 @@ var generateContent = function generateContent(_ref2) {
|
|
|
78
80
|
}, children) : children, !labelFirst && labelNode, generateHelpText({
|
|
79
81
|
helpId: helpId,
|
|
80
82
|
help: help,
|
|
83
|
+
helpClassName: helpClassName,
|
|
81
84
|
isTickElement: isTickElement
|
|
82
85
|
}), generateError(error, caution, success, validationId));
|
|
83
86
|
};
|
|
@@ -89,6 +92,7 @@ var Field = function Field(_ref3) {
|
|
|
89
92
|
error = _ref3.error,
|
|
90
93
|
forId = _ref3.forId,
|
|
91
94
|
help = _ref3.help,
|
|
95
|
+
helpClassName = _ref3.helpClassName,
|
|
92
96
|
helpId = _ref3.helpId,
|
|
93
97
|
isSelect = _ref3.isSelect,
|
|
94
98
|
isTickElement = _ref3.isTickElement,
|
|
@@ -108,6 +112,7 @@ var Field = function Field(_ref3) {
|
|
|
108
112
|
labelFirst: labelFirst,
|
|
109
113
|
labelNode: labelNode,
|
|
110
114
|
help: help,
|
|
115
|
+
helpClassName: helpClassName,
|
|
111
116
|
error: error,
|
|
112
117
|
caution: caution,
|
|
113
118
|
success: success,
|
|
@@ -20,6 +20,10 @@ export declare type Props = PropsWithSpread<{
|
|
|
20
20
|
* Help text to show below the field.
|
|
21
21
|
*/
|
|
22
22
|
help?: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Optional class(es) to pass to the help text element.
|
|
25
|
+
*/
|
|
26
|
+
helpClassName?: ReactNode;
|
|
23
27
|
/**
|
|
24
28
|
* The id of the input.
|
|
25
29
|
*/
|
|
@@ -53,5 +57,5 @@ export declare type Props = PropsWithSpread<{
|
|
|
53
57
|
*/
|
|
54
58
|
wrapperClassName?: string;
|
|
55
59
|
}, InputHTMLAttributes<HTMLInputElement>>;
|
|
56
|
-
declare const Input: ({ caution, className, error, help, id, label, labelClassName, required, stacked, success, takeFocus, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
|
|
60
|
+
declare const Input: ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
|
|
57
61
|
export default Input;
|
|
@@ -19,7 +19,7 @@ var _RadioInput = _interopRequireDefault(require("../RadioInput"));
|
|
|
19
19
|
|
|
20
20
|
var _hooks = require("../../hooks");
|
|
21
21
|
|
|
22
|
-
var _excluded = ["caution", "className", "error", "help", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "type", "wrapperClassName"];
|
|
22
|
+
var _excluded = ["caution", "className", "error", "help", "helpClassName", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "type", "wrapperClassName"];
|
|
23
23
|
|
|
24
24
|
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); }
|
|
25
25
|
|
|
@@ -44,6 +44,7 @@ var Input = function Input(_ref) {
|
|
|
44
44
|
className = _ref.className,
|
|
45
45
|
error = _ref.error,
|
|
46
46
|
help = _ref.help,
|
|
47
|
+
helpClassName = _ref.helpClassName,
|
|
47
48
|
id = _ref.id,
|
|
48
49
|
label = _ref.label,
|
|
49
50
|
labelClassName = _ref.labelClassName,
|
|
@@ -101,6 +102,7 @@ var Input = function Input(_ref) {
|
|
|
101
102
|
error: error,
|
|
102
103
|
forId: id,
|
|
103
104
|
help: help,
|
|
105
|
+
helpClassName: helpClassName,
|
|
104
106
|
helpId: helpId,
|
|
105
107
|
isTickElement: type === "checkbox" || type === "radio",
|
|
106
108
|
label: fieldLabel,
|
|
@@ -223,18 +223,47 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
223
223
|
(0, _hooks.useListener)(wrapperRef.current, mouseHandler, "mousemove", true, followMouse && isOpen); // Handle adjusting the position of the tooltip so that it remains on screen.
|
|
224
224
|
|
|
225
225
|
(0, _hooks.useWindowFitment)(messageRef.current, wrapperRef.current, onUpdateWindowFitment, 20, isOpen, autoAdjust && followMouse);
|
|
226
|
+
var handleKeyPress = (0, _react.useCallback)(function (event) {
|
|
227
|
+
if (event.key === "Escape") {
|
|
228
|
+
closePortal();
|
|
229
|
+
}
|
|
230
|
+
}, [closePortal]);
|
|
231
|
+
(0, _react.useEffect)(function () {
|
|
232
|
+
window.addEventListener("keypress", handleKeyPress);
|
|
233
|
+
return function () {
|
|
234
|
+
window.removeEventListener("keypress", handleKeyPress);
|
|
235
|
+
};
|
|
236
|
+
}, [handleKeyPress]);
|
|
226
237
|
|
|
227
238
|
var handleBlur = function handleBlur(e) {
|
|
228
|
-
var _messageRef$current;
|
|
239
|
+
var _wrapperRef$current, _messageRef$current;
|
|
240
|
+
|
|
241
|
+
// do not close if the focus is within the tooltip wrapper
|
|
242
|
+
if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
229
245
|
|
|
230
246
|
if (e.relatedTarget ? !((_messageRef$current = messageRef.current) !== null && _messageRef$current !== void 0 && _messageRef$current.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
231
247
|
closePortal();
|
|
232
248
|
}
|
|
233
249
|
};
|
|
234
250
|
|
|
251
|
+
var handleClick = function handleClick(e) {
|
|
252
|
+
var _messageRef$current2;
|
|
253
|
+
|
|
254
|
+
// ignore clicks within the tooltip message
|
|
255
|
+
if ((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.target)) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
e.target.focus();
|
|
260
|
+
openPortal();
|
|
261
|
+
};
|
|
262
|
+
|
|
235
263
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message ? /*#__PURE__*/_react.default.createElement("span", {
|
|
236
264
|
className: className,
|
|
237
265
|
onBlur: handleBlur,
|
|
266
|
+
onClick: handleClick,
|
|
238
267
|
onFocus: openPortal,
|
|
239
268
|
onMouseOut: handleBlur,
|
|
240
269
|
onMouseOver: openPortal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"author": "Huw Wilkins <huw.wilkins@canonical.com>",
|
|
@@ -125,8 +125,8 @@
|
|
|
125
125
|
"test-cypress": "concurrently 'yarn run docs' 'yarn run cypress:test' -k -s first",
|
|
126
126
|
"unlink-packages": "yarn unlink && cd node_modules/react && yarn unlink && cd ../react-dom && yarn unlink",
|
|
127
127
|
"cypress:test": "wait-on http://localhost:${PORT:-9009} && cypress run --env port=${PORT:-9009}",
|
|
128
|
-
"cypress:run": "cypress run",
|
|
129
|
-
"cypress:open": "cypress open"
|
|
128
|
+
"cypress:run": "cypress run --env port=${PORT:-9009}",
|
|
129
|
+
"cypress:open": "cypress open --env port=${PORT:-9009}"
|
|
130
130
|
},
|
|
131
131
|
"eslintConfig": {
|
|
132
132
|
"extends": "react-app"
|