akeneo-design-system 0.1.178 → 0.1.181
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/lib/components/Block/Block.d.ts +12 -9
- package/lib/components/Block/Block.js +41 -22
- package/lib/components/Block/Block.js.map +1 -1
- package/lib/components/Table/Table.d.ts +4 -2
- package/lib/components/Table/Table.js +2 -2
- package/lib/components/Table/Table.js.map +1 -1
- package/lib/components/Table/TableContext.d.ts +1 -0
- package/lib/components/Table/TableContext.js +1 -0
- package/lib/components/Table/TableContext.js.map +1 -1
- package/lib/components/Table/TableHeader/TableHeader.js +5 -3
- package/lib/components/Table/TableHeader/TableHeader.js.map +1 -1
- package/lib/components/Table/TableRow/TableRow.d.ts +4 -1
- package/lib/components/Table/TableRow/TableRow.js +12 -7
- package/lib/components/Table/TableRow/TableRow.js.map +1 -1
- package/package.json +1 -1
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-block-standard-correctly-1-snap.png +0 -0
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-block-with-actions-correctly-1-snap.png +0 -0
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-block-without-actions-correctly-1-snap.png +0 -0
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-table-warnable-rows-correctly-1-snap.png +0 -0
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-table-warning-rows-correctly-1-snap.png +0 -0
- package/src/components/Block/Block.stories.mdx +27 -11
- package/src/components/Block/Block.tsx +135 -34
- package/src/components/Block/Block.unit.tsx +63 -10
- package/src/components/Table/Table.stories.mdx +53 -0
- package/src/components/Table/Table.tsx +8 -2
- package/src/components/Table/TableContext.ts +2 -0
- package/src/components/Table/TableHeader/TableHeader.tsx +6 -1
- package/src/components/Table/TableRow/TableRow.tsx +28 -2
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { Override } from '../../shared';
|
|
3
3
|
declare type BlockProps = Override<Override<React.ButtonHTMLAttributes<HTMLButtonElement>, React.AnchorHTMLAttributes<HTMLAnchorElement>>, {
|
|
4
|
-
|
|
4
|
+
title: string;
|
|
5
|
+
actions?: ReactNode;
|
|
5
6
|
ariaLabel?: string;
|
|
6
7
|
ariaLabelledBy?: string;
|
|
7
8
|
ariaDescribedBy?: string;
|
|
8
9
|
children?: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
} & ({
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
collapseButtonLabel: string;
|
|
13
|
+
onCollapse: (isOpen: boolean) => void;
|
|
14
|
+
} | {
|
|
15
|
+
isOpen?: undefined;
|
|
16
|
+
collapseButtonLabel?: undefined;
|
|
17
|
+
onCollapse?: undefined;
|
|
18
|
+
})>;
|
|
19
|
+
declare const Block: React.ForwardRefExoticComponent<BlockProps & React.RefAttributes<HTMLButtonElement>>;
|
|
17
20
|
export { Block };
|
|
18
21
|
export type { BlockProps };
|
|
@@ -44,35 +44,54 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
44
|
}
|
|
45
45
|
return t;
|
|
46
46
|
};
|
|
47
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
50
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
48
|
exports.Block = void 0;
|
|
52
49
|
var react_1 = __importStar(require("react"));
|
|
53
|
-
var styled_components_1 =
|
|
50
|
+
var styled_components_1 = __importStar(require("styled-components"));
|
|
54
51
|
var theme_1 = require("../../theme");
|
|
52
|
+
var icons_1 = require("../../icons");
|
|
55
53
|
var IconButton_1 = require("../IconButton/IconButton");
|
|
56
|
-
var
|
|
57
|
-
var
|
|
54
|
+
var ANIMATION_DURATION = 100;
|
|
55
|
+
var ActionsContainer = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n column-gap: 10px;\n justify-content: space-between;\n"], ["\n display: flex;\n align-items: center;\n column-gap: 10px;\n justify-content: space-between;\n"])));
|
|
56
|
+
var BlockTitle = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n min-height: 24px;\n"], ["\n display: flex;\n align-items: center;\n justify-content: space-between;\n min-height: 24px;\n"])));
|
|
57
|
+
var BlockContent = styled_components_1.default.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n overflow-wrap: break-word;\n white-space: break-spaces;\n color: ", ";\n margin-top: ", "px;\n ", "\n"], ["\n overflow-wrap: break-word;\n white-space: break-spaces;\n color: ", ";\n margin-top: ", "px;\n ", "\n"])), (0, theme_1.getColor)('grey', 140), function (_a) {
|
|
58
|
+
var $height = _a.$height, isCollapsable = _a.isCollapsable;
|
|
59
|
+
return (0 === $height && isCollapsable ? 0 : 5);
|
|
60
|
+
}, function (_a) {
|
|
61
|
+
var isCollapsable = _a.isCollapsable, $height = _a.$height, $overflow = _a.$overflow, shouldAnimate = _a.shouldAnimate;
|
|
62
|
+
return isCollapsable && (0, styled_components_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n max-height: ", "px;\n overflow: ", ";\n ", "\n "], ["\n max-height: ", "px;\n overflow: ", ";\n ", "\n "])), $height, $overflow, shouldAnimate && (0, styled_components_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n transition: all ", "ms ease-in-out;\n transition-property: max-height, margin-top;\n "], ["\n transition: all ", "ms ease-in-out;\n transition-property: max-height, margin-top;\n "])), ANIMATION_DURATION));
|
|
63
|
+
});
|
|
64
|
+
var Container = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n box-sizing: border-box;\n padding: 10px 15px;\n border-style: solid;\n border-width: 1px;\n border-radius: 2px;\n display: flex;\n flex-direction: column;\n font-family: inherit;\n font-size: ", ";\n font-weight: 400;\n\n background-color: ", ";\n border-color: ", ";\n color: ", ";\n\n &:hover {\n background-color: ", ";\n }\n"], ["\n box-sizing: border-box;\n padding: 10px 15px;\n border-style: solid;\n border-width: 1px;\n border-radius: 2px;\n display: flex;\n flex-direction: column;\n font-family: inherit;\n font-size: ", ";\n font-weight: 400;\n\n background-color: ", ";\n border-color: ", ";\n color: ", ";\n\n &:hover {\n background-color: ", ";\n }\n"])), (0, theme_1.getFontSize)('default'), (0, theme_1.getColor)('white'), (0, theme_1.getColor)('grey', 80), (0, theme_1.getColor)('grey', 140), (0, theme_1.getColor)('grey', 20));
|
|
58
65
|
var Block = react_1.default.forwardRef(function (_a, forwardedRef) {
|
|
59
|
-
var
|
|
66
|
+
var title = _a.title, actions = _a.actions, ariaDescribedBy = _a.ariaDescribedBy, ariaLabel = _a.ariaLabel, ariaLabelledBy = _a.ariaLabelledBy, isOpen = _a.isOpen, collapseButtonLabel = _a.collapseButtonLabel, onCollapse = _a.onCollapse, children = _a.children, rest = __rest(_a, ["title", "actions", "ariaDescribedBy", "ariaLabel", "ariaLabelledBy", "isOpen", "collapseButtonLabel", "onCollapse", "children"]);
|
|
67
|
+
var _b = (0, react_1.useState)(0), contentHeight = _b[0], setContentHeight = _b[1];
|
|
68
|
+
var _c = (0, react_1.useState)(false), shouldAnimate = _c[0], setShouldAnimate = _c[1];
|
|
69
|
+
var contentRef = (0, react_1.useRef)(null);
|
|
70
|
+
var isCollapsable = undefined !== collapseButtonLabel && undefined !== onCollapse && undefined !== isOpen;
|
|
71
|
+
var handleCollapse = function () { return onCollapse === null || onCollapse === void 0 ? void 0 : onCollapse(!isOpen); };
|
|
72
|
+
(0, react_1.useEffect)(function () {
|
|
73
|
+
if (!isCollapsable)
|
|
74
|
+
return;
|
|
75
|
+
setContentHeight(function (contentHeight) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
var scrollHeight = (_b = (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) !== null && _b !== void 0 ? _b : 0;
|
|
78
|
+
return 0 === scrollHeight ? contentHeight : scrollHeight;
|
|
79
|
+
});
|
|
80
|
+
var shouldAnimateTimeoutId = window.setTimeout(function () {
|
|
81
|
+
setShouldAnimate(true);
|
|
82
|
+
}, ANIMATION_DURATION);
|
|
83
|
+
return function () {
|
|
84
|
+
window.clearTimeout(shouldAnimateTimeoutId);
|
|
85
|
+
};
|
|
86
|
+
}, [children]);
|
|
60
87
|
return (react_1.default.createElement(Container, __assign({ "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ref: forwardedRef }, rest),
|
|
61
|
-
react_1.default.createElement(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})),
|
|
68
|
-
react_1.default.createElement(ActionsContainer, null, (0, react_1.isValidElement)(action) && action.type === IconButton_1.IconButton
|
|
69
|
-
? (0, react_1.cloneElement)(action, {
|
|
70
|
-
level: 'tertiary',
|
|
71
|
-
ghost: 'borderless',
|
|
72
|
-
size: 'small',
|
|
73
|
-
})
|
|
74
|
-
: action)));
|
|
88
|
+
react_1.default.createElement(BlockTitle, null,
|
|
89
|
+
title,
|
|
90
|
+
react_1.default.createElement(ActionsContainer, null,
|
|
91
|
+
actions,
|
|
92
|
+
!isCollapsable ? null : (react_1.default.createElement(IconButton_1.IconButton, { icon: isOpen ? react_1.default.createElement(icons_1.ArrowUpIcon, null) : react_1.default.createElement(icons_1.ArrowDownIcon, null), title: collapseButtonLabel, level: "tertiary", ghost: true, size: "small", onClick: handleCollapse })))),
|
|
93
|
+
!isCollapsable ? null : (react_1.default.createElement(BlockContent, { ref: contentRef, isCollapsable: isCollapsable, "$overflow": shouldAnimate || !isOpen ? 'hidden' : 'inherit', "$height": true === isOpen ? contentHeight : 0, shouldAnimate: shouldAnimate, "aria-hidden": !isOpen }, children))));
|
|
75
94
|
});
|
|
76
95
|
exports.Block = Block;
|
|
77
|
-
var templateObject_1, templateObject_2;
|
|
96
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
|
|
78
97
|
//# sourceMappingURL=Block.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Block.js","sourceRoot":"","sources":["../../../src/components/Block/Block.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Block.js","sourceRoot":"","sources":["../../../src/components/Block/Block.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyE;AACzE,qEAA8C;AAC9C,qCAAqE;AAErE,qCAAuD;AACvD,uDAAoD;AA2DpD,IAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,IAAM,gBAAgB,GAAG,2BAAM,CAAC,GAAG,yKAAA,sGAKlC,IAAA,CAAC;AAEF,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,yKAAA,sGAK5B,IAAA,CAAC;AAEF,IAAM,YAAY,GAAG,2BAAM,CAAC,GAAG,kLAE9B,yEAGU,EAAqB,mBAChB,EAAsE,SAClF,EAUC,IACJ,KAbU,IAAA,gBAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EAChB,UAAC,EAAwB;QAAvB,OAAO,aAAA,EAAE,aAAa,mBAAA;IAAM,OAAA,CAAC,CAAC,KAAK,OAAO,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAAxC,CAAwC,EAClF,UAAC,EAAkD;QAAjD,aAAa,mBAAA,EAAE,OAAO,aAAA,EAAE,SAAS,eAAA,EAAE,aAAa,mBAAA;IAClD,OAAA,aAAa,QACb,uBAAG,0IAAA,sBACa,EAAO,uBACT,EAAS,WACnB,EAID,QACF,KAPe,OAAO,EACT,SAAS,EACnB,aAAa,QACf,uBAAG,iLAAA,4BACiB,EAAkB,+EAErC,KAFmB,kBAAkB,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C,aAAa,EAAE,aAAa,iBACf,CAAC,MAAM,IAEnB,QAAQ,CACI,CAChB,CACS,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEM,sBAAK"}
|
|
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import { Override } from '../../shared';
|
|
3
3
|
declare type TableProps = Override<React.HTMLAttributes<HTMLTableElement>, {
|
|
4
4
|
isSelectable?: boolean;
|
|
5
|
+
hasWarningRows?: boolean;
|
|
5
6
|
displayCheckbox?: boolean;
|
|
6
7
|
children?: ReactNode;
|
|
7
8
|
} & ({
|
|
@@ -12,7 +13,7 @@ declare type TableProps = Override<React.HTMLAttributes<HTMLTableElement>, {
|
|
|
12
13
|
onReorder: (updatedIndices: number[]) => void;
|
|
13
14
|
})>;
|
|
14
15
|
declare const Table: {
|
|
15
|
-
({ isSelectable, displayCheckbox, isDragAndDroppable, onReorder, children, ...rest }: TableProps): JSX.Element;
|
|
16
|
+
({ isSelectable, hasWarningRows, displayCheckbox, isDragAndDroppable, onReorder, children, ...rest }: TableProps): JSX.Element;
|
|
16
17
|
Header: React.ForwardRefExoticComponent<import("./TableHeader/TableHeader").TableHeaderProps & React.RefAttributes<HTMLTableSectionElement>>;
|
|
17
18
|
HeaderCell: React.ForwardRefExoticComponent<{
|
|
18
19
|
isSortable?: boolean | undefined;
|
|
@@ -21,10 +22,11 @@ declare const Table: {
|
|
|
21
22
|
children?: React.ReactNode;
|
|
22
23
|
} & React.RefAttributes<HTMLTableHeaderCellElement>>;
|
|
23
24
|
Body: React.ForwardRefExoticComponent<import("./TableBody/TableBody").TableBodyProps & React.RefAttributes<HTMLTableSectionElement>>;
|
|
24
|
-
Row: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLTableRowElement>, "children" | "onClick" | "onDragEnd" | "onDragStart" | "isSelected" | "rowIndex" | "onSelectToggle"> & {
|
|
25
|
+
Row: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLTableRowElement>, "children" | "onClick" | "onDragEnd" | "onDragStart" | "level" | "isSelected" | "rowIndex" | "onSelectToggle"> & {
|
|
25
26
|
children?: React.ReactNode;
|
|
26
27
|
onSelectToggle?: ((isSelected: boolean) => void) | undefined;
|
|
27
28
|
isSelected?: boolean | undefined;
|
|
29
|
+
level?: "warning" | undefined;
|
|
28
30
|
onClick?: ((event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void) | undefined;
|
|
29
31
|
rowIndex?: number | undefined;
|
|
30
32
|
onDragStart?: ((rowIndex: number) => void) | undefined;
|
|
@@ -60,8 +60,8 @@ var TableContext_1 = require("./TableContext");
|
|
|
60
60
|
var TableBody_1 = require("./TableBody/TableBody");
|
|
61
61
|
var TableContainer = styled_components_1.default.table(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border-collapse: collapse;\n width: 100%;\n"], ["\n border-collapse: collapse;\n width: 100%;\n"])));
|
|
62
62
|
var Table = function (_a) {
|
|
63
|
-
var _b = _a.isSelectable, isSelectable = _b === void 0 ? false : _b, _c = _a.
|
|
64
|
-
var providerValue = (0, react_1.useMemo)(function () { return ({ isSelectable: isSelectable, displayCheckbox: displayCheckbox, isDragAndDroppable: isDragAndDroppable, onReorder: onReorder }); }, [isSelectable, displayCheckbox, isDragAndDroppable, onReorder]);
|
|
63
|
+
var _b = _a.isSelectable, isSelectable = _b === void 0 ? false : _b, _c = _a.hasWarningRows, hasWarningRows = _c === void 0 ? false : _c, _d = _a.displayCheckbox, displayCheckbox = _d === void 0 ? false : _d, _e = _a.isDragAndDroppable, isDragAndDroppable = _e === void 0 ? false : _e, _f = _a.onReorder, onReorder = _f === void 0 ? undefined : _f, children = _a.children, rest = __rest(_a, ["isSelectable", "hasWarningRows", "displayCheckbox", "isDragAndDroppable", "onReorder", "children"]);
|
|
64
|
+
var providerValue = (0, react_1.useMemo)(function () { return ({ isSelectable: isSelectable, hasWarningRows: hasWarningRows, displayCheckbox: displayCheckbox, isDragAndDroppable: isDragAndDroppable, onReorder: onReorder }); }, [isSelectable, hasWarningRows, displayCheckbox, isDragAndDroppable, onReorder]);
|
|
65
65
|
return (react_1.default.createElement(TableContext_1.TableContext.Provider, { value: providerValue },
|
|
66
66
|
react_1.default.createElement(TableContainer, __assign({}, rest), children)));
|
|
67
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/components/Table/Table.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAgD;AAChD,wEAAuC;AACvC,mDAAgD;AAChD,yDAAsD;AACtD,qEAAkE;AAClE,qEAAkE;AAClE,gDAA6C;AAC7C,+CAA4C;AAC5C,mDAAgD;AAGhD,IAAM,cAAc,GAAG,2BAAM,CAAC,KAAK,qHAAA,kDAGlC,IAAA,CAAC;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/components/Table/Table.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAgD;AAChD,wEAAuC;AACvC,mDAAgD;AAChD,yDAAsD;AACtD,qEAAkE;AAClE,qEAAkE;AAClE,gDAA6C;AAC7C,+CAA4C;AAC5C,mDAAgD;AAGhD,IAAM,cAAc,GAAG,2BAAM,CAAC,KAAK,qHAAA,kDAGlC,IAAA,CAAC;AAmDF,IAAM,KAAK,GAAG,UAAC,EAQF;IAPX,IAAA,oBAAoB,EAApB,YAAY,mBAAG,KAAK,KAAA,EACpB,sBAAsB,EAAtB,cAAc,mBAAG,KAAK,KAAA,EACtB,uBAAuB,EAAvB,eAAe,mBAAG,KAAK,KAAA,EACvB,0BAA0B,EAA1B,kBAAkB,mBAAG,KAAK,KAAA,EAC1B,iBAAqB,EAArB,SAAS,mBAAG,SAAS,KAAA,EACrB,QAAQ,cAAA,EACL,IAAI,cAPM,oGAQd,CADQ;IAEP,IAAM,aAAa,GAAG,IAAA,eAAO,EAC3B,cAAM,OAAA,CAAC,EAAC,YAAY,cAAA,EAAE,cAAc,gBAAA,EAAE,eAAe,iBAAA,EAAE,kBAAkB,oBAAA,EAAE,SAAS,WAAA,EAAC,CAAC,EAAhF,CAAgF,EACtF,CAAC,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,SAAS,CAAC,CAC/E,CAAC;IAEF,OAAO,CACL,8BAAC,2BAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,aAAa;QACzC,8BAAC,cAAc,eAAK,IAAI,GAAG,QAAQ,CAAkB,CAC/B,CACzB,CAAC;AACJ,CAAC,CAAC;AAgBM,sBAAK;AAdb,yBAAW,CAAC,WAAW,GAAG,cAAc,CAAC;AACzC,iCAAe,CAAC,WAAW,GAAG,kBAAkB,CAAC;AACjD,qBAAS,CAAC,WAAW,GAAG,YAAY,CAAC;AACrC,mBAAQ,CAAC,WAAW,GAAG,WAAW,CAAC;AACnC,qBAAS,CAAC,WAAW,GAAG,YAAY,CAAC;AACrC,iCAAe,CAAC,WAAW,GAAG,kBAAkB,CAAC;AAEjD,KAAK,CAAC,MAAM,GAAG,yBAAW,CAAC;AAC3B,KAAK,CAAC,UAAU,GAAG,iCAAe,CAAC;AACnC,KAAK,CAAC,IAAI,GAAG,qBAAS,CAAC;AACvB,KAAK,CAAC,GAAG,GAAG,mBAAQ,CAAC;AACrB,KAAK,CAAC,IAAI,GAAG,qBAAS,CAAC;AACvB,KAAK,CAAC,UAAU,GAAG,iCAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableContext.js","sourceRoot":"","sources":["../../../src/components/Table/TableContext.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;
|
|
1
|
+
{"version":3,"file":"TableContext.js","sourceRoot":"","sources":["../../../src/components/Table/TableContext.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAUpC,IAAM,YAAY,GAAG,IAAA,qBAAa,EAAmB;IACnD,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,eAAe,EAAE,KAAK;IACtB,kBAAkB,EAAE,KAAK;IACzB,SAAS,EAAE,SAAS;CACrB,CAAC,CAAC;AAEK,oCAAY"}
|
|
@@ -58,16 +58,18 @@ var TableHead = styled_components_1.default.thead(templateObject_2 || (templateO
|
|
|
58
58
|
return undefined !== sticky && (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n th {\n position: sticky;\n top: ", "px;\n z-index: 1;\n background-color: ", ";\n }\n "], ["\n th {\n position: sticky;\n top: ", "px;\n z-index: 1;\n background-color: ", ";\n }\n "])), sticky, (0, theme_1.getColor)('white'));
|
|
59
59
|
});
|
|
60
60
|
var SelectColumn = styled_components_1.default.th(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: 40px;\n"], ["\n width: 40px;\n"])));
|
|
61
|
-
var
|
|
61
|
+
var HasWarningColumn = styled_components_1.default.th(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: 20px;\n background: linear-gradient(to top, ", " 1px, ", " 0px);\n"], ["\n width: 20px;\n background: linear-gradient(to top, ", " 1px, ", " 0px);\n"])), (0, theme_1.getColor)('grey', 120), (0, theme_1.getColor)('white'));
|
|
62
|
+
var OrderColumn = styled_components_1.default.th(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n width: 40px;\n background: linear-gradient(to top, ", " 1px, ", " 0px);\n"], ["\n width: 40px;\n background: linear-gradient(to top, ", " 1px, ", " 0px);\n"])), (0, theme_1.getColor)('grey', 120), (0, theme_1.getColor)('white'));
|
|
62
63
|
var TableHeader = react_1.default.forwardRef(function (_a, forwardedRef) {
|
|
63
64
|
var children = _a.children, sticky = _a.sticky, rest = __rest(_a, ["children", "sticky"]);
|
|
64
|
-
var _b = react_1.default.useContext(TableContext_1.TableContext), isSelectable = _b.isSelectable, isDragAndDroppable = _b.isDragAndDroppable;
|
|
65
|
+
var _b = react_1.default.useContext(TableContext_1.TableContext), isSelectable = _b.isSelectable, isDragAndDroppable = _b.isDragAndDroppable, hasWarningRows = _b.hasWarningRows;
|
|
65
66
|
return (react_1.default.createElement(TableHead, { sticky: sticky, ref: forwardedRef },
|
|
66
67
|
react_1.default.createElement("tr", __assign({}, rest),
|
|
67
68
|
isSelectable && react_1.default.createElement(SelectColumn, null),
|
|
69
|
+
hasWarningRows && react_1.default.createElement(HasWarningColumn, null),
|
|
68
70
|
isDragAndDroppable && react_1.default.createElement(OrderColumn, null),
|
|
69
71
|
children)));
|
|
70
72
|
});
|
|
71
73
|
exports.TableHeader = TableHeader;
|
|
72
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
|
74
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
|
|
73
75
|
//# sourceMappingURL=TableHeader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableHeader.js","sourceRoot":"","sources":["../../../../src/components/Table/TableHeader/TableHeader.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA4C;AAC5C,qEAA8C;AAC9C,wCAA2D;AAC3D,gDAA6C;AAE7C,IAAM,SAAS,GAAG,2BAAM,CAAC,KAAK,+EAAuC,MACjE,EASC,IACJ,KAVG,UAAC,EAAQ;QAAP,MAAM,YAAA;IACR,OAAA,SAAS,KAAK,MAAM,QACpB,uBAAG,wMAAA,wDAGQ,EAAM,sDAEO,EAAiB,kBAExC,KAJU,MAAM,EAEO,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAExC;AARD,CAQC,CACJ,CAAC;AAEF,IAAM,YAAY,GAAG,2BAAM,CAAC,EAAE,uFAAA,oBAE7B,IAAA,CAAC;AACF,IAAM,WAAW,GAAG,2BAAM,CAAC,EAAE,mJAAA,0DAEW,EAAqB,QAAS,EAAiB,UACtF,KADuC,IAAA,gBAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,E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A,QAAQ,cAAA,EAAE,MAAM,YAAA,EAAK,IAAI,cAA1B,sBAA2B,CAAD;IACnB,IAAA,KAAqD,eAAK,CAAC,UAAU,CAAC,2BAAY,CAAC,EAAlF,YAAY,kBAAA,EAAE,kBAAkB,wBAAA,EAAE,cAAc,oBAAkC,CAAC;IAE1F,OAAO,CACL,8BAAC,SAAS,IAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY;QAC1C,iDAAQ,IAAI;YAET,YAAY,IAAI,8BAAC,YAAY,OAAG;YAChC,cAAc,IAAI,8BAAC,gBAAgB,OAAG;YACtC,kBAAkB,IAAI,8BAAC,WAAW,OAAG;YACrC,QAAQ,CACN,CACK,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEM,kCAAW"}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import React, { ReactNode, HTMLAttributes, MouseEvent } from 'react';
|
|
2
2
|
import { Override } from '../../../shared';
|
|
3
|
+
declare type Level = 'warning';
|
|
3
4
|
declare type TableRowProps = Override<HTMLAttributes<HTMLTableRowElement>, {
|
|
4
5
|
children?: ReactNode;
|
|
5
6
|
onSelectToggle?: (isSelected: boolean) => void;
|
|
6
7
|
isSelected?: boolean;
|
|
8
|
+
level?: Level;
|
|
7
9
|
onClick?: (event: MouseEvent<HTMLTableRowElement>) => void;
|
|
8
10
|
rowIndex?: number;
|
|
9
11
|
onDragStart?: (rowIndex: number) => void;
|
|
10
12
|
onDragEnd?: () => void;
|
|
11
13
|
}>;
|
|
12
|
-
declare const TableRow: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLTableRowElement>, "children" | "onClick" | "onDragEnd" | "onDragStart" | "isSelected" | "rowIndex" | "onSelectToggle"> & {
|
|
14
|
+
declare const TableRow: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLTableRowElement>, "children" | "onClick" | "onDragEnd" | "onDragStart" | "level" | "isSelected" | "rowIndex" | "onSelectToggle"> & {
|
|
13
15
|
children?: ReactNode;
|
|
14
16
|
onSelectToggle?: ((isSelected: boolean) => void) | undefined;
|
|
15
17
|
isSelected?: boolean | undefined;
|
|
18
|
+
level?: "warning" | undefined;
|
|
16
19
|
onClick?: ((event: MouseEvent<HTMLTableRowElement>) => void) | undefined;
|
|
17
20
|
rowIndex?: number | undefined;
|
|
18
21
|
onDragStart?: ((rowIndex: number) => void) | undefined;
|
|
@@ -54,7 +54,7 @@ var TableContext_1 = require("../TableContext");
|
|
|
54
54
|
var TableCell_1 = require("../TableCell/TableCell");
|
|
55
55
|
var icons_1 = require("../../../icons");
|
|
56
56
|
var usePlaceholderPosition_1 = require("../../../hooks/usePlaceholderPosition");
|
|
57
|
-
var RowContainer = styled_components_1.default.tr(
|
|
57
|
+
var RowContainer = styled_components_1.default.tr(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n ", ";\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n &:hover > td {\n opacity: 1;\n ", "\n }\n\n &:hover > td > div {\n opacity: 1;\n }\n\n ", ";\n"], ["\n ", ";\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n &:hover > td {\n opacity: 1;\n ", "\n }\n\n &:hover > td > div {\n opacity: 1;\n }\n\n ", ";\n"])), function (_a) {
|
|
58
58
|
var isSelected = _a.isSelected;
|
|
59
59
|
return isSelected && (0, styled_components_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n > td {\n background-color: ", ";\n }\n "], ["\n > td {\n background-color: ", ";\n }\n "])), (0, theme_1.getColor)('blue', 20));
|
|
60
60
|
}, function (_a) {
|
|
@@ -72,16 +72,20 @@ var RowContainer = styled_components_1.default.tr(templateObject_7 || (templateO
|
|
|
72
72
|
}, function (_a) {
|
|
73
73
|
var isClickable = _a.isClickable;
|
|
74
74
|
return isClickable && (0, styled_components_1.css)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n background-color: ", ";\n "], ["\n background-color: ", ";\n "])), (0, theme_1.getColor)('grey', 20));
|
|
75
|
+
}, function (_a) {
|
|
76
|
+
var level = _a.level;
|
|
77
|
+
return level === 'warning' && (0, styled_components_1.css)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n > td {\n :first-child {\n padding: 0 0 0 5px;\n }\n background-color: ", ";\n }\n "], ["\n > td {\n :first-child {\n padding: 0 0 0 5px;\n }\n background-color: ", ";\n }\n "])), (0, theme_1.getColor)('yellow', 10));
|
|
75
78
|
});
|
|
76
|
-
var CheckboxContainer = styled_components_1.default.td(
|
|
79
|
+
var CheckboxContainer = styled_components_1.default.td(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n background: none !important;\n opacity: ", ";\n cursor: auto;\n\n > div {\n justify-content: center;\n }\n"], ["\n background: none !important;\n opacity: ", ";\n cursor: auto;\n\n > div {\n justify-content: center;\n }\n"])), function (_a) {
|
|
77
80
|
var isVisible = _a.isVisible;
|
|
78
81
|
return (isVisible ? 1 : 0);
|
|
79
82
|
});
|
|
80
|
-
var HandleCell = (0, styled_components_1.default)(TableCell_1.TableCell)(
|
|
83
|
+
var HandleCell = (0, styled_components_1.default)(TableCell_1.TableCell)(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n cursor: grab;\n width: 20px;\n\n > div {\n justify-content: center;\n }\n\n :active {\n cursor: grabbing;\n }\n"], ["\n cursor: grab;\n width: 20px;\n\n > div {\n justify-content: center;\n }\n\n :active {\n cursor: grabbing;\n }\n"])));
|
|
84
|
+
var WarningIcon = (0, styled_components_1.default)(icons_1.DangerIcon)(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n color: ", ";\n"], ["\n color: ", ";\n"])), (0, theme_1.getColor)('yellow', 120));
|
|
81
85
|
var TableRow = (0, react_1.forwardRef)(function (_a, forwardedRef) {
|
|
82
|
-
var _b = _a.rowIndex, rowIndex = _b === void 0 ? 0 : _b, isSelected = _a.isSelected, onSelectToggle = _a.onSelectToggle, onClick = _a.onClick, draggable = _a.draggable, onDragStart = _a.onDragStart, onDragEnd = _a.onDragEnd, children = _a.children, rest = __rest(_a, ["rowIndex", "isSelected", "onSelectToggle", "onClick", "draggable", "onDragStart", "onDragEnd", "children"]);
|
|
86
|
+
var _b = _a.rowIndex, rowIndex = _b === void 0 ? 0 : _b, isSelected = _a.isSelected, level = _a.level, onSelectToggle = _a.onSelectToggle, onClick = _a.onClick, draggable = _a.draggable, onDragStart = _a.onDragStart, onDragEnd = _a.onDragEnd, children = _a.children, rest = __rest(_a, ["rowIndex", "isSelected", "level", "onSelectToggle", "onClick", "draggable", "onDragStart", "onDragEnd", "children"]);
|
|
83
87
|
var _c = (0, usePlaceholderPosition_1.usePlaceholderPosition)(rowIndex), placeholderPosition = _c[0], placeholderDragEnter = _c[1], placeholderDragLeave = _c[2], placeholderDragEnd = _c[3];
|
|
84
|
-
var _d = (0, react_1.useContext)(TableContext_1.TableContext), isSelectable = _d.isSelectable, displayCheckbox = _d.displayCheckbox, isDragAndDroppable = _d.isDragAndDroppable;
|
|
88
|
+
var _d = (0, react_1.useContext)(TableContext_1.TableContext), isSelectable = _d.isSelectable, displayCheckbox = _d.displayCheckbox, isDragAndDroppable = _d.isDragAndDroppable, hasWarningRows = _d.hasWarningRows;
|
|
85
89
|
if (isSelectable && (undefined === isSelected || undefined === onSelectToggle)) {
|
|
86
90
|
throw Error('A row in a selectable table should have the prop "isSelected" and "onSelectToggle"');
|
|
87
91
|
}
|
|
@@ -100,15 +104,16 @@ var TableRow = (0, react_1.forwardRef)(function (_a, forwardedRef) {
|
|
|
100
104
|
placeholderDragEnd();
|
|
101
105
|
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd();
|
|
102
106
|
};
|
|
103
|
-
return (react_1.default.createElement(RowContainer, __assign({ ref: forwardedRef, isClickable: undefined !== onClick, isSelected: !!isSelected, isDragAndDroppable: isDragAndDroppable, onClick: onClick, placeholderPosition: isDragAndDroppable ? placeholderPosition : 'none', draggable: isDragAndDroppable && draggable, "data-draggable-index": rowIndex, onDragEnter: handleDragEnter, onDragLeave: placeholderDragLeave, onDragStart: handleDragStart, onDragEnd: handleDragEnd }, rest),
|
|
107
|
+
return (react_1.default.createElement(RowContainer, __assign({ ref: forwardedRef, isClickable: undefined !== onClick, isSelected: !!isSelected, level: level, isDragAndDroppable: isDragAndDroppable, onClick: onClick, placeholderPosition: isDragAndDroppable ? placeholderPosition : 'none', draggable: isDragAndDroppable && draggable, "data-draggable-index": rowIndex, onDragEnter: handleDragEnter, onDragLeave: placeholderDragLeave, onDragStart: handleDragStart, onDragEnd: handleDragEnd }, rest),
|
|
104
108
|
isSelectable && (react_1.default.createElement(CheckboxContainer, { "aria-hidden": !displayCheckbox && !isSelected, isVisible: displayCheckbox || !!isSelected, onClick: handleCheckboxChange },
|
|
105
109
|
react_1.default.createElement(components_1.Checkbox, { checked: !!isSelected, onChange: function (_value, e) {
|
|
106
110
|
handleCheckboxChange(e);
|
|
107
111
|
} }))),
|
|
108
112
|
isDragAndDroppable && (react_1.default.createElement(HandleCell, { onMouseDown: function () { return onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart(rowIndex); }, onMouseUp: onDragEnd, "data-testid": "dragAndDrop" },
|
|
109
113
|
react_1.default.createElement(icons_1.RowIcon, { size: 16 }))),
|
|
114
|
+
hasWarningRows && react_1.default.createElement(TableCell_1.TableCell, null, level === 'warning' && react_1.default.createElement(WarningIcon, { size: 16 })),
|
|
110
115
|
children));
|
|
111
116
|
});
|
|
112
117
|
exports.TableRow = TableRow;
|
|
113
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
|
|
118
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11;
|
|
114
119
|
//# sourceMappingURL=TableRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableRow.js","sourceRoot":"","sources":["../../../../src/components/Table/TableRow/TableRow.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CASe;AACf,qEAA8C;AAC9C,wCAA2D;AAC3D,kDAA6C;AAE7C,gDAA6C;AAC7C,oDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"TableRow.js","sourceRoot":"","sources":["../../../../src/components/Table/TableRow/TableRow.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CASe;AACf,qEAA8C;AAC9C,wCAA2D;AAC3D,kDAA6C;AAE7C,gDAA6C;AAC7C,oDAAiD;AACjD,wCAAmD;AACnD,gFAAkG;AAIlG,IAAM,YAAY,GAAG,2BAAM,CAAC,EAAE,uOAQ7B,MACG,EAMC,SAED,EAMC,QAED,EAMC,QAED,EAIC,QAED,EAIC,6CAIC,EAIC,6DAOH,EASC,KACJ,KA3DG,UAAC,EAAY;QAAX,UAAU,gBAAA;IACZ,OAAA,UAAU,QACV,uBAAG,oIAAA,4CAEqB,EAAoB,kBAE3C,KAFuB,IAAA,gBAAQ,EAAC,MAAM,EAAE,EAAE,CAAC,CAE3C;AALD,CAKC,EAED,UAAC,EAAa;QAAZ,WAAW,iBAAA;IACb,OAAA,WAAW,QACX,uBAAG,gIAAA,4DAIF,IAAA;AALD,CAKC,EAED,UAAC,EAAoB;QAAnB,kBAAkB,wBAAA;IACpB,OAAA,kBAAkB,QAClB,uBAAG,sIAAA,kEAIF,IAAA;AALD,CAKC,EAED,UAAC,EAAqB;QAApB,mBAAmB,yBAAA;IACrB,OAAA,mBAAmB,KAAK,KAAK,QAC7B,uBAAG,+IAAA,iDACwC,EAAoB,QAAS,EAAiB,cACxF,KAD0C,IAAA,gBAAQ,EAAC,MAAM,EAAE,EAAE,CAAC,EAAS,IAAA,gBAAQ,EAAC,OAAO,CAAC,CACxF;AAHD,CAGC,EAED,UAAC,EAAqB;QAApB,mBAAmB,yBAAA;IACrB,OAAA,mBAAmB,KAAK,QA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KAAK,EAAE,KAAK,EACZ,kBAAkB,EAAE,kBAAkB,EACtC,OAAO,EAAE,OAAO,EAChB,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,EACtE,SAAS,EAAE,kBAAkB,IAAI,SAAS,0BACpB,QAAQ,EAC9B,WAAW,EAAE,eAAe,EAC5B,WAAW,EAAE,oBAAoB,EACjC,WAAW,EAAE,eAAe,EAC5B,SAAS,EAAE,aAAa,IACpB,IAAI;QAEP,YAAY,IAAI,CACf,8BAAC,iBAAiB,mBACH,CAAC,eAAe,IAAI,CAAC,UAAU,EAC5C,SAAS,EAAE,eAAe,IAAI,CAAC,CAAC,UAAU,EAC1C,OAAO,EAAE,oBAAoB;YAE7B,8BAAC,qBAAQ,IACP,OAAO,EAAE,CAAC,CAAC,UAAU,EACrB,QAAQ,EAAE,UAAC,MAAM,EAAE,CAAC;oBAClB,oBAAoB,CAAC,CAAC,CAAC,CAAC;gBAC1B,CAAC,GACD,CACgB,CACrB;QACA,kBAAkB,IAAI,CACrB,8BAAC,UAAU,IAAC,WAAW,EAAE,cAAM,OAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,QAAQ,CAAC,EAAvB,CAAuB,EAAE,SAAS,EAAE,SAAS,iBAAc,aAAa;YACrG,8BAAC,eAAO,IAAC,IAAI,EAAE,EAAE,GAAI,CACV,CACd;QACA,cAAc,IAAI,8BAAC,qBAAS,QAAE,KAAK,KAAK,SAAS,IAAI,8BAAC,WAAW,IAAC,IAAI,EAAE,EAAE,GAAI,CAAa;QAC3F,QAAQ,CACI,CAChB,CAAC;AACJ,CAAC,CACF,CAAC;AAEM,4BAAQ"}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import {useState} from 'react';
|
|
1
2
|
import {Meta, Story, ArgsTable, Canvas} from '@storybook/addon-docs';
|
|
2
3
|
import {action} from '@storybook/addon-actions';
|
|
3
4
|
import {Block} from './Block';
|
|
4
5
|
import {IconButton} from '../IconButton/IconButton';
|
|
5
|
-
import {CloseIcon,
|
|
6
|
+
import {CloseIcon, ArrowDownIcon, MoreIcon} from '../../icons';
|
|
6
7
|
|
|
7
8
|
<Meta
|
|
8
9
|
title="Components/Block"
|
|
9
10
|
component={Block}
|
|
10
11
|
argTypes={{
|
|
12
|
+
title: {control: {type: 'text'}},
|
|
11
13
|
children: {control: {type: 'text'}},
|
|
12
14
|
}}
|
|
13
15
|
args={{
|
|
14
|
-
|
|
16
|
+
title: 'I am a block',
|
|
17
|
+
children: 'I am the block content',
|
|
15
18
|
}}
|
|
16
19
|
/>
|
|
17
20
|
|
|
@@ -36,22 +39,35 @@ Use this playground to test the block component
|
|
|
36
39
|
|
|
37
40
|
<ArgsTable story="Standard" />
|
|
38
41
|
|
|
42
|
+
## Without Actions
|
|
43
|
+
|
|
44
|
+
<Canvas>
|
|
45
|
+
<Story name="Without Actions">
|
|
46
|
+
{args => {
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<Block {...args} title="Block without action" />
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}}
|
|
53
|
+
</Story>
|
|
54
|
+
</Canvas>
|
|
55
|
+
|
|
56
|
+
|
|
39
57
|
## With Actions
|
|
40
58
|
|
|
41
59
|
<Canvas>
|
|
42
|
-
<Story name="With
|
|
60
|
+
<Story name="With Actions">
|
|
43
61
|
{args => {
|
|
62
|
+
const [isOpen, setOpen] = useState(false);
|
|
44
63
|
return (
|
|
45
64
|
<>
|
|
46
|
-
<Block {...args}>
|
|
47
|
-
Block without action
|
|
48
|
-
</Block>
|
|
49
65
|
<Block
|
|
50
|
-
{...args}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
{...args} title="Block with actions" isOpen={isOpen} onCollapse={setOpen} collapseButtonLabel="Collapse"
|
|
67
|
+
actions={<>
|
|
68
|
+
<IconButton level="danger" ghost size="small" key="remove" icon={<CloseIcon />} title='Remove' onClick={action('Remove block')} />
|
|
69
|
+
</>}
|
|
70
|
+
/>
|
|
55
71
|
</>
|
|
56
72
|
);
|
|
57
73
|
}}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import React, {ReactNode, Ref, useEffect, useRef, useState} from 'react';
|
|
2
|
+
import styled, {css} from 'styled-components';
|
|
3
3
|
import {AkeneoThemedProps, getColor, getFontSize} from '../../theme';
|
|
4
4
|
import {Override} from '../../shared';
|
|
5
|
-
import {
|
|
6
|
-
import {IconButton
|
|
5
|
+
import {ArrowDownIcon, ArrowUpIcon} from '../../icons';
|
|
6
|
+
import {IconButton} from '../IconButton/IconButton';
|
|
7
7
|
|
|
8
8
|
type BlockProps = Override<
|
|
9
9
|
Override<React.ButtonHTMLAttributes<HTMLButtonElement>, React.AnchorHTMLAttributes<HTMLAnchorElement>>,
|
|
10
10
|
{
|
|
11
|
+
/**
|
|
12
|
+
* Title of the block.
|
|
13
|
+
*/
|
|
14
|
+
title: string;
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* Add an action that will be displayed on the right of the block.
|
|
13
18
|
*/
|
|
14
|
-
|
|
19
|
+
actions?: ReactNode;
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* Accessibility label to describe shortly the button.
|
|
@@ -29,27 +34,78 @@ type BlockProps = Override<
|
|
|
29
34
|
ariaDescribedBy?: string;
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
|
-
* Children of the
|
|
37
|
+
* Children of the block.
|
|
33
38
|
*/
|
|
34
39
|
children?: ReactNode;
|
|
35
|
-
}
|
|
40
|
+
} & (
|
|
41
|
+
| {
|
|
42
|
+
/**
|
|
43
|
+
* Whether or not the Block is open.
|
|
44
|
+
*/
|
|
45
|
+
isOpen: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Label of the collapse button.
|
|
49
|
+
*/
|
|
50
|
+
collapseButtonLabel: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Handler called when the collapse button is clicked.
|
|
54
|
+
*/
|
|
55
|
+
onCollapse: (isOpen: boolean) => void;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
isOpen?: undefined;
|
|
59
|
+
collapseButtonLabel?: undefined;
|
|
60
|
+
onCollapse?: undefined;
|
|
61
|
+
}
|
|
62
|
+
)
|
|
36
63
|
>;
|
|
37
64
|
|
|
65
|
+
const ANIMATION_DURATION = 100;
|
|
66
|
+
|
|
38
67
|
const ActionsContainer = styled.div`
|
|
39
|
-
display:
|
|
68
|
+
display: flex;
|
|
40
69
|
align-items: center;
|
|
70
|
+
column-gap: 10px;
|
|
71
|
+
justify-content: space-between;
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const BlockTitle = styled.div`
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: space-between;
|
|
78
|
+
min-height: 24px;
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
const BlockContent = styled.div<
|
|
82
|
+
{isCollapsable: boolean; $height: number; $overflow: string; shouldAnimate: boolean} & AkeneoThemedProps
|
|
83
|
+
>`
|
|
84
|
+
overflow-wrap: break-word;
|
|
85
|
+
white-space: break-spaces;
|
|
86
|
+
color: ${getColor('grey', 140)};
|
|
87
|
+
margin-top: ${({$height, isCollapsable}) => (0 === $height && isCollapsable ? 0 : 5)}px;
|
|
88
|
+
${({isCollapsable, $height, $overflow, shouldAnimate}) =>
|
|
89
|
+
isCollapsable &&
|
|
90
|
+
css`
|
|
91
|
+
max-height: ${$height}px;
|
|
92
|
+
overflow: ${$overflow};
|
|
93
|
+
${shouldAnimate &&
|
|
94
|
+
css`
|
|
95
|
+
transition: all ${ANIMATION_DURATION}ms ease-in-out;
|
|
96
|
+
transition-property: max-height, margin-top;
|
|
97
|
+
`}
|
|
98
|
+
`}
|
|
41
99
|
`;
|
|
42
100
|
|
|
43
101
|
const Container = styled.div<AkeneoThemedProps>`
|
|
44
102
|
box-sizing: border-box;
|
|
45
|
-
padding:
|
|
103
|
+
padding: 10px 15px;
|
|
46
104
|
border-style: solid;
|
|
47
105
|
border-width: 1px;
|
|
48
106
|
border-radius: 2px;
|
|
49
|
-
height: 50px;
|
|
50
107
|
display: flex;
|
|
51
|
-
|
|
52
|
-
align-items: center;
|
|
108
|
+
flex-direction: column;
|
|
53
109
|
font-family: inherit;
|
|
54
110
|
font-size: ${getFontSize('default')};
|
|
55
111
|
font-weight: 400;
|
|
@@ -60,17 +116,51 @@ const Container = styled.div<AkeneoThemedProps>`
|
|
|
60
116
|
|
|
61
117
|
&:hover {
|
|
62
118
|
background-color: ${getColor('grey', 20)};
|
|
63
|
-
${ActionsContainer} {
|
|
64
|
-
display: flex;
|
|
65
|
-
}
|
|
66
119
|
}
|
|
67
120
|
`;
|
|
68
121
|
|
|
69
122
|
const Block = React.forwardRef<HTMLButtonElement, BlockProps>(
|
|
70
123
|
(
|
|
71
|
-
{
|
|
124
|
+
{
|
|
125
|
+
title,
|
|
126
|
+
actions,
|
|
127
|
+
ariaDescribedBy,
|
|
128
|
+
ariaLabel,
|
|
129
|
+
ariaLabelledBy,
|
|
130
|
+
isOpen,
|
|
131
|
+
collapseButtonLabel,
|
|
132
|
+
onCollapse,
|
|
133
|
+
children,
|
|
134
|
+
...rest
|
|
135
|
+
}: BlockProps,
|
|
72
136
|
forwardedRef: Ref<HTMLButtonElement>
|
|
73
137
|
) => {
|
|
138
|
+
const [contentHeight, setContentHeight] = useState<number>(0);
|
|
139
|
+
const [shouldAnimate, setShouldAnimate] = useState<boolean>(false);
|
|
140
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
141
|
+
|
|
142
|
+
const isCollapsable = undefined !== collapseButtonLabel && undefined !== onCollapse && undefined !== isOpen;
|
|
143
|
+
|
|
144
|
+
const handleCollapse = () => onCollapse?.(!isOpen);
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!isCollapsable) return;
|
|
148
|
+
|
|
149
|
+
setContentHeight(contentHeight => {
|
|
150
|
+
const scrollHeight = contentRef.current?.scrollHeight ?? 0;
|
|
151
|
+
|
|
152
|
+
return 0 === scrollHeight ? contentHeight : scrollHeight;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const shouldAnimateTimeoutId = window.setTimeout(() => {
|
|
156
|
+
setShouldAnimate(true);
|
|
157
|
+
}, ANIMATION_DURATION);
|
|
158
|
+
|
|
159
|
+
return () => {
|
|
160
|
+
window.clearTimeout(shouldAnimateTimeoutId);
|
|
161
|
+
};
|
|
162
|
+
}, [children]);
|
|
163
|
+
|
|
74
164
|
return (
|
|
75
165
|
<Container
|
|
76
166
|
aria-describedby={ariaDescribedBy}
|
|
@@ -79,24 +169,35 @@ const Block = React.forwardRef<HTMLButtonElement, BlockProps>(
|
|
|
79
169
|
ref={forwardedRef}
|
|
80
170
|
{...rest}
|
|
81
171
|
>
|
|
82
|
-
<
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
172
|
+
<BlockTitle>
|
|
173
|
+
{title}
|
|
174
|
+
|
|
175
|
+
<ActionsContainer>
|
|
176
|
+
{actions}
|
|
177
|
+
{!isCollapsable ? null : (
|
|
178
|
+
<IconButton
|
|
179
|
+
icon={isOpen ? <ArrowUpIcon /> : <ArrowDownIcon />}
|
|
180
|
+
title={collapseButtonLabel}
|
|
181
|
+
level="tertiary"
|
|
182
|
+
ghost
|
|
183
|
+
size="small"
|
|
184
|
+
onClick={handleCollapse}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
</ActionsContainer>
|
|
188
|
+
</BlockTitle>
|
|
189
|
+
{!isCollapsable ? null : (
|
|
190
|
+
<BlockContent
|
|
191
|
+
ref={contentRef}
|
|
192
|
+
isCollapsable={isCollapsable}
|
|
193
|
+
$overflow={shouldAnimate || !isOpen ? 'hidden' : 'inherit'}
|
|
194
|
+
$height={true === isOpen ? contentHeight : 0}
|
|
195
|
+
shouldAnimate={shouldAnimate}
|
|
196
|
+
aria-hidden={!isOpen}
|
|
197
|
+
>
|
|
198
|
+
{children}
|
|
199
|
+
</BlockContent>
|
|
200
|
+
)}
|
|
100
201
|
</Container>
|
|
101
202
|
);
|
|
102
203
|
}
|
|
@@ -2,47 +2,100 @@ import React from 'react';
|
|
|
2
2
|
import {fireEvent, render, screen} from '../../storybook/test-util';
|
|
3
3
|
import {Block} from './Block';
|
|
4
4
|
import {IconButton} from '../IconButton/IconButton';
|
|
5
|
-
import {
|
|
5
|
+
import {CloseIcon, EditIcon, PlusIcon} from '../../icons';
|
|
6
6
|
|
|
7
7
|
test('it renders without actions', () => {
|
|
8
|
-
render(<Block
|
|
8
|
+
render(<Block title="I am a block" />);
|
|
9
9
|
|
|
10
|
-
expect(screen.getByText('
|
|
10
|
+
expect(screen.getByText('I am a block')).toBeInTheDocument();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
test('it renders
|
|
13
|
+
test('it renders actions passed by props', () => {
|
|
14
14
|
const onRemove = jest.fn();
|
|
15
|
+
const onEdit = jest.fn();
|
|
15
16
|
|
|
16
17
|
render(
|
|
17
|
-
<Block
|
|
18
|
+
<Block
|
|
19
|
+
title="My block"
|
|
20
|
+
actions={
|
|
21
|
+
<>
|
|
22
|
+
<IconButton
|
|
23
|
+
level="tertiary"
|
|
24
|
+
ghost="borderless"
|
|
25
|
+
size="small"
|
|
26
|
+
key="edit"
|
|
27
|
+
icon={<EditIcon />}
|
|
28
|
+
title="Edit"
|
|
29
|
+
onClick={onEdit}
|
|
30
|
+
/>
|
|
31
|
+
<IconButton
|
|
32
|
+
level="tertiary"
|
|
33
|
+
ghost="borderless"
|
|
34
|
+
size="small"
|
|
35
|
+
key="remove"
|
|
36
|
+
icon={<CloseIcon />}
|
|
37
|
+
title="Remove"
|
|
38
|
+
onClick={onRemove}
|
|
39
|
+
/>
|
|
40
|
+
</>
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
18
43
|
);
|
|
19
44
|
|
|
45
|
+
const editIconButton = screen.getByTitle('Edit');
|
|
46
|
+
fireEvent.click(editIconButton);
|
|
47
|
+
expect(onEdit).toBeCalled();
|
|
48
|
+
|
|
20
49
|
const removeIconButton = screen.getByTitle('Remove');
|
|
21
50
|
fireEvent.click(removeIconButton);
|
|
22
51
|
expect(onRemove).toBeCalled();
|
|
23
52
|
});
|
|
24
53
|
|
|
54
|
+
test('it supports collapsing', () => {
|
|
55
|
+
const onCollapse = jest.fn();
|
|
56
|
+
const isOpen = false;
|
|
57
|
+
jest.useFakeTimers();
|
|
58
|
+
|
|
59
|
+
render(
|
|
60
|
+
<Block title="My block" isOpen={isOpen} onCollapse={onCollapse} collapseButtonLabel="Collapse" actions={<></>}>
|
|
61
|
+
I am a block
|
|
62
|
+
</Block>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const collapseIconButton = screen.getByTitle('Collapse');
|
|
66
|
+
fireEvent.click(collapseIconButton);
|
|
67
|
+
|
|
68
|
+
jest.runAllTimers();
|
|
69
|
+
|
|
70
|
+
expect(onCollapse).toBeCalled();
|
|
71
|
+
expect(screen.getByText('I am a block')).toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
|
|
25
74
|
test('Block supports forwardRef', () => {
|
|
26
75
|
const ref = {current: null};
|
|
27
76
|
|
|
28
|
-
render(<Block ref={ref}
|
|
77
|
+
render(<Block title="My block" ref={ref} />);
|
|
29
78
|
|
|
30
79
|
expect(ref.current).not.toBe(null);
|
|
31
80
|
});
|
|
32
81
|
|
|
33
82
|
test('Block supports ...rest props', () => {
|
|
34
|
-
render(<Block data-testid="my_value"
|
|
83
|
+
render(<Block title="My block" data-testid="my_value" />);
|
|
35
84
|
|
|
36
85
|
expect(screen.getByTestId('my_value')).toBeInTheDocument();
|
|
37
86
|
});
|
|
38
87
|
|
|
39
88
|
test('it renders children with icon', () => {
|
|
89
|
+
const onCollapse = jest.fn();
|
|
90
|
+
const isOpen = false;
|
|
91
|
+
|
|
40
92
|
render(
|
|
41
|
-
<Block>
|
|
42
|
-
<PlusIcon data-testid="children-icon" />
|
|
93
|
+
<Block title="My block" isOpen={isOpen} onCollapse={onCollapse} collapseButtonLabel="Collapse" actions={<></>}>
|
|
94
|
+
<PlusIcon data-testid="children-icon" />
|
|
95
|
+
Icon
|
|
43
96
|
</Block>
|
|
44
97
|
);
|
|
45
98
|
|
|
46
|
-
expect(screen.getByText('
|
|
99
|
+
expect(screen.getByText('Icon')).toBeInTheDocument();
|
|
47
100
|
expect(screen.getByTestId('children-icon')).toBeInTheDocument();
|
|
48
101
|
});
|
|
@@ -475,3 +475,56 @@ If you want your `Table.Header` to stay on top when scrolling in the Table, just
|
|
|
475
475
|
}}
|
|
476
476
|
</Story>
|
|
477
477
|
</Canvas>
|
|
478
|
+
|
|
479
|
+
## Table with warning rows
|
|
480
|
+
|
|
481
|
+
<Canvas>
|
|
482
|
+
<Story name="Warning rows">
|
|
483
|
+
{args => {
|
|
484
|
+
return (
|
|
485
|
+
<Scrollable height={250}>
|
|
486
|
+
<Table hasWarningRows={true}>
|
|
487
|
+
<Table.Header sticky={0}>
|
|
488
|
+
<Table.HeaderCell>Name</Table.HeaderCell>
|
|
489
|
+
<Table.HeaderCell>Family</Table.HeaderCell>
|
|
490
|
+
<Table.HeaderCell>Order</Table.HeaderCell>
|
|
491
|
+
<Table.HeaderCell>Genus</Table.HeaderCell>
|
|
492
|
+
<Table.HeaderCell>Conservation status</Table.HeaderCell>
|
|
493
|
+
<Table.HeaderCell>Actions</Table.HeaderCell>
|
|
494
|
+
</Table.Header>
|
|
495
|
+
<Table.Body>
|
|
496
|
+
<Table.Row level="warning">
|
|
497
|
+
<Table.Cell rowTitle={args.displayRowTitle}>Giant panda</Table.Cell>
|
|
498
|
+
<Table.Cell>Ursidae</Table.Cell>
|
|
499
|
+
<Table.Cell>Carnivora</Table.Cell>
|
|
500
|
+
<Table.Cell>Ursus</Table.Cell>
|
|
501
|
+
<Table.Cell>
|
|
502
|
+
<Badge level="warning">vu</Badge>
|
|
503
|
+
</Table.Cell>
|
|
504
|
+
<Table.ActionCell>
|
|
505
|
+
<Button level="primary" ghost>
|
|
506
|
+
Button
|
|
507
|
+
</Button>
|
|
508
|
+
</Table.ActionCell>
|
|
509
|
+
</Table.Row>
|
|
510
|
+
<Table.Row>
|
|
511
|
+
<Table.Cell rowTitle={args.displayRowTitle}>Red panda</Table.Cell>
|
|
512
|
+
<Table.Cell>Ailuridae</Table.Cell>
|
|
513
|
+
<Table.Cell>Carnivora</Table.Cell>
|
|
514
|
+
<Table.Cell>Ailurus</Table.Cell>
|
|
515
|
+
<Table.Cell>
|
|
516
|
+
<Badge level="warning">vu</Badge>
|
|
517
|
+
</Table.Cell>
|
|
518
|
+
<Table.ActionCell>
|
|
519
|
+
<Button level="primary" ghost>
|
|
520
|
+
Button
|
|
521
|
+
</Button>
|
|
522
|
+
</Table.ActionCell>
|
|
523
|
+
</Table.Row>
|
|
524
|
+
</Table.Body>
|
|
525
|
+
</Table>
|
|
526
|
+
</Scrollable>
|
|
527
|
+
);
|
|
528
|
+
}}
|
|
529
|
+
</Story>
|
|
530
|
+
</Canvas>
|
|
@@ -22,6 +22,11 @@ type TableProps = Override<
|
|
|
22
22
|
*/
|
|
23
23
|
isSelectable?: boolean;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Define if the table has some warning.
|
|
27
|
+
*/
|
|
28
|
+
hasWarningRows?: boolean;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Define if the checkbox should be always displayed or displayed on hover.
|
|
27
32
|
* This props should be true when one element is checked.
|
|
@@ -60,6 +65,7 @@ type TableProps = Override<
|
|
|
60
65
|
*/
|
|
61
66
|
const Table = ({
|
|
62
67
|
isSelectable = false,
|
|
68
|
+
hasWarningRows = false,
|
|
63
69
|
displayCheckbox = false,
|
|
64
70
|
isDragAndDroppable = false,
|
|
65
71
|
onReorder = undefined,
|
|
@@ -67,8 +73,8 @@ const Table = ({
|
|
|
67
73
|
...rest
|
|
68
74
|
}: TableProps) => {
|
|
69
75
|
const providerValue = useMemo(
|
|
70
|
-
() => ({isSelectable, displayCheckbox, isDragAndDroppable, onReorder}),
|
|
71
|
-
[isSelectable, displayCheckbox, isDragAndDroppable, onReorder]
|
|
76
|
+
() => ({isSelectable, hasWarningRows, displayCheckbox, isDragAndDroppable, onReorder}),
|
|
77
|
+
[isSelectable, hasWarningRows, displayCheckbox, isDragAndDroppable, onReorder]
|
|
72
78
|
);
|
|
73
79
|
|
|
74
80
|
return (
|
|
@@ -2,6 +2,7 @@ import {createContext} from 'react';
|
|
|
2
2
|
|
|
3
3
|
type TableContextType = {
|
|
4
4
|
isSelectable: boolean;
|
|
5
|
+
hasWarningRows: boolean;
|
|
5
6
|
displayCheckbox: boolean;
|
|
6
7
|
isDragAndDroppable: boolean;
|
|
7
8
|
onReorder: ((reorderedIndices: number[]) => void) | undefined;
|
|
@@ -9,6 +10,7 @@ type TableContextType = {
|
|
|
9
10
|
|
|
10
11
|
const TableContext = createContext<TableContextType>({
|
|
11
12
|
isSelectable: false,
|
|
13
|
+
hasWarningRows: false,
|
|
12
14
|
displayCheckbox: false,
|
|
13
15
|
isDragAndDroppable: false,
|
|
14
16
|
onReorder: undefined,
|
|
@@ -19,6 +19,10 @@ const TableHead = styled.thead<{sticky?: number} & AkeneoThemedProps>`
|
|
|
19
19
|
const SelectColumn = styled.th`
|
|
20
20
|
width: 40px;
|
|
21
21
|
`;
|
|
22
|
+
const HasWarningColumn = styled.th`
|
|
23
|
+
width: 20px;
|
|
24
|
+
background: linear-gradient(to top, ${getColor('grey', 120)} 1px, ${getColor('white')} 0px);
|
|
25
|
+
`;
|
|
22
26
|
const OrderColumn = styled.th`
|
|
23
27
|
width: 40px;
|
|
24
28
|
background: linear-gradient(to top, ${getColor('grey', 120)} 1px, ${getColor('white')} 0px);
|
|
@@ -38,13 +42,14 @@ type TableHeaderProps = {
|
|
|
38
42
|
|
|
39
43
|
const TableHeader = React.forwardRef<HTMLTableSectionElement, TableHeaderProps>(
|
|
40
44
|
({children, sticky, ...rest}: TableHeaderProps, forwardedRef: Ref<HTMLTableSectionElement>) => {
|
|
41
|
-
const {isSelectable, isDragAndDroppable} = React.useContext(TableContext);
|
|
45
|
+
const {isSelectable, isDragAndDroppable, hasWarningRows} = React.useContext(TableContext);
|
|
42
46
|
|
|
43
47
|
return (
|
|
44
48
|
<TableHead sticky={sticky} ref={forwardedRef}>
|
|
45
49
|
<tr {...rest}>
|
|
46
50
|
{/* Add new column for checkbox to be displayed properly in the tbody */}
|
|
47
51
|
{isSelectable && <SelectColumn />}
|
|
52
|
+
{hasWarningRows && <HasWarningColumn />}
|
|
48
53
|
{isDragAndDroppable && <OrderColumn />}
|
|
49
54
|
{children}
|
|
50
55
|
</tr>
|
|
@@ -14,12 +14,15 @@ import {Checkbox} from '../../../components';
|
|
|
14
14
|
import {Override} from '../../../shared';
|
|
15
15
|
import {TableContext} from '../TableContext';
|
|
16
16
|
import {TableCell} from '../TableCell/TableCell';
|
|
17
|
-
import {RowIcon} from '../../../icons';
|
|
17
|
+
import {RowIcon, DangerIcon} from '../../../icons';
|
|
18
18
|
import {PlaceholderPosition, usePlaceholderPosition} from '../../../hooks/usePlaceholderPosition';
|
|
19
19
|
|
|
20
|
+
type Level = 'warning';
|
|
21
|
+
|
|
20
22
|
const RowContainer = styled.tr<
|
|
21
23
|
{
|
|
22
24
|
isSelected: boolean;
|
|
25
|
+
level: Level;
|
|
23
26
|
isClickable: boolean;
|
|
24
27
|
isDragAndDroppable: boolean;
|
|
25
28
|
placeholderPosition: PlaceholderPosition;
|
|
@@ -73,6 +76,17 @@ const RowContainer = styled.tr<
|
|
|
73
76
|
&:hover > td > div {
|
|
74
77
|
opacity: 1;
|
|
75
78
|
}
|
|
79
|
+
|
|
80
|
+
${({level}) =>
|
|
81
|
+
level === 'warning' &&
|
|
82
|
+
css`
|
|
83
|
+
> td {
|
|
84
|
+
:first-child {
|
|
85
|
+
padding: 0 0 0 5px;
|
|
86
|
+
}
|
|
87
|
+
background-color: ${getColor('yellow', 10)};
|
|
88
|
+
}
|
|
89
|
+
`};
|
|
76
90
|
`;
|
|
77
91
|
|
|
78
92
|
const CheckboxContainer = styled.td<{isVisible: boolean}>`
|
|
@@ -98,6 +112,10 @@ const HandleCell = styled(TableCell)`
|
|
|
98
112
|
}
|
|
99
113
|
`;
|
|
100
114
|
|
|
115
|
+
const WarningIcon = styled(DangerIcon)`
|
|
116
|
+
color: ${getColor('yellow', 120)};
|
|
117
|
+
`;
|
|
118
|
+
|
|
101
119
|
type TableRowProps = Override<
|
|
102
120
|
HTMLAttributes<HTMLTableRowElement>,
|
|
103
121
|
{
|
|
@@ -116,6 +134,11 @@ type TableRowProps = Override<
|
|
|
116
134
|
*/
|
|
117
135
|
isSelected?: boolean;
|
|
118
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Define if the row has a warning
|
|
139
|
+
*/
|
|
140
|
+
level?: Level;
|
|
141
|
+
|
|
119
142
|
/**
|
|
120
143
|
* Function called when the user clicks on the row
|
|
121
144
|
*/
|
|
@@ -143,6 +166,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
143
166
|
{
|
|
144
167
|
rowIndex = 0,
|
|
145
168
|
isSelected,
|
|
169
|
+
level,
|
|
146
170
|
onSelectToggle,
|
|
147
171
|
onClick,
|
|
148
172
|
draggable,
|
|
@@ -156,7 +180,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
156
180
|
const [placeholderPosition, placeholderDragEnter, placeholderDragLeave, placeholderDragEnd] =
|
|
157
181
|
usePlaceholderPosition(rowIndex);
|
|
158
182
|
|
|
159
|
-
const {isSelectable, displayCheckbox, isDragAndDroppable} = useContext(TableContext);
|
|
183
|
+
const {isSelectable, displayCheckbox, isDragAndDroppable, hasWarningRows} = useContext(TableContext);
|
|
160
184
|
if (isSelectable && (undefined === isSelected || undefined === onSelectToggle)) {
|
|
161
185
|
throw Error('A row in a selectable table should have the prop "isSelected" and "onSelectToggle"');
|
|
162
186
|
}
|
|
@@ -185,6 +209,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
185
209
|
ref={forwardedRef}
|
|
186
210
|
isClickable={undefined !== onClick}
|
|
187
211
|
isSelected={!!isSelected}
|
|
212
|
+
level={level}
|
|
188
213
|
isDragAndDroppable={isDragAndDroppable}
|
|
189
214
|
onClick={onClick}
|
|
190
215
|
placeholderPosition={isDragAndDroppable ? placeholderPosition : 'none'}
|
|
@@ -215,6 +240,7 @@ const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
215
240
|
<RowIcon size={16} />
|
|
216
241
|
</HandleCell>
|
|
217
242
|
)}
|
|
243
|
+
{hasWarningRows && <TableCell>{level === 'warning' && <WarningIcon size={16} />}</TableCell>}
|
|
218
244
|
{children}
|
|
219
245
|
</RowContainer>
|
|
220
246
|
);
|