@canonical/react-components 0.37.7 → 0.37.9

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.
Files changed (32) hide show
  1. package/dist/components/Accordion/Accordion.d.ts +1 -1
  2. package/dist/components/Accordion/AccordionSection/AccordionSection.d.ts +1 -1
  3. package/dist/components/Accordion/AccordionSection/AccordionSection.js +3 -1
  4. package/dist/components/ActionButton/ActionButton.d.ts +4 -0
  5. package/dist/components/ActionButton/ActionButton.js +9 -1
  6. package/dist/components/Card/Card.js +8 -2
  7. package/dist/components/CheckboxInput/CheckableInput/CheckableInput.d.ts +1 -1
  8. package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +3 -2
  9. package/dist/components/Chip/Chip.d.ts +3 -0
  10. package/dist/components/Chip/Chip.js +9 -2
  11. package/dist/components/ContextualMenu/ContextualMenu.d.ts +5 -1
  12. package/dist/components/ContextualMenu/ContextualMenu.js +15 -2
  13. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +3 -0
  14. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +14 -2
  15. package/dist/components/Field/Field.d.ts +1 -1
  16. package/dist/components/Field/Field.js +13 -3
  17. package/dist/components/Input/Input.d.ts +5 -1
  18. package/dist/components/Input/Input.js +10 -3
  19. package/dist/components/Modal/Modal.js +13 -2
  20. package/dist/components/Notification/Notification.d.ts +3 -0
  21. package/dist/components/Notification/Notification.js +9 -3
  22. package/dist/components/Pagination/PaginationButton/PaginationButton.d.ts +4 -0
  23. package/dist/components/Pagination/PaginationButton/PaginationButton.js +10 -2
  24. package/dist/components/PasswordToggle/PasswordToggle.d.ts +4 -0
  25. package/dist/components/PasswordToggle/PasswordToggle.js +15 -3
  26. package/dist/components/SearchAndFilter/SearchAndFilter.d.ts +6 -1
  27. package/dist/components/SearchAndFilter/SearchAndFilter.js +25 -6
  28. package/dist/components/SearchBox/SearchBox.d.ts +4 -0
  29. package/dist/components/SearchBox/SearchBox.js +11 -3
  30. package/dist/components/Select/Select.js +1 -1
  31. package/dist/components/Textarea/Textarea.js +1 -1
  32. package/package.json +3 -10
