@carbon/ibm-products 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/README.md +38 -0
  2. package/css/index-full-carbon.css +235 -110
  3. package/css/index-full-carbon.css.map +1 -1
  4. package/css/index-full-carbon.min.css +2 -2
  5. package/css/index-full-carbon.min.css.map +1 -1
  6. package/css/index-without-carbon-released-only.css +24 -24
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon.css +59 -54
  9. package/css/index-without-carbon.css.map +1 -1
  10. package/css/index-without-carbon.min.css +2 -2
  11. package/css/index-without-carbon.min.css.map +1 -1
  12. package/css/index.css +122 -38
  13. package/css/index.css.map +1 -1
  14. package/css/index.min.css +3 -3
  15. package/css/index.min.css.map +1 -1
  16. package/es/components/APIKeyModal/APIKeyModal.js +25 -21
  17. package/es/components/ActionBar/ActionBar.js +5 -5
  18. package/es/components/CreateFullPage/CreateFullPage.js +4 -2
  19. package/es/components/CreateModal/CreateModal.docs-page.js +1 -1
  20. package/es/components/CreateModal/CreateModal.js +2 -1
  21. package/es/components/CreateSidePanel/CreateSidePanel.docs-page.js +1 -1
  22. package/es/components/CreateSidePanel/CreateSidePanel.js +6 -2
  23. package/es/components/CreateTearsheet/CreateTearsheet.js +3 -1
  24. package/es/components/CreateTearsheetNarrow/CreateTearsheetNarrow.js +6 -2
  25. package/es/components/Datagrid/Datagrid/Datagrid.js +5 -1
  26. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +15 -21
  27. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +6 -20
  28. package/es/components/Datagrid/Datagrid.docs-page.js +123 -0
  29. package/es/components/Datagrid/Extensions/ColumnAlignment/ColumnAlignment.docs-page.js +13 -0
  30. package/es/components/Datagrid/Extensions/ColumnCustomization/ColumnCustomization.docs-page.js +13 -0
  31. package/es/components/Datagrid/Extensions/EditableCell/EditableCell.docs-page.js +47 -0
  32. package/es/components/Datagrid/Extensions/ExpandableRow/ExpandableRow.docs-page.js +13 -0
  33. package/es/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +57 -0
  34. package/es/components/Datagrid/Extensions/RowActionButtons/RowActionButtons.docs-page.js +13 -0
  35. package/es/components/Datagrid/utils/DatagridActions.js +1 -1
  36. package/es/components/Datagrid/utils/getArgTypes.js +4 -0
  37. package/es/components/EditSidePanel/EditSidePanel.js +6 -2
  38. package/es/components/FilterSummary/FilterSummary.js +7 -3
  39. package/es/components/OptionsTile/OptionsTile.js +8 -1
  40. package/es/components/Tearsheet/TearsheetShell.js +2 -1
  41. package/es/global/js/hooks/useResizeObserver.js +1 -1
  42. package/es/global/js/utils/StoryDocsPage.js +6 -2
  43. package/lib/components/APIKeyModal/APIKeyModal.js +25 -21
  44. package/lib/components/ActionBar/ActionBar.js +5 -5
  45. package/lib/components/CreateFullPage/CreateFullPage.js +4 -2
  46. package/lib/components/CreateModal/CreateModal.docs-page.js +1 -1
  47. package/lib/components/CreateModal/CreateModal.js +2 -1
  48. package/lib/components/CreateSidePanel/CreateSidePanel.docs-page.js +1 -1
  49. package/lib/components/CreateSidePanel/CreateSidePanel.js +6 -2
  50. package/lib/components/CreateTearsheet/CreateTearsheet.js +3 -1
  51. package/lib/components/CreateTearsheetNarrow/CreateTearsheetNarrow.js +6 -2
  52. package/lib/components/Datagrid/Datagrid/Datagrid.js +5 -1
  53. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +14 -20
  54. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +6 -23
  55. package/lib/components/Datagrid/Datagrid.docs-page.js +134 -0
  56. package/lib/components/Datagrid/Extensions/ColumnAlignment/ColumnAlignment.docs-page.js +21 -0
  57. package/lib/components/Datagrid/Extensions/ColumnCustomization/ColumnCustomization.docs-page.js +21 -0
  58. package/lib/components/Datagrid/Extensions/EditableCell/EditableCell.docs-page.js +55 -0
  59. package/lib/components/Datagrid/Extensions/ExpandableRow/ExpandableRow.docs-page.js +21 -0
  60. package/lib/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +65 -0
  61. package/lib/components/Datagrid/Extensions/RowActionButtons/RowActionButtons.docs-page.js +21 -0
  62. package/lib/components/Datagrid/utils/DatagridActions.js +1 -1
  63. package/lib/components/Datagrid/utils/getArgTypes.js +4 -0
  64. package/lib/components/EditSidePanel/EditSidePanel.js +6 -2
  65. package/lib/components/FilterSummary/FilterSummary.js +7 -3
  66. package/lib/components/OptionsTile/OptionsTile.js +8 -1
  67. package/lib/components/Tearsheet/TearsheetShell.js +2 -1
  68. package/lib/global/js/hooks/useResizeObserver.js +1 -1
  69. package/lib/global/js/utils/StoryDocsPage.js +6 -2
  70. package/package.json +16 -16
  71. package/scss/components/Datagrid/_datagrid.scss +17 -10
  72. package/scss/components/FilterSummary/_storybook-styles.scss +2 -0
@@ -52,7 +52,7 @@ export var useResizeObserver = function useResizeObserver(ref, callback) {
52
52
  observer = null;
53
53
  };
