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,36 @@
|
|
|
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 _flatTableRowContext = _interopRequireDefault(require("../flat-table-row/__internal__/flat-table-row-context"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
var _default = id => {
|
|
11
|
+
const {
|
|
12
|
+
expandable,
|
|
13
|
+
firstCellId,
|
|
14
|
+
firstColumnExpandable,
|
|
15
|
+
leftPositions,
|
|
16
|
+
rightPositions,
|
|
17
|
+
onClick,
|
|
18
|
+
onKeyDown
|
|
19
|
+
} = (0, _react.useContext)(_flatTableRowContext.default);
|
|
20
|
+
const leftPosition = leftPositions[id];
|
|
21
|
+
const rightPosition = rightPositions[id];
|
|
22
|
+
const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
|
|
23
|
+
const isFirstCell = id === firstCellId;
|
|
24
|
+
const isExpandableCell = expandable && isFirstCell && firstColumnExpandable;
|
|
25
|
+
return {
|
|
26
|
+
expandable,
|
|
27
|
+
leftPosition,
|
|
28
|
+
rightPosition,
|
|
29
|
+
makeCellSticky,
|
|
30
|
+
onClick,
|
|
31
|
+
onKeyDown,
|
|
32
|
+
isFirstCell,
|
|
33
|
+
isExpandableCell
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.default = _default;
|
|
@@ -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;
|
|
@@ -10,6 +10,7 @@ var _flatTableCell = require("./flat-table-cell.style");
|
|
|
10
10
|
var _icon = _interopRequireDefault(require("../../icon"));
|
|
11
11
|
var _flatTable = require("../flat-table.component");
|
|
12
12
|
var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
|
|
13
|
+
var _useCalculateStickyCells = _interopRequireDefault(require("../__internal__/use-calculate-sticky-cells"));
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -18,58 +19,58 @@ const FlatTableCell = ({
|
|
|
18
19
|
align = "left",
|
|
19
20
|
children,
|
|
20
21
|
pl,
|
|
21
|
-
expandable = false,
|
|
22
|
-
onClick,
|
|
23
|
-
onKeyDown,
|
|
24
|
-
reportCellWidth,
|
|
25
|
-
cellIndex,
|
|
26
|
-
leftPosition,
|
|
27
|
-
rightPosition,
|
|
28
22
|
width,
|
|
29
23
|
truncate = false,
|
|
30
24
|
title,
|
|
31
25
|
colspan,
|
|
32
26
|
rowspan,
|
|
27
|
+
id,
|
|
33
28
|
...rest
|
|
34
29
|
}) => {
|
|
35
30
|
const ref = (0, _react.useRef)(null);
|
|
36
|
-
const
|
|
31
|
+
const internalId = (0, _react.useRef)(id || (0, _guid.default)());
|
|
37
32
|
const [tabIndex, setTabIndex] = (0, _react.useState)(-1);
|
|
38
33
|
const {
|
|
39
34
|
selectedId
|
|
40
35
|
} = (0, _react.useContext)(_flatTable.FlatTableThemeContext);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const {
|
|
37
|
+
leftPosition,
|
|
38
|
+
rightPosition,
|
|
39
|
+
expandable,
|
|
40
|
+
onClick,
|
|
41
|
+
onKeyDown,
|
|
42
|
+
isFirstCell,
|
|
43
|
+
isExpandableCell,
|
|
44
|
+
makeCellSticky
|
|
45
|
+
} = (0, _useCalculateStickyCells.default)(internalId.current);
|
|
46
46
|
(0, _react.useEffect)(() => {
|
|
47
|
-
setTabIndex(selectedId ===
|
|
48
|
-
}, [selectedId]);
|
|
47
|
+
setTabIndex(isExpandableCell && selectedId === internalId.current ? 0 : -1);
|
|
48
|
+
}, [selectedId, isExpandableCell]);
|
|
49
49
|
return /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledFlatTableCell, _extends({
|
|
50
50
|
leftPosition: leftPosition,
|
|
51
51
|
rightPosition: rightPosition,
|
|
52
|
-
makeCellSticky:
|
|
53
|
-
className:
|
|
52
|
+
makeCellSticky: makeCellSticky,
|
|
53
|
+
className: makeCellSticky ? "isSticky" : undefined,
|
|
54
54
|
ref: ref,
|
|
55
55
|
align: align,
|
|
56
56
|
"data-element": "flat-table-cell",
|
|
57
57
|
pl: pl,
|
|
58
|
-
onClick:
|
|
59
|
-
tabIndex:
|
|
60
|
-
onKeyDown:
|
|
58
|
+
onClick: isExpandableCell ? onClick : undefined,
|
|
59
|
+
tabIndex: isExpandableCell ? tabIndex : undefined,
|
|
60
|
+
onKeyDown: isExpandableCell ? onKeyDown : undefined,
|
|
61
61
|
colWidth: width,
|
|
62
62
|
isTruncated: truncate,
|
|
63
|
-
expandable: expandable
|
|
64
|
-
id: id.current
|
|
63
|
+
expandable: expandable
|
|
65
64
|
}, colspan !== undefined && {
|
|
66
65
|
colSpan: Number(colspan)
|
|
67
66
|
}, rowspan !== undefined && {
|
|
68
67
|
rowSpan: Number(rowspan)
|
|
69
|
-
}, rest
|
|
68
|
+
}, rest, {
|
|
69
|
+
id: internalId.current
|
|
70
|
+
}), /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledCellContent, {
|
|
70
71
|
title: truncate && !title && typeof children === "string" ? children : title,
|
|
71
72
|
expandable: expandable
|
|
72
|
-
}, expandable && /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
73
|
+
}, expandable && isFirstCell && /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
73
74
|
type: "chevron_down_thick",
|
|
74
75
|
bgSize: "extra-small",
|
|
75
76
|
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;
|
|
@@ -9,6 +9,9 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _flatTableCheckbox = _interopRequireDefault(require("./flat-table-checkbox.style"));
|
|
10
10
|
var _checkbox = require("../../checkbox");
|
|
11
11
|
var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events/events"));
|
|
12
|
+
var _tags = _interopRequireDefault(require("../../../__internal__/utils/helpers/tags"));
|
|
13
|
+
var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
|
|
14
|
+
var _flatTableRowContext = _interopRequireDefault(require("../flat-table-row/__internal__/flat-table-row-context"));
|
|
12
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
16
|
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); }
|
|
14
17
|
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; }
|
|
@@ -19,19 +22,19 @@ const FlatTableCheckbox = ({
|
|
|
19
22
|
onChange,
|
|
20
23
|
selectable = true,
|
|
21
24
|
onClick,
|
|
22
|
-
leftPosition,
|
|
23
|
-
rightPosition,
|
|
24
|
-
cellIndex,
|
|
25
|
-
reportCellWidth,
|
|
26
25
|
ariaLabelledBy,
|
|
26
|
+
id,
|
|
27
27
|
...rest
|
|
28
28
|
}) => {
|
|
29
29
|
const ref = (0, _react.useRef)(null);
|
|
30
|
-
(0, _react.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
30
|
+
const internalId = (0, _react.useRef)(id || (0, _guid.default)());
|
|
31
|
+
const {
|
|
32
|
+
leftPositions,
|
|
33
|
+
rightPositions
|
|
34
|
+
} = (0, _react.useContext)(_flatTableRowContext.default);
|
|
35
|
+
const leftPosition = leftPositions[internalId.current];
|
|
36
|
+
const rightPosition = rightPositions[internalId.current];
|
|
37
|
+
const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
|
|
35
38
|
const dataElement = `flat-table-checkbox-${as === "td" ? "cell" : "header"}`;
|
|
36
39
|
const handleClick = event => {
|
|
37
40
|
event.stopPropagation();
|
|
@@ -44,13 +47,17 @@ const FlatTableCheckbox = ({
|
|
|
44
47
|
};
|
|
45
48
|
return /*#__PURE__*/_react.default.createElement(_flatTableCheckbox.default, _extends({
|
|
46
49
|
ref: ref,
|
|
47
|
-
makeCellSticky:
|
|
48
|
-
className:
|
|
50
|
+
makeCellSticky: makeCellSticky,
|
|
51
|
+
className: makeCellSticky ? "isSticky" : undefined,
|
|
49
52
|
leftPosition: leftPosition,
|
|
50
53
|
rightPosition: rightPosition,
|
|
51
|
-
"data-element": dataElement,
|
|
52
54
|
as: as
|
|
53
|
-
},
|
|
55
|
+
}, (0, _tags.default)("flat-table-checkbox", {
|
|
56
|
+
"data-element": dataElement,
|
|
57
|
+
...rest
|
|
58
|
+
}), {
|
|
59
|
+
id: internalId.current
|
|
60
|
+
}), selectable && /*#__PURE__*/_react.default.createElement(_checkbox.Checkbox, {
|
|
54
61
|
checked: checked,
|
|
55
62
|
onChange: onChange,
|
|
56
63
|
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;
|
|
@@ -3,44 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.FlatTableHead = void 0;
|
|
6
|
+
exports.default = exports.FlatTableHeadContext = exports.FlatTableHead = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _flatTableHead = _interopRequireDefault(require("./flat-table-head.style"));
|
|
10
|
-
var
|
|
10
|
+
var _internal__ = require("../__internal__");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
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
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
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); }
|
|
15
|
+
const FlatTableHeadContext = /*#__PURE__*/_react.default.createContext({
|
|
16
|
+
stickyOffsets: {}
|
|
17
|
+
});
|
|
18
|
+
exports.FlatTableHeadContext = FlatTableHeadContext;
|
|
17
19
|
const FlatTableHead = ({
|
|
18
20
|
children,
|
|
19
21
|
...rest
|
|
20
22
|
}) => {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
let hasFlatTableRowHeader;
|
|
23
|
+
const ref = (0, _react.useRef)(null);
|
|
24
|
+
const [stickyOffsets, setStickyOffsets] = (0, _react.useState)({});
|
|
24
25
|
(0, _react.useEffect)(() => {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const headerRows = ref.current?.querySelectorAll("tr");
|
|
27
|
+
|
|
28
|
+
/* istanbul ignore else */
|
|
29
|
+
if (headerRows) {
|
|
30
|
+
setStickyOffsets((0, _internal__.buildPositionMap)(Array.from(headerRows), "offsetHeight"));
|
|
31
|
+
} else {
|
|
32
|
+
setStickyOffsets({});
|
|
27
33
|
}
|
|
28
34
|
}, [children]);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const previousRowHasHeader = !!hasFlatTableRowHeader;
|
|
37
|
-
hasFlatTableRowHeader = /*#__PURE__*/_react.default.isValidElement(child) && !!_react.default.Children.toArray(child.props.children).find(c => /*#__PURE__*/_react.default.isValidElement(c) && c.type.displayName === _flatTableRowHeader.default.displayName);
|
|
38
|
-
return /*#__PURE__*/_react.default.isValidElement(child) && /*#__PURE__*/_react.default.cloneElement(child, {
|
|
39
|
-
stickyOffset: rowHeights.slice(0, index).reduce((a, b) => a + b, 0),
|
|
40
|
-
ref: refs.current[index],
|
|
41
|
-
applyBorderLeft: previousRowHasHeader && !hasFlatTableRowHeader
|
|
42
|
-
});
|
|
43
|
-
}));
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_flatTableHead.default, _extends({
|
|
36
|
+
ref: ref
|
|
37
|
+
}, rest), /*#__PURE__*/_react.default.createElement(FlatTableHeadContext.Provider, {
|
|
38
|
+
value: {
|
|
39
|
+
stickyOffsets
|
|
40
|
+
}
|
|
41
|
+
}, children));
|
|
44
42
|
};
|
|
45
43
|
exports.FlatTableHead = FlatTableHead;
|
|
46
44
|
var _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
|
};
|
|
@@ -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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
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:
|
|
43
|
-
className:
|
|
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
|
|
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" | "
|
|
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;
|
package/lib/components/flat-table/flat-table-row/__internal__/flat-table-row-draggable.component.js
CHANGED
|
@@ -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 =>
|
|
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;
|