@canonical/react-components 0.47.2 → 0.47.3

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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.NotificationProvider = exports.NotificationConsumer = void 0;
7
7
  exports.useNotify = useNotify;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactRouterDom = require("react-router-dom");
10
9
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
10
  var _messageBuilder = require("./messageBuilder");
12
11
  var _Notification = _interopRequireWildcard(require("../Notification/Notification"));
@@ -24,7 +23,9 @@ const NotifyContext = /*#__PURE__*/(0, _react.createContext)({
24
23
  });
25
24
  const NotificationProvider = _ref => {
26
25
  let {
27
- children
26
+ children,
27
+ state,
28
+ pathname
28
29
  } = _ref;
29
30
  const [notification, setNotification] = (0, _react.useState)(null);
30
31
  const clear = () => notification !== null && setNotification(null);
@@ -34,6 +35,14 @@ const NotificationProvider = _ref => {
34
35
  }
35
36
  return value;
36
37
  };
38
+ (0, _react.useEffect)(() => {
39
+ if (state !== null && state !== void 0 && state.queuedNotification) {
40
+ setDeduplicated(state.queuedNotification);
41
+ window.history.replaceState({}, "");
42
+ } else {
43
+ clear();
44
+ }
45
+ }, [state, pathname]);
37
46
  const helper = {
38
47
  notification,
39
48
  clear,
@@ -49,20 +58,7 @@ const NotificationProvider = _ref => {
49
58
  };
50
59
  exports.NotificationProvider = NotificationProvider;
51
60
  function useNotify() {
52
- const ctx = (0, _react.useContext)(NotifyContext);
53
- const {
54
- state,
55
- pathname
56
- } = (0, _reactRouterDom.useLocation)();
57
- (0, _react.useEffect)(() => {
58
- if (state !== null && state !== void 0 && state.queuedNotification) {
59
- ctx.setDeduplicated(state.queuedNotification);
60
- window.history.replaceState({}, "");
61
- } else {
62
- ctx.clear();
63
- }
64
- }, [state, pathname]);
65
- return ctx;
61
+ return (0, _react.useContext)(NotifyContext);
66
62
  }
67
63
  const NotificationConsumer = () => {
68
64
  const notify = useNotify();
@@ -2,6 +2,10 @@ import { ReactNode } from "react";
2
2
  import { ValueOf } from "../../types";
3
3
  import { NotificationSeverity } from "../Notification";
4
4
  export interface NotifyProviderProps {
5
+ state?: {
6
+ queuedNotification: NotificationType | null;
7
+ };
8
+ pathname?: string;
5
9
  children: ReactNode;
6
10
  }
7
11
  export interface NotificationAction {
@@ -41,6 +41,8 @@ const PasswordToggle = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
41
41
  const validationId = (0, _hooks.useId)();
42
42
  const helpId = (0, _hooks.useId)();
43
43
  const hasError = !!error;
44
+ const defaultPasswordToggleId = (0, _hooks.useId)();
45
+ const passwordToggleId = id || defaultPasswordToggleId;
44
46
  const togglePassword = () => {
45
47
  if (isPassword) {
46
48
  setIsPassword(false);
@@ -60,7 +62,7 @@ const PasswordToggle = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
60
62
  }, /*#__PURE__*/_react.default.createElement("div", {
61
63
  className: "p-form-password-toggle"
62
64
  }, /*#__PURE__*/_react.default.createElement(_Label.default, {
63
- forId: id,
65
+ forId: passwordToggleId,
64
66
  required: required
65
67
  }, label), /*#__PURE__*/_react.default.createElement(_Button.default, {
66
68
  appearance: "base",
@@ -79,7 +81,7 @@ const PasswordToggle = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
79
81
  "aria-errormessage": hasError ? validationId : null,
80
82
  "aria-invalid": hasError,
81
83
  className: (0, _classnames.default)("p-form-validation__input", className),
82
- id: id,
84
+ id: passwordToggleId,
83
85
  readOnly: readOnly,
84
86
  ref: ref,
85
87
  type: isPassword ? "password" : "text"
@@ -47,6 +47,8 @@ const Select = _ref2 => {
47
47
  } = _ref2;
48
48
  const selectRef = (0, _react.useRef)(null);
49
49
  const validationId = (0, _hooks.useId)();
50
+ const defaultSelectId = (0, _hooks.useId)();
51
+ const selectId = id || defaultSelectId;
50
52
  const helpId = (0, _hooks.useId)();
51
53
  const hasError = !!error;
52
54
  (0, _react.useEffect)(() => {
@@ -58,7 +60,7 @@ const Select = _ref2 => {
58
60
  caution: caution,
59
61
  className: wrapperClassName,
60
62
  error: error,
61
- forId: id,
63
+ forId: selectId,
62
64
  help: help,
63
65
  helpId: helpId,
64
66
  isSelect: true,
@@ -73,7 +75,7 @@ const Select = _ref2 => {
73
75
  "aria-errormessage": hasError ? validationId : null,
74
76
  "aria-invalid": hasError,
75
77
  className: (0, _classnames.default)("p-form-validation__input", className),
76
- id: id,
78
+ id: selectId,
77
79
  onChange: evt => onChange && onChange(evt),
78
80
  ref: selectRef
79
81
  }, selectProps), generateOptions(options)));
@@ -30,6 +30,8 @@ const Slider = _ref => {
30
30
  } = _ref;
31
31
  const validationId = (0, _hooks.useId)();
32
32
  const helpId = (0, _hooks.useId)();
33
+ const defaultSliderId = (0, _hooks.useId)();
34
+ const sliderId = id || defaultSliderId;
33
35
  const hasError = !!error;
34
36
  let style = {};
35
37
  if ((_navigator = navigator) !== null && _navigator !== void 0 && (_navigator = _navigator.userAgent) !== null && _navigator !== void 0 && _navigator.includes("AppleWebKit")) {
@@ -46,6 +48,7 @@ const Slider = _ref => {
46
48
  caution: caution,
47
49
  error: error,
48
50
  help: help,
51
+ forId: sliderId,
49
52
  helpId: helpId,
50
53
  label: label,
51
54
  required: required,
@@ -57,7 +60,7 @@ const Slider = _ref => {
57
60
  "aria-errormessage": hasError ? validationId : null,
58
61
  "aria-invalid": hasError,
59
62
  disabled: disabled,
60
- id: id,
63
+ id: sliderId,
61
64
  max: max,
62
65
  min: min,
63
66
  onChange: onChange,
@@ -1,4 +1,4 @@
1
- @import "~vanilla-framework/scss/settings";
1
+ @import "vanilla-framework/scss/settings";
2
2
 
3
3
  .pagination {
4
4
  align-items: baseline;
@@ -40,6 +40,8 @@ const Textarea = _ref => {
40
40
  const helpId = (0, _hooks.useId)();
41
41
  const hasError = !!error;
42
42
  const [innerValue, setInnervalue] = (0, _react.useState)(props.defaultValue);
43
+ const defaultTextAreaId = (0, _hooks.useId)();
44
+ const textAreaId = id || defaultTextAreaId;
43
45
  (0, _react.useEffect)(() => {
44
46
  if (takeFocus) {
45
47
  textareaRef.current.focus();
@@ -59,7 +61,7 @@ const Textarea = _ref => {
59
61
  caution: caution,
60
62
  className: wrapperClassName,
61
63
  error: error,
62
- forId: id,
64
+ forId: textAreaId,
63
65
  help: help,
64
66
  helpId: helpId,
65
67
  label: label,
@@ -73,7 +75,7 @@ const Textarea = _ref => {
73
75
  "aria-errormessage": hasError ? validationId : null,
74
76
  "aria-invalid": hasError,
75
77
  className: (0, _classnames.default)("p-form-validation__input", className),
76
- id: id,
78
+ id: textAreaId,
77
79
  onKeyUp: evt => {
78
80
  onKeyUp && onKeyUp(evt);
79
81
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.47.2",
3
+ "version": "0.47.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "Huw Wilkins <huw.wilkins@canonical.com>",
@@ -41,7 +41,6 @@
41
41
  "@testing-library/jest-dom": "5.17.0",
42
42
  "@testing-library/react": "14.1.2",
43
43
  "@testing-library/user-event": "14.5.2",
44
- "@types/react-router-dom": "5.3.3",
45
44
  "@typescript-eslint/eslint-plugin": "5.62.0",
46
45
  "@typescript-eslint/parser": "5.62.0",
47
46
  "babel-jest": "27.5.1",
@@ -95,7 +94,6 @@
95
94
  "classnames": "2.5.1",
96
95
  "nanoid": "3.3.7",
97
96
  "prop-types": "15.8.1",
98
- "react-router-dom": "6.21.1",
99
97
  "react-table": "7.8.0",
100
98
  "react-useportal": "1.0.19"
101
99
  },