-
Notifications
You must be signed in to change notification settings - Fork 457
/
checkbox.js
57 lines (51 loc) · 1.54 KB
/
checkbox.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
var React = require("react");
var { View, Text, Switch } = require("react-native");
function checkbox(locals) {
if (locals.hidden) {
return null;
}
var stylesheet = locals.stylesheet;
var formGroupStyle = stylesheet.formGroup.normal;
var controlLabelStyle = stylesheet.controlLabel.normal;
var checkboxStyle = stylesheet.checkbox.normal;
var helpBlockStyle = stylesheet.helpBlock.normal;
var errorBlockStyle = stylesheet.errorBlock;
if (locals.hasError) {
formGroupStyle = stylesheet.formGroup.error;
controlLabelStyle = stylesheet.controlLabel.error;
checkboxStyle = stylesheet.checkbox.error;
helpBlockStyle = stylesheet.helpBlock.error;
}
var label = locals.label ? (
<Text style={controlLabelStyle}>{locals.label}</Text>
) : null;
var help = locals.help ? (
<Text style={helpBlockStyle}>{locals.help}</Text>
) : null;
var error =
locals.hasError && locals.error ? (
<Text accessibilityLiveRegion="polite" style={errorBlockStyle}>
{locals.error}
</Text>
) : null;
return (
<View style={formGroupStyle}>
{label}
<Switch
accessibilityLabel={locals.label}
ref="input"
disabled={locals.disabled}
onTintColor={locals.onTintColor}
thumbTintColor={locals.thumbTintColor}
tintColor={locals.tintColor}
style={checkboxStyle}
onValueChange={value => locals.onChange(value)}
value={locals.value}
testID={locals.testID}
/>
{help}
{error}
</View>
);
}
module.exports = checkbox;