-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
88 lines (79 loc) · 2.37 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import {
Button,
__experimentalText as Text,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { chevronLeft, chevronRight } from '@wordpress/icons';
import { __, _x, isRTL, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import { store as blockEditorStore } from '../../store';
function BlockCard( { title, icon, description, blockType, className, name } ) {
if ( blockType ) {
deprecated( '`blockType` property in `BlockCard component`', {
since: '5.7',
alternative: '`title, icon and description` properties',
} );
( { title, icon, description } = blockType );
}
const { parentNavBlockClientId } = useSelect( ( select ) => {
const { getSelectedBlockClientId, getBlockParentsByBlockName } =
select( blockEditorStore );
const _selectedBlockClientId = getSelectedBlockClientId();
return {
parentNavBlockClientId: getBlockParentsByBlockName(
_selectedBlockClientId,
'core/navigation',
true
)[ 0 ],
};
}, [] );
const { selectBlock } = useDispatch( blockEditorStore );
return (
<div className={ clsx( 'block-editor-block-card', className ) }>
{ parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here.
<Button
onClick={ () => selectBlock( parentNavBlockClientId ) }
label={ __( 'Go to parent Navigation block' ) }
style={
// TODO: This style override is also used in ToolsPanelHeader.
// It should be supported out-of-the-box by Button.
{ minWidth: 24, padding: 0 }
}
icon={ isRTL() ? chevronRight : chevronLeft }
size="small"
/>
) }
<BlockIcon icon={ icon } showColors />
<VStack spacing={ 1 }>
<h2 className="block-editor-block-card__title">
{ name?.length
? sprintf(
// translators: 1: Custom block name. 2: Block title.
_x( '%1$s (%2$s)', 'block label' ),
name,
title
)
: title }
</h2>
{ description && (
<Text className="block-editor-block-card__description">
{ description }
</Text>
) }
</VStack>
</div>
);
}
export default BlockCard;