@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
75 lines (69 loc) • 3.13 kB
JavaScript
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); }
import isNil from 'lodash/isNil';
import React, { memo } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { varCreator as varCreatorButton } from '../button/style';
import { getDefaultValue } from '../helpers';
import { getArrowOutline } from '../icon/helper/arrow';
import Theme from '../theme';
import { useDropdownConfig } from './context';
import DropdownBadge from './dropdown-badge';
import { varCreator, styleCreator } from './style';
const DropdownText = _ref => {
let {
textStyle,
iconStyle,
disabled = false,
title,
active = false,
pressable = true,
activeColor,
direction,
badge,
// TouchableOpacity 属性
style,
activeOpacity,
...restProps
} = _ref;
const config = useDropdownConfig();
const TOKENS = Theme.useThemeTokens();
const CV = Theme.createVar(TOKENS, varCreator);
const STYLES = Theme.createStyle(CV, styleCreator);
const CV_BUTTON = Theme.createVar(TOKENS, varCreatorButton);
const showBadge = !active && !isNil(badge) && badge !== false; // 修正数据
activeColor = getDefaultValue(activeColor, config.activeColor);
activeOpacity = getDefaultValue(activeOpacity, CV_BUTTON.button_active_opacity);
direction = getDefaultValue(direction, config.direction);
const textColor = disabled ? CV.dropdown_text_disabled_color : active ? activeColor : CV.dropdown_text_color;
const itemStyles = [STYLES.text_item, config.titleStyle, style];
const textStyles = [STYLES.text_text, showBadge ? null : STYLES.text_text_gap, config.titleTextStyle, {
color: textColor
}, textStyle];
const iconStyles = [config.iconStyle, iconStyle].filter(Boolean);
const ArrowFill = getArrowOutline(active ? direction === 'up' ? 'down' : 'up' : direction);
const ctxJSX = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
style: STYLES.text_text_container
}, /*#__PURE__*/React.createElement(Text, {
style: textStyles,
numberOfLines: 1
}, title)), showBadge ? /*#__PURE__*/React.createElement(DropdownBadge, {
count: badge,
style: [STYLES.text_text_badge, STYLES.text_text_gap]
}) : null, /*#__PURE__*/React.createElement(ArrowFill, {
style: iconStyles.length ? iconStyles : undefined,
size: CV.dropdown_text_icon_size,
color: active ? activeColor : CV.dropdown_text_icon_color
}));
if (pressable) {
return /*#__PURE__*/React.createElement(TouchableOpacity, _extends({}, restProps, {
disabled: disabled,
style: itemStyles,
activeOpacity: activeOpacity
}), ctxJSX);
}
return /*#__PURE__*/React.createElement(View, _extends({}, restProps, {
style: itemStyles
}), ctxJSX);
};
export default /*#__PURE__*/memo(DropdownText);
//# sourceMappingURL=dropdown-text.js.map