forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareEnumeratedWords.js
81 lines (76 loc) · 2.37 KB
/
SquareEnumeratedWords.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
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
import React from 'react';
import { useTheme } from '@react-navigation/native';
import { TouchableOpacity, Text, StyleSheet, View } from 'react-native';
import PropTypes from 'prop-types';
export const SquareEnumeratedWordsContentAlign = Object.freeze({ left: 'flex-start', center: 'center', right: 'flex-end' });
const SquareEnumeratedWords = props => {
const {
entries = ['Empty entries prop. Please provide an array of strings'],
appendNumber = true,
contentAlign = SquareEnumeratedWordsContentAlign.center,
} = props;
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
entryTextContainer: {
backgroundColor: colors.inputBackgroundColor,
},
entryText: {
color: colors.labelText,
},
});
const renderSecret = () => {
const component = [];
const entriesObject = entries.entries();
for (const [index, secret] of entriesObject) {
if (entries.length > 1) {
const text = appendNumber ? `${index + 1}. ${secret} ` : `${secret} `;
component.push(
<View style={[styles.entryTextContainer, stylesHook.entryTextContainer]} key={`${secret}${index}`}>
<Text textBreakStrategy="simple" style={[styles.entryText, stylesHook.entryText]}>
{text}
</Text>
</View>,
);
} else {
component.push(
<TouchableOpacity
accessibilityRole="button"
style={[styles.entryTextContainer, stylesHook.entryTextContainer]}
key={`${secret}${index}`}
>
<Text textBreakStrategy="simple" style={[styles.entryText, stylesHook.entryText]}>
{secret}
</Text>
</TouchableOpacity>,
);
}
}
return component;
};
return <View style={[styles.container, { justifyContent: contentAlign }]}>{renderSecret()}</View>;
};
const styles = StyleSheet.create({
entryTextContainer: {
marginRight: 8,
marginBottom: 8,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 8,
paddingRight: 8,
borderRadius: 4,
},
entryText: {
fontWeight: 'bold',
textAlign: 'left',
},
container: {
flexDirection: 'row',
flexWrap: 'wrap',
},
});
SquareEnumeratedWords.propTypes = {
entries: PropTypes.arrayOf(PropTypes.string),
contentAlign: PropTypes.string,
appendNumber: PropTypes.bool,
};
export default SquareEnumeratedWords;