-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathno-widgets-state.tsx
More file actions
55 lines (49 loc) · 1.41 KB
/
no-widgets-state.tsx
File metadata and controls
55 lines (49 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* External dependencies
*/
import type { ReactNode } from 'react';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { home } from '@wordpress/icons';
import { EmptyState, Stack } from '@wordpress/ui';
/**
* Internal dependencies
*/
import { useDashboardInternalContext } from '../../context/dashboard-context';
import styles from './no-widgets-state.module.css';
export interface NoWidgetsStateProps {
children?: ReactNode;
}
function NoWidgetsStateImpl( { children }: NoWidgetsStateProps ) {
const { layout } = useDashboardInternalContext();
if ( layout.length > 0 ) {
return null;
}
return (
<Stack justify="center" align="center" className={ styles.root }>
{ children ?? (
<EmptyState.Root>
<EmptyState.Icon icon={ home } />
<EmptyState.Title>
{ __( 'Your dashboard is empty' ) }
</EmptyState.Title>
<EmptyState.Description>
{ __(
'Add widgets to start customizing your dashboard.'
) }
</EmptyState.Description>
</EmptyState.Root>
) }
</Stack>
);
}
/**
* Renders an empty-state placeholder when the dashboard's `layout` has no
* widgets. Pair with `WidgetDashboard.Widgets` inside `WidgetDashboard` so
* the placeholder shows up in place of the grid until widgets are added.
* Without children, falls back to a built-in placeholder; pass children to
* override.
*/
export const NoWidgetsState = NoWidgetsStateImpl;