carbon-react 120.0.0 → 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.
- package/esm/components/flat-table/__internal__/build-position-map.d.ts +2 -0
- package/esm/components/flat-table/__internal__/build-position-map.js +14 -0
- package/esm/components/flat-table/__internal__/index.d.ts +2 -0
- package/esm/components/flat-table/__internal__/index.js +2 -0
- package/esm/components/flat-table/__internal__/use-calculate-sticky-cells.d.ts +12 -0
- package/esm/components/flat-table/__internal__/use-calculate-sticky-cells.js +28 -0
- package/esm/components/flat-table/flat-table-cell/flat-table-cell.component.d.ts +2 -41
- package/esm/components/flat-table/flat-table-cell/flat-table-cell.component.js +26 -25
- package/esm/components/flat-table/flat-table-cell/flat-table-cell.style.d.ts +7 -2
- package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.d.ts +3 -25
- package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.js +21 -14
- package/esm/components/flat-table/flat-table-checkbox/flat-table-checkbox.style.d.ts +3 -1
- package/esm/components/flat-table/flat-table-head/flat-table-head.component.d.ts +4 -0
- package/esm/components/flat-table/flat-table-head/flat-table-head.component.js +21 -24
- package/esm/components/flat-table/flat-table-header/flat-table-header.component.d.ts +2 -26
- package/esm/components/flat-table/flat-table-header/flat-table-header.component.js +15 -13
- package/esm/components/flat-table/flat-table-header/flat-table-header.style.d.ts +3 -1
- package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +12 -0
- package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-context.js +6 -0
- package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.d.ts +3 -1
- package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js +17 -3
- package/esm/components/flat-table/flat-table-row/__internal__/sub-row-provider.d.ts +15 -0
- package/esm/components/flat-table/flat-table-row/__internal__/sub-row-provider.js +28 -0
- package/esm/components/flat-table/flat-table-row/flat-table-row.component.d.ts +1 -15
- package/esm/components/flat-table/flat-table-row/flat-table-row.component.js +85 -74
- package/esm/components/flat-table/flat-table-row/flat-table-row.style.d.ts +4 -1
- package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +1 -9
- package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.component.d.ts +4 -42
- package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +33 -20
- package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.style.d.ts +7 -1
- package/esm/components/flat-table/flat-table-row-header/flat-table-row-header.style.js +5 -1
- package/esm/components/flat-table/flat-table.component.js +24 -7
- package/lib/components/flat-table/__internal__/build-position-map.d.ts +2 -0
- package/lib/components/flat-table/__internal__/build-position-map.js +21 -0
- package/lib/components/flat-table/__internal__/index.d.ts +2 -0
- package/lib/components/flat-table/__internal__/index.js +20 -0
- package/lib/components/flat-table/__internal__/package.json +6 -0
- package/lib/components/flat-table/__internal__/use-calculate-sticky-cells.d.ts +12 -0
- package/lib/components/flat-table/__internal__/use-calculate-sticky-cells.js +36 -0
- package/lib/components/flat-table/flat-table-cell/flat-table-cell.component.d.ts +2 -41
- package/lib/components/flat-table/flat-table-cell/flat-table-cell.component.js +25 -24
- package/lib/components/flat-table/flat-table-cell/flat-table-cell.style.d.ts +7 -2
- package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.d.ts +3 -25
- package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.component.js +20 -13
- package/lib/components/flat-table/flat-table-checkbox/flat-table-checkbox.style.d.ts +3 -1
- package/lib/components/flat-table/flat-table-head/flat-table-head.component.d.ts +4 -0
- package/lib/components/flat-table/flat-table-head/flat-table-head.component.js +23 -25
- package/lib/components/flat-table/flat-table-header/flat-table-header.component.d.ts +2 -26
- package/lib/components/flat-table/flat-table-header/flat-table-header.component.js +14 -12
- package/lib/components/flat-table/flat-table-header/flat-table-header.style.d.ts +3 -1
- package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-context.d.ts +12 -0
- package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-context.js +13 -0
- package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.d.ts +3 -1
- package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js +17 -3
- package/lib/components/flat-table/flat-table-row/__internal__/sub-row-provider.d.ts +15 -0
- package/lib/components/flat-table/flat-table-row/__internal__/sub-row-provider.js +38 -0
- package/lib/components/flat-table/flat-table-row/flat-table-row.component.d.ts +1 -15
- package/lib/components/flat-table/flat-table-row/flat-table-row.component.js +84 -73
- package/lib/components/flat-table/flat-table-row/flat-table-row.style.d.ts +4 -1
- package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +1 -9
- package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.component.d.ts +4 -42
- package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.component.js +32 -19
- package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.style.d.ts +7 -1
- package/lib/components/flat-table/flat-table-row-header/flat-table-row-header.style.js +5 -1
- package/lib/components/flat-table/flat-table.component.js +24 -7
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default ((array, propertyName) => array.reduce((acc, _, index) => {
|
|
2
|
+
const currentId = array[index].getAttribute("id");
|
|
3
|
+
if (currentId) {
|
|
4
|
+
if (index === 0) {
|
|
5
|
+
acc[currentId] = 0;
|
|
6
|
+
} else {
|
|
7
|
+
const previousId = array[index - 1].getAttribute("id");
|
|
8
|
+
if (previousId) {
|
|
9
|
+
acc[currentId] = acc[previousId] + array[index - 1][propertyName];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return acc;
|
|
14
|
+
}, {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const _default: (id: string) => {
|
|
3
|
+
expandable: boolean | undefined;
|
|
4
|
+
leftPosition: number;
|
|
5
|
+
rightPosition: number;
|
|
6
|
+
makeCellSticky: boolean;
|
|
7
|
+
onClick: ((ev?: import("react").MouseEvent<HTMLElement, MouseEvent> | undefined) => void) | undefined;
|
|
8
|
+
onKeyDown: ((ev: import("react").KeyboardEvent<HTMLElement>) => void) | undefined;
|
|
9
|
+
isFirstCell: boolean;
|
|
10
|
+
isExpandableCell: boolean | undefined;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import FlatTableRowContext from "../flat-table-row/__internal__/flat-table-row-context";
|
|
3
|
+
export default (id => {
|
|
4
|
+
const {
|
|
5
|
+
expandable,
|
|
6
|
+
firstCellId,
|
|
7
|
+
firstColumnExpandable,
|
|
8
|
+
leftPositions,
|
|
9
|
+
rightPositions,
|
|
10
|
+
onClick,
|
|
11
|
+
onKeyDown
|
|
12
|
+
} = useContext(FlatTableRowContext);
|
|
13
|
+
const leftPosition = leftPositions[id];
|
|
14
|
+
const rightPosition = rightPositions[id];
|
|
15
|
+
const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
|
|
16
|
+
const isFirstCell = id === firstCellId;
|
|
17
|
+
const isExpandableCell = expandable && isFirstCell && firstColumnExpandable;
|
|
18
|
+
return {
|
|
19
|
+
expandable,
|
|
20
|
+
leftPosition,
|
|
21
|
+
rightPosition,
|
|
22
|
+
makeCellSticky,
|
|
23
|
+
onClick,
|
|
24
|
+
onKeyDown,
|
|
25
|
+
isFirstCell,
|
|
26
|
+
isExpandableCell
|
|
27
|
+
};
|
|
28
|
+
});
|
|
@@ -20,50 +20,11 @@ export interface FlatTableCellProps extends PaddingProps {
|
|
|
20
20
|
verticalBorder?: TableBorderSize;
|
|
21
21
|
/** Sets the color of the right border */
|
|
22
22
|
verticalBorderColor?: string;
|
|
23
|
-
/** Sets an id string on the
|
|
23
|
+
/** Sets an id string on the element */
|
|
24
24
|
id?: string;
|
|
25
|
-
/**
|
|
26
|
-
* @private
|
|
27
|
-
* @ignore
|
|
28
|
-
*/
|
|
29
|
-
expandable?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* @private
|
|
32
|
-
* @ignore
|
|
33
|
-
*/
|
|
34
|
-
onClick?: () => void;
|
|
35
|
-
/**
|
|
36
|
-
* @private
|
|
37
|
-
* @ignore
|
|
38
|
-
*/
|
|
39
|
-
onKeyDown?: () => void;
|
|
40
|
-
/**
|
|
41
|
-
* @private
|
|
42
|
-
* @ignore
|
|
43
|
-
* Sets the left position when sticky column found
|
|
44
|
-
*/
|
|
45
|
-
leftPosition?: number;
|
|
46
|
-
/**
|
|
47
|
-
* @private
|
|
48
|
-
* @ignore
|
|
49
|
-
* Sets the right position when sticky column found
|
|
50
|
-
*/
|
|
51
|
-
rightPosition?: number;
|
|
52
|
-
/**
|
|
53
|
-
* @private
|
|
54
|
-
* @ignore
|
|
55
|
-
* Index of cell within row
|
|
56
|
-
*/
|
|
57
|
-
cellIndex?: number;
|
|
58
|
-
/**
|
|
59
|
-
* @private
|
|
60
|
-
* @ignore
|
|
61
|
-
* Callback to report the offsetWidth
|
|
62
|
-
*/
|
|
63
|
-
reportCellWidth?: (offset: number, index?: number) => void;
|
|
64
25
|
}
|
|
65
26
|
export declare const FlatTableCell: {
|
|
66
|
-
({ align, children, pl,
|
|
27
|
+
({ align, children, pl, width, truncate, title, colspan, rowspan, id, ...rest }: FlatTableCellProps): React.JSX.Element;
|
|
67
28
|
displayName: string;
|
|
68
29
|
};
|
|
69
30
|
export default FlatTableCell;
|
|
@@ -1,66 +1,67 @@
|
|
|
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, {
|
|
2
|
+
import React, { useRef, useState, useEffect, useContext } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { StyledFlatTableCell, StyledCellContent } from "./flat-table-cell.style";
|
|
5
5
|
import Icon from "../../icon";
|
|
6
6
|
import { FlatTableThemeContext } from "../flat-table.component";
|
|
7
7
|
import guid from "../../../__internal__/utils/helpers/guid";
|
|
8
|
+
import useCalculateStickyCells from "../__internal__/use-calculate-sticky-cells";
|
|
8
9
|
export const FlatTableCell = ({
|
|
9
10
|
align = "left",
|
|
10
11
|
children,
|
|
11
12
|
pl,
|
|
12
|
-
expandable = false,
|
|
13
|
-
onClick,
|
|
14
|
-
onKeyDown,
|
|
15
|
-
reportCellWidth,
|
|
16
|
-
cellIndex,
|
|
17
|
-
leftPosition,
|
|
18
|
-
rightPosition,
|
|
19
13
|
width,
|
|
20
14
|
truncate = false,
|
|
21
15
|
title,
|
|
22
16
|
colspan,
|
|
23
17
|
rowspan,
|
|
18
|
+
id,
|
|
24
19
|
...rest
|
|
25
20
|
}) => {
|
|
26
21
|
const ref = useRef(null);
|
|
27
|
-
const
|
|
22
|
+
const internalId = useRef(id || guid());
|
|
28
23
|
const [tabIndex, setTabIndex] = useState(-1);
|
|
29
24
|
const {
|
|
30
25
|
selectedId
|
|
31
26
|
} = useContext(FlatTableThemeContext);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const {
|
|
28
|
+
leftPosition,
|
|
29
|
+
rightPosition,
|
|
30
|
+
expandable,
|
|
31
|
+
onClick,
|
|
32
|
+
onKeyDown,
|
|
33
|
+
isFirstCell,
|
|
34
|
+
isExpandableCell,
|
|
35
|
+
makeCellSticky
|
|
36
|
+
} = useCalculateStickyCells(internalId.current);
|
|
37
37
|
useEffect(() => {
|
|
38
|
-
setTabIndex(selectedId ===
|
|
39
|
-
}, [selectedId]);
|
|
38
|
+
setTabIndex(isExpandableCell && selectedId === internalId.current ? 0 : -1);
|
|
39
|
+
}, [selectedId, isExpandableCell]);
|
|
40
40
|
return /*#__PURE__*/React.createElement(StyledFlatTableCell, _extends({
|
|
41
41
|
leftPosition: leftPosition,
|
|
42
42
|
rightPosition: rightPosition,
|
|
43
|
-
makeCellSticky:
|
|
44
|
-
className:
|
|
43
|
+
makeCellSticky: makeCellSticky,
|
|
44
|
+
className: makeCellSticky ? "isSticky" : undefined,
|
|
45
45
|
ref: ref,
|
|
46
46
|
align: align,
|
|
47
47
|
"data-element": "flat-table-cell",
|
|
48
48
|
pl: pl,
|
|
49
|
-
onClick:
|
|
50
|
-
tabIndex:
|
|
51
|
-
onKeyDown:
|
|
49
|
+
onClick: isExpandableCell ? onClick : undefined,
|
|
50
|
+
tabIndex: isExpandableCell ? tabIndex : undefined,
|
|
51
|
+
onKeyDown: isExpandableCell ? onKeyDown : undefined,
|
|
52
52
|
colWidth: width,
|
|
53
53
|
isTruncated: truncate,
|
|
54
|
-
expandable: expandable
|
|
55
|
-
id: id.current
|
|
54
|
+
expandable: expandable
|
|
56
55
|
}, colspan !== undefined && {
|
|
57
56
|
colSpan: Number(colspan)
|
|
58
57
|
}, rowspan !== undefined && {
|
|
59
58
|
rowSpan: Number(rowspan)
|
|
60
|
-
}, rest
|
|
59
|
+
}, rest, {
|
|
60
|
+
id: internalId.current
|
|
61
|
+
}), /*#__PURE__*/React.createElement(StyledCellContent, {
|
|
61
62
|
title: truncate && !title && typeof children === "string" ? children : title,
|
|
62
63
|
expandable: expandable
|
|
63
|
-
}, expandable && /*#__PURE__*/React.createElement(Icon, {
|
|
64
|
+
}, expandable && isFirstCell && /*#__PURE__*/React.createElement(Icon, {
|
|
64
65
|
type: "chevron_down_thick",
|
|
65
66
|
bgSize: "extra-small",
|
|
66
67
|
mr: "8px"
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { PaddingProps } from "styled-system";
|
|
2
2
|
import { FlatTableCellProps } from "./flat-table-cell.component";
|
|
3
|
-
interface StyledFlatTableCellProps extends Pick<FlatTableCellProps, "align" | "
|
|
3
|
+
interface StyledFlatTableCellProps extends Pick<FlatTableCellProps, "align" | "verticalBorder" | "verticalBorderColor">, PaddingProps {
|
|
4
4
|
makeCellSticky: boolean;
|
|
5
5
|
colWidth?: number;
|
|
6
6
|
isTruncated: boolean;
|
|
7
|
+
leftPosition: number;
|
|
8
|
+
rightPosition: number;
|
|
9
|
+
expandable?: boolean;
|
|
7
10
|
}
|
|
8
11
|
declare const StyledFlatTableCell: import("styled-components").StyledComponent<"td", any, StyledFlatTableCellProps, never>;
|
|
9
|
-
declare const StyledCellContent: import("styled-components").StyledComponent<"div", any,
|
|
12
|
+
declare const StyledCellContent: import("styled-components").StyledComponent<"div", any, {
|
|
13
|
+
expandable?: boolean | undefined;
|
|
14
|
+
}, never>;
|
|
10
15
|
export { StyledFlatTableCell, StyledCellContent };
|
|
@@ -13,33 +13,11 @@ export interface FlatTableCheckboxProps extends TagProps {
|
|
|
13
13
|
onClick?: (ev: React.MouseEvent<HTMLElement>) => void;
|
|
14
14
|
/** The id of the element that labels the input */
|
|
15
15
|
ariaLabelledBy?: string;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
* @ignore
|
|
19
|
-
* Sets the left position when sticky column found
|
|
20
|
-
*/
|
|
21
|
-
leftPosition?: number;
|
|
22
|
-
/**
|
|
23
|
-
* @private
|
|
24
|
-
* @ignore
|
|
25
|
-
* Sets the right position when sticky column found
|
|
26
|
-
*/
|
|
27
|
-
rightPosition?: number;
|
|
28
|
-
/**
|
|
29
|
-
* @private
|
|
30
|
-
* @ignore
|
|
31
|
-
* Index of cell within row
|
|
32
|
-
*/
|
|
33
|
-
cellIndex?: number;
|
|
34
|
-
/**
|
|
35
|
-
* @private
|
|
36
|
-
* @ignore
|
|
37
|
-
* Callback to report the offsetWidth
|
|
38
|
-
*/
|
|
39
|
-
reportCellWidth?: (offset: number, index?: number) => void;
|
|
16
|
+
/** Sets an id string on the element */
|
|
17
|
+
id?: string;
|
|
40
18
|
}
|
|
41
19
|
export declare const FlatTableCheckbox: {
|
|
42
|
-
({ as, checked, onChange, selectable, onClick,
|
|
20
|
+
({ as, checked, onChange, selectable, onClick, ariaLabelledBy, id, ...rest }: FlatTableCheckboxProps): React.JSX.Element;
|
|
43
21
|
displayName: string;
|
|
44
22
|
};
|
|
45
23
|
export default FlatTableCheckbox;
|
|
@@ -1,28 +1,31 @@
|
|
|
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, {
|
|
2
|
+
import React, { useContext, useRef } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import StyledFlatTableCheckbox from "./flat-table-checkbox.style";
|
|
5
5
|
import { Checkbox } from "../../checkbox";
|
|
6
6
|
import Events from "../../../__internal__/utils/helpers/events/events";
|
|
7
|
+
import tagComponent from "../../../__internal__/utils/helpers/tags";
|
|
8
|
+
import guid from "../../../__internal__/utils/helpers/guid";
|
|
9
|
+
import FlatTableRowContext from "../flat-table-row/__internal__/flat-table-row-context";
|
|
7
10
|
export const FlatTableCheckbox = ({
|
|
8
11
|
as = "td",
|
|
9
12
|
checked,
|
|
10
13
|
onChange,
|
|
11
14
|
selectable = true,
|
|
12
15
|
onClick,
|
|
13
|
-
leftPosition,
|
|
14
|
-
rightPosition,
|
|
15
|
-
cellIndex,
|
|
16
|
-
reportCellWidth,
|
|
17
16
|
ariaLabelledBy,
|
|
17
|
+
id,
|
|
18
18
|
...rest
|
|
19
19
|
}) => {
|
|
20
20
|
const ref = useRef(null);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
21
|
+
const internalId = useRef(id || guid());
|
|
22
|
+
const {
|
|
23
|
+
leftPositions,
|
|
24
|
+
rightPositions
|
|
25
|
+
} = useContext(FlatTableRowContext);
|
|
26
|
+
const leftPosition = leftPositions[internalId.current];
|
|
27
|
+
const rightPosition = rightPositions[internalId.current];
|
|
28
|
+
const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
|
|
26
29
|
const dataElement = `flat-table-checkbox-${as === "td" ? "cell" : "header"}`;
|
|
27
30
|
const handleClick = event => {
|
|
28
31
|
event.stopPropagation();
|
|
@@ -35,13 +38,17 @@ export const FlatTableCheckbox = ({
|
|
|
35
38
|
};
|
|
36
39
|
return /*#__PURE__*/React.createElement(StyledFlatTableCheckbox, _extends({
|
|
37
40
|
ref: ref,
|
|
38
|
-
makeCellSticky:
|
|
39
|
-
className:
|
|
41
|
+
makeCellSticky: makeCellSticky,
|
|
42
|
+
className: makeCellSticky ? "isSticky" : undefined,
|
|
40
43
|
leftPosition: leftPosition,
|
|
41
44
|
rightPosition: rightPosition,
|
|
42
|
-
"data-element": dataElement,
|
|
43
45
|
as: as
|
|
44
|
-
},
|
|
46
|
+
}, tagComponent("flat-table-checkbox", {
|
|
47
|
+
"data-element": dataElement,
|
|
48
|
+
...rest
|
|
49
|
+
}), {
|
|
50
|
+
id: internalId.current
|
|
51
|
+
}), selectable && /*#__PURE__*/React.createElement(Checkbox, {
|
|
45
52
|
checked: checked,
|
|
46
53
|
onChange: onChange,
|
|
47
54
|
name: "flat-table-checkbox",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FlatTableCheckboxProps } from "./flat-table-checkbox.component";
|
|
2
|
-
interface StyledFlatTableCheckboxProps extends Pick<FlatTableCheckboxProps, "as"
|
|
2
|
+
interface StyledFlatTableCheckboxProps extends Pick<FlatTableCheckboxProps, "as"> {
|
|
3
3
|
makeCellSticky: boolean;
|
|
4
|
+
leftPosition: number;
|
|
5
|
+
rightPosition: number;
|
|
4
6
|
}
|
|
5
7
|
declare const StyledFlatTableCheckbox: import("styled-components").StyledComponent<"td", any, StyledFlatTableCheckboxProps, never>;
|
|
6
8
|
export default StyledFlatTableCheckbox;
|
|
@@ -3,5 +3,9 @@ export interface FlatTableHeadProps {
|
|
|
3
3
|
/** Array of FlatTableRow. */
|
|
4
4
|
children: React.ReactNode;
|
|
5
5
|
}
|
|
6
|
+
interface FlatTableHeadContextProps {
|
|
7
|
+
stickyOffsets: Record<string, number>;
|
|
8
|
+
}
|
|
9
|
+
export declare const FlatTableHeadContext: React.Context<FlatTableHeadContextProps>;
|
|
6
10
|
export declare const FlatTableHead: ({ children, ...rest }: FlatTableHeadProps) => React.JSX.Element;
|
|
7
11
|
export default FlatTableHead;
|
|
@@ -1,36 +1,33 @@
|
|
|
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); }
|
|
1
2
|
import React, { useEffect, useState, useRef } from "react";
|
|
2
3
|
import PropTypes from "prop-types";
|
|
3
4
|
import StyledFlatTableHead from "./flat-table-head.style";
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
}
|
|
5
|
+
import { buildPositionMap } from "../__internal__";
|
|
6
|
+
export const FlatTableHeadContext = /*#__PURE__*/React.createContext({
|
|
7
|
+
stickyOffsets: {}
|
|
8
|
+
});
|
|
8
9
|
export const FlatTableHead = ({
|
|
9
10
|
children,
|
|
10
11
|
...rest
|
|
11
12
|
}) => {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
let hasFlatTableRowHeader;
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
const [stickyOffsets, setStickyOffsets] = useState({});
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const headerRows = ref.current?.querySelectorAll("tr");
|
|
17
|
+
|
|
18
|
+
/* istanbul ignore else */
|
|
19
|
+
if (headerRows) {
|
|
20
|
+
setStickyOffsets(buildPositionMap(Array.from(headerRows), "offsetHeight"));
|
|
21
|
+
} else {
|
|
22
|
+
setStickyOffsets({});
|
|
18
23
|
}
|
|
19
24
|
}, [children]);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const previousRowHasHeader = !!hasFlatTableRowHeader;
|
|
28
|
-
hasFlatTableRowHeader = /*#__PURE__*/React.isValidElement(child) && !!React.Children.toArray(child.props.children).find(c => /*#__PURE__*/React.isValidElement(c) && c.type.displayName === FlatTableRowHeader.displayName);
|
|
29
|
-
return /*#__PURE__*/React.isValidElement(child) && /*#__PURE__*/React.cloneElement(child, {
|
|
30
|
-
stickyOffset: rowHeights.slice(0, index).reduce((a, b) => a + b, 0),
|
|
31
|
-
ref: refs.current[index],
|
|
32
|
-
applyBorderLeft: previousRowHasHeader && !hasFlatTableRowHeader
|
|
33
|
-
});
|
|
34
|
-
}));
|
|
25
|
+
return /*#__PURE__*/React.createElement(StyledFlatTableHead, _extends({
|
|
26
|
+
ref: ref
|
|
27
|
+
}, rest), /*#__PURE__*/React.createElement(FlatTableHeadContext.Provider, {
|
|
28
|
+
value: {
|
|
29
|
+
stickyOffsets
|
|
30
|
+
}
|
|
31
|
+
}, children));
|
|
35
32
|
};
|
|
36
33
|
export default FlatTableHead;
|
|
@@ -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
|
|
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,
|
|
25
|
+
({ align, children, colspan, rowspan, width, py, px, id, ...rest }: FlatTableHeaderProps): React.JSX.Element;
|
|
50
26
|
defaultProps: {
|
|
51
27
|
align: string;
|
|
52
28
|
};
|
|
@@ -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, {
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
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:
|
|
34
|
-
className:
|
|
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
|
|
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" | "
|
|
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;
|
|
@@ -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;
|
package/esm/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js
CHANGED
|
@@ -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 =>
|
|
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;
|