UNPKG

1.24 kBTypeScriptView Raw
1import * as React from 'react';
2import { StyleSheet, StyleProp, TextStyle } from 'react-native';
3import color from 'color';
4import Text from '../Typography/Text';
5import { withTheme } from '../../core/theming';
6
7type Props = React.ComponentProps<typeof Text> & {
8 /**
9 * @optional
10 */
11 theme: ReactNativePaper.Theme;
12 /**
13 * Style that is passed to Text element.
14 */
15 style?: StyleProp<TextStyle>;
16};
17
18/**
19 * A component used to display a header in lists.
20 *
21 * ## Usage
22 * ```js
23 * import * as React from 'react';
24 * import { List } from 'react-native-paper';
25 *
26 * const MyComponent = () => <List.Subheader>My List Title</List.Subheader>;
27 *
28 * export default MyComponent;
29 * ```
30 */
31const ListSubheader = ({ style, theme, ...rest }: Props) => {
32 const { colors, fonts } = theme;
33 const font = fonts.medium;
34 const textColor = color(colors.text).alpha(0.54).rgb().string();
35
36 return (
37 <Text
38 numberOfLines={1}
39 {...rest}
40 style={[styles.container, { color: textColor, ...font }, style]}
41 />
42 );
43};
44
45ListSubheader.displayName = 'List.Subheader';
46
47const styles = StyleSheet.create({
48 container: {
49 paddingHorizontal: 16,
50 paddingVertical: 13,
51 },
52});
53
54export default withTheme(ListSubheader);