@carbon/ibm-products 2.6.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +6368 -5849
- 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 +24 -23
- 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 +1428 -278
- 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 +1902 -1767
- 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/AddSelectRow.js +2 -1
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +6 -7
- package/es/components/ButtonMenu/ButtonMenu.js +4 -0
- package/es/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +21 -28
- package/es/components/ComboButton/ComboButton.js +5 -0
- package/es/components/CreateTearsheet/CreateTearsheet.js +30 -14
- package/es/components/CreateTearsheet/CreateTearsheetStep.js +10 -4
- package/es/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +3 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +1 -1
- package/es/components/Datagrid/Datagrid/Datagrid.js +12 -7
- package/es/components/Datagrid/Datagrid/DatagridContent.js +18 -14
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +128 -10
- package/es/components/Datagrid/Datagrid/DatagridToolbar.js +8 -14
- package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +1 -23
- package/es/components/Datagrid/Datagrid/addons/stateReducer.js +111 -0
- package/es/components/Datagrid/Datagrid.docs-page.js +6 -0
- package/es/components/Datagrid/useDatagrid.js +5 -2
- package/es/components/Datagrid/utils/DatagridActions.js +9 -10
- package/es/components/Datagrid/utils/getColTitle.js +25 -0
- package/es/components/NotificationsPanel/NotificationsPanel.js +8 -10
- package/es/components/OptionsTile/OptionsTile.js +2 -4
- package/es/components/PageHeader/PageHeaderUtils.js +10 -3
- package/es/components/TooltipTrigger/TooltipTrigger.js +62 -0
- package/es/components/TooltipTrigger/index.js +8 -0
- package/es/components/TooltipTrigger/useExample.js +49 -0
- package/es/components/UserProfileImage/UserProfileImage.js +7 -6
- package/es/global/js/hooks/useCreateComponentStepChange.js +98 -49
- package/es/global/js/hooks/useResizeObserver.js +19 -3
- package/es/global/js/hooks/useRetrieveStepData.js +1 -1
- package/es/global/js/utils/StoryDocsPage.js +0 -1
- package/es/global/js/utils/test-helper.js +97 -43
- package/es/settings.js +8 -2
- package/lib/components/AddSelect/AddSelectRow.js +2 -1
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +5 -6
- package/lib/components/ButtonMenu/ButtonMenu.js +5 -1
- package/lib/components/ButtonSetWithOverflow/ButtonSetWithOverflow.js +20 -27
- package/lib/components/ComboButton/ComboButton.js +5 -0
- package/lib/components/CreateTearsheet/CreateTearsheet.js +30 -14
- package/lib/components/CreateTearsheet/CreateTearsheetStep.js +10 -4
- package/lib/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +3 -0
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +1 -1
- package/lib/components/Datagrid/Datagrid/Datagrid.js +12 -7
- package/lib/components/Datagrid/Datagrid/DatagridContent.js +17 -13
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +131 -10
- package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +7 -13
- package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +4 -26
- package/lib/components/Datagrid/Datagrid/addons/stateReducer.js +122 -0
- package/lib/components/Datagrid/Datagrid.docs-page.js +6 -0
- package/lib/components/Datagrid/useDatagrid.js +5 -2
- package/lib/components/Datagrid/utils/DatagridActions.js +8 -9
- package/lib/components/Datagrid/utils/getColTitle.js +32 -0
- package/lib/components/NotificationsPanel/NotificationsPanel.js +8 -10
- package/lib/components/OptionsTile/OptionsTile.js +2 -4
- package/lib/components/PageHeader/PageHeaderUtils.js +10 -3
- package/lib/components/TooltipTrigger/TooltipTrigger.js +67 -0
- package/lib/components/TooltipTrigger/index.js +12 -0
- package/lib/components/TooltipTrigger/useExample.js +58 -0
- package/lib/components/UserProfileImage/UserProfileImage.js +6 -5
- package/lib/global/js/hooks/useCreateComponentStepChange.js +98 -49
- package/lib/global/js/hooks/useResizeObserver.js +19 -3
- package/lib/global/js/hooks/useRetrieveStepData.js +1 -1
- package/lib/global/js/utils/StoryDocsPage.js +0 -1
- package/lib/global/js/utils/test-helper.js +99 -44
- package/lib/settings.js +8 -2
- package/package.json +14 -14
- package/scss/components/APIKeyModal/_storybook-styles.scss +1 -1
- package/scss/components/AboutModal/_storybook-styles.scss +1 -1
- package/scss/components/ActionSet/_storybook-styles.scss +1 -1
- package/scss/components/CreateFullPage/_storybook-styles.scss +1 -1
- package/scss/components/CreateModal/_storybook-styles.scss +1 -1
- package/scss/components/CreateSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/CreateTearsheet/_storybook-styles.scss +1 -1
- package/scss/components/CreateTearsheetNarrow/_storybook-styles.scss +1 -1
- package/scss/components/Datagrid/_storybook-styles.scss +1 -1
- package/scss/components/Datagrid/styles/_datagrid.scss +65 -0
- package/scss/components/EditSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/EditTearsheet/_storybook-styles.scss +1 -1
- package/scss/components/EditTearsheetNarrow/_storybook-styles.scss +1 -1
- package/scss/components/EditUpdateCards/_storybook-styles.scss +1 -1
- package/scss/components/ExpressiveCard/_storybook-styles.scss +1 -1
- package/scss/components/NotificationsPanel/_storybook-styles.scss +1 -1
- package/scss/components/OptionsTile/_storybook-styles.scss +1 -1
- package/scss/components/PageHeader/_page-header.scss +8 -4
- package/scss/components/Tearsheet/_storybook-styles.scss +1 -1
- package/scss/components/TooltipTrigger/_index-with-carbon.scss +8 -0
- package/scss/components/TooltipTrigger/_index.scss +8 -0
- package/scss/components/TooltipTrigger/_storybook-styles.scss +6 -0
- package/scss/components/TooltipTrigger/_tooltip-trigger.scss +29 -0
- package/scss/components/WebTerminal/_storybook-styles.scss +1 -1
- package/scss/components/_index-with-carbon.scss +1 -0
- package/scss/components/_index.scss +1 -0
@@ -78,26 +78,34 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
78
78
|
_useState10 = _slicedToArray(_useState9, 2),
|
79
79
|
isDisabled = _useState10[0],
|
80
80
|
setIsDisabled = _useState10[1];
|
81
|
-
var _useState11 = useState(),
|
81
|
+
var _useState11 = useState(false),
|
82
82
|
_useState12 = _slicedToArray(_useState11, 2),
|
83
|
-
|
84
|
-
|
83
|
+
loadingPrevious = _useState12[0],
|
84
|
+
setLoadingPrevious = _useState12[1];
|
85
85
|
var _useState13 = useState(),
|
86
86
|
_useState14 = _slicedToArray(_useState13, 2),
|
87
|
-
|
88
|
-
|
89
|
-
var _useState15 = useState(
|
87
|
+
onPrevious = _useState14[0],
|
88
|
+
_setOnPrevious = _useState14[1];
|
89
|
+
var _useState15 = useState(),
|
90
90
|
_useState16 = _slicedToArray(_useState15, 2),
|
91
|
-
|
92
|
-
|
93
|
-
var _useState17 = useState(
|
91
|
+
onNext = _useState16[0],
|
92
|
+
_setOnNext = _useState16[1];
|
93
|
+
var _useState17 = useState(),
|
94
94
|
_useState18 = _slicedToArray(_useState17, 2),
|
95
|
-
|
96
|
-
|
97
|
-
var _useState19 = useState(
|
95
|
+
onMount = _useState18[0],
|
96
|
+
_setOnMount = _useState18[1];
|
97
|
+
var _useState19 = useState([]),
|
98
98
|
_useState20 = _slicedToArray(_useState19, 2),
|
99
|
-
|
100
|
-
|
99
|
+
stepData = _useState20[0],
|
100
|
+
setStepData = _useState20[1];
|
101
|
+
var _useState21 = useState(1),
|
102
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
103
|
+
firstIncludedStep = _useState22[0],
|
104
|
+
setFirstIncludedStep = _useState22[1];
|
105
|
+
var _useState23 = useState(null),
|
106
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
107
|
+
lastIncludedStep = _useState24[0],
|
108
|
+
setLastIncludedStep = _useState24[1];
|
101
109
|
var previousState = usePreviousValue({
|
102
110
|
currentStep: currentStep,
|
103
111
|
open: open
|
@@ -141,11 +149,14 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
141
149
|
firstIncludedStep: firstIncludedStep,
|
142
150
|
lastIncludedStep: lastIncludedStep,
|
143
151
|
stepData: stepData,
|
152
|
+
onPrevious: onPrevious,
|
144
153
|
onNext: onNext,
|
145
154
|
isSubmitDisabled: isDisabled,
|
146
155
|
setCurrentStep: setCurrentStep,
|
147
156
|
setIsSubmitting: setIsSubmitting,
|
148
157
|
setShouldViewAll: setShouldViewAll,
|
158
|
+
setLoadingPrevious: setLoadingPrevious,
|
159
|
+
loadingPrevious: loadingPrevious,
|
149
160
|
onClose: onClose,
|
150
161
|
onRequestSubmit: onRequestSubmit,
|
151
162
|
componentName: componentName,
|
@@ -202,6 +213,11 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
202
213
|
value: {
|
203
214
|
currentStep: currentStep,
|
204
215
|
setIsDisabled: setIsDisabled,
|
216
|
+
setOnPrevious: function setOnPrevious(fn) {
|
217
|
+
return _setOnPrevious(function () {
|
218
|
+
return fn;
|
219
|
+
});
|
220
|
+
},
|
205
221
|
setOnNext: function setOnNext(fn) {
|
206
222
|
return _setOnNext(function () {
|
207
223
|
return fn;
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
5
|
-
var _excluded = ["children", "className", "description", "disableSubmit", "fieldsetLegendText", "hasFieldset", "includeStep", "introStep", "onNext", "
|
5
|
+
var _excluded = ["children", "className", "description", "disableSubmit", "fieldsetLegendText", "hasFieldset", "includeStep", "introStep", "onMount", "onNext", "onPrevious", "secondaryLabel", "subtitle", "title"];
|
6
6
|
/**
|
7
7
|
* Copyright IBM Corp. 2021, 2023
|
8
8
|
*
|
@@ -38,8 +38,9 @@ export var CreateTearsheetStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
38
38
|
_ref$includeStep = _ref.includeStep,
|
39
39
|
includeStep = _ref$includeStep === void 0 ? defaults.includeStep : _ref$includeStep,
|
40
40
|
introStep = _ref.introStep,
|
41
|
-
onNext = _ref.onNext,
|
42
41
|
onMount = _ref.onMount,
|
42
|
+
onNext = _ref.onNext,
|
43
|
+
onPrevious = _ref.onPrevious,
|
43
44
|
secondaryLabel = _ref.secondaryLabel,
|
44
45
|
subtitle = _ref.subtitle,
|
45
46
|
title = _ref.title,
|
@@ -81,8 +82,9 @@ export var CreateTearsheetStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
81
82
|
if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
|
82
83
|
stepsContext.setIsDisabled(disableSubmit);
|
83
84
|
stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnNext(onNext); // needs to be updated here otherwise there could be stale state values from only initially setting onNext
|
85
|
+
stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnPrevious(onPrevious);
|
84
86
|
}
|
85
|
-
}, [stepsContext, stepNumber, disableSubmit, onNext]);
|
87
|
+
}, [stepsContext, stepNumber, disableSubmit, onNext, onPrevious]);
|
86
88
|
var renderDescription = function renderDescription() {
|
87
89
|
if (description) {
|
88
90
|
if (typeof description === 'string') {
|
@@ -167,11 +169,15 @@ CreateTearsheetStep.propTypes = {
|
|
167
169
|
*/
|
168
170
|
onMount: PropTypes.func,
|
169
171
|
/**
|
170
|
-
* Optional function to be called
|
172
|
+
* Optional function to be called when you move to the next step.
|
171
173
|
* For example, this can be used to validate input fields before proceeding to the next step.
|
172
174
|
* This function can _optionally_ return a promise that is either resolved or rejected and the CreateTearsheet will handle the submitting state of the next button.
|
173
175
|
*/
|
174
176
|
onNext: PropTypes.func,
|
177
|
+
/**
|
178
|
+
* Optional function to be called when you move to the previous step.
|
179
|
+
*/
|
180
|
+
onPrevious: PropTypes.func,
|
175
181
|
/**
|
176
182
|
* Sets the optional secondary label on the progress step component
|
177
183
|
*/
|
@@ -214,6 +214,9 @@ export var MultiStepTearsheet = function MultiStepTearsheet(_ref2) {
|
|
214
214
|
},
|
215
215
|
checked: shouldIncludeAdditionalStep
|
216
216
|
})))), /*#__PURE__*/React.createElement(CreateTearsheetStep, {
|
217
|
+
onPrevious: function onPrevious() {
|
218
|
+
console.log('custom onPrevious handler');
|
219
|
+
},
|
217
220
|
title: "Dynamic step",
|
218
221
|
subtitle: "Dynamic step subtitle",
|
219
222
|
description: "This is an example showing how to include a dynamic step into the CreateTearsheet",
|
@@ -545,7 +545,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
545
545
|
setClickAndHoldActive(false);
|
546
546
|
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
547
547
|
var activeCellValue = activeCellFullData ? activeCellFullData.row.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column].value : null;
|
548
|
-
setCellEditorValue(activeCellValue);
|
548
|
+
setCellEditorValue(activeCellValue || '');
|
549
549
|
cellEditorRulerRef.current.textContent = activeCellValue;
|
550
550
|
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
551
551
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
-
var _excluded = ["datagridState"];
|
3
|
+
var _excluded = ["datagridState", "title"];
|
4
4
|
/**
|
5
5
|
* Copyright IBM Corp. 2020, 2023
|
6
6
|
*
|
@@ -25,6 +25,7 @@ var componentName = 'Datagrid';
|
|
25
25
|
*/
|
26
26
|
export var Datagrid = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
27
27
|
var datagridState = _ref.datagridState,
|
28
|
+
title = _ref.title,
|
28
29
|
rest = _objectWithoutProperties(_ref, _excluded);
|
29
30
|
if (!datagridState) {
|
30
31
|
pconsole.warn('Datagrid was not passed datagridState which is required to render this component.');
|
@@ -38,6 +39,10 @@ export var Datagrid = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
38
39
|
className = datagridState.className,
|
39
40
|
filters = datagridState.state.filters;
|
40
41
|
var rows = DatagridPagination && datagridState.page || datagridState.rows;
|
42
|
+
var props = {
|
43
|
+
title: title,
|
44
|
+
datagridState: datagridState
|
45
|
+
};
|
41
46
|
return /*#__PURE__*/React.createElement(FilterProvider, {
|
42
47
|
filters: filters
|
43
48
|
}, /*#__PURE__*/React.createElement(InlineEditProvider, null, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
@@ -46,11 +51,7 @@ export var Datagrid = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
46
51
|
className: cx(className, blockClass, withVirtualScroll ? "".concat(blockClass, "__datagridWrap") : "".concat(blockClass, "__datagridWrap-simple"), !isFetching && rows.length === 0 ? "".concat(blockClass, "__empty-state") : '')
|
47
52
|
}, getDevtoolsProps(componentName)), (filterProps === null || filterProps === void 0 ? void 0 : filterProps.variation) === 'panel' ? /*#__PURE__*/React.createElement("div", {
|
48
53
|
className: "".concat(blockClass, "__datagridWithPanel ").concat(blockClass, "__displayFlex")
|
49
|
-
}, /*#__PURE__*/React.createElement(DatagridContent,
|
50
|
-
datagridState: datagridState
|
51
|
-
})) : /*#__PURE__*/React.createElement(DatagridContent, {
|
52
|
-
datagridState: datagridState
|
53
|
-
}))));
|
54
|
+
}, /*#__PURE__*/React.createElement(DatagridContent, props)) : /*#__PURE__*/React.createElement(DatagridContent, props))));
|
54
55
|
});
|
55
56
|
|
56
57
|
// Return a placeholder if not released and not enabled by feature flag
|
@@ -63,5 +64,9 @@ Datagrid.propTypes = {
|
|
63
64
|
/**
|
64
65
|
* The data grid state, much of it being supplied by the useDatagrid hook
|
65
66
|
*/
|
66
|
-
datagridState: PropTypes.object.isRequired
|
67
|
+
datagridState: PropTypes.object.isRequired,
|
68
|
+
/**
|
69
|
+
* Table title
|
70
|
+
*/
|
71
|
+
title: PropTypes.string
|
67
72
|
};
|
@@ -7,27 +7,28 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
9
|
|
10
|
+
import { FilterContext, FilterPanel } from './addons/Filtering';
|
10
11
|
import React, { useContext, useEffect, useRef } from 'react';
|
11
|
-
import
|
12
|
-
import
|
13
|
-
import {
|
14
|
-
import { px } from '@carbon/layout';
|
15
|
-
import DatagridHead from './DatagridHead';
|
12
|
+
import { Table, TableContainer } from '@carbon/react';
|
13
|
+
import { carbon, pkg } from '../../../settings';
|
14
|
+
import { CLEAR_FILTERS } from './addons/Filtering/constants';
|
16
15
|
import DatagridBody from './DatagridBody';
|
16
|
+
import DatagridHead from './DatagridHead';
|
17
17
|
import DatagridToolbar from './DatagridToolbar';
|
18
|
-
import {
|
19
|
-
import { carbon, pkg } from '../../../settings';
|
18
|
+
import { FilterSummary } from '../../FilterSummary';
|
20
19
|
import { InlineEditContext } from './addons/InlineEdit/InlineEditContext';
|
21
|
-
import
|
20
|
+
import PropTypes from 'prop-types';
|
21
|
+
import cx from 'classnames';
|
22
22
|
import { handleGridFocus } from './addons/InlineEdit/handleGridFocus';
|
23
|
+
import { handleGridKeyPress } from './addons/InlineEdit/handleGridKeyPress';
|
24
|
+
import { px } from '@carbon/layout';
|
23
25
|
import { useClickOutside } from '../../../global/js/hooks';
|
24
26
|
import { useMultipleKeyTracking } from '../../DataSpreadsheet/hooks';
|
25
|
-
import { FilterSummary } from '../../FilterSummary';
|
26
|
-
import { CLEAR_FILTERS } from './addons/Filtering/constants';
|
27
27
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
28
28
|
export var DatagridContent = function DatagridContent(_ref) {
|
29
29
|
var _cx4;
|
30
|
-
var datagridState = _ref.datagridState
|
30
|
+
var datagridState = _ref.datagridState,
|
31
|
+
title = _ref.title;
|
31
32
|
var _useContext = useContext(InlineEditContext),
|
32
33
|
inlineEditState = _useContext.state,
|
33
34
|
dispatch = _useContext.dispatch;
|
@@ -95,7 +96,8 @@ export var DatagridContent = function DatagridContent(_ref) {
|
|
95
96
|
} : null,
|
96
97
|
onFocus: withInlineEdit ? function () {
|
97
98
|
return handleGridFocus(inlineEditState, dispatch);
|
98
|
-
} : null
|
99
|
+
} : null,
|
100
|
+
title: title
|
99
101
|
}), !withVirtualScroll ? /*#__PURE__*/React.createElement(DatagridHead, datagridState) : null, /*#__PURE__*/React.createElement(DatagridBody, _extends({}, datagridState, {
|
100
102
|
rows: rows
|
101
103
|
})));
|
@@ -126,7 +128,8 @@ export var DatagridContent = function DatagridContent(_ref) {
|
|
126
128
|
filters: filterTags,
|
127
129
|
clearFilters: function clearFilters() {
|
128
130
|
return EventEmitter.dispatch(CLEAR_FILTERS);
|
129
|
-
}
|
131
|
+
},
|
132
|
+
renderLabel: filterProps.renderLabel
|
130
133
|
});
|
131
134
|
};
|
132
135
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableContainer, {
|
@@ -177,5 +180,6 @@ DatagridContent.propTypes = {
|
|
177
180
|
setAllFilters: PropTypes.func,
|
178
181
|
getFilterProps: PropTypes.func,
|
179
182
|
state: PropTypes.object
|
180
|
-
})
|
183
|
+
}),
|
184
|
+
title: PropTypes.string
|
181
185
|
};
|
@@ -1,29 +1,103 @@
|
|
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
|
/**
|
4
|
-
* Copyright IBM Corp. 2020,
|
5
|
+
* Copyright IBM Corp. 2020, 2023
|
5
6
|
*
|
6
7
|
* This source code is licensed under the Apache-2.0 license found in the
|
7
8
|
* LICENSE file in the root directory of this source tree.
|
8
9
|
*/
|
9
10
|
|
10
11
|
// @flow
|
11
|
-
import React from 'react';
|
12
|
+
import React, { useState, useEffect } from 'react';
|
12
13
|
import cx from 'classnames';
|
13
14
|
import { TableHeader, TableRow } from '@carbon/react';
|
15
|
+
import { px } from '@carbon/layout';
|
14
16
|
import { selectionColumnId } from '../common-column-ids';
|
15
17
|
import { pkg } from '../../../settings';
|
18
|
+
import getColTitle from '../utils/getColTitle';
|
19
|
+
import { handleColumnResizeEndEvent, handleColumnResizeStartEvent, handleColumnResizingEvent } from './addons/stateReducer';
|
16
20
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
21
|
+
var getAccessibilityProps = function getAccessibilityProps(header) {
|
22
|
+
var props = {};
|
23
|
+
var title = getColTitle(header);
|
24
|
+
if (title) {
|
25
|
+
props.title = title;
|
26
|
+
} else {
|
27
|
+
props['aria-hidden'] = true;
|
28
|
+
}
|
29
|
+
return props;
|
30
|
+
};
|
17
31
|
var HeaderRow = function HeaderRow(datagridState, headRef, headerGroup) {
|
32
|
+
// Used to measure the height of the table and uses that value
|
33
|
+
// to display a vertical line to indicate the column you are resizing
|
34
|
+
useEffect(function () {
|
35
|
+
var tableId = datagridState.tableId;
|
36
|
+
if (tableId) {
|
37
|
+
var gridElement = document.querySelector("#".concat(tableId));
|
38
|
+
var tableElement = gridElement.querySelector('table');
|
39
|
+
var headerRowElement = document.querySelector("#".concat(tableId, " .").concat(blockClass, "__head"));
|
40
|
+
var hasHorizontalScrollbar = tableElement.scrollWidth > tableElement.clientWidth;
|
41
|
+
var scrollBuffer = hasHorizontalScrollbar ? 18 : 2;
|
42
|
+
var tableToolbar = gridElement.querySelector(".".concat(blockClass, "__table-toolbar"));
|
43
|
+
var tableToolbarHeight = (tableToolbar === null || tableToolbar === void 0 ? void 0 : tableToolbar.offsetHeight) || 0;
|
44
|
+
var setCustomValues = function setCustomValues(_ref) {
|
45
|
+
var _ref$rowHeight = _ref.rowHeight,
|
46
|
+
rowHeight = _ref$rowHeight === void 0 ? 48 : _ref$rowHeight,
|
47
|
+
gridHeight = _ref.gridHeight;
|
48
|
+
headerRowElement.style.setProperty("--".concat(blockClass, "--row-height"), px(rowHeight));
|
49
|
+
headerRowElement.style.setProperty("--".concat(blockClass, "--grid-height"), px(gridHeight - scrollBuffer - tableToolbarHeight));
|
50
|
+
};
|
51
|
+
setCustomValues({
|
52
|
+
gridHeight: gridElement.offsetHeight,
|
53
|
+
rowHeight: headerRowElement.clientHeight
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}, [datagridState.rowSize, datagridState.tableId, datagridState]);
|
57
|
+
var _useState = useState(2),
|
58
|
+
_useState2 = _slicedToArray(_useState, 1),
|
59
|
+
incrementAmount = _useState2[0];
|
60
|
+
var getClientXPosition = function getClientXPosition(event) {
|
61
|
+
var isTouchEvent = false;
|
62
|
+
if (event.type === 'touchstart') {
|
63
|
+
// Do not respond to multiple touches (e.g. 2 or 3 fingers)
|
64
|
+
if (event.touches && event.touches.length > 1) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
isTouchEvent = true;
|
68
|
+
}
|
69
|
+
var clientX = isTouchEvent ? Math.round(event.touches[0].clientX) : event.clientX;
|
70
|
+
var closestHeader = event.target.closest('th');
|
71
|
+
var closestHeaderCoords = closestHeader.getBoundingClientRect();
|
72
|
+
var headerOffset = closestHeaderCoords.left;
|
73
|
+
var offsetValue = clientX - headerOffset;
|
74
|
+
return offsetValue;
|
75
|
+
};
|
76
|
+
useEffect(function () {
|
77
|
+
var isResizing = datagridState.state.isResizing;
|
78
|
+
if (isResizing) {
|
79
|
+
var onColResizeEnd = datagridState.onColResizeEnd;
|
80
|
+
document.addEventListener('mouseup', function () {
|
81
|
+
handleColumnResizeEndEvent(datagridState.dispatch, onColResizeEnd, isResizing);
|
82
|
+
document.activeElement.blur();
|
83
|
+
});
|
84
|
+
}
|
85
|
+
return function () {
|
86
|
+
document.removeEventListener('mouseup', function () {
|
87
|
+
return handleColumnResizeEndEvent(datagridState.dispatch);
|
88
|
+
});
|
89
|
+
};
|
90
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
91
|
+
}, [datagridState.state.isResizing]);
|
18
92
|
return /*#__PURE__*/React.createElement(TableRow, _extends({}, headerGroup.getHeaderGroupProps({
|
19
93
|
role: false
|
20
94
|
}), {
|
21
95
|
className: cx("".concat(blockClass, "__head"), headerGroup.getHeaderGroupProps().className),
|
22
96
|
ref: headRef
|
23
|
-
}), datagridState.headers.filter(function (
|
24
|
-
var isVisible =
|
97
|
+
}), datagridState.headers.filter(function (_ref2) {
|
98
|
+
var isVisible = _ref2.isVisible;
|
25
99
|
return isVisible;
|
26
|
-
}).map(function (header) {
|
100
|
+
}).map(function (header, index) {
|
27
101
|
var _cx;
|
28
102
|
if (header.id === selectionColumnId) {
|
29
103
|
// render directly without the wrapper TableHeader
|
@@ -31,13 +105,57 @@ var HeaderRow = function HeaderRow(datagridState, headRef, headerGroup) {
|
|
31
105
|
key: header.id
|
32
106
|
});
|
33
107
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
108
|
+
var _ref3 = header || 50,
|
109
|
+
minWidth = _ref3.minWidth;
|
110
|
+
var visibleColumns = datagridState.visibleColumns,
|
111
|
+
state = datagridState.state,
|
112
|
+
dispatch = datagridState.dispatch,
|
113
|
+
onColResizeEnd = datagridState.onColResizeEnd;
|
114
|
+
var columnResizing = state.columnResizing,
|
115
|
+
isResizing = state.isResizing;
|
116
|
+
var columnWidths = columnResizing.columnWidths;
|
117
|
+
var originalCol = visibleColumns[index];
|
118
|
+
return /*#__PURE__*/React.createElement(TableHeader, _extends({}, header.getHeaderProps(), {
|
37
119
|
className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__resizableColumn"), header.getResizerProps), _defineProperty(_cx, "".concat(blockClass, "__isResizing"), header.isResizing), _defineProperty(_cx, "".concat(blockClass, "__sortableColumn"), datagridState.isTableSortable), _defineProperty(_cx, "".concat(blockClass, "__isSorted"), header.isSorted), _cx), header.getHeaderProps().className),
|
38
120
|
key: header.id
|
39
|
-
}), header.render('Header'), header.getResizerProps && /*#__PURE__*/React.createElement("
|
40
|
-
|
121
|
+
}, getAccessibilityProps(header)), header.render('Header'), header.getResizerProps && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", _extends({}, header.getResizerProps(), {
|
122
|
+
onMouseMove: function onMouseMove(event) {
|
123
|
+
if (isResizing) {
|
124
|
+
var newWidth = getClientXPosition(event);
|
125
|
+
// Sets a min width for resizing so at least one character from the column header is visible
|
126
|
+
if (newWidth >= 50) {
|
127
|
+
handleColumnResizingEvent(dispatch, header, newWidth);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
},
|
131
|
+
onMouseDown: function onMouseDown() {
|
132
|
+
return handleColumnResizeStartEvent(dispatch, header.id);
|
133
|
+
},
|
134
|
+
onKeyDown: function onKeyDown(event) {
|
135
|
+
var key = event.key;
|
136
|
+
if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
137
|
+
var currentColumnWidth = columnWidths[header.id] || (datagridState.isTableSortable && originalCol.width < 90 ? 90 : originalCol.width);
|
138
|
+
if (key === 'ArrowLeft') {
|
139
|
+
if (currentColumnWidth - incrementAmount > Math.max(minWidth, 50)) {
|
140
|
+
var newWidth = currentColumnWidth - incrementAmount;
|
141
|
+
handleColumnResizingEvent(dispatch, header, newWidth, true);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
if (key === 'ArrowRight') {
|
145
|
+
var _newWidth = currentColumnWidth + incrementAmount;
|
146
|
+
handleColumnResizingEvent(dispatch, header, _newWidth, true);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
},
|
150
|
+
onKeyUp: function onKeyUp() {
|
151
|
+
return handleColumnResizeEndEvent(dispatch, onColResizeEnd, header.id);
|
152
|
+
},
|
153
|
+
className: cx("".concat(blockClass, "__col-resizer-range")),
|
154
|
+
type: "range",
|
155
|
+
defaultValue: originalCol.width,
|
156
|
+
"aria-label": "Resize column"
|
157
|
+
})), /*#__PURE__*/React.createElement("span", {
|
158
|
+
className: "".concat(blockClass, "__col-resize-indicator")
|
41
159
|
})));
|
42
160
|
}));
|
43
161
|
};
|
@@ -8,10 +8,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
import React, { useEffect, useRef, useState } from 'react';
|
11
|
-
import {
|
12
|
-
import { TableToolbar, TableBatchActions, TableBatchAction } from '@carbon/react';
|
11
|
+
import { TableToolbar, TableBatchActions, TableBatchAction, MenuButton, MenuItem } from '@carbon/react';
|
13
12
|
import { useResizeObserver } from '../../../global/js/hooks/useResizeObserver';
|
14
|
-
import { ButtonMenu, ButtonMenuItem } from '../../ButtonMenu';
|
15
13
|
import { pkg, carbon } from '../../../settings';
|
16
14
|
import cx from 'classnames';
|
17
15
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
@@ -76,19 +74,15 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
|
|
76
74
|
if ((toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.length) <= 3 && !displayAllInMenu) {
|
77
75
|
return null;
|
78
76
|
}
|
79
|
-
return /*#__PURE__*/React.createElement(
|
80
|
-
label:
|
81
|
-
|
82
|
-
className: cx("".concat(blockClass, "__button-menu"), _defineProperty({}, "".concat(blockClass, "__button-menu--icon-only"), width <= minWidthBeforeOverflowIcon)),
|
83
|
-
menuOptionsClass: "".concat(blockClass, "__button-menu-options"),
|
84
|
-
flipped: true,
|
85
|
-
menuAriaLabel: 'Batch actions'
|
77
|
+
return /*#__PURE__*/React.createElement(MenuButton, {
|
78
|
+
label: "More",
|
79
|
+
className: cx("".concat(blockClass, "__button-menu"), _defineProperty({}, "".concat(blockClass, "__button-menu--icon-only"), width <= minWidthBeforeOverflowIcon))
|
86
80
|
}, toolbarBatchActions && toolbarBatchActions.map(function (batchAction, index) {
|
87
81
|
if (index < 2) {
|
88
82
|
if (displayAllInMenu) {
|
89
|
-
return /*#__PURE__*/React.createElement(
|
83
|
+
return /*#__PURE__*/React.createElement(MenuItem, {
|
90
84
|
key: "".concat(batchAction.label, "-").concat(index),
|
91
|
-
|
85
|
+
label: batchAction.label,
|
92
86
|
onClick: function onClick(event) {
|
93
87
|
batchAction.onClick(getSelectedRowData(), event);
|
94
88
|
if (batchAction.type === 'select_all') {
|
@@ -99,9 +93,9 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
|
|
99
93
|
}
|
100
94
|
return null;
|
101
95
|
}
|
102
|
-
return /*#__PURE__*/React.createElement(
|
96
|
+
return /*#__PURE__*/React.createElement(MenuItem, {
|
103
97
|
key: "".concat(batchAction.label, "-").concat(index),
|
104
|
-
|
98
|
+
label: batchAction.label,
|
105
99
|
onClick: function onClick(event) {
|
106
100
|
batchAction.onClick(getSelectedRowData(), event);
|
107
101
|
if (batchAction.type === 'select_all') {
|
@@ -11,6 +11,7 @@ import { Checkbox } from '@carbon/react';
|
|
11
11
|
import { isColumnVisible } from './common';
|
12
12
|
import DraggableElement from '../../DraggableElement';
|
13
13
|
import { pkg } from '../../../../../settings';
|
14
|
+
import getColTitle from '../../../utils/getColTitle';
|
14
15
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
15
16
|
export var DraggableItemsList = function DraggableItemsList(_ref) {
|
16
17
|
var columns = _ref.columns,
|
@@ -22,29 +23,6 @@ export var DraggableItemsList = function DraggableItemsList(_ref) {
|
|
22
23
|
setAriaRegionText = _ref.setAriaRegionText,
|
23
24
|
setColumnsObject = _ref.setColumnsObject,
|
24
25
|
setFocusIndex = _ref.setFocusIndex;
|
25
|
-
// This function recursively looks for the nested header element until we can find the key which contains the title.
|
26
|
-
// This can happen if multiple hooks are used together that manipulate the rendering of the column
|
27
|
-
// header, such as `useColumnCenterAlign` and `useSortableColumns`.
|
28
|
-
var getNestedTitle = function getNestedTitle(component) {
|
29
|
-
if (component && !component.key) {
|
30
|
-
return getNestedTitle(component.children);
|
31
|
-
}
|
32
|
-
if (component && component.key && typeof component.key === 'string') {
|
33
|
-
return component.key;
|
34
|
-
}
|
35
|
-
};
|
36
|
-
var getColTitle = function getColTitle(col) {
|
37
|
-
if (!col) {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
var checkTitle = function checkTitle() {
|
41
|
-
if (col.Header().props.children.props && col.Header().props.children.props.title) {
|
42
|
-
return col.Header().props.children.props.title;
|
43
|
-
}
|
44
|
-
return getNestedTitle(col.Header().props.children.props);
|
45
|
-
};
|
46
|
-
return typeof (col === null || col === void 0 ? void 0 : col.Header) === 'function' ? checkTitle() : col.Header.props.title;
|
47
|
-
};
|
48
26
|
return /*#__PURE__*/React.createElement(React.Fragment, null, columns
|
49
27
|
// hide the columns without Header, e.g the sticky actions, spacer
|
50
28
|
.filter(function (colDef) {
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
|
+
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; }
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
5
|
+
/**
|
6
|
+
* Copyright IBM Corp. 2023, 2023
|
7
|
+
*
|
8
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
10
|
+
*/
|
11
|
+
|
12
|
+
var COLUMN_RESIZE_START = 'columnStartResizing';
|
13
|
+
var COLUMN_RESIZING = 'columnResizing';
|
14
|
+
var COLUMN_RESIZE_END = 'columnDoneResizing';
|
15
|
+
var INIT = 'init';
|
16
|
+
export var handleColumnResizeStartEvent = function handleColumnResizeStartEvent(dispatch, headerId) {
|
17
|
+
dispatch({
|
18
|
+
type: COLUMN_RESIZE_START,
|
19
|
+
payload: {
|
20
|
+
headerId: headerId
|
21
|
+
}
|
22
|
+
});
|
23
|
+
};
|
24
|
+
export var handleColumnResizeEndEvent = function handleColumnResizeEndEvent(dispatch, onColResizeEnd, headerId) {
|
25
|
+
dispatch({
|
26
|
+
type: COLUMN_RESIZE_END,
|
27
|
+
payload: {
|
28
|
+
onColResizeEnd: onColResizeEnd,
|
29
|
+
headerId: headerId
|
30
|
+
}
|
31
|
+
});
|
32
|
+
};
|
33
|
+
export var handleColumnResizingEvent = function handleColumnResizingEvent(dispatch, header, newWidth, isKeyEvent) {
|
34
|
+
if (isKeyEvent) {
|
35
|
+
dispatch({
|
36
|
+
type: COLUMN_RESIZE_START,
|
37
|
+
payload: {
|
38
|
+
newWidth: newWidth,
|
39
|
+
headerId: header.id,
|
40
|
+
defaultWidth: header.originalWidth
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
dispatch({
|
45
|
+
type: COLUMN_RESIZING,
|
46
|
+
payload: {
|
47
|
+
newWidth: newWidth,
|
48
|
+
headerId: header.id,
|
49
|
+
defaultWidth: header.originalWidth
|
50
|
+
}
|
51
|
+
});
|
52
|
+
};
|
53
|
+
export var stateReducer = function stateReducer(newState, action) {
|
54
|
+
switch (action.type) {
|
55
|
+
case INIT:
|
56
|
+
{
|
57
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
58
|
+
isResizing: false
|
59
|
+
});
|
60
|
+
}
|
61
|
+
case COLUMN_RESIZE_START:
|
62
|
+
{
|
63
|
+
var headerId = action.payload.headerId;
|
64
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
65
|
+
isResizing: headerId
|
66
|
+
});
|
67
|
+
}
|
68
|
+
case COLUMN_RESIZING:
|
69
|
+
{
|
70
|
+
var _ref = action.payload || {},
|
71
|
+
_headerId = _ref.headerId,
|
72
|
+
newWidth = _ref.newWidth,
|
73
|
+
defaultWidth = _ref.defaultWidth;
|
74
|
+
var newColumnWidth = {};
|
75
|
+
if (typeof _headerId === 'undefined') {
|
76
|
+
return _objectSpread({}, newState);
|
77
|
+
}
|
78
|
+
newColumnWidth[_headerId] = newWidth;
|
79
|
+
var cleanedWidths = Object.fromEntries(Object.entries(newState.columnResizing.columnWidths).filter(function (_ref2) {
|
80
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
81
|
+
_ = _ref3[0],
|
82
|
+
value = _ref3[1];
|
83
|
+
return !isNaN(value);
|
84
|
+
}));
|
85
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
86
|
+
isResizing: _headerId,
|
87
|
+
columnResizing: _objectSpread(_objectSpread({}, newState.columnResizing), {}, {
|
88
|
+
columnWidth: defaultWidth,
|
89
|
+
columnWidths: _objectSpread(_objectSpread({}, cleanedWidths), newColumnWidth),
|
90
|
+
headerIdWidths: [_headerId, newWidth]
|
91
|
+
})
|
92
|
+
});
|
93
|
+
}
|
94
|
+
case COLUMN_RESIZE_END:
|
95
|
+
{
|
96
|
+
var _action$payload = action.payload,
|
97
|
+
onColResizeEnd = _action$payload.onColResizeEnd,
|
98
|
+
_headerId2 = _action$payload.headerId;
|
99
|
+
var currentColumn = {};
|
100
|
+
currentColumn[_headerId2] = newState.columnResizing.columnWidths[_headerId2];
|
101
|
+
var allChangedColumns = newState.columnResizing.columnWidths;
|
102
|
+
var isResizing = newState.isResizing;
|
103
|
+
if (isResizing) {
|
104
|
+
onColResizeEnd === null || onColResizeEnd === void 0 ? void 0 : onColResizeEnd(currentColumn, allChangedColumns);
|
105
|
+
}
|
106
|
+
return _objectSpread(_objectSpread({}, newState), {}, {
|
107
|
+
isResizing: false
|
108
|
+
});
|
109
|
+
}
|
110
|
+
}
|
111
|
+
};
|
@@ -41,6 +41,12 @@ export var DocsPage = function DocsPage() {
|
|
41
41
|
language: 'jsx',
|
42
42
|
code: "\n const columns = [\n {\n Header: 'First Name',\n accessor: 'firstName',\n },\n {\n Header: 'Last Name',\n accessor: 'lastName',\n Cell: ({ cell: { value } }) => (\n <span className=\"custom-cell-wrapper\">{value}</span>\n ),\n },\n];\n "
|
43
43
|
}
|
44
|
+
}, {
|
45
|
+
description: "There is also an optional resize callback when resizing columns, allowing you to save the widths of columns that have been resized. The resize callback returns the column that was just resized and it's width, in addition to all of the columns that have been resized and their widths.",
|
46
|
+
source: {
|
47
|
+
language: 'jsx',
|
48
|
+
code: "\nuseDatagrid({\n columns,\n data,\n onColResizeEnd: (currentColumn, allColumns) =>\n console.log(currentColumn, allColumns),\n});\n "
|
49
|
+
}
|
44
50
|
}, {
|
45
51
|
title: 'Rendering the table toolbar',
|
46
52
|
image: /*#__PURE__*/React.createElement("img", {
|