@canonical/react-components 2.0.0 → 2.2.0

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 (61) 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 +11 -3
  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 +5 -5
  9. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +1 -1
  10. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +2 -2
  11. package/dist/components/MainTable/MainTable.d.ts +3 -1
  12. package/dist/components/ModularTable/ModularTable.stories.js +2 -2
  13. package/dist/components/Navigation/Navigation.d.ts +1 -1
  14. package/dist/components/Notification/Notification.d.ts +1 -1
  15. package/dist/components/Notification/Notification.js +3 -1
  16. package/dist/components/NotificationProvider/NotificationProvider.js +2 -2
  17. package/dist/components/SearchAndFilter/SearchAndFilter.js +1 -4
  18. package/dist/components/SearchAndFilter/utils.d.ts +3 -2
  19. package/dist/components/SideNavigation/SideNavigation.js +1 -1
  20. package/dist/components/Tooltip/Tooltip.js +3 -3
  21. package/dist/esm/components/Card/Card.stories.d.ts +2 -2
  22. package/dist/esm/components/CodeSnippet/CodeSnippet.stories.js +3 -2
  23. package/dist/esm/components/Col/Col.stories.d.ts +2 -1
  24. package/dist/esm/components/ConfirmationButton/ConfirmationButton.d.ts +7 -2
  25. package/dist/esm/components/ConfirmationButton/ConfirmationButton.js +12 -4
  26. package/dist/esm/components/ConfirmationButton/ConfirmationButton.stories.d.ts +1 -0
  27. package/dist/esm/components/ConfirmationButton/ConfirmationButton.stories.js +22 -0
  28. package/dist/esm/components/ContextualMenu/ContextualMenu.js +4 -4
  29. package/dist/esm/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +1 -1
  30. package/dist/esm/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +2 -2
  31. package/dist/esm/components/MainTable/MainTable.d.ts +3 -1
  32. package/dist/esm/components/ModularTable/ModularTable.stories.js +60 -12
  33. package/dist/esm/components/Navigation/Navigation.d.ts +1 -1
  34. package/dist/esm/components/Notification/Notification.d.ts +1 -1
  35. package/dist/esm/components/Notification/Notification.js +4 -2
  36. package/dist/esm/components/NotificationProvider/NotificationProvider.js +2 -2
  37. package/dist/esm/components/SearchAndFilter/SearchAndFilter.js +1 -4
  38. package/dist/esm/components/SearchAndFilter/utils.d.ts +3 -2
  39. package/dist/esm/components/SideNavigation/SideNavigation.js +1 -1
  40. package/dist/esm/components/Tooltip/Tooltip.js +2 -2
  41. package/dist/esm/external/index.d.ts +2 -0
  42. package/dist/esm/external/index.js +1 -0
  43. package/dist/esm/external/usePortal.d.ts +39 -0
  44. package/dist/esm/external/usePortal.js +125 -0
  45. package/dist/esm/external/usePortal.test.d.ts +5 -0
  46. package/dist/esm/external/useSSR.d.ts +19 -0
  47. package/dist/esm/external/useSSR.js +43 -0
  48. package/dist/esm/hooks/useWindowFitment.js +2 -2
  49. package/dist/esm/index.d.ts +2 -0
  50. package/dist/esm/index.js +2 -1
  51. package/dist/external/index.d.ts +2 -0
  52. package/dist/external/index.js +12 -0
  53. package/dist/external/usePortal.d.ts +39 -0
  54. package/dist/external/usePortal.js +133 -0
  55. package/dist/external/usePortal.test.d.ts +5 -0
  56. package/dist/external/useSSR.d.ts +19 -0
  57. package/dist/external/useSSR.js +48 -0
  58. package/dist/hooks/useWindowFitment.js +2 -2
  59. package/dist/index.d.ts +2 -0
  60. package/dist/index.js +9 -1
  61. package/package.json +37 -39
