@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
56 lines (52 loc) • 1.63 kB
JavaScript
import isNil from 'lodash/isNil';
import React, { memo } from 'react';
import { View, Text } from 'react-native';
import Theme from '../theme';
import { varCreator, styleCreator } from './style';
/**
* Badge 徽标
* @description 在右上角展示徽标数字或小红点。
*/
const Badge = _ref => {
let {
children,
count,
dot,
max,
color,
style,
countStyle,
countTextStyle,
loading = false,
showZero = false,
offset,
status
} = _ref;
const TOKENS = Theme.useThemeTokens();
const CV = Theme.createVar(TOKENS, varCreator);
const STYLES = Theme.createStyle(CV, styleCreator);
if (!isNil(max) && typeof count === 'number' && count > max) {
count = `${max}+`;
}
const hasCount = !isNil(count) && (count === 0 ? showZero : true);
const countStyles = [STYLES.count, {
backgroundColor: color || CV[`badge_status_${status}`] || CV.badge_background_color
}, dot ? STYLES.count_dot : null, !isNil(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.createElement(View, {
style: countStyles
}, dot ? null : /*#__PURE__*/React.createElement(Text, {
style: [STYLES.count_text, countTextStyle]
}, count)) : null;
return /*#__PURE__*/React.createElement(View, {
style: [STYLES.badge, style],
collapsable: false
}, badgeJSX, children);
};
export default /*#__PURE__*/memo(Badge);
//# sourceMappingURL=index.js.map