UNPKG

@fruits-chain/react-native-xiaoshu

Version:
78 lines (61 loc) 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _isNil = _interopRequireDefault(require("lodash/isNil")); var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _theme = _interopRequireDefault(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; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Badge 徽标 * @description 在右上角展示徽标数字或小红点。 */ const Badge = _ref => { let { children, count, dot, max, color, style, countStyle, countTextStyle, loading = false, showZero = false, offset, status } = _ref; const TOKENS = _theme.default.useThemeTokens(); const CV = _theme.default.createVar(TOKENS, _style.varCreator); const STYLES = _theme.default.createStyle(CV, _style.styleCreator); if (!(0, _isNil.default)(max) && typeof count === 'number' && count > max) { count = `${max}+`; } const hasCount = !(0, _isNil.default)(count) && (count === 0 ? showZero : true); const countStyles = [STYLES.count, { backgroundColor: color || CV[`badge_status_${status}`] || CV.badge_background_color }, dot ? STYLES.count_dot : null, !(0, _isNil.default)(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