@commercetools-uikit/data-table 19.10.0 → 19.12.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
@@ -59,33 +59,129 @@ export default Example;
59
59
 
60
60
  ## Properties
61
61
 
62
- | Props | Type | Required | Default | Description |
63
- | ------------------------- | ---------------------------------------------------------------- | :------: | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
- | `rows` | `Array: Row[]` | ✅ | | The list of data that needs to be rendered in the table. Each object in the list can
have any shape as long as it has a unique identifier.
The data is rendered by using the callback render function `itemRenderer`. |
65
- | `columns` | `Array: TColumn<Row>[]`<br/>[See signature.](#signature-columns) | | `[]` | Each object requires a unique `key` which should correspond to property key of&#xA;the items of `rows` that you want to render under this column, and a `label`&#xA;which defines the name shown on the header.&#xA;The list of columns to be rendered.&#xA;Each column can be customized (see properties below). |
66
- | `footer` | `ReactNode` | | | Element to render within the `tfoot` (footer) element of the table. |
67
- | `maxWidth` | `union`<br/>Possible values:<br/>`number , string` | | | The max width (a number of pixels or a css value string with units) for which the table&#xA;is allowed to grow. If unset, the table will grow horizontally to fill its parent. |
68
- | `maxHeight` | `union`<br/>Possible values:<br/>`number , string` | | | The max height (a number of pixels or a css value string with units) for which the table&#xA;is allowed to grow. If unset, the table will grow vertically to fill its parent and we are able to have a sticky header. |
69
- | `onRowClick` | `Function`<br/>[See signature.](#signature-onRowClick) | | | A callback function, called when a user clicks on a row. |
70
- | `isCondensed` | `boolean` | | `true` | Set this to `true` to reduce the paddings of all cells, allowing the table to display&#xA;more data in less space. |
71
- | `onColumnResized` | `Function`<br/>[See signature.](#signature-onColumnResized) | | | A callback function, called when a column has been resized.&#xA;Use this callback to get the resized column widths and save them, to be able to restore the&#xA;value once the user comes back to the page. |
72
- | `disableSelfContainment` | `boolean` | | `false` | Set this to `true` to take control of the containment of the table and doing it on a parent element.&#xA;This means that the table will grow in size without adding scrollbars on itself,&#xA;both vertically and horizontally and, as a consequence, the `maxHeight` and `maxWidth` props are ignored.&#xA;If you need to enforce these constraints, you must also apply them on the parent element.&#xA;Additionally, the sticky behaviour of the header will get fixed relatively to the closest&#xA;parent element with `position: relative`. |
73
- | `disableHeaderStickiness` | `boolean` | | | Set this to `true` to prevent the header from being sticky.&#xA;The header can be sticky only if the table does not have a `maxHeight` set. |
74
- | `itemRenderer` | `Function`<br/>[See signature.](#signature-itemRenderer) | | `(row, column) => row[column.key]` | The default function used to render the content of each item in a cell.&#xA;In case a column has its own `renderItem` render function, it will take precedence over this function. |
75
- | `wrapHeaderLabels` | `boolean` | | `true` | Set this to `false` to ensure that every column can render their label in one line.&#xA;By default the header cell grows in height in case the label does not fit in one line. |
76
- | `verticalCellAlignment` | `union`<br/>Possible values:<br/>`'top' , 'center' , 'bottom'` | | `'top'` | The default cell vertical alignment of each row (not the table header). |
77
- | `horizontalCellAlignment` | `union`<br/>Possible values:<br/>`'left' , 'center' , 'right'` | | `'left'` | The default cell horizontal alignment.&#xA;In case a column has its own `align` property, it will take precedence over this value. |
78
- | `sortedBy` | `string` | | | The key of the column for which the data is currently sorted by. |
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
- | `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. |
62
+ | Props | Type | Required | Default | Description |
63
+ | --------- | ---------------------------------------------------------------- | :------: | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
64
+ | `rows` | `Array: Row[]` | ✅ | | The list of data that needs to be rendered in the table. Each object in the list can&#xA;have any shape as long as it has a unique identifier.&#xA;The data is rendered by using the callback render function `itemRenderer`. |
65
+ | `columns` | `Array: TColumn<Row>[]`<br/>[See signature.](#signature-columns) | | `[]` | Each object requires a unique `key` which should correspond to property key of&#xA;the items of `rows` that you want to render under this column, and a `label`&#xA;which defines the name shown on the header.&#xA;The list of columns to be rendered.Column item shape:``` |
66
+
67
+ {
68
+ key: string;
69
+ label: ReactNode;
70
+ width?: string;
71
+ align?: 'left' | 'center' | 'right';
72
+ onClick?: (event: MouseEventHandler) => void;
73
+ renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;
74
+ headerIcon?: ReactNode;
75
+ isTruncated?: boolean;
76
+ isSortable?: boolean;
77
+ disableResizing?: boolean;
78
+ shouldIgnoreRowClick?: boolean;
79
+ }
80
+
81
+ ````[Colum signatures with description](/?path=/docs/components-datatable-readme--props#signatures) |
82
+ | `customColumns` | `Array: TColumn<Row>[]`<br/>[See signature.](#signature-customColumns) | | | 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&#xA;the items of `rows` that you want to render under this column, and a `label`&#xA;which defines the name shown on the header.&#xA;The list of columns to be rendered. |
83
+ | `footer` | `ReactNode` | | | Element to render within the `tfoot` (footer) element of the table. |
84
+ | `maxWidth` | `union`<br/>Possible values:<br/>`number , string` | | | The max width (a number of pixels or a css value string with units) for which the table&#xA;is allowed to grow. If unset, the table will grow horizontally to fill its parent. |
85
+ | `maxHeight` | `union`<br/>Possible values:<br/>`number , string` | | | The max height (a number of pixels or a css value string with units) for which the table&#xA;is allowed to grow. If unset, the table will grow vertically to fill its parent and we are able to have a sticky header. |
86
+ | `onRowClick` | `Function`<br/>[See signature.](#signature-onRowClick) | | | A callback function, called when a user clicks on a row. |
87
+ | `isCondensed` | `boolean` | | `true` | Set this to `true` to reduce the paddings of all cells, allowing the table to display&#xA;more data in less space. |
88
+ | `onColumnResized` | `Function`<br/>[See signature.](#signature-onColumnResized) | | | A callback function, called when a column has been resized.&#xA;Use this callback to get the resized column widths and save them, to be able to restore the&#xA;value once the user comes back to the page. |
89
+ | `disableSelfContainment` | `boolean` | | `false` | Set this to `true` to take control of the containment of the table and doing it on a parent element.&#xA;This means that the table will grow in size without adding scrollbars on itself,&#xA;both vertically and horizontally and, as a consequence, the `maxHeight` and `maxWidth` props are ignored.&#xA;If you need to enforce these constraints, you must also apply them on the parent element.&#xA;Additionally, the sticky behaviour of the header will get fixed relatively to the closest&#xA;parent element with `position: relative`. |
90
+ | `disableHeaderStickiness` | `boolean` | | | Set this to `true` to prevent the header from being sticky.&#xA;The header can be sticky only if the table does not have a `maxHeight` set. |
91
+ | `itemRenderer` | `Function`<br/>[See signature.](#signature-itemRenderer) | | `(row, column) => row[column.key]` | The default function used to render the content of each item in a cell.&#xA;In case a column has its own `renderItem` render function, it will take precedence over this function. |
92
+ | `wrapHeaderLabels` | `boolean` | | `true` | Set this to `false` to ensure that every column can render their label in one line.&#xA;By default the header cell grows in height in case the label does not fit in one line. |
93
+ | `verticalCellAlignment` | `union`<br/>Possible values:<br/>`'top' , 'center' , 'bottom'` | | `'top'` | The default cell vertical alignment of each row (not the table header). |
94
+ | `horizontalCellAlignment` | `union`<br/>Possible values:<br/>`'left' , 'center' , 'right'` | | `'left'` | The default cell horizontal alignment.&#xA;In case a column has its own `align` property, it will take precedence over this value. |
95
+ | `sortedBy` | `string` | | | The key of the column for which the data is currently sorted by. |
96
+ | `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. |
97
+ | `sortDirection` | `union`<br/>Possible values:<br/>`'desc' , 'asc'` | | | The sorting direction. |
98
+ | `renderNestedRow` | `Function`<br/>[See signature.](#signature-renderNestedRow) | | | Custom row renderer for nested rows. |
99
+ | `maxExpandableHeight` | `number` | | | 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,&#xA;a scrollbar should make provision for the overflow. |
84
100
 
85
101
  ## Signatures
86
102
 
87
103
  ### Signature `columns`
88
104
 
105
+ ```ts
106
+ {
107
+ /**
108
+ * The unique key of the column that is used to identify your data type.
109
+ * You can use this value to determine which value from a row item should be rendered.
110
+ * <br>
111
+ * For example, if the data is a list of users, where each user has a `firstName` property,
112
+ * the column key should be `firstName`, which renders the correct value by default.
113
+ * The key can also be some custom or computed value, in which case you need to provide
114
+ * an explicit mapping of the value by implementing either the `itemRendered` function or
115
+ * the column-specific `renderItem` function.
116
+ */
117
+ key: string;
118
+ /**
119
+ * The label of the column that will be shown on the column header.
120
+ */
121
+ label: ReactNode;
122
+ /**
123
+ * Sets a width for this column. Accepts the same values as the ones specified for
124
+ * individual [grid-template-columns](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns).
125
+ * <br>
126
+ * For example, using `minmax` pairs (e.g. `minmax(200px, 400px)`), a combinations of
127
+ * fraction values (`1fr`/`2fr`/etc), or fixed values such as `200px`.
128
+ * By default, the column grows according to the content and respecting the total table available width.
129
+ */
130
+ width?: string;
131
+ /**
132
+ * Use this to override the table's own `horizontalCellAlignment` prop for this specific column.
133
+ */
134
+ align?: 'left' | 'center' | 'right';
135
+ /**
136
+ * A callback function, called when the header cell is clicked.
137
+ */
138
+ onClick?: (event: MouseEventHandler) => void;
139
+ /**
140
+ * A callback function to render the content of cells under this column, overriding
141
+ * the default `itemRenderer` prop of the table.
142
+ */
143
+ renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;
144
+ /**
145
+ * Use this prop to place an `Icon` or `IconButton` on the left of the column label.
146
+ * It is advised to place these types of components through this prop instead of `label`,
147
+ * in order to properly position and align the elements.
148
+ * This is particularly useful for medium-sized icons which require more vertical space than the typography.
149
+ */
150
+ headerIcon?: ReactNode;
151
+ /**
152
+ * Set this to `true` to allow text content of this cell to be truncated with an ellipsis,
153
+ * instead of breaking into multiple lines.
154
+ * <br>
155
+ * NOTE: when using this option, it is recommended to specify a `width` for the column, because
156
+ * if the table doesn't have enough space for all columns, it will start clipping the columns
157
+ * with _truncated_ content, and if no `width` is set (or the value is set `auto` -- the default)
158
+ * it can shrink until the column disappears completely.
159
+ * By enforcing a minimum width for these columns, the table will respect them and grow horizontally,
160
+ * adding scrollbars if needed.
161
+ */
162
+ isTruncated?: boolean;
163
+ /**
164
+ * Set this to `true` to show a sorting button, which calls `onSortChange` upon being clicked.
165
+ * You should enable this flag for every column you want to be able to sort.
166
+ * When at least one column is sortable, the table props `sortBy`, `sortDirection` and `onSortChange` should be provided.
167
+ */
168
+ isSortable?: boolean;
169
+ /**
170
+ * Set this to `true` to prevent this column from being manually resized by dragging
171
+ * the edge of the header with a mouse.
172
+ */
173
+ disableResizing?: boolean;
174
+ /**
175
+ * Set this to `true` to prevent click event propagation for this cell.
176
+ * You might want this if you need the column to have its own call-to-action or input while
177
+ * the row also has a defined `onRowClick`.
178
+ */
179
+ shouldIgnoreRowClick?: boolean;
180
+ }
181
+ ````
182
+
183
+ ### Signature `customColumns`
184
+
89
185
  ```ts
90
186
  {
91
187
  /**
@@ -187,3 +283,9 @@ export default Example;
187
283
  ```ts
188
284
  (columnKey: string, sortDirection: 'asc' | 'desc') => void
189
285
  ```
286
+
287
+ ### Signature `renderNestedRow`
288
+
289
+ ```ts
290
+ (row: Row) => ReactNode;
291
+ ```