-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathDivider.tsx
102 lines (94 loc) · 2.22 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import * as React from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import color from 'color';
import { useInternalTheme } from '../core/theming';
import { black, white } from '../styles/themes/v2/colors';
import type { $RemoveChildren, ThemeProp } from '../types';
export type Props = $RemoveChildren<typeof View> & {
/**
* @renamed Renamed from 'inset' to 'leftInset` in v5.x
* Whether divider has a left inset.
*/
leftInset?: boolean;
/**
* @supported Available in v5.x with theme version 3
* Whether divider has a horizontal inset on both sides.
*/
horizontalInset?: boolean;
/**
* @supported Available in v5.x with theme version 3
* Whether divider should be bolded.
*/
bold?: boolean;
style?: StyleProp<ViewStyle>;
/**
* @optional
*/
theme?: ThemeProp;
};
/**
* 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>Lemon</Text>
* <Divider />
* <Text>Mango</Text>
* <Divider />
* </View>
* );
*
* export default MyComponent;
* ```
*/
const Divider = ({
leftInset,
horizontalInset = false,
style,
theme: themeOverrides,
bold = false,
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const { dark: isDarkTheme, isV3 } = theme;
const dividerColor = isV3
? theme.colors.outlineVariant
: color(isDarkTheme ? white : black)
.alpha(0.12)
.rgb()
.string();
return (
<View
{...rest}
style={[
{ height: StyleSheet.hairlineWidth, backgroundColor: dividerColor },
leftInset && (isV3 ? styles.v3LeftInset : styles.leftInset),
isV3 && horizontalInset && styles.horizontalInset,
isV3 && bold && styles.bold,
style,
]}
/>
);
};
const styles = StyleSheet.create({
leftInset: {
marginLeft: 72,
},
v3LeftInset: {
marginLeft: 16,
},
horizontalInset: {
marginLeft: 16,
marginRight: 16,
},
bold: {
height: 1,
},
});
export default Divider;