@canonical/react-components 0.34.0 → 0.34.1

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.
@@ -36,6 +36,10 @@ export declare type Props = {
36
36
  * Whether the component is wrapping a select element.
37
37
  */
38
38
  isSelect?: boolean;
39
+ /**
40
+ * Whether the component is wrapping a checkbox or radio element.
41
+ */
42
+ isTickElement?: boolean;
39
43
  /**
40
44
  * The label for the field.
41
45
  */
@@ -65,5 +69,5 @@ export declare type Props = {
65
69
  */
66
70
  validationId?: string;
67
71
  };
68
- declare const Field: ({ caution, children, className, error, forId, help, helpId, isSelect, label, labelClassName, labelFirst, required, stacked, success, validationId, }: 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;
69
73
  export default Field;
@@ -15,11 +15,16 @@ var _Col = _interopRequireDefault(require("../Col"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- var generateHelp = function generateHelp(help, helpId) {
19
- return help && /*#__PURE__*/_react.default.createElement("p", {
20
- className: "p-form-help-text",
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
+ }),
21
26
  id: helpId
22
- }, help);
27
+ }, help) : null;
23
28
  };
24
29
 
25
30
  var generateError = function generateError(error, caution, success, validationId) {
@@ -54,33 +59,61 @@ var generateLabel = function generateLabel(forId, required, label, labelClassNam
54
59
  return labelNode;
55
60
  };
56
61
 
57
- var generateContent = function generateContent(isSelect, children, labelFirst, labelNode, help, error, caution, success, validationId, helpId) {
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;
58
74
  return /*#__PURE__*/_react.default.createElement("div", {
59
75
  className: "p-form__control u-clearfix"
60
76
  }, isSelect ? /*#__PURE__*/_react.default.createElement("div", {
61
77
  className: "p-form-validation__select-wrapper"
62
- }, children) : children, !labelFirst && labelNode, generateHelp(help, helpId), generateError(error, caution, success, validationId));
78
+ }, children) : children, !labelFirst && labelNode, generateHelpText({
79
+ helpId: helpId,
80
+ help: help,
81
+ isTickElement: isTickElement
82
+ }), generateError(error, caution, success, validationId));
63
83
  };
64
84
 
65
- var Field = function Field(_ref) {
66
- var caution = _ref.caution,
67
- children = _ref.children,
68
- className = _ref.className,
69
- error = _ref.error,
70
- forId = _ref.forId,
71
- help = _ref.help,
72
- helpId = _ref.helpId,
73
- isSelect = _ref.isSelect,
74
- label = _ref.label,
75
- labelClassName = _ref.labelClassName,
76
- _ref$labelFirst = _ref.labelFirst,
77
- labelFirst = _ref$labelFirst === void 0 ? true : _ref$labelFirst,
78
- required = _ref.required,
79
- stacked = _ref.stacked,
80
- success = _ref.success,
81
- validationId = _ref.validationId;
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;
82
103
  var labelNode = generateLabel(forId, required, label, labelClassName, stacked);
83
- var content = generateContent(isSelect, children, labelFirst, labelNode, help, error, caution, success, validationId, helpId);
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
+ });
84
117
  return /*#__PURE__*/_react.default.createElement("div", {
85
118
  className: (0, _classnames.default)("p-form__group", "p-form-validation", className, {
86
119
  "is-error": error,
@@ -102,6 +102,7 @@ var Input = function Input(_ref) {
102
102
  forId: id,
103
103
  help: help,
104
104
  helpId: helpId,
105
+ isTickElement: type === "checkbox" || type === "radio",
105
106
  label: fieldLabel,
106
107
  labelClassName: labelClassName,
107
108
  required: required,
@@ -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 type Position = "btm-center" | "btm-left" | "btm-right" | "left" | "right" | "top-center" | "top-left" | "top-right";
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: closePortal,
237
+ onBlur: handleBlur,
216
238
  onFocus: openPortal,
217
- onMouseOut: closePortal,
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
- }, children), isOpen && /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement("span", {
226
- className: (0, _classnames.default)("p-tooltip--".concat(adjustedPosition), "is-detached", tooltipClassName),
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 _Tooltip = _interopRequireDefault(require("./Tooltip"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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.34.0",
3
+ "version": "0.34.1",
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.0-beta.76",
29
- "@percy/storybook": "4.1.0",
30
- "@storybook/addon-a11y": "6.4.19",
31
- "@storybook/addon-controls": "6.4.19",
32
- "@storybook/addon-docs": "6.4.19",
33
- "@storybook/addons": "6.4.19",
34
- "@storybook/react": "6.4.19",
35
- "@storybook/theming": "6.4.19",
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.11.3",
38
- "@testing-library/jest-dom": "5.16.2",
39
- "@testing-library/react": "12.1.3",
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.13.0",
43
- "@typescript-eslint/parser": "5.13.0",
44
- "@wojtekmaj/enzyme-adapter-react-17": "0.6.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.3",
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.0.0",
49
+ "concurrently": "7.1.0",
50
50
  "css-loader": "5.2.7",
51
- "cypress": "9.5.1",
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.10.0",
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.2",
65
- "eslint-plugin-react-hooks": "4.3.0",
66
- "eslint-plugin-testing-library": "5.0.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.5.1",
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.9",
73
+ "sass": "1.49.11",
74
74
  "sass-loader": "10.2.1",
75
75
  "style-loader": "2.0.0",
76
- "stylelint": "14.5.3",
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.3",
82
- "tsc-alias": "1.6.3",
83
- "typescript": "4.6.2",
81
+ "ts-jest": "27.1.4",
82
+ "tsc-alias": "1.6.5",
83
+ "typescript": "4.6.3",
84
84
  "vanilla-framework": "3.1.1",
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.39",
91
- "@types/react-dom": "17.0.13",
92
- "@types/react-table": "7.7.9",
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.1",
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"