@canonical/react-components 2.1.0 → 2.2.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.
Files changed (55) hide show
  1. package/dist/components/Card/Card.stories.d.ts +2 -2
  2. package/dist/components/CodeSnippet/CodeSnippet.stories.js +3 -2
  3. package/dist/components/Col/Col.stories.d.ts +2 -1
  4. package/dist/components/ConfirmationButton/ConfirmationButton.d.ts +7 -2
  5. package/dist/components/ConfirmationButton/ConfirmationButton.js +9 -1
  6. package/dist/components/ConfirmationButton/ConfirmationButton.stories.d.ts +1 -0
  7. package/dist/components/ConfirmationButton/ConfirmationButton.stories.js +23 -1
  8. package/dist/components/ContextualMenu/ContextualMenu.js +3 -3
  9. package/dist/components/ContextualMenu/ContextualMenu.stories.d.ts +1 -0
  10. package/dist/components/ContextualMenu/ContextualMenu.stories.js +19 -1
  11. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +1 -0
  12. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +30 -3
  13. package/dist/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +0 -1
  14. package/dist/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.js +1 -23
  15. package/dist/components/MainTable/MainTable.d.ts +3 -1
  16. package/dist/components/ModularTable/ModularTable.d.ts +1 -1
  17. package/dist/components/ModularTable/ModularTable.js +1 -1
  18. package/dist/components/ModularTable/ModularTable.stories.js +2 -2
  19. package/dist/components/Navigation/Navigation.d.ts +1 -1
  20. package/dist/components/Notification/Notification.d.ts +1 -1
  21. package/dist/components/Notification/Notification.js +3 -1
  22. package/dist/components/NotificationProvider/NotificationProvider.js +2 -2
  23. package/dist/components/SearchAndFilter/SearchAndFilter.js +1 -4
  24. package/dist/components/SearchAndFilter/utils.d.ts +3 -2
  25. package/dist/components/SideNavigation/SideNavigation.js +1 -1
  26. package/dist/components/Tooltip/Tooltip.js +1 -1
  27. package/dist/esm/components/Card/Card.stories.d.ts +2 -2
  28. package/dist/esm/components/CodeSnippet/CodeSnippet.stories.js +3 -2
  29. package/dist/esm/components/Col/Col.stories.d.ts +2 -1
  30. package/dist/esm/components/ConfirmationButton/ConfirmationButton.d.ts +7 -2
  31. package/dist/esm/components/ConfirmationButton/ConfirmationButton.js +11 -3
  32. package/dist/esm/components/ConfirmationButton/ConfirmationButton.stories.d.ts +1 -0
  33. package/dist/esm/components/ConfirmationButton/ConfirmationButton.stories.js +22 -0
  34. package/dist/esm/components/ContextualMenu/ContextualMenu.js +3 -3
  35. package/dist/esm/components/ContextualMenu/ContextualMenu.stories.d.ts +1 -0
  36. package/dist/esm/components/ContextualMenu/ContextualMenu.stories.js +18 -0
  37. package/dist/esm/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +1 -0
  38. package/dist/esm/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +28 -2
  39. package/dist/esm/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.d.ts +0 -1
  40. package/dist/esm/components/CustomSelect/CustomSelectDropdown/CustomSelectDropdown.js +0 -21
  41. package/dist/esm/components/MainTable/MainTable.d.ts +3 -1
  42. package/dist/esm/components/ModularTable/ModularTable.d.ts +1 -1
  43. package/dist/esm/components/ModularTable/ModularTable.js +1 -1
  44. package/dist/esm/components/ModularTable/ModularTable.stories.js +60 -12
  45. package/dist/esm/components/Navigation/Navigation.d.ts +1 -1
  46. package/dist/esm/components/Notification/Notification.d.ts +1 -1
  47. package/dist/esm/components/Notification/Notification.js +4 -2
  48. package/dist/esm/components/NotificationProvider/NotificationProvider.js +2 -2
  49. package/dist/esm/components/SearchAndFilter/SearchAndFilter.js +1 -4
  50. package/dist/esm/components/SearchAndFilter/utils.d.ts +3 -2
  51. package/dist/esm/components/SideNavigation/SideNavigation.js +1 -1
  52. package/dist/esm/components/Tooltip/Tooltip.js +1 -1
  53. package/dist/esm/hooks/useWindowFitment.js +2 -2
  54. package/dist/hooks/useWindowFitment.js +2 -2
  55. package/package.json +36 -37
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { Meta } from "@storybook/react";
3
- import Card from "./";
3
+ import Card, { CardProps } from "./";
4
4
  declare const meta: Meta<typeof Card>;
