@canonical/react-components 0.33.0 → 0.34.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/dist/__mocks__/nanoid.d.ts +1 -0
- package/dist/__mocks__/nanoid.js +17 -0
- package/dist/components/Chip/Chip.d.ts +1 -1
- package/dist/components/Chip/Chip.js +11 -10
- package/dist/components/Field/Field.d.ts +13 -1
- package/dist/components/Field/Field.js +61 -24
- package/dist/components/Input/Input.js +31 -14
- package/dist/components/PaginationItem/PaginationItem.js +2 -1
- package/dist/components/PasswordToggle/PasswordToggle.js +14 -3
- package/dist/components/Select/Select.js +11 -1
- package/dist/components/Slider/Slider.js +14 -1
- package/dist/components/Textarea/Textarea.js +11 -1
- package/dist/components/Tooltip/Tooltip.d.ts +12 -2
- package/dist/components/Tooltip/Tooltip.js +36 -6
- package/dist/components/Tooltip/index.d.ts +1 -1
- package/dist/components/Tooltip/index.js +12 -2
- package/package.json +34 -34
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const nanoid: () => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.nanoid = void 0;
|
|
7
|
+
var id = 0;
|
|
8
|
+
beforeEach(function () {
|
|
9
|
+
id = 0;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
var nanoid = function nanoid() {
|
|
13
|
+
id++;
|
|
14
|
+
return "mock-nanoid-".concat(id);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.nanoid = nanoid;
|
|
@@ -43,6 +43,6 @@ export declare type Props = PropsWithSpread<{
|
|
|
43
43
|
* The value of the chip.
|
|
44
44
|
*/
|
|
45
45
|
value: string;
|
|
46
|
-
}, HTMLProps<
|
|
46
|
+
}, HTMLProps<HTMLButtonElement>>;
|
|
47
47
|
declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, value, ...props }: Props) => JSX.Element;
|
|
48
48
|
export default Chip;
|
|
@@ -71,27 +71,28 @@ var Chip = function Chip(_ref) {
|
|
|
71
71
|
}
|
|
72
72
|
}));
|
|
73
73
|
|
|
74
|
-
var chipClassName = (0, _classnames.default)((_classNames = {}, _defineProperty(_classNames, "p-chip--".concat(appearance), !!appearance), _defineProperty(_classNames, "p-chip", !appearance), _classNames));
|
|
74
|
+
var chipClassName = (0, _classnames.default)((_classNames = {}, _defineProperty(_classNames, "p-chip--".concat(appearance), !!appearance), _defineProperty(_classNames, "p-chip", !appearance), _classNames), props.className);
|
|
75
75
|
|
|
76
76
|
if (onDismiss) {
|
|
77
|
-
return /*#__PURE__*/_react.default.createElement("span", _extends({
|
|
78
|
-
className: chipClassName
|
|
79
|
-
|
|
80
|
-
}, props), chipContent, /*#__PURE__*/_react.default.createElement("button", {
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement("span", _extends({}, props, {
|
|
78
|
+
className: chipClassName
|
|
79
|
+
}), chipContent, /*#__PURE__*/_react.default.createElement("button", {
|
|
81
80
|
className: "p-chip__dismiss",
|
|
82
|
-
onClick: onDismiss
|
|
81
|
+
onClick: onDismiss,
|
|
82
|
+
type: "button"
|
|
83
83
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
84
84
|
className: "p-icon--close"
|
|
85
85
|
}, "Dismiss")));
|
|
86
86
|
} else {
|
|
87
|
-
return /*#__PURE__*/_react.default.createElement("button", {
|
|
88
|
-
className: chipClassName,
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement("button", _extends({}, props, {
|
|
89
88
|
"aria-pressed": selected,
|
|
89
|
+
className: chipClassName,
|
|
90
90
|
onClick: onClick,
|
|
91
91
|
onKeyDown: function onKeyDown(e) {
|
|
92
92
|
return _onKeyDown(e);
|
|
93
|
-
}
|
|
94
|
-
|
|
93
|
+
},
|
|
94
|
+
type: "button"
|
|
95
|
+
}), chipContent);
|
|
95
96
|
}
|
|
96
97
|
};
|
|
97
98
|
|
|
@@ -28,10 +28,18 @@ export declare type Props = {
|
|
|
28
28
|
* Help text to show below the field.
|
|
29
29
|
*/
|
|
30
30
|
help?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* An id to give to the help element.
|
|
33
|
+
*/
|
|
34
|
+
helpId?: string;
|
|
31
35
|
/**
|
|
32
36
|
* Whether the component is wrapping a select element.
|
|
33
37
|
*/
|
|
34
38
|
isSelect?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the component is wrapping a checkbox or radio element.
|
|
41
|
+
*/
|
|
42
|
+
isTickElement?: boolean;
|
|
35
43
|
/**
|
|
36
44
|
* The label for the field.
|
|
37
45
|
*/
|
|
@@ -56,6 +64,10 @@ export declare type Props = {
|
|
|
56
64
|
* The content for success validation.
|
|
57
65
|
*/
|
|
58
66
|
success?: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* An id to give to the caution, error or success element.
|
|
69
|
+
*/
|
|
70
|
+
validationId?: string;
|
|
59
71
|
};
|
|
60
|
-
declare const Field: ({ caution, children, className, error, forId, help, isSelect, label, labelClassName, labelFirst, required, stacked, success, }: Props) => JSX.Element;
|
|
72
|
+
declare const Field: ({ caution, children, className, error, forId, help, helpId, isSelect, isTickElement, label, labelClassName, labelFirst, required, stacked, success, validationId, }: Props) => JSX.Element;
|
|
61
73
|
export default Field;
|
|
@@ -15,20 +15,27 @@ var _Col = _interopRequireDefault(require("../Col"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
var generateHelpText = function generateHelpText(_ref) {
|
|
19
|
+
var help = _ref.help,
|
|
20
|
+
helpId = _ref.helpId,
|
|
21
|
+
isTickElement = _ref.isTickElement;
|
|
22
|
+
return help ? /*#__PURE__*/_react.default.createElement("p", {
|
|
23
|
+
className: (0, _classnames.default)("p-form-help-text", {
|
|
24
|
+
"is-tick-element": isTickElement
|
|
25
|
+
}),
|
|
26
|
+
id: helpId
|
|
27
|
+
}, help) : null;
|
|
22
28
|
};
|
|
23
29
|
|
|
24
|
-
var generateError = function generateError(error, caution, success) {
|
|
30
|
+
var generateError = function generateError(error, caution, success, validationId) {
|
|
25
31
|
if (!error && !caution && !success) {
|
|
26
32
|
return null;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
var messageType = error && "Error" || caution && "Caution" || success && "Success";
|
|
30
36
|
return /*#__PURE__*/_react.default.createElement("p", {
|
|
31
|
-
className: "p-form-validation__message"
|
|
37
|
+
className: "p-form-validation__message",
|
|
38
|
+
id: validationId
|
|
32
39
|
}, /*#__PURE__*/_react.default.createElement("strong", null, messageType, ":"), " ", error || caution || success);
|
|
33
40
|
};
|
|
34
41
|
|
|
@@ -52,31 +59,61 @@ var generateLabel = function generateLabel(forId, required, label, labelClassNam
|
|
|
52
59
|
return labelNode;
|
|
53
60
|
};
|
|
54
61
|
|
|
55
|
-
var generateContent = function generateContent(
|
|
62
|
+
var generateContent = function generateContent(_ref2) {
|
|
63
|
+
var isSelect = _ref2.isSelect,
|
|
64
|
+
children = _ref2.children,
|
|
65
|
+
labelFirst = _ref2.labelFirst,
|
|
66
|
+
labelNode = _ref2.labelNode,
|
|
67
|
+
help = _ref2.help,
|
|
68
|
+
error = _ref2.error,
|
|
69
|
+
caution = _ref2.caution,
|
|
70
|
+
success = _ref2.success,
|
|
71
|
+
validationId = _ref2.validationId,
|
|
72
|
+
helpId = _ref2.helpId,
|
|
73
|
+
isTickElement = _ref2.isTickElement;
|
|
56
74
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
57
75
|
className: "p-form__control u-clearfix"
|
|
58
76
|
}, isSelect ? /*#__PURE__*/_react.default.createElement("div", {
|
|
59
77
|
className: "p-form-validation__select-wrapper"
|
|
60
|
-
}, children) : children, !labelFirst && labelNode,
|
|
78
|
+
}, children) : children, !labelFirst && labelNode, generateHelpText({
|
|
79
|
+
helpId: helpId,
|
|
80
|
+
help: help,
|
|
81
|
+
isTickElement: isTickElement
|
|
82
|
+
}), generateError(error, caution, success, validationId));
|
|
61
83
|
};
|
|
62
84
|
|
|
63
|
-
var Field = function Field(
|
|
64
|
-
var caution =
|
|
65
|
-
children =
|
|
66
|
-
className =
|
|
67
|
-
error =
|
|
68
|
-
forId =
|
|
69
|
-
help =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
var Field = function Field(_ref3) {
|
|
86
|
+
var caution = _ref3.caution,
|
|
87
|
+
children = _ref3.children,
|
|
88
|
+
className = _ref3.className,
|
|
89
|
+
error = _ref3.error,
|
|
90
|
+
forId = _ref3.forId,
|
|
91
|
+
help = _ref3.help,
|
|
92
|
+
helpId = _ref3.helpId,
|
|
93
|
+
isSelect = _ref3.isSelect,
|
|
94
|
+
isTickElement = _ref3.isTickElement,
|
|
95
|
+
label = _ref3.label,
|
|
96
|
+
labelClassName = _ref3.labelClassName,
|
|
97
|
+
_ref3$labelFirst = _ref3.labelFirst,
|
|
98
|
+
labelFirst = _ref3$labelFirst === void 0 ? true : _ref3$labelFirst,
|
|
99
|
+
required = _ref3.required,
|
|
100
|
+
stacked = _ref3.stacked,
|
|
101
|
+
success = _ref3.success,
|
|
102
|
+
validationId = _ref3.validationId;
|
|
78
103
|
var labelNode = generateLabel(forId, required, label, labelClassName, stacked);
|
|
79
|
-
var content = generateContent(
|
|
104
|
+
var content = generateContent({
|
|
105
|
+
isSelect: isSelect,
|
|
106
|
+
isTickElement: isTickElement,
|
|
107
|
+
children: children,
|
|
108
|
+
labelFirst: labelFirst,
|
|
109
|
+
labelNode: labelNode,
|
|
110
|
+
help: help,
|
|
111
|
+
error: error,
|
|
112
|
+
caution: caution,
|
|
113
|
+
success: success,
|
|
114
|
+
validationId: validationId,
|
|
115
|
+
helpId: helpId
|
|
116
|
+
});
|
|
80
117
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
81
118
|
className: (0, _classnames.default)("p-form__group", "p-form-validation", className, {
|
|
82
119
|
"is-error": error,
|
|
@@ -17,6 +17,8 @@ var _CheckboxInput = _interopRequireDefault(require("../CheckboxInput"));
|
|
|
17
17
|
|
|
18
18
|
var _RadioInput = _interopRequireDefault(require("../RadioInput"));
|
|
19
19
|
|
|
20
|
+
var _hooks = require("../../hooks");
|
|
21
|
+
|
|
20
22
|
var _excluded = ["caution", "className", "error", "help", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "type", "wrapperClassName"];
|
|
21
23
|
|
|
22
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); }
|
|
@@ -27,6 +29,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
27
29
|
|
|
28
30
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
29
31
|
|
|
32
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
+
|
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
35
|
+
|
|
36
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
|
+
|
|
30
38
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
39
|
|
|
32
40
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -49,6 +57,19 @@ var Input = function Input(_ref) {
|
|
|
49
57
|
|
|
50
58
|
var inputRef = (0, _react.useRef)(null);
|
|
51
59
|
var fieldLabel = !["checkbox", "radio"].includes(type) ? label : "";
|
|
60
|
+
var validationId = (0, _hooks.useId)();
|
|
61
|
+
var helpId = (0, _hooks.useId)();
|
|
62
|
+
var hasError = !!error;
|
|
63
|
+
|
|
64
|
+
var commonProps = _objectSpread({
|
|
65
|
+
"aria-describedby": help ? helpId : null,
|
|
66
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
67
|
+
"aria-invalid": hasError,
|
|
68
|
+
id: id,
|
|
69
|
+
label: label,
|
|
70
|
+
required: required
|
|
71
|
+
}, inputProps);
|
|
72
|
+
|
|
52
73
|
(0, _react.useEffect)(function () {
|
|
53
74
|
if (takeFocus) {
|
|
54
75
|
inputRef.current.focus();
|
|
@@ -58,27 +79,20 @@ var Input = function Input(_ref) {
|
|
|
58
79
|
|
|
59
80
|
if (type === "checkbox") {
|
|
60
81
|
input = /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, _extends({
|
|
61
|
-
id: id,
|
|
62
82
|
label: label,
|
|
63
|
-
labelClassName: labelClassName
|
|
64
|
-
|
|
65
|
-
}, inputProps));
|
|
83
|
+
labelClassName: labelClassName
|
|
84
|
+
}, commonProps));
|
|
66
85
|
} else if (type === "radio") {
|
|
67
86
|
input = /*#__PURE__*/_react.default.createElement(_RadioInput.default, _extends({
|
|
68
|
-
id: id,
|
|
69
87
|
label: label,
|
|
70
|
-
labelClassName: labelClassName
|
|
71
|
-
|
|
72
|
-
}, inputProps));
|
|
88
|
+
labelClassName: labelClassName
|
|
89
|
+
}, commonProps));
|
|
73
90
|
} else {
|
|
74
91
|
input = /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
75
92
|
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
76
|
-
id: id,
|
|
77
93
|
ref: inputRef,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"aria-invalid": !!error
|
|
81
|
-
}, inputProps));
|
|
94
|
+
type: type
|
|
95
|
+
}, commonProps));
|
|
82
96
|
}
|
|
83
97
|
|
|
84
98
|
return /*#__PURE__*/_react.default.createElement(_Field.default, {
|
|
@@ -87,11 +101,14 @@ var Input = function Input(_ref) {
|
|
|
87
101
|
error: error,
|
|
88
102
|
forId: id,
|
|
89
103
|
help: help,
|
|
104
|
+
helpId: helpId,
|
|
105
|
+
isTickElement: type === "checkbox" || type === "radio",
|
|
90
106
|
label: fieldLabel,
|
|
91
107
|
labelClassName: labelClassName,
|
|
92
108
|
required: required,
|
|
93
109
|
stacked: stacked,
|
|
94
|
-
success: success
|
|
110
|
+
success: success,
|
|
111
|
+
validationId: validationId
|
|
95
112
|
}, input);
|
|
96
113
|
};
|
|
97
114
|
|
|
@@ -22,7 +22,8 @@ var PaginationItem = function PaginationItem(_ref) {
|
|
|
22
22
|
className: (0, _classnames.default)("p-pagination__link", {
|
|
23
23
|
"is-active": isActive
|
|
24
24
|
}),
|
|
25
|
-
onClick: onClick
|
|
25
|
+
onClick: onClick,
|
|
26
|
+
"aria-current": isActive ? "page" : undefined
|
|
26
27
|
}, number));
|
|
27
28
|
};
|
|
28
29
|
|
|
@@ -17,6 +17,8 @@ var _Field = _interopRequireDefault(require("../Field"));
|
|
|
17
17
|
|
|
18
18
|
var _Label = _interopRequireDefault(require("../Label"));
|
|
19
19
|
|
|
20
|
+
var _hooks = require("../../hooks");
|
|
21
|
+
|
|
20
22
|
var _excluded = ["caution", "className", "error", "help", "id", "label", "readOnly", "required", "success", "type", "wrapperClassName"];
|
|
21
23
|
|
|
22
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); }
|
|
@@ -62,6 +64,10 @@ var PasswordToggle = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
|
|
|
62
64
|
isPassword = _useState2[0],
|
|
63
65
|
setIsPassword = _useState2[1];
|
|
64
66
|
|
|
67
|
+
var validationId = (0, _hooks.useId)();
|
|
68
|
+
var helpId = (0, _hooks.useId)();
|
|
69
|
+
var hasError = !!error;
|
|
70
|
+
|
|
65
71
|
var togglePassword = function togglePassword() {
|
|
66
72
|
if (isPassword) {
|
|
67
73
|
setIsPassword(false);
|
|
@@ -75,8 +81,10 @@ var PasswordToggle = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
|
|
|
75
81
|
className: wrapperClassName,
|
|
76
82
|
error: error,
|
|
77
83
|
help: help,
|
|
84
|
+
helpId: helpId,
|
|
78
85
|
required: required,
|
|
79
|
-
success: success
|
|
86
|
+
success: success,
|
|
87
|
+
validationId: validationId
|
|
80
88
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
81
89
|
className: "p-form-password-toggle"
|
|
82
90
|
}, /*#__PURE__*/_react.default.createElement(_Label.default, {
|
|
@@ -97,11 +105,14 @@ var PasswordToggle = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
|
|
|
97
105
|
}, isPassword ? "Show" : "Hide"), /*#__PURE__*/_react.default.createElement("i", {
|
|
98
106
|
className: isPassword ? "p-icon--show" : "p-icon--hide"
|
|
99
107
|
}))), /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
108
|
+
"aria-describedby": help ? helpId : null,
|
|
109
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
110
|
+
"aria-invalid": hasError,
|
|
100
111
|
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
101
112
|
id: id,
|
|
113
|
+
readOnly: readOnly,
|
|
102
114
|
ref: ref,
|
|
103
|
-
type: isPassword ? "password" : "text"
|
|
104
|
-
readOnly: readOnly
|
|
115
|
+
type: isPassword ? "password" : "text"
|
|
105
116
|
}, inputProps)));
|
|
106
117
|
});
|
|
107
118
|
|
|
@@ -13,6 +13,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
13
13
|
|
|
14
14
|
var _Field = _interopRequireDefault(require("../Field"));
|
|
15
15
|
|
|
16
|
+
var _hooks = require("../../hooks");
|
|
17
|
+
|
|
16
18
|
var _excluded = ["label", "value"],
|
|
17
19
|
_excluded2 = ["caution", "className", "error", "help", "id", "label", "labelClassName", "onChange", "options", "required", "stacked", "success", "takeFocus", "wrapperClassName"];
|
|
18
20
|
|
|
@@ -59,6 +61,9 @@ var Select = function Select(_ref2) {
|
|
|
59
61
|
selectProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
60
62
|
|
|
61
63
|
var selectRef = (0, _react.useRef)(null);
|
|
64
|
+
var validationId = (0, _hooks.useId)();
|
|
65
|
+
var helpId = (0, _hooks.useId)();
|
|
66
|
+
var hasError = !!error;
|
|
62
67
|
(0, _react.useEffect)(function () {
|
|
63
68
|
if (takeFocus) {
|
|
64
69
|
selectRef.current.focus();
|
|
@@ -70,13 +75,18 @@ var Select = function Select(_ref2) {
|
|
|
70
75
|
error: error,
|
|
71
76
|
forId: id,
|
|
72
77
|
help: help,
|
|
78
|
+
helpId: helpId,
|
|
73
79
|
isSelect: true,
|
|
74
80
|
label: label,
|
|
75
81
|
labelClassName: labelClassName,
|
|
76
82
|
required: required,
|
|
77
83
|
stacked: stacked,
|
|
78
|
-
success: success
|
|
84
|
+
success: success,
|
|
85
|
+
validationId: validationId
|
|
79
86
|
}, /*#__PURE__*/_react.default.createElement("select", _extends({
|
|
87
|
+
"aria-describedby": help ? helpId : null,
|
|
88
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
89
|
+
"aria-invalid": hasError,
|
|
80
90
|
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
81
91
|
id: id,
|
|
82
92
|
onChange: function onChange(evt) {
|
|
@@ -9,6 +9,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _Field = _interopRequireDefault(require("../Field"));
|
|
11
11
|
|
|
12
|
+
var _hooks = require("../../hooks");
|
|
13
|
+
|
|
12
14
|
var _excluded = ["caution", "disabled", "error", "help", "id", "inputDisabled", "label", "max", "min", "onChange", "required", "showInput"];
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -45,6 +47,9 @@ var Slider = function Slider(_ref) {
|
|
|
45
47
|
showInput = _ref$showInput === void 0 ? false : _ref$showInput,
|
|
46
48
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
47
49
|
|
|
50
|
+
var validationId = (0, _hooks.useId)();
|
|
51
|
+
var helpId = (0, _hooks.useId)();
|
|
52
|
+
var hasError = !!error;
|
|
48
53
|
var style = {};
|
|
49
54
|
|
|
50
55
|
if ((_navigator = navigator) !== null && _navigator !== void 0 && (_navigator$userAgent = _navigator.userAgent) !== null && _navigator$userAgent !== void 0 && _navigator$userAgent.includes("AppleWebKit")) {
|
|
@@ -61,11 +66,16 @@ var Slider = function Slider(_ref) {
|
|
|
61
66
|
caution: caution,
|
|
62
67
|
error: error,
|
|
63
68
|
help: help,
|
|
69
|
+
helpId: helpId,
|
|
64
70
|
label: label,
|
|
65
|
-
required: required
|
|
71
|
+
required: required,
|
|
72
|
+
validationId: validationId
|
|
66
73
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
67
74
|
className: "p-slider__wrapper"
|
|
68
75
|
}, /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
76
|
+
"aria-describedby": help ? helpId : null,
|
|
77
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
78
|
+
"aria-invalid": hasError,
|
|
69
79
|
disabled: disabled,
|
|
70
80
|
id: id,
|
|
71
81
|
max: max,
|
|
@@ -75,6 +85,9 @@ var Slider = function Slider(_ref) {
|
|
|
75
85
|
style: style,
|
|
76
86
|
type: "range"
|
|
77
87
|
}, inputProps)), showInput && /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
88
|
+
"aria-describedby": help ? helpId : null,
|
|
89
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
90
|
+
"aria-invalid": hasError,
|
|
78
91
|
className: "p-slider__input",
|
|
79
92
|
disabled: disabled || inputDisabled,
|
|
80
93
|
max: max,
|
|
@@ -13,6 +13,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
13
13
|
|
|
14
14
|
var _Field = _interopRequireDefault(require("../Field"));
|
|
15
15
|
|
|
16
|
+
var _hooks = require("../../hooks");
|
|
17
|
+
|
|
16
18
|
var _excluded = ["caution", "className", "error", "grow", "help", "id", "label", "labelClassName", "onKeyUp", "required", "stacked", "style", "success", "takeFocus", "wrapperClassName"];
|
|
17
19
|
|
|
18
20
|
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); }
|
|
@@ -54,6 +56,9 @@ var Textarea = function Textarea(_ref) {
|
|
|
54
56
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
55
57
|
|
|
56
58
|
var textareaRef = (0, _react.useRef)(null);
|
|
59
|
+
var validationId = (0, _hooks.useId)();
|
|
60
|
+
var helpId = (0, _hooks.useId)();
|
|
61
|
+
var hasError = !!error;
|
|
57
62
|
(0, _react.useEffect)(function () {
|
|
58
63
|
if (takeFocus) {
|
|
59
64
|
textareaRef.current.focus();
|
|
@@ -65,12 +70,17 @@ var Textarea = function Textarea(_ref) {
|
|
|
65
70
|
error: error,
|
|
66
71
|
forId: id,
|
|
67
72
|
help: help,
|
|
73
|
+
helpId: helpId,
|
|
68
74
|
label: label,
|
|
69
75
|
labelClassName: labelClassName,
|
|
70
76
|
required: required,
|
|
71
77
|
stacked: stacked,
|
|
72
|
-
success: success
|
|
78
|
+
success: success,
|
|
79
|
+
validationId: validationId
|
|
73
80
|
}, /*#__PURE__*/_react.default.createElement("textarea", _extends({
|
|
81
|
+
"aria-describedby": help ? helpId : null,
|
|
82
|
+
"aria-errormessage": hasError ? validationId : null,
|
|
83
|
+
"aria-invalid": hasError,
|
|
74
84
|
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
75
85
|
id: id,
|
|
76
86
|
onKeyUp: function onKeyUp(evt) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { WindowFitment } from "../../hooks";
|
|
3
|
-
import type { ClassName } from "../../types";
|
|
3
|
+
import type { ClassName, ValueOf } from "../../types";
|
|
4
4
|
export declare type CSSPosition = "static" | "absolute" | "fixed" | "relative" | "sticky" | "initial" | "inherit";
|
|
5
5
|
export declare type PositionStyle = {
|
|
6
6
|
left: number;
|
|
@@ -8,7 +8,17 @@ export declare type PositionStyle = {
|
|
|
8
8
|
position: CSSPosition;
|
|
9
9
|
top: number;
|
|
10
10
|
};
|
|
11
|
-
export declare
|
|
11
|
+
export declare const position: {
|
|
12
|
+
readonly btmCenter: "btm-center";
|
|
13
|
+
readonly btmLeft: "btm-left";
|
|
14
|
+
readonly btmRight: "btm-right";
|
|
15
|
+
readonly left: "left";
|
|
16
|
+
readonly right: "right";
|
|
17
|
+
readonly topCenter: "top-center";
|
|
18
|
+
readonly topLeft: "top-left";
|
|
19
|
+
readonly topRight: "top-right";
|
|
20
|
+
};
|
|
21
|
+
export declare type Position = ValueOf<typeof position>;
|
|
12
22
|
export declare type Props = {
|
|
13
23
|
/**
|
|
14
24
|
* Whether the tooltip should adjust to fit in the screen.
|
|
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = exports.adjustForWindow = void 0;
|
|
8
|
+
exports.position = exports.default = exports.adjustForWindow = void 0;
|
|
9
9
|
|
|
10
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
11
|
|
|
@@ -33,6 +33,18 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
33
33
|
|
|
34
34
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
35
|
|
|
36
|
+
var position = {
|
|
37
|
+
btmCenter: "btm-center",
|
|
38
|
+
btmLeft: "btm-left",
|
|
39
|
+
btmRight: "btm-right",
|
|
40
|
+
left: "left",
|
|
41
|
+
right: "right",
|
|
42
|
+
topCenter: "top-center",
|
|
43
|
+
topLeft: "top-left",
|
|
44
|
+
topRight: "top-right"
|
|
45
|
+
};
|
|
46
|
+
exports.position = position;
|
|
47
|
+
|
|
36
48
|
var getPositionStyle = function getPositionStyle(pos, wrapperNode) {
|
|
37
49
|
if (!wrapperNode) {
|
|
38
50
|
return null;
|
|
@@ -187,6 +199,7 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
187
199
|
isOpen = _usePortal.isOpen,
|
|
188
200
|
Portal = _usePortal.Portal;
|
|
189
201
|
|
|
202
|
+
var tooltipId = (0, _hooks.useId)();
|
|
190
203
|
(0, _react.useEffect)(function () {
|
|
191
204
|
if (isOpen && !followMouse && wrapperRef.current) {
|
|
192
205
|
// Position the tooltip when it becomes visible.
|
|
@@ -210,11 +223,20 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
210
223
|
(0, _hooks.useListener)(wrapperRef.current, mouseHandler, "mousemove", true, followMouse && isOpen); // Handle adjusting the position of the tooltip so that it remains on screen.
|
|
211
224
|
|
|
212
225
|
(0, _hooks.useWindowFitment)(messageRef.current, wrapperRef.current, onUpdateWindowFitment, 20, isOpen, autoAdjust && followMouse);
|
|
226
|
+
|
|
227
|
+
var handleBlur = function handleBlur(e) {
|
|
228
|
+
var _messageRef$current;
|
|
229
|
+
|
|
230
|
+
if (e.relatedTarget ? !((_messageRef$current = messageRef.current) !== null && _messageRef$current !== void 0 && _messageRef$current.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
231
|
+
closePortal();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
213
235
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message ? /*#__PURE__*/_react.default.createElement("span", {
|
|
214
236
|
className: className,
|
|
215
|
-
onBlur:
|
|
237
|
+
onBlur: handleBlur,
|
|
216
238
|
onFocus: openPortal,
|
|
217
|
-
onMouseOut:
|
|
239
|
+
onMouseOut: handleBlur,
|
|
218
240
|
onMouseOver: openPortal
|
|
219
241
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
220
242
|
className: positionElementClassName,
|
|
@@ -222,13 +244,21 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
222
244
|
style: {
|
|
223
245
|
display: "inline-block"
|
|
224
246
|
}
|
|
225
|
-
},
|
|
226
|
-
|
|
247
|
+
}, _react.default.Children.map(children, function (child) {
|
|
248
|
+
return child && /*#__PURE__*/_react.default.isValidElement(child) ? /*#__PURE__*/_react.default.cloneElement(child, {
|
|
249
|
+
"aria-describedby": tooltipId
|
|
250
|
+
}) : child;
|
|
251
|
+
})), /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
252
|
+
className: (0, _classnames.default)("p-tooltip--".concat(adjustedPosition), "is-detached", {
|
|
253
|
+
"u-off-screen": !isOpen
|
|
254
|
+
}, tooltipClassName),
|
|
227
255
|
"data-testid": "tooltip-portal",
|
|
228
256
|
style: positionStyle
|
|
229
257
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
258
|
+
role: "tooltip",
|
|
230
259
|
className: "p-tooltip__message",
|
|
231
|
-
ref: messageRef
|
|
260
|
+
ref: messageRef,
|
|
261
|
+
id: tooltipId
|
|
232
262
|
}, message)))) : /*#__PURE__*/_react.default.createElement("span", {
|
|
233
263
|
className: className
|
|
234
264
|
}, children));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./Tooltip";
|
|
1
|
+
export { default, position } from "./Tooltip";
|
|
2
2
|
export type { Props as TooltipProps } from "./Tooltip";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -9,7 +11,15 @@ Object.defineProperty(exports, "default", {
|
|
|
9
11
|
return _Tooltip.default;
|
|
10
12
|
}
|
|
11
13
|
});
|
|
14
|
+
Object.defineProperty(exports, "position", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _Tooltip.position;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var _Tooltip = _interopRequireWildcard(require("./Tooltip"));
|
|
12
22
|
|
|
13
|
-
var
|
|
23
|
+
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
24
|
|
|
15
|
-
function
|
|
25
|
+
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; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"author": "Huw Wilkins <huw.wilkins@canonical.com>",
|
|
@@ -25,35 +25,35 @@
|
|
|
25
25
|
"@babel/cli": "7.17.6",
|
|
26
26
|
"@babel/eslint-parser": "7.17.0",
|
|
27
27
|
"@babel/preset-typescript": "7.16.7",
|
|
28
|
-
"@percy/cli": "1.0.
|
|
29
|
-
"@percy/storybook": "4.
|
|
30
|
-
"@storybook/addon-a11y": "6.4.
|
|
31
|
-
"@storybook/addon-controls": "6.4.
|
|
32
|
-
"@storybook/addon-docs": "6.4.
|
|
33
|
-
"@storybook/addons": "6.4.
|
|
34
|
-
"@storybook/react": "6.4.
|
|
35
|
-
"@storybook/theming": "6.4.
|
|
28
|
+
"@percy/cli": "1.0.5",
|
|
29
|
+
"@percy/storybook": "4.2.0",
|
|
30
|
+
"@storybook/addon-a11y": "6.4.20",
|
|
31
|
+
"@storybook/addon-controls": "6.4.20",
|
|
32
|
+
"@storybook/addon-docs": "6.4.20",
|
|
33
|
+
"@storybook/addons": "6.4.20",
|
|
34
|
+
"@storybook/react": "6.4.20",
|
|
35
|
+
"@storybook/theming": "6.4.20",
|
|
36
36
|
"@testing-library/cypress": "8.0.2",
|
|
37
|
-
"@testing-library/dom": "8.
|
|
38
|
-
"@testing-library/jest-dom": "5.16.
|
|
39
|
-
"@testing-library/react": "12.1.
|
|
37
|
+
"@testing-library/dom": "8.12.0",
|
|
38
|
+
"@testing-library/jest-dom": "5.16.3",
|
|
39
|
+
"@testing-library/react": "12.1.4",
|
|
40
40
|
"@testing-library/react-hooks": "7.0.2",
|
|
41
41
|
"@testing-library/user-event": "13.5.0",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
43
|
-
"@typescript-eslint/parser": "5.
|
|
44
|
-
"@wojtekmaj/enzyme-adapter-react-17": "0.6.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "5.18.0",
|
|
43
|
+
"@typescript-eslint/parser": "5.18.0",
|
|
44
|
+
"@wojtekmaj/enzyme-adapter-react-17": "0.6.7",
|
|
45
45
|
"babel-jest": "27.5.1",
|
|
46
|
-
"babel-loader": "8.2.
|
|
46
|
+
"babel-loader": "8.2.4",
|
|
47
47
|
"babel-plugin-module-resolver": "4.1.0",
|
|
48
48
|
"babel-plugin-typescript-to-proptypes": "2.0.0",
|
|
49
|
-
"concurrently": "7.
|
|
49
|
+
"concurrently": "7.1.0",
|
|
50
50
|
"css-loader": "5.2.7",
|
|
51
|
-
"cypress": "9.5.
|
|
51
|
+
"cypress": "9.5.3",
|
|
52
52
|
"deepmerge": "4.2.2",
|
|
53
53
|
"enzyme": "3.11.0",
|
|
54
54
|
"enzyme-adapter-react-16": "1.15.6",
|
|
55
55
|
"enzyme-to-json": "3.6.2",
|
|
56
|
-
"eslint": "8.
|
|
56
|
+
"eslint": "8.12.0",
|
|
57
57
|
"eslint-config-prettier": "8.5.0",
|
|
58
58
|
"eslint-config-react-app": "7.0.0",
|
|
59
59
|
"eslint-plugin-cypress": "2.12.1",
|
|
@@ -61,37 +61,37 @@
|
|
|
61
61
|
"eslint-plugin-import": "2.25.4",
|
|
62
62
|
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
63
63
|
"eslint-plugin-prettier": "4.0.0",
|
|
64
|
-
"eslint-plugin-react": "7.29.
|
|
65
|
-
"eslint-plugin-react-hooks": "4.
|
|
66
|
-
"eslint-plugin-testing-library": "5.
|
|
64
|
+
"eslint-plugin-react": "7.29.4",
|
|
65
|
+
"eslint-plugin-react-hooks": "4.4.0",
|
|
66
|
+
"eslint-plugin-testing-library": "5.2.1",
|
|
67
67
|
"jest": "27.5.1",
|
|
68
68
|
"npm-package-json-lint": "5.4.2",
|
|
69
|
-
"prettier": "2.
|
|
69
|
+
"prettier": "2.6.2",
|
|
70
70
|
"react": "17.0.2",
|
|
71
71
|
"react-docgen-typescript-loader": "3.7.2",
|
|
72
72
|
"react-dom": "17.0.2",
|
|
73
|
-
"sass": "1.49.
|
|
73
|
+
"sass": "1.49.11",
|
|
74
74
|
"sass-loader": "10.2.1",
|
|
75
75
|
"style-loader": "2.0.0",
|
|
76
|
-
"stylelint": "14.
|
|
76
|
+
"stylelint": "14.6.1",
|
|
77
77
|
"stylelint-config-prettier": "9.0.3",
|
|
78
78
|
"stylelint-config-recommended-scss": "5.0.2",
|
|
79
79
|
"stylelint-order": "5.0.0",
|
|
80
80
|
"stylelint-prettier": "2.0.0",
|
|
81
|
-
"ts-jest": "27.1.
|
|
82
|
-
"tsc-alias": "1.6.
|
|
83
|
-
"typescript": "4.6.
|
|
84
|
-
"vanilla-framework": "3.
|
|
81
|
+
"ts-jest": "27.1.4",
|
|
82
|
+
"tsc-alias": "1.6.5",
|
|
83
|
+
"typescript": "4.6.3",
|
|
84
|
+
"vanilla-framework": "3.2.0",
|
|
85
85
|
"wait-on": "5.3.0"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@types/jest": "27.4.1",
|
|
89
89
|
"@types/node": "16.11.26",
|
|
90
|
-
"@types/react": "17.0.
|
|
91
|
-
"@types/react-dom": "17.0.
|
|
92
|
-
"@types/react-table": "7.7.
|
|
90
|
+
"@types/react": "17.0.43",
|
|
91
|
+
"@types/react-dom": "17.0.14",
|
|
92
|
+
"@types/react-table": "7.7.10",
|
|
93
93
|
"classnames": "2.3.1",
|
|
94
|
-
"nanoid": "3.3.
|
|
94
|
+
"nanoid": "3.3.2",
|
|
95
95
|
"prop-types": "15.8.1",
|
|
96
96
|
"react-table": "7.7.0",
|
|
97
97
|
"react-useportal": "1.0.16"
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"peerDependencies": {
|
|
103
103
|
"react": "17.0.2",
|
|
104
104
|
"react-dom": "17.0.2",
|
|
105
|
-
"vanilla-framework": "3.
|
|
105
|
+
"vanilla-framework": "3.2.0"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"build": "rm -rf dist && yarn build-local; yarn build-declaration",
|