|
4 | 4 | * |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { memo } from 'react' |
8 | | -import T from 'prop-types' |
| 7 | +import { FC, memo } from 'react' |
9 | 8 |
|
10 | | -import { |
11 | | - Wrapper, |
12 | | - Item, |
13 | | - RadioWrapper, |
14 | | - RadioItem, |
15 | | - ActiveDot, |
16 | | - RadioTitle, |
17 | | -} from '../styles/filter' |
| 9 | +import type { TID, TTag } from '@/spec' |
18 | 10 |
|
19 | | -const isActive = (activeMap, expandMenuId, itemId) => { |
20 | | - if (!expandMenuId) return false |
21 | | - return activeMap[expandMenuId].id === itemId |
| 11 | +import ExpandTag from './ExpandTag' |
| 12 | +import SelectedTag from './SelectedTag' |
| 13 | + |
| 14 | +import { Wrapper, Item, TagsWrapper } from '../styles/filter' |
| 15 | + |
| 16 | +export type TProps = { |
| 17 | + id: TID |
| 18 | + expandMenuId: TID | null |
| 19 | + activeMap: Record<string, TTag> |
| 20 | + options: TTag[] |
| 21 | + revert: boolean |
| 22 | + onSelect: (expandMenuId: TID, tag: TTag) => void |
22 | 23 | } |
23 | 24 |
|
24 | | -const Filter = ({ id, expandMenuId, activeMap, options, onSelect, revert }) => { |
| 25 | +const Filter: FC<TProps> = ({ |
| 26 | + id, |
| 27 | + expandMenuId = null, |
| 28 | + activeMap, |
| 29 | + options, |
| 30 | + onSelect, |
| 31 | + revert, |
| 32 | +}) => { |
25 | 33 | return ( |
26 | 34 | <Wrapper revert={revert}> |
27 | 35 | <Item revert={revert}> |
28 | 36 | {expandMenuId === id && options ? ( |
29 | | - <RadioWrapper revert={revert}> |
| 37 | + <TagsWrapper revert={revert}> |
30 | 38 | {options.map((item) => ( |
31 | | - <RadioItem |
| 39 | + <ExpandTag |
32 | 40 | key={item.id} |
33 | | - onClick={() => onSelect(expandMenuId, item)} |
34 | | - > |
35 | | - {!revert ? ( |
36 | | - <> |
37 | | - <ActiveDot |
38 | | - active={isActive(activeMap, expandMenuId, item.id)} |
39 | | - /> |
40 | | - <RadioTitle |
41 | | - active={isActive(activeMap, expandMenuId, item.id)} |
42 | | - > |
43 | | - {item.title} |
44 | | - </RadioTitle> |
45 | | - </> |
46 | | - ) : ( |
47 | | - <> |
48 | | - <RadioTitle |
49 | | - active={isActive(activeMap, expandMenuId, item.id)} |
50 | | - revert |
51 | | - > |
52 | | - {item.title} |
53 | | - </RadioTitle> |
54 | | - <ActiveDot |
55 | | - active={isActive(activeMap, expandMenuId, item.id)} |
56 | | - /> |
57 | | - </> |
58 | | - )} |
59 | | - </RadioItem> |
| 41 | + tag={item} |
| 42 | + activeMap={activeMap} |
| 43 | + expandMenuId={expandMenuId} |
| 44 | + revert={revert} |
| 45 | + onSelect={onSelect} |
| 46 | + /> |
60 | 47 | ))} |
61 | | - </RadioWrapper> |
| 48 | + </TagsWrapper> |
62 | 49 | ) : ( |
63 | | - <RadioWrapper revert={revert}> |
64 | | - <RadioItem> |
65 | | - {!revert ? ( |
66 | | - <> |
67 | | - <ActiveDot active /> |
68 | | - <RadioTitle active> |
69 | | - {activeMap[id] ? activeMap[id].title || '全部' : '全部'} |
70 | | - </RadioTitle> |
71 | | - </> |
72 | | - ) : ( |
73 | | - <> |
74 | | - <RadioTitle active revert> |
75 | | - {activeMap[id] ? activeMap[id].title || '全部' : '全部'} |
76 | | - </RadioTitle> |
77 | | - <ActiveDot active /> |
78 | | - </> |
79 | | - )} |
80 | | - </RadioItem> |
81 | | - </RadioWrapper> |
| 50 | + <TagsWrapper revert={revert}> |
| 51 | + <SelectedTag |
| 52 | + tag={activeMap[id]} |
| 53 | + expandMenuId={expandMenuId} |
| 54 | + revert={revert} |
| 55 | + onSelect={onSelect} |
| 56 | + /> |
| 57 | + </TagsWrapper> |
82 | 58 | )} |
83 | 59 | </Item> |
84 | 60 | </Wrapper> |
85 | 61 | ) |
86 | 62 | } |
87 | 63 |
|
88 | | -Filter.propTypes = { |
89 | | - id: T.string.isRequired, |
90 | | - expandMenuId: T.oneOfType([T.string, T.instanceOf(null)]), |
91 | | - activeMap: T.shape({ |
92 | | - id: T.string, |
93 | | - title: T.string, |
94 | | - }).isRequired, |
95 | | - options: T.arrayOf( |
96 | | - T.shape({ |
97 | | - id: T.string, |
98 | | - title: T.string, |
99 | | - }), |
100 | | - ).isRequired, |
101 | | - revert: T.bool.isRequired, |
102 | | - onSelect: T.func.isRequired, |
103 | | -} |
104 | | - |
105 | | -Filter.defaultProps = { |
106 | | - expandMenuId: null, |
107 | | -} |
108 | | - |
109 | 64 | export default memo(Filter) |
0 commit comments