diff --git a/.changeset/export-table-body-skeleton.md b/.changeset/export-table-body-skeleton.md new file mode 100644 index 0000000000..18b017e734 --- /dev/null +++ b/.changeset/export-table-body-skeleton.md @@ -0,0 +1,5 @@ +--- +'@backstage/ui': patch +--- + +Exported the `TableBodySkeleton` component as a public API for use outside of the built-in `Table` component. The component now accepts any column array whose items have an `id` property, making it compatible with custom column types. diff --git a/docs-ui/src/app/components/table/page.mdx b/docs-ui/src/app/components/table/page.mdx index 5323804c88..1beeb6e955 100644 --- a/docs-ui/src/app/components/table/page.mdx +++ b/docs-ui/src/app/components/table/page.mdx @@ -24,6 +24,7 @@ import { tableRootPropDefs, columnPropDefs, rowPropDefs, + tableBodySkeletonPropDefs, } from './props-definition'; import { tableUsageSnippet, @@ -303,6 +304,12 @@ Low-level components for building custom table layouts. +#### TableBodySkeleton + +A table body that renders animated skeleton rows as a loading placeholder. Useful when composing with primitives and you need a loading state without the full `Table` component. + + + diff --git a/docs-ui/src/app/components/table/props-definition.tsx b/docs-ui/src/app/components/table/props-definition.tsx index 6e5809412e..30381e30f7 100644 --- a/docs-ui/src/app/components/table/props-definition.tsx +++ b/docs-ui/src/app/components/table/props-definition.tsx @@ -491,6 +491,15 @@ export const columnPropDefs: Record = { }, }; +export const tableBodySkeletonPropDefs: Record = { + columns: { + type: 'enum', + values: ['{ id: string }[]'], + description: + 'Array of column objects. Each item must have an `id` property. Compatible with `ColumnConfig` and custom column types.', + }, +}; + export const rowPropDefs: Record = { id: { type: 'enum', diff --git a/packages/ui/report.api.md b/packages/ui/report.api.md index e30a81a874..0bce00e90e 100644 --- a/packages/ui/report.api.md +++ b/packages/ui/report.api.md @@ -2700,6 +2700,13 @@ export interface TableBodyProps extends TableBodyOwnProps, Omit, keyof TableBodyOwnProps> {} +// @public +export function TableBodySkeleton< + T extends { + id: string; + }, +>(input: { columns: readonly T[] }): JSX_2.Element; + // @public export const TableDefinition: { readonly styles: { diff --git a/packages/ui/src/components/Table/components/TableBodySkeleton.tsx b/packages/ui/src/components/Table/components/TableBodySkeleton.tsx index 1623fdc9cf..16387fbbcc 100644 --- a/packages/ui/src/components/Table/components/TableBodySkeleton.tsx +++ b/packages/ui/src/components/Table/components/TableBodySkeleton.tsx @@ -18,25 +18,33 @@ import { TableBody } from './TableBody'; import { Row } from './Row'; import { Cell } from './Cell'; import { Skeleton } from '../../Skeleton'; -import type { ColumnConfig, TableItem } from '../types'; const SKELETON_ROW_COUNT = 5; const SKELETON_WIDTHS = ['75%', '50%', '60%', '45%', '70%']; const skeletonItems = Array.from({ length: SKELETON_ROW_COUNT }, (_, i) => ({ id: `skeleton-${i}`, + index: i, })); -/** @internal */ -export function TableBodySkeleton({ +/** + * A table body that renders animated skeleton rows as a loading placeholder. + * + * @remarks + * Accepts any column array whose items have an `id` property, making it + * compatible with both `ColumnConfig` and custom column types. + * + * @public + */ +export function TableBodySkeleton({ columns, }: { - columns: readonly ColumnConfig[]; + columns: readonly T[]; }) { return ( {item => { - const rowIndex = Number(item.id.split('-')[1]); + const rowIndex = item.index; return ( {column => ( diff --git a/packages/ui/src/components/Table/index.ts b/packages/ui/src/components/Table/index.ts index d2847fae38..07bb497426 100644 --- a/packages/ui/src/components/Table/index.ts +++ b/packages/ui/src/components/Table/index.ts @@ -23,6 +23,7 @@ export { Row } from './components/Row'; export { Cell } from './components/Cell'; export { CellText } from './components/CellText'; export { CellProfile } from './components/CellProfile'; +export { TableBodySkeleton } from './components/TableBodySkeleton'; export { useTable } from './hooks/useTable'; export type {