-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathdataview-item.js
67 lines (62 loc) · 1.39 KB
/
dataview-item.js
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
56
57
58
59
60
61
62
63
64
65
66
67
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { __experimentalHStack as HStack } from '@wordpress/components';
import { VIEW_LAYOUTS } from '@wordpress/dataviews';
/**
* Internal dependencies
*/
import { useLink } from '../routes/link';
import SidebarNavigationItem from '../sidebar-navigation-item';
import { unlock } from '../../lock-unlock';
const { useLocation } = unlock( routerPrivateApis );
export default function DataViewItem( {
title,
slug,
customViewId,
type,
icon,
isActive,
isCustom,
suffix,
navigationItemSuffix,
} ) {
const {
params: { postType },
} = useLocation();
const iconToUse =
icon || VIEW_LAYOUTS.find( ( v ) => v.type === type ).icon;
let activeView = isCustom ? customViewId : slug;
if ( activeView === 'all' ) {
activeView = undefined;
}
const linkInfo = useLink( {
postType,
layout: type,
activeView,
isCustom: isCustom ? 'true' : undefined,
} );
return (
<HStack
justify="flex-start"
className={ clsx( 'edit-site-sidebar-dataviews-dataview-item', {
'is-selected': isActive,
} ) }
>
<SidebarNavigationItem
icon={ iconToUse }
{ ...linkInfo }
suffix={ navigationItemSuffix }
aria-current={ isActive ? 'true' : undefined }
>
{ title }
</SidebarNavigationItem>
{ suffix }
</HStack>
);
}