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.
- package/esm/__internal__/input/input-presentation.style.d.ts +1 -1
- package/esm/__spec_helper__/test-utils.d.ts +3 -2
- package/esm/__spec_helper__/test-utils.js +15 -1
- package/esm/components/box/box.component.d.ts +23 -6
- package/esm/components/box/box.component.js +3570 -103
- package/esm/components/box/box.style.d.ts +3 -0
- package/esm/components/box/box.style.js +112 -0
- package/esm/components/dismissible-box/dismissible-box.style.d.ts +2 -1
- package/esm/components/drawer/drawer.style.d.ts +2 -1
- package/esm/components/duelling-picklist/picklist/picklist.style.js +4 -2
- 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/esm/components/flat-table/flat-table.style.js +2 -2
- package/esm/components/heading/heading.style.d.ts +4 -9
- package/esm/components/menu/menu-full-screen/menu-full-screen.style.js +2 -2
- package/esm/components/menu/scrollable-block/scrollable-block.style.js +2 -2
- package/esm/components/typography/typography.component.d.ts +25 -15
- package/esm/components/typography/typography.component.js +37 -184
- package/esm/components/typography/typography.style.d.ts +12 -0
- package/esm/components/typography/typography.style.js +190 -0
- package/esm/components/vertical-menu/vertical-menu.style.js +3 -3
- package/esm/style/utils/filter-styled-system-flexbox-props.d.ts +3 -0
- package/esm/style/utils/filter-styled-system-flexbox-props.js +5 -0
- package/esm/style/utils/filter-styled-system-grid-props.d.ts +3 -0
- package/esm/style/utils/filter-styled-system-grid-props.js +5 -0
- package/esm/style/utils/filter-styled-system-layout-props.d.ts +3 -0
- package/esm/style/utils/filter-styled-system-layout-props.js +5 -0
- package/esm/style/utils/index.d.ts +4 -1
- package/esm/style/utils/index.js +4 -1
- package/lib/__internal__/input/input-presentation.style.d.ts +1 -1
- package/lib/__spec_helper__/test-utils.d.ts +3 -2
- package/lib/__spec_helper__/test-utils.js +16 -1
- package/lib/components/box/box.component.d.ts +23 -6
- package/lib/components/box/box.component.js +3569 -105
- package/lib/components/box/box.style.d.ts +3 -0
- package/lib/components/box/box.style.js +122 -0
- package/lib/components/dismissible-box/dismissible-box.style.d.ts +2 -1
- package/lib/components/drawer/drawer.style.d.ts +2 -1
- package/lib/components/duelling-picklist/picklist/picklist.style.js +2 -1
- 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/lib/components/flat-table/flat-table.style.js +1 -1
- package/lib/components/heading/heading.style.d.ts +4 -9
- package/lib/components/menu/menu-full-screen/menu-full-screen.style.js +1 -1
- package/lib/components/menu/scrollable-block/scrollable-block.style.js +1 -1
- package/lib/components/typography/typography.component.d.ts +25 -15
- package/lib/components/typography/typography.component.js +39 -187
- package/lib/components/typography/typography.style.d.ts +12 -0
- package/lib/components/typography/typography.style.js +200 -0
- package/lib/components/vertical-menu/vertical-menu.style.js +1 -1
- package/lib/style/utils/filter-styled-system-flexbox-props.d.ts +3 -0
- package/lib/style/utils/filter-styled-system-flexbox-props.js +14 -0
- package/lib/style/utils/filter-styled-system-grid-props.d.ts +3 -0
- package/lib/style/utils/filter-styled-system-grid-props.js +14 -0
- package/lib/style/utils/filter-styled-system-layout-props.d.ts +3 -0
- package/lib/style/utils/filter-styled-system-layout-props.js +14 -0
- package/lib/style/utils/index.d.ts +4 -1
- package/lib/style/utils/index.js +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import { space, layout, flexbox, grid, position as positionFn } from "styled-system";
|
|
3
|
+
import BaseTheme from "../../style/themes/base";
|
|
4
|
+
import styledColor from "../../style/utils/color";
|
|
5
|
+
import boxConfig from "./box.config";
|
|
6
|
+
const calculatePosition = props => {
|
|
7
|
+
const {
|
|
8
|
+
position,
|
|
9
|
+
...rest
|
|
10
|
+
} = positionFn(props);
|
|
11
|
+
return {
|
|
12
|
+
position,
|
|
13
|
+
zIndex: ["sticky", "fixed"].includes(position) ? 1 : undefined,
|
|
14
|
+
...rest
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const StyledBox = styled.div`
|
|
18
|
+
${space}
|
|
19
|
+
${layout}
|
|
20
|
+
${flexbox}
|
|
21
|
+
${grid}
|
|
22
|
+
${calculatePosition}
|
|
23
|
+
|
|
24
|
+
${({
|
|
25
|
+
theme,
|
|
26
|
+
borderRadius = "borderRadius000"
|
|
27
|
+
}) => !theme.roundedCornersOptOut && css`
|
|
28
|
+
border-radius: var(--${borderRadius});
|
|
29
|
+
`}
|
|
30
|
+
|
|
31
|
+
${({
|
|
32
|
+
color,
|
|
33
|
+
bg,
|
|
34
|
+
backgroundColor,
|
|
35
|
+
...rest
|
|
36
|
+
}) => styledColor({
|
|
37
|
+
color,
|
|
38
|
+
bg,
|
|
39
|
+
backgroundColor,
|
|
40
|
+
...rest
|
|
41
|
+
})}
|
|
42
|
+
|
|
43
|
+
${({
|
|
44
|
+
overflowWrap
|
|
45
|
+
}) => overflowWrap && css`
|
|
46
|
+
overflow-wrap: ${overflowWrap};
|
|
47
|
+
`}
|
|
48
|
+
|
|
49
|
+
${({
|
|
50
|
+
height
|
|
51
|
+
}) => height && css`
|
|
52
|
+
height: ${height};
|
|
53
|
+
`}
|
|
54
|
+
|
|
55
|
+
${({
|
|
56
|
+
width
|
|
57
|
+
}) => width && css`
|
|
58
|
+
width: ${width};
|
|
59
|
+
`}
|
|
60
|
+
|
|
61
|
+
${({
|
|
62
|
+
scrollVariant
|
|
63
|
+
}) => scrollVariant && css`
|
|
64
|
+
scrollbar-color: ${boxConfig[scrollVariant].thumb}
|
|
65
|
+
${boxConfig[scrollVariant].track};
|
|
66
|
+
|
|
67
|
+
&::-webkit-scrollbar {
|
|
68
|
+
width: 8px;
|
|
69
|
+
}
|
|
70
|
+
&::-webkit-scrollbar-track {
|
|
71
|
+
background-color: ${boxConfig[scrollVariant].track};
|
|
72
|
+
}
|
|
73
|
+
&::-webkit-scrollbar-thumb {
|
|
74
|
+
background-color: ${boxConfig[scrollVariant].thumb};
|
|
75
|
+
}
|
|
76
|
+
`}
|
|
77
|
+
|
|
78
|
+
${({
|
|
79
|
+
boxSizing
|
|
80
|
+
}) => boxSizing && css`
|
|
81
|
+
box-sizing: ${boxSizing};
|
|
82
|
+
`}
|
|
83
|
+
|
|
84
|
+
${({
|
|
85
|
+
display,
|
|
86
|
+
gap,
|
|
87
|
+
columnGap,
|
|
88
|
+
rowGap
|
|
89
|
+
}) => (display === "flex" || display === "inline-flex" || display === "grid" || display === "inline-grid") && css`
|
|
90
|
+
${gap !== undefined && css`
|
|
91
|
+
gap: ${boxConfig.gap(gap)};
|
|
92
|
+
`}
|
|
93
|
+
|
|
94
|
+
${columnGap !== undefined && css`
|
|
95
|
+
column-gap: ${boxConfig.gap(columnGap)};
|
|
96
|
+
`}
|
|
97
|
+
|
|
98
|
+
${rowGap !== undefined && css`
|
|
99
|
+
row-gap: ${boxConfig.gap(rowGap)};
|
|
100
|
+
`}
|
|
101
|
+
`};
|
|
102
|
+
|
|
103
|
+
${({
|
|
104
|
+
boxShadow
|
|
105
|
+
}) => boxShadow && css`
|
|
106
|
+
box-shadow: var(--${boxShadow});
|
|
107
|
+
`}
|
|
108
|
+
`;
|
|
109
|
+
StyledBox.defaultProps = {
|
|
110
|
+
theme: BaseTheme
|
|
111
|
+
};
|
|
112
|
+
export default StyledBox;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export interface StyledDismissibleBoxProps {
|
|
2
3
|
/** Flag to control whether the thicker left border highlight should be rendered */
|
|
3
4
|
hasBorderLeftHighlight?: boolean;
|
|
4
5
|
/** Set the base color variant */
|
|
5
6
|
variant?: "light" | "dark";
|
|
6
7
|
}
|
|
7
|
-
declare const StyledDismissibleBox: import("styled-components").StyledComponent<"
|
|
8
|
+
declare const StyledDismissibleBox: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../box").BoxProps & import("react").RefAttributes<HTMLDivElement>>, any, StyledDismissibleBoxProps, never>;
|
|
8
9
|
export { StyledDismissibleBox };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
declare const StyledSidebarHeader: import("styled-components").StyledComponent<"div", any, {
|
|
2
3
|
isExpanded?: boolean | undefined;
|
|
3
4
|
}, never>;
|
|
@@ -7,7 +8,7 @@ interface StyledDrawerSidebarProps {
|
|
|
7
8
|
isExpanded?: boolean;
|
|
8
9
|
hasControls: boolean;
|
|
9
10
|
}
|
|
10
|
-
declare const StyledDrawerSidebar: import("styled-components").StyledComponent<"
|
|
11
|
+
declare const StyledDrawerSidebar: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../box").BoxProps & import("react").RefAttributes<HTMLDivElement>>, any, StyledDrawerSidebarProps, never>;
|
|
11
12
|
interface StyledDrawerContentProps {
|
|
12
13
|
animationDuration?: string;
|
|
13
14
|
backgroundColor?: string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import StyledBox from "../../box/box.style";
|
|
3
|
+
|
|
4
|
+
// TODO: remove polymorphism when we revisit as part of ticket FE-6177
|
|
5
|
+
const StyledPicklist = styled(StyledBox).attrs({
|
|
4
6
|
as: "ul"
|
|
5
7
|
})`
|
|
6
8
|
position: relative;
|
|
@@ -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
|
};
|