@carbon/ibm-products 2.0.0-rc.25 → 2.0.0-rc.26
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -4
- package/css/index-full-carbon.css +69 -97
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +3 -3
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +9 -88
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +69 -97
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +3 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +69 -97
- package/css/index.css.map +1 -1
- package/css/index.min.css +3 -3
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelectBody.js +1 -0
- package/es/components/AddSelect/AddSelectFormControl.js +92 -0
- package/es/components/AddSelect/AddSelectList.js +26 -195
- package/es/components/AddSelect/AddSelectRow.js +220 -0
- package/es/components/AddSelect/hooks/useFocus.js +35 -0
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +1 -1
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +15 -65
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +5 -2
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +112 -0
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/TearsheetWrapper.js +1 -0
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +29 -23
- package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -0
- package/es/components/Datagrid/index.js +7 -7
- package/es/components/Datagrid/useInfiniteScroll.js +5 -1
- package/es/components/Datagrid/useOnRowClick.js +3 -3
- package/es/components/Datagrid/useSortableColumns.js +7 -5
- package/es/components/Datagrid/utils/getAutoSizedColumnWidth.js +29 -0
- package/es/components/ExampleComponent/ExampleComponent.js +39 -5
- package/es/components/ExampleComponent/useExample.js +51 -0
- package/es/components/InlineEditV1/InlineEditV1.js +15 -20
- package/es/components/InlineEditV2/InlineEditV2.js +21 -31
- package/es/components/index.js +1 -1
- package/es/global/js/package-settings.js +24 -3
- package/es/global/js/utils/story-helper.js +9 -0
- package/es/global/js/utils/test-helper.js +38 -6
- package/lib/components/AddSelect/AddSelectBody.js +1 -0
- package/lib/components/AddSelect/AddSelectFormControl.js +110 -0
- package/lib/components/AddSelect/AddSelectList.js +29 -203
- package/lib/components/AddSelect/AddSelectRow.js +247 -0
- package/lib/components/AddSelect/hooks/useFocus.js +46 -0
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +1 -1
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +16 -69
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +5 -2
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +132 -0
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/TearsheetWrapper.js +1 -0
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +23 -16
- package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -0
- package/lib/components/Datagrid/index.js +9 -1
- package/lib/components/Datagrid/useInfiniteScroll.js +5 -0
- package/lib/components/Datagrid/useOnRowClick.js +3 -3
- package/lib/components/Datagrid/useSortableColumns.js +7 -5
- package/lib/components/Datagrid/utils/getAutoSizedColumnWidth.js +40 -0
- package/lib/components/ExampleComponent/ExampleComponent.js +47 -4
- package/lib/components/ExampleComponent/useExample.js +63 -0
- package/lib/components/InlineEditV1/InlineEditV1.js +14 -19
- package/lib/components/InlineEditV2/InlineEditV2.js +20 -30
- package/lib/components/index.js +6 -0
- package/lib/global/js/package-settings.js +24 -3
- package/lib/global/js/utils/story-helper.js +13 -2
- package/lib/global/js/utils/test-helper.js +42 -8
- package/package.json +2 -2
- package/scss/components/AddSelect/_add-select.scss +4 -16
- package/scss/components/Datagrid/styles/addons/_CustomizeColumnsTearsheet.scss +15 -2
- package/scss/components/Datagrid/styles/addons/_RowSizeDropdown.scss +18 -6
- package/scss/components/InlineEditV1/_inline-edit-v1.scss +5 -89
- package/scss/components/InlineEditV2/_inline-edit-v2.scss +42 -3
- package/scss/components/SidePanel/_side-panel.scss +2 -1
@@ -0,0 +1,112 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2023, 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
import React from 'react';
|
8
|
+
import { PropTypes } from 'prop-types';
|
9
|
+
import { Checkbox } from '@carbon/react';
|
10
|
+
import { isColumnVisible } from './common';
|
11
|
+
import DraggableElement from '../../DraggableElement';
|
12
|
+
import { pkg } from '../../../../../settings';
|
13
|
+
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
14
|
+
export var DraggableItemsList = function DraggableItemsList(_ref) {
|
15
|
+
var columns = _ref.columns,
|
16
|
+
filterString = _ref.filterString,
|
17
|
+
focusIndex = _ref.focusIndex,
|
18
|
+
getNextIndex = _ref.getNextIndex,
|
19
|
+
isTableSortable = _ref.isTableSortable,
|
20
|
+
moveElement = _ref.moveElement,
|
21
|
+
onSelectColumn = _ref.onSelectColumn,
|
22
|
+
setAriaRegionText = _ref.setAriaRegionText,
|
23
|
+
setColumnsObject = _ref.setColumnsObject,
|
24
|
+
setFocusIndex = _ref.setFocusIndex;
|
25
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, columns // hide the columns without Header, e.g the sticky actions, spacer
|
26
|
+
.filter(function (colDef) {
|
27
|
+
var _colDef$Header$props$, _colDef$Header$props;
|
28
|
+
|
29
|
+
var sortableTitle = isTableSortable && ((_colDef$Header$props$ = colDef.Header().props.children.props) === null || _colDef$Header$props$ === void 0 ? void 0 : _colDef$Header$props$.title);
|
30
|
+
return !!colDef.Header.props && !!((_colDef$Header$props = colDef.Header.props) !== null && _colDef$Header$props !== void 0 && _colDef$Header$props.title) || isTableSortable && !!sortableTitle;
|
31
|
+
}).filter(function (colDef) {
|
32
|
+
return !colDef.isAction;
|
33
|
+
}).filter(function (colDef) {
|
34
|
+
var _colDef$Header$props$2, _colDef$Header$props2, _colDef$Header$props3;
|
35
|
+
|
36
|
+
var sortableTitle = isTableSortable && ((_colDef$Header$props$2 = colDef.Header().props.children.props) === null || _colDef$Header$props$2 === void 0 ? void 0 : _colDef$Header$props$2.title);
|
37
|
+
return filterString.length === 0 || (isTableSortable ? sortableTitle === null || sortableTitle === void 0 ? void 0 : sortableTitle.toLowerCase().includes(filterString) : (_colDef$Header$props2 = colDef.Header.props) === null || _colDef$Header$props2 === void 0 ? void 0 : (_colDef$Header$props3 = _colDef$Header$props2.title) === null || _colDef$Header$props3 === void 0 ? void 0 : _colDef$Header$props3.toLowerCase().includes(filterString)) && colDef.id !== 'spacer';
|
38
|
+
}).map(function (colDef, i) {
|
39
|
+
var _colDef$Header$props$3, _colDef$Header$props4, _colDef$Header$props5, _colDef$Header$props6, _colDef$Header$props7;
|
40
|
+
|
41
|
+
var isSortableColumn = !!colDef.canSort && !!isTableSortable;
|
42
|
+
var sortableTitle = isTableSortable && ((_colDef$Header$props$3 = colDef.Header().props.children.props) === null || _colDef$Header$props$3 === void 0 ? void 0 : _colDef$Header$props$3.title);
|
43
|
+
var searchString = new RegExp('(' + filterString + ')');
|
44
|
+
var res = filterString.length ? isSortableColumn ? sortableTitle.toLowerCase().split(searchString) : colDef.Header.props.title.toLowerCase().split(searchString) : null;
|
45
|
+
var firstWord = res !== null ? res[0] === '' ? res[1].charAt(0).toUpperCase() + res[1].substring(1) : res[0].charAt(0).toUpperCase() + res[0].substring(1) : null;
|
46
|
+
var highlightedText = res !== null ? res[0] === '' ? "<strong>".concat(firstWord, "</strong>") + res[2] : firstWord + "<strong>".concat(res[1], "</strong>") + res[2] : isSortableColumn ? sortableTitle : (_colDef$Header$props4 = colDef.Header.props) === null || _colDef$Header$props4 === void 0 ? void 0 : _colDef$Header$props4.title;
|
47
|
+
var isFrozenColumn = !!colDef.sticky;
|
48
|
+
var listContents = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
|
49
|
+
wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox-wrapper"),
|
50
|
+
checked: isColumnVisible(colDef),
|
51
|
+
disabled: isFrozenColumn,
|
52
|
+
onChange: function onChange(_, _ref2) {
|
53
|
+
var checked = _ref2.checked;
|
54
|
+
return onSelectColumn(colDef, checked);
|
55
|
+
},
|
56
|
+
id: "".concat(blockClass, "__customization-column-").concat(colDef.id),
|
57
|
+
labelText: isSortableColumn ? sortableTitle : (_colDef$Header$props5 = colDef.Header.props) === null || _colDef$Header$props5 === void 0 ? void 0 : _colDef$Header$props5.title,
|
58
|
+
title: isSortableColumn ? sortableTitle : (_colDef$Header$props6 = colDef.Header.props) === null || _colDef$Header$props6 === void 0 ? void 0 : _colDef$Header$props6.title,
|
59
|
+
className: "".concat(blockClass, "__customize-columns-checkbox"),
|
60
|
+
hideLabel: true
|
61
|
+
}), /*#__PURE__*/React.createElement("div", {
|
62
|
+
dangerouslySetInnerHTML: {
|
63
|
+
__html: highlightedText
|
64
|
+
},
|
65
|
+
className: "".concat(blockClass, "__customize-columns-checkbox-visible-label")
|
66
|
+
}));
|
67
|
+
return /*#__PURE__*/React.createElement(DraggableElement, {
|
68
|
+
key: colDef.id,
|
69
|
+
index: i,
|
70
|
+
listData: columns,
|
71
|
+
setListData: setColumnsObject,
|
72
|
+
id: "dnd-datagrid-columns-".concat(colDef.id),
|
73
|
+
type: "column-customization",
|
74
|
+
disabled: filterString.length > 0 || isFrozenColumn,
|
75
|
+
ariaLabel: isSortableColumn ? sortableTitle : (_colDef$Header$props7 = colDef.Header.props) === null || _colDef$Header$props7 === void 0 ? void 0 : _colDef$Header$props7.title,
|
76
|
+
onGrab: setAriaRegionText,
|
77
|
+
isFocused: focusIndex === i,
|
78
|
+
moveElement: moveElement,
|
79
|
+
onArrowKeyDown: function onArrowKeyDown(e, isGrabbed, currentIndex) {
|
80
|
+
if (isGrabbed) {
|
81
|
+
var _columns$nextIndex;
|
82
|
+
|
83
|
+
var nextIndex = getNextIndex(columns, currentIndex, e.key);
|
84
|
+
e.preventDefault();
|
85
|
+
e.stopPropagation();
|
86
|
+
|
87
|
+
if (nextIndex >= 0 && !((_columns$nextIndex = columns[nextIndex]) !== null && _columns$nextIndex !== void 0 && _columns$nextIndex.sticky)) {
|
88
|
+
setFocusIndex(nextIndex);
|
89
|
+
moveElement(currentIndex, nextIndex);
|
90
|
+
e.target.scrollIntoView({
|
91
|
+
block: 'center'
|
92
|
+
});
|
93
|
+
}
|
94
|
+
}
|
95
|
+
},
|
96
|
+
isSticky: isFrozenColumn,
|
97
|
+
selected: isColumnVisible(colDef)
|
98
|
+
}, listContents);
|
99
|
+
}));
|
100
|
+
};
|
101
|
+
DraggableItemsList.propTypes = {
|
102
|
+
columns: PropTypes.array.isRequired,
|
103
|
+
filterString: PropTypes.string.isRequired,
|
104
|
+
focusIndex: PropTypes.number.isRequired,
|
105
|
+
getNextIndex: PropTypes.func.isRequired,
|
106
|
+
isTableSortable: PropTypes.bool,
|
107
|
+
moveElement: PropTypes.func.isRequired,
|
108
|
+
onSelectColumn: PropTypes.func.isRequired,
|
109
|
+
setAriaRegionText: PropTypes.func.isRequired,
|
110
|
+
setColumnsObject: PropTypes.func.isRequired,
|
111
|
+
setFocusIndex: PropTypes.func.isRequired
|
112
|
+
};
|
@@ -23,6 +23,7 @@ var TearsheetWrapper = function TearsheetWrapper(_ref) {
|
|
23
23
|
|
24
24
|
return /*#__PURE__*/React.createElement(CustomizeColumnsTearsheet, _extends({}, rest, labels, {
|
25
25
|
isOpen: isTearsheetOpen,
|
26
|
+
isTableSortable: instance === null || instance === void 0 ? void 0 : instance.isTableSortable,
|
26
27
|
setIsTearsheetOpen: setIsTearsheetOpen,
|
27
28
|
columnDefinitions: instance.allColumns,
|
28
29
|
originalColumnDefinitions: instance.columns,
|
@@ -1,28 +1,27 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
4
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
5
|
-
var _excluded = ["legendText"];
|
6
|
-
// @flow
|
4
|
+
var _excluded = ["align", "legendText"];
|
7
5
|
|
8
|
-
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
6
|
+
/**
|
7
|
+
* Copyright IBM Corp. 2021, 2023
|
8
|
+
*
|
9
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
14
11
|
*/
|
15
12
|
import * as React from 'react';
|
16
13
|
import PropTypes from 'prop-types';
|
17
14
|
import { Settings } from '@carbon/react/icons';
|
18
|
-
import { IconButton,
|
15
|
+
import { IconButton, Toggletip, ToggletipContent, ToggletipButton } from '@carbon/react';
|
19
16
|
import cx from 'classnames';
|
20
17
|
import RowSizeRadioGroup from './RowSizeRadioGroup';
|
21
18
|
import { pkg } from '../../../../../settings';
|
22
19
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
23
20
|
|
24
21
|
var RowSizeDropdown = function RowSizeDropdown(_ref) {
|
25
|
-
var _ref$
|
22
|
+
var _ref$align = _ref.align,
|
23
|
+
align = _ref$align === void 0 ? 'bottom' : _ref$align,
|
24
|
+
_ref$legendText = _ref.legendText,
|
26
25
|
legendText = _ref$legendText === void 0 ? 'Row height' : _ref$legendText,
|
27
26
|
props = _objectWithoutProperties(_ref, _excluded);
|
28
27
|
|
@@ -31,31 +30,38 @@ var RowSizeDropdown = function RowSizeDropdown(_ref) {
|
|
31
30
|
isOpen = _React$useState2[0],
|
32
31
|
setIsOpen = _React$useState2[1];
|
33
32
|
|
34
|
-
return /*#__PURE__*/React.createElement(
|
35
|
-
align: "bottom-right",
|
36
|
-
caret: false,
|
37
|
-
dropShadow: false,
|
38
|
-
open: isOpen,
|
39
|
-
className: "".concat(blockClass, "__row-height-settings-popover")
|
40
|
-
}, /*#__PURE__*/React.createElement(IconButton, {
|
33
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, !isOpen && /*#__PURE__*/React.createElement(IconButton, {
|
41
34
|
kind: "ghost",
|
42
|
-
align:
|
35
|
+
align: align,
|
43
36
|
onClick: function onClick() {
|
44
|
-
return setIsOpen(
|
37
|
+
return setIsOpen(function (prevOpen) {
|
38
|
+
return !prevOpen;
|
39
|
+
});
|
45
40
|
},
|
46
41
|
label: legendText,
|
47
|
-
className: cx("".concat(blockClass, "__row-size-button")
|
42
|
+
className: cx("".concat(blockClass, "__row-size-button"))
|
48
43
|
}, /*#__PURE__*/React.createElement(Settings, {
|
49
44
|
size: 16
|
50
|
-
})),
|
45
|
+
})), isOpen && /*#__PURE__*/React.createElement(Toggletip, {
|
46
|
+
defaultOpen: true,
|
47
|
+
className: "".concat(blockClass, "__row-size-toggle-tip")
|
48
|
+
}, /*#__PURE__*/React.createElement(ToggletipButton, {
|
49
|
+
className: cx("".concat(blockClass, "__row-size-toggle-tip-button"), "".concat(blockClass, "__row-size-button--open")),
|
50
|
+
label: legendText
|
51
|
+
}, /*#__PURE__*/React.createElement(Settings, {
|
52
|
+
size: 16
|
53
|
+
})), /*#__PURE__*/React.createElement(ToggletipContent, {
|
54
|
+
className: "".concat(blockClass, "__row-size-toggle-tip-content")
|
55
|
+
}, /*#__PURE__*/React.createElement(RowSizeRadioGroup, _extends({}, props, {
|
51
56
|
legendText: legendText,
|
52
57
|
hideRadioGroup: function hideRadioGroup() {
|
53
58
|
setIsOpen(false);
|
54
59
|
}
|
55
|
-
}))));
|
60
|
+
})))));
|
56
61
|
};
|
57
62
|
|
58
63
|
RowSizeDropdown.propTypes = {
|
64
|
+
align: IconButton.propTypes.align,
|
59
65
|
datagridName: PropTypes.string,
|
60
66
|
legendText: PropTypes.string,
|
61
67
|
light: PropTypes.bool,
|
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2020, 2023
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
7
6
|
*/
|
8
7
|
export { Datagrid } from './Datagrid';
|
9
8
|
export { default as useDatagrid } from './useDatagrid';
|
@@ -23,4 +22,5 @@ export { default as useSelectAllWithToggle } from './useSelectAllToggle';
|
|
23
22
|
export { default as useColumnCenterAlign } from './useColumnCenterAlign';
|
24
23
|
export { default as useColumnOrder } from './useColumnOrder';
|
25
24
|
export { default as useInlineEdit } from './useInlineEdit';
|
26
|
-
export { default as useFiltering } from './useFiltering';
|
25
|
+
export { default as useFiltering } from './useFiltering';
|
26
|
+
export { getAutoSizedColumnWidth } from './utils/getAutoSizedColumnWidth';
|
@@ -5,14 +5,18 @@
|
|
5
5
|
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
6
|
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
7
|
*/
|
8
|
-
import { useCallback } from 'react';
|
8
|
+
import { useCallback, useEffect } from 'react';
|
9
9
|
import debounce from 'lodash/debounce';
|
10
10
|
import useParentDimensions from './useParentDimensions';
|
11
11
|
import useResizeTable from './useResizeTable';
|
12
|
+
import { pkg } from '../../settings';
|
12
13
|
|
13
14
|
var useInfiniteScroll = function useInfiniteScroll(hooks) {
|
14
15
|
useParentDimensions(hooks);
|
15
16
|
useResizeTable(hooks);
|
17
|
+
useEffect(function () {
|
18
|
+
pkg.checkReportFeatureEnabled('Datagrid.useInfiniteScroll');
|
19
|
+
}, []);
|
16
20
|
|
17
21
|
var useInstance = function useInstance(instance) {
|
18
22
|
var isFetching = instance.isFetching,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* Licensed Materials - Property of IBM
|
3
3
|
* 5724-Q36
|
4
|
-
* (c) Copyright IBM Corp. 2020
|
4
|
+
* (c) Copyright IBM Corp. 2020, 2023
|
5
5
|
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
6
|
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
7
|
*/
|
@@ -16,9 +16,9 @@ var useOnRowClick = function useOnRowClick(hooks) {
|
|
16
16
|
var id = row.id,
|
17
17
|
toggleRowSelected = row.toggleRowSelected;
|
18
18
|
|
19
|
-
var onClick = function onClick() {
|
19
|
+
var onClick = function onClick(event) {
|
20
20
|
if (!isFetching && onRowClick) {
|
21
|
-
onRowClick(row);
|
21
|
+
onRowClick(row, event);
|
22
22
|
instance.selectedFlatRows && instance.selectedFlatRows.map(function (toggleRow) {
|
23
23
|
return toggleRow.toggleRowSelected(false);
|
24
24
|
});
|
@@ -26,6 +26,8 @@ var ordering = {
|
|
26
26
|
|
27
27
|
var useSortableColumns = function useSortableColumns(hooks) {
|
28
28
|
var sortableVisibleColumns = function sortableVisibleColumns(visibleColumns, _ref) {
|
29
|
+
var _instance$customizeCo;
|
30
|
+
|
29
31
|
var instance = _ref.instance;
|
30
32
|
var onSort = instance.onSort;
|
31
33
|
|
@@ -46,7 +48,7 @@ var useSortableColumns = function useSortableColumns(hooks) {
|
|
46
48
|
|
47
49
|
var sortableColumns = visibleColumns.map(function (column) {
|
48
50
|
var icon = function icon(col, props) {
|
49
|
-
if (col.isSorted) {
|
51
|
+
if (col !== null && col !== void 0 && col.isSorted) {
|
50
52
|
switch (col.isSortedDesc) {
|
51
53
|
case false:
|
52
54
|
return /*#__PURE__*/React.createElement(ArrowUp, _extends({
|
@@ -83,13 +85,13 @@ var useSortableColumns = function useSortableColumns(hooks) {
|
|
83
85
|
|
84
86
|
return column.disableSortBy === true ? column.Header : /*#__PURE__*/React.createElement(Button, {
|
85
87
|
onClick: function onClick() {
|
86
|
-
return onSortClick(headerProp.column);
|
88
|
+
return onSortClick(headerProp === null || headerProp === void 0 ? void 0 : headerProp.column);
|
87
89
|
},
|
88
90
|
kind: "ghost",
|
89
91
|
renderIcon: function renderIcon(props) {
|
90
|
-
return icon(headerProp.column, props);
|
92
|
+
return icon(headerProp === null || headerProp === void 0 ? void 0 : headerProp.column, props);
|
91
93
|
},
|
92
|
-
className: cx("".concat(carbon.prefix, "--table-sort ").concat(blockClass, "--table-sort"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "--table-sort--desc"), headerProp.column.isSortedDesc), _defineProperty(_cx, "".concat(blockClass, "--table-sort--asc"), headerProp.column.isSortedDesc === false), _cx))
|
94
|
+
className: cx("".concat(carbon.prefix, "--table-sort ").concat(blockClass, "--table-sort"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "--table-sort--desc"), headerProp === null || headerProp === void 0 ? void 0 : headerProp.column.isSortedDesc), _defineProperty(_cx, "".concat(blockClass, "--table-sort--asc"), (headerProp === null || headerProp === void 0 ? void 0 : headerProp.column.isSortedDesc) === false), _cx))
|
93
95
|
}, column.Header);
|
94
96
|
};
|
95
97
|
|
@@ -98,7 +100,7 @@ var useSortableColumns = function useSortableColumns(hooks) {
|
|
98
100
|
minWidth: column.disableSortBy === true ? 0 : 90
|
99
101
|
});
|
100
102
|
});
|
101
|
-
return _toConsumableArray(sortableColumns);
|
103
|
+
return (_instance$customizeCo = instance.customizeColumnsProps) !== null && _instance$customizeCo !== void 0 && _instance$customizeCo.isTearsheetOpen ? visibleColumns : _toConsumableArray(sortableColumns);
|
102
104
|
};
|
103
105
|
|
104
106
|
var sortInstanceProps = function sortInstanceProps(instance) {
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Copyright IBM Corp. 2023, 2023
|
5
|
+
*
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
8
|
+
*/
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Calculates the auto sized width of a column
|
12
|
+
* @param {Array<object>} rows - The datagrid rows
|
13
|
+
* @param {string} accessor - The accessor for the column
|
14
|
+
* @param {string} headerText - The header text for the column
|
15
|
+
*/
|
16
|
+
export var getAutoSizedColumnWidth = function getAutoSizedColumnWidth(rows, accessor, headerText) {
|
17
|
+
var maxWidth = 400;
|
18
|
+
var minWidth = 58;
|
19
|
+
var letterSpacing = 10;
|
20
|
+
var cellLength = Math.max.apply(Math, _toConsumableArray(rows.map(function (row) {
|
21
|
+
return ("".concat(row[accessor]) || '').length;
|
22
|
+
})).concat([headerText.length]));
|
23
|
+
|
24
|
+
if (cellLength <= 3) {
|
25
|
+
return minWidth;
|
26
|
+
}
|
27
|
+
|
28
|
+
return Math.min(maxWidth, cellLength * letterSpacing + 16);
|
29
|
+
};
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
-
var _excluded = ["borderColor", "boxedBorder", "className", "disabled", "onPrimaryClick", "onSecondaryClick", "primaryButtonLabel", "primaryKind", "secondaryButtonLabel", "secondaryKind", "size", "style"];
|
5
|
+
var _excluded = ["borderColor", "boxedBorder", "className", "disabled", "usesExampleHook", "onPrimaryClick", "onSecondaryClick", "primaryButtonLabel", "primaryKind", "secondaryButtonLabel", "secondaryKind", "secondaryIcon", "size", "style"];
|
5
6
|
|
6
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
7
8
|
|
@@ -14,13 +15,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
14
15
|
* LICENSE file in the root directory of this source tree.
|
15
16
|
*/
|
16
17
|
// Import portions of React that are needed.
|
17
|
-
import React from 'react'; // Other standard imports.
|
18
|
+
import React, { useRef, useEffect, useState } from 'react'; // Other standard imports.
|
18
19
|
|
19
20
|
import PropTypes from 'prop-types';
|
20
21
|
import cx from 'classnames';
|
21
22
|
import { pkg } from '../../settings'; // Carbon and package components we use.
|
22
23
|
|
23
|
-
import { Button, ButtonSet } from '@carbon/react';
|
24
|
+
import { Button, ButtonSet } from '@carbon/react';
|
25
|
+
import useExample from './useExample'; // The block part of our conventional BEM class names (blockClass__E--M).
|
24
26
|
|
25
27
|
var blockClass = "".concat(pkg.prefix, "--example-component");
|
26
28
|
var componentName = 'ExampleComponent'; // NOTE: the component SCSS is not imported here: it is rolled up separately.
|
@@ -29,6 +31,7 @@ var componentName = 'ExampleComponent'; // NOTE: the component SCSS is not impor
|
|
29
31
|
var defaults = {
|
30
32
|
primaryKind: 'primary',
|
31
33
|
secondaryKind: 'secondary',
|
34
|
+
secondaryIcon: null,
|
32
35
|
size: 'lg'
|
33
36
|
};
|
34
37
|
/**
|
@@ -40,6 +43,7 @@ export var ExampleComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
40
43
|
boxedBorder = _ref.boxedBorder,
|
41
44
|
className = _ref.className,
|
42
45
|
disabled = _ref.disabled,
|
46
|
+
usesExampleHook = _ref.usesExampleHook,
|
43
47
|
onPrimaryClick = _ref.onPrimaryClick,
|
44
48
|
onSecondaryClick = _ref.onSecondaryClick,
|
45
49
|
primaryButtonLabel = _ref.primaryButtonLabel,
|
@@ -48,11 +52,22 @@ export var ExampleComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
48
52
|
secondaryButtonLabel = _ref.secondaryButtonLabel,
|
49
53
|
_ref$secondaryKind = _ref.secondaryKind,
|
50
54
|
secondaryKind = _ref$secondaryKind === void 0 ? defaults.secondaryKind : _ref$secondaryKind,
|
55
|
+
_ref$secondaryIcon = _ref.secondaryIcon,
|
56
|
+
secondaryIcon = _ref$secondaryIcon === void 0 ? defaults.secondaryIcon : _ref$secondaryIcon,
|
51
57
|
_ref$size = _ref.size,
|
52
58
|
size = _ref$size === void 0 ? defaults.size : _ref$size,
|
53
59
|
style = _ref.style,
|
54
60
|
rest = _objectWithoutProperties(_ref, _excluded);
|
55
61
|
|
62
|
+
var _useState = useState(primaryButtonLabel),
|
63
|
+
_useState2 = _slicedToArray(_useState, 2),
|
64
|
+
thePrimaryButtonLabel = _useState2[0],
|
65
|
+
setThePrimaryButtonLabel = _useState2[1];
|
66
|
+
|
67
|
+
var _useExample = useExample(usesExampleHook),
|
68
|
+
_useExample2 = _slicedToArray(_useExample, 1),
|
69
|
+
exampleUse = _useExample2[0];
|
70
|
+
|
56
71
|
var modeClass = boxedBorder ? "".concat(blockClass, "--boxed-set") : "".concat(blockClass, "--shadow-set");
|
57
72
|
|
58
73
|
var handlePrimaryClick = function handlePrimaryClick(e) {
|
@@ -67,6 +82,14 @@ export var ExampleComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
67
82
|
}
|
68
83
|
};
|
69
84
|
|
85
|
+
var theSecondaryIcon = useRef(secondaryIcon && pkg.checkReportFeatureEnabled('ExampleComponent.secondaryIcon') ? secondaryIcon : null);
|
86
|
+
useEffect(function () {
|
87
|
+
if (usesExampleHook !== undefined && pkg.checkReportFeatureEnabled('ExampleComponent.useExample')) {
|
88
|
+
setThePrimaryButtonLabel("".concat(primaryButtonLabel, " ").concat(exampleUse.toFixed(1), "s"));
|
89
|
+
} else {
|
90
|
+
setThePrimaryButtonLabel(primaryButtonLabel);
|
91
|
+
}
|
92
|
+
}, [primaryButtonLabel, usesExampleHook, exampleUse]);
|
70
93
|
return /*#__PURE__*/React.createElement(ButtonSet, _extends({}, rest, {
|
71
94
|
className: cx(blockClass, // Apply the block class to the main HTML element
|
72
95
|
className, // Apply any supplied class names to the main HTML element.
|
@@ -78,6 +101,7 @@ export var ExampleComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
78
101
|
className: "".concat(blockClass, "__secondary-button"),
|
79
102
|
kind: secondaryKind,
|
80
103
|
onClick: handleSecondaryClick,
|
104
|
+
renderIcon: theSecondaryIcon.current,
|
81
105
|
disabled: disabled,
|
82
106
|
size: size
|
83
107
|
}, secondaryButtonLabel), /*#__PURE__*/React.createElement(Button, {
|
@@ -86,7 +110,7 @@ export var ExampleComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
86
110
|
onClick: handlePrimaryClick,
|
87
111
|
disabled: disabled,
|
88
112
|
size: size
|
89
|
-
},
|
113
|
+
}, thePrimaryButtonLabel));
|
90
114
|
}); // Return a placeholder if not released and not enabled by feature flag.
|
91
115
|
|
92
116
|
ExampleComponent = pkg.checkComponentEnabled(ExampleComponent, componentName); // The display name of the component, used by React. Note that displayName
|
@@ -142,6 +166,11 @@ ExampleComponent.propTypes = {
|
|
142
166
|
*/
|
143
167
|
secondaryButtonLabel: PropTypes.string.isRequired,
|
144
168
|
|
169
|
+
/**
|
170
|
+
* The icon to use for the secondary button.
|
171
|
+
*/
|
172
|
+
secondaryIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
173
|
+
|
145
174
|
/**
|
146
175
|
* The kind of button for the secondary button ('secondary' or 'tertiary').
|
147
176
|
*/
|
@@ -155,5 +184,10 @@ ExampleComponent.propTypes = {
|
|
155
184
|
/**
|
156
185
|
* Optional style settings for the containing node.
|
157
186
|
*/
|
158
|
-
style: PropTypes.object
|
187
|
+
style: PropTypes.object,
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Hook example timeout (in seconds) or undefined
|
191
|
+
*/
|
192
|
+
usesExampleHook: PropTypes.number
|
159
193
|
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Copyright IBM Corp. 2020, 2021
|
5
|
+
*
|
6
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
8
|
+
*/
|
9
|
+
import { useState, useEffect } from 'react';
|
10
|
+
import { pkg } from '../../settings';
|
11
|
+
|
12
|
+
var useExample = function useExample(initialTime) {
|
13
|
+
// NOTE: hooks cannot be called conditionally.
|
14
|
+
//
|
15
|
+
// ** If the hook uses other hooks then they must be called,
|
16
|
+
// ** this could lead to unexpected behavior.
|
17
|
+
// ** As some hooks may still be called even if the condition is false.
|
18
|
+
var _useState = useState( // Disable hook in a safe way if possible, else use despite feature disabled.
|
19
|
+
// Either a console error or warning will be logged.
|
20
|
+
initialTime),
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
22
|
+
time = _useState2[0],
|
23
|
+
setTime = _useState2[1]; // Use of the feature flag to
|
24
|
+
|
25
|
+
|
26
|
+
var feature = 'ExampleComponent.useExample';
|
27
|
+
var tryFeature = initialTime !== undefined;
|
28
|
+
var featureEnabled = tryFeature && pkg.checkReportFeatureEnabled(feature);
|
29
|
+
|
30
|
+
if (tryFeature && !featureEnabled) {
|
31
|
+
// Output a useful message if the feature is disabled.
|
32
|
+
console.warn("Disabled feature \"".concat(feature, "\" does not change the initialTime."));
|
33
|
+
} // Actual hook is code is below
|
34
|
+
|
35
|
+
|
36
|
+
useEffect(function () {
|
37
|
+
if (!featureEnabled) {
|
38
|
+
return;
|
39
|
+
} // turn off all or part of the feature
|
40
|
+
|
41
|
+
|
42
|
+
if (time > 0) {
|
43
|
+
setTimeout(function () {
|
44
|
+
setTime(Math.max(0, time - 0.1));
|
45
|
+
}, 100);
|
46
|
+
}
|
47
|
+
}, [featureEnabled, time]);
|
48
|
+
return [time];
|
49
|
+
};
|
50
|
+
|
51
|
+
export default useExample;
|
@@ -21,7 +21,7 @@ import { pkg } from '../../settings'; // Carbon and package components we use.
|
|
21
21
|
|
22
22
|
/* TODO: @use(s) of carbon components and other package components. */
|
23
23
|
|
24
|
-
import {
|
24
|
+
import { IconButton, usePrefix } from '@carbon/react';
|
25
25
|
import { Close, Edit, EditOff, Checkmark, WarningFilled } from '@carbon/react/icons'; // The block part of our conventional BEM class names (blockClass__E--M).
|
26
26
|
|
27
27
|
var blockClass = "".concat(pkg.prefix, "--inline-edit");
|
@@ -285,35 +285,30 @@ export var InlineEditV1 = /*#__PURE__*/React.forwardRef(function (_ref, refIn) {
|
|
285
285
|
className: cx("".concat(blockClass, "__toolbar"), (_cx3 = {}, _defineProperty(_cx3, "".concat(blockClass, "__toolbar--animation"), toolbarAnimation), _defineProperty(_cx3, "".concat(blockClass, "__toolbar--saveable"), refInput.current && value !== internalValue), _cx3))
|
286
286
|
}, showValidation && /*#__PURE__*/React.createElement("div", {
|
287
287
|
className: "".concat(blockClass, "__validation-icon")
|
288
|
-
}, validationIcon), editing ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(
|
288
|
+
}, validationIcon), editing ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconButton, _extends({
|
289
289
|
className: "".concat(blockClass, "__cancel"),
|
290
290
|
kind: "ghost",
|
291
|
-
|
292
|
-
iconDescription: cancelDescription,
|
291
|
+
label: cancelDescription,
|
293
292
|
onClick: handleCancel,
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
}
|
299
|
-
}, tipPositions.cancel)), /*#__PURE__*/React.createElement(Button, _extends({
|
293
|
+
size: size
|
294
|
+
}, tipPositions.cancel), /*#__PURE__*/React.createElement(Close, {
|
295
|
+
size: 16
|
296
|
+
})), /*#__PURE__*/React.createElement(IconButton, _extends({
|
300
297
|
className: "".concat(blockClass, "__save"),
|
301
298
|
kind: "ghost",
|
302
|
-
|
303
|
-
iconDescription: saveDescription,
|
299
|
+
label: saveDescription,
|
304
300
|
onClick: handleSave,
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
disabled: value === internalValue
|
311
|
-
}, tipPositions.save))) : /*#__PURE__*/React.createElement(IconButton, _extends({
|
301
|
+
disabled: value === internalValue,
|
302
|
+
size: size
|
303
|
+
}, tipPositions.save), /*#__PURE__*/React.createElement(Checkmark, {
|
304
|
+
size: 16
|
305
|
+
}))) : /*#__PURE__*/React.createElement(IconButton, _extends({
|
312
306
|
className: cx("".concat(blockClass, "__edit"), _defineProperty({}, "".concat(blockClass, "__edit--always-visible"), editAlwaysVisible)),
|
313
307
|
kind: "ghost",
|
314
308
|
label: editDescription,
|
315
309
|
onClick: handleEdit,
|
316
|
-
disabled: disabled
|
310
|
+
disabled: disabled,
|
311
|
+
size: size
|
317
312
|
}, tipPositions.edit), disabled ? /*#__PURE__*/React.createElement(EditOff, {
|
318
313
|
size: 16
|
319
314
|
}) : /*#__PURE__*/React.createElement(Edit, {
|