carbon-react 119.12.2 → 120.1.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 (120) hide show
  1. package/esm/__internal__/input/input-presentation.style.d.ts +1 -1
  2. package/esm/__spec_helper__/test-utils.d.ts +3 -2
  3. package/esm/__spec_helper__/test-utils.js +15 -1
  4. package/esm/components/box/box.component.d.ts +23 -6
  5. package/esm/components/box/box.component.js +3570 -103
  6. package/esm/components/box/box.style.d.ts +3 -0
  7. package/esm/components/box/box.style.js +112 -0
  8. package/esm/components/dismissible-box/dismissible-box.style.d.ts +2 -1
  9. package/esm/components/drawer/drawer.style.d.ts +2 -1
  10. package/esm/components/duelling-picklist/picklist/picklist.style.js +4 -2
  11. package/esm/components/flat-table/__internal__/build-position-map.d.ts +2 -0
  12. package/esm/components/flat-table/__internal__/build-position-map.js +14 -0
  13. package/esm/components/flat-table/__internal__/index.d.ts +2 -0
  14. package/esm/components/flat-table/__internal__/index.js +2 -0
  15. package/esm/components/flat-table/__internal__/use-calculate-sticky-cells.d.ts +12 -0
  16. package/esm/components/flat-table/__internal__/use-calculate-sticky-cells.js +28 -0
  17. package/esm/components/flat-table/flat-table-cell/flat-table-cell.component.d.ts +2 -41
  18. package/esm/components/flat-table/flat-table-cell/flat-table-cell.component.js +26 -25
  19. package/esm/components/flat-table/flat-table-cell/flat-table-cell.style.d.ts +7 -2
  20. package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.d.ts +3 -25
  21. package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.js +21 -14
  22. package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.style.d.ts +3 -1
  23. package/esm/components/flat-table/flat-table-head/flat-table-head.component.d.ts +4 -0
  24. package/esm/components/flat-table/flat-table-head/flat-table-head.component.js +21 -24
  25. package/esm/components/flat-table/flat-table-header/flat-table-header.component.d.ts +2 -26
  26. package/esm/components/flat-table/flat-table-header/flat-table-header.component.js +15 -13
  27. package/esm/components/flat-table/flat-table-header/flat-table-header.style.d.ts +3 -1
  28. package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +12 -0
  29. package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-context.js +6 -0
  30. package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.d.ts +3 -1
  31. package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js +17 -3
  32. package/esm/components/flat-table/flat-table-row/__internal__/sub-row-provider.d.ts +15 -0
  33. package/esm/components/flat-table/flat-table-row/__internal__/sub-row-provider.js +28 -0
  34. package/esm/components/flat-table/flat-table-row/flat-table-row.component.d.ts +1 -15
  35. package/esm/components/flat-table/flat-table-row/flat-table-row.component.js +85 -74
  36. package/esm/components/flat-table/flat-table-row/flat-table-row.style.d.ts +4 -1
  37. package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +1 -9
  38. package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.component.d.ts +4 -42
  39. package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +33 -20
  40. package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.style.d.ts +7 -1
  41. package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.style.js +5 -1
  42. package/esm/components/flat-table/flat-table.component.js +24 -7
  43. package/esm/components/flat-table/flat-table.style.js +2 -2
  44. package/esm/components/heading/heading.style.d.ts +4 -9
  45. package/esm/components/menu/menu-full-screen/menu-full-screen.style.js +2 -2
  46. package/esm/components/menu/scrollable-block/scrollable-block.style.js +2 -2
  47. package/esm/components/typography/typography.component.d.ts +25 -15
  48. package/esm/components/typography/typography.component.js +37 -184
  49. package/esm/components/typography/typography.style.d.ts +12 -0
  50. package/esm/components/typography/typography.style.js +190 -0
  51. package/esm/components/vertical-menu/vertical-menu.style.js +3 -3
  52. package/esm/style/utils/filter-styled-system-flexbox-props.d.ts +3 -0
  53. package/esm/style/utils/filter-styled-system-flexbox-props.js +5 -0
  54. package/esm/style/utils/filter-styled-system-grid-props.d.ts +3 -0
  55. package/esm/style/utils/filter-styled-system-grid-props.js +5 -0
  56. package/esm/style/utils/filter-styled-system-layout-props.d.ts +3 -0
  57. package/esm/style/utils/filter-styled-system-layout-props.js +5 -0
  58. package/esm/style/utils/index.d.ts +4 -1
  59. package/esm/style/utils/index.js +4 -1
  60. package/lib/__internal__/input/input-presentation.style.d.ts +1 -1
  61. package/lib/__spec_helper__/test-utils.d.ts +3 -2
  62. package/lib/__spec_helper__/test-utils.js +16 -1
  63. package/lib/components/box/box.component.d.ts +23 -6
  64. package/lib/components/box/box.component.js +3569 -105
  65. package/lib/components/box/box.style.d.ts +3 -0
  66. package/lib/components/box/box.style.js +122 -0
  67. package/lib/components/dismissible-box/dismissible-box.style.d.ts +2 -1
  68. package/lib/components/drawer/drawer.style.d.ts +2 -1
  69. package/lib/components/duelling-picklist/picklist/picklist.style.js +2 -1
  70. package/lib/components/flat-table/__internal__/build-position-map.d.ts +2 -0
  71. package/lib/components/flat-table/__internal__/build-position-map.js +21 -0
  72. package/lib/components/flat-table/__internal__/index.d.ts +2 -0
  73. package/lib/components/flat-table/__internal__/index.js +20 -0
  74. package/lib/components/flat-table/__internal__/package.json +6 -0
  75. package/lib/components/flat-table/__internal__/use-calculate-sticky-cells.d.ts +12 -0
  76. package/lib/components/flat-table/__internal__/use-calculate-sticky-cells.js +36 -0
  77. package/lib/components/flat-table/flat-table-cell/flat-table-cell.component.d.ts +2 -41
  78. package/lib/components/flat-table/flat-table-cell/flat-table-cell.component.js +25 -24
  79. package/lib/components/flat-table/flat-table-cell/flat-table-cell.style.d.ts +7 -2
  80. package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.d.ts +3 -25
  81. package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.js +20 -13
  82. package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.style.d.ts +3 -1
  83. package/lib/components/flat-table/flat-table-head/flat-table-head.component.d.ts +4 -0
  84. package/lib/components/flat-table/flat-table-head/flat-table-head.component.js +23 -25
  85. package/lib/components/flat-table/flat-table-header/flat-table-header.component.d.ts +2 -26
  86. package/lib/components/flat-table/flat-table-header/flat-table-header.component.js +14 -12
  87. package/lib/components/flat-table/flat-table-header/flat-table-header.style.d.ts +3 -1
  88. package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +12 -0
  89. package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-context.js +13 -0
  90. package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.d.ts +3 -1
  91. package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js +17 -3
  92. package/lib/components/flat-table/flat-table-row/__internal__/sub-row-provider.d.ts +15 -0
  93. package/lib/components/flat-table/flat-table-row/__internal__/sub-row-provider.js +38 -0
  94. package/lib/components/flat-table/flat-table-row/flat-table-row.component.d.ts +1 -15
  95. package/lib/components/flat-table/flat-table-row/flat-table-row.component.js +84 -73
  96. package/lib/components/flat-table/flat-table-row/flat-table-row.style.d.ts +4 -1
  97. package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +1 -9
  98. package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.component.d.ts +4 -42
  99. package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +32 -19
  100. package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.style.d.ts +7 -1
  101. package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.style.js +5 -1
  102. package/lib/components/flat-table/flat-table.component.js +24 -7
  103. package/lib/components/flat-table/flat-table.style.js +1 -1
  104. package/lib/components/heading/heading.style.d.ts +4 -9
  105. package/lib/components/menu/menu-full-screen/menu-full-screen.style.js +1 -1
  106. package/lib/components/menu/scrollable-block/scrollable-block.style.js +1 -1
  107. package/lib/components/typography/typography.component.d.ts +25 -15
  108. package/lib/components/typography/typography.component.js +39 -187
  109. package/lib/components/typography/typography.style.d.ts +12 -0
  110. package/lib/components/typography/typography.style.js +200 -0
  111. package/lib/components/vertical-menu/vertical-menu.style.js +1 -1
  112. package/lib/style/utils/filter-styled-system-flexbox-props.d.ts +3 -0
  113. package/lib/style/utils/filter-styled-system-flexbox-props.js +14 -0
  114. package/lib/style/utils/filter-styled-system-grid-props.d.ts +3 -0
  115. package/lib/style/utils/filter-styled-system-grid-props.js +14 -0
  116. package/lib/style/utils/filter-styled-system-layout-props.d.ts +3 -0
  117. package/lib/style/utils/filter-styled-system-layout-props.js +14 -0
  118. package/lib/style/utils/index.d.ts +4 -1
  119. package/lib/style/utils/index.js +21 -0
  120. package/package.json +1 -1
