Skip to content

Commit 1bde15e

Browse files
committed
more docs
1 parent 718986a commit 1bde15e

File tree

2 files changed

+81
-25
lines changed

2 files changed

+81
-25
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,67 @@ const TableComponent = () => {
567567
568568
<Canvas of={ComponentStories.NoData} />
569569
570+
### Code
571+
572+
<details>
573+
574+
<summary>Show static code</summary>
575+
576+
```tsx
577+
function NoDataTable(props) {
578+
const [selected, setSelected] = useState('noData');
579+
const [filtered, setFiltered] = useState(false);
580+
const handleChange: SegmentedButtonPropTypes['onSelectionChange'] = (e) => {
581+
const { key } = e.detail.selectedItems[0].dataset;
582+
setSelected(key);
583+
if (key === 'data') {
584+
setFiltered(false);
585+
}
586+
};
587+
const handleClick: ToggleButtonPropTypes['onClick'] = (e) => {
588+
setFiltered(!!e.target.pressed);
589+
};
590+
591+
const NoDataComponent: AnalyticalTablePropTypes['NoDataComponent'] =
592+
selected === 'noData'
593+
? undefined
594+
: (props) => {
595+
return filtered ? (
596+
<IllustratedMessage role={props.role} name={NoFilterResults} />
597+
) : (
598+
<IllustratedMessage role={props.role} name={NoDataIllustration} />
599+
);
600+
};
601+
return (
602+
<>
603+
<SegmentedButton onSelectionChange={handleChange} accessibleName="Select data view mode">
604+
<SegmentedButtonItem selected={selected === 'noData'} data-key="noData">
605+
Default NoData Component
606+
</SegmentedButtonItem>
607+
<SegmentedButtonItem selected={selected === 'illustratedMessage'} data-key="illustratedMessage">
608+
IllustratedMessage NoData Component
609+
</SegmentedButtonItem>
610+
<SegmentedButtonItem selected={selected === 'data'} data-key="data">
611+
With Data
612+
</SegmentedButtonItem>
613+
</SegmentedButton>{' '}
614+
|{' '}
615+
<ToggleButton onClick={handleClick} pressed={filtered} disabled={selected === 'data'}>
616+
Table filtered
617+
</ToggleButton>
618+
<AnalyticalTable
619+
{...props}
620+
data={selected === 'data' ? props.data : []}
621+
globalFilterValue={filtered ? 'Non-existing text' : undefined}
622+
NoDataComponent={NoDataComponent}
623+
/>
624+
</>
625+
);
626+
}
627+
```
628+
629+
</details>
630+
570631
## Kitchen Sink
571632
572633
<Canvas of={ComponentStories.KitchenSink} />

packages/main/src/components/AnalyticalTable/AnalyticalTable.stories.tsx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,24 @@ export const NoData: Story = {
605605
setFiltered(!!e.target.pressed);
606606
};
607607

608+
const NoDataComponent: AnalyticalTablePropTypes['NoDataComponent'] =
609+
selected === 'noData'
610+
? undefined
611+
: (props) => {
612+
return filtered ? (
613+
<IllustratedMessage role={props.role} name={NoFilterResults} />
614+
) : (
615+
<IllustratedMessage role={props.role} name={NoDataIllustration} />
616+
);
617+
};
618+
619+
const tableProps = {
620+
...args,
621+
data: selected === 'data' ? args.data : [],
622+
globalFilterValue: filtered ? 'Non-existing text' : undefined,
623+
NoDataComponent: NoDataComponent,
624+
};
625+
608626
return (
609627
<>
610628
<SegmentedButton onSelectionChange={handleChange} accessibleName="Select data view mode">
@@ -623,34 +641,11 @@ export const NoData: Story = {
623641
Table filtered
624642
</ToggleButton>
625643
{context.viewMode === 'story' ? (
626-
<AnalyticalTable
627-
{...args}
628-
data={selected === 'data' ? args.data : []}
629-
globalFilterValue={filtered ? 'Non-existing text' : undefined}
630-
NoDataComponent={
631-
selected === 'noData'
632-
? undefined
633-
: (props) => {
634-
return filtered ? (
635-
<IllustratedMessage role={props.role} name={NoFilterResults} />
636-
) : (
637-
<IllustratedMessage role={props.role} name={NoDataIllustration} />
638-
);
639-
}
640-
}
641-
/>
644+
<AnalyticalTable {...tableProps} />
642645
) : (
643646
<>
644647
<hr />
645-
<ToggleableTable
646-
{...args}
647-
data={selected === 'data' ? args.data : []}
648-
NoDataComponent={
649-
selected === 'noData'
650-
? undefined
651-
: () => <IllustratedMessage role="gridcell" name={NoDataIllustration} />
652-
}
653-
/>
648+
<ToggleableTable {...tableProps} />
654649
</>
655650
)}
656651
</>

0 commit comments

Comments
 (0)