@commercetools-uikit/data-table 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,275 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # DataTable
5
+
6
+ ## Description
7
+
8
+ Shows tabular data, defined by a list of items: the `rows`, and another list with their corresponding definitions: the `columns`. Both these lists are arrays of objects.
9
+
10
+ - The `rows` list defines the items you want to render, where each item only requires a unique `id` which is used for mapping, and the remaining properties to be shown under each column.
11
+ - On the `columns` list, 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 of the column.
12
+
13
+ These are the only requirements for rendering the most simple table which should suffice for most use cases and is scaled automatically for the available space.
14
+
15
+ For more advanced configuration and layout customization, a plethora of other options are available, including <i>per-column</i> specific options.
16
+
17
+ For adding a Row Selection behavior, check the `useRowSelection` hook which you can use to prepare your `rows` and `columns` before passing them to the DataTable component.
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ yarn add @commercetools-uikit/data-table
23
+ ```
24
+
25
+ ```
26
+ npm --save install @commercetools-uikit/data-table
27
+ ```
28
+
29
+ Additionally install the peer dependencies (if not present)
30
+
31
+ ```
32
+ yarn add react
33
+ ```
34
+
35
+ ```
36
+ npm --save install react
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```jsx
42
+ import DataTable from '@commercetools-uikit/data-table';
43
+
44
+ const rows = [
45
+ { id: 'parasite', title: 'Parasite', country: 'South Korea' },
46
+ { id: 'portrait', title: 'Portrait of a Lady on Fire', country: 'France' },
47
+ { id: 'wat', title: 'Woman at War', country: 'Iceland' },
48
+ ];
49
+
50
+ const columns = [
51
+ { key: 'title', label: 'Title' },
52
+ { key: 'country', label: 'Country' },
53
+ ];
54
+
55
+ const Example = () => <DataTable rows={rows} columns={columns} />;
56
+
57
+ export default Example;
58
+ ```
59
+
60
+ ## Properties
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&#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) | | `[]` | The list of columns to be rendered.&#xA;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. |
66
+ | `customColumns` | `Array: TColumn<Row>[]`<br/>[See signature.](#signature-customcolumns) | | | The list of columns to be rendered.&#xA;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. |
67
+ | `footer` | `ReactNode` | | | Element to render within the `tfoot` (footer) element of the table. |
68
+ | `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. |
69
+ | `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. |
70
+ | `onRowClick` | `Function`<br/>[See signature.](#signature-onrowclick) | | | A callback function, called when a user clicks on a row. |
71
+ | `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. |
72
+ | `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. |
73
+ | `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`. |
74
+ | `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. |
75
+ | `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. |
76
+ | `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. |
77
+ | `verticalCellAlignment` | `union`<br/>Possible values:<br/>`'top' , 'center' , 'bottom'` | | `'top'` | The default cell vertical alignment of each row (not the table header). |
78
+ | `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. |
79
+ | `sortedBy` | `string` | | | The key of the column for which the data is currently sorted by. |
80
+ | `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. |
81
+ | `sortDirection` | `union`<br/>Possible values:<br/>`'desc' , 'asc'` | | | The sorting direction. |
82
+ | `renderNestedRow` | `Function`<br/>[See signature.](#signature-rendernestedrow) | | | Custom row renderer for nested rows. |
83
+ | `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
+
85
+ ## Signatures
86
+
87
+ ### Signature `columns`
88
+
89
+ ```ts
90
+ {
91
+ /**
92
+ * The unique key of the column that is used to identify your data type.
93
+ * You can use this value to determine which value from a row item should be rendered.
94
+ * <br>
95
+ * For example, if the data is a list of users, where each user has a `firstName` property,
96
+ * the column key should be `firstName`, which renders the correct value by default.
97
+ * The key can also be some custom or computed value, in which case you need to provide
98
+ * an explicit mapping of the value by implementing either the `itemRendered` function or
99
+ * the column-specific `renderItem` function.
100
+ */
101
+ key: string;
102
+ /**
103
+ * The label of the column that will be shown on the column header.
104
+ */
105
+ label: ReactNode;
106
+ /**
107
+ * Sets a width for this column. Accepts the same values as the ones specified for
108
+ * individual [grid-template-columns](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns).
109
+ * <br>
110
+ * For example, using `minmax` pairs (e.g. `minmax(200px, 400px)`), a combinations of
111
+ * fraction values (`1fr`/`2fr`/etc), or fixed values such as `200px`.
112
+ * By default, the column grows according to the content and respecting the total table available width.
113
+ */
114
+ width?: string;
115
+ /**
116
+ * Use this to override the table's own `horizontalCellAlignment` prop for this specific column.
117
+ */
118
+ align?: 'left' | 'center' | 'right';
119
+ /**
120
+ * A callback function, called when the header cell is clicked.
121
+ */
122
+ onClick?: (event: MouseEventHandler) => void;
123
+ /**
124
+ * A callback function to render the content of cells under this column, overriding
125
+ * the default `itemRenderer` prop of the table.
126
+ */
127
+ renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;
128
+ /**
129
+ * Use this prop to place an `Icon` or `IconButton` on the left of the column label.
130
+ * It is advised to place these types of components through this prop instead of `label`,
131
+ * in order to properly position and align the elements.
132
+ * This is particularly useful for medium-sized icons which require more vertical space than the typography.
133
+ */
134
+ headerIcon?: ReactNode;
135
+ /**
136
+ * Set this to `true` to allow text content of this cell to be truncated with an ellipsis,
137
+ * instead of breaking into multiple lines.
138
+ * <br>
139
+ * NOTE: when using this option, it is recommended to specify a `width` for the column, because
140
+ * if the table doesn't have enough space for all columns, it will start clipping the columns
141
+ * with _truncated_ content, and if no `width` is set (or the value is set `auto` -- the default)
142
+ * it can shrink until the column disappears completely.
143
+ * By enforcing a minimum width for these columns, the table will respect them and grow horizontally,
144
+ * adding scrollbars if needed.
145
+ */
146
+ isTruncated?: boolean;
147
+ /**
148
+ * Set this to `true` to show a sorting button, which calls `onSortChange` upon being clicked.
149
+ * You should enable this flag for every column you want to be able to sort.
150
+ * When at least one column is sortable, the table props `sortBy`, `sortDirection` and `onSortChange` should be provided.
151
+ */
152
+ isSortable?: boolean;
153
+ /**
154
+ * Set this to `true` to prevent this column from being manually resized by dragging
155
+ * the edge of the header with a mouse.
156
+ */
157
+ disableResizing?: boolean;
158
+ /**
159
+ * Set this to `true` to prevent click event propagation for this cell.
160
+ * You might want this if you need the column to have its own call-to-action or input while
161
+ * the row also has a defined `onRowClick`.
162
+ */
163
+ shouldIgnoreRowClick?: boolean;
164
+ }
165
+ ```
166
+
167
+ ### Signature `customColumns`
168
+
169
+ ```ts
170
+ {
171
+ /**
172
+ * The unique key of the column that is used to identify your data type.
173
+ * You can use this value to determine which value from a row item should be rendered.
174
+ * <br>
175
+ * For example, if the data is a list of users, where each user has a `firstName` property,
176
+ * the column key should be `firstName`, which renders the correct value by default.
177
+ * The key can also be some custom or computed value, in which case you need to provide
178
+ * an explicit mapping of the value by implementing either the `itemRendered` function or
179
+ * the column-specific `renderItem` function.
180
+ */
181
+ key: string;
182
+ /**
183
+ * The label of the column that will be shown on the column header.
184
+ */
185
+ label: ReactNode;
186
+ /**
187
+ * Sets a width for this column. Accepts the same values as the ones specified for
188
+ * individual [grid-template-columns](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns).
189
+ * <br>
190
+ * For example, using `minmax` pairs (e.g. `minmax(200px, 400px)`), a combinations of
191
+ * fraction values (`1fr`/`2fr`/etc), or fixed values such as `200px`.
192
+ * By default, the column grows according to the content and respecting the total table available width.
193
+ */
194
+ width?: string;
195
+ /**
196
+ * Use this to override the table's own `horizontalCellAlignment` prop for this specific column.
197
+ */
198
+ align?: 'left' | 'center' | 'right';
199
+ /**
200
+ * A callback function, called when the header cell is clicked.
201
+ */
202
+ onClick?: (event: MouseEventHandler) => void;
203
+ /**
204
+ * A callback function to render the content of cells under this column, overriding
205
+ * the default `itemRenderer` prop of the table.
206
+ */
207
+ renderItem?: (row: Row, isRowCollapsed: boolean) => ReactNode;
208
+ /**
209
+ * Use this prop to place an `Icon` or `IconButton` on the left of the column label.
210
+ * It is advised to place these types of components through this prop instead of `label`,
211
+ * in order to properly position and align the elements.
212
+ * This is particularly useful for medium-sized icons which require more vertical space than the typography.
213
+ */
214
+ headerIcon?: ReactNode;
215
+ /**
216
+ * Set this to `true` to allow text content of this cell to be truncated with an ellipsis,
217
+ * instead of breaking into multiple lines.
218
+ * <br>
219
+ * NOTE: when using this option, it is recommended to specify a `width` for the column, because
220
+ * if the table doesn't have enough space for all columns, it will start clipping the columns
221
+ * with _truncated_ content, and if no `width` is set (or the value is set `auto` -- the default)
222
+ * it can shrink until the column disappears completely.
223
+ * By enforcing a minimum width for these columns, the table will respect them and grow horizontally,
224
+ * adding scrollbars if needed.
225
+ */
226
+ isTruncated?: boolean;
227
+ /**
228
+ * Set this to `true` to show a sorting button, which calls `onSortChange` upon being clicked.
229
+ * You should enable this flag for every column you want to be able to sort.
230
+ * When at least one column is sortable, the table props `sortBy`, `sortDirection` and `onSortChange` should be provided.
231
+ */
232
+ isSortable?: boolean;
233
+ /**
234
+ * Set this to `true` to prevent this column from being manually resized by dragging
235
+ * the edge of the header with a mouse.
236
+ */
237
+ disableResizing?: boolean;
238
+ /**
239
+ * Set this to `true` to prevent click event propagation for this cell.
240
+ * You might want this if you need the column to have its own call-to-action or input while
241
+ * the row also has a defined `onRowClick`.
242
+ */
243
+ shouldIgnoreRowClick?: boolean;
244
+ }
245
+ ```
246
+
247
+ ### Signature `onRowClick`
248
+
249
+ ```ts
250
+ (row: Row, rowIndex: number, columnKey: string) => void
251
+ ```
252
+
253
+ ### Signature `onColumnResized`
254
+
255
+ ```ts
256
+ (args: TColumn<Row>[]) => void
257
+ ```
258
+
259
+ ### Signature `itemRenderer`
260
+
261
+ ```ts
262
+ (item: Row, column: TColumn<Row>, isRowCollapsed: boolean) => ReactNode;
263
+ ```
264
+
265
+ ### Signature `onSortChange`
266
+
267
+ ```ts
268
+ (columnKey: string, sortDirection: 'asc' | 'desc') => void
269
+ ```
270
+
271
+ ### Signature `renderNestedRow`
272
+
273
+ ```ts
274
+ (row: Row) => ReactNode;
275
+ ```
@@ -0,0 +1,3 @@
1
+ export * from "./declarations/src/index.js";
2
+ export { default } from "./declarations/src/index.js";
3
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1kYXRhLXRhYmxlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==