@@ -18,35 +18,11 @@ export interface FlatTableHeaderProps extends PaddingProps {
18
18
  verticalBorderColor?: string;
19
19
  /** Column width, pass a number to set a fixed width in pixels */
20
20
  width?: number;
21
- /** Sets an id string on the DOM element */
21
+ /** Sets an id string on the element */
22
22
  id?: string;
23
- /**
24
- * @private
25
- * @ignore
26
- * Sets the left position when sticky column found
27
- */
28
- leftPosition?: number;
29
- /**
30
- * @private
31
- * @ignore
32
- * Sets the right position when sticky column found
33
- */
34
- rightPosition?: number;
35
- /**
36
- * @private
37
- * @ignore
38
- * Index of cell within row
39
- */
40
- cellIndex?: number;
41
- /**
42
- * @private
43
- * @ignore
44
- * Callback to report the offsetWidth
45
- */
46
- reportCellWidth?: (offset: number, index?: number) => void;
47
23
  }
48
24
  export declare const FlatTableHeader: {
49
- ({ align, children, colspan, rowspan, width, py, px, reportCellWidth, cellIndex, leftPosition, rightPosition, ...rest }: FlatTableHeaderProps): React.JSX.Element;
25
+ ({ align, children, colspan, rowspan, width, py, px, id, ...rest }: FlatTableHeaderProps): React.JSX.Element;
50
26
  defaultProps: {
51
27
  align: string;
52
28
  };
@@ -8,6 +8,8 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  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
+ var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
12
+ var _useCalculateStickyCells = _interopRequireDefault(require("../__internal__/use-calculate-sticky-cells"));
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
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); }
13
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; }
@@ -20,27 +22,25 @@ const FlatTableHeader = ({
20
22
  width,
21
23
  py,
22
24
  px,
23
- reportCellWidth,
24
- cellIndex,
25
- leftPosition,
26
- rightPosition,
25
+ id,
27
26
  ...rest
28
27
  }) => {
29
28
  const ref = (0, _react.useRef)(null);
29
+ const internalId = (0, _react.useRef)(id || (0, _guid.default)());
30
30
  const {
31
31
  colorTheme
32
32
  } = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
33
- (0, _react.useLayoutEffect)(() => {
34
- if (ref.current && reportCellWidth) {
35
- reportCellWidth(ref.current.offsetWidth, cellIndex);
36
- }
37
- }, [reportCellWidth, cellIndex]);
33
+ const {
34
+ leftPosition,
35
+ rightPosition,
36
+ makeCellSticky
37
+ } = (0, _useCalculateStickyCells.default)(internalId.current);
38
38
  return /*#__PURE__*/_react.default.createElement(_flatTableHeader.default, _extends({
39
39
  ref: ref,
40
40
  leftPosition: leftPosition,
41
41
  rightPosition: rightPosition,
42
- makeCellSticky: !!reportCellWidth,
43
- className: reportCellWidth ? "isSticky" : undefined,
42
+ makeCellSticky: makeCellSticky,
43
+ className: makeCellSticky ? "isSticky" : undefined,
44
44
  align: align,
45
45
  colorTheme: colorTheme,
46
46
  "data-element": "flat-table-header"
@@ -52,7 +52,9 @@ const FlatTableHeader = ({
52
52
  colWidth: width,
53
53
  py: py,
54
54
  px: px
55
- }, rest), /*#__PURE__*/_react.default.createElement("div", null, children));
55
+ }, rest, {
56
+ id: internalId.current
57
+ }), /*#__PURE__*/_react.default.createElement("div", null, children));
56
58
  };
