Skip to content

Commit c2d2d7a

Browse files
committed
docs(AnalyticalTable): restructure stories and improve docs
1 parent 89f550a commit c2d2d7a

5 files changed

Lines changed: 304 additions & 422 deletions

File tree

.storybook/components/VersionSwitch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ addons.register(ADDON_ID, () => {
6363
onClick={() => {
6464
setOpen(true);
6565
}}
66+
ariaLabel={false}
6667
>
6768
Version: {activeVersion}
6869
</IconButton>

packages/main/src/components/AnalyticalTable/docs/AnalyticalTable.mdx

Lines changed: 15 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,23 @@ const InfiniteScrollTable = (props) => {
182182

183183
</details>
184184

185-
## Adjust the number of rows to the container height
185+
## Auto Row Count
186186

187-
By adding the `visibleRowCountMode` prop and setting it to `AnalyticalTableVisibleRowCountMode.Auto` the table automatically fills the surrounding container with rows and when setting it to `AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows`, empty rows fill the container as well, if not enough visible rows are available.
187+
Set `visibleRowCountMode` to `AnalyticalTableVisibleRowCountMode.Auto` or `AutoWithEmptyRows` to let the table automatically fill its container with rows.
188+
189+
**Prerequisites:**
190+
191+
- The table **must** be placed inside a container with a **defined height** (e.g. `height: 500px`, `flex: 1`, or a CSS Grid row). Without a constrained parent, the table cannot determine how many rows to render.
192+
- `AutoWithEmptyRows` fills remaining space with empty rows when there aren't enough data rows to fill the container.
193+
- `Auto` may lead to inconsistent table heights depending on the container — prefer `AutoWithEmptyRows` for a stable layout.
188194

189195
<ControlsWithNote
190-
of={ComponentStories.DynamicRowCount}
196+
of={ComponentStories.AutoRowCount}
191197
include={['containerHeight', 'visibleRowCountMode']}
192198
hideHTMLPropsNote
193199
/>
194200

195-
<Canvas sourceState="none" of={ComponentStories.DynamicRowCount} />
201+
<Canvas sourceState="none" of={ComponentStories.AutoRowCount} />
196202

197203
### Code
198204

@@ -212,10 +218,10 @@ const TableComponent = (props) => {
212218
};
213219
```
214220

215-
## Responsively display columns on small devices (Pop-In)
221+
## Responsive Columns (Pop-In)
216222

217223
<ControlsWithNote
218-
of={ComponentStories.ResponsiveColumns}
224+
of={ComponentStories.ResponsiveColumnsPopIn}
219225
hideHTMLPropsNote
220226
include={['adjustTableHeightOnPopIn', 'containerWidth']}
221227
/>
@@ -233,7 +239,7 @@ In the example below you can have a look at this behavior:
233239
- `600`: The content of the "Age" column is moved to the first column (`responsiveMinWidth: 601`) and receives a custom header.
234240
- `400`: The content of the "Friend Name" column is moved to the first column and the "Friend Age" column is hidden (`responsiveMinWidth: 401`). The "Friend Name" column also receives a custom header.
235241

236-
<Canvas sourceState="none" of={ComponentStories.ResponsiveColumns} />
242+
<Canvas sourceState="none" of={ComponentStories.ResponsiveColumnsPopIn} />
237243

238244
### Columns Config
239245

@@ -328,121 +334,12 @@ const COLUMNS = [
328334
];
329335
```
330336

331-
## Display indicator for navigated rows
332-
333-
To display show the navigation column you need to set `withNavigationHighlight` to `true` and to mark a row as "navigated" the `markNavigatedRow` prop is required.
334-
With the `markNavigatedRow` callback it is possible to define when and how many navigation indicators should be shown.
335-
336-
Click on any of the rows in the example below to display the "navigated" indicator in the navigation-column.
337-
338-
<Canvas sourceState="none" of={ComponentStories.NavigationIndicator} />
339-
340-
### Code
341-
342-
```jsx
343-
export const TableWithNavigationIndicators = () => {
344-
const [selectedRow, setSelectedRow] = useState();
345-
const onRowSelect = (e) => {
346-
setSelectedRow(e.detail.row);
347-
};
348-
const markNavigatedRow = useCallback(
349-
(row) => {
350-
return selectedRow?.id === row.id;
351-
},
352-
[selectedRow]
353-
);
354-
return (
355-
<AnalyticalTable
356-
data={data}
357-
columns={columns}
358-
withNavigationHighlight
359-
selectionMode={AnalyticalTableSelectionMode.Multiple}
360-
markNavigatedRow={markNavigatedRow}
361-
onRowSelect={onRowSelect}
362-
/>
363-
);
364-
};
365-
```
366-
367-
## Custom column filtering
368-
369-
It is possible to define your own filter function and filter component on each column. For this you need to customize the column option `filter` or add a custom filter type to the `reactTableOptions.filterTypes` object (for a custom filter function) and the column option `Filter` (for a custom filter component).
370-
371-
Here you can find an example using a `MultiComboBox` with multiple values as filter.
372-
373-
<Canvas sourceState="none" of={ComponentStories.CustomFilter} />
374-
375-
### Code
376-
377-
<details>
378-
379-
<summary>Show static code</summary>
380-
381-
```jsx
382-
const filterFn = (rows, accessor, filterValue) => {
383-
if (filterValue.length > 0) {
384-
return rows.filter((row) => {
385-
const rowVal = row.values[accessor];
386-
if (filterValue.some((item) => rowVal.includes(item))) {
387-
return true;
388-
}
389-
return false;
390-
});
391-
}
392-
return rows;
393-
};
394-
const COLUMNS = [
395-
{
396-
Header: 'Name',
397-
accessor: 'name',
398-
// either define your filter function here or set is as `reactTableOption` and pass the key as string here (see below)
399-
filter: filterFn,
400-
Filter: ({ column }) => {
401-
const firstNames = ['Carl', 'Dan', 'Rose', 'Susanne'];
402-
return (
403-
<MultiComboBox
404-
onSelectionChange={(e) => {
405-
column.setFilter(e.detail.items.map((item) => item.getAttribute('text')));
406-
}}
407-
>
408-
{firstNames.map((item) => {
409-
const isSelected = column?.filterValue?.some((filterVal) => filterVal.includes(item));
410-
return <MultiComboBoxItem text={item} key={item} selected={isSelected} />;
411-
})}
412-
</MultiComboBox>
413-
);
414-
}
415-
},
416-
{
417-
Header: 'Age',
418-
accessor: 'age'
419-
}
420-
];
421-
const TableComponent = () => {
422-
return (
423-
<ThemeProvider>
424-
<AnalyticalTable
425-
columns={COLUMNS}
426-
data={DATA}
427-
filterable
428-
// you can also define your function here, then you can just pass the key as string to the `filter` column option
429-
// reactTableOptions={{
430-
// filterTypes: {
431-
// multiValueFilter: filterFn
432-
// }
433-
// }}
434-
/>
435-
</ThemeProvider>
436-
);
437-
};
438-
```
439-
440-
</details>
441-
442337
## Table Without Data
443338

444339
Use the `NoDataComponent` prop to customize the empty state. By default, a simple text message is shown. You can pass a custom component (e.g. an `IllustratedMessage`) to display a richer empty state for different scenarios like "no data" vs. "no filter results". The component receives an `accessibleRole` prop that should be forwarded for accessibility.
445340

341+
**Note:** When using an `IllustratedMessage` as `NoDataComponent`, the table must have sufficient height for the illustration to render properly. With `visibleRowCountMode` set to `Auto` or `AutoWithEmptyRows`, the table container needs a minimum height of approximately `300px`. With the default `Fixed` mode, ensure `visibleRows` provides enough vertical space (typically 5+ rows).
342+
446343
<Canvas of={ComponentStories.NoData} />
447344

448345
### Code
@@ -506,90 +403,6 @@ function NoDataTable(props) {
506403

507404
</details>
508405

509-
## AnalyticalTable with subcomponents
510-
511-
Adding custom subcomponents below table rows can be achieved by setting the `renderRowSubComponent` prop.
512-
The prop expects a function with an optional parameter containing the `row` instance, there you can control which row should display subcomponents. Use the `subComponentsBehavior` control below to switch between `"Expandable"` (default, click to expand), `"Visible"` (always shown), `"IncludeHeight"` (always shown, height included in body calculation), and `"IncludeHeightExpandable"` (expandable, body height adjusts on toggle).
513-
514-
**Notes:**
515-
516-
- When `renderRowSubComponent` is set, `grouping` is disabled.
517-
- When rendering active elements inside the subcomponent, make sure to add the `data-subcomponent-active-element` attribute, otherwise focus behavior won't be consistent.
518-
- When `AnalyticalTableSubComponentsBehavior.IncludeHeight` or `AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable` is used, `AnalyticalTableVisibleRowCountMode.Interactive` is not supported.
519-
520-
<ControlsWithNote of={ComponentStories.Subcomponents} include={['renderRowSubComponent', 'subComponentsBehavior']} />
521-
522-
<Canvas sourceState="none" of={ComponentStories.Subcomponents} />
523-
524-
### Code
525-
526-
<details>
527-
528-
<summary>Show Code</summary>
529-
530-
```jsx
531-
const TableWithSubcomponents = (props) => {
532-
const renderRowSubComponent = (row) => {
533-
if (row.id === '0') {
534-
return (
535-
<FlexBox
536-
style={{ backgroundColor: 'lightblue', height: '300px' }}
537-
justifyContent={FlexBoxJustifyContent.Center}
538-
alignItems={FlexBoxAlignItems.Center}
539-
direction={FlexBoxDirection.Column}
540-
>
541-
<Tag>height: 300px</Tag>
542-
<Text>This subcomponent will only be displayed below the first row.</Text>
543-
<hr />
544-
<Text>
545-
The button below is rendered with `data-subcomponent-active-element` attribute to ensure consistent focus
546-
behavior
547-
</Text>
548-
<Button data-subcomponent-active-element>Click</Button>
549-
</FlexBox>
550-
);
551-
}
552-
if (row.id === '1') {
553-
return (
554-
<FlexBox
555-
style={{ backgroundColor: 'lightyellow', height: '100px' }}
556-
justifyContent={FlexBoxJustifyContent.Center}
557-
alignItems={FlexBoxAlignItems.Center}
558-
direction={FlexBoxDirection.Column}
559-
>
560-
<Tag>height: 100px</Tag>
561-
<Text>This subcomponent will only be displayed below the second row.</Text>
562-
</FlexBox>
563-
);
564-
}
565-
if (row.id === '2') {
566-
return null;
567-
}
568-
return (
569-
<FlexBox
570-
style={{ backgroundColor: 'lightgrey', height: '50px' }}
571-
justifyContent={FlexBoxJustifyContent.Center}
572-
alignItems={FlexBoxAlignItems.Center}
573-
direction={FlexBoxDirection.Column}
574-
>
575-
<Tag>height: 50px</Tag>
576-
<Text>This subcomponent will be displayed below all rows except the first, second and third.</Text>
577-
</FlexBox>
578-
);
579-
};
580-
return (
581-
<AnalyticalTable
582-
data={props.data}
583-
columns={props.columns}
584-
renderRowSubComponent={renderRowSubComponent}
585-
subComponentsBehavior={subComponentsBehavior} // "Expandable" (default), "Visible", "IncludeHeight", "IncludeHeightExpandable"
586-
/>
587-
);
588-
};
589-
```
590-
591-
</details>
592-
593406
## Kitchen Sink
594407

595408
A comprehensive example combining many AnalyticalTable features: sorting, filtering, grouping, custom cells, row and navigation highlighting, infinite scrolling, column reordering, vertical alignment, `scaleWidthModeOptions` for custom renderers, `retainColumnWidth`, `sortDescFirst`, and more.

0 commit comments

Comments
 (0)