All files / app/(tabs)/ranking/components FilterChips.tsx

100% Statements 5/5
80.55% Branches 29/36
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                                    6x 6x   6x                                                                                     1x                                               1x                                                                                                              
import { Pressable, ScrollView } from 'react-native';
import { Text, XStack } from 'tamagui';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
 
interface FilterChipsProps {
  sortBy: 'score' | 'likes';
  selectedBrand: string;
  onSortChange: (sort: 'score' | 'likes') => void;
  onResetFilters: () => void;
  onToggleBrandMenu: () => void;
  brandMenuExpanded: boolean;
}
 
/**
 * 快捷筛选标签组件
 * 用于排序和品牌筛选
 */
export function FilterChips({
  sortBy,
  selectedBrand,
  onSortChange,
  onResetFilters,
  onToggleBrandMenu,
  brandMenuExpanded,
}: FilterChipsProps) {
  const colors = useThemeColors();
  const isDark = useIsDarkMode();
 
  return (
    <ScrollView
      horizontal
      showsHorizontalScrollIndicator={false}
      contentContainerStyle={{
        paddingHorizontal: 16,
        paddingBottom: 16,
        gap: 10,
      }}
    >
      {/* 综合推荐 */}
      <Pressable onPress={onResetFilters}>
        <XStack
          paddingHorizontal="$4"
          paddingVertical="$2.5"
          borderRadius="$12"
          backgroundColor={
            (sortBy === 'score' && selectedBrand === 'all'
              ? colors.selected
              : colors.cardBackground) as any
          }
          borderWidth={2}
          borderColor={
            (sortBy === 'score' && selectedBrand === 'all' ? colors.primary : colors.border) as any
          }
          alignItems="center"
        >
          <Text
            fontSize={14}
            fontWeight="700"
            color={
              (sortBy === 'score' && selectedBrand === 'all'
                ? colors.primary
                : colors.textSecondary) as any
            }
            letterSpacing={0.3}
          >
            综合推荐
          </Text>
        </XStack>
      </Pressable>
 
      {/* 高评分 */}
      <Pressable onPress={() => onSortChange('score')}>
        <XStack
          paddingHorizontal="$4"
          paddingVertical="$2.5"
          borderRadius="$12"
          backgroundColor={
            (sortBy === 'score' ? colors.warningMuted : colors.cardBackground) as any
          }
          borderWidth={2}
          borderColor={(sortBy === 'score' ? colors.warning : colors.border) as any}
          alignItems="center"
        >
          <Text
            fontSize={14}
            fontWeight="700"
            color={(sortBy === 'score' ? colors.warning : colors.textSecondary) as any}
            letterSpacing={0.3}
          >
            高评分
          </Text>
        </XStack>
      </Pressable>
 
      {/* 最受欢迎 */}
      <Pressable onPress={() => onSortChange('likes')}>
        <XStack
          paddingHorizontal="$4"
          paddingVertical="$2.5"
          borderRadius="$12"
          backgroundColor={(sortBy === 'likes' ? colors.errorMuted : colors.cardBackground) as any}
          borderWidth={2}
          borderColor={(sortBy === 'likes' ? colors.error : colors.border) as any}
          alignItems="center"
        >
          <Text
            fontSize={14}
            fontWeight="700"
            color={(sortBy === 'likes' ? colors.error : colors.textSecondary) as any}
            letterSpacing={0.3}
          >
            最受欢迎
          </Text>
        </XStack>
      </Pressable>
 
      {/* 品牌筛选 */}
      <Pressable onPress={onToggleBrandMenu}>
        <XStack
          paddingHorizontal="$4"
          paddingVertical="$2.5"
          borderRadius="$12"
          backgroundColor={
            (selectedBrand !== 'all' ? colors.selected : colors.cardBackground) as any
          }
          borderWidth={2}
          borderColor={(selectedBrand !== 'all' ? colors.primary : colors.border) as any}
          gap="$2"
          alignItems="center"
        >
          <Text
            fontSize={14}
            fontWeight="700"
            color={(selectedBrand !== 'all' ? colors.primary : colors.textSecondary) as any}
            letterSpacing={0.3}
            numberOfLines={1}
            maxWidth={120}
          >
            {selectedBrand === 'all' ? '品牌' : selectedBrand}
          </Text>
          <IconSymbol
            name={brandMenuExpanded ? 'chevron.up' : 'chevron.down'}
            size={14}
            color={(selectedBrand !== 'all' ? colors.primary : colors.textTertiary) as any}
          />
        </XStack>
      </Pressable>
    </ScrollView>
  );
}