UNPKG

@fruits-chain/react-native-xiaoshu

Version:
87 lines (86 loc) • 4.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _color = _interopRequireDefault(require("color")); var _isNil = _interopRequireDefault(require("lodash/isNil")); var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../helpers/index.js"); var _index2 = _interopRequireDefault(require("../theme/index.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 }; } const ButtonOption = ({ theme, active, activeHighlight = true, badge, type = 'hazy', text, textStyle, size = 's', hairline, round = false, style, children, ...restProps }) => { const [CV, STYLES, TOKENS] = _index2.default.useStyle({ varCreator: _style.varCreator, styleCreator: _style.styleCreator, theme }); const inactiveBackgroundColor = (0, _react.useMemo)(() => { if (type === 'outline') { return TOKENS.white; } if (type === 'white') { return TOKENS.white; } return TOKENS.gray_2; }, [TOKENS.gray_2, TOKENS.white, type]); const inactiveBorderColor = (0, _react.useMemo)(() => { if (restProps.disabled) { if (type === 'white') { return TOKENS.white; } return CV.button_option_disabled_border_color; } if (type === 'outline') { return TOKENS.gray_5; } if (type === 'white') { return TOKENS.white; } return inactiveBackgroundColor; }, [CV.button_option_disabled_border_color, TOKENS.gray_5, TOKENS.white, inactiveBackgroundColor, restProps.disabled, type]); const activeBackgroundColor = (0, _react.useMemo)(() => (0, _color.default)(CV.button_primary_color).fade(0.89).string(), [CV.button_primary_color]); const buttonStyles = [STYLES.button, STYLES.option, { height: CV[`button_${size}_height`], backgroundColor: active && activeHighlight ? activeBackgroundColor : inactiveBackgroundColor, borderColor: active ? CV.button_primary_color : inactiveBorderColor, borderWidth: hairline ? _reactNative.StyleSheet.hairlineWidth : 1 }, STYLES[`button_${size}_padding_horizontal`], round ? STYLES.button_round : null, restProps.disabled ? STYLES.button_disabled : null, style]; const childrenJSX = /*#__PURE__*/(0, _react.isValidElement)(children) ? children : (0, _index.renderTextLikeJSX)(!(0, _isNil.default)(children) ? children : text, [{ color: restProps.disabled ? CV.button_option_disabled_text_color : active && activeHighlight ? CV.button_primary_color : TOKENS.gray_8, fontSize: CV[`button_${size}_font_size`] }, textStyle]); const badgeTextJSX = (0, _index.renderTextLikeJSX)(badge, [STYLES.option_badge_text]); const badgeJSX = !(0, _isNil.default)(badgeTextJSX) ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: STYLES.option_badge, children: badgeTextJSX }) : null; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { accessibilityRole: "button", ...restProps, activeOpacity: CV.button_active_opacity, style: buttonStyles, children: [childrenJSX, badgeJSX] }); }; var _default = exports.default = /*#__PURE__*/(0, _react.memo)(ButtonOption); //# sourceMappingURL=button-option.js.map