carbon-react 120.0.0 → 120.2.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/__spec_helper__/test-utils.js +16 -8
- package/esm/components/button-toggle/button-toggle-group/button-toggle-group.component.js +2 -0
- 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/heading/heading.style.d.ts +1 -1
- package/esm/components/typography/typography.component.d.ts +4 -1
- package/esm/components/typography/typography.component.js +3 -1
- package/esm/components/typography/typography.style.js +4 -1
- package/lib/__spec_helper__/test-utils.js +16 -8
- package/lib/components/button-toggle/button-toggle-group/button-toggle-group.component.js +2 -0
- 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/heading/heading.style.d.ts +1 -1
- package/lib/components/typography/typography.component.d.ts +4 -1
- package/lib/components/typography/typography.component.js +3 -1
- package/lib/components/typography/typography.style.js +4 -1
- package/package.json +3 -2
|
@@ -12,7 +12,7 @@ declare type StyledHeadingTitleProps = {
|
|
|
12
12
|
withMargin?: boolean;
|
|
13
13
|
};
|
|
14
14
|
declare const StyledHeadingTitle: import("styled-components").StyledComponent<{
|
|
15
|
-
({ "data-component": dataComponent, variant, as, id, fontSize, fontWeight, textTransform, lineHeight, textDecoration, display, listStyleType, whiteSpace, wordWrap, textOverflow, truncate, color, backgroundColor, bg, opacity, children, className, ...rest }: import("../typography").TypographyProps): import("react").JSX.Element;
|
|
15
|
+
({ "data-component": dataComponent, variant, as, id, fontSize, fontWeight, textTransform, lineHeight, textDecoration, display, listStyleType, whiteSpace, wordWrap, textOverflow, truncate, color, backgroundColor, bg, opacity, children, className, screenReaderOnly, ...rest }: import("../typography").TypographyProps): import("react").JSX.Element;
|
|
16
16
|
displayName: string;
|
|
17
17
|
}, any, StyledHeadingTitleProps, never>;
|
|
18
18
|
declare const StyledHeadingPills: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
@@ -44,9 +44,12 @@ export interface TypographyProps extends SpaceProps, TagProps {
|
|
|
44
44
|
opacity?: string | number;
|
|
45
45
|
/** @private @ignore */
|
|
46
46
|
className?: string;
|
|
47
|
+
/** Set whether it will be visually hidden
|
|
48
|
+
* NOTE: This is for screen readers only and will make a lot of the other props redundant */
|
|
49
|
+
screenReaderOnly?: boolean;
|
|
47
50
|
}
|
|
48
51
|
export declare const Typography: {
|
|
49
|
-
({ "data-component": dataComponent, variant, as, id, fontSize, fontWeight, textTransform, lineHeight, textDecoration, display, listStyleType, whiteSpace, wordWrap, textOverflow, truncate, color, backgroundColor, bg, opacity, children, className, ...rest }: TypographyProps): React.JSX.Element;
|
|
52
|
+
({ "data-component": dataComponent, variant, as, id, fontSize, fontWeight, textTransform, lineHeight, textDecoration, display, listStyleType, whiteSpace, wordWrap, textOverflow, truncate, color, backgroundColor, bg, opacity, children, className, screenReaderOnly, ...rest }: TypographyProps): React.JSX.Element;
|
|
50
53
|
displayName: string;
|
|
51
54
|
};
|
|
52
55
|
export default Typography;
|
|
@@ -27,6 +27,7 @@ export const Typography = ({
|
|
|
27
27
|
opacity,
|
|
28
28
|
children,
|
|
29
29
|
className,
|
|
30
|
+
screenReaderOnly,
|
|
30
31
|
...rest
|
|
31
32
|
}) => {
|
|
32
33
|
return /*#__PURE__*/React.createElement(StyledTypography, _extends({
|
|
@@ -48,7 +49,8 @@ export const Typography = ({
|
|
|
48
49
|
backgroundColor: backgroundColor,
|
|
49
50
|
bg: bg,
|
|
50
51
|
opacity: opacity,
|
|
51
|
-
className: className
|
|
52
|
+
className: className,
|
|
53
|
+
screenReaderOnly: screenReaderOnly
|
|
52
54
|
}, tagComponent(dataComponent, rest), filterStyledSystemMarginProps(rest), filterStyledSystemPaddingProps(rest)), children);
|
|
53
55
|
};
|
|
54
56
|
Typography.displayName = "Typography";
|
|
@@ -2,6 +2,7 @@ import styled, { css } from "styled-components";
|
|
|
2
2
|
import { space } from "styled-system";
|
|
3
3
|
import styledColor from "../../style/utils/color";
|
|
4
4
|
import baseTheme from "../../style/themes/base";
|
|
5
|
+
import visuallyHidden from "../../style/utils/visually-hidden";
|
|
5
6
|
const getAs = variant => {
|
|
6
7
|
switch (variant) {
|
|
7
8
|
case "h1-large":
|
|
@@ -149,7 +150,8 @@ const StyledTypography = styled.span.attrs(({
|
|
|
149
150
|
whiteSpace,
|
|
150
151
|
wordWrap,
|
|
151
152
|
textOverflow,
|
|
152
|
-
truncate
|
|
153
|
+
truncate,
|
|
154
|
+
screenReaderOnly
|
|
153
155
|
}) => css`
|
|
154
156
|
font-style: normal;
|
|
155
157
|
font-size: ${size};
|
|
@@ -165,6 +167,7 @@ const StyledTypography = styled.span.attrs(({
|
|
|
165
167
|
${truncate && css`
|
|
166
168
|
overflow: hidden;
|
|
167
169
|
`};
|
|
170
|
+
${screenReaderOnly && visuallyHidden}
|
|
168
171
|
${variant === "sup" && "vertical-align: super;"};
|
|
169
172
|
${variant === "sub" && "vertical-align: sub;"};
|
|
170
173
|
${display && `display: ${display};`};
|
|
@@ -133,10 +133,14 @@ const getDefaultValue = value => {
|
|
|
133
133
|
exports.getDefaultValue = getDefaultValue;
|
|
134
134
|
const testStyledSystemMargin = (component, defaults, styleContainer, assertOpts) => {
|
|
135
135
|
describe("default props", () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
let wrapper;
|
|
137
|
+
let StyleElement;
|
|
138
|
+
beforeAll(() => {
|
|
139
|
+
wrapper = (0, _enzyme.mount)(component({
|
|
140
|
+
...defaults
|
|
141
|
+
}));
|
|
142
|
+
StyleElement = styleContainer ? styleContainer(wrapper) : wrapper;
|
|
143
|
+
});
|
|
140
144
|
it("should set the correct margins", () => {
|
|
141
145
|
let margin;
|
|
142
146
|
let marginLeft;
|
|
@@ -182,10 +186,14 @@ const testStyledSystemMargin = (component, defaults, styleContainer, assertOpts)
|
|
|
182
186
|
exports.testStyledSystemMargin = testStyledSystemMargin;
|
|
183
187
|
const testStyledSystemPadding = (component, defaults, styleContainer, assertOpts) => {
|
|
184
188
|
describe("default props", () => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
let wrapper;
|
|
190
|
+
let StyleElement;
|
|
191
|
+
beforeAll(() => {
|
|
192
|
+
wrapper = (0, _enzyme.mount)(component({
|
|
193
|
+
...defaults
|
|
194
|
+
}));
|
|
195
|
+
StyleElement = styleContainer ? styleContainer(wrapper) : wrapper;
|
|
196
|
+
});
|
|
189
197
|
it("should set the correct paddings", () => {
|
|
190
198
|
let padding;
|
|
191
199
|
let paddingLeft;
|
|
@@ -106,8 +106,10 @@ const ButtonToggleGroup = ({
|
|
|
106
106
|
// guard needed to avoid warnings about setting state on an unmounted component - the callback ref will
|
|
107
107
|
// get called with null when the component is about to be unmounted, and it has been unmounted by the time
|
|
108
108
|
// the setTimeout completes
|
|
109
|
+
/* istanbul ignore else */
|
|
109
110
|
if (button) {
|
|
110
111
|
const innerButtons = getInnerButtons();
|
|
112
|
+
/* istanbul ignore if */
|
|
111
113
|
if (!innerButtons) {
|
|
112
114
|
setFirstButton(undefined);
|
|
113
115
|
} else if (button === innerButtons[0]) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = (array, propertyName) => array.reduce((acc, _, index) => {
|
|
8
|
+
const currentId = array[index].getAttribute("id");
|
|
9
|
+
if (currentId) {
|
|
10
|
+
if (index === 0) {
|
|
11
|
+
acc[currentId] = 0;
|
|
12
|
+
} else {
|
|
13
|
+
const previousId = array[index - 1].getAttribute("id");
|
|
14
|
+
if (previousId) {
|
|
15
|
+
acc[currentId] = acc[previousId] + array[index - 1][propertyName];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
exports.default = _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "buildPositionMap", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _buildPositionMap.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useCalculateStickyCells", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useCalculateStickyCells.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _useCalculateStickyCells = _interopRequireDefault(require("./use-calculate-sticky-cells"));
|
|
19
|
+
var _buildPositionMap = _interopRequireDefault(require("./build-position-map"));
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -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,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
|
};
|