-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (41 loc) · 1.17 KB
/
index.js
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
/*
* Project: react-native-unordered-list
* File: /index.js
* Author: Qi Xi
* Email: [email protected]
* File Created: Wednesday, 22nd January 2020 10:46:46 pm
* Description: react-native unordered list component
*/
import React from 'react';
import { Text, StyleSheet, View } from 'react-native';
const bullets = ['\u2022', '\u25E6', '\u25AA'];
const styles = StyleSheet.create({
bulletPointLine: {
flexDirection: 'row',
alignItems: 'flex-start'
},
bulletPointText: {
flex: 1,
paddingLeft: 5
}
});
export default ({ children, unorderedListLevel, bulletUnicode, color, style }) => {
const level = !unorderedListLevel ? 0 : unorderedListLevel;
const newChildren = React.Children.map(children, (child) => {
return React.cloneElement(child, {
unorderedListLevel: level + 1
});
});
return (
<View style={styles.bulletPointLine}>
<Text style={[style, { color }]}>
{bulletUnicode
? String.fromCharCode(bulletUnicode)
: level > bullets.length
? bullets[bullets.length - 1]
: bullets[level]}
</Text>
<View style={styles.bulletPointText}>{newChildren}</View>
</View>
);
};