-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
block-selection-button.native.js
102 lines (96 loc) · 2.47 KB
/
block-selection-button.native.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { getBlockType } from '@wordpress/blocks';
import { BlockIcon } from '@wordpress/block-editor';
/**
* External dependencies
*/
import { View, Text, TouchableOpacity } from 'react-native';
/**
* Internal dependencies
*/
import BlockTitle from '../block-title';
import useBlockDisplayInformation from '../use-block-display-information';
import SubdirectorSVG from './subdirectory-icon';
import { store as blockEditorStore } from '../../store';
import styles from './block-selection-button.scss';
const BlockSelectionButton = ( {
clientId,
rootClientId,
rootBlockIcon,
isRTL,
} ) => {
const blockInformation = useBlockDisplayInformation( clientId );
return (
<View
style={ [
styles.selectionButtonContainer,
rootClientId && styles.densedPaddingLeft,
] }
>
<TouchableOpacity
style={ styles.button }
onPress={ () => {
/* Open BottomSheet with markup. */
} }
disabled={
true
} /* Disable temporarily since onPress function is empty. */
>
{ rootClientId &&
rootBlockIcon && [
<Icon
key="parent-icon"
size={ 24 }
icon={ rootBlockIcon.src }
fill={ styles.icon.color }
/>,
<View key="subdirectory-icon" style={ styles.arrow }>
<SubdirectorSVG
fill={ styles.arrow.color }
isRTL={ isRTL }
/>
</View>,
] }
{ blockInformation?.icon && (
<BlockIcon
size={ 24 }
icon={ blockInformation.icon }
fill={ styles.icon.color }
/>
) }
<Text
maxFontSizeMultiplier={ 1.25 }
ellipsizeMode="tail"
numberOfLines={ 1 }
style={ styles.selectionButtonTitle }
>
<BlockTitle clientId={ clientId } maximumLength={ 35 } />
</Text>
</TouchableOpacity>
</View>
);
};
export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockRootClientId, getBlockName, getSettings } =
select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientId );
if ( ! rootClientId ) {
return { clientId };
}
const rootBlockName = getBlockName( rootClientId );
const rootBlockType = getBlockType( rootBlockName );
const rootBlockIcon = rootBlockType ? rootBlockType.icon : {};
return {
clientId,
rootClientId,
rootBlockIcon,
isRTL: getSettings().isRTL,
};
} ),
] )( BlockSelectionButton );