@nexara/nativeflow
Version:
Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.
46 lines (45 loc) • 1.42 kB
JavaScript
;
import { Switch as NativeSwitch } from "react-native";
import { verticalScale } from "../../helpers/ResponsiveCalculations.js";
import { useTheme } from "../../hooks/index.js";
import Color from "color";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
const Switch = ({
checked = true,
color,
disabled = false,
size = 0.9,
activeTrackColor,
inactiveTrackColor,
onChange,
...rest
}) => {
const {
colors
} = useTheme();
const switchColor = disabled ? colors.states.disabled : color ?? colors.brand.primary;
const disabledAndInActiveTrackColor = colors.palette.natural[200];
const generateActiveTrackColor = Color(colors.brand.primary).lighten(0).alpha(0.3).rgb().string();
return /*#__PURE__*/_jsx(_Fragment, {
children: /*#__PURE__*/_jsx(NativeSwitch, {
value: checked,
trackColor: {
true: disabled && disabledAndInActiveTrackColor || (activeTrackColor ?? generateActiveTrackColor),
false: disabled && disabledAndInActiveTrackColor || (inactiveTrackColor ?? disabledAndInActiveTrackColor)
},
thumbColor: switchColor,
onValueChange: onChange,
style: {
transform: [{
scaleX: verticalScale(size)
}, {
scaleY: verticalScale(size)
}]
},
disabled: disabled,
...rest
})
});
};
export default Switch;
//# sourceMappingURL=Switch.js.map