54
54
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
- }, [ref]);
55
+ }, [ref.current]);
56
56
  return {
57
57
  width: width,
58
58
  height: height
@@ -25,7 +25,7 @@ export var CustomBlocks = function CustomBlocks(_ref) {
25
25
  key: "block-index--".concat(index)
26
26
  }, block.title && /*#__PURE__*/React.createElement("h3", {
27
27
  id: paramCase(block.title)
28
- }, block.title), block.subTitle && /*#__PURE__*/React.createElement("h4", null, block.subTitle), block.description && typeof block.description === 'string' ? /*#__PURE__*/React.createElement(Description, null, block.description) : block.description, block.story && /*#__PURE__*/React.createElement(Canvas, {
28
+ }, block.title), block.subTitle && /*#__PURE__*/React.createElement("h4", null, block.subTitle), block.image, block.description && typeof block.description === 'string' ? /*#__PURE__*/React.createElement(Description, null, block.description) : block.description, block.story && /*#__PURE__*/React.createElement(Canvas, {
29
29
  of: block.story
30
30
  }), block.source && /*#__PURE__*/React.createElement(Source, source));
31
31
  });
@@ -194,6 +194,10 @@ StoryDocsPage.propTypes = {
194
194
  * Optional description, strings treated as markdown.
195
195
  */
196
196
  description: PropTypes.node,
197
+ /**
198
+ * Optional block image
199
+ */
200
+ image: PropTypes.node,
197
201
  /**
198
202
  * Story imported from story file
199
203
  */
@@ -203,7 +207,7 @@ StoryDocsPage.propTypes = {
203
207
  * default language `jsx`
204
208
  */
205
209
  source: PropTypes.shape({
206
- language: PropTypes.oneOf('javascript', 'css', 'jsx'),
210
+ language: PropTypes.oneOf('javascript', 'css', 'jsx', 'json'),
207
211
  code: PropTypes.string
208
212
  })
209
213
  })),
@@ -85,18 +85,22 @@ var APIKeyModal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
85
85
  previousStepButtonText = _ref.previousStepButtonText,
86
86
  showAPIKeyLabel = _ref.showAPIKeyLabel,
87
87
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
88
- var _useState = (0, _react.useState)(false),
88
+ var _useState = (0, _react.useState)(null),
89
89
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
90
- copyError = _useState2[0],
91
- setCopyError = _useState2[1];
92
- var _useState3 = (0, _react.useState)(apiKeyName),
90
+ title = _useState2[0],
91
+ setTitle = _useState2[1];
92
+ var _useState3 = (0, _react.useState)(false),
93
93
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
94
- name = _useState4[0],
95
- setName = _useState4[1];
96
- var _useState5 = (0, _react.useState)(0),
94
+ copyError = _useState4[0],
95
+ setCopyError = _useState4[1];
96
+ var _useState5 = (0, _react.useState)(apiKeyName),
97
97
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
98
- currentStep = _useState6[0],
99
- setCurrentStep = _useState6[1];
98
+ name = _useState6[0],
99
+ setName = _useState6[1];
100
+ var _useState7 = (0, _react.useState)(0),
101
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
102
+ currentStep = _useState8[0],
103
+ setCurrentStep = _useState8[1];
100
104
  var copyRef = (0, _react.useRef)();
101
105
  var apiKeyInputId = (0, _react.useRef)((0, _uuidv.default)());
102
106
  var nameInputId = (0, _react.useRef)((0, _uuidv.default)());
@@ -149,18 +153,17 @@ var APIKeyModal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
149
153
  }
150
154
  return closeButtonText;
151
155
  };
152
- var getTitle = function getTitle() {
156
+ (0, _react.useEffect)(function () {
153
157
  if (editing && editSuccess) {
154
- return editSuccessTitle;
155
- }
156
- if (apiKeyLoaded) {
157
- return generateSuccessTitle;
158
- }
159
- if (hasSteps) {
160
- return customSteps[currentStep].title;
158
+ setTitle(editSuccessTitle);
159
+ } else if (apiKeyLoaded) {
160
+ setTitle(generateSuccessTitle);
161
+ } else if (hasSteps) {
162
+ setTitle(customSteps[currentStep].title);
163
+ } else {
164
+ setTitle(generateTitle);
161
165
  }
162
- return generateTitle;
163
- };
166
+ }, [apiKeyLoaded, editing, editSuccess, editSuccessTitle, hasSteps, generateSuccessTitle, generateTitle, currentStep, customSteps]);
164
167
  var setNameHandler = function setNameHandler(evt) {
165
168
  setName(evt.target.value);
166
169
  };
@@ -243,7 +246,7 @@ var APIKeyModal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
243
246
  preventCloseOnClickOutside: true
