@carbon/ibm-products 2.3.2 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/css/index-full-carbon.css +262 -110
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +40 -24
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +2 -2
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +86 -54
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +145 -38
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Card/Card.js +11 -1
  18. package/es/components/Card/CardFooter.js +4 -2
  19. package/es/components/Card/CardHeader.js +20 -2
  20. package/es/components/Datagrid/Datagrid/Datagrid.js +5 -1
  21. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +15 -21
  22. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +6 -20
  23. package/es/components/Datagrid/Datagrid.docs-page.js +123 -0
  24. package/es/components/Datagrid/Extensions/ColumnAlignment/ColumnAlignment.docs-page.js +13 -0
  25. package/es/components/Datagrid/Extensions/ColumnCustomization/ColumnCustomization.docs-page.js +13 -0
  26. package/es/components/Datagrid/Extensions/EditableCell/EditableCell.docs-page.js +47 -0
  27. package/es/components/Datagrid/Extensions/ExpandableRow/ExpandableRow.docs-page.js +13 -0
  28. package/es/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +57 -0
  29. package/es/components/Datagrid/Extensions/RowActionButtons/RowActionButtons.docs-page.js +13 -0
  30. package/es/components/Datagrid/utils/DatagridActions.js +1 -1
  31. package/es/components/Datagrid/utils/getArgTypes.js +4 -0
  32. package/es/components/EditUpdateCards/EditUpdateCards.js +66 -4
  33. package/es/components/FilterSummary/FilterSummary.js +7 -3
  34. package/es/components/OptionsTile/OptionsTile.js +8 -1
  35. package/es/components/ProductiveCard/ProductiveCard.js +21 -1
  36. package/es/global/js/utils/StoryDocsPage.js +6 -2
  37. package/lib/components/Card/Card.js +11 -1
  38. package/lib/components/Card/CardFooter.js +4 -2
  39. package/lib/components/Card/CardHeader.js +20 -2
  40. package/lib/components/Datagrid/Datagrid/Datagrid.js +5 -1
  41. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +14 -20
  42. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +6 -23
  43. package/lib/components/Datagrid/Datagrid.docs-page.js +134 -0
  44. package/lib/components/Datagrid/Extensions/ColumnAlignment/ColumnAlignment.docs-page.js +21 -0
  45. package/lib/components/Datagrid/Extensions/ColumnCustomization/ColumnCustomization.docs-page.js +21 -0
  46. package/lib/components/Datagrid/Extensions/EditableCell/EditableCell.docs-page.js +55 -0
  47. package/lib/components/Datagrid/Extensions/ExpandableRow/ExpandableRow.docs-page.js +21 -0
  48. package/lib/components/Datagrid/Extensions/Filtering/Filtering.docs-page.js +65 -0
  49. package/lib/components/Datagrid/Extensions/RowActionButtons/RowActionButtons.docs-page.js +21 -0
  50. package/lib/components/Datagrid/utils/DatagridActions.js +1 -1
  51. package/lib/components/Datagrid/utils/getArgTypes.js +4 -0
  52. package/lib/components/EditUpdateCards/EditUpdateCards.js +66 -4
  53. package/lib/components/FilterSummary/FilterSummary.js +7 -3
  54. package/lib/components/OptionsTile/OptionsTile.js +8 -1
  55. package/lib/components/ProductiveCard/ProductiveCard.js +21 -1
  56. package/lib/global/js/utils/StoryDocsPage.js +6 -2
  57. package/package.json +16 -16
  58. package/scss/components/Datagrid/_datagrid.scss +17 -10
  59. package/scss/components/Datagrid/_storybook-styles.scss +5 -0
  60. package/scss/components/EditUpdateCards/_edit-update-cards.scss +10 -0
  61. package/scss/components/FilterSummary/_storybook-styles.scss +2 -0
  62. package/scss/components/ProductiveCard/_productive-card.scss +15 -0
  63. package/scss/components/Tearsheet/_tearsheet.scss +6 -0