57
59
  exports.FlatTableHeader = FlatTableHeader;
58
60
  FlatTableHeader.defaultProps = {
@@ -1,10 +1,12 @@
1
1
  import { PaddingProps } from "styled-system";
2
2
  import { FlatTableHeaderProps } from "./flat-table-header.component";
3
3
  import { FlatTableProps } from "..";
4
- interface StyledFlatTableHeaderProps extends Pick<FlatTableHeaderProps, "align" | "leftPosition" | "rightPosition" | "verticalBorder" | "verticalBorderColor" | "alternativeBgColor">, PaddingProps {
4
+ interface StyledFlatTableHeaderProps extends Pick<FlatTableHeaderProps, "align" | "verticalBorder" | "verticalBorderColor" | "alternativeBgColor">, PaddingProps {
5
5
  makeCellSticky: boolean;
6
6
  colWidth?: number;
7
7
  colorTheme: FlatTableProps["colorTheme"];
8
+ leftPosition: number;
9
+ rightPosition: number;
8
10
  }
9
11
  declare const StyledFlatTableHeader: import("styled-components").StyledComponent<"th", any, StyledFlatTableHeaderProps, never>;
10
12
  export default StyledFlatTableHeader;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export interface FlatTableRowContextProps {
3
+ expandable?: boolean;
4
+ onClick?: (ev?: React.MouseEvent<HTMLElement>) => void;
5
+ onKeyDown?: (ev: React.KeyboardEvent<HTMLElement>) => void;
6
+ firstCellId: string | null;
7
+ leftPositions: Record<string, number>;
8
+ rightPositions: Record<string, number>;
9
+ firstColumnExpandable?: boolean;
10
+ }
11
+ declare const _default: React.Context<FlatTableRowContextProps>;
12
+ export default _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _default = /*#__PURE__*/(0, _react.createContext)({
9
+ firstCellId: "",
10
+ leftPositions: {},
11
+ rightPositions: {}
12
+ });
13
+ exports.default = _default;
@@ -10,9 +10,11 @@ export interface FlatTableRowDraggableProps {
10
10
  moveItem?: (id?: number | string, index?: number) => void;
11
11
  /** item is draggable */
12
12
  draggable?: boolean;
13
+ /** ref for row element */
14
+ rowRef?: React.ForwardedRef<HTMLTableRowElement | null>;
13
15
  }
14
16
  export declare const FlatTableRowDraggable: {
15
- ({ children, id, findItem, moveItem, }: FlatTableRowDraggableProps): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
17
+ ({ children, id, findItem, moveItem, rowRef, }: FlatTableRowDraggableProps): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
16
18
  displayName: string;
17
19
  };
18
20
  export default FlatTableRowDraggable;
@@ -12,7 +12,8 @@ const FlatTableRowDraggable = ({
12
12
  children,
13
13
  id,
14
14
  findItem,
15
- moveItem
15
+ moveItem,
16
+ rowRef
16
17
  }) => {
17
18
  const originalIndex = Number(findItem?.(id).index);
18
19
  const [{
@@ -53,7 +54,17 @@ const FlatTableRowDraggable = ({
53
54
  key: originalIndex,
54
55
  id,
55
56
  isDragging,
56
- ref: node => drag(drop(node))
57
+ ref: node => {
58
+ drag(drop(node));
59
+ /* istanbul ignore else */
60
+ if (rowRef) {
61
+ if (typeof rowRef === "function") {
62
+ rowRef(node);
63
+ } else {
64
+ rowRef.current = node;
65
+ }
66
+ }
67
+ }
57
68
  });
58
69
  };
59
70
  exports.FlatTableRowDraggable = FlatTableRowDraggable;
@@ -62,7 +73,10 @@ FlatTableRowDraggable.propTypes = {
62
73
  "draggable": _propTypes.default.bool,
63
74
  "findItem": _propTypes.default.func,
64
75
  "id": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
65
- "moveItem": _propTypes.default.func
76
+ "moveItem": _propTypes.default.func,
77
+ "rowRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
78
+ "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
79
+ })])
66
80
  };