244
247
  }), /*#__PURE__*/_react.default.createElement(_react2.ModalHeader, {
245
248
  className: "".concat(blockClass, "__header"),
246
- title: getTitle(),
249
+ title: title,
247
250
  label: modalLabel
248
251
  }), /*#__PURE__*/_react.default.createElement(_react2.ModalBody, {
249
252
  className: "".concat(blockClass, "__body-container")
@@ -261,7 +264,8 @@ var APIKeyModal = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
261
264
  labelText: apiKeyLabel,
262
265
  id: apiKeyInputId.current
263
266
  }), (editing || !apiKeyLoaded && nameRequired) && /*#__PURE__*/_react.default.createElement(_react2.Form, {
264
- onSubmit: submitHandler
267
+ onSubmit: submitHandler,
268
+ "aria-label": title
265
269
  }, /*#__PURE__*/_react.default.createElement(_react2.TextInput, {
266
270
  helperText: nameHelperText,
267
271
  placeholder: namePlaceholder,
@@ -79,13 +79,12 @@ var ActionBar = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
79
79
  className: "".concat(blockClass, "__hidden-sizing-items"),
80
80
  "aria-hidden": true,
81
81
  ref: sizingRef
82
- }, /*#__PURE__*/_react.default.createElement("span", {
83
- "aria-hidden": false
84
- }, /*#__PURE__*/_react.default.createElement(_ActionBarOverflowItems.ActionBarOverflowItems, {
82
+ }, /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement(_ActionBarOverflowItems.ActionBarOverflowItems, {
85
83
  className: "".concat(blockClass, "__hidden-sizing-item"),
86
84
  overflowAriaLabel: "hidden sizing overflow items",
87
85
  overflowItems: [],
88
- key: "hidden-overflow-menu"
86
+ key: "hidden-overflow-menu",
87
+ tabIndex: -1
89
88
  }), actions.map(function (_ref2) {
90
89
  var key = _ref2.key,
91
90
  id = _ref2.id,
@@ -94,7 +93,8 @@ var ActionBar = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
94
93
  // ensure id is not duplicated
95
94
  "data-original-id": id,
96
95
  key: "hidden-item-".concat(key),
97
- className: "".concat(blockClass, "__hidden-sizing-item")
96
+ className: "".concat(blockClass, "__hidden-sizing-item"),
97
+ tabIndex: -1
98
98
  }));
99
99
  }))));
100
100
  }, [actions]);
@@ -19,7 +19,7 @@ var _CreateInfluencer = require("../CreateInfluencer");
19
19
  var _ActionSet = require("../ActionSet");
20
20
  var _hooks = require("../../global/js/hooks");
21
21
  var _lastIndexInArray = require("../../global/js/utils/lastIndexInArray");
