1
- import React , { useState , useEffect } from "react" ;
1
+ import React , { useCallback , useState , useEffect , useRef } from "react" ;
2
2
import clsx from "clsx" ;
3
3
import CloseIcon from "../../../static/img/recipe_selector_close.png" ;
4
- import OpenIcon from "../../../static/img/recipe_selector_open.png" ;
5
4
6
- import { useLocation } from ' @docusaurus/router' ;
5
+ import { useLocation } from " @docusaurus/router" ;
7
6
8
7
export default function RecipeSelector ( props ) {
9
- const { pathname } = useLocation ( )
8
+ const { pathname } = useLocation ( ) ;
10
9
const currDocs = pathname . split ( "/" ) [ 2 ] ;
10
+ const ref = useRef ( null ) ;
11
11
const [ open , setOpen ] = useState ( false ) ;
12
12
const activeSelector = ( id ) => {
13
13
return id === currDocs ;
@@ -42,25 +42,33 @@ export default function RecipeSelector(props) {
42
42
return "Select Recipe" ;
43
43
}
44
44
} ;
45
+ const closeDropdownMenuOnOusideClick = useCallback ( ( e ) => {
46
+ if ( ref . current && ! ref . current . contains ( e . target ) ) {
47
+ setOpen ( false ) ;
48
+ }
49
+ } , [ ] ) ;
50
+
45
51
useEffect ( ( ) => {
46
- const closeDropDown = ( e ) => {
47
- if ( e . target . classList [ 0 ] ?. startsWith ( "recipe_selector" ) ) {
48
- // no-op
49
- } else {
50
- setOpen ( false ) ;
51
- }
52
- } ;
53
- window . addEventListener ( "click" , closeDropDown ) ;
52
+ window . addEventListener ( "click" , closeDropdownMenuOnOusideClick ) ;
53
+ return ( ) =>
54
+ window . removeEventListener ( "click" , closeDropdownMenuOnOusideClick ) ;
54
55
} , [ ] ) ;
56
+
55
57
return (
56
- < div className = "recipe_selector" >
58
+ < div className = "recipe_selector" ref = { ref } >
57
59
< div
58
60
onClick = { ( ) => setOpen ( ! open ) }
59
61
className = { clsx ( "recipe_selector__dropdown" , { open : open } ) }
60
62
>
61
63
< span > { label ( ) } </ span >
62
64
< div >
63
- < img src = { CloseIcon } style = { { transform : open ? "rotate(180deg)" : "" , transition : "all 250ms linear" } } />
65
+ < img
66
+ src = { CloseIcon }
67
+ style = { {
68
+ transform : open ? "rotate(180deg)" : "" ,
69
+ transition : "all 250ms linear" ,
70
+ } }
71
+ />
64
72
</ div >
65
73
</ div >
66
74
< div
@@ -77,7 +85,9 @@ export default function RecipeSelector(props) {
77
85
active : activeSelector ( "thirdpartyemailpassword" ) ,
78
86
} ) }
79
87
>
80
- < a href = "/docs/thirdpartyemailpassword/introduction" > Email password + Social / Enterprise Login</ a >
88
+ < a href = "/docs/thirdpartyemailpassword/introduction" >
89
+ Email password + Social / Enterprise Login
90
+ </ a >
81
91
</ li >
82
92
< li
83
93
className = { clsx ( "recipe_selector__menu__auth_methods_items" , {
@@ -91,28 +101,36 @@ export default function RecipeSelector(props) {
91
101
active : activeSelector ( "emailpassword" ) ,
92
102
} ) }
93
103
>
94
- < a href = "/docs/emailpassword/introduction" > Email password Login</ a >
104
+ < a href = "/docs/emailpassword/introduction" >
105
+ Email password Login
106
+ </ a >
95
107
</ li >
96
108
< li
97
109
className = { clsx ( "recipe_selector__menu__auth_methods_items" , {
98
110
active : activeSelector ( "thirdpartypasswordless" ) ,
99
111
} ) }
100
112
>
101
- < a href = "/docs/thirdpartypasswordless/introduction" > Social / Enterprise Login + Passwordless</ a >
113
+ < a href = "/docs/thirdpartypasswordless/introduction" >
114
+ Social / Enterprise Login + Passwordless
115
+ </ a >
102
116
</ li >
103
117
< li
104
118
className = { clsx ( "recipe_selector__menu__auth_methods_items" , {
105
119
active : activeSelector ( "thirdparty" ) ,
106
120
} ) }
107
121
>
108
- < a href = "/docs/thirdparty/introduction" > Social / Enterprise Login</ a >
122
+ < a href = "/docs/thirdparty/introduction" >
123
+ Social / Enterprise Login
124
+ </ a >
109
125
</ li >
110
126
< li
111
127
className = { clsx ( "recipe_selector__menu__auth_methods_items" , {
112
128
active : activeSelector ( "phonepassword" ) ,
113
129
} ) }
114
130
>
115
- < a href = "/docs/phonepassword/introduction" > Phone Password Login</ a >
131
+ < a href = "/docs/phonepassword/introduction" >
132
+ Phone Password Login
133
+ </ a >
116
134
</ li >
117
135
</ ul >
118
136
</ div >
@@ -152,14 +170,18 @@ export default function RecipeSelector(props) {
152
170
active : activeSelector ( "microservice_auth" ) ,
153
171
} ) }
154
172
>
155
- < a href = "/docs/microservice_auth/introduction" > Microservice Authentication</ a >
173
+ < a href = "/docs/microservice_auth/introduction" >
174
+ Microservice Authentication
175
+ </ a >
156
176
</ li >
157
177
< li
158
178
className = { clsx ( "recipe_selector__menu__add_ons_items" , {
159
179
active : activeSelector ( "multitenancy" ) ,
160
180
} ) }
161
181
>
162
- < a href = "/docs/multitenancy/introduction" > Multi tenancy / organizations</ a >
182
+ < a href = "/docs/multitenancy/introduction" >
183
+ Multi tenancy / organizations
184
+ </ a >
163
185
</ li >
164
186
</ ul >
165
187
</ div >
0 commit comments