-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathDrawerSection.tsx
More file actions
134 lines (127 loc) · 3.02 KB
/
Copy pathDrawerSection.tsx
File metadata and controls
134 lines (127 loc) · 3.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as React from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import { useInternalTheme } from '../../core/theming';
import { Palette } from '../../theme/tokens';
import type { ThemeProp } from '../../types';
import Divider from '../Divider';
import Text from '../Typography/Text';
export type Props = React.ComponentPropsWithRef<typeof View> & {
/**
* Title to show as the header for the section.
*/
title?: string;
/**
* Content of the `Drawer.Section`.
*/
children: React.ReactNode;
/**
* Whether to show `Divider` at the end of the section. True by default.
*/
showDivider?: boolean;
/**
* Specifies the largest possible scale a title font can reach.
*/
titleMaxFontSizeMultiplier?: number;
style?: StyleProp<ViewStyle>;
/**
* @optional
*/
theme?: ThemeProp;
};
/**
* A component to group content inside a navigation drawer.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { Drawer } from 'react-native-paper';
*
* const MyComponent = () => {
* const [active, setActive] = React.useState('');
*
* return (
* <Drawer.Section title="Some title">
* <Drawer.Item
* label="First Item"
* active={active === 'first'}
* onPress={() => setActive('first')}
* />
* <Drawer.Item
* label="Second Item"
* active={active === 'second'}
* onPress={() => setActive('second')}
* />
* </Drawer.Section>
* );
* };
*
* export default MyComponent;
* ```
*/
const DrawerSection = ({
children,
title,
theme: themeOverrides,
style,
showDivider = true,
titleMaxFontSizeMultiplier,
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const titleColor = theme.colors.onSurfaceVariant;
const titleMargin = 28;
const font = theme.fonts.titleSmall;
return (
<View style={[styles.container, style]} {...rest}>
{title && (
<View style={[styles.titleContainer, styles.v3TitleContainer]}>
{title && (
<Text
variant="titleSmall"
numberOfLines={1}
style={[
{
color: titleColor,
marginLeft: titleMargin,
...font,
},
]}
maxFontSizeMultiplier={titleMaxFontSizeMultiplier}
>
{title}
</Text>
)}
</View>
)}
{children}
{showDivider && (
<Divider
horizontalInset
bold
style={[styles.divider, styles.v3Divider]}
theme={theme}
/>
)}
</View>
);
};
DrawerSection.displayName = 'Drawer.Section';
const styles = StyleSheet.create({
container: {
marginBottom: 4,
},
titleContainer: {
height: 40,
justifyContent: 'center',
},
v3TitleContainer: {
height: 56,
},
divider: {
marginTop: 4,
},
v3Divider: {
backgroundColor: Palette.neutralVariant50,
},
});
export default DrawerSection;