@commercetools-uikit/data-table 19.9.0 → 19.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,6 +78,9 @@ export default Example;
78
78
  | `sortedBy` | `string` | | | The key of the column for which the data is currently sorted by. |
79
79
  | `onSortChange` | `Function`<br/>[See signature.](#signature-onSortChange) | | | A callback function, called when a sortable column's header is clicked.&#xA;It's required when the `isSortable` flag is set on at least one column. |
80
80
  | `sortDirection` | `union`<br/>Possible values:<br/>`'desc' , 'asc'` | | | The sorting direction. |
81
+ | `customSettingsPayload` | `Record<string, unknown>` | | | Manage custom settings for the table |
82
+ | `customColumns` | `Array: TColumn<Row>[]` | | | The columns of the nested items to be rendered in the table. Just like the columns, Each object requires a unique `key` which should correspond to property key of the items of `rows` that you want to render under this column, and a `label` which defines the name shown on the header. The list of columns to be rendered. |
83
+ | `customRows` | `Array: Row[]` | | | The list of data that needs to be rendered in the nested component. Each object in the list can have any shape as long as it has a unique identifier. |
81
84
 
82
85
  ## Signatures
83
86
 
@@ -648,7 +648,8 @@ DataRow.propTypes = process.env.NODE_ENV !== "production" ? {
648
648
  rowIndex: _pt__default["default"].number.isRequired,
649
649
  columns: _pt__default["default"].arrayOf(_pt__default["default"].any).isRequired,
650
650
  shouldClipContent: _pt__default["default"].bool.isRequired,
651
- shouldRenderBottomBorder: _pt__default["default"].bool.isRequired
651
+ shouldRenderBottomBorder: _pt__default["default"].bool.isRequired,
652
+ onExpandRow: _pt__default["default"].func
652
653
  } : {};
653
654
  DataRow.defaultProps = defaultProps$1;
654
655
  DataRow.displayName = 'DataRow';
@@ -838,6 +839,16 @@ const DataTable = props => {
838
839
  const isValueFromProvider = Boolean(columns && columns.length !== 0);
839
840
  const columnsData = isValueFromProvider ? columns : props.columns;
840
841
  const condensedValue = isValueFromProvider && isCondensed !== undefined ? isCondensed : props.isCondensed;
842
+
843
+ // TODO - initial poc for the nested rows
844
+ // const [openedItemIds, setOpenedItemIds] = useState<string[]>([]);
845
+ // const handleExpandRow = (row: Row) => {
846
+ // const newOpenedItemIds = openedItemIds.includes(row.id)
847
+ // ? openedItemIds.filter((id) => id !== row.id)
848
+ // : [...openedItemIds, row.id];
849
+ // setOpenedItemIds(newOpenedItemIds);
850
+ // };
851
+
841
852
  process.env.NODE_ENV !== "production" ? utils.warning(columnsData.length > 0, "ui-kit/DataTable: empty table \"columns\", expected at least one column. If you are using DataTableManager you need to pass the \"columns\" there and they will be injected into DataTable.") : void 0;
842
853
  const tableRef = react$1.useRef();
843
854
  const columnResizingReducer = useManualColumnResizing$1(tableRef);
@@ -935,6 +946,19 @@ DataTable.propTypes = process.env.NODE_ENV !== "production" ? {
935
946
  disableResizing: _pt__default["default"].bool,
936
947
  shouldIgnoreRowClick: _pt__default["default"].bool
937
948
  })).isRequired,
949
+ customColumns: _pt__default["default"].arrayOf(_pt__default["default"].shape({
950
+ key: _pt__default["default"].string.isRequired,
951
+ label: _pt__default["default"].node.isRequired,
952
+ width: _pt__default["default"].string,
953
+ align: _pt__default["default"].oneOf(['left', 'center', 'right']),
954
+ onClick: _pt__default["default"].func,
955
+ renderItem: _pt__default["default"].func,
956
+ headerIcon: _pt__default["default"].node,
957
+ isTruncated: _pt__default["default"].bool,
958
+ isSortable: _pt__default["default"].bool,
959
+ disableResizing: _pt__default["default"].bool,
960
+ shouldIgnoreRowClick: _pt__default["default"].bool
961
+ })),
938
962
  footer: _pt__default["default"].node,
