|
1 | | -import { Space, Tag, Button } from 'antd'; |
| 1 | +import { Space, Tag, Button, Row, Col } from 'antd'; |
2 | 2 | import { CloseOutlined } from '@ant-design/icons'; |
3 | 3 | import { useTranslation } from 'react-i18next'; |
4 | 4 | import SearchBox from '../SearchBox'; |
5 | 5 | import StarRating from '../StarRating'; |
| 6 | +import { useMediaQuery } from 'react-responsive'; |
6 | 7 |
|
7 | 8 | interface ChallengeFiltersProps { |
8 | 9 | /** |
@@ -72,60 +73,90 @@ const ChallengeFilters: React.FC<ChallengeFiltersProps> = ({ |
72 | 73 | searchValue = '' |
73 | 74 | }) => { |
74 | 75 | const { t } = useTranslation(); |
| 76 | + const isMobile = useMediaQuery({ maxWidth: 768 }); |
75 | 77 |
|
76 | 78 | return ( |
77 | 79 | <div> |
78 | | - {/* 搜索框组件 */} |
79 | | - <SearchBox |
80 | | - onSearch={onSearch} |
81 | | - value={searchValue} |
82 | | - placeholder={t('challenges.filters.search')} |
83 | | - historyStorageKey="challenge-search-history" |
84 | | - /> |
| 80 | + {/* 搜索框组件 - 移除style属性,使用div包装处理边距 */} |
| 81 | + <div style={{ marginBottom: isMobile ? '8px' : '16px' }}> |
| 82 | + <SearchBox |
| 83 | + onSearch={onSearch} |
| 84 | + value={searchValue} |
| 85 | + placeholder={t('challenges.filters.search')} |
| 86 | + historyStorageKey="challenge-search-history" |
| 87 | + /> |
| 88 | + </div> |
85 | 89 |
|
86 | 90 | {/* 已应用的过滤器 */} |
87 | 91 | {hasFilters && ( |
88 | | - <Space wrap style={{ marginBottom: 16 }}> |
89 | | - {selectedDifficulty !== 'all' && ( |
90 | | - <Tag |
91 | | - closable |
92 | | - onClose={onRemoveDifficulty} |
93 | | - style={{ background: '#f0f5ff', borderColor: '#adc6ff' }} |
94 | | - > |
95 | | - {t('challenges.sort.difficulty')}: <StarRating difficulty={parseInt(selectedDifficulty)} /> |
96 | | - </Tag> |
97 | | - )} |
98 | | - |
99 | | - {selectedPlatform !== 'all' && ( |
100 | | - <Tag |
101 | | - closable |
102 | | - onClose={onRemovePlatform} |
103 | | - color={selectedPlatform === 'LeetCode' ? 'orange' : 'purple'} |
104 | | - > |
105 | | - {t('challenge.detail.targetWebsite')}: {selectedPlatform} |
106 | | - </Tag> |
107 | | - )} |
108 | | - |
109 | | - {selectedTags.map(tag => ( |
110 | | - <Tag |
111 | | - key={tag} |
112 | | - closable |
113 | | - onClose={() => onRemoveTag(tag)} |
114 | | - style={{ background: '#f6ffed', borderColor: '#b7eb8f' }} |
115 | | - > |
116 | | - {tag} |
117 | | - </Tag> |
118 | | - ))} |
119 | | - |
120 | | - <Button |
121 | | - type="text" |
122 | | - icon={<CloseOutlined />} |
123 | | - onClick={onClearAll} |
124 | | - style={{ color: '#ff4d4f' }} |
125 | | - > |
126 | | - {t('challenges.filters.clearAll')} |
127 | | - </Button> |
128 | | - </Space> |
| 92 | + <Row gutter={[8, 8]} style={{ marginBottom: isMobile ? '8px' : '16px' }}> |
| 93 | + <Col span={24}> |
| 94 | + <Space wrap size={isMobile ? 4 : 8} style={{ width: '100%' }}> |
| 95 | + {selectedDifficulty !== 'all' && ( |
| 96 | + <Tag |
| 97 | + closable |
| 98 | + onClose={onRemoveDifficulty} |
| 99 | + style={{ |
| 100 | + background: '#f0f5ff', |
| 101 | + borderColor: '#adc6ff', |
| 102 | + fontSize: isMobile ? '12px' : '14px', |
| 103 | + padding: isMobile ? '0 4px' : '0 7px', |
| 104 | + margin: isMobile ? '0 4px 4px 0' : '0 8px 8px 0' |
| 105 | + }} |
| 106 | + > |
| 107 | + {isMobile ? '' : `${t('challenges.sort.difficulty')}: `} |
| 108 | + <StarRating difficulty={parseInt(selectedDifficulty)} /> |
| 109 | + </Tag> |
| 110 | + )} |
| 111 | + |
| 112 | + {selectedPlatform !== 'all' && ( |
| 113 | + <Tag |
| 114 | + closable |
| 115 | + onClose={onRemovePlatform} |
| 116 | + color={selectedPlatform === 'LeetCode' ? 'orange' : 'purple'} |
| 117 | + style={{ |
| 118 | + fontSize: isMobile ? '12px' : '14px', |
| 119 | + padding: isMobile ? '0 4px' : '0 7px', |
| 120 | + margin: isMobile ? '0 4px 4px 0' : '0 8px 8px 0' |
| 121 | + }} |
| 122 | + > |
| 123 | + {isMobile ? selectedPlatform : `${t('challenge.detail.targetWebsite')}: ${selectedPlatform}`} |
| 124 | + </Tag> |
| 125 | + )} |
| 126 | + |
| 127 | + {selectedTags.map(tag => ( |
| 128 | + <Tag |
| 129 | + key={tag} |
| 130 | + closable |
| 131 | + onClose={() => onRemoveTag(tag)} |
| 132 | + style={{ |
| 133 | + background: '#f6ffed', |
| 134 | + borderColor: '#b7eb8f', |
| 135 | + fontSize: isMobile ? '12px' : '14px', |
| 136 | + padding: isMobile ? '0 4px' : '0 7px', |
| 137 | + margin: isMobile ? '0 4px 4px 0' : '0 8px 8px 0' |
| 138 | + }} |
| 139 | + > |
| 140 | + {tag} |
| 141 | + </Tag> |
| 142 | + ))} |
| 143 | + |
| 144 | + <Button |
| 145 | + type="text" |
| 146 | + icon={<CloseOutlined />} |
| 147 | + onClick={onClearAll} |
| 148 | + style={{ |
| 149 | + color: '#ff4d4f', |
| 150 | + fontSize: isMobile ? '12px' : '14px', |
| 151 | + height: isMobile ? '22px' : '28px', |
| 152 | + padding: isMobile ? '0 4px' : '0 8px' |
| 153 | + }} |
| 154 | + > |
| 155 | + {isMobile ? t('challenges.filters.clearAllShort') : t('challenges.filters.clearAll')} |
| 156 | + </Button> |
| 157 | + </Space> |
| 158 | + </Col> |
| 159 | + </Row> |
129 | 160 | )} |
130 | 161 | </div> |
131 | 162 | ); |
|
0 commit comments