5
5
  export default meta;
6
6
  export declare const Default: {
@@ -29,5 +29,5 @@ export declare const Overlay: {
29
29
  overlay: boolean;
30
30
  children: string;
31
31
  };
32
- render: (args: any) => React.JSX.Element;
32
+ render: (args: CardProps) => React.JSX.Element;
33
33
  };
@@ -105,13 +105,14 @@ const WrapLines = exports.WrapLines = {
105
105
  */
106
106
  const Dropdown = exports.Dropdown = {
107
107
  render: () => {
108
- // eslint-disable-next-line react-hooks/rules-of-hooks
109
- const [lang, setLang] = (0, _react.useState)("html");
110
108
  const code = {
111
109
  js: "console.log(\"Example 1\");",
112
110
  css: ".p-heading--2 { color: red; }",
113
111
  html: "<h1 class=\"p-heading--2\">How to use code snippets</h1>"
114
112
  };
113
+
114
+ // eslint-disable-next-line react-hooks/rules-of-hooks
115
+ const [lang, setLang] = (0, _react.useState)("html");
115
116
  return /*#__PURE__*/_react.default.createElement(_CodeSnippet.default, {
116
117
  blocks: [{
117
118
  code: code[lang],
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
2
  import { Meta, StoryObj } from "@storybook/react";
3
3
  import Col from "./Col";
4
- declare const Template: (args: any) => React.JSX.Element;
4
+ import { ColProps } from ".";
5
+ declare const Template: (args: ColProps) => React.JSX.Element;
5
6
  declare const meta: Meta<typeof Template>;
6
7
  export default meta;
7
8
  type Story = StoryObj<typeof Col>;
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { MouseEvent } from "react";
2
2
  import { PropsWithSpread, SubComponentProps } from "../../types";
3
3
  import { ActionButtonProps } from "../ActionButton";
4
4
  import { ConfirmationModalProps } from "../ConfirmationModal";
@@ -20,9 +20,14 @@ export type Props = PropsWithSpread<{
20
20
  * Whether to show a hint about the SHIFT+Click shortcut to skip the confirmation modal.
21
21
  */
22
22
  showShiftClickHint?: boolean;
23
+ /**
24
+ * A handler that determines whether the confirmation modal should be shown.
25
+ * If it returns `true`, the modal is shown. If it returns `false`, the modal is not shown.
26
+ */
27
+ preModalOpenHook?: (event: MouseEvent<HTMLButtonElement>) => boolean;
23
28
  }, ActionButtonProps>;
24
29
  /**
25
30
  * `ConfirmationButton` is a specialised version of the [ActionButton](?path=/docs/actionbutton--default-story) component that uses a [ConfirmationModal](?path=/docs/confirmationmodal--default-story) to prompt a confirmation from the user before executing an action.
26
31
  */
27
- export declare const ConfirmationButton: ({ confirmationModalProps, onHoverText, shiftClickEnabled, showShiftClickHint, ...actionButtonProps }: Props) => React.JSX.Element;
32
+ export declare const ConfirmationButton: ({ confirmationModalProps, onHoverText, shiftClickEnabled, showShiftClickHint, preModalOpenHook, ...actionButtonProps }: Props) => React.JSX.Element;
28
33
  export default ConfirmationButton;
@@ -28,6 +28,7 @@ const ConfirmationButton = _ref => {
28
28
  onHoverText,
29
29
  shiftClickEnabled = false,
30
30
  showShiftClickHint = false,
31
+ preModalOpenHook,
31
32
  ...actionButtonProps
32
33
  } = _ref;
33
34
  const {
@@ -53,6 +54,13 @@ const ConfirmationButton = _ref => {
53
54
  openPortal(e);
54
55
  }
55
56
  };
57
+ const handleClick = e => {
58
+ if (preModalOpenHook) {
59
+ const result = preModalOpenHook(e);
60
+ if (!result) return;
61
+ }
62
+ shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
63
+ };
56
64
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen && /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, _extends({}, confirmationModalProps, {
57
65
  close: handleCancelModal,
58
66
  confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
@@ -60,7 +68,7 @@ const ConfirmationButton = _ref => {
60
68
  }), confirmationModalProps.children, showShiftClickHint && /*#__PURE__*/_react.default.createElement("p", {
61
69
  className: "p-text--small u-text--muted u-hide--small"
62
70
  }, "Next time, you can skip this confirmation by holding", " ", /*#__PURE__*/_react.default.createElement("code", null, "SHIFT"), " and clicking the action."))), /*#__PURE__*/_react.default.createElement(_ActionButton.default, _extends({}, actionButtonProps, {
63
- onClick: shiftClickEnabled ? handleShiftClick : openPortal,
71
+ onClick: handleClick,
64
72
  title: generateTitle(onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel)
65
73
  }), actionButtonProps.children));
66
74
  };
@@ -7,3 +7,4 @@ type Story = StoryObj<typeof ConfirmationButton>;
7
7
  export declare const IconAndLabel: Story;
8
8
  export declare const IconOnly: Story;
9
9
  export declare const BaseAppearance: Story;
10
+ export declare const WithPreModalOpenHook: Story;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.IconOnly = exports.IconAndLabel = exports.Default = exports.BaseAppearance = void 0;
6
+ exports.default = exports.WithPreModalOpenHook = exports.IconOnly = exports.IconAndLabel = exports.Default = exports.BaseAppearance = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _ConfirmationButton = _interopRequireDefault(require("./ConfirmationButton"));
9
9
  var _Icon = _interopRequireWildcard(require("../Icon"));
@@ -105,4 +105,26 @@ const BaseAppearance = exports.BaseAppearance = {
105
105
  }));
106
106
  },
107
107
  name: "Base appearance"
108
+ };
109
+ const WithPreModalOpenHook = exports.WithPreModalOpenHook = {
110
+ render: () => {
111
+ const dontOpenModal = () => false;
112
+ const openModal = () => true;
113
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ConfirmationButton.default, {
114
+ preModalOpenHook: dontOpenModal,
115
+ confirmationModalProps: {
116
+ title: "Confirm delete",
117
+ confirmButtonLabel: "Delete",
118
+ children: /*#__PURE__*/_react.default.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/_react.default.createElement("br", null), "You cannot undo this action.")
119
+ }
120
+ }, "Don't open modal"), /*#__PURE__*/_react.default.createElement(_ConfirmationButton.default, {
121
+ preModalOpenHook: openModal,
122
+ confirmationModalProps: {
123
+ title: "Confirm delete",
124
+ confirmButtonLabel: "Delete",
125
+ children: /*#__PURE__*/_react.default.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/_react.default.createElement("br", null), "You cannot undo this action.")
126
+ }
127
+ }, "Open modal"));
128
+ },
129
+ name: "With preModalOpenHook handler"
108
130
  };
