forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListSubheader.tsx
65 lines (59 loc) · 1.38 KB
/
ListSubheader.tsx
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
import * as React from 'react';
import { StyleSheet, StyleProp, TextStyle } from 'react-native';
import color from 'color';
import Text from '../Typography/Text';
import { withTheme } from '../../core/theming';
import { Theme } from '../../types';
type Props = React.ComponentProps<typeof Text> & {
/**
* @optional
*/
theme: Theme;
/**
* Style that is passed to Text element.
*/
style?: StyleProp<TextStyle>;
};
/**
* A component used to display a header in lists.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { List } from 'react-native-paper';
*
* class MyComponent extends React.Component {
* render () {
* return <List.Subheader>My List Title</List.Subheader>;
* }
* }
*
* export default MyComponent;
* ```
*/
class ListSubheader extends React.Component<Props> {
static displayName = 'List.Subheader';
render() {
const { style, theme, ...rest } = this.props;
const { colors, fonts } = theme;
const font = fonts.medium;
const textColor = color(colors.text)
.alpha(0.54)
.rgb()
.string();
return (
<Text
numberOfLines={1}
{...rest}
style={[styles.container, { color: textColor, ...font }, style]}
/>
);
}
}
const styles = StyleSheet.create({
container: {
paddingHorizontal: 16,
paddingVertical: 13,
},
});
export default withTheme(ListSubheader);