@fruits-chain/react-native-xiaoshu
Version:
React Native UI library
98 lines (91 loc) • 3.08 kB
JavaScript
import React, { memo, useMemo } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { useTheme, widthStyle } from '../theme';
import { CrossOutline } from '../icon';
import { hex2rgba, isDef } from '../helpers';
import { createStyles } from './style';
/**
* Tag 标签
*/
const Tag = _ref => {
let {
children,
style,
innerStyle,
textStyle,
color,
textColor,
mark = false,
outward = 'fill',
round = false,
size = 'medium',
type = 'default',
closeable = false,
onPressClose,
hairline = false
} = _ref;
const THEME_VAR = useTheme();
const STYLES = widthStyle(THEME_VAR, createStyles);
const mainColor = isDef(color) ? color : THEME_VAR[`tag_${type}_color`] || THEME_VAR.tag_default_color;
const padding_vertical_size = `padding_vertical_${size}`;
const padding_horizontal_size = `padding_horizontal_${size}`;
const {
outwardInnerStyle,
outwardTextStyle
} = useMemo(() => {
const tempInnerStyle = {};
const tempTextStyle = {};
switch (outward) {
case 'fill':
tempInnerStyle.backgroundColor = mainColor;
tempInnerStyle.borderColor = mainColor;
tempTextStyle.color = THEME_VAR.tag_text_color;
break;
case 'ghost':
tempInnerStyle.backgroundColor = THEME_VAR.tag_ghost_bg_color;
tempInnerStyle.borderColor = mainColor;
tempTextStyle.color = mainColor;
break;
case 'flat':
tempInnerStyle.backgroundColor = hex2rgba(mainColor, 0.1);
tempInnerStyle.borderColor = hex2rgba(mainColor, 0.1);
tempTextStyle.color = mainColor;
break;
default:
break;
}
return {
outwardInnerStyle: tempInnerStyle,
outwardTextStyle: tempTextStyle
};
}, [outward, mainColor, THEME_VAR.tag_text_color, THEME_VAR.tag_ghost_bg_color]);
const innerStyles = [
/** 基础样式 */
STYLES.inner,
/** 类型样式 */
outwardInnerStyle, hairline ? STYLES.border_width_hairline : null, size === 'large' && STYLES.border_radius_large, round && STYLES.border_radius_round, mark && STYLES.inner_mark,
/** 外部样式 */
innerStyle];
const textStyleSummary = StyleSheet.flatten([
/** 基础样式 */
STYLES.text,
/** 类型样式 */
outwardTextStyle, STYLES === null || STYLES === void 0 ? void 0 : STYLES[padding_vertical_size], STYLES === null || STYLES === void 0 ? void 0 : STYLES[padding_horizontal_size], size === 'large' && STYLES.font_size_large,
/** 外部样式 */
isDef(textColor) && {
color: textColor
}, textStyle]);
return /*#__PURE__*/React.createElement(View, {
style: [STYLES.tag, style]
}, /*#__PURE__*/React.createElement(View, {
style: innerStyles
}, /*#__PURE__*/React.createElement(Text, {
style: textStyleSummary
}, children), closeable ? /*#__PURE__*/React.createElement(CrossOutline, {
onPress: onPressClose,
size: textStyleSummary.fontSize,
color: textStyleSummary.color
}) : null));
};
export default /*#__PURE__*/memo(Tag);
//# sourceMappingURL=index.js.map