67
81
  FlatTableRowDraggable.displayName = "FlatTableRowDraggable";
68
82
  var _default = FlatTableRowDraggable;
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ export interface SubRowContextProps {
3
+ isSubRow?: boolean;
4
+ firstRowId: string;
5
+ addRow: (id: string) => void;
6
+ removeRow: (id: string) => void;
7
+ }
8
+ export declare const SubRowContext: React.Context<SubRowContextProps>;
9
+ declare const SubRowProvider: {
10
+ ({ children }: {
11
+ children: React.ReactNode;
12
+ }): React.JSX.Element;
13
+ displayName: string;
14
+ };
15
+ export default SubRowProvider;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.SubRowContext = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ 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); }
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
+ const SubRowContext = /*#__PURE__*/(0, _react.createContext)({
11
+ isSubRow: false,
12
+ firstRowId: "",
13
+ addRow: () => {},
14
+ removeRow: () => {}
15
+ });
16
+ exports.SubRowContext = SubRowContext;
17
+ const SubRowProvider = ({
18
+ children
19
+ }) => {
20
+ const [rowIds, setRowIds] = (0, _react.useState)([]);
21
+ const addRow = (0, _react.useCallback)(id => {
22
+ setRowIds(p => [...p, id]);
23
+ }, []);
24
+ const removeRow = (0, _react.useCallback)(id => {
25
+ setRowIds(p => p.filter(rowId => rowId !== id));
26
+ }, []);
27
+ return /*#__PURE__*/_react.default.createElement(SubRowContext.Provider, {
28
+ value: {
29
+ isSubRow: true,
30
+ firstRowId: rowIds[0],
31
+ addRow,
32
+ removeRow
33
+ }
34
+ }, children);
35
+ };
36
+ SubRowProvider.displayName = "SubRowProvider";
37
+ var _default = SubRowProvider;
38
+ exports.default = _default;
@@ -24,18 +24,6 @@ export interface FlatTableRowProps {
24
24
  selected?: boolean;
25
25
  /** Sub rows to be shown when the row is expanded, must be used with the `expandable` prop. */
26
26
  subRows?: React.ReactNode;
27
- /** @ignore @private */
28
- isSubRow?: boolean;
29
- /** @ignore @private */
30
- isFirstSubRow?: boolean;
31
- /** @ignore @private position in header if multiple rows */
32
- stickyOffset?: number;
33
- /** @ignore @private applies a border-left to the first child */
34
- applyBorderLeft?: boolean;
35
- /** ID for use in drag and drop functionality
36
- * @private
37
- * @ignore
38
- */
39
27
  id?: string | number;
40
28
  /**
41
29
  * @private
@@ -49,8 +37,6 @@ export interface FlatTableRowProps {
49
37
  moveItem?: FlatTableRowDraggableProps["moveItem"];
50
38
  /** @ignore @private position in header if multiple rows */
51
39
  draggable?: boolean;
52
- /** @ignore @private */
53
- ref?: React.RefObject<HTMLTableRowElement>;
54
40
  }
55
- export declare const FlatTableRow: React.ForwardRefExoticComponent<Pick<FlatTableRowProps, "draggable" | "id" | "children" | "onClick" | "selected" | "bgColor" | "expanded" | "findItem" | "moveItem" | "highlighted" | "expandable" | "horizontalBorderColor" | "stickyOffset" | "isSubRow" | "isFirstSubRow" | "applyBorderLeft" | "horizontalBorderSize" | "expandableArea" | "subRows"> & React.RefAttributes<HTMLTableRowElement>>;
41
+ export declare const FlatTableRow: React.ForwardRefExoticComponent<FlatTableRowProps & React.RefAttributes<HTMLTableRowElement>>;
56
42
  export default FlatTableRow;
