UNPKG

react-native-rounded-checkbox

Version:

Rounded Checkbox with animated and fully customizable options library for React Native

48 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const react_native_1 = require("react-native"); const react_native_bounceable_1 = tslib_1.__importDefault(require("@freakycoder/react-native-bounceable")); /** * ? Local Imports */ const PureRoundedCheckbox_style_1 = tslib_1.__importStar(require("./PureRoundedCheckbox.style")); class PureRoundedCheckbox extends React.PureComponent { constructor(props) { super(props); this.handlePress = () => { if (typeof this.props.active === "boolean") this.props.onPress && this.props.onPress(this.props.active); else this.setState({ checked: !this.state.checked }, () => this.props.onPress && this.props.onPress(this.state.checked)); }; this.state = { checked: props.isChecked || false, }; } render() { const { active, isChecked, children, text = "L", textStyle, outerStyle, innerStyle, checkedColor = "#0bc8a5", uncheckedColor = "#f0f0f0", checkedTextColor = "#fdfdfd", uncheckedTextColor = "#5c5969", onPress, ...rest } = this.props; const { checked } = this.state; const isActive = active || checked; const backgroundColor = isActive ? checkedColor : uncheckedColor; const textColor = isActive ? checkedTextColor : uncheckedTextColor; return (<react_native_bounceable_1.default {...rest} style={[ PureRoundedCheckbox_style_1.default.outerContainer, outerStyle, PureRoundedCheckbox_style_1._outerBorderWithStyle(isActive ? 1 : 0), ]} onPress={this.handlePress}> <react_native_1.View style={[ PureRoundedCheckbox_style_1.default.innerContainer, innerStyle, PureRoundedCheckbox_style_1._innerBorderWidthStyle(backgroundColor), ]}> {children || (<react_native_1.Text style={[PureRoundedCheckbox_style_1.default.textStyle, textStyle, PureRoundedCheckbox_style_1._textColorStyle(textColor)]}> {text} </react_native_1.Text>)} </react_native_1.View> </react_native_bounceable_1.default>); } } exports.default = PureRoundedCheckbox; //# sourceMappingURL=PureRoundedCheckbox.js.map