carbon-react 120.3.0 → 120.4.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 (43) hide show
  1. package/esm/components/flat-table/__internal__/index.d.ts +1 -1
  2. package/esm/components/flat-table/__internal__/index.js +1 -1
  3. package/esm/components/flat-table/__internal__/{use-calculate-sticky-cells.d.ts → use-table-cell.d.ts} +3 -0
  4. package/esm/components/flat-table/__internal__/{use-calculate-sticky-cells.js → use-table-cell.js} +21 -3
  5. package/esm/components/flat-table/flat-table-cell/flat-table-cell.component.js +10 -14
  6. package/esm/components/flat-table/flat-table-header/flat-table-header.component.js +2 -2
  7. package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +2 -0
  8. package/esm/components/flat-table/flat-table-row/flat-table-row.component.js +9 -11
  9. package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +10 -12
  10. package/esm/components/flat-table/flat-table.component.d.ts +1 -2
  11. package/esm/components/flat-table/flat-table.component.js +9 -29
  12. package/esm/components/message/message.component.d.ts +1 -1
  13. package/esm/components/message/message.component.js +1 -1
  14. package/esm/components/message/message.style.js +3 -2
  15. package/esm/components/message/type-icon/type-icon.component.js +6 -1
  16. package/esm/components/message/type-icon/type-icon.style.js +4 -2
  17. package/esm/components/toast/toast.component.d.ts +4 -1
  18. package/esm/components/toast/toast.component.js +27 -5
  19. package/esm/components/toast/toast.config.js +1 -1
  20. package/esm/components/toast/toast.style.d.ts +4 -0
  21. package/esm/components/toast/toast.style.js +36 -3
  22. package/lib/components/flat-table/__internal__/index.d.ts +1 -1
  23. package/lib/components/flat-table/__internal__/index.js +3 -3
  24. package/lib/components/flat-table/__internal__/{use-calculate-sticky-cells.d.ts → use-table-cell.d.ts} +3 -0
  25. package/lib/components/flat-table/__internal__/{use-calculate-sticky-cells.js → use-table-cell.js} +20 -2
  26. package/lib/components/flat-table/flat-table-cell/flat-table-cell.component.js +9 -13
  27. package/lib/components/flat-table/flat-table-header/flat-table-header.component.js +2 -2
  28. package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +2 -0
  29. package/lib/components/flat-table/flat-table-row/flat-table-row.component.js +9 -11
  30. package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +9 -11
  31. package/lib/components/flat-table/flat-table.component.d.ts +1 -2
  32. package/lib/components/flat-table/flat-table.component.js +9 -29
  33. package/lib/components/message/message.component.d.ts +1 -1
  34. package/lib/components/message/message.component.js +1 -1
  35. package/lib/components/message/message.style.js +3 -2
  36. package/lib/components/message/type-icon/type-icon.component.js +6 -1
  37. package/lib/components/message/type-icon/type-icon.style.js +4 -2
  38. package/lib/components/toast/toast.component.d.ts +4 -1
  39. package/lib/components/toast/toast.component.js +27 -5
  40. package/lib/components/toast/toast.config.js +1 -1
  41. package/lib/components/toast/toast.style.d.ts +4 -0
  42. package/lib/components/toast/toast.style.js +36 -3
  43. package/package.json +1 -1
@@ -6,8 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
8
  var _flatTableRowContext = _interopRequireDefault(require("../flat-table-row/__internal__/flat-table-row-context"));