@@ -91,7 +91,7 @@ const ContextualMenu = _ref => {
91
91
  const updatePositionCoords = (0, _react.useCallback)(() => {
92
92
  const parent = getPositionNode(wrapper.current, positionNode);
93
93
  if (!parent) {
94
- return null;
94
+ return;
95
95
  }
96
96
  setPositionCoords(parent.getBoundingClientRect());
97
97
  }, [wrapper, positionNode]);
@@ -143,13 +143,13 @@ const ContextualMenu = _ref => {
143
143
  }
144
144
  }
145
145
  }, [closePortal, openPortal, visible, isOpen, previousVisible]);
146
- const onResize = (0, _react.useCallback)(evt => {
146
+ const onResize = (0, _react.useCallback)(() => {
147
147
  const parent = getPositionNode(wrapper.current, positionNode);
148
148
  if (parent && !getPositionNodeVisible(parent)) {
149
149
  // Hide the menu if the item has become hidden. This might happen in
150
150
  // a responsive table when columns become hidden as the page
151
151
  // becomes smaller.
152
- closePortal(evt);
152
+ closePortal();
153
153
  } else {
154
154
  // Update the coordinates so that the menu stays relative to the
155
155
  // toggle button.
@@ -11,3 +11,4 @@ export declare const Toggle: Story;
11
11
  export declare const OverflowingContainer: Story;
12
12
  export declare const ChildFunction: Story;
13
13
  export declare const ChildElement: Story;
14
+ export declare const InsideModal: Story;
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Toggle = exports.OverflowingContainer = exports.Default = exports.ChildFunction = exports.ChildElement = void 0;
6
+ exports.default = exports.Toggle = exports.OverflowingContainer = exports.InsideModal = exports.Default = exports.ChildFunction = exports.ChildElement = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _Button = _interopRequireDefault(require("../Button"));
9
9
  var _ContextualMenu = _interopRequireDefault(require("./ContextualMenu"));
10
+ var _Modal = _interopRequireDefault(require("../Modal"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  const ScrollTemplate = args => /*#__PURE__*/_react.default.createElement("div", {
12
13
  style: {
@@ -104,4 +105,21 @@ const ChildElement = exports.ChildElement = {
104
105
  position: "right",
105
106
  toggleLabel: "Click me!"
106
107
  }
108
+ };
109
+ const InsideModal = exports.InsideModal = {
110
+ name: "Inside modal",
111
+ args: {
112
+ links: Array.from({
113
+ length: 5
114
+ }, (_, index) => ({
115
+ children: "Link ".concat(index + 1),
116
+ onClick: () => {}
117
+ })),
118
+ hasToggleIcon: true,
119
+ position: "right",
120
+ toggleLabel: "Click me!"
121
+ },
122
+ render: args => /*#__PURE__*/_react.default.createElement(_Modal.default, {
123
+ title: "Contextual Menu inside Modal"
124
+ }, /*#__PURE__*/_react.default.createElement(Template, args))
107
125
  };
@@ -39,5 +39,6 @@ export type Props<L = null> = {
39
39
  * @return The new position.
40
40
  */
41
41
  export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
42
+ export declare const getNearestParentsZIndex: (element: HTMLElement | null) => string;
42
43
  declare const ContextualMenuDropdown: <L>({ adjustedPosition, autoAdjust, handleClose, constrainPanelWidth, dropdownClassName, dropdownContent, id, isOpen, links, position, positionCoords, positionNode, scrollOverflow, setAdjustedPosition, contextualMenuClassName, ...props }: Props<L>) => React.JSX.Element;
43
44
  export default ContextualMenuDropdown;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.adjustForWindow = exports.Label = void 0;
6
+ exports.getNearestParentsZIndex = exports.default = exports.adjustForWindow = exports.Label = void 0;
7
7
  var _classnames = _interopRequireDefault(require("classnames"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _hooks = require("../../../hooks");
@@ -134,6 +134,22 @@ const getClosestScrollableParent = node => {
134
134
  }
135
135
  return document.body;
136
136
  };
137
+
138
+ // nearest parents z-index that is not 0 or auto
139
+ const getNearestParentsZIndex = element => {
140
+ if (!window || !element) {
141
+ return "0";
142
+ }
143
+ const zIndex = window.getComputedStyle(element, null).getPropertyValue("z-index");
144
+ if (!element.parentElement) {
145
+ return zIndex;
146
+ }
147
+ if (zIndex === "auto" || zIndex === "0" || zIndex === "") {
148
+ return getNearestParentsZIndex(element.parentElement);
149
+ }
150
+ return zIndex;
151
+ };
152
+ exports.getNearestParentsZIndex = getNearestParentsZIndex;
137
153
  const ContextualMenuDropdown = _ref => {
138
154
  let {
139
155
  adjustedPosition,
@@ -164,11 +180,11 @@ const ContextualMenuDropdown = _ref => {
164
180
  const updateVerticalPosition = (0, _react.useCallback)(() => {
165
181
  var _dropdown$current$get;
166
182
  if (!positionNode) {
167
- return null;
183
+ return;
168
184
  }
169
185
  const scrollableParent = getClosestScrollableParent(positionNode);
170
186
  if (!scrollableParent) {
171
- return null;
187
+ return;
172
188
  }
173
189
  const scrollableParentRect = scrollableParent.getBoundingClientRect();
174
190
  const toggleRect = positionNode.getBoundingClientRect();
@@ -206,6 +222,17 @@ const ContextualMenuDropdown = _ref => {
206
222
  (0, _react.useEffect)(() => {
207
223
  updateVerticalPosition();
208
224
  }, [updateVerticalPosition]);
225
+ (0, _react.useEffect)(() => {
226
+ if (!dropdown.current) return;
227
+
228
+ // align z-index: when we are in a modal context, we want the dropdown to be above the modal
229
+ // apply the nearest parents z-index + 1
230
+ const zIndex = getNearestParentsZIndex(positionNode);
231
+ if (parseInt(zIndex) > 0) {
232
+ var _dropdown$current$par;
233
+ (_dropdown$current$par = dropdown.current.parentElement) === null || _dropdown$current$par === void 0 || _dropdown$current$par.style.setProperty("z-index", zIndex + 1);
234
+ }
235
+ }, [positionNode]);
209
236
  return (
210
237
  /*#__PURE__*/
211
238
  // Vanilla Framework uses .p-contextual-menu parent modifier classnames to determine the correct position of the .p-contextual-menu__dropdown dropdown (left, center, right).
@@ -19,7 +19,6 @@ export declare const adjustDropdownHeightBelow: (dropdown: HTMLUListElement) =>
19
19
  export declare const adjustDropdownHeightAbove: (dropdown: HTMLUListElement, search: HTMLInputElement | null) => void;
20
20
  export declare const dropdownIsAbove: (dropdown: HTMLUListElement) => boolean;
21
21
  export declare const adjustDropdownHeight: (dropdown: HTMLUListElement | null, search: HTMLInputElement | null) => void;
22
- export declare const getNearestParentsZIndex: (element: HTMLElement | null) => string;
23
22
  export declare const getOptionText: (option: CustomSelectOption) => string;
24
23
  declare const CustomSelectDropdown: FC<Props>;
25
24
  export default CustomSelectDropdown;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getOptionText = exports.getNearestParentsZIndex = exports.dropdownIsAbove = exports.default = exports.adjustDropdownHeightBelow = exports.adjustDropdownHeightAbove = exports.adjustDropdownHeight = void 0;
6
+ exports.getOptionText = exports.dropdownIsAbove = exports.default = exports.adjustDropdownHeightBelow = exports.adjustDropdownHeightAbove = exports.adjustDropdownHeight = void 0;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
@@ -87,20 +87,6 @@ const adjustDropdownHeight = (dropdown, search) => {
87
87
  adjustDropdownHeightBelow(dropdown);
88
88
  };
89
89
  exports.adjustDropdownHeight = adjustDropdownHeight;
90
- const getNearestParentsZIndex = element => {
91
- if (!document.defaultView || !element) {
92
- return "0";
93
- }
94
- const zIndex = document.defaultView.getComputedStyle(element, null).getPropertyValue("z-index");
95
- if (!element.parentElement) {
96
- return zIndex;
97
- }
98
- if (zIndex === "auto" || zIndex === "0" || zIndex === "") {
99
- return getNearestParentsZIndex(element.parentElement);
100
- }
101
- return zIndex;
102
- };
103
- exports.getNearestParentsZIndex = getNearestParentsZIndex;
104
90
  const getOptionText = option => {
105
91
  if (option.text) {
106
92
  return option.text;
@@ -139,14 +125,6 @@ const CustomSelectDropdown = _ref => {
139
125
  // align width with wrapper toggle width
140
126
  const toggleWidth = (_toggle$getBoundingCl = toggle === null || toggle === void 0 || (_toggle$getBoundingCl2 = toggle.getBoundingClientRect()) === null || _toggle$getBoundingCl2 === void 0 ? void 0 : _toggle$getBoundingCl2.width) !== null && _toggle$getBoundingCl !== void 0 ? _toggle$getBoundingCl : 0;
141
127
  dropdownRef.current.style.setProperty("min-width", "".concat(toggleWidth, "px"));
142
-
143
- // align z-index: when we are in a modal context, we want the dropdown to be above the modal
144
- // apply the nearest parents z-index + 1
145
- const zIndex = getNearestParentsZIndex(toggle);
146
- if (parseInt(zIndex) > 0) {
147
- var _dropdownRef$current$;
148
- (_dropdownRef$current$ = dropdownRef.current.parentElement) === null || _dropdownRef$current$ === void 0 || _dropdownRef$current$.style.setProperty("z-index", zIndex + 1);
149
- }
150
128
  }
151
129
  setTimeout(() => {
152
130
  var _dropdownRef$current;
@@ -26,7 +26,9 @@ export type MainTableCell = PropsWithSpread<{
26
26
  * The content of the table cell.
27
27
  */
28
28
  content?: ReactNode;
29
- }, Omit<TableCellProps, "children">>;
29
+ }, Omit<TableCellProps, "children"> & {
30
+ [data: `data-${string}`]: string;
31
+ }>;
30
32
  export type MainTableRow = PropsWithSpread<{
31
33
  /**
32
34
  * Optional class(es) to apply to the row.
@@ -57,7 +57,7 @@ ModularTable components accepts `columns` and `data` arguments in the same forma
57
57
  `columns` - The core columns configuration object for the entire table. https://react-table.tanstack.com/docs/api/useTable#column-options
58
58
  `data` - The data array that you want to display on the table.
59
59
  ### Important note!
60
- Values passed to both of these params have to me memoized (for example via{" "}
60
+ Values passed to both of these params have to be memoized (for example via{" "}
61
61
  <code>React.useMemo</code>). Memoization ensures that our data isn't recreated
62
62
  on every render. If we didn't use <code>React.useMemo</code>, the table would
63
63
  think it was receiving new data on every render and attempt to recalulate a
@@ -53,7 +53,7 @@ ModularTable components accepts `columns` and `data` arguments in the same forma
53
53
  `columns` - The core columns configuration object for the entire table. https://react-table.tanstack.com/docs/api/useTable#column-options
54
54
  `data` - The data array that you want to display on the table.
55
55
  ### Important note!
56
- Values passed to both of these params have to me memoized (for example via{" "}
56
+ Values passed to both of these params have to be memoized (for example via{" "}
57
57
  <code>React.useMemo</code>). Memoization ensures that our data isn't recreated
58
58
  on every render. If we didn't use <code>React.useMemo</code>, the table would
59
59
  think it was receiving new data on every render and attempt to recalulate a
@@ -255,14 +255,14 @@ const Subrows = exports.Subrows = {
255
255
  Header: "Flavour",
256
256
  accessor: "flavour",
257
257
  sortType: "basic",
258
- Cell: props => props.row.depth === 0 ? /*#__PURE__*/_react.default.createElement("strong", null, props.value) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
258
+ Cell: props => "depth" in props.row && props.row.depth === 0 ? /*#__PURE__*/_react.default.createElement("strong", null, props.value) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
259
259
  type: "checkbox"
260
260
  }), " ", props.value)
261
261
  }, {
262
262
  Header: "Scoops",
263
263
  accessor: "scoops",
264
264
  sortType: "basic",
265
- Cell: props => props.row.depth === 0 ? /*#__PURE__*/_react.default.createElement("span", {
265
+ Cell: props => "depth" in props.row && props.row.depth === 0 ? /*#__PURE__*/_react.default.createElement("span", {
266
266
  className: "u-text--muted"
267
267
  }, props.value) : props.value
268
268
  }], [])
@@ -1,6 +1,6 @@
1
1
  import { ReactNode, HTMLProps } from "react";
2
2
  import React from "react";
3
- import type { GenerateLink, NavItem, LogoProps } from "./types";
3
+ import { GenerateLink, NavItem, LogoProps } from "./types";
4
4
  import { PropsWithSpread, SubComponentProps } from "../../types";
5
5
  import { SearchBoxProps } from "../SearchBox";
6
6
  import { Theme } from "../../enums";
@@ -27,7 +27,7 @@ export type Props = PropsWithSpread<{
27
27
  /**
28
28
  * A list of up to two actions that the notification can perform.
29
29
  */
30
- actions?: NotificationAction[];
30
+ actions?: (NotificationAction | ReactNode)[];
31
31
  /**
32
32
  * Whether the notification should not have a border.
33
33
  */
@@ -103,6 +103,7 @@ const Notification = _ref => {
103
103
  }, title), inline && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "\u2002"), /*#__PURE__*/_react.default.createElement("p", {
104
104
  className: "p-notification__message"
105
105
  }, children), onDismiss && /*#__PURE__*/_react.default.createElement("button", {
106
+ type: "button",
106
107
  className: "p-notification__close",
107
108
  "data-testid": "notification-close-button",
108
109
  onClick: onDismiss
@@ -114,7 +115,8 @@ const Notification = _ref => {
114
115
  "data-testid": "notification-timestamp"
115
116
  }, timestamp), hasActions ? /*#__PURE__*/_react.default.createElement("div", {
116
117
  className: "p-notification__actions"
117
- }, actions.map((action, i) => /*#__PURE__*/_react.default.createElement(_Button.default, {
118
+ }, actions.map((action, i) => (0, _utils.isReactNode)(action) ? action : /*#__PURE__*/_react.default.createElement(_Button.default, {
119
+ type: "button",
118
120
  appearance: _Button.ButtonAppearance.LINK,
119
121
  className: "p-notification__action",
120
122
  "data-testid": "notification-action",
@@ -6,7 +6,7 @@ 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 _isEqual = _interopRequireDefault(require("lodash/isEqual"));
9
+ var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
10
10
  var _messageBuilder = require("./messageBuilder");
11
11
  var _Notification = _interopRequireWildcard(require("../Notification/Notification"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -30,7 +30,7 @@ const NotificationProvider = _ref => {
30
30
  const [notification, setNotification] = (0, _react.useState)(null);
31
31
  const clear = () => notification !== null && setNotification(null);
32
32
  const setDeduplicated = value => {
33
- if (!(0, _isEqual.default)(value, notification)) {
33
+ if (!(0, _fastDeepEqual.default)(value, notification)) {
34
34
  setNotification(value);
35
35
  }
36
36
  return value;
@@ -58,9 +58,6 @@ const SearchAndFilter = _ref => {
58
58
  mounted = false;
59
59
  };
60
60
  }, [searchData, returnSearchData]);
61
- const searchOnChange = searchTerm => {
62
- setSearchTerm(searchTerm);
63
- };
64
61
 
65
62
  // Hide manual input form field when search container is inactive
66
63
  (0, _react.useEffect)(() => {
@@ -242,7 +239,7 @@ const SearchAndFilter = _ref => {
242
239
  className: "p-search-and-filter__input",
243
240
  id: "search-and-filter-input",
244
241
  name: "search",
245
- onChange: e => searchOnChange(e.target.value),
242
+ onChange: e => setSearchTerm(e.target.value),
246
243
  placeholder: placeholder,
247
244
  type: "search",
248
245
  value: searchTerm
@@ -1,13 +1,14 @@
1
+ import { SearchAndFilterChip } from "./types";
1
2
  /**
2
3
  * Return number of overflowing chips given a row threshold
3
4
  * @param {array} chips - An array of chips
4
5
  * @param {Integer} overflowRowLimit - Number of rows to show before counting
5
6
  * overflow
6
7
  */
7
- export declare const overflowingChipsCount: (chips: any, overflowRowLimit: any) => number;
8
+ export declare const overflowingChipsCount: (chips: NodeListOf<HTMLElement>, overflowRowLimit: number) => number;
8
9
  /**
9
10
  * Check if supplied chip object already exists in searchData prop
10
11
  * @param {Object} chip - A chip object {lead: 'foo', value: 'bar'}
11
12
  * @param {Array} existingArr - An array of chip objects
12
13
  */
13
- export declare const isChipInArray: (chip: any, existingArr: any) => any;
14
+ export declare const isChipInArray: (chip: SearchAndFilterChip, existingArr: SearchAndFilterChip[]) => boolean;
@@ -59,7 +59,7 @@ const generateItems = (groups, listClassName, linkComponent, dark) => {
59
59
  };
60
60
  const getHasIcons = groups => groups === null || groups === void 0 ? void 0 : groups.some(group => {
61
61
  var _ref;
62
- return (_ref = group && "items" in group ? group.items : group) === null || _ref === void 0 ? void 0 : _ref.some(item => (0, _utils.isReactNode)(item) ? false : item && "icon" in item && !!item.icon);
62
+ return group && ((_ref = "items" in group ? group.items : group) === null || _ref === void 0 ? void 0 : _ref.some(item => (0, _utils.isReactNode)(item) ? false : item && "icon" in item && !!item.icon));
63
63
  });
64
64
 
65
65
  /**
@@ -204,7 +204,7 @@ const Tooltip = _ref => {
204
204
  return;
205
205
  }
206
206
  e.target.focus();
207
- openPortal(e);
207
+ openPortal();
208
208
  };
209
209
  const delayedOpenPortal = (0, _react.useCallback)(() => {
210
210
  if (isOpen) {
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { Meta } from "@storybook/react";
3
- import Card from "./";
3
+ import Card, { CardProps } from "./";
4
4
  declare const meta: Meta<typeof Card>;
5
5
  export default meta;
6
6
  export declare const Default: {
@@ -29,5 +29,5 @@ export declare const Overlay: {
29
29
  overlay: boolean;
30
30
  children: string;
31
31
  };
32
- render: (args: any) => React.JSX.Element;
32
+ render: (args: CardProps) => React.JSX.Element;
33
33
  };
@@ -97,13 +97,14 @@ export var WrapLines = {
97
97
  */
98
98
  export var Dropdown = {
99
99
  render: () => {
100
- // eslint-disable-next-line react-hooks/rules-of-hooks
101
- var [lang, setLang] = useState("html");
102
100
  var code = {
103
101
  js: "console.log(\"Example 1\");",
104
102
  css: ".p-heading--2 { color: red; }",
105
103
  html: "<h1 class=\"p-heading--2\">How to use code snippets</h1>"
106
104
  };
105
+
106
+ // eslint-disable-next-line react-hooks/rules-of-hooks
107
+ var [lang, setLang] = useState("html");
107
108
  return /*#__PURE__*/React.createElement(CodeSnippet, {
108
109
  blocks: [{
109
110
  code: code[lang],
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
2
  import { Meta, StoryObj } from "@storybook/react";
3
3
  import Col from "./Col";
4
- declare const Template: (args: any) => React.JSX.Element;
4
+ import { ColProps } from ".";
5
+ declare const Template: (args: ColProps) => React.JSX.Element;
5
6
  declare const meta: Meta<typeof Template>;
6
7
  export default meta;
7
8
  type Story = StoryObj<typeof Col>;
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { MouseEvent } from "react";
2
2
  import { PropsWithSpread, SubComponentProps } from "../../types";
3
3
  import { ActionButtonProps } from "../ActionButton";
4
4
  import { ConfirmationModalProps } from "../ConfirmationModal";
@@ -20,9 +20,14 @@ export type Props = PropsWithSpread<{
20
20
  * Whether to show a hint about the SHIFT+Click shortcut to skip the confirmation modal.
21
21
  */
22
22
  showShiftClickHint?: boolean;
23
+ /**
24
+ * A handler that determines whether the confirmation modal should be shown.
25
+ * If it returns `true`, the modal is shown. If it returns `false`, the modal is not shown.
26
+ */
27
+ preModalOpenHook?: (event: MouseEvent<HTMLButtonElement>) => boolean;
23
28
  }, ActionButtonProps>;
24
29
  /**
25
30
  * `ConfirmationButton` is a specialised version of the [ActionButton](?path=/docs/actionbutton--default-story) component that uses a [ConfirmationModal](?path=/docs/confirmationmodal--default-story) to prompt a confirmation from the user before executing an action.
26
31
  */
27
- export declare const ConfirmationButton: ({ confirmationModalProps, onHoverText, shiftClickEnabled, showShiftClickHint, ...actionButtonProps }: Props) => React.JSX.Element;
32
+ export declare const ConfirmationButton: ({ confirmationModalProps, onHoverText, shiftClickEnabled, showShiftClickHint, preModalOpenHook, ...actionButtonProps }: Props) => React.JSX.Element;
28
33
  export default ConfirmationButton;
@@ -1,4 +1,4 @@
1
- var _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint"];
1
+ var _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint", "preModalOpenHook"];
2
2
  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); }
3
3
  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; }
4
4
  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; }
@@ -23,7 +23,8 @@ export var ConfirmationButton = _ref => {
23
23
  confirmationModalProps,
24
24
  onHoverText,
25
25
  shiftClickEnabled = false,
26
- showShiftClickHint = false
26
+ showShiftClickHint = false,
27
+ preModalOpenHook
27
28
  } = _ref,
28
29
  actionButtonProps = _objectWithoutProperties(_ref, _excluded);
29
30
  var {
@@ -49,6 +50,13 @@ export var ConfirmationButton = _ref => {
49
50
  openPortal(e);
50
51
  }
51
52
  };
53
+ var handleClick = e => {
54
+ if (preModalOpenHook) {
55
+ var result = preModalOpenHook(e);
56
+ if (!result) return;
57
+ }
58
+ shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
59
+ };
52
60
  return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(ConfirmationModal, _extends({}, confirmationModalProps, {
53
61
  close: handleCancelModal,
54
62
  confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
@@ -56,7 +64,7 @@ export var ConfirmationButton = _ref => {
56
64
  }), confirmationModalProps.children, showShiftClickHint && /*#__PURE__*/React.createElement("p", {
57
65
  className: "p-text--small u-text--muted u-hide--small"
58
66
  }, "Next time, you can skip this confirmation by holding", " ", /*#__PURE__*/React.createElement("code", null, "SHIFT"), " and clicking the action."))), /*#__PURE__*/React.createElement(ActionButton, _extends({}, actionButtonProps, {
59
- onClick: shiftClickEnabled ? handleShiftClick : openPortal,
67
+ onClick: handleClick,
60
68
  title: generateTitle(onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel)
61
69
  }), actionButtonProps.children));
62
70
  };
@@ -7,3 +7,4 @@ type Story = StoryObj<typeof ConfirmationButton>;
7
7
  export declare const IconAndLabel: Story;
8
8
  export declare const IconOnly: Story;
9
9
  export declare const BaseAppearance: Story;
10
+ export declare const WithPreModalOpenHook: Story;