Skip to content

Commit

Permalink
chore: add correct table component types to the prop tables (#4091)
Browse files Browse the repository at this point in the history
* add correct table component types to the prop tables

* ignore directory from coverage
  • Loading branch information
aromko authored Aug 6, 2024
1 parent 5d4c753 commit 9052aed
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/content/components/collection/table/table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,23 @@ Note the usage of `isRowHeader` in the example below. It controls which columns

### Table.Header

<PropsTable component="TableHeader" />
<PropsTable component="Table.Header" />

### Table.Column

<PropsTable component="TableColumnHeader" />
<PropsTable component="Table.Column" />

### Table.Body

<PropsTable component="TableBody" />
<PropsTable component="Table.Body" />

### Table.Row

<PropsTable component="TableRow" />
<PropsTable component="Table.Row" />

### Table.Cell

<PropsTable component="TableCell" />
<PropsTable component="Table.Cell" />

## Alternative components

Expand Down
1 change: 1 addition & 0 deletions docs/scripts/build-component-props.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const transformTypeValue = async val => {
'keyof NumberFormatOptionsCurrencyDisplayRegistry',
'boolean | keyof NumberFormatOptionsUseGroupingRegistry | "true" | "false"',
'keyof NumberFormatOptionsSignDisplayRegistry',
'T[]',
];
let text = val.type.name;

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = createConfig({
'!**/packages/types/**',
'!**/*.stories.tsx',
'!**/theme-preset/**',
'!packages/components/src/_propTableTypes/**',
// needed for coverage not to break should be fixed soon
'!packages/components/src/Accordion/useAccordionItem.ts',
'!packages/components/src/Accordion/Accordion.tsx',
Expand Down
34 changes: 34 additions & 0 deletions packages/components/src/_propTableTypes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# \_propTableTypes directory

This directory is a workaround for using compound components like in the table because react-docgen-typescript can't
solve types from compound components. It is used by the script `build-component-props.mjs` to generate the correct type.
Then this type can be used in the props table.

## File name

Create a file with the name of the compound component part e.g `Table.Body`.

## import type

Import the type which can't be autogenerated. Normally it is the type which belongs to the compound component part
e.g. `Table.Cell = <b>Cell</b>;`

`import { Cell as ReactAriaCell } from '@react-stately/table';`

Note: You should use an alias. Name it whatever you want.

## export type

Finally export the imported type.

`export const Cell = ReactAriaCell;`

## run script

After creating the file with the content run `pnpm buil-component-props`. Then search for the file name in `props.json`
and you should find the type.

## using in prop table

Use the new type in the props table. For this just pass the file name into the component prop e.g.
`<PropsTable component="Table.Cell" />`
3 changes: 3 additions & 0 deletions packages/components/src/_propTableTypes/Table.Body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TableBody as ReactAriaTableBody } from '@react-stately/table';

export const Body = ReactAriaTableBody;
3 changes: 3 additions & 0 deletions packages/components/src/_propTableTypes/Table.Cell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Cell as ReactAriaCell } from '@react-stately/table';

export const Cell = ReactAriaCell;
3 changes: 3 additions & 0 deletions packages/components/src/_propTableTypes/Table.Column.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Column as ReactAriaColumn } from '@react-stately/table';

export const Column = ReactAriaColumn;
3 changes: 3 additions & 0 deletions packages/components/src/_propTableTypes/Table.Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TableHeader as ReactAriaTableHeader } from '@react-stately/table';

export const Header = ReactAriaTableHeader;
3 changes: 3 additions & 0 deletions packages/components/src/_propTableTypes/Table.Row.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Row as ReactAriaRow } from '@react-stately/table';

export const Row = ReactAriaRow;

0 comments on commit 9052aed

Please sign in to comment.