diff --git a/.changeset/swift-readers-sin.md b/.changeset/swift-readers-sin.md new file mode 100644 index 0000000000..05bd05a94c --- /dev/null +++ b/.changeset/swift-readers-sin.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-components': patch +--- + +Allow custom images in the empty state component diff --git a/packages/core-components/src/components/EmptyState/EmptyState.test.tsx b/packages/core-components/src/components/EmptyState/EmptyState.test.tsx index 6487fcf4e6..f4a772c0d2 100644 --- a/packages/core-components/src/components/EmptyState/EmptyState.test.tsx +++ b/packages/core-components/src/components/EmptyState/EmptyState.test.tsx @@ -36,4 +36,20 @@ describe('', () => { expect(rendered.getByLabelText('button')).toBeInTheDocument(); expect(rendered.getByAltText('annotation is missing')).toBeInTheDocument(); }); + + it('renders custom image if one is provided', async () => { + const { getByText, getByRole } = await renderWithEffects( + wrapInTestApp( + Action} + customImage={
Custom Image
} + />, + ), + ); + + expect(getByText('Some empty state text')).toBeInTheDocument(); + expect(getByText('Custom Image')).toBeInTheDocument(); + expect(getByRole('button')).toBeInTheDocument(); + }); }); diff --git a/packages/core-components/src/components/EmptyState/EmptyState.tsx b/packages/core-components/src/components/EmptyState/EmptyState.tsx index b4fbf6d510..7671dabadb 100644 --- a/packages/core-components/src/components/EmptyState/EmptyState.tsx +++ b/packages/core-components/src/components/EmptyState/EmptyState.tsx @@ -42,9 +42,14 @@ const useStyles = makeStyles( type Props = { title: string; description?: string | JSX.Element; - missing: 'field' | 'info' | 'content' | 'data'; action?: JSX.Element; -}; +} & ( + | { + missing: 'field' | 'info' | 'content' | 'data'; + customImage?: never; + } + | { missing?: never; customImage: JSX.Element } +); /** * Various placeholder views for empty state pages @@ -53,7 +58,7 @@ type Props = { * */ export function EmptyState(props: Props) { - const { title, description, missing, action } = props; + const { title, description, missing, action, customImage } = props; const classes = useStyles(); return ( - + {customImage ?? } );