@@ -10,11 +10,14 @@ var _invariant = _interopRequireDefault(require("invariant"));
10
10
  var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events"));
11
11
  var _flatTableRow = _interopRequireDefault(require("./flat-table-row.style"));
12
12
  var _drawer = require("../../drawer");
13
- var _flatTableCheckbox = _interopRequireDefault(require("../flat-table-checkbox"));
14
13
  var _flatTableRowHeader = _interopRequireDefault(require("../flat-table-row-header"));
15
14
  var _flatTableRowDraggable = _interopRequireDefault(require("./__internal__/flat-table-row-draggable.component"));
16
15
  var _flatTable = require("../flat-table.component");
17
16
  var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
17
+ var _flatTableRowContext = _interopRequireDefault(require("./__internal__/flat-table-row-context"));
18
+ var _subRowProvider = _interopRequireWildcard(require("./__internal__/sub-row-provider"));
19
+ var _internal__ = require("../__internal__");
20
+ var _flatTableHead = require("../flat-table-head/flat-table-head.component");
18
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
22
  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); }
20
23
  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; }
@@ -25,37 +28,70 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
25
28
  expandable,
26
29
  expandableArea = "wholeRow",
27
30
  expanded = false,
28
- isSubRow,
29
- isFirstSubRow,
30
- stickyOffset,
31
31
  highlighted,
32
32
  selected,
33
33
  subRows,
34
34
  bgColor,
35
35
  horizontalBorderColor,
36
36
  horizontalBorderSize = "small",
37
- applyBorderLeft,
38
37
  id,
39
38
  draggable,
40
39
  findItem,
41
40
  moveItem,
42
41
  ...rest
