UNPKG

2.33 kBJavaScriptView Raw
1var __rest = (this && this.__rest) || function (s, e) {
2 var t = {};
3 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4 t[p] = s[p];
5 if (s != null && typeof Object.getOwnPropertySymbols === "function")
6 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8 t[p[i]] = s[p[i]];
9 }
10 return t;
11};
12import React from 'react';
13import { Switch as NativeSwitch, Platform, } from 'react-native';
14import { withTheme } from '../config';
15const Switch = (_a) => {
16 var _b, _c, _d;
17 var { value = false, disabled = false, onValueChange, color = 'primary', style, theme } = _a, rest = __rest(_a, ["value", "disabled", "onValueChange", "color", "style", "theme"]);
18 // switchedOnColor deals with picking up a color provided as props by user or picks up default theme
19 const switchedOnColor = color === 'primary'
20 ? ((_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.primary) ? theme.colors.primary
21 : ''
22 : color;
23 const onTintColor = Platform.OS === 'ios' || !disabled
24 ? switchedOnColor
25 : ((_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.disabled) ? theme.colors.disabled
26 : '';
27 const thumbTintColor = Platform.OS === 'ios'
28 ? undefined
29 : disabled || !value
30 ? (_d = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _d === void 0 ? void 0 : _d.disabled : switchedOnColor;
31 const props = Platform.OS === 'web'
32 ? {
33 activeTrackColor: onTintColor,
34 thumbColor: thumbTintColor,
35 activeThumbColor: switchedOnColor,
36 }
37 : {
38 thumbColor: thumbTintColor,
39 trackColor: {
40 true: onTintColor,
41 false: '',
42 },
43 };
44 return (<NativeSwitch value={value} accessibilityState={{
45 checked: value,
46 disabled,
47 }} disabled={disabled} onValueChange={disabled ? undefined : onValueChange} style={style} {...props} {...rest}/>);
48};
49export { Switch };
50export default withTheme(Switch, 'Switch');
51
\No newline at end of file