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
@@ -1,8 +1,10 @@
1
1
  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); }
2
- import React, { useLayoutEffect, useRef, useContext } from "react";
2
+ import React, { useRef, useContext } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import StyledFlatTableHeader from "./flat-table-header.style";
5
5
  import { FlatTableThemeContext } from "../flat-table.component";
6
+ import guid from "../../../__internal__/utils/helpers/guid";
7
+ import useCalculateStickyCells from "../__internal__/use-calculate-sticky-cells";
6
8
  export const FlatTableHeader = ({
7
9
  align,
8
10
  children,
@@ -11,27 +13,25 @@ export const FlatTableHeader = ({
11
13
  width,
12
14
  py,
13
15
  px,
14
- reportCellWidth,
15
- cellIndex,
16
- leftPosition,
17
- rightPosition,
16
+ id,
18
17
  ...rest
19
18
  }) => {
20
19
  const ref = useRef(null);
20
+ const internalId = useRef(id || guid());
21
21
  const {
22
22
  colorTheme
23
23
  } = useContext(FlatTableThemeContext);
24
- useLayoutEffect(() => {
25
- if (ref.current && reportCellWidth) {
26
- reportCellWidth(ref.current.offsetWidth, cellIndex);
27
- }
28
- }, [reportCellWidth, cellIndex]);
24
+ const {
25
+ leftPosition,
26
+ rightPosition,
27
+ makeCellSticky
28
+ } = useCalculateStickyCells(internalId.current);
29
29
  return /*#__PURE__*/React.createElement(StyledFlatTableHeader, _extends({
30
30
  ref: ref,
31
31
  leftPosition: leftPosition,
32
32
  rightPosition: rightPosition,
33
- makeCellSticky: !!reportCellWidth,
34
- className: reportCellWidth ? "isSticky" : undefined,
33
+ makeCellSticky: makeCellSticky,
34
+ className: makeCellSticky ? "isSticky" : undefined,
35
35
  align: align,
36
36
  colorTheme: colorTheme,
37
37
  "data-element": "flat-table-header"
@@ -43,7 +43,9 @@ export const FlatTableHeader = ({
43
43
  colWidth: width,
44
44
  py: py,
45
45
  px: px
46
- }, rest), /*#__PURE__*/React.createElement("div", null, children));
46
+ }, rest, {
47
+ id: internalId.current
48
+ }), /*#__PURE__*/React.createElement("div", null, children));
47
49
  };
48
50
  FlatTableHeader.defaultProps = {
49
51
  align: "left"
@@ -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,6 @@
1
+ import { createContext } from "react";
2
+ export default /*#__PURE__*/createContext({
3
+ firstCellId: "",
4
+ leftPositions: {},
5
+ rightPositions: {}
6
+ });
@@ -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;
@@ -5,7 +5,8 @@ const FlatTableRowDraggable = ({
5
5
  children,
6
6
  id,
7
7
  findItem,
8
- moveItem
8
+ moveItem,
9
+ rowRef
9
10
  }) => {
10
11
  const originalIndex = Number(findItem?.(id).index);
11
12
  const [{
@@ -46,7 +47,17 @@ const FlatTableRowDraggable = ({
46
47
  key: originalIndex,
47
48
  id,
48
49
  isDragging,
49
- ref: node => drag(drop(node))
50
+ ref: node => {
51
+ drag(drop(node));
52
+ /* istanbul ignore else */
53
+ if (rowRef) {
54
+ if (typeof rowRef === "function") {
55
+ rowRef(node);
56
+ } else {
57
+ rowRef.current = node;
58
+ }
59
+ }
60
+ }
50
61
  });
51
62
  };
52
63
  FlatTableRowDraggable.propTypes = {
@@ -54,7 +65,10 @@ FlatTableRowDraggable.propTypes = {
54
65
  "draggable": PropTypes.bool,
55
66
  "findItem": PropTypes.func,
56
67
  "id": PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
57
- "moveItem": PropTypes.func
68
+ "moveItem": PropTypes.func,
69
+ "rowRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
70
+ "current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
71
+ })])
58
72
  };
59
73
  export { FlatTableRowDraggable };
60
74
  FlatTableRowDraggable.displayName = "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,28 @@
1
+ import React, { createContext, useCallback, useState } from "react";
2
+ export const SubRowContext = /*#__PURE__*/createContext({
3
+ isSubRow: false,
4
+ firstRowId: "",
5
+ addRow: () => {},
6
+ removeRow: () => {}
7
+ });
8
+ const SubRowProvider = ({
9
+ children
10
+ }) => {
11
+ const [rowIds, setRowIds] = useState([]);
12
+ const addRow = useCallback(id => {
13
+ setRowIds(p => [...p, id]);
14
+ }, []);
15
+ const removeRow = useCallback(id => {
16
+ setRowIds(p => p.filter(rowId => rowId !== id));
17
+ }, []);
18
+ return /*#__PURE__*/React.createElement(SubRowContext.Provider, {
19
+ value: {
20
+ isSubRow: true,
21
+ firstRowId: rowIds[0],
22
+ addRow,
23
+ removeRow
24
+ }
25
+ }, children);
26
+ };
27
+ SubRowProvider.displayName = "SubRowProvider";
28
+ export default SubRowProvider;
@@ -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;
@@ -1,52 +1,88 @@
1
1
  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); }
