Skip to content

Commit

Permalink
[v11.0.x] EmptyState: Add completed variant (#86503)
Browse files Browse the repository at this point in the history
EmptyState: Add `completed` variant (#86497)

* add 'completed' variant

* add central text alignment

(cherry picked from commit 0704430)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
  • Loading branch information
grafana-delivery-bot[bot] and ashharrison90 committed Apr 18, 2024
1 parent a399168 commit 011c3fa
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/grafana-ui/src/components/EmptyState/EmptyState.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ import { EmptyState } from '@grafana/ui';
<EmptyState variant="not-found" message="No playlists found" />;
```

### `variant="completed"`

For when a user has completed all tasks on a page, such as reading all their notifications.

```jsx
import { EmptyState } from '@grafana/ui';

<EmptyState variant="completed" message="You're all caught up" />;
```

## Customization

For all variants you can:
Expand Down
17 changes: 14 additions & 3 deletions packages/grafana-ui/src/components/EmptyState/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { ReactNode } from 'react';
import SVG from 'react-inlinesvg';

import { Box } from '../Layout/Box/Box';
import { Stack } from '../Layout/Stack/Stack';
import { Text } from '../Text/Text';

import { GrotCTA } from './GrotCTA/GrotCTA';
import { GrotNotFound } from './GrotNotFound/GrotNotFound';
import GrotCompleted from './grot-completed.svg';

interface Props {
/**
Expand All @@ -24,7 +26,7 @@ interface Props {
/**
* Which variant to use. Affects the default image shown.
*/
variant: 'call-to-action' | 'not-found';
variant: 'call-to-action' | 'not-found' | 'completed';
}

export const EmptyState = ({
Expand All @@ -41,8 +43,14 @@ export const EmptyState = ({
<Box paddingY={4} gap={4} display="flex" direction="column" alignItems="center">
{!hideImage && imageToShow}
<Stack direction="column" alignItems="center">
<Text variant="h4">{message}</Text>
{children && <Text color="secondary">{children}</Text>}
<Text variant="h4" textAlignment="center">
{message}
</Text>
{children && (
<Text color="secondary" textAlignment="center">
{children}
</Text>
)}
</Stack>
{button}
</Box>
Expand All @@ -57,6 +65,9 @@ function getDefaultImageForVariant(variant: Props['variant']) {
case 'not-found': {
return <GrotNotFound width={300} />;
}
case 'completed': {
return <SVG src={GrotCompleted} width={300} />;
}
default: {
throw new Error(`Unknown variant: ${variant}`);
}
Expand Down
Loading

0 comments on commit 011c3fa

Please sign in to comment.