@@ -27,7 +27,7 @@ export declare type Props = PropsWithSpread<{
27
27
  * Optional function that is called when the expanded section is changed.
28
28
  * The function is provided the section title or null.
29
29
  */
30
- onExpandedChange?: (id: any, title: string) => void;
30
+ onExpandedChange?: (id: string, title: string) => void;
31
31
  /**
32
32
  * An array of sections and content.
33
33
  */
@@ -10,7 +10,7 @@ export declare type Props = {
10
10
  * An optional value to set the expanded section. The value must match a
11
11
  * section key.
12
12
  */
13
- expanded?: string;
13
+ expanded?: string | null;
14
14
  headingLevel?: number;
15
15
  /**
16
16
  * An optional click event when the title is clicked.
@@ -22,6 +22,7 @@ var AccordionSection = function AccordionSection(_ref) {
22
22
  _ref$headingLevel = _ref.headingLevel,
23
23
  headingLevel = _ref$headingLevel === void 0 ? 3 : _ref$headingLevel;
24
24
  var sectionId = (0, _useId.useId)();
25
+ var tabId = (0, _useId.useId)();
25
26
  var key = sectionKey || sectionId;
26
27
  var isExpanded = expanded === key;
27
28
  var Title = titleElement || "div";
@@ -35,6 +36,7 @@ var AccordionSection = function AccordionSection(_ref) {
35
36
  "aria-controls": "#".concat(sectionId),
36
37
  "aria-expanded": isExpanded ? "true" : "false",
37
38
  className: "p-accordion__tab",
39
+ id: tabId,
38
40
  onClick: function onClick() {
39
41
  if (isExpanded) {
40
42
  setExpanded(null, null);
@@ -48,7 +50,7 @@ var AccordionSection = function AccordionSection(_ref) {
48
50
  type: "button"
49
51
  }, title)), /*#__PURE__*/_react.default.createElement("section", {
50
52
  "aria-hidden": isExpanded ? "false" : "true",
51
- "aria-labelledby": sectionId,
53
+ "aria-labelledby": tabId,
52
54
  className: "p-accordion__panel",
53
55
  id: sectionId,
54
56
  role: "tabpanel"
@@ -3,6 +3,10 @@ import type { ButtonProps } from "../Button";
3
3
  import type { ClassName, PropsWithSpread } from "../../types";
4
4
  export declare const LOADER_MIN_DURATION = 400;
5
5
  export declare const SUCCESS_DURATION = 2000;
6
+ export declare enum Label {
7
+ WAITING = "Waiting for action to complete",
8
+ SUCCESS = "Action completed"
9
+ }
6
10
  export declare type Props = PropsWithSpread<{
7
11
  /**
8
12
  * The appearance of the button.
@@ -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.SUCCESS_DURATION = exports.LOADER_MIN_DURATION = void 0;
8
+ exports.default = exports.SUCCESS_DURATION = exports.Label = exports.LOADER_MIN_DURATION = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -45,6 +45,13 @@ exports.LOADER_MIN_DURATION = LOADER_MIN_DURATION;
45
45
  var SUCCESS_DURATION = 2000; // duration (ms) success tick is displayed
46
46
 
47
47
  exports.SUCCESS_DURATION = SUCCESS_DURATION;
48
+ var Label;
49
+ exports.Label = Label;
50
+
51
+ (function (Label) {
52
+ Label["WAITING"] = "Waiting for action to complete";
53
+ Label["SUCCESS"] = "Action completed";
54
+ })(Label || (exports.Label = Label = {}));
48
55
 
49
56
  var ActionButton = function ActionButton(_ref) {
50
57
  var appearance = _ref.appearance,
@@ -146,6 +153,7 @@ var ActionButton = function ActionButton(_ref) {
146
153
  width: "".concat(width, "px")
147
154
  } : undefined
148
155
  }, buttonProps), showIcon ? /*#__PURE__*/_react.default.createElement(_Icon.default, {
156
+ "aria-label": showLoader ? Label.WAITING : Label.SUCCESS,
149
157
  className: showLoader ? "u-animation--spin" : null,
150
158
  light: iconLight,
151
159
  name: icon
@@ -9,6 +9,8 @@ var _classnames = _interopRequireDefault(require("classnames"));
9
9
 
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
 
12
+ var _hooks = require("../../hooks");
13
+
12
14
  var _excluded = ["children", "className", "highlighted", "overlay", "thumbnail", "title"];
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -28,12 +30,15 @@ var Card = function Card(_ref) {
28
30
  title = _ref.title,
29
31
  props = _objectWithoutProperties(_ref, _excluded);
30
32
 
33
+ var titleId = (0, _hooks.useId)();
31
34
  return /*#__PURE__*/_react.default.createElement("div", _extends({
35
+ "aria-labelledby": titleId,
32
36
  className: (0, _classnames.default)(className, {
33
37
  "p-card": !highlighted && !overlay,
34
38
  "p-card--highlighted": highlighted,
35
39
  "p-card--overlay": overlay
36
- })
40
+ }),
41
+ role: "group"
37
42
  }, props), thumbnail && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("img", {
38
43
  className: "p-card__thumbnail",
39
44
  src: thumbnail,
@@ -41,7 +46,8 @@ var Card = function Card(_ref) {
41
46
  }), /*#__PURE__*/_react.default.createElement("hr", {
42
47
  className: "u-sv1"
43
48
  })), title && /*#__PURE__*/_react.default.createElement("h3", {
44
- className: "p-card__title"
49
+ className: "p-card__title",
50
+ id: titleId
45
51
  }, title), /*#__PURE__*/_react.default.createElement("div", {
46
52
  className: "p-card__content"
47
53
  }, children));
@@ -23,5 +23,5 @@ export declare type Props = PropsWithSpread<{
23
23
  */
24
24
  inline?: boolean;
25
25
  }, Omit<HTMLProps<HTMLInputElement>, "type">>;
26
- declare const CheckableInput: ({ inputType, label, labelClassName, indeterminate, ...checkboxProps }: Props) => JSX.Element;
26
+ declare const CheckableInput: ({ inputType, label, labelClassName, indeterminate, inline, ...checkboxProps }: Props) => JSX.Element;
27
27
  export default CheckableInput;
@@ -13,7 +13,7 @@ var _react = _interopRequireWildcard(require("react"));
13
13
 
14
14
  var _useId = require("../../../hooks/useId");
15
15
 
16
- var _excluded = ["inputType", "label", "labelClassName", "indeterminate"];
16
+ var _excluded = ["inputType", "label", "labelClassName", "indeterminate", "inline"];
17
17
 
18
18
  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); }
19
19
 
@@ -33,6 +33,7 @@ var CheckableInput = function CheckableInput(_ref) {
33
33
  labelClassName = _ref.labelClassName,
34
34
  _ref$indeterminate = _ref.indeterminate,
35
35
  indeterminate = _ref$indeterminate === void 0 ? false : _ref$indeterminate,
36
+ inline = _ref.inline,
36
37
  checkboxProps = _objectWithoutProperties(_ref, _excluded);
37
38
 
38
39
  var inputId = (0, _useId.useId)();
@@ -41,7 +42,7 @@ var CheckableInput = function CheckableInput(_ref) {
41
42
  inputRef.current.indeterminate = indeterminate;
42
43
  }, [indeterminate]);
43
44
  return /*#__PURE__*/_react.default.createElement("label", {
44
- className: (0, _classnames.default)(labelClassName, "p-".concat(inputType).concat(checkboxProps.inline ? "--inline" : ""), {
45
+ className: (0, _classnames.default)(labelClassName, "p-".concat(inputType).concat(inline ? "--inline" : ""), {
45
46
  "is-required": checkboxProps.required
46
47
  })
47
48
  }, /*#__PURE__*/_react.default.createElement("input", _extends({
@@ -1,5 +1,8 @@
1
1
  import type { MouseEvent, HTMLProps } from "react";
2
2
  import { ValueOf, PropsWithSpread } from "../../types";
3
+ export declare enum Label {
4
+ Dismiss = "Dismiss"
5
+ }
3
6
  export declare const ChipType: {
4
7
  readonly CAUTION: "caution";
5
8
  readonly INFORMATION: "information";
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.ChipType = void 0;
6
+ exports.default = exports.Label = exports.ChipType = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
@@ -23,6 +23,13 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
23
23
 
24
24
  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; }
25
25
 
26
+ var Label;
27
+ exports.Label = Label;
28
+
29
+ (function (Label) {
30
+ Label["Dismiss"] = "Dismiss";
31
+ })(Label || (exports.Label = Label = {}));
32
+
26
33
  var ChipType = {
27
34
  CAUTION: "caution",
28
35
  INFORMATION: "information",
@@ -82,7 +89,7 @@ var Chip = function Chip(_ref) {
82
89
  type: "button"
83
90
  }, /*#__PURE__*/_react.default.createElement("i", {
84
91
  className: "p-icon--close"
85
- }, "Dismiss")));
92
+ }, Label.Dismiss)));
86
93
  } else {
87
94
  return /*#__PURE__*/_react.default.createElement("button", _extends({}, props, {
88
95
  "aria-pressed": selected,
@@ -1,8 +1,12 @@
1
+ import React from "react";
1
2
  import type { HTMLProps, ReactNode } from "react";
2
3
  import type { ButtonProps } from "../Button";
3
4
  import type { ContextualMenuDropdownProps } from "./ContextualMenuDropdown";
4
5
  import type { MenuLink, Position } from "./ContextualMenuDropdown";
5
6
  import { ClassName, PropsWithSpread, SubComponentProps } from "../../types";
7
+ export declare enum Label {
8
+ Toggle = "Toggle menu"
9
+ }
6
10
  /**
7
11
  * The props for the ContextualMenu component.
8
12
  * @template L - The type of the link props.
@@ -75,7 +79,7 @@ export declare type Props<L> = PropsWithSpread<{
75
79
  /**
76
80
  * The toggle button's label.
77
81
  */
78
- toggleLabel?: string | null;
82
+ toggleLabel?: string | React.ReactNode | null;
79
83
  /**
80
84
  * Whether the toggle lable or icon should appear first.
81
85
  */
@@ -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 = void 0;
8
+ exports.default = exports.Label = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -49,6 +49,18 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
49
49
 
50
50
  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; }
51
51
 
52
+ var Label;
53
+ /**
54
+ * The props for the ContextualMenu component.
55
+ * @template L - The type of the link props.
56
+ */
57
+
58
+ exports.Label = Label;
59
+
60
+ (function (Label) {
61
+ Label["Toggle"] = "Toggle menu";
62
+ })(Label || (exports.Label = Label = {}));
63
+
52
64
  /**
53
65
  * Get the node to use for positioning the menu.
54
66
  * @param wrapper - The component's wrapping element.
@@ -176,7 +188,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
176
188
  ref = _usePortal.ref;
177
189
 
178
190
  var previousVisible = (0, _hooks.usePrevious)(visible);
179
- var labelNode = toggleLabel ? /*#__PURE__*/_react.default.createElement("span", null, toggleLabel) : null;
191
+ var labelNode = toggleLabel && typeof toggleLabel === "string" ? /*#__PURE__*/_react.default.createElement("span", null, toggleLabel) : /*#__PURE__*/_react.default.isValidElement(toggleLabel) ? toggleLabel : null;
180
192
  var wrapperClass = (0, _classnames.default)(className, "p-contextual-menu", _defineProperty({}, "p-contextual-menu--".concat(adjustedPosition), adjustedPosition !== "right")); // Update the coordinates of the wrapper once it mounts to the dom. This uses
181
193
  // The callback ref pattern:
182
194
  // https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node
@@ -224,6 +236,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
224
236
  appearance: toggleAppearance,
225
237
  "aria-controls": id,
226
238
  "aria-expanded": isOpen ? "true" : "false",
239
+ "aria-label": toggleLabel ? null : Label.Toggle,
227
240
  "aria-pressed": isOpen ? "true" : "false",
228
241
  "aria-haspopup": "true",
229
242
  className: (0, _classnames.default)("p-contextual-menu__toggle", toggleClassName),
@@ -1,6 +1,9 @@
1
1
  import type { HTMLProps, ReactNode } from "react";
2
2
  import type { ButtonProps } from "../../Button";
3
3
  import type { WindowFitment } from "../../../hooks";
4
+ export declare enum Label {
5
+ Dropdown = "submenu"
6
+ }
4
7
  /**
5
8
  * The type of the menu links.
6
9
  * @template L - The type of the link props.
@@ -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.default = exports.adjustForWindow = exports.Label = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -48,6 +48,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
48
48
 
49
49
  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; }
50
50
 
51
+ var Label;
52
+ /**
53
+ * The type of the menu links.
54
+ * @template L - The type of the link props.
55
+ */
56
+
57
+ exports.Label = Label;
58
+
59
+ (function (Label) {
60
+ Label["Dropdown"] = "submenu";
61
+ })(Label || (exports.Label = Label = {}));
62
+
51
63
  /**
52
64
  * Calculate the styles for the menu.
53
65
  * @param position - The menu position.
@@ -200,7 +212,7 @@ var ContextualMenuDropdown = function ContextualMenuDropdown(_ref) {
200
212
  className: (0, _classnames.default)("p-contextual-menu__dropdown", dropdownClassName),
201
213
  id: id,
202
214
  "aria-hidden": isOpen ? "false" : "true",
203
- "aria-label": "submenu",
215
+ "aria-label": Label.Dropdown,
204
216
  ref: dropdown,
205
217
  style: constrainPanelWidth && positionStyle !== null && positionStyle !== void 0 && positionStyle.width ? {
206
218
  width: positionStyle.width,
@@ -73,5 +73,5 @@ export declare type Props = {
73
73
  */
74
74
  validationId?: string;
75
75
  };
76
- declare const Field: ({ caution, children, className, error, forId, help, helpClassName, 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 }: Props) => JSX.Element;
77
77
  export default Field;
@@ -13,8 +13,16 @@ var _Label = _interopRequireDefault(require("../Label"));
13
13
 
14
14
  var _Col = _interopRequireDefault(require("../Col"));
15
15
 
16
+ var _excluded = ["caution", "children", "className", "error", "forId", "help", "helpClassName", "helpId", "isSelect", "isTickElement", "label", "labelClassName", "labelFirst", "required", "stacked", "success", "validationId"];
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
20
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
18
26
  var generateHelpText = function generateHelpText(_ref) {
19
27
  var help = _ref.help,
20
28
  helpId = _ref.helpId,
@@ -103,7 +111,9 @@ var Field = function Field(_ref3) {
103
111
  required = _ref3.required,
104
112
  stacked = _ref3.stacked,
105
113
  success = _ref3.success,
106
- validationId = _ref3.validationId;
114
+ validationId = _ref3.validationId,
115
+ props = _objectWithoutProperties(_ref3, _excluded);
116
+
107
117
  var labelNode = generateLabel(forId, required, label, labelClassName, stacked);
108
118
  var content = generateContent({
109
119
  isSelect: isSelect,
@@ -119,14 +129,14 @@ var Field = function Field(_ref3) {
119
129
  validationId: validationId,
120
130
  helpId: helpId
121
131
  });
122
- return /*#__PURE__*/_react.default.createElement("div", {
132
+ return /*#__PURE__*/_react.default.createElement("div", _extends({
123
133
  className: (0, _classnames.default)("p-form__group", "p-form-validation", className, {
124
134
  "is-error": error,
125
135
  "is-caution": caution,
126
136
  "is-success": success,
127
137
  row: stacked
128
138
  })
129
- }, labelFirst && labelNode, stacked ? /*#__PURE__*/_react.default.createElement(_Col.default, {
139
+ }, props), labelFirst && labelNode, stacked ? /*#__PURE__*/_react.default.createElement(_Col.default, {
130
140
  size: 8
131
141
  }, content) : content);
132
142
  };
@@ -52,10 +52,14 @@ export declare type Props = PropsWithSpread<{
52
52
  * Whether to focus on the input on initial render.
53
53
  */
54
54
  takeFocus?: boolean;
55
+ /**
56
+ * Delay takeFocus in milliseconds i.e. to let animations finish
57
+ */
58
+ takeFocusDelay?: number;
55
59
  /**
56
60
  * Optional class(es) to pass to the wrapping Field component
57
61
  */
58
62
  wrapperClassName?: string;
59
63
  }, InputHTMLAttributes<HTMLInputElement>>;
60
- declare const Input: ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
64
+ declare const Input: ({ caution, className, error, help, helpClassName, id, label, labelClassName, required, stacked, success, takeFocus, takeFocusDelay, type, wrapperClassName, ...inputProps }: Props) => JSX.Element;
61
65
  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", "helpClassName", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "type", "wrapperClassName"];
22
+ var _excluded = ["caution", "className", "error", "help", "helpClassName", "id", "label", "labelClassName", "required", "stacked", "success", "takeFocus", "takeFocusDelay", "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
 
@@ -52,6 +52,7 @@ var Input = function Input(_ref) {
52
52
  stacked = _ref.stacked,
53
53
  success = _ref.success,
54
54
  takeFocus = _ref.takeFocus,
55
+ takeFocusDelay = _ref.takeFocusDelay,
55
56
  type = _ref.type,
56
57
  wrapperClassName = _ref.wrapperClassName,
57
58
  inputProps = _objectWithoutProperties(_ref, _excluded);
@@ -63,7 +64,7 @@ var Input = function Input(_ref) {
63
64
  var hasError = !!error;
64
65
 
65
66
  var commonProps = _objectSpread({
66
- "aria-describedby": help ? helpId : null,
67
+ "aria-describedby": [help ? helpId : null, success ? validationId : null].filter(Boolean).join(" "),
67
68
  "aria-errormessage": hasError ? validationId : null,
68
69
  "aria-invalid": hasError,
69
70
  id: id,
@@ -73,7 +74,13 @@ var Input = function Input(_ref) {
73
74
 
74
75
  (0, _react.useEffect)(function () {
75
76
  if (takeFocus) {
76
- inputRef.current.focus();
77
+ if (takeFocusDelay) {
78
+ setTimeout(function () {
79
+ return inputRef.current.focus();
80
+ }, takeFocusDelay);
81
+ } else {
82
+ inputRef.current.focus();
83
+ }
77
84
  }
78
85
  }, [takeFocus]);
79
86
  var input;
@@ -61,7 +61,12 @@ var Modal = function Modal(_ref) {
61
61
  }
62
62
  };
63
63
 
64
- var keyListenersMap = new Map([["Escape", close], ["Tab", handleTabKey]]);
64
+ var handleEscKey = function handleEscKey(e) {
65
+ e.nativeEvent.stopImmediatePropagation();
66
+ close();
67
+ };
68
+
69
+ var keyListenersMap = new Map([["Escape", handleEscKey], ["Tab", handleTabKey]]);
65
70
  (0, _react.useEffect)(function () {
66
71
  modalRef.current.focus();
67
72
  }, [modalRef]);
@@ -69,7 +74,13 @@ var Modal = function Modal(_ref) {
69
74
  var _focusableModalElemen;
70
75
 
71
76
  focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
72
- (_focusableModalElemen = focusableModalElements.current[0]) === null || _focusableModalElemen === void 0 ? void 0 : _focusableModalElemen.focus();
77
+ var focusIndex = 0; // when the close button is rendered, focus on the 2nd content element and not the close btn.
78
+
79
+ if (close && focusableModalElements.current.length > 1) {
80
+ focusIndex = 1;
81
+ }
82
+
83
+ (_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0 ? void 0 : _focusableModalElemen.focus();
73
84
  }, []);
74
85
  (0, _react.useEffect)(function () {
75
86
  var keyDown = function keyDown(e) {
@@ -1,5 +1,8 @@
1
1
  import type { HTMLProps, ReactNode } from "react";
2
2
  import type { ClassName, PropsWithSpread, ValueOf } from "../../types";
3
+ export declare enum Label {
4
+ Close = "Close notification"
5
+ }
3
6
  export declare const NotificationSeverity: {
4
7
  readonly CAUTION: "caution";
5
8
  readonly INFORMATION: "information";
@@ -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.NotificationSeverity = void 0;
8
+ exports.default = exports.NotificationSeverity = exports.Label = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -31,6 +31,13 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
31
31
 
32
32
  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; }
33
33
 
34
+ var Label;
35
+ exports.Label = Label;
36
+
37
+ (function (Label) {
38
+ Label["Close"] = "Close notification";
39
+ })(Label || (exports.Label = Label = {}));
40
+
34
41
  var NotificationSeverity = {
35
42
  CAUTION: "caution",
36
43
  INFORMATION: "information",
@@ -89,11 +96,10 @@ var Notification = function Notification(_ref) {
89
96
  }, title), inline && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "\u2002"), /*#__PURE__*/_react.default.createElement("p", {
90
97
  className: "p-notification__message"
91
98
  }, children), onDismiss && /*#__PURE__*/_react.default.createElement("button", {
92
- "aria-label": "Close notification",
93
99
  className: "p-notification__close",
94
100
  "data-testid": "notification-close-button",
95
101
  onClick: onDismiss
96
- }, "Close")), showMeta && /*#__PURE__*/_react.default.createElement("div", {
102
+ }, Label.Close)), showMeta && /*#__PURE__*/_react.default.createElement("div", {
97
103
  className: "p-notification__meta",
98
104
  "data-testid": "notification-meta"
99
105
  }, timestamp && /*#__PURE__*/_react.default.createElement("span", {
@@ -1,4 +1,8 @@
1
1
  import type { MouseEventHandler } from "react";
2
+ export declare enum Label {
3
+ Next = "Next page",
4
+ Previous = "Previous page"
5
+ }
2
6
  export declare type PaginationDirection = "forward" | "back";
3
7
  export declare type Props = {
4
8
  /**
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.Label = void 0;
7
7
 
8
8
  var _classnames = _interopRequireDefault(require("classnames"));
9
9
 
@@ -11,12 +11,20 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
+ var Label;
15
+ exports.Label = Label;
16
+
17
+ (function (Label) {
18
+ Label["Next"] = "Next page";
19
+ Label["Previous"] = "Previous page";
20
+ })(Label || (exports.Label = Label = {}));
21
+
14
22
  var PaginationButton = function PaginationButton(_ref) {
15
23
  var direction = _ref.direction,
16
24
  onClick = _ref.onClick,
17
25
  _ref$disabled = _ref.disabled,
18
26
  disabled = _ref$disabled === void 0 ? false : _ref$disabled;
19
- var label = direction === "back" ? "Previous page" : "Next page";
27
+ var label = direction === "back" ? Label.Previous : Label.Next;
20
28
  return /*#__PURE__*/_react.default.createElement("li", {
21
29
  className: "p-pagination__item"
22
30
  }, /*#__PURE__*/_react.default.createElement("button", {
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
2
  import type { InputHTMLAttributes, ReactNode } from "react";
3
3
  import type { ClassName, PropsWithSpread } from "../../types";
4
+ export declare enum Label {
5
+ Hide = "Hide",
6
+ Show = "Show"
7
+ }
4
8
  /**
5
9
  * The props for the Password Toggle component.
6
10
  */
@@ -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 = void 0;
8
+ exports.default = exports.Label = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -45,6 +45,18 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
45
45
 
46
46
  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; }
47
47
 
48
+ var Label;
49
+ /**
50
+ * The props for the Password Toggle component.
51
+ */
52
+
53
+ exports.Label = Label;
54
+
55
+ (function (Label) {
56
+ Label["Hide"] = "Hide";
57
+ Label["Show"] = "Show";
58
+ })(Label || (exports.Label = Label = {}));
59
+
48
60
  var PasswordToggle = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
49
61
  var caution = _ref.caution,
50
62
  className = _ref.className,
@@ -102,10 +114,10 @@ var PasswordToggle = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
102
114
  }
103
115
  }, /*#__PURE__*/_react.default.createElement("span", {
104
116
  className: "p-form-password-toggle__label"
105
- }, isPassword ? "Show" : "Hide"), /*#__PURE__*/_react.default.createElement("i", {
117
+ }, isPassword ? Label.Show : Label.Hide), /*#__PURE__*/_react.default.createElement("i", {
106
118
  className: isPassword ? "p-icon--show" : "p-icon--hide"
107
119
  }))), /*#__PURE__*/_react.default.createElement("input", _extends({
108
- "aria-describedby": help ? helpId : null,
120
+ "aria-describedby": [help ? helpId : null, success ? validationId : null].filter(Boolean).join(" "),
109
121
  "aria-errormessage": hasError ? validationId : null,
110
122
  "aria-invalid": hasError,
111
123
  className: (0, _classnames.default)("p-form-validation__input", className),
@@ -1,4 +1,9 @@
1
1
  import type { SearchAndFilterChip, SearchAndFilterData } from "./types";
2
+ export declare enum Label {
3
+ AddFilter = "Add filter",
4
+ Clear = "Clear input",
5
+ SearchAndFilter = "Search and filter"
6
+ }
2
7
  export declare type Props = {
3
8
  /**
4
9
  * A list of chips to initialise inside the input.
@@ -13,5 +18,5 @@ export declare type Props = {
13
18
  */
14
19
  returnSearchData: (searchData: SearchAndFilterChip[]) => void;
15
20
  };
16
- declare const SearchAndFilter: ({ existingSearchData, filterPanelData, returnSearchData, }: Props) => JSX.Element;
21
+ declare const SearchAndFilter: ({ existingSearchData, filterPanelData, returnSearchData, ...props }: Props) => JSX.Element;
17
22
  export default SearchAndFilter;
@@ -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 = void 0;
8
+ exports.default = exports.Label = void 0;
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -19,12 +19,16 @@ var _utils = require("./utils");
19
19
 
20
20
  var _hooks = require("../../hooks");
21
21
 
22
+ var _excluded = ["existingSearchData", "filterPanelData", "returnSearchData"];
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); }
23
25
 
24
26
  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; }
25
27
 
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
29
 
30
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
31
+
28
32
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
29
33
 
30
34
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -45,11 +49,25 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
45
49
 
46
50
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
47
51
 
52
+ 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; }
53
+
54
+ 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; }
55
+
56
+ var Label;
57
+ exports.Label = Label;
58
+
59
+ (function (Label) {
60
+ Label["AddFilter"] = "Add filter";
61
+ Label["Clear"] = "Clear input";
62
+ Label["SearchAndFilter"] = "Search and filter";
63
+ })(Label || (exports.Label = Label = {}));
64
+
48
65
  var SearchAndFilter = function SearchAndFilter(_ref) {
49
66
  var _ref$existingSearchDa = _ref.existingSearchData,
50
67
  existingSearchData = _ref$existingSearchDa === void 0 ? [] : _ref$existingSearchDa,
51
68
  filterPanelData = _ref.filterPanelData,
52
- returnSearchData = _ref.returnSearchData;
69
+ returnSearchData = _ref.returnSearchData,
70
+ props = _objectWithoutProperties(_ref, _excluded);
53
71
 
54
72
  var _useState = (0, _react.useState)(existingSearchData),
55
73
  _useState2 = _slicedToArray(_useState, 2),
@@ -246,20 +264,21 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
246
264
  setSearchTerm("");
247
265
  };
248
266
 
249
- var placeholder = searchData.length ? "Add filter" : "Search and filter";
250
- return /*#__PURE__*/_react.default.createElement("div", {
267
+ var placeholder = searchData.length ? Label.AddFilter : Label.SearchAndFilter;
268
+ return /*#__PURE__*/_react.default.createElement("div", _extends({
251
269
  className: "p-search-and-filter",
252
270
  ref: searchAndFilterRef,
253
271
  onClick: function onClick() {
254
272
  return filterPanelHidden && setFilterPanelHidden(false);
255
273
  }
256
- }, /*#__PURE__*/_react.default.createElement("div", {
274
+ }, props), /*#__PURE__*/_react.default.createElement("div", {
257
275
  className: "p-search-and-filter__search-container",
258
276
  "aria-expanded": searchBoxExpanded,
259
277
  "data-active": searchContainerActive || searchData.length === 0,
260
278
  "data-empty": searchData.length <= 0,
261
279
  ref: searchContainerRef
262
280
  }, searchTerm !== "" && /*#__PURE__*/_react.default.createElement("button", {
281
+ "aria-label": Label.Clear,
263
282
  className: "p-search-and-filter__clear",
264
283
  onClick: function onClick() {
265
284
  return clearAllSearchTerms();
@@ -288,7 +307,7 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
288
307
  }, /*#__PURE__*/_react.default.createElement("label", {
289
308
  className: "u-off-screen",
290
309
  htmlFor: "search-and-filter-input"
291
- }, searchData.length ? "Add filter" : "Search and filter"), /*#__PURE__*/_react.default.createElement("input", {
310
+ }, searchData.length ? Label.AddFilter : Label.SearchAndFilter), /*#__PURE__*/_react.default.createElement("input", {
292
311
  autoComplete: "off",
293
312
  className: "p-search-and-filter__input",
294
313
  id: "search-and-filter-input",
@@ -1,5 +1,9 @@
1
1
  import React, { HTMLProps } from "react";
2
2
  import type { ClassName, PropsWithSpread } from "../../types";
3
+ export declare enum Label {
4
+ Clear = "Clear search field",
5
+ Search = "Search"
6
+ }
3
7
  export declare type Props = PropsWithSpread<{
4
8
  /**
5
9
  * Whether autocomplete should be enabled for the search input.
@@ -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 = void 0;
8
+ exports.default = exports.Label = void 0;
9
9
 
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
 
@@ -27,6 +27,14 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
27
27
 
28
28
  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; }
29
29
 
30
+ var Label;
31
+ exports.Label = Label;
32
+
33
+ (function (Label) {
34
+ Label["Clear"] = "Clear search field";
35
+ Label["Search"] = "Search";
36
+ })(Label || (exports.Label = Label = {}));
37
+
30
38
  var SearchBox = /*#__PURE__*/_react.default.forwardRef(function (_ref, forwardedRef) {
31
39
  var _ref$autocomplete = _ref.autocomplete,
32
40
  autocomplete = _ref$autocomplete === void 0 ? "on" : _ref$autocomplete,
@@ -88,13 +96,13 @@ var SearchBox = /*#__PURE__*/_react.default.forwardRef(function (_ref, forwarded
88
96
  type: "reset"
89
97
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
90
98
  name: "close"
91
- }, "Clear search field")), /*#__PURE__*/_react.default.createElement("button", {
99
+ }, Label.Clear)), /*#__PURE__*/_react.default.createElement("button", {
92
100
  className: "p-search-box__button",
93
101
  disabled: disabled,
94
102
  onClick: triggerSearch
95
103
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
96
104
  name: "search"
97
- }, "Search")));
105
+ }, Label.Search)));
98
106
  });
99
107
 
100
108
  SearchBox.displayName = "SearchBox";
@@ -84,7 +84,7 @@ var Select = function Select(_ref2) {
84
84
  success: success,
85
85
  validationId: validationId
86
86
  }, /*#__PURE__*/_react.default.createElement("select", _extends({
87
- "aria-describedby": help ? helpId : null,
87
+ "aria-describedby": [help ? helpId : null, success ? validationId : null].filter(Boolean).join(" "),
88
88
  "aria-errormessage": hasError ? validationId : null,
89
89
  "aria-invalid": hasError,
90
90
  className: (0, _classnames.default)("p-form-validation__input", className),
@@ -78,7 +78,7 @@ var Textarea = function Textarea(_ref) {
78
78
  success: success,
79
79
  validationId: validationId
80
80
  }, /*#__PURE__*/_react.default.createElement("textarea", _extends({
81
- "aria-describedby": help ? helpId : null,
81
+ "aria-describedby": [help ? helpId : null, success ? validationId : null].filter(Boolean).join(" "),
82
82
  "aria-errormessage": hasError ? validationId : null,
83
83
  "aria-invalid": hasError,
84
84
  className: (0, _classnames.default)("p-form-validation__input", className),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.37.7",
3
+ "version": "0.37.9",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",
@@ -43,7 +43,6 @@
43
43
  "@testing-library/user-event": "14.3.0",
44
44
  "@typescript-eslint/eslint-plugin": "5.32.0",
45
45
  "@typescript-eslint/parser": "5.32.0",
46
- "@wojtekmaj/enzyme-adapter-react-17": "0.6.7",
47
46
  "babel-jest": "27.5.1",
48
47
  "babel-loader": "8.2.5",
49
48
  "babel-plugin-module-resolver": "4.1.0",
@@ -52,9 +51,6 @@
52
51
  "css-loader": "6.7.1",
53
52
  "cypress": "9.7.0",
54
53
  "deepmerge": "4.2.2",
55
- "enzyme": "3.11.0",
56
- "enzyme-adapter-react-16": "1.15.6",
57
- "enzyme-to-json": "3.6.2",
58
54
  "eslint": "8.21.0",
59
55
  "eslint-config-prettier": "8.5.0",
60
56
  "eslint-config-react-app": "7.0.1",
@@ -83,7 +79,7 @@
83
79
  "ts-jest": "27.1.5",
84
80
  "tsc-alias": "1.7.0",
85
81
  "typescript": "4.7.4",
86
- "vanilla-framework": "3.8.1",
82
+ "vanilla-framework": "3.10.0",
87
83
  "wait-on": "5.3.0",
88
84
  "webpack": "5.74.0"
89
85
  },
@@ -107,7 +103,7 @@
107
103
  "peerDependencies": {
108
104
  "react": "^17.0.2 || ^18.0.0",
109
105
  "react-dom": "^17.0.2 || ^18.0.0",
110
- "vanilla-framework": "3.8.1"
106
+ "vanilla-framework": "3.10.0"
111
107
  },
112
108
  "scripts": {
113
109
  "build": "rm -rf dist && yarn build-local; yarn build-declaration",
@@ -156,9 +152,6 @@
156
152
  "roots": [
157
153
  "<rootDir>/src/"
158
154
  ],
159
- "snapshotSerializers": [
160
- "enzyme-to-json/serializer"
161
- ],
162
155
  "setupFilesAfterEnv": [
163
156
  "<rootDir>/src/setupTests.js"
164
157
  ],