Skip to content

Commit c485e50

Browse files
committed
docs(AnalyticalTable): add feature examples subfolder
1 parent 911cd15 commit c485e50

5 files changed

Lines changed: 2408 additions & 158 deletions

File tree

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

Lines changed: 111 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const TableComp = () => {
9999

100100
## Tree Table
101101

102+
Set `isTreeTable` to `true` and provide nested data via the `subRows` key (configurable with `subRowsKey`). Each row with `subRows` becomes expandable.
103+
102104
<Canvas of={ComponentStories.TreeTable} sourceState={'none'} />
103105

104106
The `data` structure of the tree table is as follows:
@@ -136,7 +138,7 @@ In this example the default key for sub row detection is used (`subRows`), you c
136138

137139
The table initially contains 50 rows, when the last 10 rows are reached the table will load more data.
138140

139-
**Note:** To prevent the table state from resetting when the data is updated, please see [this recipe](?path=/docs/data-display-analyticaltable-recipes--docs#how-to-stop-the-table-state-from-automatically-resetting-when-the-data-changes).
141+
**Note:** To prevent the table state from resetting when the data is updated, please see [this faq entry](?path=/docs/data-display-analyticaltable-faq--docs#how-to-stop-the-table-state-from-automatically-resetting-when-the-data-changes).
140142

141143
<Canvas sourceState="none" of={ComponentStories.InfiniteScrolling} />
142144

@@ -172,91 +174,7 @@ const InfiniteScrollTable = (props) => {
172174
header="Scroll to load more data"
173175
onLoadMore={onLoadMore}
174176
loading={loading}
175-
reactTableOptions: {{ autoResetSelectedRows: false }}
176-
/>
177-
);
178-
};
179-
```
180-
181-
</details>
182-
183-
## AnalyticalTable with subcomponents
184-
185-
Adding custom subcomponents below table rows can be achieved by setting the `renderRowSubComponent` prop.
186-
The prop expects a function with an optional parameter containing the `row` instance, there you can control which row should display subcomponents. If you want to display the subcomponent at the bottom of the row without an expandable container, you can set `subComponentsBehavior` prop to `"Visible"` or to `"IncludeHeight"`. "Visible" simply adds the subcomponent to the row without including its height in the initial calculation of the table body, whereas "IncludeHeight" does.
187-
188-
### Notes
189-
190-
- When `renderRowSubComponent` is set, `grouping` is disabled.
191-
- When rendering active elements inside the subcomponent, make sure to add the `data-subcomponent-active-element' attribute, otherwise focus behavior won't be consistent.
192-
- When `AnalyticalTableSubComponentsBehavior.IncludeHeight` or `AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable` is used, `AnalyticalTableVisibleRowCountMode.Interactive` is not supported.
193-
194-
<ControlsWithNote of={ComponentStories.Subcomponents} include={['renderRowSubComponent', 'subComponentsBehavior']} />
195-
196-
<Canvas sourceState="none" of={ComponentStories.Subcomponents} />
197-
198-
### Code
199-
200-
<details>
201-
202-
<summary>Show Code</summary>
203-
204-
```jsx
205-
const TableWithSubcomponents = (props) => {
206-
const renderRowSubComponent = (row) => {
207-
if (row.id === '0') {
208-
return (
209-
<FlexBox
210-
style={{ backgroundColor: 'lightblue', height: '300px' }}
211-
justifyContent={FlexBoxJustifyContent.Center}
212-
alignItems={FlexBoxAlignItems.Center}
213-
direction={FlexBoxDirection.Column}
214-
>
215-
<Tag>height: 300px</Tag>
216-
<Text>This subcomponent will only be displayed below the first row.</Text>
217-
<hr />
218-
<Text>
219-
The button below is rendered with `data-subcomponent-active-element` attribute to ensure consistent focus
220-
behavior
221-
</Text>
222-
<Button data-subcomponent-active-element>Click</Button>
223-
</FlexBox>
224-
);
225-
}
226-
if (row.id === '1') {
227-
return (
228-
<FlexBox
229-
style={{ backgroundColor: 'lightyellow', height: '100px' }}
230-
justifyContent={FlexBoxJustifyContent.Center}
231-
alignItems={FlexBoxAlignItems.Center}
232-
direction={FlexBoxDirection.Column}
233-
>
234-
<Tag>height: 100px</Tag>
235-
<Text>This subcomponent will only be displayed below the second row.</Text>
236-
</FlexBox>
237-
);
238-
}
239-
if (row.id === '2') {
240-
return null;
241-
}
242-
return (
243-
<FlexBox
244-
style={{ backgroundColor: 'lightgrey', height: '50px' }}
245-
justifyContent={FlexBoxJustifyContent.Center}
246-
alignItems={FlexBoxAlignItems.Center}
247-
direction={FlexBoxDirection.Column}
248-
>
249-
<Tag>height: 50px</Tag>
250-
<Text>This subcomponent will be displayed below all rows except the first, second and third.</Text>
251-
</FlexBox>
252-
);
253-
};
254-
return (
255-
<AnalyticalTable
256-
data={props.data}
257-
columns={props.columns}
258-
renderRowSubComponent={renderRowSubComponent}
259-
subComponentsBehavior={AnalyticalTableSubComponentsBehavior.Expandable} //default value
177+
reactTableOptions={{ autoResetSelectedRows: false }}
260178
/>
261179
);
262180
};
@@ -366,9 +284,9 @@ const COLUMNS = [
366284
Header: 'PopinDisplay Modes',
367285
responsivePopIn: true,
368286
responsiveMinWidth: 801,
369-
popinDisplay: popinDisplay, // possible values: "Block", "Inline", "WithoutHeader"
287+
popinDisplay: AnalyticalTablePopinDisplay.Block, // possible values: "Block", "Inline", "WithoutHeader"
370288
Cell: () => {
371-
return <Text maxLines={1}>Using popinDisplay: {popinDisplay}</Text>;
289+
return <Text maxLines={1}>Using popinDisplay: Block</Text>;
372290
}
373291
}
374292
];
@@ -438,7 +356,7 @@ export const TableWithNavigationIndicators = () => {
438356
data={data}
439357
columns={columns}
440358
withNavigationHighlight
441-
selectionMode={selectionMode}
359+
selectionMode={AnalyticalTableSelectionMode.Multiple}
442360
markNavigatedRow={markNavigatedRow}
443361
onRowSelect={onRowSelect}
444362
/>
@@ -523,6 +441,8 @@ const TableComponent = () => {
523441
524442
## Table Without Data
525443
444+
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.
445+
526446
<Canvas of={ComponentStories.NoData} />
527447
528448
### Code
@@ -586,8 +506,94 @@ function NoDataTable(props) {
586506
587507
</details>
588508
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+
589593
## Kitchen Sink
590594
595+
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.
596+
591597
<Canvas of={ComponentStories.KitchenSink} />
592598
593599
### Code
@@ -634,12 +640,14 @@ const columns = [
634640
disableFilters: false,
635641
disableGroupBy: true,
636642
disableSortBy: false,
637-
hAlign: 'End'
643+
hAlign: 'End',
644+
sortDescFirst: true
638645
},
639646
{
640647
Header: 'Friend Name',
641648
accessor: 'friend.name',
642-
autoResizable: true
649+
autoResizable: true,
650+
vAlign: VerticalAlign.Middle
643651
},
644652
{
645653
Filter: () => {},
@@ -648,17 +656,26 @@ const columns = [
648656
autoResizable: true,
649657
filter: () => {},
650658
hAlign: 'End',
651-
headerLabel: 'Friend Age'
659+
headerLabel: 'Friend Age',
660+
scaleWidthModeOptions: { headerString: 'Friend Age' }
661+
},
662+
{
663+
Header: 'Status',
664+
id: 'os',
665+
Cell: () => {},
666+
scaleWidthModeOptions: { cellString: 'Negative' }
652667
},
653668
{
654669
Cell: () => {},
655670
Header: 'Actions',
656671
accessor: '.',
657672
cellLabel: () => {},
658673
disableFilters: true,
674+
disableGlobalFilter: true,
659675
disableGroupBy: true,
660676
disableResizing: true,
661677
disableSortBy: true,
678+
disableDragAndDrop: true,
662679
id: 'actions',
663680
minWidth: 100,
664681
width: 100
@@ -688,6 +705,7 @@ const TestComp2 = () => {
688705
minRows={5}
689706
noDataText="Custom 'noDataText' message"
690707
overscanCountHorizontal={5}
708+
retainColumnWidth
691709
scaleWidthMode="Smart"
692710
selectedRowIds={{
693711
3: true
@@ -698,6 +716,7 @@ const TestComp2 = () => {
698716
subRowsKey="subRows"
699717
visibleRowCountMode="Interactive"
700718
visibleRows={5}
719+
withNavigationHighlight
701720
withRowHighlight
702721
onAutoResize={() => {}}
703722
onColumnsReorder={() => {}}

0 commit comments

Comments
 (0)