UNPKG

@fruits-chain/react-native-xiaoshu

Version:
72 lines (59 loc) 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _helpers = require("../helpers"); var _theme = require("../theme"); var _style = require("./style"); 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; } /** * Badge 徽标 * @description 在右上角展示徽标数字或小红点。 */ const Badge = _ref => { let { children, count, dot, max, color, style, countStyle, countTextStyle, loading = false, showZero = false, offset, status } = _ref; const THEME_VAR = (0, _theme.useTheme)(); const STYLES = (0, _theme.widthStyle)(THEME_VAR, _style.createStyles); if (max && typeof count === 'number' && count > max) { count = `${max}+`; } const hasCount = (0, _helpers.isDef)(count) && (count === 0 ? showZero : true); const countStyles = [STYLES.count, { backgroundColor: color || THEME_VAR[status] || THEME_VAR.badge_background_color }, dot ? STYLES.count_dot : null, (0, _helpers.isDef)(children) ? [STYLES.count_fixed, dot ? STYLES.count_dot_fixed : null, offset ? { transform: [{ translateX: offset[0] }, { translateY: offset[1] }] } : null] : [], countStyle]; const badgeJSX = !loading && (hasCount || dot) ? /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: countStyles }, dot ? null : /*#__PURE__*/_react.default.createElement(_reactNative.Text, { style: [STYLES.count_text, countTextStyle] }, count)) : null; return /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: [STYLES.badge, style], collapsable: false }, badgeJSX, children); }; var _default = /*#__PURE__*/(0, _react.memo)(Badge); exports.default = _default; //# sourceMappingURL=index.js.map