939
963
  maxWidth: _pt__default["default"].oneOfType([_pt__default["default"].number, _pt__default["default"].string]),
940
964
  maxHeight: _pt__default["default"].oneOfType([_pt__default["default"].number, _pt__default["default"].string]),
@@ -949,14 +973,16 @@ DataTable.propTypes = process.env.NODE_ENV !== "production" ? {
949
973
  horizontalCellAlignment: _pt__default["default"].oneOf(['left', 'center', 'right']),
950
974
  sortedBy: _pt__default["default"].string,
951
975
  onSortChange: _pt__default["default"].func,
952
- sortDirection: _pt__default["default"].oneOf(['desc', 'asc'])
976
+ sortDirection: _pt__default["default"].oneOf(['desc', 'asc']),
977
+ renderNestedRow: _pt__default["default"].func,
978
+ maxExpandableHeight: _pt__default["default"].number
953
979
  } : {};
954
980
  DataTable.defaultProps = defaultProps;
955
981
  DataTable.displayName = 'DataTable';
956
982
  var DataTable$1 = DataTable;
957
983
 
958
984
  // NOTE: This string will be replaced on build time with the package version.
959
- var version = "19.9.0";
985
+ var version = "19.10.0";
960
986
 
961
987
  Object.defineProperty(exports, 'useRowSelection', {
962
988
  enumerable: true,
@@ -759,7 +759,7 @@ DataTable.displayName = 'DataTable';
759
759
  var DataTable$1 = DataTable;
760
760
 
761
761
  // NOTE: This string will be replaced on build time with the package version.
762
- var version = "19.9.0";
762
+ var version = "19.10.0";
763
763
 
764
764
  Object.defineProperty(exports, 'useRowSelection', {
765
765
  enumerable: true,
@@ -624,7 +624,8 @@ DataRow.propTypes = process.env.NODE_ENV !== "production" ? {
624
624
  rowIndex: _pt.number.isRequired,
625
625
  columns: _pt.arrayOf(_pt.any).isRequired,
626
626
  shouldClipContent: _pt.bool.isRequired,
627
- shouldRenderBottomBorder: _pt.bool.isRequired
627
+ shouldRenderBottomBorder: _pt.bool.isRequired,
628
+ onExpandRow: _pt.func
628
629
  } : {};
629
630
  DataRow.defaultProps = defaultProps$1;
630
631
  DataRow.displayName = 'DataRow';
@@ -814,6 +815,16 @@ const DataTable = props => {
814
815
  const isValueFromProvider = Boolean(columns && columns.length !== 0);
815
816
  const columnsData = isValueFromProvider ? columns : props.columns;
816
817
  const condensedValue = isValueFromProvider && isCondensed !== undefined ? isCondensed : props.isCondensed;
818
+
819
+ // TODO - initial poc for the nested rows
820
+ // const [openedItemIds, setOpenedItemIds] = useState<string[]>([]);
821
+ // const handleExpandRow = (row: Row) => {
822
+ // const newOpenedItemIds = openedItemIds.includes(row.id)
823
+ // ? openedItemIds.filter((id) => id !== row.id)
824
+ // : [...openedItemIds, row.id];
825
+ // setOpenedItemIds(newOpenedItemIds);
826
+ // };
827
+
817
828
  process.env.NODE_ENV !== "production" ? warning(columnsData.length > 0, "ui-kit/DataTable: empty table \"columns\", expected at least one column. If you are using DataTableManager you need to pass the \"columns\" there and they will be injected into DataTable.") : void 0;
818
829
  const tableRef = useRef();
819
830
  const columnResizingReducer = useManualColumnResizing$1(tableRef);
@@ -911,6 +922,19 @@ DataTable.propTypes = process.env.NODE_ENV !== "production" ? {
911
922
  disableResizing: _pt.bool,
912
923
  shouldIgnoreRowClick: _pt.bool
913
924
  })).isRequired,
925
+ customColumns: _pt.arrayOf(_pt.shape({
926
+ key: _pt.string.isRequired,
927
+ label: _pt.node.isRequired,
928
+ width: _pt.string,
929
+ align: _pt.oneOf(['left', 'center', 'right']),
930
+ onClick: _pt.func,
931
+ renderItem: _pt.func,
932
+ headerIcon: _pt.node,
933
+ isTruncated: _pt.bool,
934
+ isSortable: _pt.bool,
935
+ disableResizing: _pt.bool,
936
+ shouldIgnoreRowClick: _pt.bool
937
+ })),
914
938
  footer: _pt.node,
915
939
  maxWidth: _pt.oneOfType([_pt.number, _pt.string]),
916
940
  maxHeight: _pt.oneOfType([_pt.number, _pt.string]),
@@ -925,13 +949,15 @@ DataTable.propTypes = process.env.NODE_ENV !== "production" ? {
925
949
  horizontalCellAlignment: _pt.oneOf(['left', 'center', 'right']),
926
950
  sortedBy: _pt.string,
927
951
  onSortChange: _pt.func,
928
- sortDirection: _pt.oneOf(['desc', 'asc'])
952
+ sortDirection: _pt.oneOf(['desc', 'asc']),
953
+ renderNestedRow: _pt.func,
954
+ maxExpandableHeight: _pt.number
929
955
  } : {};
930
956
  DataTable.defaultProps = defaultProps;
931
957
  DataTable.displayName = 'DataTable';
932
958
  var DataTable$1 = DataTable;
933
959
 
934
960
  // NOTE: This string will be replaced on build time with the package version.
935
- var version = "19.9.0";
961
+ var version = "19.10.0";
936
962
 
937
963
  export { DataTable$1 as default, version };
@@ -3,36 +3,186 @@ export interface TRow {
3
3
  id: string;
4
4
  }
5
5
  export type TColumn<Row extends TRow = TRow> = {
6
+ /**
7
+ * The unique key of the column that is used to identify your data type.
8
+ * You can use this value to determine which value from a row item should be rendered.
9
+ * <br>
10
+ * For example, if the data is a list of users, where each user has a `firstName` property,
11
+ * the column key should be `firstName`, which renders the correct value by default.
12
+ * The key can also be some custom or computed value, in which case you need to provide
13
+ * an explicit mapping of the value by implementing either the `itemRendered` function or
14
+ * the column-specific `renderItem` function.
15
+ */
6
16
  key: string;
17
+ /**
18
+ * The label of the column that will be shown on the column header.
19
+ */
7
20
  label: ReactNode;
21
+ /**
22
+ * Sets a width for this column. Accepts the same values as the ones specified for
23
+ * individual [grid-template-columns](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns).
24
+ * <br>
25
+ * For example, using `minmax` pairs (e.g. `minmax(200px, 400px)`), a combinations of
26
+ * fraction values (`1fr`/`2fr`/etc), or fixed values such as `200px`.
27
+ * By default, the column grows according to the content and respecting the total table available width.
28
+ */
8
29
  width?: string;
30
+ /**
31
+ * Use this to override the table's own `horizontalCellAlignment` prop for this specific column.
32
+ */
9
33
  align?: 'left' | 'center' | 'right';
34
+ /**
35
+ * A callback function, called when the header cell is clicked.
36
+ */
10
37
  onClick?: (event: MouseEventHandler) => void;
38
+ /**
39
+ * A callback function to render the content of cells under this column, overriding
40
+ * the default `itemRenderer` prop of the table.
41
+ */
11
42
  renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;
43
+ /**
44
+ * Use this prop to place an `Icon` or `IconButton` on the left of the column label.
45
+ * It is advised to place these types of components through this prop instead of `label`,
46
+ * in order to properly position and align the elements.
47
+ * This is particularly useful for medium-sized icons which require more vertical space than the typography.
48
+ */
12
49
  headerIcon?: ReactNode;
50
+ /**
51
+ * Set this to `true` to allow text content of this cell to be truncated with an ellipsis,
52
+ * instead of breaking into multiple lines.
53
+ * <br>
54
+ * NOTE: when using this option, it is recommended to specify a `width` for the column, because
55
+ * if the table doesn't have enough space for all columns, it will start clipping the columns
56
+ * with _truncated_ content, and if no `width` is set (or the value is set `auto` -- the default)
57
+ * it can shrink until the column disappears completely.
58
+ * By enforcing a minimum width for these columns, the table will respect them and grow horizontally,
59
+ * adding scrollbars if needed.
60
+ */
13
61
  isTruncated?: boolean;
62
+ /**
63
+ * Set this to `true` to show a sorting button, which calls `onSortChange` upon being clicked.
64
+ * You should enable this flag for every column you want to be able to sort.
65
+ * When at least one column is sortable, the table props `sortBy`, `sortDirection` and `onSortChange` should be provided.
66
+ */
14
67
  isSortable?: boolean;
68
+ /**
69
+ * Set this to `true` to prevent this column from being manually resized by dragging
70
+ * the edge of the header with a mouse.
71
+ */
15
72
  disableResizing?: boolean;
73
+ /**
74
+ * Set this to `true` to prevent click event propagation for this cell.
75
+ * You might want this if you need the column to have its own call-to-action or input while
76
+ * the row also has a defined `onRowClick`.
77
+ */
16
78
  shouldIgnoreRowClick?: boolean;
17
79
  };
18
80
  export type TDataTableProps<Row extends TRow = TRow> = {
81
+ /**
82
+ * The list of data that needs to be rendered in the table. Each object in the list can
83
+ * have any shape as long as it has a unique identifier.
84
+ * The data is rendered by using the callback render function `itemRenderer`.
85
+ */
19
86
  rows: Row[];
87
+ /**
88
+ * Each object requires a unique `key` which should correspond to property key of
89
+ * the items of `rows` that you want to render under this column, and a `label`
90
+ * which defines the name shown on the header.
91
+ * The list of columns to be rendered.
92
+ * Each column can be customized (see properties below).
93
+ */
20
94
  columns: TColumn<Row>[];
95
+ /**
96
+ * The columns of the nested items to be rendered in the table. Just like the columns, Each object requires a unique `key` which should correspond to property key of
97
+ * the items of `rows` that you want to render under this column, and a `label`
98
+ * which defines the name shown on the header.
99
+ * The list of columns to be rendered.
100
+ */
101
+ customColumns?: TColumn<Row>[];
102
+ /**
103
+ * Element to render within the `tfoot` (footer) element of the table.
104
+ */
21
105
  footer?: ReactNode;
106
+ /**
107
+ * The max width (a number of pixels or a css value string with units) for which the table
108
+ * is allowed to grow. If unset, the table will grow horizontally to fill its parent.
109
+ */
22
110
  maxWidth?: number | string;
111
+ /**
112
+ * The max height (a number of pixels or a css value string with units) for which the table
113
+ * is allowed to grow. If unset, the table will grow vertically to fill its parent and we are able to have a sticky header.
114
+ */
23
115
  maxHeight?: number | string;
116
+ /**
117
+ * A callback function, called when a user clicks on a row.
118
+ */
24
119
  onRowClick?: (row: Row, rowIndex: number, columnKey: string) => void;
120
+ /**
121
+ * Set this to `true` to reduce the paddings of all cells, allowing the table to display
122
+ * more data in less space.
123
+ */
25
124
  isCondensed?: boolean;
125
+ /**
126
+ * A callback function, called when a column has been resized.
127
+ * Use this callback to get the resized column widths and save them, to be able to restore the
128
+ * value once the user comes back to the page.
129
+ */
26
130
  onColumnResized?: (args: TColumn<Row>[]) => void;
131
+ /**
132
+ * Set this to `true` to take control of the containment of the table and doing it on a parent element.
133
+ * This means that the table will grow in size without adding scrollbars on itself,
134
+ * both vertically and horizontally and, as a consequence, the `maxHeight` and `maxWidth` props are ignored.
135
+ * If you need to enforce these constraints, you must also apply them on the parent element.
136
+ * Additionally, the sticky behaviour of the header will get fixed relatively to the closest
137
+ * parent element with `position: relative`.
138
+ */
27
139
  disableSelfContainment?: boolean;
140
+ /**
141
+ * Set this to `true` to prevent the header from being sticky.
142
+ * The header can be sticky only if the table does not have a `maxHeight` set.
143
+ */
28
144
  disableHeaderStickiness?: boolean;
145
+ /**
146
+ * The default function used to render the content of each item in a cell.
147
+ * In case a column has its own `renderItem` render function, it will take precedence over this function.
148
+ */
29
149
  itemRenderer: (item: Row, column: TColumn<Row>, isRowCollapsed: boolean) => ReactNode;
150
+ /**
151
+ * Set this to `false` to ensure that every column can render their label in one line.
152
+ * By default the header cell grows in height in case the label does not fit in one line.
153
+ */
30
154
  wrapHeaderLabels?: boolean;
155
+ /**
156
+ * The default cell vertical alignment of each row (not the table header).
157
+ */
31
158
  verticalCellAlignment?: 'top' | 'center' | 'bottom';
159
+ /**
160
+ * The default cell horizontal alignment.
161
+ * In case a column has its own `align` property, it will take precedence over this value.
162
+ */
32
163
  horizontalCellAlignment?: 'left' | 'center' | 'right';
164
+ /**
165
+ * The key of the column for which the data is currently sorted by.
166
+ */
33
167
  sortedBy?: string;
168
+ /**
169
+ * A callback function, called when a sortable column's header is clicked.
170
+ * It's required when the `isSortable` flag is set on at least one column.
171
+ */
34
172
  onSortChange?: (columnKey: string, sortDirection: 'asc' | 'desc') => void;
173
+ /**
174
+ * The sorting direction.
175
+ */
35
176
  sortDirection?: 'desc' | 'asc';
177
+ /**
178
+ * Custom row renderer for nested rows.
179
+ */
180
+ renderNestedRow?: (row: Row) => ReactNode;
181
+ /**
182
+ * If this is provided, then it should control the height of the expanded rows. In the event where there is more content than the maxHeight,
183
+ * a scrollbar should make provision for the overflow.
184
+ */
185
+ maxExpandableHeight?: number;
36
186
  };
37
187
  declare const DataTable: {
38
188
  <Row extends TRow = TRow>(props: TDataTableProps<Row>): import("@emotion/react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/data-table",
3
3
  "description": "A component for rendering tabular data.",
4
- "version": "19.9.0",
4
+ "version": "19.10.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,13 +21,13 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.20.13",
23
23
  "@babel/runtime-corejs3": "^7.20.13",
24
- "@commercetools-uikit/accessible-button": "19.9.0",
25
- "@commercetools-uikit/data-table-manager": "19.9.0",
26
- "@commercetools-uikit/design-system": "19.9.0",
27
- "@commercetools-uikit/hooks": "19.9.0",
28
- "@commercetools-uikit/icons": "19.9.0",
29
- "@commercetools-uikit/secondary-icon-button": "19.9.0",
30
- "@commercetools-uikit/utils": "19.9.0",
24
+ "@commercetools-uikit/accessible-button": "19.10.0",
25
+ "@commercetools-uikit/data-table-manager": "19.10.0",
26
+ "@commercetools-uikit/design-system": "19.10.0",
27
+ "@commercetools-uikit/hooks": "19.10.0",
28
+ "@commercetools-uikit/icons": "19.10.0",
29
+ "@commercetools-uikit/secondary-icon-button": "19.10.0",
30
+ "@commercetools-uikit/utils": "19.10.0",
31
31
  "@emotion/react": "^11.10.5",
32
32
  "@emotion/styled": "^11.10.5",
33
33
  "lodash": "4.17.21",