forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDivider.tsx
78 lines (74 loc) · 1.62 KB
/
Divider.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
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as React from 'react';
import color from 'color';
import { StyleSheet, View, ViewStyle, StyleProp } from 'react-native';
import { withTheme } from '../core/theming';
import { black, white } from '../styles/colors';
import { Theme, $RemoveChildren } from '../types';
type Props = $RemoveChildren<typeof View> & {
/**
* Whether divider has a left inset.
*/
inset?: boolean;
style?: StyleProp<ViewStyle>;
/**
* @optional
*/
theme: Theme;
};
/**
* A divider is a thin, lightweight separator that groups content in lists and page layouts.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { View } from 'react-native';
* import { Divider, Text } from 'react-native-paper';
*
* const MyComponent = () => (
* <View>
* <Text>Apple</Text>
* <Divider />
* <Text>Orange</Text>
* <Divider />
* </View>
* );
*
* export default MyComponent;
* ```
*/
class Divider extends React.Component<Props> {
render() {
const { inset, style, theme, ...rest } = this.props;
const { dark: isDarkTheme } = theme;
return (
<View
{...rest}
style={[
isDarkTheme ? styles.dark : styles.light,
inset && styles.inset,
style,
]}
/>
);
}
}
const styles = StyleSheet.create({
light: {
backgroundColor: color(black)
.alpha(0.12)
.rgb()
.string(),
height: StyleSheet.hairlineWidth,
},
dark: {
backgroundColor: color(white)
.alpha(0.12)
.rgb()
.string(),
height: StyleSheet.hairlineWidth,
},
inset: {
marginLeft: 72,
},
});
export default withTheme(Divider);