@@ -27,7 +27,7 @@ export var ProductiveCard = /*#__PURE__*/forwardRef(function (_ref, ref) {
27
27
  var _ref$actionsPlacement = _ref.actionsPlacement,
28
28
  actionsPlacement = _ref$actionsPlacement === void 0 ? defaults.actionsPlacement : _ref$actionsPlacement,
29
29
  rest = _objectWithoutProperties(_ref, _excluded);
30
- var validProps = prepareProps(rest, ['media', 'mediaPosition', 'onSecondaryButtonClick', 'pictogram', 'primaryButtonClick', 'productive', 'secondaryButtonKind', 'secondaryButtonText']);
30
+ var validProps = prepareProps(rest, ['media', 'mediaPosition', 'pictogram', 'primaryButtonClick', 'productive', 'secondaryButtonKind']);
31
31
  return /*#__PURE__*/React.createElement(Card, _extends({}, _objectSpread(_objectSpread({}, validProps), {}, {
32
32
  actionsPlacement: actionsPlacement,
33
33
  ref: ref
@@ -82,6 +82,10 @@ ProductiveCard.propTypes = {
82
82
  * Function that's called from the primary button or action icon
83
83
  */
84
84
  onPrimaryButtonClick: PropTypes.func,
85
+ /**
86
+ * Function that's called from the secondary button or action icon
87
+ */
88
+ onSecondaryButtonClick: PropTypes.func,
85
89
  /**
86
90
  * Use an overflow menu instead of action icons. Refer to design documentation for implementation guidelines
87
91
  */
@@ -111,6 +115,22 @@ ProductiveCard.propTypes = {
111
115
  * The text that's displayed in the primary button
112
116
  */
113
117
  primaryButtonText: PropTypes.node,
118
+ /**
119
+ * Optionally specify an href for your Button to become an <a> element
120
+ */
121
+ secondaryButtonHref: PropTypes.string,
122
+ /**
123
+ * Optional prop to allow overriding the icon rendering. Can be a React component class
124
+ */
125
+ secondaryButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
126
+ /**
127
+ * Determines if the secondary button is on the top or bottom of the card
128
+ */
129
+ secondaryButtonPlacement: PropTypes.oneOf(['top', 'bottom']),
130
+ /**
131
+ * The text that's displayed in the secondary button
132
+ */
133
+ secondaryButtonText: PropTypes.node,
114
134
  /**
115
135
  * Title that's displayed at the top of the card
116
136
  */
@@ -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
  })),
@@ -16,7 +16,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
16
16
  var _CardHeader = require("./CardHeader");
17
17
  var _CardFooter = require("./CardFooter");
18
18
  var _settings = require("../../settings");
19
- var _excluded = ["actionIcons", "actionsPlacement", "children", "className", "clickZone", "description", "label", "media", "mediaPosition", "onClick", "onKeyDown", "onPrimaryButtonClick", "overflowActions", "overflowAriaLabel", "onSecondaryButtonClick", "pictogram", "primaryButtonHref", "primaryButtonIcon", "primaryButtonKind", "primaryButtonPlacement", "primaryButtonText", "productive", "secondaryButtonHref", "secondaryButtonIcon", "secondaryButtonKind", "secondaryButtonText", "title", "titleSize"],
19
+ var _excluded = ["actionIcons", "actionsPlacement", "children", "className", "clickZone", "description", "label", "media", "mediaPosition", "onClick", "onKeyDown", "onPrimaryButtonClick", "overflowActions", "overflowAriaLabel", "onSecondaryButtonClick", "pictogram", "primaryButtonHref", "primaryButtonIcon", "primaryButtonKind", "primaryButtonPlacement", "primaryButtonText", "productive", "secondaryButtonHref", "secondaryButtonIcon", "secondaryButtonKind", "secondaryButtonPlacement", "secondaryButtonText", "title", "titleSize"],
20
20
  _excluded2 = ["id"],
21
21
  _excluded3 = ["id", "icon", "onClick", "iconDescription", "href"]; //
22
22
  // Copyright IBM Corp. 2020, 2023
@@ -41,6 +41,7 @@ var defaults = {
41
41
  primaryButtonPlacement: 'bottom',
42
42
  productive: false,
43
43
  secondaryButtonKind: 'secondary',
44
+ secondaryButtonPlacement: 'bottom',
44
45
  titleSize: 'default'
45
46
  };
46
47
  var Card = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
@@ -78,6 +79,8 @@ var Card = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
78
79
  secondaryButtonIcon = _ref.secondaryButtonIcon,
79
80
  _ref$secondaryButtonK = _ref.secondaryButtonKind,
80
81
  secondaryButtonKind = _ref$secondaryButtonK === void 0 ? defaults.secondaryButtonKind : _ref$secondaryButtonK,
82
+ _ref$secondaryButtonP = _ref.secondaryButtonPlacement,
83
+ secondaryButtonPlacement = _ref$secondaryButtonP === void 0 ? defaults.secondaryButtonPlacement : _ref$secondaryButtonP,
81
84
  secondaryButtonText = _ref.secondaryButtonText,
82
85
  title = _ref.title,
83
86
  _ref$titleSize = _ref.titleSize,
@@ -182,12 +185,17 @@ var Card = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
182
185
  noActionIcons: actionIcons.length > 0 && actionsPlacement === 'top' ? false : true,
183
186
  actionsPlacement: actionsPlacement,
184
187
  onPrimaryButtonClick: onPrimaryButtonClick,
188
+ onSecondaryButtonClick: onSecondaryButtonClick,
185
189
  primaryButtonIcon: primaryButtonIcon,
186
190
  primaryButtonPlacement: primaryButtonPlacement,
187
191
  primaryButtonText: primaryButtonText,
188
192
  description: description,
189
193
  hasActions: hasActions,
190
194
  label: label,
195
+ secondaryButtonHref: secondaryButtonHref,
196
+ secondaryButtonIcon: secondaryButtonIcon,
197
+ secondaryButtonPlacement: secondaryButtonPlacement,
198
+ secondaryButtonText: secondaryButtonText,
191
199
  title: title,
192
200
  titleSize: titleSize
193
201
  };
@@ -216,6 +224,7 @@ var Card = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
216
224
  secondaryButtonHref: secondaryButtonHref,
217
225
  secondaryButtonIcon: secondaryButtonIcon,
218
226
  secondaryButtonKind: secondaryButtonKind,
227
+ secondaryButtonPlacement: secondaryButtonPlacement,
219
228
  secondaryButtonText: secondaryButtonText
220
229
  };
221
230
  };
@@ -266,6 +275,7 @@ Card.propTypes = {
266
275
  secondaryButtonHref: _propTypes.default.string,
267
276
  secondaryButtonIcon: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
268
277
  secondaryButtonKind: _propTypes.default.oneOf(['secondary', 'ghost']),
278
+ secondaryButtonPlacement: _propTypes.default.oneOf(['top', 'bottom']),
269
279
  secondaryButtonText: _propTypes.default.string,
270
280
  title: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object, _propTypes.default.node]),
271
281
  titleSize: _propTypes.default.oneOf(['default', 'large'])
@@ -44,14 +44,15 @@ var CardFooter = function CardFooter(_ref) {
44
44
  secondaryButtonIcon = _ref.secondaryButtonIcon,
45
45
  _ref$secondaryButtonK = _ref.secondaryButtonKind,
46
46
  secondaryButtonKind = _ref$secondaryButtonK === void 0 ? defaults.secondaryButtonKind : _ref$secondaryButtonK,
47
+ secondaryButtonPlacement = _ref.secondaryButtonPlacement,
47
48
  secondaryButtonText = _ref.secondaryButtonText;
48
49
  var blockClass = "".concat(_settings.pkg.prefix, "--card");
49
50
  var footerClass = "".concat(_settings.pkg.prefix, "--card__footer");
50
51
  var footerClasses = (0, _classnames.default)(footerClass, (0, _defineProperty2.default)({}, "".concat(footerClass, "-no-button"), !hasButton));
51
52
  return /*#__PURE__*/_react.default.createElement("div", {
52
53
  className: footerClasses
53
- }, secondaryButtonText && /*#__PURE__*/_react.default.createElement(_react2.Button, {
54
- kind: secondaryButtonKind,
54
+ }, secondaryButtonText && secondaryButtonPlacement === 'bottom' && /*#__PURE__*/_react.default.createElement(_react2.Button, {
55
+ kind: productive ? 'ghost' : secondaryButtonKind,
55
56
  onClick: onSecondaryButtonClick,
56
57
  size: "md",
57
58
  renderIcon: secondaryButtonIcon,
@@ -82,6 +83,7 @@ CardFooter.propTypes = {
82
83
  secondaryButtonHref: _propTypes.default.string,
83
84
  secondaryButtonIcon: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
84
85
  secondaryButtonKind: _propTypes.default.oneOf(['secondary', 'ghost']),
86
+ secondaryButtonPlacement: _propTypes.default.oneOf(['top', 'bottom']),
85
87
  secondaryButtonText: _propTypes.default.string
86
88
  };
87
89
  CardFooter.displayName = componentName;
@@ -28,6 +28,7 @@ var CardHeader = function CardHeader(_ref) {
28
28
  var actions = _ref.actions,
29
29
  noActionIcons = _ref.noActionIcons,
30
30
  onPrimaryButtonClick = _ref.onPrimaryButtonClick,
31
+ onSecondaryButtonClick = _ref.onSecondaryButtonClick,
31
32
  primaryButtonIcon = _ref.primaryButtonIcon,
32
33
  primaryButtonPlacement = _ref.primaryButtonPlacement,
33
34
  primaryButtonText = _ref.primaryButtonText,
@@ -35,6 +36,10 @@ var CardHeader = function CardHeader(_ref) {
35
36
  _ref$hasActions = _ref.hasActions,
36
37
  hasActions = _ref$hasActions === void 0 ? defaults.hasActions : _ref$hasActions,
37
38
  label = _ref.label,
39
+ secondaryButtonHref = _ref.secondaryButtonHref,
40
+ secondaryButtonIcon = _ref.secondaryButtonIcon,
41
+ secondaryButtonPlacement = _ref.secondaryButtonPlacement,
42
+ secondaryButtonText = _ref.secondaryButtonText,
38
43
  title = _ref.title,
39
44
  _ref$titleSize = _ref.titleSize,
40
45
  titleSize = _ref$titleSize === void 0 ? defaults.titleSize : _ref$titleSize;
@@ -57,9 +62,16 @@ var CardHeader = function CardHeader(_ref) {
57
62
  className: "".concat(blockClass, "__description")
58
63
  }, description)), hasActions && /*#__PURE__*/_react.default.createElement("div", {
59
64
  className: "".concat(blockClass, "__actions ").concat(blockClass, "__actions-header")
60
- }, actions, primaryButtonText && primaryButtonPlacement === 'top' && /*#__PURE__*/_react.default.createElement(_react2.Button, {
65
+ }, actions, secondaryButtonText && secondaryButtonPlacement === 'top' && /*#__PURE__*/_react.default.createElement(_react2.Button, {
61
66
  kind: "ghost",
62
- size: "small",
67
+ onClick: onSecondaryButtonClick,
68
+ size: "sm",
69
+ renderIcon: secondaryButtonIcon,
70
+ href: secondaryButtonHref,
71
+ className: actionGhostButtonClass
72
+ }, secondaryButtonText), primaryButtonText && primaryButtonPlacement === 'top' && /*#__PURE__*/_react.default.createElement(_react2.Button, {
73
+ kind: "ghost",
74
+ size: "sm",
63
75
  renderIcon: primaryButtonIcon,
64
76
  onClick: onPrimaryButtonClick,
65
77
  className: actionGhostButtonClass
@@ -73,9 +85,15 @@ CardHeader.propTypes = {
73
85
  label: _propTypes.default.string,
74
86
  noActionIcons: _propTypes.default.bool,
75
87
  onPrimaryButtonClick: _propTypes.default.func,
88
+ onSecondaryButtonClick: _propTypes.default.func,
76
89
  primaryButtonIcon: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
77
90
  primaryButtonPlacement: _propTypes.default.oneOf(['top', 'bottom']),
78
91
  primaryButtonText: _propTypes.default.string,
92
+ secondaryButtonHref: _propTypes.default.string,
93
+ secondaryButtonIcon: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
94
+ secondaryButtonKind: _propTypes.default.oneOf(['secondary', 'ghost']),
95
+ secondaryButtonPlacement: _propTypes.default.oneOf(['top', 'bottom']),
96
+ secondaryButtonText: _propTypes.default.string,
79
97
  title: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object, _propTypes.default.node]),
80
98
  titleSize: _propTypes.default.oneOf(['default', 'large'])
81
99
  };
@@ -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;
@@ -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
+ title: 'Customizing columns',
14
+ description: "Customizing columns allows user to reorder and hide certain columns of the datagrid. Consuming component can use the provided callback to save/update according to their persistent strategy.\n- Include `useCustomizeColumns` and `useColumnOrder` hooks (required)\n - `useColumnOrder` comes from `react-table` but is exported by `@carbon/ibm-products` to be used alongside `useCustomizeColumns`.\n- Implement `options.DatagridActions` component\n - this component will have props: `datagridState`\n - render `datagridState.CustomizeColumnsButton` component wherever makes sense.\n- Options available to set:\n - `options.initialState.hiddenColumns: Array<ColumnId: String>`\n - Array of column ids that will be hidden after initial render\n - [react-table doc](https://react-table.tanstack.com/docs/api/useTable#table-options)\n - `options.initialState.columnOrder: Array<ColumnId: String>`\n - Order of the columns. Any column ids not in this array will be ordered by their position in the `options.columns`\n - [react-table doc](https://react-table.tanstack.com/docs/api/useColumnOrder#table-options)\n - `options.customizeColumnsProps.onSaveColumnPrefs`\n - type: `Function(Columns: Array<{ColumnId: String, isVisible: Boolean}>) => void`\n - Callback function when 'Save' button clicked on the narrow tearsheet. It allows consumer to preserve the updated column preference. This output can also be used to compute the `hiddenColumns` and `columnOrder`\n - Reset to default (optional)\n - There is a reset to default button on the modal. It will use the `options.columns` as the default. If there are columns should be hidden by default, denote them with property: `isVisible: false` (undefined will be treated as `true`).\n ",
15
+ source: {
16
+ code: "\nconst columns = React.useMemo(() => defaultHeader, []);\nconst [data] = useState(makeData(10));\nconst DatagridActions = (datagridState) => (\n <TableToolbarContent>\n <TableToolbarSearch ... />\n <Button ... />\n <datagridState.CustomizeColumnsButton />\n </TableToolbarContent>\n)\nconst datagridState = useDatagrid(\n {\n columns,\n data,\n initialState: {\n hiddenColumns: ['age'],\n columnOrder: [],\n },\n customizeColumnsProps: {\n onSaveColumnPrefs: (newColDefs) => {\n console.log(newColDefs);\n },\n },\n DatagridActions,\n },\n useCustomizeColumns,\n useColumnOrder,\n);\n\nreturn (\n <Datagrid datagridState={datagridState} />\n);\n "
17
+ }
18
+ }]
19
+ });
20
+ };
21
+ exports.DocsPage = DocsPage;
@@ -0,0 +1,55 @@
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 _EditableCell = require("./EditableCell.stories");
11
+ var DocsPage = function DocsPage() {
12
+ return /*#__PURE__*/_react.default.createElement(_StoryDocsPage.StoryDocsPage, {
13
+ blocks: [{
14
+ description: "The `Datagrid` supports inline editing when used with the `useEditableCell` hook (previously named `useInlineEdit` in v1) and columns are provided the required configuration. The four data types supported are strings, numbers, dates, and\n selection (dropdown)."
15
+ }, {
16
+ description: "Below are example column configurations for the supported inline edit data types:\n \nDefault/string:\n ",
17
+ source: {
18
+ language: 'json',
19
+ code: "\n {\n Header: 'First Name',\n accessor: 'firstName',\n inlineEdit: {\n type: 'text',\n // required for including validation, this is used to set the invalid prop internally\n validator: (n) => n.length >= 40,\n // These props are passed to the Carbon component used for inline editing, in this case the TextInput\n inputProps: {\n invalidText: 'Invalid text, character count must be less than 40',\n },\n },\n }\n "
20
+ }
21
+ }, {
22
+ description: 'Number',
23
+ source: {
24
+ language: 'json',
25
+ code: "\n{\n Header: 'Age',\n accessor: 'age',\n width: 120,\n inlineEdit: {\n // required for including validation, this is used to set the invalid prop internally\n validator: (n) => n && n < 18,\n type: 'number',\n // These props are passed to the Carbon component used for inline editing, in this case NumberInput\n inputProps: {\n invalidText: 'Invalid number, must be 18 or greater',\n },\n },\n},\n "
26
+ }
27
+ }, {
28
+ description: 'Date',
29
+ source: {
30
+ language: 'json',
31
+ code: "\n{\n Header: 'Active since',\n accessor: 'activeSince',\n inlineEdit: {\n type: 'date',\n inputProps: {\n // optionally pass props here to be passed through to Carbon's DatePicker component\n onChange: (newDateObj, cell) => {\n console.log(newDateObj, cell);\n },\n labelText: 'Change active since date',\n // optionally pass props here to be passed through to Carbon's DatePickerInput component\n datePickerInputProps: {\n labelText: 'Change active since date',\n },\n },\n },\n},\n "
32
+ }
33
+ }, {
34
+ description: 'Selection',
35
+ source: {
36
+ language: 'json',
37
+ code: "\n{\n Header: 'Chart type',\n accessor: 'chartType',\n inlineEdit: {\n type: 'selection',\n inputProps: {\n // These props are passed to the Carbon component used for inline editing\n items: [\n {\n id: 'option-0',\n icon: ChartColumnFloating16,\n text: 'Column Chart',\n },\n {\n id: 'option-1',\n icon: ChartBubble16,\n text: 'Bubble Chart',\n },\n {\n id: 'option-2',\n icon: ChartVennDiagram16,\n text: 'Venn Diagram',\n },\n ],\n onChange: (item) => {\n console.log(item);\n },\n },\n },\n},\n "
38
+ }
39
+ }, {
40
+ description: "Using the column structure outlined above, along with the use of the `useEditableCell` hook (previously named `useInlineEdit` in v1), the `Datagrid` will support inline editing. See example below:",
41
+ source: {
42
+ code: "\nimport { Datagrid, useDatagrid, useEditableCell } from '@carbon/ibm-products';\nconst App = () => {\n const [data, setData] = useState(makeData(10));\n const columns = React.useMemo(() => getInlineEditColumns(), []); // These columns follow the inline edit column configuration detailed above\n const datagridState = useDatagrid(\n {\n columns,\n data,\n onDataUpdate: setData,\n },\n useEditableCell\n );\n return <Datagrid datagridState={datagridState} />;\n};\n "
43
+ },
44
+ story: _EditableCell.EditableCellUsageStory
45
+ }, {
46
+ title: 'Using deprecated useInlineEdit hook',
47
+ description: "At this time, it is possible to still use the deprecated `useInlineEdit` hook but requires setting a feature flag. See example below:",
48
+ source: {
49
+ code: "\nimport {\n Datagrid,\n useDatagrid,\n useInlineEdit,\n pkg,\n} from '@carbon/ibm-products';\n\nconst MyInlineEditDatagrid = () => {\n pkg.feature['Datagrid.useInlineEdit'] = true;\n const [data, setData] = useState(gridData);\n const datagridState = useDatagrid(\n {\n columns,\n data,\n onDataUpdate: setData,\n },\n useInlineEdit\n );\n return <Datagrid datagridState={datagridState} />;\n};\n "
50
+ },
51
+ story: _EditableCell.InlineEditUsageStory
52
+ }]
53
+ });
54
+ };
55
+ exports.DocsPage = DocsPage;