43
42
  }, ref) => {
44
- const internalId = (0, _react.useRef)(id ?? (0, _guid.default)());
43
+ const internalId = (0, _react.useRef)(id ? String(id) : (0, _guid.default)());
45
44
  const [isExpanded, setIsExpanded] = (0, _react.useState)(expanded);
46
45
  let rowRef = (0, _react.useRef)(null);
47
46
  if (ref) {
48
47
  rowRef = ref;
49
48
  }
50
49
  const firstColumnExpandable = expandableArea === "firstColumn";
51
- const [leftStickyCellWidths, setLeftStickyCellWidths] = (0, _react.useState)([]);
52
- const [rightStickyCellWidths, setRightStickyCellWidths] = (0, _react.useState)([]);
53
- const [leftPositions, setLeftPositions] = (0, _react.useState)([]);
54
- const [rightPositions, setRightPositions] = (0, _react.useState)([]);
55
- const childrenArray = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
56
- const lhsRowHeaderIndex = (0, _react.useMemo)(() => childrenArray.findIndex(child => /*#__PURE__*/_react.default.isValidElement(child) && child.type.displayName === _flatTableRowHeader.default.displayName && child.props.stickyAlignment !== "right"), [childrenArray]);
57
- const rhsRowHeaderIndex = (0, _react.useMemo)(() => childrenArray.findIndex(child => /*#__PURE__*/_react.default.isValidElement(child) && child.type.displayName === _flatTableRowHeader.default.displayName && child.props.stickyAlignment === "right"), [childrenArray]);
50
+ const [leftPositions, setLeftPositions] = (0, _react.useState)({});
51
+ const [rightPositions, setRightPositions] = (0, _react.useState)({});
52
+ const [firstCellIndex, setFirstCellIndex] = (0, _react.useState)(0);
53
+ const [lhsRowHeaderIndex, setLhsRowHeaderIndex] = (0, _react.useState)(-1);
54
+ const [rhsRowHeaderIndex, setRhsRowHeaderIndex] = (0, _react.useState)(-1);
55
+ const [firstCellId, setFirstCellId] = (0, _react.useState)(null);
56
+ const [cellsArray, setCellsArray] = (0, _react.useState)([]);
58
57
  const [tabIndex, setTabIndex] = (0, _react.useState)(-1);
58
+ let interactiveRowProps = {};
59
+ (0, _react.useLayoutEffect)(() => {
60
+ const checkForPositionUpdates = (updated, current) => {
61
+ const updatedKeys = Object.keys(updated);
62
+ const currentKeys = Object.keys(current);
63
+ if (updatedKeys.length !== currentKeys.length) {
64
+ return true;
65
+ }
66
+ return updatedKeys.some(key => updated[key] !== current[key]);
67
+ };
68
+ const cells = rowRef.current?.querySelectorAll("th, td");
69
+ const cellArray = Array.from(cells || []);
70
+ setCellsArray(cellArray);
71
+ const firstIndex = cellArray.findIndex(cell => cell.getAttribute("data-component") !== "flat-table-checkbox");
72
+ const lhsIndex = cellArray.findIndex(cell => cell.getAttribute("data-sticky-align") === "left");
73
+ const rhsIndex = cellArray.findIndex(cell => cell.getAttribute("data-sticky-align") === "right");
74
+ setLhsRowHeaderIndex(lhsIndex);
75
+ setRhsRowHeaderIndex(rhsIndex);
76
+ if (firstIndex !== -1) {
77
+ setFirstCellIndex(firstIndex);
78
+ setFirstCellId(cellArray[firstIndex].getAttribute("id"));
79
+ } else {
80
+ setFirstCellIndex(0);
81
+ }
82
+ if (lhsIndex !== -1) {
83
+ const updatedLeftPositions = (0, _internal__.buildPositionMap)(cellArray.slice(0, lhsRowHeaderIndex + 1), "offsetWidth");
84
+ if (checkForPositionUpdates(updatedLeftPositions, leftPositions)) {
85
+ setLeftPositions(updatedLeftPositions);
86
+ }
87
+ }
88
+ if (rhsIndex !== -1) {
89
+ const updatedRightPositions = (0, _internal__.buildPositionMap)(cellArray.slice(rhsRowHeaderIndex, cellArray.length).reverse(), "offsetWidth");
90
+ if (checkForPositionUpdates(updatedRightPositions, rightPositions)) {
91
+ setRightPositions(updatedRightPositions);
92
+ }
93
+ }
94
+ }, [children, leftPositions, lhsRowHeaderIndex, rhsRowHeaderIndex, rightPositions]);
59
95
  const noStickyColumnsOverlap = (0, _react.useMemo)(() => {
60
96
  const hasLhsColumn = lhsRowHeaderIndex !== -1;
61
97
  const hasRhsColumn = rhsRowHeaderIndex !== -1;
@@ -72,22 +108,9 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
72
108
  const {
73
109
  isInSidebar
74
110
  } = (0, _react.useContext)(_drawer.DrawerSidebarContext);
75
- const reportCellWidth = (0, _react.useCallback)((width, index) => {
76
- const isLeftSticky = index < lhsRowHeaderIndex;
77
- const copiedArray = isLeftSticky ? leftStickyCellWidths : rightStickyCellWidths;
78
- if (copiedArray[index] !== undefined) {
79
- copiedArray[index] = width;
80
- } else {
81
- copiedArray.push(width);
82
- }
83
- if (isLeftSticky) {
84
- setLeftStickyCellWidths(copiedArray);
85
- } else {
86
- setRightStickyCellWidths(copiedArray);
87
- }
88
- }, [lhsRowHeaderIndex, leftStickyCellWidths, rightStickyCellWidths]);
89
- let interactiveRowProps = {};
90
- const firstCellIndex = /*#__PURE__*/_react.default.isValidElement(childrenArray[0]) && childrenArray[0].type === _flatTableCheckbox.default ? 1 : 0;
111
+ const {
112
+ stickyOffsets
113
+ } = (0, _react.useContext)(_flatTableHead.FlatTableHeadContext);
91
114
  const toggleExpanded = () => setIsExpanded(!isExpanded);
92
115
  function onKeyDown(ev) {
93
116
  const isEnterOrSpaceKey = _events.default.isEnterKey(ev) || _events.default.isSpaceKey(ev);
@@ -123,32 +146,31 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
123
146
  toggleExpanded();
124
147
  }
125
148
  }
126
- const buildPositionArray = (setter, widthsArray, length) => {
127
- setter([0, ...Array.from({
128
- length
129
- }).map((_, index) => widthsArray.slice(0, index + 1).reduce((a, b) => a + b, 0), 0)]);
130
- };
131
- (0, _react.useLayoutEffect)(() => {
132
- if (leftStickyCellWidths.length && lhsRowHeaderIndex !== -1) {
133
- buildPositionArray(setLeftPositions, leftStickyCellWidths, lhsRowHeaderIndex);
134
- }
135
- }, [lhsRowHeaderIndex, leftStickyCellWidths]);
136
- (0, _react.useLayoutEffect)(() => {
137
- if (rightStickyCellWidths.length && rhsRowHeaderIndex !== -1) {
138
- buildPositionArray(setRightPositions, rightStickyCellWidths, childrenArray.length - (rhsRowHeaderIndex + 1));
139
- }
140
- }, [rhsRowHeaderIndex, rightStickyCellWidths, childrenArray]);
141
149
  (0, _react.useEffect)(() => {
142
150
  setIsExpanded(expanded);
143
151
  }, [expanded]);
144
152
  (0, _react.useEffect)(() => {
145
153
  if (highlighted || selected) {
146
- setSelectedId(String(internalId.current));
154
+ setSelectedId(internalId.current);
147
155
  }
148
156
  }, [highlighted, selected, setSelectedId]);
149
157
  (0, _react.useEffect)(() => {
150
158
  setTabIndex(selectedId === internalId.current ? 0 : -1);
151
159
  }, [selectedId]);
160
+ const {
161
+ isSubRow,
162
+ firstRowId,
163
+ addRow,
164
+ removeRow
165
+ } = (0, _react.useContext)(_subRowProvider.SubRowContext);
166
+ (0, _react.useEffect)(() => {
167
+ const rowId = internalId.current;
168
+ addRow(rowId);
169
+ return () => {
170
+ removeRow(rowId);
171
+ };
172
+ }, [addRow, removeRow]);
173
+ const isFirstSubRow = firstRowId === internalId.current;
152
174
  const rowComponent = () => /*#__PURE__*/_react.default.createElement(_flatTableRow.default, _extends({
153
175
  isInSidebar: isInSidebar,
154
176
  expandable: expandable,
@@ -164,42 +186,34 @@ const FlatTableRow = /*#__PURE__*/_react.default.forwardRef(({
164
186
  rhsRowHeaderIndex: rhsRowHeaderIndex,
165
187
  colorTheme: colorTheme,
166
188
  size: size,
167
- stickyOffset: stickyOffset,
189
+ stickyOffset: stickyOffsets[internalId.current],
168
190
  bgColor: bgColor,
169
191
  horizontalBorderColor: horizontalBorderColor,
170
192
  horizontalBorderSize: horizontalBorderSize,
171
- applyBorderLeft: applyBorderLeft,
172
193
  draggable: draggable,
173
- totalChildren: childrenArray.length,
174
- id: String(internalId.current)
175
- }, interactiveRowProps, rest), _react.default.Children.map(children, (child, index) => {
176
- return /*#__PURE__*/_react.default.isValidElement(child) && /*#__PURE__*/_react.default.cloneElement(child, {
177
- expandable: expandable && index === firstCellIndex,
178
- onClick: expandable && index === firstCellIndex && firstColumnExpandable ? () => toggleExpanded() : undefined,
179
- onKeyDown: expandable && index === firstCellIndex && firstColumnExpandable ? handleCellKeyDown : undefined,
180
- cellIndex: index,
181
- reportCellWidth: index < lhsRowHeaderIndex || rhsRowHeaderIndex !== -1 && index > rhsRowHeaderIndex ? reportCellWidth : undefined,
182
- leftPosition: leftPositions[index],
183
- rightPosition: rightPositions[childrenArray.length - (index + 1)],
184
- ...child.props
185
- });
186
- }));
194
+ totalChildren: cellsArray.length,
195
+ id: internalId.current
196
+ }, interactiveRowProps, rest), /*#__PURE__*/_react.default.createElement(_flatTableRowContext.default.Provider, {
197
+ value: {
198
+ firstCellId,
199
+ expandable,
200
+ leftPositions,
201
+ rightPositions,
202
+ firstColumnExpandable,
203
+ onKeyDown: handleCellKeyDown,
204
+ onClick: () => toggleExpanded()
205
+ }
206
+ }, children));
187
207
  const draggableComponent = () => /*#__PURE__*/_react.default.createElement(_flatTableRowDraggable.default, {
188
208
  id: internalId.current,
189
209
  moveItem: moveItem,
190
- findItem: findItem
210
+ findItem: findItem,
211
+ rowRef: rowRef
191
212
  }, rowComponent());
192
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, draggable ? draggableComponent() : rowComponent(), isExpanded && subRows && _react.default.Children.map(subRows, (child, index) => child && /*#__PURE__*/_react.default.cloneElement(child, {
193
- isSubRow: true,
194
- isFirstSubRow: index === 0,
195
- ...( /*#__PURE__*/_react.default.isValidElement(child) && {
196
- ...child.props
197
- })
198
- })));
213
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, draggable ? draggableComponent() : rowComponent(), isExpanded && subRows && /*#__PURE__*/_react.default.createElement(_subRowProvider.default, null, subRows));
199
214
  });
