-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathColorPickerRow.tsx
More file actions
92 lines (88 loc) · 2.08 KB
/
Copy pathColorPickerRow.tsx
File metadata and controls
92 lines (88 loc) · 2.08 KB
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
import { type FC } from 'react';
import { Pressable, ScrollView, StyleSheet, Text } from 'react-native';
interface Props {
colors: string[];
activeColor: string;
onSelectColor: (color: string) => void;
onClear: () => void;
}
export const ColorPickerRow: FC<Props> = ({
colors,
activeColor,
onSelectColor,
onClear,
}) => {
return (
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
style={styles.container}
contentContainerStyle={styles.content}
>
<Pressable
testID="color-swatch-clear"
style={styles.clearButton}
onPress={onClear}
>
<Text style={styles.clearText}>✕</Text>
</Pressable>
{colors.map((color) => {
const isActive = color.toLowerCase() === activeColor?.toLowerCase();
const swatchId = `color-swatch-${color.replace('#', '').toUpperCase()}`;
return (
<Pressable
key={color}
testID={swatchId}
onPress={() => onSelectColor(color)}
style={[
styles.swatch,
{ backgroundColor: color },
isActive && styles.swatchActive,
color === '#FFFFFF' && styles.swatchBordered,
]}
/>
);
})}
</ScrollView>
);
};
const SWATCH_SIZE = 28;
const styles = StyleSheet.create({
container: {
width: '100%',
backgroundColor: 'rgba(0, 26, 114, 0.9)',
},
content: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 8,
paddingVertical: 8,
gap: 8,
},
clearButton: {
width: SWATCH_SIZE,
height: SWATCH_SIZE,
borderRadius: SWATCH_SIZE / 2,
backgroundColor: 'rgba(255,255,255,0.15)',
justifyContent: 'center',
alignItems: 'center',
},
clearText: {
color: 'white',
fontSize: 14,
lineHeight: 16,
},
swatch: {
width: SWATCH_SIZE,
height: SWATCH_SIZE,
borderRadius: SWATCH_SIZE / 2,
},
swatchActive: {
borderWidth: 3,
borderColor: 'white',
},
swatchBordered: {
borderWidth: 1,
borderColor: 'rgba(0,0,0,0.25)',
},
});