2
- import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import React, { useContext, useEffect, useMemo, useRef, useState, useLayoutEffect } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import invariant from "invariant";
5
5
  import Event from "../../../__internal__/utils/helpers/events";
6
6
  import StyledFlatTableRow from "./flat-table-row.style";
7
7
  import { DrawerSidebarContext } from "../../drawer";
8
- import FlatTableCheckbox from "../flat-table-checkbox";
9
8
  import FlatTableRowHeader from "../flat-table-row-header";
10
9
  import FlatTableRowDraggable from "./__internal__/flat-table-row-draggable.component";
11
10
  import { FlatTableThemeContext } from "../flat-table.component";
12
11
  import guid from "../../../__internal__/utils/helpers/guid";
12
+ import FlatTableRowContext from "./__internal__/flat-table-row-context";
13
+ import SubRowProvider, { SubRowContext } from "./__internal__/sub-row-provider";
14
+ import { buildPositionMap } from "../__internal__";
15
+ import { FlatTableHeadContext } from "../flat-table-head/flat-table-head.component";
13
16
  const FlatTableRow = /*#__PURE__*/React.forwardRef(({
14
17
  children,
15
18
  onClick,
16
19
  expandable,
17
20
  expandableArea = "wholeRow",
18
21
  expanded = false,
19
- isSubRow,
20
- isFirstSubRow,
21
- stickyOffset,
22
22
  highlighted,
23
23
  selected,
24
24
  subRows,
25
25
  bgColor,
26
26
  horizontalBorderColor,
27
27
  horizontalBorderSize = "small",
28
- applyBorderLeft,
29
28
  id,
30
29
  draggable,
31
30
  findItem,
32
31
  moveItem,
33
32
  ...rest
34
33
  }, ref) => {
35
- const internalId = useRef(id ?? guid());
34
+ const internalId = useRef(id ? String(id) : guid());
36
35
  const [isExpanded, setIsExpanded] = useState(expanded);
37
36
  let rowRef = useRef(null);
38
37
  if (ref) {
39
38
  rowRef = ref;
40
39
  }
41
40
  const firstColumnExpandable = expandableArea === "firstColumn";
42
- const [leftStickyCellWidths, setLeftStickyCellWidths] = useState([]);
43
- const [rightStickyCellWidths, setRightStickyCellWidths] = useState([]);
44
- const [leftPositions, setLeftPositions] = useState([]);
45
- const [rightPositions, setRightPositions] = useState([]);
46
- const childrenArray = useMemo(() => React.Children.toArray(children), [children]);
47
- const lhsRowHeaderIndex = useMemo(() => childrenArray.findIndex(child => /*#__PURE__*/React.isValidElement(child) && child.type.displayName === FlatTableRowHeader.displayName && child.props.stickyAlignment !== "right"), [childrenArray]);
48
- const rhsRowHeaderIndex = useMemo(() => childrenArray.findIndex(child => /*#__PURE__*/React.isValidElement(child) && child.type.displayName === FlatTableRowHeader.displayName && child.props.stickyAlignment === "right"), [childrenArray]);
41
+ const [leftPositions, setLeftPositions] = useState({});
42
+ const [rightPositions, setRightPositions] = useState({});
43
+ const [firstCellIndex, setFirstCellIndex] = useState(0);
44
+ const [lhsRowHeaderIndex, setLhsRowHeaderIndex] = useState(-1);
45
+ const [rhsRowHeaderIndex, setRhsRowHeaderIndex] = useState(-1);
46
+ const [firstCellId, setFirstCellId] = useState(null);
47
+ const [cellsArray, setCellsArray] = useState([]);
49
48
  const [tabIndex, setTabIndex] = useState(-1);
49
+ let interactiveRowProps = {};
50
+ useLayoutEffect(() => {
51
+ const checkForPositionUpdates = (updated, current) => {
52
+ const updatedKeys = Object.keys(updated);
53
+ const currentKeys = Object.keys(current);
54
+ if (updatedKeys.length !== currentKeys.length) {
55
+ return true;
56
+ }
57
+ return updatedKeys.some(key => updated[key] !== current[key]);
58
+ };
59
+ const cells = rowRef.current?.querySelectorAll("th, td");
60
+ const cellArray = Array.from(cells || []);
61
+ setCellsArray(cellArray);
62
+ const firstIndex = cellArray.findIndex(cell => cell.getAttribute("data-component") !== "flat-table-checkbox");
63
+ const lhsIndex = cellArray.findIndex(cell => cell.getAttribute("data-sticky-align") === "left");
64
+ const rhsIndex = cellArray.findIndex(cell => cell.getAttribute("data-sticky-align") === "right");
65
+ setLhsRowHeaderIndex(lhsIndex);
66
+ setRhsRowHeaderIndex(rhsIndex);
67
+ if (firstIndex !== -1) {
68
+ setFirstCellIndex(firstIndex);
69
+ setFirstCellId(cellArray[firstIndex].getAttribute("id"));
70
+ } else {
71
+ setFirstCellIndex(0);
72
+ }
73
+ if (lhsIndex !== -1) {
74
+ const updatedLeftPositions = buildPositionMap(cellArray.slice(0, lhsRowHeaderIndex + 1), "offsetWidth");
75
+ if (checkForPositionUpdates(updatedLeftPositions, leftPositions)) {
76
+ setLeftPositions(updatedLeftPositions);
77
+ }
78
+ }
79
+ if (rhsIndex !== -1) {
80
+ const updatedRightPositions = buildPositionMap(cellArray.slice(rhsRowHeaderIndex, cellArray.length).reverse(), "offsetWidth");
81
+ if (checkForPositionUpdates(updatedRightPositions, rightPositions)) {
82
+ setRightPositions(updatedRightPositions);
83
+ }
84
+ }
85
+ }, [children, leftPositions, lhsRowHeaderIndex, rhsRowHeaderIndex, rightPositions]);
50
86
  const noStickyColumnsOverlap = useMemo(() => {
51
87
  const hasLhsColumn = lhsRowHeaderIndex !== -1;
52
88
  const hasRhsColumn = rhsRowHeaderIndex !== -1;
@@ -63,22 +99,9 @@ const FlatTableRow = /*#__PURE__*/React.forwardRef(({
63
99
  const {
64
100
  isInSidebar
65
101
  } = useContext(DrawerSidebarContext);
66
- const reportCellWidth = useCallback((width, index) => {
67
- const isLeftSticky = index < lhsRowHeaderIndex;
68
- const copiedArray = isLeftSticky ? leftStickyCellWidths : rightStickyCellWidths;
69
- if (copiedArray[index] !== undefined) {
70
- copiedArray[index] = width;
71
- } else {
72
- copiedArray.push(width);
73
- }
74
- if (isLeftSticky) {
75
- setLeftStickyCellWidths(copiedArray);
76
- } else {
77
- setRightStickyCellWidths(copiedArray);
78
- }
79
- }, [lhsRowHeaderIndex, leftStickyCellWidths, rightStickyCellWidths]);
80
- let interactiveRowProps = {};
81
- const firstCellIndex = /*#__PURE__*/React.isValidElement(childrenArray[0]) && childrenArray[0].type === FlatTableCheckbox ? 1 : 0;
102
+ const {
103
+ stickyOffsets
104
+ } = useContext(FlatTableHeadContext);
82
105
  const toggleExpanded = () => setIsExpanded(!isExpanded);
83
106
  function onKeyDown(ev) {
84
107
  const isEnterOrSpaceKey = Event.isEnterKey(ev) || Event.isSpaceKey(ev);
@@ -114,32 +137,31 @@ const FlatTableRow = /*#__PURE__*/React.forwardRef(({
114
137
  toggleExpanded();
115
138
  }
116
139
  }
117
- const buildPositionArray = (setter, widthsArray, length) => {
118
- setter([0, ...Array.from({
119
- length
120
- }).map((_, index) => widthsArray.slice(0, index + 1).reduce((a, b) => a + b, 0), 0)]);
121
- };
122
- useLayoutEffect(() => {
123
- if (leftStickyCellWidths.length && lhsRowHeaderIndex !== -1) {
124
- buildPositionArray(setLeftPositions, leftStickyCellWidths, lhsRowHeaderIndex);
125
- }
126
- }, [lhsRowHeaderIndex, leftStickyCellWidths]);
127
- useLayoutEffect(() => {
128
- if (rightStickyCellWidths.length && rhsRowHeaderIndex !== -1) {
129
- buildPositionArray(setRightPositions, rightStickyCellWidths, childrenArray.length - (rhsRowHeaderIndex + 1));
130
- }
131
- }, [rhsRowHeaderIndex, rightStickyCellWidths, childrenArray]);
132
140
  useEffect(() => {
133
141
  setIsExpanded(expanded);
134
142
  }, [expanded]);
135
143
  useEffect(() => {
136
144
  if (highlighted || selected) {
137
- setSelectedId(String(internalId.current));
145
+ setSelectedId(internalId.current);
138
146
  }
139
147
  }, [highlighted, selected, setSelectedId]);
140
148
  useEffect(() => {
141
149
  setTabIndex(selectedId === internalId.current ? 0 : -1);
142
150
  }, [selectedId]);
151
+ const {
152
+ isSubRow,
153
+ firstRowId,
154
+ addRow,
155
+ removeRow
156
+ } = useContext(SubRowContext);
157
+ useEffect(() => {
158
+ const rowId = internalId.current;
159
+ addRow(rowId);
160
+ return () => {
161
+ removeRow(rowId);
162
+ };
163
+ }, [addRow, removeRow]);
164
+ const isFirstSubRow = firstRowId === internalId.current;
143
165
  const rowComponent = () => /*#__PURE__*/React.createElement(StyledFlatTableRow, _extends({
144
166
  isInSidebar: isInSidebar,
145
167
  expandable: expandable,
@@ -155,41 +177,33 @@ const FlatTableRow = /*#__PURE__*/React.forwardRef(({
155
177
  rhsRowHeaderIndex: rhsRowHeaderIndex,
156
178
  colorTheme: colorTheme,
157
179
  size: size,
158
- stickyOffset: stickyOffset,
180
+ stickyOffset: stickyOffsets[internalId.current],
159
181
  bgColor: bgColor,
160
182
  horizontalBorderColor: horizontalBorderColor,
161
183
  horizontalBorderSize: horizontalBorderSize,
162
- applyBorderLeft: applyBorderLeft,
163
184
  draggable: draggable,
164
- totalChildren: childrenArray.length,
165
- id: String(internalId.current)
166
- }, interactiveRowProps, rest), React.Children.map(children, (child, index) => {
167
- return /*#__PURE__*/React.isValidElement(child) && /*#__PURE__*/React.cloneElement(child, {
168
- expandable: expandable && index === firstCellIndex,
169
- onClick: expandable && index === firstCellIndex && firstColumnExpandable ? () => toggleExpanded() : undefined,
170
- onKeyDown: expandable && index === firstCellIndex && firstColumnExpandable ? handleCellKeyDown : undefined,
171
- cellIndex: index,
172
- reportCellWidth: index < lhsRowHeaderIndex || rhsRowHeaderIndex !== -1 && index > rhsRowHeaderIndex ? reportCellWidth : undefined,
173
- leftPosition: leftPositions[index],
174
- rightPosition: rightPositions[childrenArray.length - (index + 1)],
175
- ...child.props
176
- });
177
- }));
185
+ totalChildren: cellsArray.length,
186
+ id: internalId.current
187
+ }, interactiveRowProps, rest), /*#__PURE__*/React.createElement(FlatTableRowContext.Provider, {
188
+ value: {
189
+ firstCellId,
190
+ expandable,
191
+ leftPositions,
192
+ rightPositions,
193
+ firstColumnExpandable,
194
+ onKeyDown: handleCellKeyDown,
195
+ onClick: () => toggleExpanded()
196
+ }
197
+ }, children));
178
198
  const draggableComponent = () => /*#__PURE__*/React.createElement(FlatTableRowDraggable, {
179
199
  id: internalId.current,
180
200
  moveItem: moveItem,
181
- findItem: findItem
201
+ findItem: findItem,
202
+ rowRef: rowRef
182
203
  }, rowComponent());
183
- return /*#__PURE__*/React.createElement(React.Fragment, null, draggable ? draggableComponent() : rowComponent(), isExpanded && subRows && React.Children.map(subRows, (child, index) => child && /*#__PURE__*/React.cloneElement(child, {
184
- isSubRow: true,
185
- isFirstSubRow: index === 0,
186
- ...( /*#__PURE__*/React.isValidElement(child) && {
187
- ...child.props
188
- })
189
- })));
204
+ return /*#__PURE__*/React.createElement(React.Fragment, null, draggable ? draggableComponent() : rowComponent(), isExpanded && subRows && /*#__PURE__*/React.createElement(SubRowProvider, null, subRows));
190
205
  });
191
206
  FlatTableRow.propTypes = {
192
- "applyBorderLeft": PropTypes.bool,
193
207
  "bgColor": PropTypes.string,
194
208
  "children": PropTypes.node,
195
209
  "draggable": PropTypes.bool,
@@ -201,12 +215,9 @@ FlatTableRow.propTypes = {
201
215
  "horizontalBorderColor": PropTypes.string,
202
216
  "horizontalBorderSize": PropTypes.oneOf(["large", "medium", "small"]),
203
217
  "id": PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
204
- "isFirstSubRow": PropTypes.bool,
205
- "isSubRow": PropTypes.bool,
206
218
  "moveItem": PropTypes.func,
207
219
  "onClick": PropTypes.func,
208
220
  "selected": PropTypes.bool,
209
- "stickyOffset": PropTypes.number,
210
221
  "subRows": PropTypes.node
211
222
  };
212
223
  export { 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;
@@ -115,7 +115,6 @@ const StyledFlatTableRow = styled.tr`
115
115
  isFirstSubRow,
116
116
  size,
117
117
  theme,
118
- applyBorderLeft,
119
118
  isDragging,
120
119
  draggable
121
120
  }) => {
@@ -188,7 +187,7 @@ const StyledFlatTableRow = styled.tr`
188
187
  `}
189
188
  }
190
189
 
191
- ${stickyOffset !== undefined && stickyOffset > 0 && css`
190
+ ${stickyOffset !== undefined && css`
192
191
  && th {
193
192
  top: ${stickyOffset}px;
194
193
  }
@@ -300,13 +299,6 @@ const StyledFlatTableRow = styled.tr`
300
299
  }
301
300
  `}
302
301
 
303
-
304
- ${applyBorderLeft && css`
305
- th:first-of-type {
306
- border-left: 1px solid ${customBorderColor || borderColor(colorTheme)};
307
- }
308
- `}
309
-
310
302
  ${isInSidebar && css`
311
303
  ${allCellTypes} {
312
304
  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;