9
+ var _flatTable = require("../flat-table.component");
9
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
11
  var _default = id => {
12
+ const {
13
+ getTabStopElementId
14
+ } = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
15
+ const [tabIndex, setTabIndex] = (0, _react.useState)(-1);
11
16
  const {
12
17
  expandable,
13
18
  firstCellId,
@@ -15,13 +20,23 @@ var _default = id => {
15
20
  leftPositions,
16
21
  rightPositions,
17
22
  onClick,
18
- onKeyDown
23
+ onKeyDown,
24
+ highlighted,
25
+ selected
19
26
  } = (0, _react.useContext)(_flatTableRowContext.default);
20
27
  const leftPosition = leftPositions[id];
21
28
  const rightPosition = rightPositions[id];
22
29
  const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
23
30
  const isFirstCell = id === firstCellId;
24
31
  const isExpandableCell = expandable && isFirstCell && firstColumnExpandable;
32
+ (0, _react.useEffect)(() => {
33
+ const tabstopTimer = setTimeout(() => {
34
+ setTabIndex(isExpandableCell && getTabStopElementId() === id ? 0 : -1);
35
+ }, 0);
36
+ return () => {
37
+ clearTimeout(tabstopTimer);
38
+ };
39
+ }, [getTabStopElementId, isExpandableCell, id]);
25
40
  return {
26
41
  expandable,
27
42
  leftPosition,
@@ -30,7 +45,10 @@ var _default = id => {
30
45
  onClick,
31
46
  onKeyDown,
32
47
  isFirstCell,
33
- isExpandableCell
48
+ isExpandableCell,
49
+ tabIndex,
50
+ isInHighlightedRow: highlighted,
51
+ isInSelectedRow: selected
34
52
  };
35
53
  };
36
54
  exports.default = _default;
@@ -8,9 +8,8 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _flatTableCell = require("./flat-table-cell.style");
10
10
  var _icon = _interopRequireDefault(require("../../icon"));
11
- var _flatTable = require("../flat-table.component");
12
11
  var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
13
- var _useCalculateStickyCells = _interopRequireDefault(require("../__internal__/use-calculate-sticky-cells"));
12
+ var _useTableCell = _interopRequireDefault(require("../__internal__/use-table-cell"));
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
15
  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; }
@@ -27,12 +26,7 @@ const FlatTableCell = ({
27
26
  id,
28
27
  ...rest
29
28
  }) => {
30
- const ref = (0, _react.useRef)(null);
31
29
  const internalId = (0, _react.useRef)(id || (0, _guid.default)());
32
- const [tabIndex, setTabIndex] = (0, _react.useState)(-1);
33
- const {
34
- selectedId
35
- } = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
36
30
  const {
37
31
  leftPosition,
38
32
  rightPosition,
@@ -41,17 +35,16 @@ const FlatTableCell = ({
41
35
  onKeyDown,
42
36
  isFirstCell,
43
37
  isExpandableCell,
44
- makeCellSticky
45
- } = (0, _useCalculateStickyCells.default)(internalId.current);
46
- (0, _react.useEffect)(() => {
47
- setTabIndex(isExpandableCell && selectedId === internalId.current ? 0 : -1);
48
- }, [selectedId, isExpandableCell]);
38
+ makeCellSticky,
39
+ isInHighlightedRow,
40
+ isInSelectedRow,
41
+ tabIndex
42
+ } = (0, _useTableCell.default)(internalId.current);
49
43
  return /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledFlatTableCell, _extends({
50
44
  leftPosition: leftPosition,
51
45
  rightPosition: rightPosition,
52
46
  makeCellSticky: makeCellSticky,
53
47
  className: makeCellSticky ? "isSticky" : undefined,
54
- ref: ref,
55
48
  align: align,
56
49
  "data-element": "flat-table-cell",
57
50
  pl: pl,
@@ -65,6 +58,9 @@ const FlatTableCell = ({
65
58
  colSpan: Number(colspan)
66
59
  }, rowspan !== undefined && {
67
60
  rowSpan: Number(rowspan)
61
+ }, {
62
+ "data-selected": isInSelectedRow && isExpandableCell,
63
+ "data-highlighted": isInHighlightedRow && isExpandableCell
68
64
  }, rest, {
69
65
  id: internalId.current
70
66
  }), /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledCellContent, {
@@ -9,7 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _flatTableHeader = _interopRequireDefault(require("./flat-table-header.style"));
10
10
  var _flatTable = require("../flat-table.component");
11
11
  var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
12
- var _useCalculateStickyCells = _interopRequireDefault(require("../__internal__/use-calculate-sticky-cells"));
12
+ var _useTableCell = _interopRequireDefault(require("../__internal__/use-table-cell"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
  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; }
@@ -34,7 +34,7 @@ const FlatTableHeader = ({
34
34
  leftPosition,
35
35
  rightPosition,
36
36
  makeCellSticky
37
- } = (0, _useCalculateStickyCells.default)(internalId.current);
37
+ } = (0, _useTableCell.default)(internalId.current);
38
38
  return /*#__PURE__*/_react.default.createElement(_flatTableHeader.default, _extends({
39
39
  ref: ref,
40
40
  leftPosition: leftPosition,
@@ -7,6 +7,8 @@ export interface FlatTableRowContextProps {
7
7
  leftPositions: Record<string, number>;
8
8
  rightPositions: Record<string, number>;
9
9
  firstColumnExpandable?: boolean;
10
+ highlighted?: boolean;
11
+ selected?: boolean;
10
12
  }
11
13
  declare const _default: React.Context<FlatTableRowContextProps>;
12
14
  export default _default;
@@ -102,8 +102,7 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
102
102
  const {
103
103
  colorTheme,
104
104
  size,
105
- setSelectedId,
106
- selectedId
105
+ getTabStopElementId
107
106
  } = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
108
107
  const {
109
108
  isInSidebar
@@ -150,13 +149,8 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
150
149
  setIsExpanded(expanded);
151
150
  }, [expanded]);
152
151
  (0, _react.useEffect)(() => {
153
- if (highlighted || selected) {
154
- setSelectedId(internalId.current);
155
- }
156
- }, [highlighted, selected, setSelectedId]);
157
- (0, _react.useEffect)(() => {
158
- setTabIndex(selectedId === internalId.current ? 0 : -1);
159
- }, [selectedId]);
152
+ setTabIndex(getTabStopElementId() === internalId.current ? 0 : -1);
153
+ }, [getTabStopElementId]);
160
154
  const {
161
155
  isSubRow,
162
156
  firstRowId,
@@ -192,7 +186,9 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
192
186
  horizontalBorderSize: horizontalBorderSize,
193
187
  draggable: draggable,
194
188
  totalChildren: cellsArray.length,
195
- id: internalId.current
189
+ id: internalId.current,
190
+ "data-selected": selected && expandableArea === "wholeRow",
191
+ "data-highlighted": highlighted && expandableArea === "wholeRow"
196
192
  }, interactiveRowProps, rest), /*#__PURE__*/_react.default.createElement(_flatTableRowContext.default.Provider, {
197
193
  value: {
198
194
  firstCellId,
@@ -201,7 +197,9 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
201
197
  rightPositions,
202
198
  firstColumnExpandable,
203
199
  onKeyDown: handleCellKeyDown,
204
- onClick: () => toggleExpanded()
200
+ onClick: () => toggleExpanded(),
201
+ highlighted,
202
+ selected
205
203
  }
206
204
  }, children));
207
205
  const draggableComponent = () => /*#__PURE__*/_react.default.createElement(_flatTableRowDraggable.default, {
@@ -8,10 +8,9 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _icon = _interopRequireDefault(require("../../icon"));
10
10
  var _flatTableRowHeader = require("./flat-table-row-header.style");
11
- var _flatTable = require("../flat-table.component");
12
11
  var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
13
12
  var _tags = _interopRequireDefault(require("../../../__internal__/utils/helpers/tags/tags"));
14
- var _useCalculateStickyCells = _interopRequireDefault(require("../__internal__/use-calculate-sticky-cells"));
13
+ var _useTableCell = _interopRequireDefault(require("../__internal__/use-table-cell"));
15
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
16
  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; }
@@ -31,10 +30,6 @@ const FlatTableRowHeader = ({
31
30
  ...rest
32
31
  }) => {
33
32
  const internalId = (0, _react.useRef)(id || (0, _guid.default)());
34
- const [tabIndex, setTabIndex] = (0, _react.useState)(-1);
35
- const {
36
- selectedId
37
- } = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
38
33
  const {
39
34
  leftPosition,
40
35
  rightPosition,
@@ -42,11 +37,11 @@ const FlatTableRowHeader = ({
42
37
  onClick,
43
38
  onKeyDown,
44
39
  isFirstCell,
45
- isExpandableCell
46
- } = (0, _useCalculateStickyCells.default)(internalId.current);
47
- (0, _react.useEffect)(() => {
48
- setTabIndex(isExpandableCell && selectedId === internalId.current ? 0 : -1);
49
- }, [selectedId, isExpandableCell]);
40
+ isExpandableCell,
41
+ tabIndex,
42
+ isInHighlightedRow,
43
+ isInSelectedRow
44
+ } = (0, _useTableCell.default)(internalId.current);
50
45
  const handleOnClick = (0, _react.useCallback)(ev => {
51
46
  if (isExpandableCell && onClick) onClick(ev);
52
47
  }, [isExpandableCell, onClick]);
@@ -76,6 +71,9 @@ const FlatTableRowHeader = ({
76
71
  colSpan: Number(colspan)
77
72
  }, rowspan !== undefined && {
78
73
  rowSpan: Number(rowspan)
74
+ }, {
75
+ "data-selected": isInSelectedRow && isExpandableCell,
76
+ "data-highlighted": isInHighlightedRow && isExpandableCell
79
77
  }, rest, {
80
78
  id: internalId.current
81
79
  }), /*#__PURE__*/_react.default.createElement(_flatTableRowHeader.StyledFlatTableRowHeaderContent, {
@@ -31,8 +31,7 @@ export interface FlatTableProps extends MarginProps {
31
31
  width?: string;
32
32
  }
33
33
  export interface FlatTableThemeContextProps extends Pick<FlatTableProps, "colorTheme" | "size"> {
34
- selectedId?: string;
35
- setSelectedId: (id: string) => void;
34
+ getTabStopElementId: () => string;
36
35
  }
37
36
  export declare const FlatTableThemeContext: React.Context<FlatTableThemeContextProps>;
38
37
  export declare const FlatTable: {
@@ -14,7 +14,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
14
14
  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; }
15
15
  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); }
16
16
  const FlatTableThemeContext = /*#__PURE__*/_react.default.createContext({
17
- setSelectedId: () => {}
17
+ getTabStopElementId: () => ""
18
18
  });
19
19
  exports.FlatTableThemeContext = FlatTableThemeContext;
20
20
  const FOCUSABLE_ROW_AND_CELL_QUERY = "tbody tr[tabindex], tbody tr td[tabindex], tbody tr th[tabindex]";
@@ -41,7 +41,6 @@ const FlatTable = ({
41
41
  const [hasHorizontalScrollbar, setHasHorizontalScrollbar] = (0, _react.useState)(false);
42
42
  const [firstColRowSpanIndex, setFirstColRowSpanIndex] = (0, _react.useState)(-1);
43
43
  const [lastColRowSpanIndex, setLastColRowSpanIndex] = (0, _react.useState)(-1);
44
- const [selectedId, setSelectedId] = (0, _react.useState)("");
45
44
  const addDefaultHeight = !height && (hasStickyHead || hasStickyFooter);
46
45
  const tableStylingProps = {
47
46
  caption,
@@ -134,32 +133,14 @@ const FlatTable = ({
134
133
  }
135
134
  }
136
135
  };
137
- (0, _react.useLayoutEffect)(() => {
138
- const findSelectedId = () => {
139
- const firstfocusableElement = tableRef.current?.querySelector(FOCUSABLE_ROW_AND_CELL_QUERY);
140
-
141
- // if no other menu item is selected, we need to make the first row a tab stop
142
- if (firstfocusableElement && !selectedId) {
143
- const currentlySelectedId = firstfocusableElement?.getAttribute("id");
144
-
145
- /* istanbul ignore else */
146
- if (currentlySelectedId && selectedId !== currentlySelectedId) {
147
- setSelectedId(currentlySelectedId);
148
- }
149
- }
150
- };
151
- const observer = new MutationObserver(findSelectedId);
136
+ const getTabStopElementId = () => {
137
+ const focusableElements = Array.from(tableRef.current?.querySelectorAll(FOCUSABLE_ROW_AND_CELL_QUERY) || /* istanbul ignore next */[]);
152
138
 
153
- /* istanbul ignore else */
154
- if (wrapperRef.current) {
155
- observer.observe(wrapperRef.current, {
156
- subtree: true,
157
- childList: true,
158
- attributes: true
159
- });
160
- }
161
- return () => observer.disconnect();
162
- }, [selectedId]);
139
+ // if no other row is selected/ highlighted, we need to make the first row/ cell a tab stop
140
+ const focusableElement = focusableElements.find(el => el.getAttribute("data-selected") === "true" || el.getAttribute("data-highlighted") === "true") || focusableElements[0];
141
+ const currentlySelectedId = focusableElement?.getAttribute("id") || "";
142
+ return currentlySelectedId;
143
+ };
163
144
  return /*#__PURE__*/_react.default.createElement(_flatTable.StyledFlatTableWrapper, _extends({
164
145
  ref: wrapperRef,
165
146
  "data-component": "flat-table-wrapper",
@@ -194,8 +175,7 @@ const FlatTable = ({
194
175
  value: {
195
176
  colorTheme,
196
177
  size,
197
- setSelectedId,
198
- selectedId
178
+ getTabStopElementId
199
179
  }
200
180
  }, children))), footer && /*#__PURE__*/_react.default.createElement(_flatTable.StyledFlatTableFooter, {
201
181
  hasStickyFooter: hasStickyFooter
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { MarginProps } from "styled-system";
3
- export declare type MessageVariant = "error" | "info" | "success" | "warning";
3
+ export declare type MessageVariant = "error" | "info" | "success" | "warning" | "neutral";
4
4
  export interface MessageProps extends MarginProps {
5
5
  /** set content to component */
6
6
  children?: React.ReactNode;
@@ -227,7 +227,7 @@ Message.propTypes = {
227
227
  "showCloseIcon": _propTypes.default.bool,
228
228
  "title": _propTypes.default.node,
229
229
  "transparent": _propTypes.default.bool,
230
- "variant": _propTypes.default.oneOf(["error", "info", "success", "warning"])
230
+ "variant": _propTypes.default.oneOf(["error", "info", "neutral", "success", "warning"])
231
231
  };
232
232
  Message.displayName = "Message";
233
233
  var _default = Message;
@@ -13,9 +13,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
13
13
  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; }
14
14
  const messageVariants = {
15
15
  error: "var(--colorsSemanticNegative500)",
16
- info: "var(--colorsSemanticNeutral500)",
16
+ info: "var(--colorsSemanticInfo500)",
17
17
  success: "var(--colorsSemanticPositive500)",
18
- warning: "var(--colorsSemanticCaution500)"
18
+ warning: "var(--colorsSemanticCaution500)",
19
+ neutral: "var(--colorsSemanticNeutral500)"
19
20
  };
20
21
  const MessageStyle = _styledComponents.default.div`
21
22
  position: relative;
@@ -13,11 +13,16 @@ const TypeIcon = ({
13
13
  variant = "info",
14
14
  transparent = false
15
15
  }) => {
16
+ function iconToRender() {
17
+ if (variant === "neutral") return "info";
18
+ if (variant === "success") return "tick_circle";
19
+ return variant;
20
+ }
16
21
  return /*#__PURE__*/_react.default.createElement(_typeIcon.default, {
17
22
  variant: variant,
18
23
  transparent: transparent
19
24
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
20
- type: variant
25
+ type: iconToRender()
21
26
  }));
22
27
  };
23
28
  var _default = TypeIcon;
@@ -9,9 +9,11 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
9
9
  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; }
10
10
  const messageVariants = {
11
11
  error: "var(--colorsSemanticNegative500)",
12
- info: "var(--colorsSemanticNeutral500)",
12
+ info: "var(--colorsSemanticInfo500)",
13
13
  success: "var(--colorsSemanticPositive500)",
14
- warning: "var(--colorsSemanticCaution500)"
14
+ warning: "var(--colorsSemanticCaution500)",
15
+ neutral: "var(--colorsSemanticNeutral500)",
16
+ notification: "var(--colorsSemanticInfo500)"
15
17
  };
16
18
  const TypeIconStyle = _styledComponents.default.div`
17
19
  align-items: center;
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
- declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice";
2
+ declare type ToastVariants = "error" | "info" | "success" | "warning" | "notice" | "neutral" | "notification";
3
+ declare type AlignOptions = "left" | "center" | "right";
3
4
  export interface ToastProps {
5
+ /** Sets the alignment of the component. */
6
+ align?: AlignOptions;
4
7
  /** The rendered children of the component. */
5
8
  children: React.ReactNode;
6
9
  /** Customizes the appearance in the DLS theme */
@@ -14,11 +14,14 @@ var _iconButton = _interopRequireDefault(require("../icon-button"));
14
14
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
15
15
  var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
16
16
  var _useModalManager = _interopRequireDefault(require("../../hooks/__internal__/useModalManager"));
17
+ var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
20
  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; }
20
21
  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); }
22
+ let isDeprecationWarningTriggered = false;
21
23
  const Toast = /*#__PURE__*/_react.default.forwardRef(({
24
+ align,
22
25
  children,
23
26
  className,
24
27
  id,
@@ -33,6 +36,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
33
36
  ...restProps
34
37
  }, ref) => {
35
38
  const isNotice = variant === "notice";
39
+ const isNotification = variant === "notification";
36
40
  const locale = (0, _useLocale.default)();
37
41
  const toastRef = (0, _react.useRef)(null);
38
42
  const timer = (0, _react.useRef)(null);
@@ -44,6 +48,10 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
44
48
  if (ref && typeof ref === "object" && "current" in ref) {
45
49
  refToPass = ref;
46
50
  }
51
+ if (isCenter !== undefined && !isDeprecationWarningTriggered) {
52
+ isDeprecationWarningTriggered = true;
53
+ _logger.default.deprecate(`isCenter prop in ${Toast.displayName} is being deprecated in favour of the align prop.`);
54
+ }
47
55
  const dismissToast = (0, _react.useCallback)(ev => {
48
56
  if (onDismiss && _events.default.isEscKey(ev)) {
49
57
  ev.stopImmediatePropagation();
@@ -96,10 +104,19 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
96
104
  type: "close"
97
105
  }));
98
106
  }
107
+ const iconToRender = {
108
+ notification: "alert",
109
+ neutral: "info",
110
+ success: "tick_circle",
111
+ error: "error",
112
+ info: "info",
113
+ warning: "warning"
114
+ };
115
+ const toastIcon = iconToRender[variant] || "none";
99
116
  function renderToastContent() {
100
117
  if (!open) return null;
101
118
  let toastVariant;
102
- if (variant !== "notice") {
119
+ if (!isNotice && !isNotification) {
103
120
  toastVariant = variant;
104
121
  }
105
122
  return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
@@ -112,7 +129,9 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
112
129
  },
113
130
  nodeRef: toastContentNodeRef
114
131
  }, /*#__PURE__*/_react.default.createElement(_toast.ToastStyle, _extends({
132
+ align: align,
115
133
  isNotice: isNotice,
134
+ isNotification: isNotification,
116
135
  className: className
117
136
  }, (0, _tags.default)(restProps["data-component"] || "toast", restProps), {
118
137
  isCenter: isCenter,
@@ -123,10 +142,10 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
123
142
  }, !disableAutoFocus && {
124
143
  tabIndex,
125
144
  onBlur: () => setTabIndex(undefined)
126
- }), variant !== "notice" && /*#__PURE__*/_react.default.createElement(_toast.TypeIcon, {
127
- variant: variant
145
+ }), !isNotice && /*#__PURE__*/_react.default.createElement(_toast.TypeIcon, {
146
+ variant: isNotification ? "info" : variant
128
147
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
129
- type: variant
148
+ type: toastIcon
130
149
  })), /*#__PURE__*/_react.default.createElement(_toast.ToastContentStyle, {
131
150
  isNotice: isNotice,
132
151
  isDismiss: !!onDismiss
@@ -134,9 +153,11 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
134
153
  }
135
154
  return /*#__PURE__*/_react.default.createElement(_toast.StyledPortal, {
136
155
  id: targetPortalId,
156
+ align: align,
137
157
  isCenter: isCenter,
138
158
  isNotice: isNotice
139
159
  }, /*#__PURE__*/_react.default.createElement(_toast.ToastWrapper, {
160
+ align: align,
140
161
  isCenter: isCenter,
141
162
  ref: refToPass,
142
163
  isNotice: isNotice
@@ -144,6 +165,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
144
165
  });
145
166
  exports.Toast = Toast;
146
167
  Toast.propTypes = {
168
+ "align": _propTypes.default.oneOf(["center", "left", "right"]),
147
169
  "children": _propTypes.default.node,
148
170
  "className": _propTypes.default.string,
149
171
  "data-component": _propTypes.default.string,
@@ -155,7 +177,7 @@ Toast.propTypes = {
155
177
  "open": _propTypes.default.bool,
156
178
  "targetPortalId": _propTypes.default.string,
157
179
  "timeout": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
158
- "variant": _propTypes.default.oneOf(["error", "info", "notice", "success", "warning"])
180
+ "variant": _propTypes.default.oneOf(["error", "info", "neutral", "notice", "notification", "success", "warning"])
159
181
  };
160
182
  Toast.displayName = "Toast";
161
183
  var _default = Toast;
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.TOAST_COLORS = void 0;
7
7
  // eslint-disable-next-line import/prefer-default-export
8
- const TOAST_COLORS = ["error", "info", "success", "warning"];
8
+ const TOAST_COLORS = ["error", "info", "success", "warning", "neutral", "notification"];
9
9
  exports.TOAST_COLORS = TOAST_COLORS;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import TypeIcon from "../message/type-icon/type-icon.style";
3
3
  declare const StyledPortal: import("styled-components").StyledComponent<({ children, className, id, onReposition }: import("../portal/portal").PortalProps) => import("react").JSX.Element, any, {
4
+ align?: "left" | "right" | "center" | undefined;
4
5
  isCenter?: boolean | undefined;
5
6
  isNotice?: boolean | undefined;
6
7
  }, never>;
@@ -8,15 +9,18 @@ declare const ToastStyle: import("styled-components").StyledComponent<"div", any
8
9
  variant?: import("../message/message.component").MessageVariant | undefined;
9
10
  transparent?: boolean | undefined;
10
11
  } & import("styled-system").MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
12
+ align?: "left" | "right" | "center" | undefined;
11
13
  maxWidth?: string | undefined;
12
14
  isCenter?: boolean | undefined;
13
15
  isNotice?: boolean | undefined;
16
+ isNotification?: boolean | undefined;
14
17
  }, never>;
15
18
  declare const ToastContentStyle: import("styled-components").StyledComponent<"div", any, Pick<import("../message/message-content/message-content.component").MessageContentProps, "showCloseIcon"> & {
16
19
  isNotice?: boolean | undefined;
17
20
  isDismiss?: boolean | undefined;
18
21
  }, never>;
19
22
  declare const ToastWrapper: import("styled-components").StyledComponent<"div", any, {
23
+ align?: "left" | "right" | "center" | undefined;
20
24
  isCenter?: boolean | undefined;
21
25
  isNotice?: boolean | undefined;
22
26
  }, never>;
@@ -25,7 +25,8 @@ const StyledPortal = (0, _styledComponents.default)(_portal.default)`
25
25
  ${({
26
26
  theme,
27
27
  isCenter,
28
- isNotice
28
+ isNotice,
29
+ align
29
30
  }) => (0, _styledComponents.css)`
30
31
  position: fixed;
31
32
  top: 0;
@@ -37,6 +38,22 @@ const StyledPortal = (0, _styledComponents.default)(_portal.default)`
37
38
  transform: translateX(-50%);
38
39
  `}
39
40
 
41
+ ${align === "left" && (0, _styledComponents.css)`
42
+ left: 12%;
43
+ transform: translateX(-50%);
44
+ `}
45
+
46
+ ${align === "center" && (0, _styledComponents.css)`
47
+ margin-left: 50%;
48
+ transform: translateX(-50%);
49
+ `}
50
+
51
+ ${align === "right" && (0, _styledComponents.css)`
52
+ display: flex;
53
+ right: 0;
54
+ transform: translateX(-50%);
55
+ `}
56
+
40
57
  ${isNotice && (0, _styledComponents.css)`
41
58
  bottom: 0;
42
59
  top: auto;
@@ -53,7 +70,9 @@ const alternativeAnimationName = ".toast-alternative";
53
70
  const ToastStyle = (0, _styledComponents.default)(_message.default)`
54
71
  ${({
55
72
  maxWidth,
56
- isCenter
73
+ isCenter,
74
+ align,
75
+ isNotification
57
76
  }) => (0, _styledComponents.css)`
58
77
  box-shadow: 0 10px 30px 0 rgba(0, 20, 29, 0.1),
59
78
  0 30px 60px 0 rgba(0, 20, 29, 0.1);
@@ -61,7 +80,11 @@ const ToastStyle = (0, _styledComponents.default)(_message.default)`
61
80
  margin-top: 30px;
62
81
  max-width: ${!maxWidth ? "300px" : maxWidth};
63
82
  position: relative;
64
- margin-right: ${isCenter ? "auto" : "30px"};
83
+ margin-right: ${isCenter || align === "right" ? "auto" : "30px"};
84
+
85
+ ${isNotification && (0, _styledComponents.css)`
86
+ border: 1px solid var(--colorsSemanticInfo500);
87
+ `}
65
88
  `}
66
89
 
67
90
  :focus {
@@ -157,6 +180,16 @@ const ToastContentStyle = (0, _styledComponents.default)(_messageContent.default
157
180
  `;
158
181
  exports.ToastContentStyle = ToastContentStyle;
159
182
  const ToastWrapper = _styledComponents.default.div`
183
+ ${({
184
+ align
185
+ }) => align && (0, _styledComponents.css)`
186
+ position: relative;
187
+ width: auto;
188
+ height: auto;
189
+ justify-content: ${align};
190
+ display: flex;
191
+ `}
192
+
160
193
  ${({
161
194
  isCenter
162
195
  }) => isCenter && (0, _styledComponents.css)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "120.3.0",
3
+ "version": "120.4.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",