@canonical/react-components 1.2.3 → 1.2.4

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.
@@ -22,6 +22,10 @@ export type Props<C> = PropsWithSpread<{
22
22
  * The navigation item's status.
23
23
  */
24
24
  status?: ReactNode;
25
+ /**
26
+ * A ref to pass to the element.
27
+ */
28
+ forwardRef?: React.Ref<C> | null;
25
29
  }, C>;
26
- declare const SideNavigationBase: <C>({ component: Component, dark, icon, label, status, ...props }: Props<C>) => React.JSX.Element;
30
+ declare const SideNavigationBase: <C>({ component: Component, dark, icon, label, status, forwardRef, ...props }: Props<C>) => React.JSX.Element;
27
31
  export default SideNavigationBase;
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _Icon = _interopRequireDefault(require("../../Icon"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
10
11
  const SideNavigationBase = _ref => {
11
12
  let {
12
13
  component: Component,
@@ -14,9 +15,12 @@ const SideNavigationBase = _ref => {
14
15
  icon,
15
16
  label,
16
17
  status,
18
+ forwardRef,
17
19
  ...props
18
20
  } = _ref;
19
- return /*#__PURE__*/_react.default.createElement(Component, props, icon ? /*#__PURE__*/_react.default.createElement(_Icon.default, {
21
+ return /*#__PURE__*/_react.default.createElement(Component, _extends({
22
+ ref: forwardRef
23
+ }, props), icon ? /*#__PURE__*/_react.default.createElement(_Icon.default, {
20
24
  name: icon,
21
25
  light: dark,
22
26
  className: "p-side-navigation__icon"
@@ -1,8 +1,12 @@
1
1
  import React from "react";
2
- import type { HTMLProps } from "react";
2
+ import type { HTMLProps, ReactNode } from "react";
3
3
  import type { SideNavigationBaseProps } from "../SideNavigationBase";
4
4
  export type LinkDefaultElement = HTMLProps<HTMLAnchorElement>;
5
- export type Props<L = LinkDefaultElement, E = HTMLAnchorElement> = Omit<SideNavigationBaseProps<L>, "component"> & {
5
+ export type Props<L = LinkDefaultElement, E = HTMLAnchorElement> = Partial<Omit<SideNavigationBaseProps<L>, "component">> & {
6
+ /**
7
+ * The navigation item's label.
8
+ */
9
+ label: ReactNode;
6
10
  /**
7
11
  * The component or element to use for the link element e.g. `a` or `NavLink`.
8
12
  * @default a
@@ -22,9 +22,8 @@ const SideNavigationLink = _ref => {
22
22
  }
23
23
  return /*#__PURE__*/_react.default.createElement(_SideNavigationBase.default, _extends({
24
24
  className: (0, _classnames.default)("p-side-navigation__link", className),
25
- component: component !== null && component !== void 0 ? component : "a"
26
- }, props, {
27
- ref: forwardRef
28
- }));
25
+ component: component !== null && component !== void 0 ? component : "a",
26
+ forwardRef: forwardRef
27
+ }, props));
29
28
  };
30
29
  var _default = exports.default = SideNavigationLink;
package/dist/utils.js CHANGED
@@ -20,7 +20,8 @@ const highlightSubString = (str, subString) => {
20
20
  match: false
21
21
  };
22
22
  }
23
- const caseInsensitiveRegex = new RegExp(subString, "gi");
23
+ const escapedSubstring = subString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
24
+ const caseInsensitiveRegex = new RegExp(escapedSubstring, "gi");
24
25
  const newStr = str.replace(caseInsensitiveRegex, match => "<strong>".concat(match, "</strong>"));
25
26
  return {
26
27
  text: subString === "" ? str : newStr,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {