-
Notifications
You must be signed in to change notification settings - Fork 13
/
SwitchLabeled.js
80 lines (71 loc) · 1.66 KB
/
SwitchLabeled.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// @flow
import React from 'react';
import { Switch, View, Text } from 'react-native';
import { MediaQueryStyleSheet } from 'react-native-responsive';
import GlobalStyles from '../styles';
import Colors from '../styles/colors';
type Props = {
/**
* @desc Value of the Switch.
*/
value?: boolean,
/**
* @desc Text label at the right of the Switch.
*/
label?: string,
/**
* @desc Switch alignment
*/
align?: string,
/**
* @desc Callback to be called on Switch when changes value.
*/
onValueChange?: () => void,
/**
* @desc Swich disabled status
*/
disabled?: boolean,
};
/**
* @desc Generates a standard native Switch with a Label at the right
* @return {React.Component} A component.
*/
const SwitchLabeled = ({
onValueChange, value, label, align, disabled,
}:Props) => {
const styles = MediaQueryStyleSheet.create({
...GlobalStyles,
});
const switchStyle = [styles.switchContainer];
if (align === 'right') {
switchStyle.push({
flexDirection: 'row-reverse',
});
}
const textStyle = [styles.formSwitchLabelText];
if (disabled) {
textStyle.push(styles.disabledText);
}
return (
<View style={styles.formRow}>
<View style={switchStyle}>
<Switch
disabled={disabled}
style={styles.switchObject}
onTintColor={Colors.BitnationHighlightColor}
onValueChange={onValueChange}
value={value}
/>
<Text style={textStyle}>{label}</Text>
</View>
</View>
);
};
SwitchLabeled.defaultProps = {
value: false,
label: '',
align: 'left',
disabled: false,
onValueChange: () => undefined,
};
export default SwitchLabeled;