@@ -16,30 +16,25 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
16
16
import CancelIcon from '@mui/icons-material/Cancel' ;
17
17
import ComparePopover from './ComparePopover' ;
18
18
19
- type childFilter = {
20
- label : string ;
21
- onChange : ( value : string ) => void ;
22
- } ;
23
19
export interface DisplayFilterProps {
24
20
label : string ;
25
21
showAll ?: boolean ;
26
22
onChange : ( ) => void ;
27
23
value : boolean ;
28
24
showCancel ?: boolean ;
29
- children ?: childFilter [ ] ;
25
+ showCompare ?: boolean ;
30
26
isChild ?: boolean ;
27
+ cancelFilter ?: ( e : any ) => void ;
31
28
}
32
29
33
- export function DisplayFilter ( {
34
- label,
35
- onChange,
36
- value,
37
- showCancel,
38
- children,
39
- showAll
30
+ export function DisplayFilter ( { label, onChange, value, showCancel, showAll, showCompare, cancelFilter,
40
31
} : DisplayFilterProps ) {
41
32
const [ show , setShow ] = useState < boolean > ( false ) ;
42
33
const [ open , setOpen ] = useState < boolean > ( false ) ;
34
+ const [ children , setChildren ] = useState < { name : string ; value : string } [ ] > ( [ {
35
+ value : '' ,
36
+ name : 'as of now'
37
+ } ] ) ;
43
38
44
39
const filterClicked = ( ) => {
45
40
setShow ( ! show ) ;
@@ -51,14 +46,24 @@ export function DisplayFilter({
51
46
setOpen ( ! open ) ;
52
47
} ;
53
48
54
- const cancelFilter = ( e : React . SyntheticEvent ) => {
55
- e . stopPropagation ( ) ;
56
- } ;
57
-
58
49
useEffect ( ( ) => {
59
50
setShow ( value ) ;
60
51
} , [ value ] ) ;
61
52
53
+ const search = ( { name, value } : { name : string ; value : string } ) => {
54
+ console . log ( 'value ' , value ) ;
55
+ console . log ( 'name ' , name ) ;
56
+ // has results -
57
+ // add the tag to the children list.
58
+ const newChildren = [ ...children || [ ] , { name, value} ] ;
59
+ setChildren ( newChildren ) ;
60
+ // empty - toggle on no results
61
+ } ;
62
+
63
+ const removeChildFilter = ( e : any ) => {
64
+ console . log ( 'e' , e ) ;
65
+ } ;
66
+
62
67
return (
63
68
< div >
64
69
< ThemeProvider theme = { theme } >
@@ -67,19 +72,20 @@ export function DisplayFilter({
67
72
gap = { 1 }
68
73
direction = { 'row' }
69
74
sx = { {
70
- cursor : 'pointer' ,
71
- background : '#F8FAFC' ,
75
+ background : open ? '#F1F5F9' : '#F8FAFC' ,
72
76
color : '#172D32' ,
77
+ '&:hover' : {
78
+ backgroundColor : '#F1F5F9'
79
+ } ,
73
80
'&:hover #cancel' : {
74
81
display : 'initial'
75
- }
82
+ } ,
83
+ borderLeft : open ? '3px solid #C4B5FD' : '3px solid transparent'
76
84
} }
77
85
display = { 'flex' }
78
86
justifyContent = { 'space-between' }
79
87
alignItems = { 'center' }
80
- onClick = { filterClicked }
81
88
padding = { '8px' }
82
- role = { 'button' }
83
89
>
84
90
< Box
85
91
alignItems = { 'center' }
@@ -99,16 +105,18 @@ export function DisplayFilter({
99
105
{ label }
100
106
</ Typography >
101
107
102
- { children ?. length && (
108
+ { children ?. length > 1 && (
103
109
< IconButton
104
110
sx = { {
111
+ padding : 0 ,
112
+ height : '20px' ,
113
+ width : '20px' ,
105
114
transition : '.3s ease-in-out' ,
106
115
transform : open ? 'rotate(180deg)' : 'unset' ,
107
116
'&:hover' : {
108
117
backgroundColor : 'transparent'
109
118
}
110
119
} }
111
- disableRipple
112
120
onClick = { onToggle }
113
121
>
114
122
< ExpandMoreIcon />
@@ -117,8 +125,8 @@ export function DisplayFilter({
117
125
</ Box >
118
126
119
127
< Stack direction = { 'row' } gap = { 1 } >
120
- { showCancel && (
121
- < IconButton onClick = { cancelFilter } sx = { { padding : 0 } } disableRipple >
128
+ { ! ! cancelFilter && (
129
+ < IconButton onClick = { ( ) => cancelFilter ( label ) } sx = { { padding : 0 } } >
122
130
< CancelIcon
123
131
id = { 'cancel' }
124
132
sx = { {
@@ -132,33 +140,33 @@ export function DisplayFilter({
132
140
</ IconButton >
133
141
) }
134
142
143
+ { showCompare && < ComparePopover search = { search } /> }
144
+
135
145
< IconButton
136
146
sx = { { padding : 0 , height : '20px' , width : '21.08px' } }
137
- disableRipple
138
- onClick = { ( ) => { } }
147
+ onClick = { filterClicked }
139
148
>
140
149
< Icon icon = { show ? 'eye' : 'eye-off' } height = { 20 } width = { 21.08 } fill = { '#94A3B8' } />
141
150
</ IconButton >
142
151
</ Stack >
143
152
</ Box >
144
153
</ Stack >
145
154
146
- < ComparePopover />
147
-
148
155
{ /*annotations */ }
149
- { children ?. length && (
156
+ { children ?. length > 1 && (
150
157
< Collapse in = { open } timeout = "auto" unmountOnExit >
151
158
< List component = "div" disablePadding >
152
- < Box borderLeft = { '3px solid #C4B5FD' } paddingLeft = { 2 } >
159
+ < Box paddingLeft = { 2 } >
153
160
{ children ?. map ( ( item ) => (
154
- < Tooltip title = { item ?. label } >
161
+ < Tooltip title = { item ?. name } >
155
162
< div >
156
163
< DisplayFilter
157
164
isChild
158
165
value = { ! ! showAll }
159
- label = { item ?. label }
166
+ label = { item ?. name }
160
167
onChange = { ( ) => console . log ( 'changed' ) }
161
168
showCancel
169
+ cancelFilter = { removeChildFilter }
162
170
/>
163
171
</ div >
164
172
</ Tooltip >
0 commit comments