22
- var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "firstFocusElement", "submitButtonText"];
22
+ var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "firstFocusElement", "submitButtonText", "title"];
23
23
  /**
24
24
  * Copyright IBM Corp. 2021, 2023
25
25
  *
@@ -71,6 +71,7 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
71
71
  onRequestSubmit = _ref.onRequestSubmit,
72
72
  firstFocusElement = _ref.firstFocusElement,
73
73
  submitButtonText = _ref.submitButtonText,
74
+ title = _ref.title,
74
75
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
75
76
  var _useState = (0, _react.useState)([]),
76
77
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -181,7 +182,8 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
181
182
  }, /*#__PURE__*/_react.default.createElement("div", {
182
183
  className: "".concat(blockClass, "__content")
183
184
  }, /*#__PURE__*/_react.default.createElement(_react2.Form, {
184
- className: "".concat(blockClass, "__form")
185
+ className: "".concat(blockClass, "__form"),
186
+ "aria-label": title
185
187
  }, /*#__PURE__*/_react.default.createElement(StepsContext.Provider, {
186
188
  value: {
187
189
  currentStep: currentStep,
@@ -18,7 +18,7 @@ var DocsPage = function DocsPage() {
18
18
  story: stories.Default
19
19
  }, {
20
20
  title: 'Form validation',
21
- description: "All forms, including that within the `CreateModal` should follow C&CS guidelines\nfor form validation.\n\nThis includes the following:\n\n- The `Submit` button in the modal should be disabled, until all required inputs\n are filled in and valid\n- All required inputs should _only_ throw an invalid error _after_ the element\n loses focus\n- All optional form fields should have an `(optional)` text at the end of the\n input `labelText`. Optional should always be in parentheses\n\nYou can find more information on how to validate your form fields in\n[Carbon's Form usage page](https://www.carbondesignsystem.com/components/form/usage)."
21
+ description: "All forms, including that within the `CreateModal` should follow @carbon/ibm-products guidelines\nfor form validation.\n\nThis includes the following:\n\n- The `Submit` button in the modal should be disabled, until all required inputs\n are filled in and valid\n- All required inputs should _only_ throw an invalid error _after_ the element\n loses focus\n- All optional form fields should have an `(optional)` text at the end of the\n input `labelText`. Optional should always be in parentheses\n\nYou can find more information on how to validate your form fields in\n[Carbon's Form usage page](https://www.carbondesignsystem.com/components/form/usage)."
22
22
  }, {
23
23
  title: 'Overriding Carbon theme',
24
24
  description: "The design recommendation is to use a dark theme for the CreateModal if the\napplication is currently using a light theme, and vice versa. The theme applied\nto the CreateModal can easily be customized as follows:\n\nIn SCSS:",
@@ -78,7 +78,8 @@ var CreateModal = /*#__PURE__*/_react.default.forwardRef(function (_ref2, ref) {
78
78
  }, description && /*#__PURE__*/_react.default.createElement("p", {
79
79
  className: "".concat(blockClass, "__description")
80
80
  }, description), /*#__PURE__*/_react.default.createElement(_react2.Form, {
81
- className: "".concat(blockClass, "__form")
81
+ className: "".concat(blockClass, "__form"),
82
+ "aria-label": title
82
83
  }, children)), /*#__PURE__*/_react.default.createElement(_react2.ModalFooter, null, /*#__PURE__*/_react.default.createElement(_react2.Button, {
83
84
  type: "button",
84
85
  kind: "secondary",
@@ -21,7 +21,7 @@ var DocsPage = function DocsPage() {
21
21
  story: stories.Default
22
22
  }, {
23
23
  title: 'Form validation',
24
- description: "All forms, including that within the `CreateSidePanel` should follow C&CS\nguidelines for form validation.\n\nThis includes the following:\n\n- The `Submit` button in the side panel should be disabled, until all required\n inputs are filled in and valid\n- All required inputs should _only_ throw an invalid error _after_ the element\n loses focus\n- All optional form fields should have an `(optional)` text at the end of the\n input `labelText`. Optional should always be in parentheses\n\nYou can find more information on how to validate your form fields in\n[Carbon's Form usage page](https://www.carbondesignsystem.com/components/form/usage)."
24
+ description: "All forms, including that within the `CreateSidePanel` should follow @carbon/ibm-products\nguidelines for form validation.\n\nThis includes the following:\n\n- The `Submit` button in the side panel should be disabled, until all required\n inputs are filled in and valid\n- All required inputs should _only_ throw an invalid error _after_ the element\n loses focus\n- All optional form fields should have an `(optional)` text at the end of the\n input `labelText`. Optional should always be in parentheses\n\nYou can find more information on how to validate your form fields in\n[Carbon's Form usage page](https://www.carbondesignsystem.com/components/form/usage)."
25
25
  }]
26
26
  });
27
27
  };
@@ -15,6 +15,7 @@ var _settings = require("../../settings");
15
15
  var _devtools = require("../../global/js/utils/devtools");
16
16
  var _react2 = require("@carbon/react");
17
17
  var _SidePanel = require("../SidePanel");
18
+ var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
18
19
  var _excluded = ["className", "children", "disableSubmit", "formTitle", "formDescription", "onRequestClose", "onRequestSubmit", "open", "primaryButtonText", "secondaryButtonText", "selectorPageContent", "selectorPrimaryFocus", "subtitle", "title"];
19
20
  /**
20
21
  * Copyright IBM Corp. 2021, 2021
@@ -66,6 +67,7 @@ var CreateSidePanel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
66
67
  onClick: onRequestClose,
67
68
  kind: 'secondary'
68
69
  }];
70
+ var formTitleId = (0, _uuidv.default)();
69
71
  return selectorPageContent && /*#__PURE__*/_react.default.createElement(_SidePanel.SidePanel, (0, _extends2.default)({}, rest, _objectSpread({
70
72
  open: open,
71
73
  ref: ref,
@@ -82,11 +84,13 @@ var CreateSidePanel = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
82
84
  size: "md",
83
85
  actions: actions
84
86
  }), /*#__PURE__*/_react.default.createElement("h3", {
85
- className: "".concat(blockClass, "__form-title-text ").concat(blockClass, "__content-text")
87
+ className: "".concat(blockClass, "__form-title-text ").concat(blockClass, "__content-text"),
88
+ id: formTitleId
86
89
  }, formTitle), /*#__PURE__*/_react.default.createElement("p", {
87
90
  className: "".concat(blockClass, "__form-description-text ").concat(blockClass, "__content-text")
88
91
  }, formDescription), /*#__PURE__*/_react.default.createElement(_react2.Form, {
89
- className: "".concat(blockClass, "__form")
92
+ className: "".concat(blockClass, "__form"),
93
+ "aria-labelledby": formTitleId
90
94
  }, children));
91
95
  });
92
96
  exports.CreateSidePanel = CreateSidePanel;
@@ -207,7 +207,9 @@ var CreateTearsheet = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
207
207
  className: "".concat(blockClass, "__content"),
208
208
  onBlur: handleBlur,
209
209
  ref: contentRef
210
- }, /*#__PURE__*/_react.default.createElement(_react2.Form, null, /*#__PURE__*/_react.default.createElement(StepsContext.Provider, {
210
+ }, /*#__PURE__*/_react.default.createElement(_react2.Form, {
211
+ "aria-label": title
212
+ }, /*#__PURE__*/_react.default.createElement(StepsContext.Provider, {
211
213
  value: {
212
214
  currentStep: currentStep,
213
215
  setIsDisabled: setIsDisabled,
@@ -14,6 +14,7 @@ var _react2 = require("@carbon/react");
14
14
  var _devtools = require("../../global/js/utils/devtools");
15
15
  var _settings = require("../../settings");
16
16
  var _TearsheetNarrow = require("../Tearsheet/TearsheetNarrow");
17
+ var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
17
18
  var _excluded = ["children", "className", "description", "disableSubmit", "formDescription", "formTitle", "label", "open", "onRequestClose", "onRequestSubmit", "primaryButtonText", "secondaryButtonText", "selectorPrimaryFocus", "title", "verticalPosition"];
18
19
  /**
19
20
  * Copyright IBM Corp. 2021, 2021
@@ -61,6 +62,7 @@ var CreateTearsheetNarrow = /*#__PURE__*/_react.default.forwardRef(function (_re
61
62
  kind: 'secondary'
62
63
  }];
63
64
  var formTextClass = "".concat(blockClass, "__content-text");
65
+ var formTitleId = (0, _uuidv.default)();
64
66
  return /*#__PURE__*/_react.default.createElement(_TearsheetNarrow.TearsheetNarrow, (0, _extends2.default)({}, rest, {
65
67
  title: title,
66
68
  description: description,
@@ -77,11 +79,13 @@ var CreateTearsheetNarrow = /*#__PURE__*/_react.default.forwardRef(function (_re
77
79
  verticalPosition: verticalPosition,
78
80
  role: "presentation"
79
81
  }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("h3", {
80
- className: (0, _classnames.default)("".concat(blockClass, "__form-title-text"), formTextClass)
82
+ className: (0, _classnames.default)("".concat(blockClass, "__form-title-text"), formTextClass),
83
+ id: formTitleId
81
84
  }, formTitle), /*#__PURE__*/_react.default.createElement("p", {
82
85
  className: (0, _classnames.default)("".concat(blockClass, "__form-description-text"), formTextClass)
83
86
  }, formDescription), /*#__PURE__*/_react.default.createElement(_react2.Form, {
84
- className: "".concat(blockClass, "__form")
87
+ className: "".concat(blockClass, "__form"),
88
+ "aria-labelledby": formTitleId
85
89
  }, children));
86
90
  });
87
91
 
@@ -18,13 +18,17 @@ var _DatagridContent = require("./DatagridContent");
18
18
  var _FilterProvider = require("./addons/Filtering/FilterProvider");
19
19
  var _excluded = ["datagridState"];
20
20
  /**
21
- * Copyright IBM Corp. 2020, 2022
21
+ * Copyright IBM Corp. 2020, 2023
22
22
  *
23
23
  * This source code is licensed under the Apache-2.0 license found in the
24
24
  * LICENSE file in the root directory of this source tree.
25
25
  */
26
26
  var blockClass = "".concat(_settings.pkg.prefix, "--datagrid");
27
27
  var componentName = 'Datagrid';
28
+
29
+ /**
30
+ * The `Datagrid` component is an extension of Carbon's DataTable component. At the most basic level, the `Datagrid` component takes in columns and rows and renders a data table. There is a set of data table extensions which this component provides support for, these can be found [here](https://pages.github.ibm.com/cdai-design/pal/components/data-table/overview/). This component is data driven and allows you to choose what pieces will be included based on the hooks/plugins that are provided.
31
+ */
28
32
  var Datagrid = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
29
33
  var datagridState = _ref.datagridState,
30
34
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
@@ -13,7 +13,6 @@ var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _icons = require("@carbon/react/icons");
15
15
  var _react2 = require("@carbon/react");
16
- var _classnames = _interopRequireDefault(require("classnames"));
17
16
  var _RowSizeRadioGroup = _interopRequireDefault(require("./RowSizeRadioGroup"));
18
17
  var _settings = require("../../../../../settings");
19
18
  var _excluded = ["align", "legendText"];
@@ -28,7 +27,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
28
27
  var blockClass = "".concat(_settings.pkg.prefix, "--datagrid");
29
28
  var RowSizeDropdown = function RowSizeDropdown(_ref) {
30
29
  var _ref$align = _ref.align,
31
- align = _ref$align === void 0 ? 'bottom' : _ref$align,
30
+ align = _ref$align === void 0 ? 'bottom-right' : _ref$align,
32
31
  _ref$legendText = _ref.legendText,
33
32
  legendText = _ref$legendText === void 0 ? 'Row height' : _ref$legendText,
34
33
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
@@ -36,33 +35,28 @@ var RowSizeDropdown = function RowSizeDropdown(_ref) {
36
35
  _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
37
36
  isOpen = _React$useState2[0],
38
37
  setIsOpen = _React$useState2[1];
39
- return /*#__PURE__*/React.createElement(React.Fragment, null, !isOpen && /*#__PURE__*/React.createElement(_react2.IconButton, {
40
- kind: "ghost",
38
+ return /*#__PURE__*/React.createElement(_react2.Popover, {
39
+ isTabTip: true,
40
+ align: "bottom-right",
41
+ open: isOpen,
42
+ onRequestClose: function onRequestClose() {
43
+ return setIsOpen(false);
44
+ },
45
+ className: "".concat(blockClass, "__row-size-options-container")
46
+ }, /*#__PURE__*/React.createElement(_react2.IconButton, {
41
47
  align: align,
48
+ kind: "ghost",
42
49
  onClick: function onClick() {
43
50
  return setIsOpen(function (prevOpen) {
44
51
  return !prevOpen;
45
52
  });
46
53
  },
47
54
  label: legendText,
48
- className: (0, _classnames.default)("".concat(blockClass, "__row-size-button"))
49
- }, /*#__PURE__*/React.createElement(_icons.Settings, {
50
- size: 16
51
- })), isOpen && /*#__PURE__*/React.createElement(_react2.Toggletip, {
52
- defaultOpen: true,
53
- className: "".concat(blockClass, "__row-size-toggle-tip")
54
- }, /*#__PURE__*/React.createElement(_react2.ToggletipButton, {
55
- className: (0, _classnames.default)("".concat(blockClass, "__row-size-toggle-tip-button"), "".concat(blockClass, "__row-size-button--open")),
56
- label: legendText
55
+ className: "".concat(blockClass, "__row-size-button")
57
56
  }, /*#__PURE__*/React.createElement(_icons.Settings, {
58
57
  size: 16
59
- })), /*#__PURE__*/React.createElement(_react2.ToggletipContent, {
60
- className: "".concat(blockClass, "__row-size-toggle-tip-content")
61
- }, /*#__PURE__*/React.createElement(_RowSizeRadioGroup.default, (0, _extends2.default)({}, props, {
62
- legendText: legendText,
63
- hideRadioGroup: function hideRadioGroup() {
64
- setIsOpen(false);
65
- }
58
+ })), /*#__PURE__*/React.createElement(_react2.PopoverContent, null, /*#__PURE__*/React.createElement(_react2.Layer, null, /*#__PURE__*/React.createElement(_RowSizeRadioGroup.default, (0, _extends2.default)({}, props, {
59
+ legendText: legendText
66
60
  })))));
67
61
  };
68
62
  RowSizeDropdown.propTypes = {
@@ -1,27 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
10
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
10
  var _react2 = require("@carbon/react");
12
11
  var _isArray = _interopRequireDefault(require("lodash/isArray"));
13
12
  var _settings = require("../../../../../settings");
14
- var _hooks = require("../../../../../global/js/hooks");
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- /* eslint-disable react/default-props-match-prop-types */
18
- // @flow
19
- /*
20
- * Licensed Materials - Property of IBM
21
- * 5724-Q36
22
- * (c) Copyright IBM Corp. 2021
23
- * US Government Users Restricted Rights - Use, duplication or disclosure
24
- * restricted by GSA ADP Schedule Contract with IBM Corp.
13
+ /**
14
+ * Copyright IBM Corp. 2021, 2023
15
+ *
16
+ * This source code is licensed under the Apache-2.0 license found in the
17
+ * LICENSE file in the root directory of this source tree.
25
18
  */
26
19
 
27
20
  var blockClass = "".concat(_settings.pkg.prefix, "--datagrid");
@@ -30,7 +23,6 @@ var RowSizeRadioGroup = function RowSizeRadioGroup(_ref) {
30
23
  selectedOption = _ref.selectedOption,
31
24
  datagridName = _ref.datagridName,
32
25
  onChange = _ref.onChange,
33
- hideRadioGroup = _ref.hideRadioGroup,
34
26
  legendText = _ref.legendText,
35
27
  _ref$rowSizeLabels = _ref.rowSizeLabels,
36
28
  rowSizeLabels = _ref$rowSizeLabels === void 0 ? {
@@ -40,15 +32,7 @@ var RowSizeRadioGroup = function RowSizeRadioGroup(_ref) {
40
32
  sm: 'Small',
41
33
  xs: 'Extra small'
42
34
  } : _ref$rowSizeLabels;
43
- var popoverContentRef = (0, _react.useRef)();
44
- (0, _hooks.useClickOutside)(popoverContentRef, function (target) {
45
- if (target.closest(".".concat(blockClass, "__row-size-button"))) {
46
- return;
47
- }
48
- hideRadioGroup();
49
- });
50
35
  return /*#__PURE__*/_react.default.createElement("div", {
51
- ref: popoverContentRef,
52
36
  className: "".concat(blockClass, "__row-size-dropdown"),
53
37
  role: "presentation",
54
38
  onClick: function onClick(e) {
@@ -105,7 +89,6 @@ RowSizeRadioGroup.defaultProps = {
105
89
  };
106
90
  RowSizeRadioGroup.propTypes = {
107
91
  datagridName: _propTypes.default.string,
108
- hideRadioGroup: _propTypes.default.func.isRequired,
109
92
  legendText: _propTypes.default.string,
110
93
  onChange: _propTypes.default.func.isRequired,
111
94
  rowSizeLabels: _propTypes.default.object,
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.DocsPage = void 0;
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _StoryDocsPage = require("../../global/js/utils/StoryDocsPage");
11
+ var stories = _interopRequireWildcard(require("./Datagrid.stories"));
12
+ var _datagridActionsExample = _interopRequireDefault(require("./storybook-assets/datagrid-actions-example.png"));
13
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ var DocsPage = function DocsPage() {
16
+ return /*#__PURE__*/_react.default.createElement(_StoryDocsPage.StoryDocsPage, {
17
+ blocks: [{
18
+ title: 'Getting started',
19
+ description: "You can use the `Datagrid` component to create various kinds of Carbon data tables. Simply import the `Datagrid` along with any accompanying hooks (listed below) depending on what extensions you'd like to be included.",
20
+ source: {
21
+ code: "import {\n Datagrid,\n useDatagrid,\n useInfiniteScroll,\n useNestedRows,\n useSelectRows,\n useExpandedRow,\n useOnRowClick,\n useSortableColumns,\n useRowIsMouseOver,\n useColumnRightAlign,\n useDisableSelectRows,\n useStickyColumn,\n useActionsColumn,\n useCustomizeColumns,\n useSelectAllWithToggle,\n useColumnCenterAlign,\n useColumnOrder,\n useEditableCell,\n useFiltering,\n useFilterContext\n} from '@carbon/ibm-products';"
22
+ }
23
+ }, {
24
+ title: 'Basic',
25
+ description: "Here is a basic usage example. The following component will render the datagrid seen below, with pagination and some toolbar actions. One of the key pieces to building the `Datagrid` is the `useDatagrid` hook, this will give you all of the state/props required to render a `Datagrid`."
26
+ }, {
27
+ subTitle: 'Multi line wrap',
28
+ description: 'This setting enables the table cell text wrap to two lines. This can be turned on for only one column in the datagrid or for every column.',
29
+ source: {
30
+ language: 'jsx',
31
+ code: "\n import { Datagrid, useDatagrid } from '@carbon/ibm-products';\n\nconst App = () => {\n const columns = React.useMemo(() => defaultHeader, []); // These are the columns that will be used by the datagrid\n const [data] = useState(makeData(10)); // This is the data that will be rendered by the datagrid\n\n const columns = React.useMemo(\n () => [\n ...defaultHeader,\n {\n Header: 'Someone 11',\n accessor: 'someone11',\n multiLineWrap: true, //If `multiLineWrap` is required only for specific columns\n },\n ],\n []\n );\n\n const datagridState = useDatagrid({\n columns,\n data,\n multiLineWrapAll: true, // If `multiLineWrap` is required for all columns in data grid\n });\n\n return <Datagrid datagridState={datagridState} />;\n};\n "
32
+ }
33
+ }, {
34
+ story: stories.BasicUsage
35
+ }, {
36
+ title: 'Column structure',
37
+ description: "The columns that are passed to the `useDatagrid` hook will have the following structure:",
38
+ source: {
39
+ language: 'jsx',
40
+ code: "\n const columns = [\n {\n Header: 'First Name',\n accessor: 'firstName',\n },\n {\n Header: 'Last Name',\n accessor: 'lastName',\n },\n];"
41
+ }
42
+ }, {
43
+ description: "To change the default/initial width of a column, add a `width` property to the column.",
44
+ source: {
45
+ language: 'jsx',
46
+ code: "\n const columns = [\n {\n Header: 'First Name',\n accessor: 'firstName',\n width: 120,\n },\n {\n Header: 'Last Name',\n accessor: 'lastName',\n width: 180,\n },\n];\n "
47
+ }
48
+ }, {
49
+ description: 'If needed, it is also possible to wrap each cell in a containing element. See below:',
50
+ source: {
51
+ language: 'jsx',
52
+ 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 "
53
+ }
54
+ }, {
55
+ title: 'Rendering the table toolbar',
56
+ image: /*#__PURE__*/_react.default.createElement("img", {
57
+ src: _datagridActionsExample.default,
58
+ alt: "Datagrid highlighting toolbar area"
59
+ }),
60
+ description: "In some of the examples you will see a component named `DatagridActions` passed to the `useDatagrid` hook. This component will render the table toolbar and is something that you will need to create on your own and then provide it to the `useDatagrid` hook. You can reference the `DatagridActions` that we have [created for our stories](https://github.com/carbon-design-system/ibm-products/blob/main/packages/ibm-products/src/components/Datagrid/utils/DatagridActions.js) when building your own."
61
+ }, {
62
+ title: 'Empty',
63
+ story: stories.EmptyState,
64
+ description: "The `Datagrid` supports empty states, when the data prop passed to the `useDatagrid` hook is an empty array.\n ",
65
+ source: {
66
+ language: 'jsx',
67
+ code: "\nimport { Datagrid, useDatagrid } from '@carbon/ibm-products';\n\nconst App = () => {\n const columns = React.useMemo(() => defaultHeader, []); // These are the columns that will be used by the datagrid\n const [data] = useState([]); // This is the data that will be rendered by the datagrid\n\n const datagridState = useDatagrid({\n columns,\n data,\n emptyStateTitle: 'Empty state title',\n emptyStateDescription: 'Description explaining why table is empty',\n emptyStateSize: 'lg', // See empty state size options from the EmptyState component\n });\n\n return <Datagrid datagridState={datagridState} />;\n};\n "
68
+ }
69
+ }, {
70
+ title: 'Auto size column to fit content',
71
+ description: "The `getAutoSizedColumnWidth` utility function can be used to auto size columns based on it's content. The width will be set to that of the largest cell in the column or the column header, whichever is greater. If this is not used, the width will be set to the default column width (150px) or the value passed to the `width` property in the column definition. See example below:",
72
+ source: {
73
+ code: "\nimport { Datagrid, useDatagrid, getAutoSizedColumnWidth } from '@carbon/ibm-products';\n\n...\n\nconst myColumns = [\n {\n Header: 'Column 1',\n accessor: 'column_1',\n width: getAutoSizedColumnWidth(rows, 'column_1', 'Column 1'),\n }\n]\n\n...\n "
74
+ }
75
+ }, {
76
+ title: 'Disabling select rows',
77
+ description: "\n Disabling select rows allows you to choose which rows will be disabled in the table.\n\n- Include the `useDisableSelectRows` hook in the `endPlugins` property of `useDatagrid`.\n- Add the `shouldDisableSelectRow` to the `useDatagrid` hook, this will be a function that returns the row indexes that will be disabled.\n ",
78
+ source: {
79
+ code: "\nconst [data] = useState(makeData(10));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n DatagridActions,\n DatagridBatchActions,\n endPlugins: [useDisableSelectRows],\n shouldDisableSelectRow: (row) => row.id % 2 === 0,\n disableSelectAll: true,\n },\n useSelectRows\n);\n\nreturn <Datagrid datagridState={datagridState} />;\n "
80
+ }
81
+ }, {
82
+ title: 'Infinite scroll',
83
+ description: "Infinite scroll is supported via the `useInfiniteScroll` hook. This hook will allow you to fetch more data to display to the user after a certain scroll threshold. The `useInfiniteScroll` hook can also be used to support virtualized data, this is required when working with large amounts of data, only rendering the rows that need to be visible in the component at a point in time."
84
+ }, {
85
+ description: "Infinite scroll:\n- Include `useInfiniteScroll` hook\n- Add `fetchMoreData` property to `useDatagrid`, this will be a function that is called when the scroll threshold is met. Optionally change the height of the grid with the `virtualHeight` property.",
86
+ source: {
87
+ code: "\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n isFetching,\n fetchMoreData: fetchData,\n virtualHeight: 540,\n emptyStateTitle: 'Empty state title',\n emptyStateDescription: 'Description explaining why the table is empty',\n },\n useInfiniteScroll\n);"
88
+ }
89
+ }, {
90
+ description: "Virtualized data:\n- Include `useInfiniteScroll` hook\n- The Datagrid will know to use virtualized data just by providing the `useInfiniteScroll` hook\n ",
91
+ source: {
92
+ code: "\nconst [data] = useState(makeData(10000));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n },\n useInfiniteScroll\n);\n "
93
+ }
94
+ }, {
95
+ title: 'Detect row hover',
96
+ description: "There may be cases when you want to detect if a user is hovering on a particular row. In this case, use the `useRowIsMouseOver` hook.\n- Include the `useRowIsMouseOver` hook\n- When hover is detected on a row, a property called `isMouseOver` is changed from `false` to `true` within that row.\n "
97
+ }, {
98
+ title: 'Select items across all pages',
99
+ description: "By default, selecting all items with paginated rows will result in just the current page rows being selected. Incorporating the `useSelectAllWithToggle` hook will provide the option to select all rows across all pages.\n- Include `useSelectAllWithToggle` and `useSelectRows` hook\n- Add the `selectAllToggle` property to the `useDatagrid` hook\n- Optionally pass in labels to ensure proper translation\n- Optionally pass in `onSelectAllRoss`, function that will be called via the select all rows checkbox `onChange`\n ",
100
+ source: {
101
+ code: "\nconst [data] = useState(makeData(100));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst [areAllSelected, setAreAllSelected] = useState(false);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n initialState: {\n pageSize: 10,\n pageSizes: [5, 10, 25, 50],\n },\n selectAllToggle: {\n labels: {\n allRows: 'Select all',\n allPageRows: 'Select all on page',\n },\n onSelectAllRows: setAreAllSelected,\n },\n DatagridPagination,\n DatagridActions,\n DatagridBatchActions,\n },\n useSelectRows,\n useSelectAllWithToggle\n);\n\nreturn (\n <Datagrid datagridState={datagridState} />\n);\n "
102
+ }
103
+ }, {
104
+ title: 'Selecting rows',
105
+ description: "When building a Datagrid that requires selectable rows, use the `useSelectRows` hook.\n- Include `useSelectRows` hook\n- Add `onRowSelect` to the `useDatagrid` hook, this is a callback function called when on a row's selection checkbox onChange, and sends back the row object and the event\n ",
106
+ source: {
107
+ code: "\nconst [data] = useState(makeData(10));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n onRowSelect: (row, event) => console.log(row, event),\n },\n useSelectRows\n);\n\nreturn <Datagrid datagridState={datagridState} />;\n "
108
+ }
109
+ }, {
110
+ description: "The select all checkbox can be optionally hidden by settings the `hideSelectAll` property to `true` in the `useDatagrid` hook.",
111
+ source: {
112
+ code: "\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n onRowSelect: (row, event) => console.log(row, event),\n hideSelectAll: true,\n },\n useSelectRows\n);\n "
113
+ }
114
+ }, {
115
+ description: "Datagrid also provides the option to use radio selection in cases where only one row should be selected at a time. Additionally, you can have preselected row/rows, see example below.",
116
+ source: {
117
+ code: "\nconst [data] = useState(makeData(10));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n radio: true,\n onRadioSelect: (row) => console.log(`Row clicked`),\n initialState: {\n selectedRowIds: {\n 3: true,\n },\n },\n },\n useSelectRows\n);\n\nreturn <Datagrid datagridState={datagridState} />;\n "
118
+ }
119
+ }, {
120
+ title: 'Sortable columns',
121
+ description: "To add sortable columns to your Datagrid, simply add the `useSortableColumns` hook. This will allow each column header to be clickable and sort each column in either ascending or descending order.\n- Include `useSortableColumns` hook\n ",
122
+ source: {
123
+ code: "\nconst [data] = useState(makeData(10));\nconst columns = React.useMemo(() => getColumns(data), []);\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n },\n useSortableColumns\n);\n\nreturn <Datagrid datagridState={datagridState} />;\n "
124
+ }
125
+ }, {
126
+ title: 'Sticky column',
127
+ description: "Sticky columns can be useful when you have many columns that create a horizontal scroll and you have important data in the first or last column that you always want to be visible.\n- Include the `useStickyColumn` hook\n- Sticky columns can _only_ be applied to the first and the last columns in the Datagrid. To have the first column stick, add `sticky: 'left'` to the first column definition. To have the last column stick, add `sticky: 'right'` to the last column definition.\n ",
128
+ source: {
129
+ code: "\nconst columns = [\n {\n Header: 'First column',\n accessor: 'first_column',\n sticky: 'left',\n },\n {\n ...\n },\n {\n ...\n }\n];\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n },\n useStickyColumn\n);\n\nreturn <Datagrid datagridState={datagridState} />;\n "
130
+ }
131
+ }]
132
+ });
133
+ };
134
+ exports.DocsPage = DocsPage;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DocsPage = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _StoryDocsPage = require("../../../../global/js/utils/StoryDocsPage");
10
+ var DocsPage = function DocsPage() {
11
+ return /*#__PURE__*/_react.default.createElement(_StoryDocsPage.StoryDocsPage, {
12
+ blocks: [{
13
+ description: "The default column alignment in the `Datagrid` is left, however there is support for center and right aligned as well. See [design guidance](https://pages.github.ibm.com/cdai-design/pal/components/data-table/column-alignment/usage) for details around when to change default column alignment.\n\nTo utilize center or right aligned columns refer to the steps below:\n\n - Include `useColumnCenterAlign` or `useColumnRightAlign` hook/s.\n - Add `rightAlignedColumn` or `centerAlignedColumn` to the column object in which you which to change the default column alignment.\n ",
14
+ source: {
15
+ language: 'jsx',
16
+ code: "\nimport {\n Datagrid,\n useDatagrid,\n useColumnCenterAlign,\n useColumnRightAlign,\n} from '@carbon/ibm-products';\n\nconst defaultColumns = [\n ...defaultCols,\n {\n Header: 'Bonus',\n accessor: 'bonus',\n width: 120,\n rightAlignedColumn: true,\n },\n {\n Header: 'Status',\n accessor: 'status_icon',\n width: 100,\n centerAlignedColumn: true,\n },\n];\n\nconst App = () => {\n const columns = React.useMemo(() => [...defaultHeader], []);\n const [data] = useState(makeData(10));\n\n const datagridState = useDatagrid(\n {\n columns,\n data,\n initialState: {\n pageSize: 10,\n pageSizes: [5, 10, 25, 50],\n },\n DatagridActions,\n DatagridPagination,\n },\n useColumnCenterAlign,\n useColumnRightAlign\n );\n\n return <Datagrid datagridState={datagridState} />;\n};\n "
17
+ }
18
+ }]
19
+ });
20
+ };
21
+ exports.DocsPage = DocsPage;