diff --git a/docs/content/drafts/DataTable.mdx b/docs/content/drafts/DataTable.mdx index 348b8252d59..6de1197e178 100644 --- a/docs/content/drafts/DataTable.mdx +++ b/docs/content/drafts/DataTable.mdx @@ -6,66 +6,6 @@ status: Draft import data from '../../../src/DataTable/DataTable.docs.json' -## Examples - -```jsx - { - return - }, - }, - { - header: 'Dependabot', - renderCell: row => { - return row.securityFeatures.dependabot.length > 0 ? ( - - {row.securityFeatures.dependabot.map(feature => { - return - })} - - ) : null - }, - }, - ]} -/> -``` - ## Props diff --git a/generated/components.json b/generated/components.json index eed9305dd6e..09ca4707715 100644 --- a/generated/components.json +++ b/generated/components.json @@ -1906,6 +1906,26 @@ { "id": "components-datatable--default", "code": "() => (\n \n \n Repositories\n \n \n A subtitle could appear here to give extra context to the data.\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n />\n \n)" + }, + { + "id": "drafts-components-datatable--with-title", + "code": "() => (\n \n \n Repositories\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n />\n \n)" + }, + { + "id": "drafts-components-datatable--with-title-and-subtitle", + "code": "() => (\n \n \n Repositories\n \n \n A subtitle could appear here to give extra context to the data.\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n />\n \n)" + }, + { + "id": "drafts-components-datatable--with-sorting", + "code": "() => {\n const rows = Array.from(data).sort((a, b) => {\n return b.updatedAt - a.updatedAt\n })\n return (\n \n \n Repositories\n \n \n A subtitle could appear here to give extra context to the data.\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n sortBy: true,\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n initialSortColumn=\"updatedAt\"\n initialSortDirection=\"DESC\"\n />\n \n )\n}" + }, + { + "id": "drafts-components-datatable--with-actions", + "code": "() => (\n \n \n Repositories\n \n \n \n \n \n \n \n A subtitle could appear here to give extra context to the data.\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n />\n \n)" + }, + { + "id": "drafts-components-datatable--with-action", + "code": "() => (\n \n \n Repositories\n \n \n \n \n \n \n A subtitle could appear here to give extra context to the data.\n \n {\n return \n },\n },\n {\n header: 'Updated',\n field: 'updatedAt',\n renderCell: (row) => {\n return \n },\n },\n {\n header: 'Dependabot',\n field: 'securityFeatures.dependabot',\n renderCell: (row) => {\n return row.securityFeatures.dependabot.length > 0 ? (\n \n {row.securityFeatures.dependabot.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n {\n header: 'Code scanning',\n field: 'securityFeatures.codeScanning',\n renderCell: (row) => {\n return row.securityFeatures.codeScanning.length > 0 ? (\n \n {row.securityFeatures.codeScanning.map((feature) => {\n return \n })}\n \n ) : null\n },\n },\n ]}\n />\n \n)" } ], "props": [ @@ -2005,7 +2025,7 @@ }, { "name": "scope", - "type": "string", + "type": "'row'", "description": "Provide the scope for a table cell, useful for defining a row header using `scope=\"row\"`" } ] diff --git a/src/DataTable/DataTable.docs.json b/src/DataTable/DataTable.docs.json index 8a140da5c42..fd2c937f69e 100644 --- a/src/DataTable/DataTable.docs.json +++ b/src/DataTable/DataTable.docs.json @@ -3,7 +3,23 @@ "name": "DataTable", "status": "draft", "a11yReviewed": false, - "stories": [], + "stories": [ + { + "id": "drafts-components-datatable--with-title" + }, + { + "id": "drafts-components-datatable--with-title-and-subtitle" + }, + { + "id": "drafts-components-datatable--with-sorting" + }, + { + "id": "drafts-components-datatable--with-actions" + }, + { + "id": "drafts-components-datatable--with-action" + } + ], "props": [ { "name": "aria-describedby", @@ -101,7 +117,7 @@ }, { "name": "scope", - "type": "string", + "type": "'row'", "description": "Provide the scope for a table cell, useful for defining a row header using `scope=\"row\"`" } ] diff --git a/src/DataTable/DataTable.tsx b/src/DataTable/DataTable.tsx index 0ae159cc9a7..61e65509c48 100644 --- a/src/DataTable/DataTable.tsx +++ b/src/DataTable/DataTable.tsx @@ -14,18 +14,18 @@ export type DataTableProps = { /** * Provide an id to an element which uniquely describes this table */ - 'aria-describedby'?: string | undefined + 'aria-describedby'?: string /** * Provide an id to an element which uniquely labels this table */ - 'aria-labelledby'?: string | undefined + 'aria-labelledby'?: string /** * Specify the amount of space that should be available around the contents of * a cell */ - cellPadding?: 'condensed' | 'normal' | 'spacious' | undefined + cellPadding?: 'condensed' | 'normal' | 'spacious' /** * Provide a collection of the rows which will be rendered inside of the table @@ -43,13 +43,13 @@ export type DataTableProps = { * using this `prop`, the input data must be sorted by this column in * ascending order */ - initialSortColumn?: ObjectPaths | string | undefined + initialSortColumn?: ObjectPaths | string /** * Provide the sort direction that the table should be sorted by on the * currently sorted column */ - initialSortDirection?: Exclude | undefined + initialSortDirection?: Exclude } function DataTable({ diff --git a/src/DataTable/Table.tsx b/src/DataTable/Table.tsx index 40330bfcf59..9b9765438ca 100644 --- a/src/DataTable/Table.tsx +++ b/src/DataTable/Table.tsx @@ -144,18 +144,18 @@ export type TableProps = React.ComponentPropsWithoutRef<'table'> & { /** * Provide an id to an element which uniquely describes this table */ - 'aria-describedby'?: string | undefined + 'aria-describedby'?: string /** * Provide an id to an element which uniquely labels this table */ - 'aria-labelledby'?: string | undefined + 'aria-labelledby'?: string /** * Specify the amount of space that should be available around the contents of * a cell */ - cellPadding?: 'condensed' | 'normal' | 'spacious' | undefined + cellPadding?: 'condensed' | 'normal' | 'spacious' } const Table = React.forwardRef(function Table({cellPadding = 'normal', ...rest}, ref) { @@ -252,7 +252,7 @@ export type TableCellProps = React.ComponentPropsWithoutRef<'td'> & { * Provide the scope for a table cell, useful for defining a row header using * `scope="row"` */ - scope?: 'row' | undefined + scope?: 'row' } function TableCell({children, scope, ...rest}: TableCellProps) { diff --git a/src/DataTable/column.ts b/src/DataTable/column.ts index 1fe540b865d..7a97202ae27 100644 --- a/src/DataTable/column.ts +++ b/src/DataTable/column.ts @@ -3,7 +3,7 @@ import {UniqueRow} from './row' import {SortStrategies} from './sorting' export interface Column { - id?: string | undefined + id?: string /** * Provide the name of the column. This will be rendered as a table header @@ -25,13 +25,13 @@ export interface Column { * Provide a custom component or render prop to render the data for this * column in a row */ - renderCell?: ((data: Data) => React.ReactNode) | undefined + renderCell?: (data: Data) => React.ReactNode /** * Specify if the value of this column for a row should be treated as a row * header */ - rowHeader?: boolean | undefined + rowHeader?: boolean /** * Specify if the table should sort by this column and, if applicable, a diff --git a/src/DataTable/useTable.ts b/src/DataTable/useTable.ts index 295c5b15f11..fefd283f966 100644 --- a/src/DataTable/useTable.ts +++ b/src/DataTable/useTable.ts @@ -7,8 +7,8 @@ import {ObjectPathValue} from './utils' interface TableConfig { columns: Array> data: Array - initialSortColumn?: string | undefined - initialSortDirection?: Exclude | undefined + initialSortColumn?: string + initialSortDirection?: Exclude } interface Table { diff --git a/src/__tests__/storybook.test.tsx b/src/__tests__/storybook.test.tsx index c75b49a951d..e9474630794 100644 --- a/src/__tests__/storybook.test.tsx +++ b/src/__tests__/storybook.test.tsx @@ -18,6 +18,7 @@ const allowlist = [ 'Checkbox', 'CheckboxGroup', 'CounterLabel', + 'DataTable', 'Details', 'Flash', 'Heading',