@@ -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;
@@ -7,7 +7,7 @@ exports.default = exports.ConfirmationButton = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _ActionButton = _interopRequireDefault(require("../ActionButton"));
9
9
  var _ConfirmationModal = _interopRequireDefault(require("../ConfirmationModal"));
10
- var _reactUseportal = _interopRequireDefault(require("react-useportal"));
10
+ var _external = require("../../external");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  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); }
13
13
  const generateTitle = title => {
@@ -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 {
@@ -35,7 +36,7 @@ const ConfirmationButton = _ref => {
35
36
  closePortal,
36
37
  isOpen,
37
38
  Portal
38
- } = (0, _reactUseportal.default)();
39
+ } = (0, _external.usePortal)();
39
40
  const handleCancelModal = () => {
40
41
  closePortal();
41
42
  if (confirmationModalProps.close) {
@@ -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
  };
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = exports.Label = void 0;
7
7
  var _classnames = _interopRequireDefault(require("classnames"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactUseportal = _interopRequireDefault(require("react-useportal"));
10
9
  var _hooks = require("../../hooks");
11
10
  var _Button = _interopRequireDefault(require("../Button"));
12
11
  var _ContextualMenuDropdown = _interopRequireDefault(require("./ContextualMenuDropdown"));
12
+ var _external = require("../../external");
13
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -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]);
@@ -100,7 +100,7 @@ const ContextualMenu = _ref => {
100
100
  closePortal,
101
101
  isOpen,
102
102
  Portal
103
- } = (0, _reactUseportal.default)({
103
+ } = (0, _external.usePortal)({
104
104
  closeOnEsc,
105
105
  closeOnOutsideClick,
106
106
  isOpen: visible,
@@ -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.
@@ -18,7 +18,7 @@ export type Position = "left" | "center" | "right";
18
18
  export type Props<L = null> = {
19
19
  adjustedPosition?: Position;
20
20
  autoAdjust?: boolean;
21
- handleClose?: (evt?: MouseEvent) => void;
21
+ handleClose?: (evt?: React.MouseEvent<HTMLButtonElement>) => void;
22
22
  constrainPanelWidth?: boolean;
23
23
  dropdownClassName?: string;
24
24
  dropdownContent?: ReactNode | ((close: () => void) => React.JSX.Element);
@@ -164,11 +164,11 @@ const ContextualMenuDropdown = _ref => {
164
164
  const updateVerticalPosition = (0, _react.useCallback)(() => {
165
165
  var _dropdown$current$get;
166
166
  if (!positionNode) {
167
- return null;
167
+ return;
168
168
  }
169
169
  const scrollableParent = getClosestScrollableParent(positionNode);
170
170
  if (!scrollableParent) {
171
- return null;
171
+ return;
172
172
  }
173
173
  const scrollableParentRect = scrollableParent.getBoundingClientRect();
174
174
  const toggleRect = positionNode.getBoundingClientRect();
@@ -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.
@@ -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
  /**
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.position = exports.default = exports.adjustForWindow = void 0;
7
7
  var _classnames = _interopRequireDefault(require("classnames"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactUseportal = _interopRequireDefault(require("react-useportal"));
10
9
  var _hooks = require("../../hooks");
10
+ var _external = require("../../external");
11
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -142,7 +142,7 @@ const Tooltip = _ref => {
142
142
  closePortal,
143
143
  isOpen,
144
144
  Portal
145
- } = (0, _reactUseportal.default)({
145
+ } = (0, _external.usePortal)({
146
146
  programmaticallyOpen: true
147
147
  });
148
148
  const tooltipId = (0, _react.useId)();
@@ -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,11 +1,11 @@
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; }
5
5
  import React from "react";
6
6
  import ActionButton from "../ActionButton";
7
7
  import ConfirmationModal from "../ConfirmationModal";
8
- import usePortal from "react-useportal";
8
+ import { usePortal } from "../../external";
9
9
  var generateTitle = title => {
10
10
  if (typeof title === "string") {
11
11
  return title;
@@ -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;
@@ -97,4 +97,26 @@ export var BaseAppearance = {
97
97
  }));
98
98
  },
99
99
  name: "Base appearance"
100
+ };
101
+ export var WithPreModalOpenHook = {
102
+ render: () => {
103
+ var dontOpenModal = () => false;
104
+ var openModal = () => true;
105
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ConfirmationButton, {
106
+ preModalOpenHook: dontOpenModal,
107
+ confirmationModalProps: {
108
+ title: "Confirm delete",
109
+ confirmButtonLabel: "Delete",
110
+ children: /*#__PURE__*/React.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/React.createElement("br", null), "You cannot undo this action.")
111
+ }
112
+ }, "Don't open modal"), /*#__PURE__*/React.createElement(ConfirmationButton, {
113
+ preModalOpenHook: openModal,
114
+ confirmationModalProps: {
115
+ title: "Confirm delete",
116
+ confirmButtonLabel: "Delete",
117
+ children: /*#__PURE__*/React.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/React.createElement("br", null), "You cannot undo this action.")
118
+ }
119
+ }, "Open modal"));
120
+ },
121
+ name: "With preModalOpenHook handler"
100
122
  };
@@ -4,10 +4,10 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
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; }
5
5
  import classNames from "classnames";
