Allow custom images in empty state component
Signed-off-by: Joon Park <joonp@spotify.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-components': patch
|
||||
---
|
||||
|
||||
Allow custom images in the empty state component
|
||||
@@ -36,4 +36,20 @@ describe('<EmptyState />', () => {
|
||||
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(
|
||||
<EmptyState
|
||||
title="Some empty state text"
|
||||
action={<Button aria-label="button">Action</Button>}
|
||||
customImage={<div>Custom Image</div>}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
|
||||
expect(getByText('Some empty state text')).toBeInTheDocument();
|
||||
expect(getByText('Custom Image')).toBeInTheDocument();
|
||||
expect(getByRole('button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 (
|
||||
<Grid
|
||||
@@ -78,7 +83,7 @@ export function EmptyState(props: Props) {
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={6} className={classes.imageContainer}>
|
||||
<EmptyStateImage missing={missing} />
|
||||
{customImage ?? <EmptyStateImage missing={missing} />}
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user