UNPKG

@fruits-chain/react-native-xiaoshu

Version:
82 lines (81 loc) • 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _isNil = _interopRequireDefault(require("lodash/isNil")); var _omit = _interopRequireDefault(require("lodash/omit")); var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../helpers/index.js"); var _index2 = require("../hooks/index.js"); var _index3 = _interopRequireDefault(require("../theme/index.js")); var _checkboxIcon = _interopRequireDefault(require("./checkbox-icon.js")); var _style = require("./style.js"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function Checkbox({ theme, labelTextStyle, iconStyle, activeValue = true, inactiveValue = false, label, labelDisabled = false, labelPosition = 'right', iconSize = 20, renderIcon, disabled, activeColor, gap, style, children, ...restProps }) { if (disabled) { labelDisabled = disabled; } const [value, onChange] = (0, _index2.useControllableValue)(restProps, { defaultValue: inactiveValue }); const [CV, STYLES] = _index3.default.useStyle({ varCreator: _style.varCreator, styleCreator: _style.styleCreator, theme }); const _gap = (0, _index.getDefaultValue)(gap, CV.checkbox_label_margin); const active = value === activeValue; const onChangeValue = () => { const newValue = active ? inactiveValue : activeValue; onChange(newValue); }; const labelJSX = !(0, _isNil.default)(label) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { suppressHighlighting: true, style: [STYLES.label, { [labelPosition === 'left' ? 'marginRight' : 'marginLeft']: _gap }, disabled ? STYLES.label_disabled : null, labelTextStyle], onPress: labelDisabled ? undefined : onChangeValue, children: label }) : children; const iconProps = { style: iconStyle, active, activeColor, disabled, size: iconSize, onPress: onChangeValue }; const iconJSX = renderIcon ? renderIcon(iconProps) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkboxIcon.default, { testID: "CHECKBOX_ICON", ...iconProps }); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { ...(0, _omit.default)(restProps, ['value', 'defaultValue', 'onChange']), style: [STYLES.checkbox, style], children: [labelPosition === 'left' ? labelJSX : null, iconJSX, labelPosition === 'right' ? labelJSX : null] }); } var _default = exports.default = /*#__PURE__*/(0, _react.memo)(Checkbox); //# sourceMappingURL=checkbox.js.map