200
215
  exports.FlatTableRow = FlatTableRow;
201
216
  FlatTableRow.propTypes = {
202
- "applyBorderLeft": _propTypes.default.bool,
203
217
  "bgColor": _propTypes.default.string,
204
218
  "children": _propTypes.default.node,
205
219
  "draggable": _propTypes.default.bool,
@@ -211,12 +225,9 @@ FlatTableRow.propTypes = {
211
225
  "horizontalBorderColor": _propTypes.default.string,
212
226
  "horizontalBorderSize": _propTypes.default.oneOf(["large", "medium", "small"]),
213
227
  "id": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
214
- "isFirstSubRow": _propTypes.default.bool,
215
- "isSubRow": _propTypes.default.bool,
216
228
  "moveItem": _propTypes.default.func,
217
229
  "onClick": _propTypes.default.func,
218
230
  "selected": _propTypes.default.bool,
219
- "stickyOffset": _propTypes.default.number,
220
231
  "subRows": _propTypes.default.node
221
232
  };
222
233
  FlatTableRow.displayName = "FlatTableRow";
@@ -1,6 +1,6 @@
1
1
  import { FlatTableProps } from "..";
2
2
  import { FlatTableRowProps } from "./flat-table-row.component";
3
- interface StyledFlatTableRowProps extends Pick<FlatTableRowProps, "bgColor" | "horizontalBorderColor" | "stickyOffset" | "expandable" | "selected" | "highlighted" | "isSubRow" | "isFirstSubRow" | "applyBorderLeft" | "draggable"> {
3
+ interface StyledFlatTableRowProps extends Pick<FlatTableRowProps, "bgColor" | "horizontalBorderColor" | "expandable" | "selected" | "highlighted" | "draggable"> {
4
4
  isRowInteractive?: boolean;
5
5
  isFirstColumnInteractive?: boolean;
6
6
  lhsRowHeaderIndex: number;
@@ -13,6 +13,9 @@ interface StyledFlatTableRowProps extends Pick<FlatTableRowProps, "bgColor" | "h
13
13
  size: FlatTableProps["size"];
14
14
  isDragging?: boolean;
15
15
  horizontalBorderSize: NonNullable<FlatTableRowProps["horizontalBorderSize"]>;
16
+ isSubRow?: boolean;
17
+ isFirstSubRow?: boolean;
18
+ stickyOffset?: number;
16
19
  }
17
20
  declare const StyledFlatTableRow: import("styled-components").StyledComponent<"tr", any, StyledFlatTableRowProps, never>;
18
21
  export default StyledFlatTableRow;
@@ -124,7 +124,6 @@ const StyledFlatTableRow = _styledComponents.default.tr`
124
124
  isFirstSubRow,
125
125
  size,
126
126
  theme,
127
- applyBorderLeft,
128
127
  isDragging,
129
128
  draggable
130
129
  }) => {
@@ -197,7 +196,7 @@ const StyledFlatTableRow = _styledComponents.default.tr`
197
196
  `}
198
197
  }
199
198
 
200
- ${stickyOffset !== undefined && stickyOffset > 0 && (0, _styledComponents.css)`
199
+ ${stickyOffset !== undefined && (0, _styledComponents.css)`
201
200
  && th {
202
201
  top: ${stickyOffset}px;
203
202
  }
@@ -309,13 +308,6 @@ const StyledFlatTableRow = _styledComponents.default.tr`
309
308
  }
310
309
  `}
311
310
 
312
-
313
- ${applyBorderLeft && (0, _styledComponents.css)`
314
- th:first-of-type {
315
- border-left: 1px solid ${customBorderColor || borderColor(colorTheme)};
316
- }
317
- `}
318
-
319
311
  ${isInSidebar && (0, _styledComponents.css)`
320
312
  ${allCellTypes} {
321
313
  background-color: ${bgColor || "var(--colorsUtilityMajor040)"};
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
2
  import { PaddingProps } from "styled-system";
3
3
  import { TableBorderSize, TableCellAlign } from "..";
4
- export interface FlatTableRowHeaderProps extends PaddingProps {
4
+ import { TagProps } from "../../../__internal__/utils/helpers/tags/tags";
5
+ export interface FlatTableRowHeaderProps extends PaddingProps, TagProps {
5
6
  /** Content alignment */
6
7
  align?: TableCellAlign;
7
8
  /** RowHeader content */
@@ -22,50 +23,11 @@ export interface FlatTableRowHeaderProps extends PaddingProps {
22
23
  colspan?: number | string;
23
24
  /** Number of rows that a header cell should span */
24
25
  rowspan?: number | string;
25
- /** Sets an id string on the DOM element */
26
+ /** Sets an id string on the element */
26
27
  id?: string;
27
- /**
28
- * @private
29
- * @ignore
30
- */
31
- expandable?: boolean;
32
- /**
33
- * @private
34
- * @ignore
35
- */
36
- onClick?: (ev: React.MouseEvent<HTMLElement>) => void;
37
- /**
38
- * @private
39
- * @ignore
40
- */
41
- onKeyDown?: (ev: React.KeyboardEvent<HTMLElement>) => void;
42
- /**
43
- * @private
44
- * @ignore
45
- * Sets the left position when sticky column found
46
- */
47
- leftPosition?: number;
48
- /**
49
- * @private
50
- * @ignore
51
- * Sets the right position when sticky column found
52
- */
53
- rightPosition?: number;
54
- /**
55
- * @private
56
- * @ignore
57
- * Index of cell within row
58
- */
59
- cellIndex?: number;
60
- /**
61
- * @private
62
- * @ignore
63
- * Callback to report the offsetWidth
64
- */
65
- reportCellWidth?: (offset: number, index?: number) => void;
66
28
  }
67
29
  export declare const FlatTableRowHeader: {
68
- ({ align, children, width, py, px, expandable, onClick, onKeyDown, leftPosition, rightPosition, truncate, title, stickyAlignment, colspan, rowspan, ...rest }: FlatTableRowHeaderProps): React.JSX.Element;
30
+ ({ align, children, width, py, px, truncate, title, stickyAlignment, colspan, rowspan, id, ...rest }: FlatTableRowHeaderProps): React.JSX.Element;
69
31
  displayName: string;
70
32
  };
71
33
  export default FlatTableRowHeader;