import React, { forwardRef } from 'react'; import type { Ref } from 'react'; import { StyleSheet } from 'react-native'; import type { StyleProp, ViewStyle } from 'react-native'; import { isNil } from 'lodash'; import Dropdown from '../Dropdown'; import type { DropdownItemProps } from '../Dropdown/interface'; import { DropdownItemOption } from '../../core'; import type { ItemRef } from '../../core'; import { mergeProps } from '../../core/helpers'; import useFilterItemStyles from './hooks/useFilterItemStyles'; import createStyle from './styles/filter-item.style'; import { IconXLowersmall1, IconXUppersmall1, } from '../../icons'; import { useTheme } from '../Theme/Theme'; // @ts-ignore export interface FilterItemProps extends DropdownItemProps { /** * 选项数组 */ options?: DropdownItemOption[]; /** * 自定义样式属性 */ style?: StyleProp; /** * 每一个Item标题的 numberOfLines,默认为 1,通常搭配 ellipsizeMode 使用 */ numberOfLines?: number; /** * 标题样式 */ cusTextStyle?: StyleProp; } const FilterItem = (p: FilterItemProps, ref: Ref) => { const token = useTheme(); const styles = createStyle(token); const defaultProps = { options: [], arrowIconColor: token['--color-text-5'], arrowIconActiveColor: token['--color-primary-6'], iconSize: token['--font-size-3'], }; const allProps: FilterItemProps = mergeProps(defaultProps, p); const { options = [], titleStyle, arrowIconColor, arrowIconActiveColor, iconSize, titleTextStyle, textActiveStyle, style, itemLabel, useNative = false, ...props } = allProps; const { titleStyle: getTitleStyle } = useFilterItemStyles(); const getArrowIconColor = () => { // 如果当前项中有值,则高亮展示 if (!isNil(itemLabel)) { return arrowIconActiveColor; } return arrowIconColor; }; return ( // @ts-ignore { if (active) { const color = !isNil(itemLabel) || active ? arrowIconActiveColor : arrowIconColor; return ( ); } else { const color = !isNil(itemLabel) ? arrowIconActiveColor : arrowIconColor; return ( ); } } } /> ); }; export default forwardRef(FilterItem);