-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathCheckboxIOS.tsx
More file actions
111 lines (101 loc) · 2.65 KB
/
CheckboxIOS.tsx
File metadata and controls
111 lines (101 loc) · 2.65 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import * as React from 'react';
import { GestureResponderEvent, StyleSheet, View } from 'react-native';
import { getSelectionControlIOSColor } from './utils';
import { useInternalTheme } from '../../core/theming';
import type { $RemoveChildren, ThemeProp } from '../../types';
import MaterialCommunityIcon from '../MaterialCommunityIcon';
import TouchableRipple from '../TouchableRipple/TouchableRipple';
export type Props = $RemoveChildren<typeof TouchableRipple> & {
/**
* Status of checkbox.
*/
status: 'checked' | 'unchecked' | 'indeterminate';
/**
* Whether checkbox is disabled.
*/
disabled?: boolean;
/**
* Function to execute on press.
*/
onPress?: (e: GestureResponderEvent) => void;
/**
* Custom color for checkbox.
*/
color?: string;
/**
* @optional
*/
theme?: ThemeProp;
/**
* testID to be used on tests.
*/
testID?: string;
/**
* custom icon.
*/
icon?: (props: { size: number; color: string }) => JSX.Element;
};
/**
* Checkboxes allow the selection of multiple options from a set.
* This component follows platform guidelines for iOS, but can be used
* on any platform.
*
* @extends TouchableRipple props https://callstack.github.io/react-native-paper/docs/components/TouchableRipple
*/
const CheckboxIOS = ({
status,
disabled,
onPress,
theme: themeOverrides,
testID,
icon: customIcon,
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const checked = status === 'checked';
const indeterminate = status === 'indeterminate';
const { checkedColor, rippleColor } = getSelectionControlIOSColor({
theme,
disabled,
customColor: rest.color,
});
const icon = indeterminate ? 'minus' : 'check';
const opacity = indeterminate || checked ? 1 : 0;
return (
<TouchableRipple
{...rest}
borderless
rippleColor={rippleColor}
onPress={onPress}
disabled={disabled}
accessibilityRole="checkbox"
accessibilityState={{ disabled, checked }}
accessibilityLiveRegion="polite"
style={styles.container}
testID={testID}
theme={theme}
>
<View style={{ opacity }}>
{customIcon?.({ size: 24, color: checkedColor }) || (
<MaterialCommunityIcon
allowFontScaling={false}
name={icon}
size={24}
color={checkedColor}
direction="ltr"
/>
)}
</View>
</TouchableRipple>
);
};
CheckboxIOS.displayName = 'Checkbox.IOS';
const styles = StyleSheet.create({
container: {
borderRadius: 18,
padding: 6,
},
});
export default CheckboxIOS;
// @component-docs ignore-next-line
export { CheckboxIOS };