@arpitbhalla/rneui-base-dev
Version:
Cross Platform React Native UI Toolkit
99 lines (98 loc) • 5.78 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckBox = void 0;
var react_1 = __importDefault(require("react"));
var react_native_1 = require("react-native");
var Text_1 = require("../Text");
var CheckBoxIcon_1 = require("./components/CheckBoxIcon");
var helpers_1 = require("../helpers");
var helpers_2 = require("../helpers");
var CheckBox = function (_a) {
var _b, _c, _d;
var _e = _a.checked, checked = _e === void 0 ? false : _e, _f = _a.Component, Component = _f === void 0 ? react_native_1.Pressable : _f, _g = _a.iconRight, iconRight = _g === void 0 ? false : _g, title = _a.title, _h = _a.titleProps, titleProps = _h === void 0 ? {} : _h, _j = _a.center, center = _j === void 0 ? false : _j, _k = _a.right, right = _k === void 0 ? false : _k, containerStyle = _a.containerStyle, wrapperStyle = _a.wrapperStyle, textStyle = _a.textStyle, checkedTitle = _a.checkedTitle, fontFamily = _a.fontFamily, _l = _a.theme, theme = _l === void 0 ? helpers_2.defaultTheme : _l, onPress = _a.onPress, onLongPress = _a.onLongPress, _m = _a.disabled, disabled = _m === void 0 ? false : _m, disabledStyle = _a.disabledStyle, disabledTitleStyle = _a.disabledTitleStyle, _o = _a.checkedColor, checkedColor = _o === void 0 ? (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.primary : _o, rest = __rest(_a, ["checked", "Component", "iconRight", "title", "titleProps", "center", "right", "containerStyle", "wrapperStyle", "textStyle", "checkedTitle", "fontFamily", "theme", "onPress", "onLongPress", "disabled", "disabledStyle", "disabledTitleStyle", "checkedColor"]);
var accessibilityState = {
checked: !!checked,
};
var iconProps = __assign({ checked: checked, onLongPress: onLongPress, checkedColor: checkedColor }, rest);
return (react_1.default.createElement(Component, __assign({ accessibilityRole: "checkbox", accessibilityState: accessibilityState, testID: "RNE__CheckBox__Wrapper" }, rest, { disabled: disabled, onLongPress: onLongPress, onPress: onPress, style: react_native_1.StyleSheet.flatten([
{
backgroundColor: theme.colors.background,
borderColor: theme.colors.white,
},
styles.container,
containerStyle && containerStyle,
disabled && disabledStyle,
]) }),
react_1.default.createElement(react_native_1.View, { style: react_native_1.StyleSheet.flatten([
styles.wrapper,
right && { justifyContent: 'flex-end' },
center && { justifyContent: 'center' },
wrapperStyle && wrapperStyle,
]) },
!iconRight && (react_1.default.createElement(CheckBoxIcon_1.CheckBoxIcon, __assign({}, iconProps, { checkedColor: checkedColor }))),
react_1.default.isValidElement(title)
? title
: title !== '' &&
title && (react_1.default.createElement(Text_1.Text, __assign({ testID: "RNE__CheckBox__Title", style: react_native_1.StyleSheet.flatten([
__assign({ marginLeft: 10, marginRight: 10, color: (_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.grey1 }, react_native_1.Platform.select({
android: __assign({}, helpers_1.fonts.android.bold),
default: {
fontWeight: 'bold',
},
})),
textStyle && textStyle,
fontFamily && { fontFamily: fontFamily },
disabled && {
color: (0, helpers_2.color)((_d = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _d === void 0 ? void 0 : _d.disabled)
.darken(0.3)
.string(),
},
disabled && disabledTitleStyle,
]) }, titleProps), checked ? checkedTitle || title : title)),
iconRight && (react_1.default.createElement(CheckBoxIcon_1.CheckBoxIcon, __assign({}, iconProps, { checkedColor: checkedColor }))))));
};
exports.CheckBox = CheckBox;
var styles = react_native_1.StyleSheet.create({
wrapper: {
flexDirection: 'row',
alignItems: 'center',
},
container: {
margin: 5,
marginLeft: 10,
marginRight: 10,
padding: 10,
},
containerHasTitle: {
borderWidth: 1,
borderRadius: 3,
backgroundColor: '#fafafa',
borderColor: '#ededed',
},
});
exports.CheckBox.displayName = 'CheckBox';