-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathCheckbox.tsx
More file actions
82 lines (77 loc) · 1.81 KB
/
Checkbox.tsx
File metadata and controls
82 lines (77 loc) · 1.81 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
import * as React from 'react';
import { GestureResponderEvent, Platform } from 'react-native';
import CheckboxAndroid from './CheckboxAndroid';
import CheckboxIOS from './CheckboxIOS';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../types';
export type Props = {
/**
* 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 unchecked checkbox.
*/
uncheckedColor?: string;
/**
* 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.
*
* ## Usage
* ```js
* import * as React from 'react';
* import { Checkbox } from 'react-native-paper';
*
* const MyComponent = () => {
* const [checked, setChecked] = React.useState(false);
*
* return (
* <Checkbox
* status={checked ? 'checked' : 'unchecked'}
* onPress={() => {
* setChecked(!checked);
* }}
* />
* );
* };
*
* export default MyComponent;
* ```
*/
const Checkbox = ({ theme: themeOverrides, ...props }: Props) => {
const theme = useInternalTheme(themeOverrides);
return Platform.OS === 'ios' ? (
<CheckboxIOS {...props} theme={theme} />
) : (
<CheckboxAndroid {...props} theme={theme} />
);
};
export default Checkbox;
// @component-docs ignore-next-line
const CheckboxWithTheme = Checkbox;
// @component-docs ignore-next-line
export { CheckboxWithTheme as Checkbox };