UNPKG

1.64 kBTypeScriptView Raw
1import * as React from 'react';
2import {
3 View,
4 ViewStyle,
5 StyleSheet,
6 StyleProp,
7 TextStyle,
8} from 'react-native';
9import ListSubheader from './ListSubheader';
10import { withTheme } from '../../core/theming';
11
12type Props = React.ComponentPropsWithRef<typeof View> & {
13 /**
14 * Title text for the section.
15 */
16 title?: string;
17 /**
18 * Content of the section.
19 */
20 children: React.ReactNode;
21 /**
22 * @optional
23 */
24 theme: ReactNativePaper.Theme;
25 /**
26 * Style that is passed to Title element.
27 */
28 titleStyle?: StyleProp<TextStyle>;
29 style?: StyleProp<ViewStyle>;
30};
31
32/**
33 * A component used to group list items.
34 *
35 * <div class="screenshots">
36 * <img src="screenshots/list-section.png" />
37 * </div>
38 *
39 * ## Usage
40 * ```js
41 * import * as React from 'react';
42 * import { List } from 'react-native-paper';
43 *
44 * const MyComponent = () => (
45 * <List.Section>
46 * <List.Subheader>Some title</List.Subheader>
47 * <List.Item title="First Item" left={() => <List.Icon icon="folder" />} />
48 * <List.Item
49 * title="Second Item"
50 * left={() => <List.Icon color="#000" icon="folder" />}
51 * />
52 * </List.Section>
53 * );
54 *
55 * export default MyComponent;
56 * ```
57 */
58const ListSection = ({
59 children,
60 title,
61 titleStyle,
62 style,
63 ...rest
64}: Props) => (
65 <View {...rest} style={[styles.container, style]}>
66 {title ? <ListSubheader style={titleStyle}>{title}</ListSubheader> : null}
67 {children}
68 </View>
69);
70
71ListSection.displayName = 'List.Section';
72
73const styles = StyleSheet.create({
74 container: {
75 marginVertical: 8,
76 },
77});
78
79export default withTheme(ListSection);