UNPKG

@fruits-chain/react-native-xiaoshu

Version:
102 lines (83 loc) 4.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _theme = require("../theme"); var _loading = _interopRequireDefault(require("../loading")); var _style = require("./style"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /** * Button 按钮 * @description 按钮用于触发一个操作,如提交表单。 */ const Button = _ref => { let { children, style, text, textStyle, type = 'default', size = 'default', ghost = false, hairline = false, disabled = false, loading = false, loadingText, square = false, round = false, renderLeftIcon, color, textColor, ...otherProps } = _ref; const THEME_VAR = (0, _theme.useTheme)(); const STYLES = (0, _theme.widthStyle)(THEME_VAR, _style.createStyles); const commonButtonStyle = _reactNative.StyleSheet.flatten([STYLES.button, { backgroundColor: THEME_VAR[`button_${type}_background_color`] || THEME_VAR.button_default_background_color, borderColor: THEME_VAR[`button_${type}_border_color`] || THEME_VAR.button_default_border_color, height: THEME_VAR[`button_${size}_height`] || THEME_VAR.button_default_font_size }, STYLES[`button_${size}`], hairline ? STYLES.button_border_width_hairline : null, square ? STYLES.button_square : null, round ? STYLES.button_round : null, color ? { backgroundColor: color, borderColor: color } : null, disabled ? STYLES.button_disabled : null]); const commonTextStyle = _reactNative.StyleSheet.flatten([STYLES.text, { color: THEME_VAR[`button_${type}_color`] || THEME_VAR.button_default_color, fontSize: THEME_VAR[`button_${type}_font_size`] || THEME_VAR.button_default_font_size }, color || textColor ? { color: textColor || '#fff' } : null]); if (ghost) { commonButtonStyle.backgroundColor = THEME_VAR.button_ghost_background_color; commonTextStyle.color = commonButtonStyle.borderColor; if (type === 'default') { commonButtonStyle.borderColor = '#BEC6D2'; commonTextStyle.color = THEME_VAR.primary; } } const textStyleSummary = _reactNative.StyleSheet.flatten([commonTextStyle, textStyle]); const iconSize = THEME_VAR[`button_${size}_loading_size`] || 24; const iconColor = textStyleSummary.color; const contextJSX = loading ? /*#__PURE__*/_react.default.createElement(_loading.default, { type: "spinner", color: iconColor, size: iconSize, textSize: textStyleSummary.fontSize }, loadingText) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderLeftIcon ? renderLeftIcon(iconColor, iconSize) : null, /*#__PURE__*/_react.default.createElement(_reactNative.Text, { style: textStyleSummary, numberOfLines: 1 }, text || children)); return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, _extends({ disabled: disabled || loading, style: [commonButtonStyle, style], activeOpacity: THEME_VAR.button_active_opacity }, otherProps), contextJSX); }; var _default = /*#__PURE__*/(0, _react.memo)(Button); exports.default = _default; //# sourceMappingURL=index.js.map