6
6
  import React, { useCallback, useEffect, useId, useRef, useState } from "react";
7
- import usePortal from "react-useportal";
8
7
  import { useListener, usePrevious } from "../../hooks";
9
8
  import Button from "../Button";
10
9
  import ContextualMenuDropdown from "./ContextualMenuDropdown";
10
+ import { usePortal } from "../../external";
11
11
  export var Label = /*#__PURE__*/function (Label) {
12
12
  Label["Toggle"] = "Toggle menu";
13
13
  return Label;
@@ -87,7 +87,7 @@ var ContextualMenu = _ref => {
87
87
  var updatePositionCoords = useCallback(() => {
88
88
  var parent = getPositionNode(wrapper.current, positionNode);
89
89
  if (!parent) {
90
- return null;
90
+ return;
91
91
  }
92
92
  setPositionCoords(parent.getBoundingClientRect());
93
93
  }, [wrapper, positionNode]);
@@ -139,13 +139,13 @@ var ContextualMenu = _ref => {
139
139
  }
140
140
  }
141
141
  }, [closePortal, openPortal, visible, isOpen, previousVisible]);
142
- var onResize = useCallback(evt => {
142
+ var onResize = useCallback(() => {
143
143
  var parent = getPositionNode(wrapper.current, positionNode);
144
144
  if (parent && !getPositionNodeVisible(parent)) {
145
145
  // Hide the menu if the item has become hidden. This might happen in
146
146
  // a responsive table when columns become hidden as the page
147
147
  // becomes smaller.
148
- closePortal(evt);
148
+ closePortal();
149
149
  } else {
150
150
  // Update the coordinates so that the menu stays relative to the
151
151
  // toggle button.
@@ -18,7 +18,7 @@ export type Position = "left" | "center" | "right";
18
18
  export type Props<L = null> = {
19
19
  adjustedPosition?: Position;
20
20
  autoAdjust?: boolean;
21
- handleClose?: (evt?: MouseEvent) => void;
21
+ handleClose?: (evt?: React.MouseEvent<HTMLButtonElement>) => void;
22
22
  constrainPanelWidth?: boolean;
23
23
  dropdownClassName?: string;
24
24
  dropdownContent?: ReactNode | ((close: () => void) => React.JSX.Element);
@@ -164,11 +164,11 @@ var ContextualMenuDropdown = _ref => {
164
164
  var updateVerticalPosition = useCallback(() => {
165
165
  var _dropdown$current$get;
166
166
  if (!positionNode) {
167
- return null;
167
+ return;
168
168
  }
169
169
  var scrollableParent = getClosestScrollableParent(positionNode);
170
170
  if (!scrollableParent) {
171
- return null;
171
+ return;
172
172
  }
173
173
  var scrollableParentRect = scrollableParent.getBoundingClientRect();
174
174
  var toggleRect = positionNode.getBoundingClientRect();
@@ -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.