-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox.tsx
64 lines (59 loc) · 1.49 KB
/
checkbox.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
import { Check } from 'lucide-react-native';
import React, { useState } from 'react';
import { Pressable, Text, View, type TextStyle } from 'react-native';
import tw from './tailwind';
interface CustomCheckboxProps {
label: string;
onSelect: (checked: boolean) => void;
isChecked?: boolean;
color?: string;
width?: string;
textStyle?: TextStyle;
}
export function Checkbox({
label,
onSelect,
isChecked,
color,
width,
textStyle,
}: CustomCheckboxProps) {
const [checked, setChecked] = useState(isChecked || false);
const [customWidth, setCustomWidth] = useState(width ? width : '100%');
const unselectedButton = () => {
return (
<View
style={tw`h-6 w-6 rounded-lg border border-neutral bg-white items-center justify-center`}
/>
);
};
const selectedButton = () => {
return (
<View
style={tw`h-6 w-6 rounded-lg bg-${
color ? color : 'primary'
} items-center justify-center`}
>
<Check color="white" size={20} />
</View>
);
};
return (
<View
//@ts-ignore
style={tw`my-1 w-${customWidth}`}
>
<Pressable
onPress={() => {
onSelect(!checked);
setChecked(!checked);
}}
>
<View style={tw`flex-row items-center p-1 bg-transparent`}>
{checked ? selectedButton() : unselectedButton()}
<Text style={[tw`ml-3 text-base font-body`, textStyle]}>{label}</Text>
</View>
</Pressable>
</View>
);
}