-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathmobile-tab-navigation.js
More file actions
84 lines (82 loc) · 2.02 KB
/
mobile-tab-navigation.js
File metadata and controls
84 lines (82 loc) · 2.02 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
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
/**
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalSpacer as Spacer,
__experimentalView as View,
Navigator,
FlexBlock,
} from '@wordpress/components';
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
import { Text } from '@wordpress/ui';
function ScreenHeader( { title } ) {
return (
<VStack spacing={ 0 }>
<View>
<Spacer marginBottom={ 0 } paddingX={ 4 } paddingY={ 3 }>
<HStack spacing={ 2 }>
<Navigator.BackButton
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"
label={ __( 'Back' ) }
/>
<Spacer>
<Text variant="heading-sm" render={ <h5 /> }>
{ title }
</Text>
</Spacer>
</HStack>
</Spacer>
</View>
</VStack>
);
}
export default function MobileTabNavigation( { categories, children } ) {
return (
<Navigator
initialPath="/"
className="block-editor-inserter__mobile-tab-navigation"
>
<Navigator.Screen path="/">
<ItemGroup>
{ categories.map( ( category ) => (
<Navigator.Button
key={ category.name }
path={ `/category/${ category.name }` }
as={ Item }
isAction
>
<HStack>
<FlexBlock>{ category.label }</FlexBlock>
<Icon
icon={
isRTL() ? chevronLeft : chevronRight
}
/>
</HStack>
</Navigator.Button>
) ) }
</ItemGroup>
</Navigator.Screen>
{ categories.map( ( category ) => (
<Navigator.Screen
key={ category.name }
path={ `/category/${ category.name }` }
>
<ScreenHeader title={ __( 'Back' ) } />
{ children( category ) }
</Navigator.Screen>
) ) }
</Navigator>
);
}